diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-03-06 09:24:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-03-06 09:31:28 +0300 |
commit | 5be0e3430d13341feddee739997130239daf71d5 (patch) | |
tree | b8af4c1d47d40425d0703883f8efdc0c297e37ea /source/blender/makesrna | |
parent | 73ef27f15611ccb254816e199f8c74103b3d5172 (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/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 25 |
2 files changed, 38 insertions, 5 deletions
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); |