After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 781285 - Key repeat cancel under Wayland should depend on which key is repeating
Key repeat cancel under Wayland should depend on which key is repeating
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Wayland
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 781896 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-04-13 19:28 UTC by Dan Torop
Modified: 2017-06-02 17:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] wayland: selectively cancel key repeat on key release (2.75 KB, patch)
2017-04-13 19:28 UTC, Dan Torop
none Details | Review
[PATCH v2] wayland: selectively cancel key repeat on key release (3.67 KB, patch)
2017-05-04 09:27 UTC, Olivier Fourdan
none Details | Review
[PATCH v3] wayland: selectively cancel key repeat on key release (3.36 KB, patch)
2017-05-04 14:03 UTC, Olivier Fourdan
none Details | Review
[PATCH v4] wayland: selectively cancel key repeat on key release (3.42 KB, patch)
2017-05-04 15:26 UTC, Olivier Fourdan
committed Details | Review

Description Dan Torop 2017-04-13 19:28:04 UTC
Created attachment 349836 [details] [review]
[PATCH] wayland: selectively cancel key repeat on key release

Under Wayland, when multiple keys are pressed and the user releases a key, key repeat should continue unless the key released is the one currently repeating.

In the case of:

- key1 press
- key1 repeat
- key2 press -> key1 repeat stopped
- key2 repeats
- key2 release

The behavior should be to cancel keyboard repeat, though key1 is still held down. This is consistent with prior X11/XWayland behavior.

The following also must work:

- key1 press
- key2 press
- key2 release
- key2 press
- key1 release
- key2 should continue to repeat

The fix for bug #778019 should continue to work:

- key1 press
- key1 repeat
- key2 press -> key1 repeat stopped
- key1 release
- key2 should repeat

The choice to change the counter nkeys to the flag repeat_active helps to solve the second test case.

Attached is a proposed patch to fix this behavior.
Comment 1 Olivier Fourdan 2017-05-02 13:21:27 UTC
That looks very similar to bug 781896 and attachment 350636 [details] [review]

Can you see if this works for you?
Comment 2 Dan Torop 2017-05-03 18:56:24 UTC
(In reply to Olivier Fourdan from comment #1)

Hi Olivier,

Glad to hear back! 

> That looks very similar to bug 781896 and attachment 350636 [details] [review]

Indeed bug 781896 and this one both address the same underlying problem. 

> 
> Can you see if this works for you?

Mixed results: attachment 350636 [details] [review] does solve bug 781896, but it doesn't produce expected behavior in the second case of this bug. To rewrite that case as in your (clearer) steps in bug 781896:

Steps to reproduce:

1. Press key "a" and keep the key pressed.
2. Press key "b" and release.
3. Press key "b" and keep the key pressed.
4. Release key "a".

Actual result:

Key "a" is repeated. Once key "b" is pressed and released, all repeats stop. Then key "b" is repeated when it is pressed again, but all repeat stops when key "a" is released.

Expected result:

Once key "a" is released, key "b" should continue to repeat, as it is still depressed and was one repeating.


The expected result may well be debatable, and is the proverbial corner case! But I put it in to suggest that counting the number of keys pressed is not actually pertinent. And this counting is easy to fool. So in the case above, in your patch, I believe that this is happening:

1. Press key "a" and keep the key pressed [nkeys = 1]
2. Press key "b" [nkeys = 2] and release [nkeys = 0, as have released the repeated key]
3. Press key "b" and keep the key pressed [nkeys = 1]
4. Release key "a". [nkeys = 0, and hence repeating stops, though "b" is still pressed and was repeating]

I'd argue that what really matters here isn't the count of keys pressed, but rather whether the key released is the currently repeated key. Hence my attachment 349836 [details] [review] entirely eliminates the nkeys counter, and just uses a flag (repeat_active).

As an aside, in your patch, you init repeat_key to 0. In my patch, I didn't initialize repeat_key, but do test it, assuming that, as it was only tested after a key release, it would by then have already been set by a keypress. Your approach is certainly safer!

This bug report came from a problem with darktable to under Wayland (https://redmine.darktable.org/issues/11535#note-14), and both your attachment 350636 [details] [review] and my attachment 349836 [details] [review] solve that problem. I don't have the big picture of Wayland devices which you have, and would hate to blithely advocate removal of nkeys, but do want to put it out there for consideration!

Thank you,
Dan
Comment 3 Olivier Fourdan 2017-05-04 09:27:42 UTC
Created attachment 351038 [details] [review]
[PATCH v2] wayland: selectively cancel key repeat on key release

(In reply to Dan Torop from comment #2)
> Glad to hear back! 

Sorry, it's just that I didn't see your bug report initially.
 
> Mixed results: attachment 350636 [details] [review] [review] does solve bug 781896,
> but it doesn't produce expected behavior in the second case of this bug. To
> rewrite that case as in your (clearer) steps in bug 781896:
> 
> Steps to reproduce:
> 
> 1. Press key "a" and keep the key pressed.
> 2. Press key "b" and release.
> 3. Press key "b" and keep the key pressed.
> 4. Release key "a".
> [...]

Yeah, I see what you mean. I don't have strong opinions there, whatever works and is close enough to Xorg behavior will be fine with me, and Xorg behaves as described here.
 
> As an aside, in your patch, you init repeat_key to 0. In my patch, I didn't
> initialize repeat_key, but do test it, assuming that, as it was only tested
> after a key release, it would by then have already been set by a keypress.
> Your approach is certainly safer!

Well it's easy enough to add.

> This bug report came from a problem with darktable to under Wayland
> (https://redmine.darktable.org/issues/11535#note-14), and both your
> attachment 350636 [details] [review] [review] and my attachment 349836 [details] [review]
> [review] solve that problem. I don't have the big picture of Wayland devices
> which you have, and would hate to blithely advocate removal of nkeys, but do
> want to put it out there for consideration!

Again I don't have strong opinions, we could go with your patch, it makes sense.

I am attaching an updated version of your patch with some changes (it needed updating after commit 83322a4 had landed), including the repeat_key value (I am not sure this is actually needed, just the over cautious part of me asking for that) - I also change the type of repeat_active to be a boolean, not hat it makes much difference eventually, but in essence it is a boolean so klet's use the appropriate type.

Lastly, I added a link to this bugzilla in your commit message, but if it was me, I would shorten and simplify the commit message though.
Comment 4 Olivier Fourdan 2017-05-04 09:28:22 UTC
Let's see what Carlos think of this :)
Comment 5 Olivier Fourdan 2017-05-04 09:29:03 UTC
*** Bug 781896 has been marked as a duplicate of this bug. ***
Comment 6 Olivier Fourdan 2017-05-04 14:03:33 UTC
Created attachment 351053 [details] [review]
[PATCH v3] wayland: selectively cancel key repeat on key release

Ah wait, following your logic, you don't even need a "repeat_key" at all, the attached patch works just as well, no?

And it's waaaaay simpler imho.
Comment 7 Olivier Fourdan 2017-05-04 14:11:44 UTC
Ah no sorry, my bad, I forgot we do need the "repeat key" flag or some other counter such as nkeys because we won't get a key release from the compositor on focus change (otherwise we'll end up re-introducing bug 779374) so attachment 351038 [details] [review] is better.
Comment 8 Olivier Fourdan 2017-05-04 15:26:29 UTC
Created attachment 351063 [details] [review]
[PATCH v4] wayland: selectively cancel key repeat on key release

Ok, last try and then I put it at rest, promise...

My take is that we don't even need a "repeat_key" flag, we could simply use the existing seat->repeat_key for that, as 0 is not a valid value there.
Comment 9 Dan Torop 2017-05-04 17:16:32 UTC
(In reply to Olivier Fourdan from comment #8)
> Created attachment 351063 [details] [review] [review]
> [PATCH v4] wayland: selectively cancel key repeat on key release
> 
> Ok, last try and then I put it at rest, promise...
> 
> My take is that we don't even need a "repeat_key" flag, we could simply use
> the existing seat->repeat_key for that, as 0 is not a valid value there.

Hi Olivier,

The last version attachment 351063 [details] [review] looks pretty ideal! (Excepting my somewhat verbose commit message...). It fixes all the test cases for this bug, as well as taking care of the original darktable issue which brought me to this.

With regards,
Dan
Comment 10 Olivier Fourdan 2017-06-01 12:47:24 UTC
Anyone to review  attachment 351063 [details] [review]? Carlos maybe?
Comment 11 Carlos Garnacho 2017-06-02 15:43:06 UTC
Comment on attachment 351063 [details] [review]
[PATCH v4] wayland: selectively cancel key repeat on key release

Makes sense, and looks simpler :). Please push to gtk-3-22 and master.
Comment 12 Olivier Fourdan 2017-06-02 17:19:42 UTC
Comment on attachment 351063 [details] [review]
[PATCH v4] wayland: selectively cancel key repeat on key release

attachment 351063 [details] [review] pushed to git master as commit a23ad61 - wayland: selectively cancel key repeat on key release

attachment 351063 [details] [review] pushed to branch gtk-3-22 as commit d9a9530 - wayland: selectively cancel key repeat on key release