Blender V4.5
wm_keymap.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstring>
12#include <fmt/format.h>
13
14#include "DNA_screen_types.h"
15#include "DNA_space_types.h"
16#include "DNA_userdef_types.h"
18#include "DNA_workspace_types.h"
19
20#include "CLG_log.h"
21#include "MEM_guardedalloc.h"
22
23#include "BLI_listbase.h"
24#include "BLI_string.h"
25#include "BLI_string_utf8.h"
26#include "BLI_utildefines.h"
27
28#include "BLF_api.hh"
29
30#include "UI_interface.hh"
31
32#include "BKE_context.hh"
33#include "BKE_global.hh"
34#include "BKE_idprop.hh"
35#include "BKE_main.hh"
36#include "BKE_report.hh"
37#include "BKE_screen.hh"
38#include "BKE_workspace.hh"
39
40#include "BLT_translation.hh"
41
42#include "RNA_access.hh"
43#include "RNA_enum_types.hh"
44
45#include "WM_api.hh"
46#include "WM_keymap.hh"
47#include "WM_types.hh"
48#include "wm_event_system.hh"
49#include "wm_event_types.hh"
50
51#include "ED_screen.hh"
52
54 bool (*filter_fn)(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data);
55 void *user_data;
56};
57
58/* -------------------------------------------------------------------- */
63
65{
66 wmKeyMapItem *kmin = static_cast<wmKeyMapItem *>(MEM_dupallocN(kmi));
67
68 kmin->prev = kmin->next = nullptr;
69 kmin->flag &= ~KMI_UPDATE;
70
71 if (kmin->properties) {
72 kmin->ptr = MEM_new<PointerRNA>("UserKeyMapItemPtr");
74
75 /* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
76 kmin->ptr->owner_id = nullptr;
77
79 kmin->ptr->data = kmin->properties;
80 }
81 else {
82 kmin->properties = nullptr;
83 kmin->ptr = nullptr;
84 }
85
86 return kmin;
87}
88
90{
91 /* Not the `kmi` itself. */
92 if (kmi->ptr) {
94 MEM_delete(kmi->ptr);
95 kmi->ptr = nullptr;
96 kmi->properties = nullptr;
97 }
98 else if (kmi->properties) {
100 kmi->properties = nullptr;
101 }
102}
103
105{
106 IDProperty *properties = kmi->properties;
107 kmi->properties = nullptr;
108 if (kmi->ptr) {
109 kmi->ptr->data = nullptr;
110 }
112 kmi->properties = properties;
113}
114
116{
117 WM_operator_properties_alloc(&(kmi->ptr), &(kmi->properties), kmi->idname);
119
120 /* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
121 kmi->ptr->owner_id = nullptr;
122}
123
128static void wm_keymap_item_properties_update_ot(wmKeyMapItem *kmi, const bool keep_properties)
129{
130 if (kmi->idname[0] == 0) {
131 BLI_assert(kmi->ptr == nullptr);
132 return;
133 }
134
135 if (kmi->ptr == nullptr) {
137 }
138 else {
140 if (ot) {
141 if (ot->srna != kmi->ptr->type) {
142 /* Matches #wm_keymap_item_properties_set but doesn't alloc new ptr. */
144 /* 'kmi->ptr->data' nullptr'd above, keep using existing properties.
145 * NOTE: the operators property types may have changed,
146 * we will need a more comprehensive sanitize function to support this properly.
147 */
148 if (kmi->properties) {
149 kmi->ptr->data = kmi->properties;
150 }
152
153 /* Signal for no context, see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
154 kmi->ptr->owner_id = nullptr;
155 }
156 }
157 else {
158 /* Zombie key-map item. */
159 if (keep_properties) {
161 }
162 else {
164 }
165 }
166 }
167}
168
170 const bool keep_properties)
171{
172 LISTBASE_FOREACH (wmKeyMap *, km, km_lb) {
173 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
174 wm_keymap_item_properties_update_ot(kmi, keep_properties);
175 }
176
177 LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) {
178 if (kmdi->add_item) {
179 wm_keymap_item_properties_update_ot(kmdi->add_item, keep_properties);
180 }
181 if (kmdi->remove_item) {
182 wm_keymap_item_properties_update_ot(kmdi->remove_item, keep_properties);
183 }
184 }
185 }
186}
187
189{
190 return (STREQ(a->idname, b->idname) &&
191 /* We do not really care about which Main we pass here, TBH. */
193 (a->flag & KMI_INACTIVE) == (b->flag & KMI_INACTIVE) && a->propvalue == b->propvalue);
194}
195
197{
198 return (wm_keymap_item_equals_result(a, b) && a->type == b->type && a->val == b->val &&
199 a->shift == b->shift && a->ctrl == b->ctrl && a->alt == b->alt && a->oskey == b->oskey &&
200 a->hyper == b->hyper && a->keymodifier == b->keymodifier && a->maptype == b->maptype &&
201 ((a->val != KM_CLICK_DRAG) || (a->direction == b->direction)) &&
202 ((ISKEYBOARD(a->type) == 0) ||
203 (a->flag & KMI_REPEAT_IGNORE) == (b->flag & KMI_REPEAT_IGNORE)));
204}
205
207{
208 if (LIKELY(kmi->ptr)) {
210 MEM_delete(kmi->ptr);
211
212 kmi->ptr = nullptr;
213 }
214 else if (kmi->properties) {
216 }
217
218 kmi->properties = properties;
219
221}
222
224{
225 if (ISTIMER(kmi->type)) {
226 return KMI_TYPE_TIMER;
227 }
228 if (ISKEYBOARD(kmi->type)) {
229 return KMI_TYPE_KEYBOARD;
230 }
231 if (ISMOUSE(kmi->type)) {
232 return KMI_TYPE_MOUSE;
233 }
234 if (ISNDOF(kmi->type)) {
235 return KMI_TYPE_NDOF;
236 }
237 if (kmi->type == KM_TEXTINPUT) {
238 return KMI_TYPE_TEXTINPUT;
239 }
240 if (ELEM(kmi->type, TABLET_STYLUS, TABLET_ERASER)) {
241 return KMI_TYPE_MOUSE;
242 }
243 return KMI_TYPE_KEYBOARD;
244}
245
247
248/* -------------------------------------------------------------------- */
253
255{
256 wmKeyMapDiffItem *kmdin = static_cast<wmKeyMapDiffItem *>(MEM_dupallocN(kmdi));
257
258 kmdin->next = kmdin->prev = nullptr;
259 if (kmdi->add_item) {
260 kmdin->add_item = wm_keymap_item_copy(kmdi->add_item);
261 }
262 if (kmdi->remove_item) {
264 }
265
266 return kmdin;
267}
268
270{
271 if (kmdi->remove_item) {
273 MEM_freeN(kmdi->remove_item);
274 }
275 if (kmdi->add_item) {
277 MEM_freeN(kmdi->add_item);
278 }
279}
280
282
283/* -------------------------------------------------------------------- */
290
291wmKeyConfig *WM_keyconfig_new(wmWindowManager *wm, const char *idname, bool user_defined)
292{
293 BLI_assert(!BLI_findstring(&wm->keyconfigs, idname, offsetof(wmKeyConfig, idname)));
294 /* Create new configuration. */
295 wmKeyConfig *keyconf = MEM_callocN<wmKeyConfig>("wmKeyConfig");
296 STRNCPY_UTF8(keyconf->idname, idname);
297 BLI_addtail(&wm->keyconfigs, keyconf);
298
299 if (user_defined) {
300 keyconf->flag |= KEYCONF_USER;
301 }
302
303 return keyconf;
304}
305
306wmKeyConfig *WM_keyconfig_ensure(wmWindowManager *wm, const char *idname, bool user_defined)
307{
308 wmKeyConfig *keyconf = static_cast<wmKeyConfig *>(
309 BLI_findstring(&wm->keyconfigs, idname, offsetof(wmKeyConfig, idname)));
310 if (keyconf) {
311 if (keyconf == wm->defaultconf) {
312 /* For default configuration, we need to keep keymap
313 * modal items and poll functions intact. */
314 LISTBASE_FOREACH (wmKeyMap *, km, &keyconf->keymaps) {
315 WM_keymap_clear(km);
316 }
317 }
318 else {
319 /* For user defined key configuration, clear all keymaps. */
320 WM_keyconfig_clear(keyconf);
321 }
322
323 return keyconf;
324 }
325
326 return WM_keyconfig_new(wm, idname, user_defined);
327}
328
330{
331 BLI_assert(BLI_findindex(&wm->keyconfigs, keyconf) != -1);
332 if (STREQLEN(U.keyconfigstr, keyconf->idname, sizeof(U.keyconfigstr))) {
333 STRNCPY(U.keyconfigstr, wm->defaultconf->idname);
334 U.runtime.is_dirty = true;
335 WM_keyconfig_update_tag(nullptr, nullptr);
336 }
337
338 BLI_remlink(&wm->keyconfigs, keyconf);
339 WM_keyconfig_free(keyconf);
340
341 /* Clear pointers. */
342 wmKeyConfig **keyconf_arr_p[] = {WM_KEYCONFIG_ARRAY_P(wm)};
343 for (int i = 0; i < ARRAY_SIZE(keyconf_arr_p); i++) {
344 wmKeyConfig **kc_p = keyconf_arr_p[i];
345 if (*kc_p == keyconf) {
346 *kc_p = nullptr;
347 }
348 }
349}
350
352{
353 LISTBASE_FOREACH_MUTABLE (wmKeyMap *, km, &keyconf->keymaps) {
354 WM_keymap_clear(km);
355 MEM_freeN(km);
356 }
357
358 BLI_listbase_clear(&keyconf->keymaps);
359}
360
362{
363 WM_keyconfig_clear(keyconf);
364 MEM_freeN(keyconf);
365}
366
368{
369 wmKeyConfig *keyconf;
370
371 /* First try from preset. */
372 keyconf = static_cast<wmKeyConfig *>(
373 BLI_findstring(&wm->keyconfigs, U.keyconfigstr, offsetof(wmKeyConfig, idname)));
374 if (keyconf) {
375 return keyconf;
376 }
377
378 /* Otherwise use default. */
379 return wm->defaultconf;
380}
381
382void WM_keyconfig_set_active(wmWindowManager *wm, const char *idname)
383{
384 /* Setting a different key configuration as active:
385 * we ensure all is updated properly before and after making the change. */
386
388
389 STRNCPY(U.keyconfigstr, idname);
391 U.runtime.is_dirty = true;
392 }
393
394 WM_keyconfig_update_tag(nullptr, nullptr);
396}
397
399
400/* -------------------------------------------------------------------- */
405
406static wmKeyMap *wm_keymap_new(const char *idname, int spaceid, int regionid)
407{
408 wmKeyMap *km = MEM_callocN<wmKeyMap>("keymap list");
409
410 STRNCPY_UTF8(km->idname, idname);
411 km->spaceid = spaceid;
412 km->regionid = regionid;
413
414 {
415 const char *owner_id = RNA_struct_state_owner_get();
416 if (owner_id) {
417 STRNCPY(km->owner_id, owner_id);
418 }
419 }
420 return km;
421}
422
424{
425 wmKeyMap *keymapn = static_cast<wmKeyMap *>(MEM_dupallocN(keymap));
426
427 keymapn->modal_items = keymap->modal_items;
428 keymapn->poll = keymap->poll;
429 keymapn->poll_modal_item = keymap->poll_modal_item;
430 BLI_listbase_clear(&keymapn->items);
431 keymapn->flag &= ~(KEYMAP_UPDATE | KEYMAP_EXPANDED);
432
433 LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &keymap->diff_items) {
435 BLI_addtail(&keymapn->items, kmdi_new);
436 }
437
438 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
439 wmKeyMapItem *kmi_new = wm_keymap_item_copy(kmi);
440 BLI_addtail(&keymapn->items, kmi_new);
441 }
442
443 return keymapn;
444}
445
447{
450 MEM_freeN(kmdi);
451 }
452
453 LISTBASE_FOREACH_MUTABLE (wmKeyMapItem *, kmi, &keymap->items) {
455 MEM_freeN(kmi);
456 }
457
459 BLI_listbase_clear(&keymap->items);
460}
461
462void WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
463{
464 BLI_assert(BLI_findindex(&keyconf->keymaps, keymap) != -1);
465 WM_keymap_clear(keymap);
466 BLI_remlink(&keyconf->keymaps, keymap);
467 MEM_freeN(keymap);
468}
469
471{
472 /* If we're tagged, only use compatible. */
473 if (keymap->owner_id[0] != '\0') {
474 const WorkSpace *workspace = CTX_wm_workspace(C);
475 if (BKE_workspace_owner_id_check(workspace, keymap->owner_id) == false) {
476 return false;
477 }
478 }
479
480 if (UNLIKELY(BLI_listbase_is_empty(&keymap->items))) {
481 /* Empty key-maps may be missing more there may be a typo in the name.
482 * Warn early to avoid losing time investigating each case.
483 * When developing a customized Blender though you may want empty keymaps. */
484 if (!U.app_template[0] &&
485 /* Fallback key-maps may be intentionally empty, don't flood the output. */
486 !BLI_str_endswith(keymap->idname, " (fallback)") &&
487 /* This is an exception which may be empty.
488 * Longer term we might want a flag to indicate an empty key-map is intended. */
489 !STREQ(keymap->idname, "Node Tool: Tweak") &&
490 /* Another exception: Asset shelf keymap is meant for add-ons to use, it's empty by
491 * default. */
492 !STREQ(keymap->idname, "Asset Shelf"))
493 {
494 CLOG_WARN(WM_LOG_KEYMAPS, "empty keymap '%s'", keymap->idname);
495 }
496 }
497
498 if (keymap->poll != nullptr) {
499 return keymap->poll(C);
500 }
501 return true;
502}
503
504static bool wm_keymap_is_match(const wmKeyMap *km_a, const wmKeyMap *km_b)
505{
506 return ((km_a->spaceid == km_b->spaceid) && (km_a->regionid == km_b->regionid) &&
507 STREQ(km_a->idname, km_b->idname));
508}
509
511{
512 kmi->type = params->type;
513 kmi->val = params->value;
514 kmi->keymodifier = params->keymodifier;
515 kmi->direction = params->direction;
516
517 if (params->modifier == KM_ANY) {
518 kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = kmi->hyper = KM_ANY;
519 }
520 else {
521 const int8_t mod = params->modifier & 0xff;
522 const int8_t mod_any = KMI_PARAMS_MOD_FROM_ANY(params->modifier);
523
524 /* Only one of the flags should be set. */
525 BLI_assert((mod & mod_any) == 0);
526
527 kmi->shift = ((mod & KM_SHIFT) ? KM_MOD_HELD : ((mod_any & KM_SHIFT) ? KM_ANY : KM_NOTHING));
528 kmi->ctrl = ((mod & KM_CTRL) ? KM_MOD_HELD : ((mod_any & KM_CTRL) ? KM_ANY : KM_NOTHING));
529 kmi->alt = ((mod & KM_ALT) ? KM_MOD_HELD : ((mod_any & KM_ALT) ? KM_ANY : KM_NOTHING));
530 kmi->oskey = ((mod & KM_OSKEY) ? KM_MOD_HELD : ((mod_any & KM_OSKEY) ? KM_ANY : KM_NOTHING));
531 kmi->hyper = ((mod & KM_HYPER) ? KM_MOD_HELD : ((mod_any & KM_HYPER) ? KM_ANY : KM_NOTHING));
532 }
533}
534
535static void keymap_item_set_id(wmKeyMap *keymap, wmKeyMapItem *kmi)
536{
537 keymap->kmi_id++;
538 if ((keymap->flag & KEYMAP_USER) == 0) {
539 kmi->id = keymap->kmi_id;
540 }
541 else {
542 kmi->id = -keymap->kmi_id; /* User defined keymap entries have negative ids. */
543 }
544}
545
547 const char *idname,
549{
550 wmKeyMapItem *kmi = MEM_callocN<wmKeyMapItem>("keymap entry");
551
552 BLI_addtail(&keymap->items, kmi);
553 STRNCPY(kmi->idname, idname);
554
557
558 keymap_item_set_id(keymap, kmi);
559
560 WM_keyconfig_update_tag(keymap, kmi);
561
562 return kmi;
563}
564
566{
567 wmKeyMapItem *kmi_dst = wm_keymap_item_copy(kmi_src);
568
569 BLI_addtail(&keymap->items, kmi_dst);
570
571 keymap_item_set_id(keymap, kmi_dst);
572
573 WM_keyconfig_update_tag(keymap, kmi_dst);
574
575 return kmi_dst;
576}
577
579{
580 BLI_assert(BLI_findindex(&keymap->items, kmi) != -1);
581 if (kmi->ptr) {
583 MEM_delete(kmi->ptr);
584 }
585 else if (kmi->properties) {
587 }
588 BLI_freelinkN(&keymap->items, kmi);
589
590 WM_keyconfig_update_tag(keymap, nullptr);
591}
592
594
595/* -------------------------------------------------------------------- */
603
604static void wm_keymap_addon_add(wmKeyMap *keymap, wmKeyMap *addonmap)
605{
606 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &addonmap->items) {
607 wmKeyMapItem *kmi_new = wm_keymap_item_copy(kmi);
608 keymap_item_set_id(keymap, kmi_new);
609 BLI_addhead(&keymap->items, kmi_new);
610 }
611}
612
614{
615 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
616 if (wm_keymap_item_equals(kmi, needle)) {
617 return kmi;
618 }
619 }
620
621 return nullptr;
622}
623
625{
626 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
627 if (wm_keymap_item_equals_result(kmi, needle)) {
628 return kmi;
629 }
630 }
631
632 return nullptr;
633}
634
635static void wm_keymap_diff(
636 wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km)
637{
638 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &from_km->items) {
639 wmKeyMapItem *to_kmi = WM_keymap_item_find_id(to_km, kmi->id);
640
641 if (!to_kmi) {
642 /* Remove item. */
643 wmKeyMapDiffItem *kmdi = MEM_callocN<wmKeyMapDiffItem>("wmKeyMapDiffItem");
644 kmdi->remove_item = wm_keymap_item_copy(kmi);
645 BLI_addtail(&diff_km->diff_items, kmdi);
646 }
647 else if (to_kmi && !wm_keymap_item_equals(kmi, to_kmi)) {
648 /* Replace item. */
649 wmKeyMapDiffItem *kmdi = MEM_callocN<wmKeyMapDiffItem>("wmKeyMapDiffItem");
650 kmdi->remove_item = wm_keymap_item_copy(kmi);
651 kmdi->add_item = wm_keymap_item_copy(to_kmi);
652 BLI_addtail(&diff_km->diff_items, kmdi);
653 }
654
655 /* Sync expanded flag back to original so we don't lose it on re-patch. */
656 if (to_kmi) {
657 wmKeyMapItem *orig_kmi = WM_keymap_item_find_id(orig_km, kmi->id);
658
659 if (!orig_kmi && addon_km) {
660 orig_kmi = wm_keymap_find_item_equals(addon_km, kmi);
661 }
662
663 if (orig_kmi) {
664 orig_kmi->flag &= ~KMI_EXPANDED;
665 orig_kmi->flag |= (to_kmi->flag & KMI_EXPANDED);
666 }
667 }
668 }
669
670 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &to_km->items) {
671 if (kmi->id < 0) {
672 /* Add item. */
673 wmKeyMapDiffItem *kmdi = MEM_callocN<wmKeyMapDiffItem>("wmKeyMapDiffItem");
674 kmdi->add_item = wm_keymap_item_copy(kmi);
675 BLI_addtail(&diff_km->diff_items, kmdi);
676 }
677 }
678}
679
680static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km)
681{
682 LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &diff_km->diff_items) {
683 /* Find item to remove. */
684 wmKeyMapItem *kmi_remove = nullptr;
685 if (kmdi->remove_item) {
686 kmi_remove = wm_keymap_find_item_equals(km, kmdi->remove_item);
687 if (!kmi_remove) {
688 kmi_remove = wm_keymap_find_item_equals_result(km, kmdi->remove_item);
689 }
690 }
691
692 /* Add item. */
693 if (kmdi->add_item) {
694 /* Do not re-add an already existing keymap item! See #42088. */
695 /* We seek only for exact copy here! See #42137. */
696 wmKeyMapItem *kmi_add = wm_keymap_find_item_equals(km, kmdi->add_item);
697
698 /* If kmi_add is same as kmi_remove (can happen in some cases,
699 * typically when we got kmi_remove from #wm_keymap_find_item_equals_result()),
700 * no need to add or remove anything, see #45579. */
701
714 if (kmi_add != nullptr && kmi_add == kmi_remove) {
715 kmi_remove = nullptr;
716 }
717 /* Only if nothing to remove or item to remove found. */
718 else if (!kmi_add && (!kmdi->remove_item || kmi_remove)) {
719 kmi_add = wm_keymap_item_copy(kmdi->add_item);
720 kmi_add->flag |= KMI_USER_MODIFIED;
721
722 if (kmi_remove) {
723 kmi_add->flag &= ~KMI_EXPANDED;
724 kmi_add->flag |= (kmi_remove->flag & KMI_EXPANDED);
725 kmi_add->id = kmi_remove->id;
726 BLI_insertlinkbefore(&km->items, kmi_remove, kmi_add);
727 }
728 else {
729 keymap_item_set_id(km, kmi_add);
730 BLI_addtail(&km->items, kmi_add);
731 }
732 }
733 }
734
735 /* Remove item. */
736 if (kmi_remove) {
737 wm_keymap_item_free_data(kmi_remove);
738 BLI_freelinkN(&km->items, kmi_remove);
739 }
740 }
741}
742
744 wmKeyMap *defaultmap,
745 wmKeyMap *addonmap,
746 wmKeyMap *usermap)
747{
748 int expanded = 0;
749
750 /* Remove previous keymap in list, we will replace it. */
752 lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid);
753 if (km) {
754 expanded = (km->flag & (KEYMAP_EXPANDED | KEYMAP_CHILDREN_EXPANDED));
755 WM_keymap_clear(km);
756 BLI_freelinkN(lb, km);
757 }
758
759 /* Copy new keymap from an existing one. */
760 if (usermap && !(usermap->flag & KEYMAP_DIFF)) {
761 /* For compatibility with old user preferences with non-diff
762 * keymaps we override the original entirely. */
763
764 km = wm_keymap_copy(usermap);
765
766 /* Try to find corresponding id's for items. */
767 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
768 wmKeyMapItem *orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi);
769 if (!orig_kmi) {
770 orig_kmi = wm_keymap_find_item_equals_result(defaultmap, kmi);
771 }
772
773 if (orig_kmi) {
774 kmi->id = orig_kmi->id;
775 }
776 else {
777 kmi->id = -(km->kmi_id++);
778 }
779 }
780
781 km->flag |= KEYMAP_UPDATE; /* Update again to create diff. */
782 }
783 else {
784 km = wm_keymap_copy(defaultmap);
785 }
786
787 /* Add addon keymap items. */
788 if (addonmap) {
789 wm_keymap_addon_add(km, addonmap);
790 }
791
792 /* Tag as being user edited. */
793 if (usermap) {
795 }
796 km->flag |= KEYMAP_USER | expanded;
797
798 /* Apply user changes of diff keymap. */
799 if (usermap && (usermap->flag & KEYMAP_DIFF)) {
800 wm_keymap_patch(km, usermap);
801 }
802
803 /* Add to list. */
804 BLI_addtail(lb, km);
805
806 return km;
807}
808
810 wmKeyMap *defaultmap,
811 wmKeyMap *addonmap,
812 wmKeyMap *km)
813{
814 /* Create temporary default + addon keymap for diff. */
815 wmKeyMap *origmap = defaultmap;
816
817 if (addonmap) {
818 defaultmap = wm_keymap_copy(defaultmap);
819 wm_keymap_addon_add(defaultmap, addonmap);
820 }
821
822 /* Remove previous diff keymap in list, we will replace it. */
823 wmKeyMap *prevmap = WM_keymap_list_find(lb, km->idname, km->spaceid, km->regionid);
824 if (prevmap) {
825 WM_keymap_clear(prevmap);
826 BLI_freelinkN(lb, prevmap);
827 }
828
829 /* Create diff keymap. */
830 wmKeyMap *diffmap = wm_keymap_new(km->idname, km->spaceid, km->regionid);
831 diffmap->flag |= KEYMAP_DIFF;
832 if (defaultmap->flag & KEYMAP_MODAL) {
833 diffmap->flag |= KEYMAP_MODAL;
834 }
835 wm_keymap_diff(diffmap, defaultmap, km, origmap, addonmap);
836
837 /* Add to list if not empty. */
838 if (diffmap->diff_items.first) {
839 BLI_addtail(lb, diffmap);
840 }
841 else {
842 WM_keymap_clear(diffmap);
843 MEM_freeN(diffmap);
844 }
845
846 /* Free temporary default map. */
847 if (addonmap) {
848 WM_keymap_clear(defaultmap);
849 MEM_freeN(defaultmap);
850 }
851}
852
854
855/* -------------------------------------------------------------------- */
863
864wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid)
865{
866 LISTBASE_FOREACH (wmKeyMap *, km, lb) {
867 if (km->spaceid == spaceid && km->regionid == regionid) {
868 if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
869 return km;
870 }
871 }
872 }
873
874 return nullptr;
875}
876
878 const char *idname,
879 int spaceid,
880 int regionid)
881{
882 LISTBASE_FOREACH (wmKeyMap *, km, lb) {
883 if (ELEM(km->spaceid, spaceid, SPACE_EMPTY) && km->regionid == regionid) {
884 if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
885 return km;
886 }
887 }
888 }
889
890 return nullptr;
891}
892
893wmKeyMap *WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
894{
895 wmKeyMap *km = WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
896
897 if (km == nullptr) {
898 km = wm_keymap_new(idname, spaceid, regionid);
899 BLI_addtail(&keyconf->keymaps, km);
900
901 WM_keyconfig_update_tag(km, nullptr);
902 }
903
904 return km;
905}
906
907wmKeyMap *WM_keymap_find_all(wmWindowManager *wm, const char *idname, int spaceid, int regionid)
908{
909 return WM_keymap_list_find(&wm->userconf->keymaps, idname, spaceid, regionid);
910}
911
913 const char *idname,
914 int spaceid,
915 int regionid)
916{
917 return WM_keymap_list_find_spaceid_or_empty(&wm->userconf->keymaps, idname, spaceid, regionid);
918}
919
921
922/* -------------------------------------------------------------------- */
928
930 const char *idname,
931 const EnumPropertyItem *items)
932{
933 wmKeyMap *km = WM_keymap_ensure(keyconf, idname, SPACE_EMPTY, RGN_TYPE_WINDOW);
934 km->flag |= KEYMAP_MODAL;
935
936 /* Initialize modal items from default configuration. */
937 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
938 if (wm->defaultconf && wm->defaultconf != keyconf) {
939 wmKeyMap *defaultkm = WM_keymap_list_find(
941
942 if (defaultkm) {
943 km->modal_items = defaultkm->modal_items;
944 km->poll = defaultkm->poll;
945 km->poll_modal_item = defaultkm->poll_modal_item;
946 }
947 }
948
949 if (items) {
950 km->modal_items = items;
951 }
952
953 return km;
954}
955
956wmKeyMap *WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
957{
958 LISTBASE_FOREACH (wmKeyMap *, km, &keyconf->keymaps) {
959 if (km->flag & KEYMAP_MODAL) {
960 if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
961 return km;
962 }
963 }
964 }
965
966 return nullptr;
967}
968
970{
971 wmKeyMapItem *kmi = MEM_callocN<wmKeyMapItem>("keymap entry");
972
973 BLI_addtail(&km->items, kmi);
974 kmi->propvalue = value;
975
977
978 keymap_item_set_id(km, kmi);
979
981
982 return kmi;
983}
984
987 const char *value)
988{
989 wmKeyMapItem *kmi = MEM_callocN<wmKeyMapItem>("keymap entry");
990
991 BLI_addtail(&km->items, kmi);
992 STRNCPY(kmi->propvalue_str, value);
993
995
996 keymap_item_set_id(km, kmi);
997
999
1000 return kmi;
1001}
1002
1004 const wmKeyMapItem *kmi,
1005 const int propvalue)
1006{
1007 if (km->flag & KEYMAP_MODAL) {
1008 kmi = static_cast<const wmKeyMapItem *>(kmi ? kmi->next : km->items.first);
1009 for (; kmi; kmi = kmi->next) {
1010 if (kmi->propvalue == propvalue) {
1011 return kmi;
1012 }
1013 }
1014 }
1015 else {
1016 BLI_assert_msg(0, "called with non modal keymap");
1017 }
1018
1019 return nullptr;
1020}
1021
1022const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
1023{
1024 return wm_modalkeymap_find_propvalue_iter(km, nullptr, propvalue);
1025}
1026
1027void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
1028{
1029 wmOperatorType *ot = WM_operatortype_find(opname, false);
1030
1031 if (ot) {
1032 ot->modalkeymap = km;
1033 }
1034 else {
1035 CLOG_ERROR(WM_LOG_KEYMAPS, "unknown operator '%s'", opname);
1036 }
1037}
1038
1040{
1041 /* Here we convert propvalue string values delayed, due to python keymaps
1042 * being created before the actual modal keymaps, so no modal_items. */
1043
1044 if (km && (km->flag & KEYMAP_MODAL) && !km->modal_items) {
1045 if (wm->defaultconf == nullptr) {
1046 return;
1047 }
1048
1049 wmKeyMap *defaultkm = WM_keymap_list_find(
1051 if (!defaultkm) {
1052 return;
1053 }
1054
1055 km->modal_items = defaultkm->modal_items;
1056 km->poll = defaultkm->poll;
1057 km->poll_modal_item = defaultkm->poll_modal_item;
1058
1059 if (km->modal_items) {
1060 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
1061 if (kmi->propvalue_str[0]) {
1062 int propvalue;
1063 if (RNA_enum_value_from_id(static_cast<const EnumPropertyItem *>(km->modal_items),
1064 kmi->propvalue_str,
1065 &propvalue))
1066 {
1067 kmi->propvalue = propvalue;
1068 }
1069 kmi->propvalue_str[0] = '\0';
1070 }
1071 }
1072 }
1073 }
1074}
1075
1077
1078/* -------------------------------------------------------------------- */
1081
1082static const char *key_event_glyph_or_text(const int font_id,
1083 const char *text,
1084 const char *single_glyph)
1085{
1086 BLI_assert(single_glyph == nullptr || (BLI_strlen_utf8(single_glyph) == 1));
1087 return (single_glyph && BLF_has_glyph(font_id, BLI_str_utf8_as_unicode_or_error(single_glyph))) ?
1088 single_glyph :
1089 text;
1090}
1091
1092const char *WM_key_event_string(const short type, const bool compact)
1093{
1094 if (compact) {
1095 /* String storing a single unicode character or nullptr. */
1096 const char *single_glyph = nullptr;
1097 int font_id = BLF_default();
1098 const enum {
1099 UNIX,
1100 MACOS,
1101 MSWIN,
1102 } platform =
1103
1104#if defined(__APPLE__)
1105 MACOS
1106#elif defined(_WIN32)
1107 MSWIN
1108#else
1109 UNIX
1110#endif
1111 ;
1112
1113 switch (type) {
1114 case EVT_LEFTSHIFTKEY:
1115 case EVT_RIGHTSHIFTKEY: {
1116 if (platform == MACOS) {
1117 single_glyph = BLI_STR_UTF8_UPWARDS_WHITE_ARROW;
1118 }
1120 font_id, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Shift"), single_glyph);
1121 }
1122 case EVT_LEFTCTRLKEY:
1123 case EVT_RIGHTCTRLKEY:
1124 if (platform == MACOS) {
1126 }
1127 return IFACE_("Ctrl");
1128 case EVT_LEFTALTKEY:
1129 case EVT_RIGHTALTKEY: {
1130 if (platform == MACOS) {
1131 /* Option symbol on Mac keyboard. */
1132 single_glyph = BLI_STR_UTF8_OPTION_KEY;
1133 }
1134 return key_event_glyph_or_text(font_id, IFACE_("Alt"), single_glyph);
1135 }
1136 case EVT_OSKEY: {
1137 /* Keep these labels in sync with: `scripts/modules/rna_keymap_ui.py`. */
1138 if (platform == MACOS) {
1141 }
1142 if (platform == MSWIN) {
1145 }
1146 return IFACE_("OS");
1147 }
1148 case EVT_TABKEY:
1151 case EVT_BACKSPACEKEY:
1153 case EVT_ESCKEY:
1154 if (platform == MACOS) {
1156 }
1157 return key_event_glyph_or_text(font_id, IFACE_("Esc"), single_glyph);
1158 case EVT_RETKEY:
1160 case EVT_SPACEKEY:
1163 case EVT_LEFTARROWKEY:
1165 case EVT_UPARROWKEY:
1167 case EVT_RIGHTARROWKEY:
1169 case EVT_DOWNARROWKEY:
1171 }
1172 }
1173
1174 const EnumPropertyItem *it;
1175 const int i = RNA_enum_from_value(rna_enum_event_type_items, int(type));
1176
1177 if (i == -1) {
1178 return "";
1179 }
1181
1182 /* We first try enum items' description (abused as short-name here),
1183 * and fall back to usual name if empty. */
1184 if (compact && it->description[0]) {
1185 /* XXX No context for enum descriptions... In practice shall not be an issue though. */
1186 return IFACE_(it->description);
1187 }
1188
1190}
1191
1192std::optional<std::string> WM_keymap_item_raw_to_string(const int8_t shift,
1193 const int8_t ctrl,
1194 const int8_t alt,
1195 const int8_t oskey,
1196 const int8_t hyper,
1197 const short keymodifier,
1198 const short val,
1199 const short type,
1200 const bool compact)
1201{
1202 /* TODO: also support (some) value, like e.g. double-click? */
1204
1205 const char *space = " ";
1206
1207 /* When a modifier is #KM_ANY, it isn't shown as this would end up being overly verbose. */
1208
1209 if (shift == KM_MOD_HELD) {
1210 result_array.append(WM_key_event_string(EVT_LEFTSHIFTKEY, true));
1211 result_array.append(space);
1212 }
1213 if (ctrl == KM_MOD_HELD) {
1214 result_array.append(WM_key_event_string(EVT_LEFTCTRLKEY, true));
1215 result_array.append(space);
1216 }
1217 if (alt == KM_MOD_HELD) {
1218 result_array.append(WM_key_event_string(EVT_LEFTALTKEY, true));
1219 result_array.append(space);
1220 }
1221 if (oskey == KM_MOD_HELD) {
1222 result_array.append(WM_key_event_string(EVT_OSKEY, true));
1223 result_array.append(space);
1224 }
1225 if (hyper == KM_MOD_HELD) {
1226 result_array.append(WM_key_event_string(EVT_HYPER, true));
1227 result_array.append(space);
1228 }
1229
1230 if (keymodifier) {
1231 result_array.append(WM_key_event_string(keymodifier, compact));
1232 result_array.append(space);
1233 }
1234
1235 if (type) {
1236 if (val == KM_DBL_CLICK) {
1237 result_array.append(IFACE_("dbl-"));
1238 }
1239 else if (val == KM_CLICK_DRAG) {
1240 result_array.append(IFACE_("drag-"));
1241 }
1242 result_array.append(WM_key_event_string(type, compact));
1243 }
1244
1245 if (!result_array.is_empty() && (result_array.last() == space)) {
1246 result_array.remove_last();
1247 }
1248
1249 return fmt::to_string(fmt::join(result_array, ""));
1250}
1251
1252std::optional<std::string> WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
1253{
1255 kmi->ctrl,
1256 kmi->alt,
1257 kmi->oskey,
1258 kmi->hyper,
1259 kmi->keymodifier,
1260 kmi->val,
1261 kmi->type,
1262 compact);
1263}
1264
1265std::optional<std::string> WM_modalkeymap_items_to_string(const wmKeyMap *km,
1266 const int propvalue,
1267 const bool compact)
1268{
1269 const wmKeyMapItem *kmi;
1270 if (km == nullptr || (kmi = WM_modalkeymap_find_propvalue(km, propvalue)) == nullptr) {
1271 return std::nullopt;
1272 }
1273
1274 std::string result;
1275 do {
1276 result += WM_keymap_item_to_string(kmi, compact).value_or("");
1277
1278 if ((kmi = wm_modalkeymap_find_propvalue_iter(km, kmi, propvalue)) == nullptr) {
1279 break;
1280 }
1281 result += '/';
1282 } while (true);
1283
1284 return result;
1285}
1286
1288 const int propvalue,
1289 const bool compact)
1290{
1291 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
1292 wmKeyMap *keymap = WM_keymap_active(wm, ot->modalkeymap);
1293 return WM_modalkeymap_items_to_string(keymap, propvalue, compact);
1294}
1295
1297
1298/* -------------------------------------------------------------------- */
1301
1303 const char *opname,
1304 IDProperty *properties,
1305 const bool is_strict,
1307{
1308 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
1309 /* Skip disabled keymap items, see: #38447. */
1310 if (kmi->flag & KMI_INACTIVE) {
1311 continue;
1312 }
1313 if (!STREQ(kmi->idname, opname)) {
1314 continue;
1315 }
1316
1317 bool kmi_match = false;
1318 if (properties) {
1319/* Example of debugging keymaps. */
1320#if 0
1321 if (kmi->ptr) {
1322 if (STREQ("MESH_OT_rip_move", opname)) {
1323 printf("OPERATOR\n");
1324 IDP_print(properties);
1325 printf("KEYMAP\n");
1326 IDP_print(kmi->ptr->data);
1327 }
1328 }
1329#endif
1330
1331 if (kmi->ptr && IDP_EqualsProperties_ex(
1332 properties, static_cast<const IDProperty *>(kmi->ptr->data), is_strict))
1333 {
1334 kmi_match = true;
1335 }
1336 /* Debug only, helps spotting mismatches between menu entries and shortcuts! */
1337 else if (G.debug & G_DEBUG_WM) {
1338 if (is_strict && kmi->ptr) {
1339 wmOperatorType *ot = WM_operatortype_find(opname, true);
1340 if (ot) {
1341 /* Make a copy of the properties and set unset ones to their default values. */
1342 IDProperty *properties_default = IDP_CopyProperty(
1343 static_cast<const IDProperty *>(kmi->ptr->data));
1344
1345 PointerRNA opptr = RNA_pointer_create_discrete(nullptr, ot->srna, properties_default);
1346 WM_operator_properties_default(&opptr, true);
1347
1348 if (IDP_EqualsProperties_ex(properties, properties_default, is_strict)) {
1349 std::string kmi_str = WM_keymap_item_to_string(kmi, false).value_or("");
1350 /* NOTE: given properties could come from other things than menu entry. */
1351 printf(
1352 "%s: Some set values in menu entry match default op values, "
1353 "this might not be desired!\n",
1354 opname);
1355 printf("\tkm: '%s', kmi: '%s'\n", keymap->idname, kmi_str.c_str());
1356#ifndef NDEBUG
1357# ifdef WITH_PYTHON
1358 printf("OPERATOR\n");
1359 IDP_print(properties);
1360 printf("KEYMAP\n");
1361 IDP_print(static_cast<IDProperty *>(kmi->ptr->data));
1362# endif
1363#endif
1364 printf("\n");
1365 }
1366
1367 IDP_FreeProperty(properties_default);
1368 }
1369 }
1370 }
1371 }
1372 else {
1373 kmi_match = true;
1374 }
1375
1376 if (kmi_match) {
1377 if ((params == nullptr) || params->filter_fn(keymap, kmi, params->user_data)) {
1378 return kmi;
1379 }
1380 }
1381 }
1382 return nullptr;
1383}
1384
1386 wmWindowManager *wm,
1387 wmWindow *win,
1388 ListBase *handlers,
1389 const char *opname,
1390 wmOperatorCallContext /*opcontext*/,
1391 IDProperty *properties,
1392 const bool is_strict,
1394 wmKeyMap **r_keymap)
1395{
1396 /* Find keymap item in handlers. */
1397 LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
1398 if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
1399 wmEventHandler_Keymap *handler = (wmEventHandler_Keymap *)handler_base;
1401 WM_event_get_keymaps_from_handler(wm, win, handler, &km_result);
1402 for (int km_index = 0; km_index < km_result.keymaps_len; km_index++) {
1403 wmKeyMap *keymap = km_result.keymaps[km_index];
1404 if (WM_keymap_poll((bContext *)C, keymap)) {
1406 keymap, opname, properties, is_strict, params);
1407 if (kmi != nullptr) {
1408 if (r_keymap) {
1409 *r_keymap = keymap;
1410 }
1411 return kmi;
1412 }
1413 }
1414 }
1415 }
1416 }
1417 /* Ensure un-initialized keymap is never used. */
1418 if (r_keymap) {
1419 *r_keymap = nullptr;
1420 }
1421 return nullptr;
1422}
1423
1425 const char *opname,
1426 wmOperatorCallContext opcontext,
1427 IDProperty *properties,
1428 const bool is_strict,
1430 wmKeyMap **r_keymap)
1431{
1433 wmWindow *win = CTX_wm_window(C);
1434 ScrArea *area = CTX_wm_area(C);
1435 ARegion *region = CTX_wm_region(C);
1436 wmKeyMapItem *found = nullptr;
1437
1438 /* Look into multiple handler lists to find the item. */
1439 if (win) {
1441 wm,
1442 win,
1443 &win->modalhandlers,
1444 opname,
1445 opcontext,
1446 properties,
1447 is_strict,
1448 params,
1449 r_keymap);
1450 if (found == nullptr) {
1452 C, wm, win, &win->handlers, opname, opcontext, properties, is_strict, params, r_keymap);
1453 }
1454 }
1455
1456 if (area && found == nullptr) {
1458 C, wm, win, &area->handlers, opname, opcontext, properties, is_strict, params, r_keymap);
1459 }
1460
1461 if (found == nullptr) {
1463 if (area) {
1464 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
1466 }
1467
1468 if (region) {
1470 wm,
1471 win,
1472 &region->runtime->handlers,
1473 opname,
1474 opcontext,
1475 properties,
1476 is_strict,
1477 params,
1478 r_keymap);
1479 }
1480 }
1481 }
1483 if (!(region && region->regiontype == RGN_TYPE_CHANNELS)) {
1485 }
1486
1487 if (region) {
1489 wm,
1490 win,
1491 &region->runtime->handlers,
1492 opname,
1493 opcontext,
1494 properties,
1495 is_strict,
1496 params,
1497 r_keymap);
1498 }
1499 }
1501 if (!(region && region->regiontype == RGN_TYPE_PREVIEW)) {
1503 }
1504
1505 if (region) {
1507 wm,
1508 win,
1509 &region->runtime->handlers,
1510 opname,
1511 opcontext,
1512 properties,
1513 is_strict,
1514 params,
1515 r_keymap);
1516 }
1517 }
1518 else {
1519 if (region) {
1521 wm,
1522 win,
1523 &region->runtime->handlers,
1524 opname,
1525 opcontext,
1526 properties,
1527 is_strict,
1528 params,
1529 r_keymap);
1530 }
1531 }
1532 }
1533
1534 return found;
1535}
1536
1538 const char *opname,
1539 wmOperatorCallContext opcontext,
1540 IDProperty *properties,
1541 bool is_strict,
1543 wmKeyMap **r_keymap)
1544{
1545 /* XXX Hack! Macro operators in menu entry have their whole props defined,
1546 * which is not the case for relevant keymap entries.
1547 * Could be good to check and harmonize this,
1548 * but for now always compare non-strict in this case. */
1549 wmOperatorType *ot = WM_operatortype_find(opname, true);
1550 if (ot) {
1551 is_strict = is_strict && ((ot->flag & OPTYPE_MACRO) == 0);
1552 }
1553
1555 C, opname, opcontext, properties, is_strict, params, r_keymap);
1556
1557 /* This block is *only* useful in one case: when op uses an enum menu in its prop member
1558 * (then, we want to rerun a comparison with that 'prop' unset). Note this remains brittle,
1559 * since now any enum prop may be used in UI (specified by name), ot->prop is not so much used...
1560 * Otherwise:
1561 * * If non-strict, unset properties always match set ones in IDP_EqualsProperties_ex.
1562 * * If strict, unset properties never match set ones in IDP_EqualsProperties_ex,
1563 * and we do not want that to change (else we get things like #41757)!
1564 * ...so in either case, re-running a comparison with unset props set to default is useless.
1565 */
1566 if (!found && properties) {
1567 if (ot && ot->prop) { /* XXX Shall we also check ot->prop is actually an enum? */
1568 /* Make a copy of the properties and unset the 'ot->prop' one if set. */
1569 IDProperty *properties_temp = IDP_CopyProperty(properties);
1570
1571 PointerRNA opptr = RNA_pointer_create_discrete(nullptr, ot->srna, properties_temp);
1572
1573 if (RNA_property_is_set(&opptr, ot->prop)) {
1574 /* For operator that has enum menu,
1575 * unset it so its value does not affect comparison result. */
1576 RNA_property_unset(&opptr, ot->prop);
1577
1579 C, opname, opcontext, properties_temp, is_strict, params, r_keymap);
1580 }
1581
1582 IDP_FreeProperty(properties_temp);
1583 }
1584 }
1585
1586 /* Debug only, helps spotting mismatches between menu entries and shortcuts! */
1587 if (G.debug & G_DEBUG_WM) {
1588 if (!found && is_strict && properties) {
1589 if (ot) {
1590 /* Make a copy of the properties and set unset ones to their default values. */
1591 IDProperty *properties_default = IDP_CopyProperty(properties);
1592
1593 PointerRNA opptr = RNA_pointer_create_discrete(nullptr, ot->srna, properties_default);
1594 WM_operator_properties_default(&opptr, true);
1595
1596 wmKeyMap *km;
1598 C, opname, opcontext, properties_default, is_strict, params, &km);
1599 if (kmi) {
1600 std::string kmi_str = WM_keymap_item_to_string(kmi, false).value_or("");
1601 printf(
1602 "%s: Some set values in keymap entry match default op values, "
1603 "this might not be desired!\n",
1604 opname);
1605 printf("\tkm: '%s', kmi: '%s'\n", km->idname, kmi_str.c_str());
1606#ifndef NDEBUG
1607# ifdef WITH_PYTHON
1608 printf("OPERATOR\n");
1609 IDP_print(properties);
1610 printf("KEYMAP\n");
1611 IDP_print(static_cast<IDProperty *>(kmi->ptr->data));
1612# endif
1613#endif
1614 printf("\n");
1615 }
1616
1617 IDP_FreeProperty(properties_default);
1618 }
1619 }
1620 }
1621
1622 return found;
1623}
1624
1625static bool kmi_filter_is_visible(const wmKeyMap * /*km*/,
1626 const wmKeyMapItem *kmi,
1627 void * /*user_data*/)
1628{
1629 return ((WM_key_event_string(kmi->type, false)[0] != '\0') &&
1630 (IS_EVENT_ACTIONZONE(kmi->type) == false));
1631}
1632
1633std::optional<std::string> WM_key_event_operator_string(const bContext *C,
1634 const char *opname,
1635 wmOperatorCallContext opcontext,
1636 IDProperty *properties,
1637 const bool is_strict)
1638{
1640 params.filter_fn = kmi_filter_is_visible;
1641 params.user_data = nullptr;
1643 C, opname, opcontext, properties, is_strict, &params, nullptr);
1644 if (kmi) {
1645 return WM_keymap_item_to_string(kmi, false);
1646 }
1647
1648 /* Check UI state (non key-map actions for UI regions). */
1649 if (std::optional<std::string> result = UI_key_event_operator_string(
1650 C, opname, properties, is_strict))
1651 {
1652 return result;
1653 }
1654
1655 return std::nullopt;
1656}
1657
1659 const wmKeyMapItem *kmi,
1660 void *user_data)
1661{
1662 short *mask_pair = static_cast<short int *>(user_data);
1663 return ((WM_event_type_mask_test(kmi->type, eEventType_Mask(mask_pair[0])) == true) &&
1664 (WM_event_type_mask_test(kmi->type, eEventType_Mask(mask_pair[1])) == false) &&
1665 kmi_filter_is_visible(km, kmi, user_data));
1666}
1667
1669 const char *opname,
1670 wmOperatorCallContext opcontext,
1671 IDProperty *properties,
1672 const short include_mask,
1673 const short exclude_mask,
1674 wmKeyMap **r_keymap)
1675{
1676 short user_data_mask[2] = {include_mask, exclude_mask};
1677 bool use_mask = (include_mask != EVT_TYPE_MASK_ALL) || (exclude_mask != 0);
1680 params.user_data = use_mask ? user_data_mask : nullptr;
1681 return wm_keymap_item_find(C, opname, opcontext, properties, true, &params, r_keymap);
1682}
1683
1685 const char *opname,
1686 IDProperty *properties,
1687 const short include_mask,
1688 const short exclude_mask)
1689{
1690 short user_data_mask[2] = {include_mask, exclude_mask};
1691 bool use_mask = (include_mask != EVT_TYPE_MASK_ALL) || (exclude_mask != 0);
1694 params.user_data = use_mask ? user_data_mask : nullptr;
1695
1696 return wm_keymap_item_find_in_keymap(keymap, opname, properties, true, &params);
1697}
1698
1700{
1701 if (k1->flag & KMI_INACTIVE || k2->flag & KMI_INACTIVE) {
1702 return false;
1703 }
1704
1705 /* Take event mapping into account. */
1706 int k1type = WM_userdef_event_map(k1->type);
1707 int k2type = WM_userdef_event_map(k2->type);
1708
1709 if (k1type != KM_ANY && k2type != KM_ANY && k1type != k2type) {
1710 return false;
1711 }
1712
1713 if (k1->val != KM_ANY && k2->val != KM_ANY) {
1714 /* Take click, press, release conflict into account. */
1715 if (k1->val == KM_CLICK && ELEM(k2->val, KM_PRESS, KM_RELEASE, KM_CLICK) == 0) {
1716 return false;
1717 }
1718 if (k2->val == KM_CLICK && ELEM(k1->val, KM_PRESS, KM_RELEASE, KM_CLICK) == 0) {
1719 return false;
1720 }
1721 if (k1->val != k2->val) {
1722 return false;
1723 }
1724 if (k1->val == KM_CLICK_DRAG && (k1->direction != k2->direction)) {
1725 return false;
1726 }
1727 }
1728
1729 if (k1->shift != KM_ANY && k2->shift != KM_ANY && k1->shift != k2->shift) {
1730 return false;
1731 }
1732
1733 if (k1->ctrl != KM_ANY && k2->ctrl != KM_ANY && k1->ctrl != k2->ctrl) {
1734 return false;
1735 }
1736
1737 if (k1->alt != KM_ANY && k2->alt != KM_ANY && k1->alt != k2->alt) {
1738 return false;
1739 }
1740
1741 if (k1->oskey != KM_ANY && k2->oskey != KM_ANY && k1->oskey != k2->oskey) {
1742 return false;
1743 }
1744
1745 if (k1->hyper != KM_ANY && k2->hyper != KM_ANY && k1->hyper != k2->hyper) {
1746 return false;
1747 }
1748
1749 if (k1->keymodifier != k2->keymodifier) {
1750 return false;
1751 }
1752
1753 return true;
1754}
1755
1757
1758/* -------------------------------------------------------------------- */
1765
1766/* So operator removal can trigger update. */
1767enum {
1769
1770 /* Ensure all wmKeyMap have their operator types validated after removing an operator. */
1772
1774};
1775
1777
1779#ifndef NDEBUG
1781#endif
1782
1784{
1785 /* Quick tag to do delayed keymap updates. */
1787
1788 if (keymap) {
1789 keymap->flag |= KEYMAP_UPDATE;
1790 }
1791 if (kmi) {
1792 kmi->flag |= KMI_UPDATE;
1793 }
1794}
1795
1800
1801/* NOTE(@ideasman42): regarding suppressing updates.
1802 * If this becomes a common operation it would be better use something more general,
1803 * a key-map flag for example to signify that the key-map is stored outside of a #wmKeyConfig
1804 * and should not receive updates on modification. At the moment this has the down-side of
1805 * needing to be supported in quite a few places for something which isn't used much.
1806 * Since the use case for this is limited, add functions to begin/end suppression.
1807 * If these end up being used a lot we can consider alternatives. */
1808
1817
1827
1832
1837
1839{
1840 int update = (km->flag & KEYMAP_UPDATE);
1841 km->flag &= ~KEYMAP_UPDATE;
1842
1843 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
1844 update = update || (kmi->flag & KMI_UPDATE);
1845 kmi->flag &= ~KMI_UPDATE;
1846 }
1847
1848 return (update != 0);
1849}
1850
1852{
1853 BLI_assert(keyconf == WM_keyconfig_active(wm));
1854 wmKeyMap *keymap = WM_keymap_list_find(&keyconf->keymaps, km->idname, km->spaceid, km->regionid);
1855 if (!keymap && wm->defaultconf) {
1856 keymap = WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, km->spaceid, km->regionid);
1857 }
1858
1859 return keymap;
1860}
1861
1863{
1864 /* Ignore #WM_KEYMAP_UPDATE_OPERATORTYPE flag on startup,
1865 * it's likely to be enabled because it's set when registering any operator
1866 * however running this is unnecessary since the key-map hasn't been initialized.
1867 * It's harmless but would add redundant initialization every startup. */
1869
1870 WM_keyconfig_update_ex(wm, false);
1871}
1872
1874{
1875 WM_keyconfig_update_ex(wm, false);
1876}
1877
1878void WM_keyconfig_update_ex(wmWindowManager *wm, bool keep_properties)
1879{
1880 if (wm_keymap_update_flag == 0) {
1881 return;
1882 }
1883
1884 bool compat_update = false;
1885
1886 /* Update drop-boxes when the operators have been added or removed. While this isn't an ideal
1887 * place to update drop-boxes, they share characteristics with key-map items.
1888 * We could consider renaming this to API function so it's not only relating to keymaps. */
1889 bool dropbox_update = false;
1890
1891 /* Postpone update until after the key-map has been initialized
1892 * to ensure add-ons have been loaded, see: #113603. */
1894 return;
1895 }
1896
1898 /* One or more operator-types have been removed, this won't happen often
1899 * but when it does we have to check _every_ key-map item. */
1900 wm_keymap_item_properties_update_ot_from_list(&U.user_keymaps, keep_properties);
1902 wm_keymap_item_properties_update_ot_from_list(&kc->keymaps, keep_properties);
1903 }
1904
1905 /* An operator has been removed, refresh. */
1906 dropbox_update = true;
1907
1909 }
1910
1912 wmKeyConfig *kc_active = WM_keyconfig_active(wm);
1913
1914 /* Update operator properties for non-modal user keymaps. */
1915 LISTBASE_FOREACH (wmKeyMap *, km, &U.user_keymaps) {
1916 if ((km->flag & KEYMAP_MODAL) == 0) {
1917 LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) {
1918 if (kmdi->add_item) {
1919 wm_keymap_item_properties_set(kmdi->add_item);
1920 }
1921 if (kmdi->remove_item) {
1922 wm_keymap_item_properties_set(kmdi->remove_item);
1923 }
1924 }
1925
1926 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
1928 }
1929 }
1930 }
1931
1932 /* Update `U.user_keymaps` with user key configuration changes. */
1933 LISTBASE_FOREACH (wmKeyMap *, km, &wm->userconf->keymaps) {
1934 /* Only diff if the user keymap was modified. */
1936 /* Find keymaps. */
1937 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, km);
1938 wmKeyMap *addonmap = WM_keymap_list_find(
1939 &wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid);
1940
1941 /* Diff. */
1942 if (defaultmap) {
1943 wm_keymap_diff_update(&U.user_keymaps, defaultmap, addonmap, km);
1944 }
1945 }
1946 }
1947
1948 /* Create user key configuration from preset + addon + user preferences. */
1950 /* Find keymaps. */
1951 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, km);
1952 wmKeyMap *addonmap = WM_keymap_list_find(
1953 &wm->addonconf->keymaps, km->idname, km->spaceid, km->regionid);
1954 wmKeyMap *usermap = WM_keymap_list_find(
1955 &U.user_keymaps, km->idname, km->spaceid, km->regionid);
1956
1957 /* For now only the default map defines modal key-maps,
1958 * if we support modal keymaps for 'addonmap', these will need to be enabled too. */
1959 wm_user_modal_keymap_set_items(wm, defaultmap);
1960
1961 /* Add. */
1963 &wm->userconf->keymaps, defaultmap, addonmap, usermap);
1964
1965 if (kmn) {
1966 kmn->modal_items = km->modal_items;
1967 kmn->poll = km->poll;
1968 kmn->poll_modal_item = km->poll_modal_item;
1969 }
1970
1971 /* In case of old non-diff keymaps, force extra update to create diffs. */
1972 compat_update = compat_update || (usermap && !(usermap->flag & KEYMAP_DIFF));
1973 }
1974
1975 /* An operator may have been added, refresh. */
1976 dropbox_update = true;
1977
1979 }
1980
1982
1983 if (compat_update) {
1984 WM_keyconfig_update_tag(nullptr, nullptr);
1986 }
1987
1988 if (dropbox_update) {
1990 }
1991
1992 /* NOTE(@ideasman42): open preferences will contain "stale" #wmKeyMapItem data.
1993 *
1994 * The common case this solves is using Blender with the key-map editor open,
1995 * an action in the view-port for example may manipulate the key-map causing it to be rebuilt.
1996 * Later interaction with the key-map editor may then attempt to access freed data.
1997 *
1998 * Take care, this is _not_ fool proof because it's possible:
1999 * - Key-map options to be shown in any region (using scripts).
2000 * - Key-map re-generation could happen while the preferences is open,
2001 * where the data becomes stale before the UI has a chance to redraw.
2002 *
2003 * In practice both cases are quite unlikely though. */
2004 if (U.space_data.section_active == USER_SECTION_KEYMAP) {
2005 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2006 bScreen *screen = WM_window_get_active_screen(win);
2007 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
2008 if (area->spacetype == SPACE_USERPREF) {
2009 ED_area_tag_redraw(area);
2010 }
2011 }
2012 }
2013 }
2014}
2015
2017
2018/* -------------------------------------------------------------------- */
2024
2026{
2027 if (!keymap) {
2028 return nullptr;
2029 }
2030
2031 /* First user defined keymaps. */
2033 &wm->userconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
2034
2035 if (km) {
2036 return km;
2037 }
2038
2039 return keymap;
2040}
2041
2043
2044/* -------------------------------------------------------------------- */
2049
2051{
2052 if (!keymap) {
2053 return;
2054 }
2055
2056 /* Construct default keymap from preset + addons. */
2057 wmKeyConfig *kc_active = WM_keyconfig_active(wm);
2058 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, keymap);
2059 wmKeyMap *addonmap = WM_keymap_list_find(
2060 &wm->addonconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
2061
2062 if (addonmap) {
2063 defaultmap = wm_keymap_copy(defaultmap);
2064 wm_keymap_addon_add(defaultmap, addonmap);
2065 }
2066
2067 /* Find original item. */
2068 wmKeyMapItem *orig = WM_keymap_item_find_id(defaultmap, kmi->id);
2069
2070 if (orig) {
2071 /* Restore to original. */
2072 if (!STREQ(orig->idname, kmi->idname)) {
2073 STRNCPY(kmi->idname, orig->idname);
2074 WM_keymap_item_properties_reset(kmi, nullptr);
2075 }
2076
2077 if (orig->properties) {
2078 if (kmi->properties) {
2080 kmi->properties = nullptr;
2081 }
2082
2084 if (kmi->ptr) {
2085 kmi->ptr->data = kmi->properties;
2086 }
2087 }
2088
2089 kmi->propvalue = orig->propvalue;
2090 kmi->type = orig->type;
2091 kmi->val = orig->val;
2092 kmi->shift = orig->shift;
2093 kmi->ctrl = orig->ctrl;
2094 kmi->alt = orig->alt;
2095 kmi->oskey = orig->oskey;
2096 kmi->hyper = orig->hyper;
2097 kmi->keymodifier = orig->keymodifier;
2098 kmi->maptype = orig->maptype;
2099 kmi->flag = (kmi->flag & ~(KMI_REPEAT_IGNORE | KMI_INACTIVE)) |
2100 (orig->flag & (KMI_REPEAT_IGNORE | KMI_INACTIVE));
2101
2102 WM_keyconfig_update_tag(keymap, kmi);
2103 }
2104
2105 /* Free temporary keymap. */
2106 if (addonmap) {
2107 WM_keymap_clear(defaultmap);
2108 MEM_freeN(defaultmap);
2109 }
2110}
2111
2113{
2114 /* Remove keymap from U.user_keymaps and update. */
2115 wmKeyMap *usermap = WM_keymap_list_find(
2116 &U.user_keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
2117
2118 if (usermap) {
2119 WM_keymap_clear(usermap);
2120 BLI_freelinkN(&U.user_keymaps, usermap);
2121
2122 WM_keyconfig_update_tag(nullptr, nullptr);
2124 }
2125}
2126
2127const char *WM_bool_as_string(bool test)
2128{
2129 return test ? IFACE_("ON") : IFACE_("OFF");
2130}
2131
2133
2134/* -------------------------------------------------------------------- */
2137
2139{
2140 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
2141 if (kmi->id == id) {
2142 return kmi;
2143 }
2144 }
2145
2146 return nullptr;
2147}
2148
2150 wmKeyMap *km_match,
2151 wmKeyMapItem *kmi_match,
2153{
2154 /* NOTE: this is called by RNA, some of the reports in this function
2155 * would be asserts when called from C++. */
2156
2157 if (wm_keymap_update_flag != 0) {
2158 /* NOTE: this could be limited to the key-maps marked for updating.
2159 * However #KEYMAP_UPDATE is only cleared for `wm->userconf`
2160 * so only check the global flag for now.
2161 *
2162 * Use a warning not an error because scripts cannot prevent other scripts from manipulating
2163 * key-map items, so we won't want scripts to create exceptions in unrelated scripts.
2164 * Ideally we could detect which key-maps have been modified. */
2167 "KeyMap item result may be incorrect since an update is pending, call "
2168 "`context.window_manager.keyconfigs.update()` to ensure matches can be found.");
2169 }
2170
2171 if (km_base == km_match) {
2172 /* We could also return `kmi_match` (it's technically correct)
2173 * however this is almost certainly API misuse (as it's a no-op). */
2174 BKE_report(reports, RPT_ERROR, "KeyMaps are equal");
2175 return nullptr;
2176 }
2177
2178 const char *idname = km_base->idname;
2179 const short spaceid = km_base->spaceid;
2180 const short regionid = km_base->regionid;
2181
2182 if (!wm_keymap_is_match(km_base, km_match)) {
2184 reports, RPT_ERROR, "KeyMap \"%s\" doesn't match \"%s\"", idname, km_match->idname);
2185 return nullptr;
2186 }
2187
2188 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
2189 wmKeyConfig *kc_active = WM_keyconfig_active(wm);
2190
2191 /* NOTE: the key-maps could store this, it would simplify checks here. */
2192 enum {
2193 KM_TYPE_UNKNOWN = 0,
2194 KM_TYPE_USER,
2195 KM_TYPE_ADDON,
2196 KM_TYPE_ACTIVE,
2197 /* No support yet for preferences. */
2198 } base_type = KM_TYPE_UNKNOWN,
2199 match_type = KM_TYPE_UNKNOWN;
2200
2201 if (km_base->flag & KEYMAP_USER) {
2202 if (km_base == WM_keymap_list_find(&wm->userconf->keymaps, idname, spaceid, regionid)) {
2203 base_type = KM_TYPE_USER;
2204 }
2205 }
2206
2207 if ((km_match->flag & KEYMAP_USER) == 0) {
2208 if (km_match == WM_keymap_list_find(&wm->addonconf->keymaps, idname, spaceid, regionid)) {
2209 match_type = KM_TYPE_ADDON;
2210 }
2211 else if (km_match == WM_keymap_list_find(&kc_active->keymaps, idname, spaceid, regionid)) {
2212 match_type = KM_TYPE_ACTIVE;
2213 }
2214 }
2215
2216 if (base_type == KM_TYPE_UNKNOWN) {
2217 BKE_reportf(reports, RPT_ERROR, "KeyMap \"%s\" (base) must be a user keymap", idname);
2218 return nullptr;
2219 }
2220
2221 if (match_type == KM_TYPE_UNKNOWN) {
2223 reports, RPT_ERROR, "KeyMap \"%s\" (other) must be an add-on or active keymap", idname);
2224 return nullptr;
2225 }
2226
2227 const int kmi_index = BLI_findindex(&km_match->items, kmi_match);
2228 if (kmi_index == -1) {
2229 BKE_reportf(reports, RPT_ERROR, "KeyMap \"%s\" item not part of the keymap", idname);
2230 return nullptr;
2231 }
2232
2233 int kmi_id;
2234 if (match_type == KM_TYPE_ADDON) {
2235 /* Perform the following lookup that calculates the ID that *would* be used
2236 * if the user key-map was re-created, see: #WM_keymap_item_restore_to_default.
2237 *
2238 * Find the index of the key-map item and add this to the `defaultmap`'s key-map index
2239 * since this is how the "user" key-map ID's are generated.
2240 *
2241 * This is needed so add-ons can show the user key-map items in preferences. */
2242
2243 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, km_base);
2244 if (defaultmap == nullptr) {
2245 /* This should practically never fail, it could be caused by failure
2246 * to refresh the user key-map after manipulating the add-on key-map. */
2247 return nullptr;
2248 }
2249 kmi_id = defaultmap->kmi_id + kmi_index + 1;
2250 }
2251 else {
2252 kmi_id = kmi_match->id;
2253 }
2254
2255 /* Returning null here isn't an error because it's possible there is no match. */
2256 return WM_keymap_item_find_id(km_base, kmi_id);
2257}
2258
WorkSpace * CTX_wm_workspace(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
#define G_MAIN
@ G_DEBUG_WM
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1243
bool IDP_EqualsProperties_ex(const IDProperty *prop1, const IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:905
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:873
void IDP_print(const IDProperty *prop)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:840
bool BKE_workspace_owner_id_check(const WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
Definition workspace.cc:535
bool BLF_has_glyph(int fontid, unsigned int unicode) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:151
int BLF_default()
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:608
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:270
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:371
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define STRNCPY_UTF8(dst, src)
unsigned int BLI_str_utf8_as_unicode_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define BLI_STR_UTF8_BROKEN_CIRCLE_WITH_NORTHWEST_ARROW
#define BLI_STR_UTF8_LEFTWARDS_ARROW
#define BLI_STR_UTF8_BLACK_DIAMOND_MINUS_WHITE_X
#define BLI_STR_UTF8_UPWARDS_WHITE_ARROW
#define BLI_STR_UTF8_UPWARDS_ARROW
#define BLI_STR_UTF8_DOWNWARDS_ARROW
#define BLI_STR_UTF8_OPEN_BOX
#define BLI_STR_UTF8_PLACE_OF_INTEREST_SIGN
#define BLI_STR_UTF8_UP_ARROWHEAD
#define BLI_STR_UTF8_HORIZONTAL_TAB_KEY
#define BLI_STR_UTF8_RIGHTWARDS_ARROW
#define BLI_STR_UTF8_ERASE_TO_THE_LEFT
#define BLI_STR_UTF8_RETURN_SYMBOL
#define BLI_STR_UTF8_OPTION_KEY
#define ARRAY_SIZE(arr)
#define STREQLEN(a, b, n)
#define UNLIKELY(x)
#define ELEM(...)
#define STREQ(a, b)
#define LIKELY(x)
#define BLT_I18NCONTEXT_ID_WINDOWMANAGER
#define CTX_N_(context, msgid)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_UI_EVENTS
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:182
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:181
@ RGN_TYPE_CHANNELS
@ RGN_TYPE_WINDOW
@ RGN_TYPE_PREVIEW
@ SPACE_USERPREF
@ SPACE_EMPTY
@ USER_SECTION_KEYMAP
#define KMAP_MAX_NAME
@ WM_INIT_FLAG_KEYCONFIG
#define WM_KEYCONFIG_ARRAY_P(wm)
@ KEYMAP_USER_MODIFIED
@ KEYMAP_CHILDREN_EXPANDED
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:714
Read Guarded memory(de)allocation.
@ RNA_EQ_UNSET_MATCH_NONE
#define C
Definition RandGen.cpp:29
std::optional< std::string > UI_key_event_operator_string(const bContext *C, blender::StringRefNull opname, IDProperty *properties, bool is_strict)
#define KMI_PARAMS_MOD_FROM_ANY(mod)
Definition WM_keymap.hh:89
@ KM_CTRL
Definition WM_types.hh:276
@ KM_ALT
Definition WM_types.hh:277
@ KM_HYPER
Definition WM_types.hh:289
@ KM_OSKEY
Definition WM_types.hh:279
@ KM_SHIFT
Definition WM_types.hh:275
@ OPTYPE_MACRO
Definition WM_types.hh:185
ReportList * reports
Definition WM_types.hh:1025
wmOperatorCallContext
Definition WM_types.hh:236
@ WM_OP_INVOKE_REGION_WIN
Definition WM_types.hh:239
@ WM_OP_EXEC_REGION_WIN
Definition WM_types.hh:246
@ WM_OP_EXEC_REGION_PREVIEW
Definition WM_types.hh:248
@ WM_OP_INVOKE_REGION_PREVIEW
Definition WM_types.hh:241
@ WM_OP_EXEC_REGION_CHANNELS
Definition WM_types.hh:247
@ WM_OP_INVOKE_REGION_CHANNELS
Definition WM_types.hh:240
@ KM_TEXTINPUT
Definition WM_types.hh:301
@ KM_NOTHING
Definition WM_types.hh:307
@ KM_ANY
Definition WM_types.hh:306
@ KM_PRESS
Definition WM_types.hh:308
@ KM_CLICK_DRAG
Definition WM_types.hh:316
@ KM_DBL_CLICK
Definition WM_types.hh:311
@ KM_RELEASE
Definition WM_types.hh:309
@ KM_CLICK
Definition WM_types.hh:310
CLG_LogRef * WM_LOG_KEYMAPS
#define KM_MOD_HELD
Definition WM_types.hh:323
#define U
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
#define offsetof(t, d)
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
#define printf(...)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
#define G(x, y, z)
static void update(bNodeTree *ntree)
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_struct_state_owner_get()
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_struct_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACompareMode mode)
const EnumPropertyItem rna_enum_event_type_items[]
Definition rna_wm.cc:215
ARegionRuntimeHandle * runtime
const char * name
Definition RNA_types.hh:627
const char * description
Definition RNA_types.hh:629
void * first
ID * owner_id
Definition RNA_types.hh:51
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
ListBase handlers
ListBase areabase
struct wmKeyMapDiffItem * next
struct wmKeyMapDiffItem * prev
bool(* filter_fn)(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data)
Definition wm_keymap.cc:54
struct PointerRNA * ptr
struct wmKeyMapItem * next
struct wmKeyMapItem * prev
bool(* poll_modal_item)(const struct wmOperator *op, int value)
bool(* poll)(struct bContext *)
const void * modal_items
struct wmKeyConfig * defaultconf
struct wmKeyConfig * userconf
struct wmKeyConfig * addonconf
i
Definition text_draw.cc:230
void WM_dropbox_update_ot()
int WM_userdef_event_map(int kmitype)
bool WM_event_type_mask_test(const int event_type, const enum eEventType_Mask mask)
void WM_event_get_keymaps_from_handler(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
@ WM_HANDLER_TYPE_KEYMAP
eEventType_Mask
@ EVT_RIGHTCTRLKEY
@ EVT_TABKEY
@ EVT_DOWNARROWKEY
@ EVT_OSKEY
@ EVT_LEFTCTRLKEY
@ TABLET_ERASER
@ EVT_RIGHTARROWKEY
@ EVT_SPACEKEY
@ TABLET_STYLUS
@ EVT_RIGHTALTKEY
@ EVT_UPARROWKEY
@ EVT_LEFTARROWKEY
@ EVT_LEFTALTKEY
@ EVT_ESCKEY
@ EVT_BACKSPACEKEY
@ EVT_RIGHTSHIFTKEY
@ EVT_LEFTSHIFTKEY
@ EVT_HYPER
@ EVT_RETKEY
#define ISTIMER(event_type)
#define IS_EVENT_ACTIONZONE(event_type)
#define ISKEYBOARD(event_type)
#define EVT_TYPE_MASK_ALL
#define ISNDOF(event_type)
#define ISMOUSE(event_type)
wmOperatorType * ot
Definition wm_files.cc:4225
void WM_keyconfig_clear(wmKeyConfig *keyconf)
Definition wm_keymap.cc:351
static char wm_keymap_update_flag
static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km)
static void keymap_item_set_id(wmKeyMap *keymap, wmKeyMapItem *kmi)
Definition wm_keymap.cc:535
static int8_t wm_keymap_update_suppress_count
std::optional< std::string > WM_modalkeymap_operator_items_to_string(wmOperatorType *ot, const int propvalue, const bool compact)
static wmKeyMap * wm_keymap_copy(wmKeyMap *keymap)
Definition wm_keymap.cc:423
void WM_keyconfig_update_on_startup(wmWindowManager *wm)
wmKeyConfig * WM_keyconfig_new(wmWindowManager *wm, const char *idname, bool user_defined)
Definition wm_keymap.cc:291
std::optional< std::string > WM_keymap_item_raw_to_string(const int8_t shift, const int8_t ctrl, const int8_t alt, const int8_t oskey, const int8_t hyper, const short keymodifier, const short val, const short type, const bool compact)
void WM_keyconfig_update_operatortype_tag()
void WM_keymap_item_restore_to_default(wmWindowManager *wm, wmKeyMap *keymap, wmKeyMapItem *kmi)
wmKeyMapItem * WM_key_event_operator(const bContext *C, const char *opname, wmOperatorCallContext opcontext, IDProperty *properties, const short include_mask, const short exclude_mask, wmKeyMap **r_keymap)
void WM_keymap_restore_to_default(wmKeyMap *keymap, wmWindowManager *wm)
static void wm_keymap_item_properties_update_ot(wmKeyMapItem *kmi, const bool keep_properties)
Definition wm_keymap.cc:128
static void wm_keymap_item_properties_set(wmKeyMapItem *kmi)
Definition wm_keymap.cc:115
wmKeyMapItem * WM_keymap_add_item_copy(wmKeyMap *keymap, wmKeyMapItem *kmi_src)
Definition wm_keymap.cc:565
static wmKeyMap * wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap)
Definition wm_keymap.cc:743
wmKeyMap * WM_keymap_find_all_spaceid_or_empty(wmWindowManager *wm, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:912
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:929
wmKeyMap * WM_keymap_list_find_spaceid_or_empty(ListBase *lb, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:877
wmKeyMapItem * WM_key_event_operator_from_keymap(wmKeyMap *keymap, const char *opname, IDProperty *properties, const short include_mask, const short exclude_mask)
void WM_keyconfig_update(wmWindowManager *wm)
static wmKeyMapItem * wm_keymap_find_item_equals(wmKeyMap *km, wmKeyMapItem *needle)
Definition wm_keymap.cc:613
wmKeyMapItem * WM_keymap_item_find_id(wmKeyMap *keymap, int id)
static wmKeyMapItem * wm_keymap_item_find_props(const bContext *C, const char *opname, wmOperatorCallContext opcontext, IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
wmKeyMapItem * WM_modalkeymap_add_item(wmKeyMap *km, const KeyMapItem_Params *params, int value)
Definition wm_keymap.cc:969
void WM_keymap_item_properties_reset(wmKeyMapItem *kmi, IDProperty *properties)
Definition wm_keymap.cc:206
void WM_keyconfig_update_ex(wmWindowManager *wm, bool keep_properties)
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
void WM_keymap_clear(wmKeyMap *keymap)
Definition wm_keymap.cc:446
static void wm_keymap_addon_add(wmKeyMap *keymap, wmKeyMap *addonmap)
Definition wm_keymap.cc:604
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, wmOperatorCallContext opcontext, IDProperty *properties, const bool is_strict)
static wmKeyMapItem * wm_keymap_item_copy(wmKeyMapItem *kmi)
Definition wm_keymap.cc:64
const wmKeyMapItem * WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
wmKeyMap * WM_keymap_find_all(wmWindowManager *wm, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:907
static wmKeyMapItem * wm_keymap_item_find_handlers(const bContext *C, wmWindowManager *wm, wmWindow *win, ListBase *handlers, const char *opname, wmOperatorCallContext, IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km)
Definition wm_keymap.cc:680
static const char * key_event_glyph_or_text(const int font_id, const char *text, const char *single_glyph)
static wmKeyConfig * WM_keyconfig_active(wmWindowManager *wm)
Definition wm_keymap.cc:367
wmKeyConfig * WM_keyconfig_ensure(wmWindowManager *wm, const char *idname, bool user_defined)
Definition wm_keymap.cc:306
static bool wm_keymap_test_and_clear_update(wmKeyMap *km)
int WM_keymap_item_map_type_get(const wmKeyMapItem *kmi)
Definition wm_keymap.cc:223
static bool wm_keymap_is_match(const wmKeyMap *km_a, const wmKeyMap *km_b)
Definition wm_keymap.cc:504
static void wm_keymap_diff_item_free(wmKeyMapDiffItem *kmdi)
Definition wm_keymap.cc:269
static wmKeyMap * wm_keymap_preset(wmWindowManager *wm, wmKeyConfig *keyconf, wmKeyMap *km)
void WM_keyconfig_free(wmKeyConfig *keyconf)
Definition wm_keymap.cc:361
bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
Definition wm_keymap.cc:470
void WM_keyconfig_update_suppress_begin()
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
static void wm_keymap_diff_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *km)
Definition wm_keymap.cc:809
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:956
void WM_keyconfig_update_postpone_end()
wmKeyMapItem * WM_keymap_item_find_match(wmKeyMap *km_base, wmKeyMap *km_match, wmKeyMapItem *kmi_match, ReportList *reports)
std::optional< std::string > WM_modalkeymap_items_to_string(const wmKeyMap *km, const int propvalue, const bool compact)
static wmKeyMapItem * wm_keymap_find_item_equals_result(wmKeyMap *km, wmKeyMapItem *needle)
Definition wm_keymap.cc:624
void WM_keyconfig_update_suppress_end()
static bool kmi_filter_is_visible_type_mask(const wmKeyMap *km, const wmKeyMapItem *kmi, void *user_data)
wmKeyMapItem * WM_keymap_add_item(wmKeyMap *keymap, const char *idname, const KeyMapItem_Params *params)
Definition wm_keymap.cc:546
static bool kmi_filter_is_visible(const wmKeyMap *, const wmKeyMapItem *kmi, void *)
static void wm_keymap_item_clear_runtime(wmKeyMapItem *kmi)
Definition wm_keymap.cc:104
std::optional< std::string > WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
void WM_keyconfig_update_postpone_begin()
void WM_keyconfig_set_active(wmWindowManager *wm, const char *idname)
Definition wm_keymap.cc:382
const char * WM_bool_as_string(bool test)
static void wm_keymap_item_free_data(wmKeyMapItem *kmi)
Definition wm_keymap.cc:89
void WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
Definition wm_keymap.cc:462
static wmKeyMap * wm_keymap_new(const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:406
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:893
static char wm_keymap_update_suppress_flag
static const wmKeyMapItem * wm_modalkeymap_find_propvalue_iter(const wmKeyMap *km, const wmKeyMapItem *kmi, const int propvalue)
static wmKeyMapDiffItem * wm_keymap_diff_item_copy(wmKeyMapDiffItem *kmdi)
Definition wm_keymap.cc:254
static wmKeyMapItem * wm_keymap_item_find(const bContext *C, const char *opname, wmOperatorCallContext opcontext, IDProperty *properties, bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
static void wm_keymap_diff(wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km)
Definition wm_keymap.cc:635
const char * WM_key_event_string(const short type, const bool compact)
wmKeyMap * WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:864
static bool wm_keymap_item_equals(wmKeyMapItem *a, wmKeyMapItem *b)
Definition wm_keymap.cc:196
static wmKeyMapItem * wm_keymap_item_find_in_keymap(wmKeyMap *keymap, const char *opname, IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params)
wmKeyMapItem * WM_modalkeymap_add_item_str(wmKeyMap *km, const KeyMapItem_Params *params, const char *value)
Definition wm_keymap.cc:985
void WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf)
Definition wm_keymap.cc:329
void WM_keyconfig_update_tag(wmKeyMap *keymap, wmKeyMapItem *kmi)
void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
Definition wm_keymap.cc:578
bool WM_keymap_item_compare(const wmKeyMapItem *k1, const wmKeyMapItem *k2)
@ WM_KEYMAP_UPDATE_POSTPONE
@ WM_KEYMAP_UPDATE_RECONFIGURE
@ WM_KEYMAP_UPDATE_OPERATORTYPE
static bool wm_keymap_item_equals_result(wmKeyMapItem *a, wmKeyMapItem *b)
Definition wm_keymap.cc:188
static void keymap_event_set(wmKeyMapItem *kmi, const KeyMapItem_Params *params)
Definition wm_keymap.cc:510
static void wm_keymap_item_properties_update_ot_from_list(ListBase *km_lb, const bool keep_properties)
Definition wm_keymap.cc:169
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
bool WM_operator_properties_default(PointerRNA *ptr, const bool do_update)
void WM_operator_properties_create(PointerRNA *ptr, const char *opstring)
void WM_operator_properties_free(PointerRNA *ptr)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
bScreen * WM_window_get_active_screen(const wmWindow *win)