[Bf-blender-cvs] [3be5859b219] master: Cleanup: pass keymap items as const where possible

Campbell Barton noreply at git.blender.org
Thu Feb 4 12:25:15 CET 2021


Commit: 3be5859b21950ed5f5949fce803cf8cbe68dcf99
Author: Campbell Barton
Date:   Thu Feb 4 21:53:58 2021 +1100
Branches: master
https://developer.blender.org/rB3be5859b21950ed5f5949fce803cf8cbe68dcf99

Cleanup: pass keymap items as const where possible

===================================================================

M	source/blender/editors/transform/transform_mode_edge_seq_slide.c
M	source/blender/editors/transform/transform_mode_shrink_fatten.c
M	source/blender/makesrna/intern/rna_wm_api.c
M	source/blender/windowmanager/WM_keymap.h
M	source/blender/windowmanager/intern/wm_keymap.c
M	source/blender/windowmanager/intern/wm_keymap_utils.c

===================================================================

diff --git a/source/blender/editors/transform/transform_mode_edge_seq_slide.c b/source/blender/editors/transform/transform_mode_edge_seq_slide.c
index 7ccfd0149bd..dd212af7caf 100644
--- a/source/blender/editors/transform/transform_mode_edge_seq_slide.c
+++ b/source/blender/editors/transform/transform_mode_edge_seq_slide.c
@@ -49,7 +49,7 @@
 static eRedrawFlag seq_slide_handleEvent(struct TransInfo *t, const wmEvent *event)
 {
   BLI_assert(t->mode == TFM_SEQ_SLIDE);
-  wmKeyMapItem *kmi = t->custom.mode.data;
+  const wmKeyMapItem *kmi = t->custom.mode.data;
   if (kmi && event->type == kmi->type && event->val == kmi->val) {
     /* Allows the 'Expand to fit' effect to be enabled as a toogle. */
     t->flag ^= T_ALT_TRANSFORM;
@@ -73,7 +73,7 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA
   ofs += BLI_snprintf(
       str + ofs, UI_MAX_DRAW_STR - ofs, TIP_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text);
 
-  wmKeyMapItem *kmi = t->custom.mode.data;
+  const wmKeyMapItem *kmi = t->custom.mode.data;
   if (kmi) {
     ofs += WM_keymap_item_to_string(kmi, false, str + ofs, UI_MAX_DRAW_STR - ofs);
   }
@@ -158,7 +158,7 @@ void initSeqSlide(TransInfo *t)
 
   if (t->keymap) {
     /* Workaround to use the same key as the modal keymap. */
-    t->custom.mode.data = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE);
+    t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE);
   }
 }
 /** \} */
