Keymaps: reload key configuration when changing select mouse.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 13 Nov 2018 18:02:12 +0000 (19:02 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 13 Nov 2018 18:29:13 +0000 (19:29 +0100)
For configuration scripts that want to change keymaps based on this setting.

source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/WM_keymap.h
source/blender/windowmanager/intern/wm.c
source/creator/creator.c

index abd35a3cc738865b9ed828b095763af1b34f56e8..e13847f24730c9dfd57a615f2655bca3361a6d62 100644 (file)
@@ -168,7 +168,7 @@ typedef struct wmWindowManager {
 /* wmWindowManager.initialized */
 enum {
        WM_WINDOW_IS_INITIALIZED = (1<<0),
-       WM_KEYMAP_IS_INITIALIZED = (1<<1),
+       WM_KEYCONFIG_IS_INITIALIZED = (1<<1),
 };
 
 /* IME is win32 only! */
index 1ea5c1644491b5d9428f8c7c8f0f42908270bc83..84258835b14aab90bcc4e62d9ef08679c890bd34 100644 (file)
@@ -222,6 +222,11 @@ static void rna_userdef_select_mouse_set(PointerRNA *ptr, int value)
                userdef->flag &= ~USER_LMOUSESELECT;
 }
 
+static void rna_userdef_select_mouse_update(bContext *C, Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+{
+       WM_keyconfig_reload(C);
+}
+
 static int rna_userdef_autokeymode_get(PointerRNA *ptr)
 {
        UserDef *userdef = (UserDef *)ptr->data;
@@ -4546,6 +4551,8 @@ static void rna_def_userdef_input(BlenderRNA *brna)
        RNA_def_property_enum_items(prop, select_mouse_items);
        RNA_def_property_enum_funcs(prop, NULL, "rna_userdef_select_mouse_set", NULL);
        RNA_def_property_ui_text(prop, "Select Mouse", "Mouse button used for selection");
+       RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+       RNA_def_property_update(prop, 0, "rna_userdef_select_mouse_update");
 
        prop = RNA_def_property(srna, "view_zoom_method", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "viewzoom");
index 71037ab162e3934d7849e8a9a4f92843dd7ebfc1..f93ef005b2a2261703b0e4d333a9711d4c638cc0 100644 (file)
@@ -42,6 +42,9 @@ struct EnumPropertyItem;
 
 /* Key Configuration */
 
+void           WM_keyconfig_init       (struct bContext *C);
+void           WM_keyconfig_reload     (struct bContext *C);
+
 wmKeyConfig *WM_keyconfig_new  (struct wmWindowManager *wm, const char *idname, bool user_defined);
 wmKeyConfig *WM_keyconfig_new_user(struct wmWindowManager *wm, const char *idname);
 bool        WM_keyconfig_remove        (struct wmWindowManager *wm, struct wmKeyConfig *keyconf);
@@ -56,7 +59,6 @@ void        WM_keyconfig_update_operatortype(void);
 
 /* Keymap */
 
-void           WM_keymap_init          (struct bContext *C);
 void           WM_keymap_clear         (struct wmKeyMap *keymap);
 
 wmKeyMapItem *WM_keymap_verify_item(
index bc9c1e263cbc23db050bccb3c441e19c0029aa11..29a1252cf4b590be544650842011a9c1ccb843f0 100644 (file)
@@ -225,7 +225,16 @@ void WM_operator_handlers_clear(wmWindowManager *wm, wmOperatorType *ot)
 
 /* ****************************************** */
 
-void WM_keymap_init(bContext *C)
+void WM_keyconfig_reload(bContext *C)
+{
+       if (CTX_py_init_get(C) && !G.background) {
+               BPY_execute_string(
+                       C, (const char *[]){"bpy", NULL},
+                       "bpy.utils.keyconfig_init()");
+       }
+}
+
+void WM_keyconfig_init(bContext *C)
 {
        wmWindowManager *wm = CTX_wm_manager(C);
 
@@ -239,16 +248,14 @@ void WM_keymap_init(bContext *C)
 
        /* initialize only after python init is done, for keymaps that
         * use python operators */
-       if (CTX_py_init_get(C) && (wm->initialized & WM_KEYMAP_IS_INITIALIZED) == 0) {
+       if (CTX_py_init_get(C) && (wm->initialized & WM_KEYCONFIG_IS_INITIALIZED) == 0) {
                /* create default key config, only initialize once,
                 * it's persistent across sessions */
                if (!(wm->defaultconf->flag & KEYCONF_INIT_DEFAULT)) {
                        wm_window_keymap(wm->defaultconf);
                        ED_spacetypes_keymap(wm->defaultconf);
 
-                       BPY_execute_string(
-                               C, (const char *[]){"bpy", NULL},
-                               "bpy.utils.keyconfig_init()");
+                       WM_keyconfig_reload(C);
 
                        wm->defaultconf->flag |= KEYCONF_INIT_DEFAULT;
                }
@@ -256,7 +263,7 @@ void WM_keymap_init(bContext *C)
                WM_keyconfig_update_tag(NULL, NULL);
                WM_keyconfig_update(wm);
 
-               wm->initialized |= WM_KEYMAP_IS_INITIALIZED;
+               wm->initialized |= WM_KEYCONFIG_IS_INITIALIZED;
        }
 }
 
@@ -278,7 +285,7 @@ void WM_check(bContext *C)
        if (!G.background) {
                /* case: fileread */
                if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) {
-                       WM_keymap_init(C);
+                       WM_keyconfig_init(C);
                        WM_autosave_init(wm);
                }
 
index 3cd3e2986f98e51fd7a28186bf8203b4b34cce4c..5bc266427d5a0922429f84bd3e60c53d9fbee92c 100644 (file)
@@ -465,7 +465,7 @@ int main(
 #endif
 
        CTX_py_init_set(C, 1);
-       WM_keymap_init(C);
+       WM_keyconfig_init(C);
 
        /* Called on load, however Python is not yet initialized, so call again here. */
        if (!G.background) {