Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-03-06 09:24:12 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-03-06 09:31:28 +0300
commit5be0e3430d13341feddee739997130239daf71d5 (patch)
treeb8af4c1d47d40425d0703883f8efdc0c297e37ea /source/blender/windowmanager
parent73ef27f15611ccb254816e199f8c74103b3d5172 (diff)
GHOST/Keymap: support for detecting repeat events
- Keymap items now have 'repeat' boolean which can be set to make keymap items respond to key repeat events or not. - Support for X11 & WIN32 (not macOS currently). This allows for the possibility to perform actions while a key is held and finish the action upon release. Thanks to @Severin for review and WIN32 support.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_types.h4
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c9
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c5
3 files changed, 16 insertions, 2 deletions
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index d5853045091..2038871844f 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -540,7 +540,9 @@ typedef struct wmEvent {
char utf8_buf[6];
/** From ghost, fallback if utf8 isn't set. */
char ascii;
- char pad;
+
+ /** Generated by auto-repeat. */
+ char is_repeat;
/** Previous state, used for double click and the 'click'. */
short prevtype;
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index b36d8f69886..c1bfa904fad 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1772,6 +1772,12 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
return false;
}
+ if (winevent->is_repeat) {
+ if (kmi->flag & KMI_REPEAT_IGNORE) {
+ return false;
+ }
+ }
+
const int kmitype = WM_userdef_event_map(kmi->type);
/* the matching rules */
@@ -4254,6 +4260,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
/* initialize and copy state (only mouse x y and modifiers) */
event = *evt;
+ event.is_repeat = false;
switch (type) {
/* mouse move, also to inactive window (X11 does this) */
@@ -4407,6 +4414,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
event.ascii = kd->ascii;
memcpy(
event.utf8_buf, kd->utf8_buf, sizeof(event.utf8_buf)); /* might be not null terminated*/
+ event.is_repeat = kd->is_repeat;
event.val = (type == GHOST_kEventKeyDown) ? KM_PRESS : KM_RELEASE;
wm_eventemulation(&event, false);
@@ -4418,6 +4426,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
/* copy to event state */
evt->val = event.val;
evt->type = event.type;
+ evt->is_repeat = event.is_repeat;
/* exclude arrow keys, esc, etc from text input */
if (type == GHOST_kEventKeyUp) {
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 68a12fa4272..bbe685b56cb 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -180,7 +180,9 @@ static bool wm_keymap_item_equals(wmKeyMapItem *a, wmKeyMapItem *b)
{
return (wm_keymap_item_equals_result(a, b) && a->type == b->type && a->val == b->val &&
a->shift == b->shift && a->ctrl == b->ctrl && a->alt == b->alt && a->oskey == b->oskey &&
- a->keymodifier == b->keymodifier && a->maptype == b->maptype);
+ a->keymodifier == b->keymodifier && a->maptype == b->maptype &&
+ ((ISKEYBOARD(a->type) == 0) ||
+ (a->flag & KMI_REPEAT_IGNORE) == (b->flag & KMI_REPEAT_IGNORE)));
}
/* properties can be NULL, otherwise the arg passed is used and ownership is given to the kmi */
@@ -2012,6 +2014,7 @@ void WM_keymap_item_restore_to_default(bContext *C, wmKeyMap *keymap, wmKeyMapIt
kmi->oskey = orig->oskey;
kmi->keymodifier = orig->keymodifier;
kmi->maptype = orig->maptype;
+ kmi->flag = (kmi->flag & ~KMI_REPEAT_IGNORE) | (orig->flag & KMI_REPEAT_IGNORE);
WM_keyconfig_update_tag(keymap, kmi);
}