diff --git a/source/blender/editors/transform/transform_mode_shrink_fatten.c b/source/blender/editors/transform/transform_mode_shrink_fatten.c
index 2a5c631df41..bccf4db66af 100644
--- a/source/blender/editors/transform/transform_mode_shrink_fatten.c
+++ b/source/blender/editors/transform/transform_mode_shrink_fatten.c
@@ -49,7 +49,7 @@
 static eRedrawFlag shrinkfatten_handleEvent(struct TransInfo *t, const wmEvent *event)
 {
   BLI_assert(t->mode == TFM_SHRINKFATTEN);
-  wmKeyMapItem *kmi = t->custom.mode.data;
+  const wmKeyMapItem *kmi = t->custom.mode.data;
   if (kmi && event->type == kmi->type && event->val == kmi->val) {
     /* Allows the 'Even Thickness' effect to be enabled as a toogle. */
     t->flag ^= T_ALT_TRANSFORM;
@@ -90,7 +90,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
   }
   ofs += BLI_strncpy_rlen(str + ofs, ", (", sizeof(str) - ofs);
 
-  wmKeyMapItem *kmi = t->custom.mode.data;
+  const wmKeyMapItem *kmi = t->custom.mode.data;
   if (kmi) {
     ofs += WM_keymap_item_to_string(kmi, false, str + ofs, sizeof(str) - ofs);
   }
@@ -150,7 +150,7 @@ void initShrinkFatten(TransInfo *t)
 
     if (t->keymap) {
       /* Workaround to use the same key as the modal keymap. */
-      t->custom.mode.data = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE);
+      t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE);
     }
   }
 }
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index 3ebcb09a65d..5541fe3053f 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -72,6 +72,12 @@ const EnumPropertyItem rna_enum_window_cursor_items[] = {
 
 #  include "WM_types.h"
 
+/* Needed since RNA doesn't use `const` in function signatures. */
+static bool rna_KeyMapItem_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2)
+{
+  return WM_keymap_item_compare(k1, k2);
+}
+
 static void rna_KeyMapItem_to_string(wmKeyMapItem *kmi, bool compact, char *result)
 {
   WM_keymap_item_to_string(kmi, compact, result, UI_MAX_SHORTCUT_STR);
@@ -1103,7 +1109,7 @@ void RNA_api_keymapitem(StructRNA *srna)
   FunctionRNA *func;
   PropertyRNA *parm;
 
-  func = RNA_def_function(srna, "compare", "WM_keymap_item_compare");
+  func = RNA_def_function(srna, "compare", "rna_KeyMapItem_compare");
   parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
   parm = RNA_def_boolean(func, "result", 0, "Comparison result", "");
diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h
index 15be21bdbc4..564afe084b9 100644
--- a/source/blender/windowmanager/WM_keymap.h
+++ b/source/blender/windowmanager/WM_keymap.h
@@ -59,7 +59,7 @@ wmKeyMapItem *WM_keymap_add_item(
 wmKeyMapItem *WM_keymap_add_item_copy(struct wmKeyMap *keymap, wmKeyMapItem *kmi_src);
 
 bool WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi);
-int WM_keymap_item_to_string(wmKeyMapItem *kmi,
+int WM_keymap_item_to_string(const wmKeyMapItem *kmi,
                              const bool compact,
                              char *result,
                              const int result_len);
@@ -86,7 +86,7 @@ bool WM_keymap_remove(struct wmKeyConfig *keyconfig, struct wmKeyMap *keymap);
 bool WM_keymap_poll(struct bContext *C, struct wmKeyMap *keymap);
 
 wmKeyMapItem *WM_keymap_item_find_id(struct wmKeyMap *keymap, int id);
-bool WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2);
+bool WM_keymap_item_compare(const struct wmKeyMapItem *k1, const struct wmKeyMapItem *k2);
 
 /* keymap_utils.c */
 
@@ -111,13 +111,13 @@ void WM_keymap_add_context_enum_set_items(wmKeyMap *keymap,
 wmKeyMap *WM_keymap_guess_from_context(const struct bContext *C);
 wmKeyMap *WM_keymap_guess_opname(const struct bContext *C, const char *opname);
 
-bool WM_keymap_uses_event_modifier(wmKeyMap *keymap, const int event_modifier);
+bool WM_keymap_uses_event_modifier(const wmKeyMap *keymap, const int event_modifier);
 
 void WM_keymap_fix_linking(void);
 
 /* Modal Keymap */
 
-int WM_modalkeymap_items_to_string(struct wmKeyMap *km,
+int WM_modalkeymap_items_to_string(const struct wmKeyMap *km,
                                    const int propvalue,
                                    const bool compact,
                                    char *result,
@@ -142,7 +142,7 @@ wmKeyMapItem *WM_modalkeymap_add_item(
     struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value);
 wmKeyMapItem *WM_modalkeymap_add_item_str(
     struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, const char *value);
-wmKeyMapItem *WM_modalkeymap_find_propvalue(wmKeyMap *km, const int propvalue);
+const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue);
 void WM_modalkeymap_assign(struct wmKeyMap *km, const char *opname);
 
 /* Keymap Editor */
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 8bfec0dc5c9..fcb13fff0a5 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -949,9 +949,9 @@ wmKeyMapItem *WM_modalkeymap_add_item_str(
   return kmi;
 }
 
-static wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(wmKeyMap *km,
-                                                        wmKeyMapItem *kmi,
-                                                        const int propvalue)
+static const wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(const wmKeyMap *km,
+                                                              const wmKeyMapItem *kmi,
+                                                              const int propvalue)
 {
   if (km->flag & KEYMAP_MODAL) {
     kmi = kmi ? kmi->next : km->items.first;
@@ -968,7 +968,7 @@ static wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(wmKeyMap *km,
   return NULL;
 }
 
-wmKeyMapItem *WM_modalkeymap_find_propvalue(wmKeyMap *km, const int propvalue)
+const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
 {
   return wm_modalkeymap_find_propvalue_iter(km, NULL, propvalue);
 }
@@ -1201,7 +1201,7 @@ int WM_keymap_item_raw_to_string(const short shift,
 #undef ADD_SEP
 }
 
-int WM_keymap_item_to_string(wmKeyMapItem *kmi,
+int WM_keymap_item_to_string(const wmKeyMapItem *kmi,
                              const bool compact,
                              char *result,
                              const int result_len)
@@ -1218,14 +1218,17 @@ int WM_keymap_item_to_string(wmKeyMapItem *kmi,
                                       result_len);
 }
 
-int WM_modalkeymap_items_to_string(
-    wmKeyMap *km, const int propvalue, const bool compact, char *result, const int result_len)
+int WM_modalkeymap_items_to_string(const wmKeyMap *km,
+                                   const int propvalue,
+                                   const bool compact,
+                                   char *result,
+                                   const int result_len)
 {
   int totlen = 0;
   bool add_sep = false;
 
   if (km) {
-    wmKeyMapItem *kmi;
+    const wmKeyMapItem *kmi;
 
     /* Find all shortcuts related to that propvalue! */
     for (kmi = WM_modalkeymap_find_propvalue(km, propvalue); kmi && totlen < (result_len - 2);
@@ -1654,7 +1657,7 @@ wmKeyMapItem *WM_key_event_operator_from_keymap(wmKeyMap *keymap,
       });
 }
 
-bool WM_keymap_item_compare(wmKeyMapItem *k1, wmKeyMapItem *k2)
+bool WM_keymap_item_compare(const wmKeyMapItem *k1, const wmKeyMapItem *k2)
 {
   if (k1->flag & KMI_INACTIVE || k2->flag & KMI_INACTIVE) {
     return 0;
diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.c b/source/blender/windowmanager/intern/wm_keymap_utils.c
index 953fb9fed79..865889e7e64 100644
--- a/source/blender/windowmanager/intern/wm_keymap_utils.c
+++ b/source/blender/windowmanager/intern/wm_keymap_utils.c
@@ -477,7 +477,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
   return km;
 }
 
-static bool wm_keymap_item_uses_modifier(wmKeyMapItem *kmi, const int event_modifier)
+static bool wm_keymap_item_uses_modifier(const wmKeyMapItem *kmi, const int event_modifier)
 {
   if (kmi->ctrl != KM_ANY) {
     if ((kmi->ctrl == KM_NOTHING) != ((event_modifier & KM_CTRL) == 0)) {
@@ -505,9 +505,9 @@ static bool wm_keymap_item_uses_modifier(wmKeyMapItem *kmi, const int event_modi
   return true;
 }
 
-bool WM_keymap_uses_event_modifier(wmKeyMap *keymap, const int event_modifier)
+bool WM_keymap_uses_event_modifier(const wmKeyMap *keymap, const int event_modifier)


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list