-
-
Notifications
You must be signed in to change notification settings - Fork 40.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Community modules #24848
base: develop
Are you sure you want to change the base?
Community modules #24848
Conversation
Very cool! I'm excited to see #if !defined(IS_QK_MOD_TAP)
// Attempt to detect out-of-date QMK installation, which would fail with
// implicit-function-declaration errors in the code below.
#error "achordion: QMK version is too old to build. Please update QMK."
#else
// Achordion implementation...
|
@@ -335,7 +356,7 @@ bool process_record_quantum(keyrecord_t *record) { | |||
#if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE) | |||
process_auto_mouse(keycode, record) && | |||
#endif | |||
process_record_kb(keycode, record) && | |||
process_record_modules(keycode, record) && process_record_kb(keycode, record) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a keymap using multiple modules at once, how do you call the process_record, etc. hooks for every module? I was expecting a "call next module" or a loop somewhere but didn't find how you do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules calls kb calls user. To facilitate users/kb overriding the module, each module has its own module_user and module_kb, called in the usual way. The codegen handles the base implementation core-side, so user/kb-level code doesn’t need to call modules as it’s the new “parent” — each module call is chained within the codegen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To elaborate, at the moment codegen generates the following invocation styles:
void keyboard_post_init_modules(void) {
keyboard_post_init_hello_world2();
keyboard_post_init_hello_world();
}
bool pre_process_record_modules(uint16_t keycode, keyrecord_t *record) {
return true
&& pre_process_record_hello_world2(keycode, record)
&& pre_process_record_hello_world(keycode, record)
;
}
As well as the module-specific callbacks:
__attribute__((weak)) bool pre_process_record_hello_world_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
__attribute__((weak)) bool pre_process_record_hello_world_kb(uint16_t keycode, keyrecord_t *record) {
if(!pre_process_record_hello_world_user(keycode, record)) { return false; }
return true;
}
__attribute__((weak)) bool pre_process_record_hello_world(uint16_t keycode, keyrecord_t *record) {
if(!pre_process_record_hello_world_kb(keycode, record)) { return false; }
return true;
}
The user/kb can override the first two, with the module implementing the third as necessary. If unused, then the optimiser just skips the lot.
{ | ||
"ranges": { | ||
"0x77C0/0x003F": { | ||
"define": "QK_COMMUNITY_MODULE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see range QK_COMMUNITY_MODULE
to QK_COMMUNITY_MODULE_MAX
is reserved for modules, which is helpful. If multiple modules are used at once, and each needs a few keycodes, is there a way that each module could get part of this range without overlapping with other modules? It would be great if modules could each allocate keycodes in a standardized way, essentially, an automatic way to enumerate the range like:
enum module_keycodes {
// Keycodes for module Foo.
FOO_KC1 = QK_COMMUNITY_MODULE,
FOO_KC2,
FOO_KC3,
FOO_KC4,
// Keycodes for module Bar.
BAR_KC1,
BAR_KC2,
// Keycodes for more modules...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All module keycodes are assigned automatically, with keyboard module keycodes preceding keymap module keycodes, in the module order specified in the keyboard or keymap json.
Basically does exactly what you specified but with stable ordering. The define is mainly just to allocate a range, rather than using the keycode directly.
Description
Add support for community modules. Community modules are intended to be an area which provides common functionality to be easily imported into a keymap.
Additionally, community modules support placement inside userspace; module developers can thus create modules in separate repositories, and users can subsequently add them as userspace-local submodules to make them available for use in user keymaps.
keyboard.json
,info.json
, andkeymap.json
now accept a top-level array of strings called"modules"
_modules
=>_kb
=>_user
._modules
, in the module order provided.hello_world
module has the following overridable functions defined:process_record_hello_world_user
-- a no-op but allows user keymaps to hook the moduleprocess_record_hello_world_kb
-- invokes_user
by default, follows the same callback ordering as the rest of QMKprocess_record_hello_world
-- the actual module implementation ofprocess_record_xxxx
, executed beforeprocess_record_kb
orprocess_record_user
.Types of Changes
Checklist