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

Cleanup and refactoring, mostly prepared for custom values #1

Merged
merged 5 commits into from
Aug 6, 2020

Conversation

IsaacElenbaas
Copy link

I've done my best to condense this to just one evaluate function and remove conditions. It fits more with AutoShift's behavior (record stuff on press, evaluate on release or another key down [and now timeout]) and is easier to wrap your head around.

Adding support for custom values should at this point be a 10-minute task, aside from somehow recording whether the shifted key was the one pressed (for if its release isn't immediately triggered and the shift state could have been changed). Simply releasing both the unshifted and shifted base keys is also an option.

@IsaacElenbaas
Copy link
Author

As far as I can tell behavior is unchanged, but this does not rely on the key's own releases which makes custom values possible.

Copy link
Owner

@p00ya p00ya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

I'll do some testing with your change as well.

quantum/process_keycode/process_auto_shift.c Outdated Show resolved Hide resolved
quantum/process_keycode/process_auto_shift.c Outdated Show resolved Hide resolved
quantum/process_keycode/process_auto_shift.c Outdated Show resolved Hide resolved
quantum/process_keycode/process_auto_shift.c Show resolved Hide resolved
quantum/process_keycode/process_auto_shift.c Outdated Show resolved Hide resolved
@IsaacElenbaas
Copy link
Author

Pressing one autoshift key, pressing another, and releasing the first causes both to be unshifted regardless of the second one's hold time. Not sure how to fix here, but found a solution if custom shifts is merged.

@p00ya
Copy link
Owner

p00ya commented Jul 31, 2020

Issues from manual testing (with AUTO_SHIFT_REPEAT):

  1. Both shift keys are getting held. I can see that the code is only doing add_weak_mods(MOD_BIT(KC_LSFT)), so possibly that's something misleading in how add_weak_mods works. Why this is bad: double-shift can have a special action in the OS (e.g. setxkbmap -option grp:shifts_toggle binds double-shift to changing the OS keymap in X11).
  2. The shift keys are stuck on after the auto-shifted key is released. Release the shift key when the last auto-shifted key is released (unless the user manually held down the left shift key themselves). Why this is bad: something like "click and insert" in a document will instead "select and replace" because you're actually shift-clicking.

You'll have to rebase to get rid of the conflicts (sorry - I'm rebasing over qmk/develop myself).

Pressing one autoshift key, pressing another, and releasing the first causes both to be unshifted regardless of the second one's hold time. Not sure how to fix here, but found a solution if custom shifts is merged.

FYI I couldn't repro the issue you mentioned (if I hold 1 until it repeats as !, then hold 2, then release 1, then shift is still correctly held for me).

@IsaacElenbaas
Copy link
Author

IsaacElenbaas commented Jul 31, 2020

Shoot, thought I had already fixed the conflicts. Oh well, will try again.

Tested with xbindkeys --multikey, only LSFT is being hit. Reason for 2 was del_weak_mods that doesn't trigger a keyboard report.

The issue with releasing is when under the tapping term - pressing the second key triggers evaluation of the first, and releasing the first key still in the second one's hold time causes the latter to be evaluated and released as non-shifted, even if you're still holding it. The cause is autoshift_end not having a specified key to release, and defaulting to the currently autoshifted one if it is in progress. The fix from custom shifts might actually work, I don't see why it wouldn't anymore. Will test.

}
} else {
autoshift_end(keycode, record->event.time, false);
return false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would it take to rewrite this so that we could return true here (at least for the non-custom case)?

I tried to avoid eating records since the behaviour becomes less transparent to things downstream (like process_record_user).

Copy link
Author

@IsaacElenbaas IsaacElenbaas Jul 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically just not mergng this. It's near impossible to return true and still have control of keyrepeat to make this not a breaking change, and this refactor relies heavily on the assumption that it will be the one pressing and releasing keys (as I was preparing for custom ones). Your original pull is simpler if you want to go with only-keyrepeat, though I would probably submit another cleanup pull to make it handle shift more like this.

IMO that is more of a QMK-wide issue. We need a way to let other processes know that a key was pressed but that it's been handled and they shouldn't press anything, avoiding return false; everywhere is a pain.

unregister_code(keycode);
if (keycode == autoshift_lastkey) {
// This will only fire when the key was the last auto-shiftable
// pressed. That prevents aaaaBBBB then releasing a from unshifting
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do you mind putting quotes around the keys here ("releasing a from" is a bit hard to parse eagerly).

if (elapsed < TAPPING_TERM && keycode == autoshift_lastkey) {
// Allow a tap-then-hold for keyrepeat.
if (!autoshift_flags.lastshifted) {
register_code(autoshift_lastkey);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good if we could return true here rather than registering the key ourselves. Though you'd miss updating autoshift_time below if you returned directly.

@p00ya p00ya merged this pull request into p00ya:pull-auto-shift Aug 6, 2020
@IsaacElenbaas IsaacElenbaas deleted the auto-shift-cleanup branch February 23, 2022 15:39
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.

2 participants