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/makesrna/intern/rna_wm_api.c
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/makesrna/intern/rna_wm_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c25
1 files changed, 20 insertions, 5 deletions
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);