[Bf-blender-cvs] [06ac655b8dd] master: WM: expose the "any" state of KeyMapItem modifiers
Campbell Barton
noreply at git.blender.org
Fri Sep 17 08:54:41 CEST 2021
Commit: 06ac655b8dda53aa2122844d487ed68510211395
Author: Campbell Barton
Date: Thu Sep 16 23:20:57 2021 +1000
Branches: master
https://developer.blender.org/rB06ac655b8dda53aa2122844d487ed68510211395
WM: expose the "any" state of KeyMapItem modifiers
Change KeyMapItem.alt/ctrl/shift/oskey to integer types,
where -1 is used to ignore the modifier when matching key-map items.
It was only possible to set all modifiers to -1 at once from RNA
using the 'any' property.
Afterwards individual modifiers could be set back to true/false.
Although these key-map items could not be exported/imported.
Exposing the values directly avoids the need for cumbersome workarounds.
===================================================================
M release/scripts/modules/bl_keymap_utils/io.py
M release/scripts/modules/rna_keymap_ui.py
M source/blender/editors/interface/interface_layout.c
M source/blender/makesrna/intern/rna_wm.c
M source/blender/makesrna/intern/rna_wm_api.c
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_keymap.c
===================================================================
diff --git a/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py
index 96832cbd9c7..d8b68822feb 100644
--- a/release/scripts/modules/bl_keymap_utils/io.py
+++ b/release/scripts/modules/bl_keymap_utils/io.py
@@ -63,16 +63,11 @@ def kmi_args_as_data(kmi):
if kmi.any:
s.append("\"any\": True")
else:
- if kmi.shift:
- s.append("\"shift\": True")
- if kmi.ctrl:
- s.append("\"ctrl\": True")
- if kmi.alt:
- s.append("\"alt\": True")
- if kmi.oskey:
- s.append("\"oskey\": True")
- if kmi.key_modifier and kmi.key_modifier != 'NONE':
- s.append(f"\"key_modifier\": '{kmi.key_modifier}'")
+ for attr in ("shift", "ctrl", "alt", "oskey"):
+ if mod := getattr(kmi, attr):
+ s.append(f"\"{attr:s}\": " + ("-1" if mod == -1 else "True"))
+ if (mod := kmi.key_modifier) and (mod != 'NONE'):
+ s.append(f"\"key_modifier\": '{mod:s}'")
if kmi.repeat:
if (
diff --git a/release/scripts/modules/rna_keymap_ui.py b/release/scripts/modules/rna_keymap_ui.py
index b42539ac44a..08035d25481 100644
--- a/release/scripts/modules/rna_keymap_ui.py
+++ b/release/scripts/modules/rna_keymap_ui.py
@@ -199,10 +199,12 @@ def draw_kmi(display_keymaps, kc, km, kmi, layout, level):
subrow = sub.row()
subrow.scale_x = 0.75
subrow.prop(kmi, "any", toggle=True)
- subrow.prop(kmi, "shift", toggle=True)
- subrow.prop(kmi, "ctrl", toggle=True)
- subrow.prop(kmi, "alt", toggle=True)
- subrow.prop(kmi, "oskey", text="Cmd", toggle=True)
+ # Use `*_ui` properties as integers aren't practical.
+ subrow.prop(kmi, "shift_ui", toggle=True)
+ subrow.prop(kmi, "ctrl_ui", toggle=True)
+ subrow.prop(kmi, "alt_ui", toggle=True)
+ subrow.prop(kmi, "oskey_ui", text="Cmd", toggle=True)
+
subrow.prop(kmi, "key_modifier", text="", event=True)
# Operator properties
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index ec5a30f7793..66c75c63050 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -921,10 +921,10 @@ static void ui_keymap_but_cb(bContext *UNUSED(C), void *but_v, void *UNUSED(key_
{
uiBut *but = but_v;
- RNA_boolean_set(&but->rnapoin, "shift", (but->modifier_key & KM_SHIFT) != 0);
- RNA_boolean_set(&but->rnapoin, "ctrl", (but->modifier_key & KM_CTRL) != 0);
- RNA_boolean_set(&but->rnapoin, "alt", (but->modifier_key & KM_ALT) != 0);
- RNA_boolean_set(&but->rnapoin, "oskey", (but->modifier_key & KM_OSKEY) != 0);
+ RNA_int_set(&but->rnapoin, "shift", (but->modifier_key & KM_SHIFT) ? KM_MOD_HELD : KM_NOTHING);
+ RNA_int_set(&but->rnapoin, "ctrl", (but->modifier_key & KM_CTRL) ? KM_MOD_HELD : KM_NOTHING);
+ RNA_int_set(&but->rnapoin, "alt", (but->modifier_key & KM_ALT) ? KM_MOD_HELD : KM_NOTHING);
+ RNA_int_set(&but->rnapoin, "oskey", (but->modifier_key & KM_OSKEY) ? KM_MOD_HELD : KM_NOTHING);
}
/**
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 31fdbf528bb..c2d1ac67675 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -440,8 +440,7 @@ const EnumPropertyItem rna_enum_event_type_mask_items[] = {
static const EnumPropertyItem keymap_modifiers_items[] = {
{KM_ANY, "ANY", 0, "Any", ""},
{0, "NONE", 0, "None", ""},
- {1, "FIRST", 0, "First", ""},
- {2, "SECOND", 0, "Second", ""},
+ {KM_MOD_HELD, "HELD", 0, "Held", ""},
{0, NULL, 0, NULL, NULL},
};
#endif
@@ -2732,38 +2731,62 @@ static void rna_def_keyconfig(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Any", "Any modifier keys pressed");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
- prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
+ prop = RNA_def_property(srna, "shift", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "shift");
+ RNA_def_property_range(prop, KM_ANY, KM_MOD_HELD);
+ RNA_def_property_ui_text(prop, "Shift", "Shift key pressed, -1 for any state");
+ RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER);
+ RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+
+ prop = RNA_def_property(srna, "ctrl", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "ctrl");
+ RNA_def_property_range(prop, KM_ANY, KM_MOD_HELD);
+ RNA_def_property_ui_text(prop, "Ctrl", "Control key pressed, -1 for any state");
+ RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+
+ prop = RNA_def_property(srna, "alt", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "alt");
+ RNA_def_property_range(prop, KM_ANY, KM_MOD_HELD);
+ RNA_def_property_ui_text(prop, "Alt", "Alt key pressed, -1 for any state");
+ RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+
+ prop = RNA_def_property(srna, "oskey", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "oskey");
+ RNA_def_property_range(prop, KM_ANY, KM_MOD_HELD);
+ RNA_def_property_ui_text(prop, "OS Key", "Operating system key pressed, -1 for any state");
+ RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+
+ /* XXX(@campbellbarton): the `*_ui` suffix is only for the UI, may be removed,
+ * since this is only exposed so the UI can show these settings as toggle-buttons. */
+ prop = RNA_def_property(srna, "shift_ui", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "shift", 0);
RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_shift_get", NULL);
- /* RNA_def_property_enum_sdna(prop, NULL, "shift"); */
/* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
RNA_def_property_ui_text(prop, "Shift", "Shift key pressed");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER);
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
- prop = RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
+ prop = RNA_def_property(srna, "ctrl_ui", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 0);
RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_ctrl_get", NULL);
- /* RNA_def_property_enum_sdna(prop, NULL, "ctrl"); */
/* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
RNA_def_property_ui_text(prop, "Ctrl", "Control key pressed");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
- prop = RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
+ prop = RNA_def_property(srna, "alt_ui", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "alt", 0);
RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_alt_get", NULL);
- /* RNA_def_property_enum_sdna(prop, NULL, "alt"); */
/* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
RNA_def_property_ui_text(prop, "Alt", "Alt key pressed");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
- prop = RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
+ prop = RNA_def_property(srna, "oskey_ui", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "oskey", 0);
RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_oskey_get", NULL);
- /* RNA_def_property_enum_sdna(prop, NULL, "oskey"); */
/* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
RNA_def_property_ui_text(prop, "OS Key", "Operating system key pressed");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+ /* End `_ui` modifiers. */
prop = RNA_def_property(srna, "key_modifier", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "keymodifier");
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index 79cc689c6c2..7c3b119abb9 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -39,6 +39,8 @@
#include "wm_cursors.h"
#include "wm_event_types.h"
+#include "WM_types.h"
+
#include "rna_internal.h" /* own include */
/* confusing 2 enums mixed up here */
@@ -216,49 +218,70 @@ static int rna_Operator_props_popup(bContext *C, wmOperator *op, wmEvent *event)
return WM_operator_props_popup(C, op, event);
}
+static int keymap_item_modifier_flag_from_args(bool any, int shift, int ctrl, int alt, int oskey)
+{
+ int modifier = 0;
+ if (any) {
+ modifier = KM_ANY;
+ }
+ else {
+ if (shift == KM_MOD_HELD) {
+ modifier |= KM_SHIFT;
+ }
+ else if (shift == KM_ANY) {
+ modifier |= KM_SHIFT_ANY;
+ }
+
+ if (ctrl == KM_MOD_HELD) {
+ modifier |= KM_CTRL;
+ }
+ else if (ctrl == KM_ANY) {
+ modifier |= KM_CTRL_ANY;
+ }
+
+ if (alt == KM_MOD_HELD) {
+ modifier |= KM_ALT;
+ }
+ else if (alt == KM_ANY) {
+ modifier |= KM_ALT_ANY;
+ }
+
+ if (oskey == KM_MOD_HELD) {
+ modifier |= KM_OSKEY;
+ }
+ else if (oskey == KM_ANY) {
+ modifier |= KM_OSKEY_ANY;
+ }
+ }
+ return modifier;
+}
+
static wmKeyMapItem *rna_KeyMap_item_new(wmKeyMap *km,
ReportList *reports,
const char *idname,
int type,
int value,
bool any,
- bool shift,
- bool ctrl,
- bool alt,
- bool oskey,
+ int shift,
+ int ctrl,
+ int alt,
+ int oskey,
int keymodifier,
bool repeat,
bool head)
{
- // wmWindowManager *wm = CTX_wm_manager(C);
- wmKeyMapItem *kmi = NULL;
- c
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list