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
path: root/source
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
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')
-rw-r--r--source/blender/makesdna/DNA_windowmanager_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_wm.c18
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c25
-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
6 files changed, 55 insertions, 7 deletions
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 491b481d001..1eaf3777d0a 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -370,6 +370,7 @@ enum {
KMI_EXPANDED = (1 << 1),
KMI_USER_MODIFIED = (1 << 2),
KMI_UPDATE = (1 << 3),
+ KMI_REPEAT_IGNORE = (1 << 4),
};
/** #wmKeyMapItem.maptype */
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index bf3c562f95f..929540f10ac 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -652,6 +652,12 @@ static int rna_Event_unicode_length(PointerRNA *ptr)
}
}
+static bool rna_Event_is_repeat_get(PointerRNA *ptr)
+{
+ const wmEvent *event = ptr->data;
+ return event->is_repeat;
+}
+
static float rna_Event_pressure_get(PointerRNA *ptr)
{
const wmEvent *event = ptr->data;
@@ -2131,6 +2137,12 @@ static void rna_def_event(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Type", "");
+ /* keyboard */
+ prop = RNA_def_property(srna, "is_repeat", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_Event_is_repeat_get", NULL);
+ RNA_def_property_ui_text(prop, "Is Repeat", "The event is generated by holding a key down");
+
/* mouse */
prop = RNA_def_property(srna, "mouse_x", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "x");
@@ -2728,6 +2740,12 @@ static void rna_def_keyconfig(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Key Modifier", "Regular key pressed as a modifier");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+ prop = RNA_def_property(srna, "repeat", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", KMI_REPEAT_IGNORE);
+ RNA_def_property_ui_text(prop, "Repeat", "Active on key-repeat events (when a key is held)");
+ RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+
prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_EXPANDED);
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index c7a187e47b3..98e2f0c993d 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -216,6 +216,7 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
bool alt,
bool oskey,
int keymodifier,
+ bool repeat,
bool head)
{
/* wmWindowManager *wm = CTX_wm_manager(C); */
@@ -251,6 +252,10 @@ static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
/* create keymap item */
kmi = WM_keymap_add_item(km, idname_bl, type, value, modifier, keymodifier);
+ if (!repeat) {
+ kmi->flag |= KMI_REPEAT_IGNORE;
+ }
+
/* [#32437] allow scripts to define hotkeys that get added to start of keymap
* so that they stand a chance against catch-all defines later on
*/
@@ -293,8 +298,10 @@ static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km,
bool ctrl,
bool alt,
bool oskey,
- int keymodifier)
+ int keymodifier,
+ bool repeat)
{
+ wmKeyMapItem *kmi = NULL;
int modifier = 0;
int propvalue = 0;
@@ -323,14 +330,20 @@ static wmKeyMapItem *rna_KeyMap_item_new_modal(wmKeyMap *km,
/* not initialized yet, do delayed lookup */
if (!km->modal_items) {
- return WM_modalkeymap_add_item_str(km, type, value, modifier, keymodifier, propvalue_str);
+ kmi = WM_modalkeymap_add_item_str(km, type, value, modifier, keymodifier, propvalue_str);
+ }
+ else {
+ if (RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue) == 0) {
+ BKE_report(reports, RPT_WARNING, "Property value not in enumeration");
+ }
+ kmi = WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue);
}
- if (RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue) == 0) {
- BKE_report(reports, RPT_WARNING, "Property value not in enumeration");
+ if (!repeat) {
+ kmi->flag |= KMI_REPEAT_IGNORE;
}
- return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue);
+ return kmi;
}
static void rna_KeyMap_item_remove(wmKeyMap *km, ReportList *reports, PointerRNA *kmi_ptr)
@@ -1083,6 +1096,7 @@ void RNA_api_keymapitems(StructRNA *srna)
RNA_def_boolean(func, "alt", 0, "Alt", "");
RNA_def_boolean(func, "oskey", 0, "OS Key", "");
RNA_def_enum(func, "key_modifier", rna_enum_event_type_items, 0, "Key Modifier", "");
+ RNA_def_boolean(func, "repeat", true, "Repeat", "When set, accept key-repeat events");
RNA_def_boolean(func,
"head",
0,
@@ -1106,6 +1120,7 @@ void RNA_api_keymapitems(StructRNA *srna)
RNA_def_boolean(func, "alt", 0, "Alt", "");
RNA_def_boolean(func, "oskey", 0, "OS Key", "");
RNA_def_enum(func, "key_modifier", rna_enum_event_type_items, 0, "Key Modifier", "");
+ RNA_def_boolean(func, "repeat", true, "Repeat", "When set, accept key-repeat events");
parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item");
RNA_def_function_return(func, parm);
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);
}