Skip to content
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

Merged
merged 2 commits into from
Nov 3, 2020

Conversation

okke-formsma
Copy link
Collaborator

Implements #86.

&sft NUM_1 presses shift, then 1, then releases shift, then releases 1.

Copy link
Contributor

@BrainWart BrainWart left a 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.

app/dts/behaviors/modifiers.dtsi Outdated Show resolved Hide resolved
app/include/dt-bindings/zmk/keys.h Outdated Show resolved Hide resolved
app/src/hid.c Outdated Show resolved Hide resolved
@CrossR
Copy link
Contributor

CrossR commented Sep 9, 2020

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.

@okke-formsma
Copy link
Collaborator Author

I've fixed the bug CrossR was running into, and updated the test so it won't happen again.

Copy link
Contributor

@CrossR CrossR left a 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.

app/dts/behaviors/modifiers.dtsi Outdated Show resolved Hide resolved
app/dts/behaviors/modifiers.dtsi Outdated Show resolved Hide resolved
app/src/hid.c Outdated Show resolved Hide resolved
app/src/hid.c Outdated Show resolved Hide resolved
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?
Copy link
Collaborator Author

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

#define MOD_LCTL 0x01
Copy link
Contributor

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.

Copy link
Contributor

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.

@innovaker
Copy link
Contributor

Thanks @okke-formsma! Just a quick suggestion for now (above), will look closer tomorrow with fresh eyes.

Comment on lines 165 to +168
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();
Copy link
Contributor

@innovaker innovaker Nov 1, 2020

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 into hid_keyboard.c and hid_consumer.c

Perhaps it's better suited to a dedicated module, say modifiers.h/c or hid_modifiers.h/c?

Copy link
Contributor

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.

Comment on lines +29 to +33
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);
Copy link
Contributor

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?

Copy link
Contributor

@petejohanson petejohanson left a 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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants