Page MenuHome

wayland: repeat key on key press and hold
AbandonedPublic

Authored by Christian Rauch (christian.rauch) on May 8 2020, 1:14 AM.

Details

Summary

This implements key repeats when a key is pressed and held.

The key repeating is implemented via a GHOST timer which is enabled by switching to non-blocking event processing. This in turn fixes animation issues such as https://developer.blender.org/T76720.

Diff Detail

Repository
rB Blender
Branch
key_repeat
Build Status
Buildable 8105
Build 8105: arc lint + arc unit

Event Timeline

Christian Rauch (christian.rauch) requested review of this revision.May 8 2020, 1:14 AM
Christian Rauch (christian.rauch) created this revision.
Christian Rauch (christian.rauch) retitled this revision from repeat key on key press and hold to wayland: repeat key on key press and hold.May 8 2020, 1:22 AM
Christian Rauch (christian.rauch) edited the summary of this revision. (Show Details)

mutex for event queue access

Christian Rauch (christian.rauch) edited the summary of this revision. (Show Details)

I added a mutex to the GHOST_EventManager to synchronise the access to the event queue. This solves the issue with the NULL access.

@Campbell Barton (campbellbarton) Can you have a look at this?

@Campbell Barton (campbellbarton) @Brecht Van Lommel (brecht) Can you have a look at this, especially since it introduces a mutex in the event handler?

Brecht Van Lommel (brecht) requested changes to this revision.EditedMay 12 2020, 4:05 PM

I don't think using multithreading here will work well. GHOST is not designed to support sending events from threads.

Care must also me taken to ensure events are passed in the right order, before/after other events. And to make sure the appropriate amount of events is sent even if the key up event is processed later than the actual time it happened. I think such events should somehow be generated in the same function that processes other events, checking elapsed timed.

EDIT: nevermind, I misread the code here, wl_keyboard_listener is used for getting repeat event info.

Still it may be useful to look at other implementations like https://github.com/glfw/glfw/pull/1210 that handle this without launching threads.

This revision now requires changes to proceed.May 12 2020, 4:05 PM

implement key repeat via timer

This is now implemented via a GHOST_TimerTask. For this, I also had to change to a non-blocking loop, which as a side effect solves the animation issue in https://developer.blender.org/T76720.

The most intrusive change is that I had to change the time source in GHOST from the CPU cycles spent in the process to a steady clock that accurately measures the time differences in real physical time.

Campbell Barton (campbellbarton) requested changes to this revision.May 14 2020, 10:30 AM
Campbell Barton (campbellbarton) added inline comments.
intern/ghost/intern/GHOST_SystemWayland.cpp
120–127

The way key repeat works (on X11 at least), is you only ever repeat the last key pressed.

If hold A, then B, the B key will repeat, however releasing B wont start repeating A.

So I don't see the need to store a timer per key, instead one timer can be used for the last repeat key pressed, every time a new key is pressed that can be reset.

This revision now requires changes to proceed.May 14 2020, 10:30 AM
Christian Rauch (christian.rauch) added inline comments.
intern/ghost/intern/GHOST_SystemWayland.cpp
120–127

This is intentional because the meaning of "key repeat" is that "a key is repeated until it is released". It does not account for other key states like "a key is repeated until an arbitrary key is released". I think the first interpretation is the correct one.

Also, it enables to toggle UI functionality in parallel (as far as parallelisation goes in GHOST), e.g. you can repeat O and T in parallel in the 3D Viewport and toggle the respective UI elements.

Would there be a drawback in Blender functionality when using this parallel key repeating?

@Campbell Barton (campbellbarton) Is this viable as is (independent key repeats) or do you need to have the X11 behaviour where only the last pressed key can repeat?

@Christian Rauch (christian.rauch) the way key repeat works both on X11, Wayland (Weston), and non-graphical text mode (I assume Windows and MacOS too) is to only repeat the last pressed key. This is what users will expect when typing.

I'd rather not introduce Wayland only keyboard behavior for now, and instead bring it to the same level as other platforms.

More advanced functionality can always be considered once basics are working.

I changed this back to a single timer that is reseted whenever a key, that can repeat, is pressed.

intern/ghost/intern/GHOST_SystemWayland.cpp
95–100

Renamed to key_repeat_keyload_t.

95–100

Edit key_repeat_payload_t