Page MenuHome

Event system & keymap support for key detecting/ignoring key repeat events
AbandonedPublic

Authored by Campbell Barton (campbellbarton) on Jun 30 2019, 8:14 AM.

Details

Summary

This patch adds is_repeat member to an event and an option for key-map items to handle repeat events.

The keymap author can choose if they want press events to activate when the key is held (this patch enables for text editing and frame changes, otherwise repeat events aren't acted on).

This resolves T40537: Holding down "R" causes rapid switching between rotate and trackball rotate.

Notes

  • Not proposing this for 2.80.
  • Currently only X11 is supported.
  • Uses ghost to track of the last held key which has auto-repeat enabled (using XKB when supported).
  • This isn't fool proof, once a non-blender window is active we can't tell the key state. Currently the held key is cleared when the window is activated.

Diff Detail

Repository
rB Blender
Branch
TEMP-EVENT-KEY-REPEAT-SUPPORT (branched from master)
Build Status
Buildable 4137
Build 4137: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) retitled this revision from Event system & keymap support for key repeat events to Event system & keymap support for key detecting/ignoring key repeat events.Jun 30 2019, 8:32 AM
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
  • Add Event.is_repeat to RNA
  • Use ghost to detect key repeat events
  • Clear keys when a window is activated
  • Use xkb, remove use of set to stored held keys
  • Merge branch 'master' into arcpatch-D5153 (withouth this I got an ASan crash on startup)
  • Fix changing "Repeat" in keymap item through Preferences not working
  • Fix resetting key map item not resetting "Repeat" property
Julian Eisel (Severin) requested changes to this revision.Sep 30 2019, 5:12 PM

First off, sorry for taking so long to check on this. I actually did check earlier and noticed the following issue with the prefs which I wanted to investigate, but then the file browser stuff got in the way...

  • Noticed that changing the repeat property through the prefs doesn't do anything. Fixed the keymap side of this, but there are some further issues making this fail (see following).
  • The XKB implementation seems to always allow key repeat events on arrow keys, space bar, etc. Not too sure what the rationale behind that is and if that's the behavior we want too.
    • As a result, for a good amount of keymap items, the repeat property doesn't have an effect. E.g. text cursor move items. I don't have a strong opinion on if that's fine, but should be checked on.
  • I guess the industry compatible keymap should be updated too?

Just to test my fixes, you can use the backspace text.delete item, that works despite the XKB issue.

Also, do you have plans to check on other distros?

source/blender/editors/transform/transform.c
1373

Hmm, would be nice if this could actually respect the keymap item property, would have to look into how simple/complicated that is though.

This revision now requires changes to proceed.Sep 30 2019, 5:12 PM
  • Fix bitfield array check.
  • Fix clearing repeat when non-repeat key released.

Tested quickly, works fine now :)

The only thing stopping me from accepting it is that it's unclear what the plans for other OSes are. I could look into the Win32 implementation myself, but it'll have to wait a few days then.

For other OS's we could do something we have in the X11 under the comment:

/* No XKB support (filter by modifier). */

If they don't have the repeat information available, although ideally we could access this information.

  • Fix compile errors when building with SDL, NDOF or on macOS
  • Add Windows support

On Windows we don't actually get repeat events for modifier keys, so we don't need to do any manual filtering. Character keys, arrow keys and the like work fine (i.e. send repeat events).
In older Win32 APIs, keyboard messages contain a flag for repeat events (see https://docs.microsoft.com/en-us/windows/win32/learnwin32/keyboard-input#key-down-and-key-up-messages). This is not the case for the WM_INPUT message API we use, so we have to keep track of repeat events ourselves. That is of course easily done, although it has the same issue with activating windows as Linux.

I guess macOS support is a TODO. But I'm fine with committing this.

This revision is now accepted and ready to land.Mar 4 2020, 7:23 PM
Campbell Barton (campbellbarton) abandoned this revision.EditedMar 16 2020, 1:10 AM

Note that I ended up changing the flag to be off by default so as not to interfere with existing keymaps.

Committed rB5be0e3430d13341feddee739997130239daf71d5 closing.