-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
initial implementation for modifiers #153
Conversation
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.
Thanks, Okke. I saw a couple of things and was wondering what MOD_LAST_MODIFIER
was for. I haven't had a chance to test it yet personally.
c7dfbce
to
29d66e3
Compare
Just to duplicate the comment I made on discord, I'm seeing some stuck modifiers using this PR merged with main. I see either my LCTL or LSFT stick after pressing them, and I don't see this behaviour on main. My config is in a branch here, and I don't believe I'm doing anything especially odd, just defining the keys for my layout. https://github.com/CrossR/zmk_config/compare/CrossR/ShiftedKeyCodes I'm seeing the stuck modifiers when using the normal LCTL and LSFT on my default layer, which are unchanged from my normal keymap. |
I've fixed the bug CrossR was running into, and updated the test so it won't happen again. |
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.
No stuck mods now! Though I am not seeing any mod applied keypresses, though I believe I see why, assuming I'm following the code correctly.
With the change I've mentioned, "it works on my machine" TM at least.
ead705a
to
63e18ce
Compare
63e18ce
to
7f0409b
Compare
423f342
to
ef9ada3
Compare
ev->keycode = keycode; | ||
// this is ugly and after merging https://github.com/zmkfirmware/zmk/pull/300 | ||
// should move into the keycode_state_changed_from_encoded method | ||
// discuss: should we keep LCTL and MOD_LCTL even though it causes this ugly code? |
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 don't like this code here, but I'm not sure it's better to in hid.c.
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 think one good reason to remove this from here is to help keep clearly distinct the modifiers that are being held/applied because they are being asked for in addition to a different keycode, and a modifier that truly is just a modifier being pressed/released.
That context I think is important to preserve, because we'll need to when we work to solve the more nuanced handling of modifiers and when we release them because of other key presses, etc.
Thoughts?
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.
Agreed, that's a neat way to separate the implicit/explicit modifiers.
ef9ada3
to
d4b6ee0
Compare
d4b6ee0
to
9c2b21d
Compare
#define MOD_LCTL 0x01 |
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'd suggest moving the modifiers codes and macros into their own header - perhaps modifiers.h
?
For now, modifiers.h
can be included into keys.h
until the single entry point enhancement for keymaps has been implemented. The includes to keys.h
elsewhere in the system (such as in keycode-state-changed.h
) can then be replaced by modifiers.h
which is a tighter design.
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.
Fully agreed. I'm going to merge this from @okke-formsma , and then follow up with that small refactor.
Thanks @okke-formsma! Just a quick suggestion for now (above), will look closer tomorrow with fresh eyes. |
int zmk_hid_register_mod(zmk_mod modifier); | ||
int zmk_hid_unregister_mod(zmk_mod modifier); | ||
int zmk_hid_register_mods(zmk_mod_flags modifiers); | ||
int zmk_hid_unregister_mods(zmk_mod_flags modifiers); | ||
int zmk_hid_implicit_modifiers_press(zmk_mod_flags implicit_modifiers); | ||
int zmk_hid_implicit_modifiers_release(); |
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'm not sure if the modifier implicit/explicit/counting state and related functions should live within hid.h/c
.
Rationale:
- it reduces the cohesion of the
hid
system/module. - there's weak coupling to the rest of the
hid
module. - it feels like a conceptual layer above
hid
. - the
modifiers
system will likely be part of or linked to the internal state subsystem(s) that have been discussed recently. hid.c
itself can probably be refactored intohid_keyboard.c
andhid_consumer.c
Perhaps it's better suited to a dedicated module, say modifiers.h/c
or hid_modifiers.h/c
?
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 think this is fine for now, and we can refactor if/when we have a plan/need for the state changes.
int zmk_hid_register_mod(zmk_mod modifier) { | ||
explicit_modifier_counts[modifier]++; | ||
LOG_DBG("Modifier %d count %d", modifier, explicit_modifier_counts[modifier]); | ||
WRITE_BIT(explicit_modifiers, modifier, true); | ||
SET_MODIFIERS(explicit_modifiers); |
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.
If we're going for explicit
and implicit
, let's be consistent throughout?
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.
Thanks for this! I've been playing with it the past couple hours, and it seems really solid. Definitely good enough we should get this in, and pound on it a bit, get the HID refactor from @innovaker in with the nice defines for common shifted codes, and call it a day. Thanks again!
#define MOD_LCTL 0x01 |
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.
Fully agreed. I'm going to merge this from @okke-formsma , and then follow up with that small refactor.
Implements #86.
&sft NUM_1
presses shift, then 1, then releases shift, then releases 1.