Blender V5.0
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_PRESS_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->runtime->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->runtime->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->runtime->keyconfigs, idname, offsetof(wmKeyConfig, idname)));
310 if (keyconf) {
311 if (keyconf == wm->runtime->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->runtime->keyconfigs, keyconf) != -1);
332 if (STREQLEN(U.keyconfigstr, keyconf->idname, sizeof(U.keyconfigstr))) {
333 STRNCPY(U.keyconfigstr, wm->runtime->defaultconf->idname);
334 U.runtime.is_dirty = true;
335 WM_keyconfig_update_tag(nullptr, nullptr);
336 }
337
338 BLI_remlink(&wm->runtime->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->runtime->keyconfigs, U.keyconfigstr, offsetof(wmKeyConfig, idname)));
374 if (keyconf) {
375 return keyconf;
376 }
377
378 /* Otherwise use default. */
379 return wm->runtime->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 /* Same for the asset browser keymap. */
494 !STREQ(keymap->idname, "Asset Browser Main"))
495 {
496 CLOG_WARN(WM_LOG_EVENTS, "empty keymap '%s'", keymap->idname);
497 }
498 }
499
500 if (keymap->poll != nullptr) {
501 return keymap->poll(C);
502 }
503 return true;
504}
505
506static bool wm_keymap_is_match(const wmKeyMap *km_a, const wmKeyMap *km_b)
507{
508 return ((km_a->spaceid == km_b->spaceid) && (km_a->regionid == km_b->regionid) &&
509 STREQ(km_a->idname, km_b->idname));
510}
511
513{
514 kmi->type = params->type;
515 kmi->val = params->value;
516 kmi->keymodifier = params->keymodifier;
517 kmi->direction = params->direction;
518
519 if (params->modifier == KM_ANY) {
520 kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = kmi->hyper = KM_ANY;
521 }
522 else {
523 const int8_t mod = params->modifier & 0xff;
524 const int8_t mod_any = KMI_PARAMS_MOD_FROM_ANY(params->modifier);
525
526 /* Only one of the flags should be set. */
527 BLI_assert((mod & mod_any) == 0);
528
529 kmi->shift = ((mod & KM_SHIFT) ? KM_MOD_HELD : ((mod_any & KM_SHIFT) ? KM_ANY : KM_NOTHING));
530 kmi->ctrl = ((mod & KM_CTRL) ? KM_MOD_HELD : ((mod_any & KM_CTRL) ? KM_ANY : KM_NOTHING));
531 kmi->alt = ((mod & KM_ALT) ? KM_MOD_HELD : ((mod_any & KM_ALT) ? KM_ANY : KM_NOTHING));
532 kmi->oskey = ((mod & KM_OSKEY) ? KM_MOD_HELD : ((mod_any & KM_OSKEY) ? KM_ANY : KM_NOTHING));
533 kmi->hyper = ((mod & KM_HYPER) ? KM_MOD_HELD : ((mod_any & KM_HYPER) ? KM_ANY : KM_NOTHING));
534 }
535}
536
537static void keymap_item_set_id(wmKeyMap *keymap, wmKeyMapItem *kmi)
538{
539 keymap->kmi_id++;
540 if ((keymap->flag & KEYMAP_USER) == 0) {
541 kmi->id = keymap->kmi_id;
542 }
543 else {
544 kmi->id = -keymap->kmi_id; /* User defined keymap entries have negative ids. */
545 }
546}
547
549 const char *idname,
551{
552 wmKeyMapItem *kmi = MEM_callocN<wmKeyMapItem>("keymap entry");
553
554 BLI_addtail(&keymap->items, kmi);
555 STRNCPY(kmi->idname, idname);
556
559
560 keymap_item_set_id(keymap, kmi);
561
562 WM_keyconfig_update_tag(keymap, kmi);
563
564 return kmi;
565}
566
568{
569 wmKeyMapItem *kmi_dst = wm_keymap_item_copy(kmi_src);
570
571 BLI_addtail(&keymap->items, kmi_dst);
572
573 keymap_item_set_id(keymap, kmi_dst);
574
575 WM_keyconfig_update_tag(keymap, kmi_dst);
576
577 return kmi_dst;
578}
579
581{
582 BLI_assert(BLI_findindex(&keymap->items, kmi) != -1);
583 if (kmi->ptr) {
585 MEM_delete(kmi->ptr);
586 }
587 else if (kmi->properties) {
589 }
590 BLI_freelinkN(&keymap->items, kmi);
591
592 WM_keyconfig_update_tag(keymap, nullptr);
593}
594
596
597/* -------------------------------------------------------------------- */
605
606static void wm_keymap_addon_add(wmKeyMap *keymap, wmKeyMap *addonmap)
607{
608 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &addonmap->items) {
609 wmKeyMapItem *kmi_new = wm_keymap_item_copy(kmi);
610 keymap_item_set_id(keymap, kmi_new);
611 BLI_addhead(&keymap->items, kmi_new);
612 }
613}
614
616{
617 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
618 if (wm_keymap_item_equals(kmi, needle)) {
619 return kmi;
620 }
621 }
622
623 return nullptr;
624}
625
627{
628 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
629 if (wm_keymap_item_equals_result(kmi, needle)) {
630 return kmi;
631 }
632 }
633
634 return nullptr;
635}
636
637static void wm_keymap_diff(
638 wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km)
639{
640 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &from_km->items) {
641 wmKeyMapItem *to_kmi = WM_keymap_item_find_id(to_km, kmi->id);
642
643 if (!to_kmi) {
644 /* Remove item. */
645 wmKeyMapDiffItem *kmdi = MEM_callocN<wmKeyMapDiffItem>("wmKeyMapDiffItem");
646 kmdi->remove_item = wm_keymap_item_copy(kmi);
647 BLI_addtail(&diff_km->diff_items, kmdi);
648 }
649 else if (to_kmi && !wm_keymap_item_equals(kmi, to_kmi)) {
650 /* Replace item. */
651 wmKeyMapDiffItem *kmdi = MEM_callocN<wmKeyMapDiffItem>("wmKeyMapDiffItem");
652 kmdi->remove_item = wm_keymap_item_copy(kmi);
653 kmdi->add_item = wm_keymap_item_copy(to_kmi);
654 BLI_addtail(&diff_km->diff_items, kmdi);
655 }
656
657 /* Sync expanded flag back to original so we don't lose it on re-patch. */
658 if (to_kmi) {
659 wmKeyMapItem *orig_kmi = WM_keymap_item_find_id(orig_km, kmi->id);
660
661 if (!orig_kmi && addon_km) {
662 orig_kmi = wm_keymap_find_item_equals(addon_km, kmi);
663 }
664
665 if (orig_kmi) {
666 orig_kmi->flag &= ~KMI_EXPANDED;
667 orig_kmi->flag |= (to_kmi->flag & KMI_EXPANDED);
668 }
669 }
670 }
671
672 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &to_km->items) {
673 if (kmi->id < 0) {
674 /* Add item. */
675 wmKeyMapDiffItem *kmdi = MEM_callocN<wmKeyMapDiffItem>("wmKeyMapDiffItem");
676 kmdi->add_item = wm_keymap_item_copy(kmi);
677 BLI_addtail(&diff_km->diff_items, kmdi);
678 }
679 }
680}
681
682static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km)
683{
684 LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &diff_km->diff_items) {
685 /* Find item to remove. */
686 wmKeyMapItem *kmi_remove = nullptr;
687 if (kmdi->remove_item) {
688 kmi_remove = wm_keymap_find_item_equals(km, kmdi->remove_item);
689 if (!kmi_remove) {
690 kmi_remove = wm_keymap_find_item_equals_result(km, kmdi->remove_item);
691 }
692 }
693
694 /* Add item. */
695 if (kmdi->add_item) {
696 /* Do not re-add an already existing keymap item! See #42088. */
697 /* We seek only for exact copy here! See #42137. */
698 wmKeyMapItem *kmi_add = wm_keymap_find_item_equals(km, kmdi->add_item);
699
700 /* If kmi_add is same as kmi_remove (can happen in some cases,
701 * typically when we got kmi_remove from #wm_keymap_find_item_equals_result()),
702 * no need to add or remove anything, see #45579. */
703
716 if (kmi_add != nullptr && kmi_add == kmi_remove) {
717 kmi_remove = nullptr;
718 }
719 /* Only if nothing to remove or item to remove found. */
720 else if (!kmi_add && (!kmdi->remove_item || kmi_remove)) {
721 kmi_add = wm_keymap_item_copy(kmdi->add_item);
722 kmi_add->flag |= KMI_USER_MODIFIED;
723
724 if (kmi_remove) {
725 kmi_add->flag &= ~KMI_EXPANDED;
726 kmi_add->flag |= (kmi_remove->flag & KMI_EXPANDED);
727 kmi_add->id = kmi_remove->id;
728 BLI_insertlinkbefore(&km->items, kmi_remove, kmi_add);
729 }
730 else {
731 keymap_item_set_id(km, kmi_add);
732 BLI_addtail(&km->items, kmi_add);
733 }
734 }
735 }
736
737 /* Remove item. */
738 if (kmi_remove) {
739 wm_keymap_item_free_data(kmi_remove);
740 BLI_freelinkN(&km->items, kmi_remove);
741 }
742 }
743}
744
746 wmKeyMap *defaultmap,
747 wmKeyMap *addonmap,
748 wmKeyMap *usermap)
749{
750 int expanded = 0;
751
752 /* Remove previous keymap in list, we will replace it. */
754 lb, defaultmap->idname, defaultmap->spaceid, defaultmap->regionid);
755 if (km) {
756 expanded = (km->flag & (KEYMAP_EXPANDED | KEYMAP_CHILDREN_EXPANDED));
757 WM_keymap_clear(km);
758 BLI_freelinkN(lb, km);
759 }
760
761 /* Copy new keymap from an existing one. */
762 if (usermap && !(usermap->flag & KEYMAP_DIFF)) {
763 /* For compatibility with old user preferences with non-diff
764 * keymaps we override the original entirely. */
765
766 km = wm_keymap_copy(usermap);
767
768 /* Try to find corresponding id's for items. */
769 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
770 wmKeyMapItem *orig_kmi = wm_keymap_find_item_equals(defaultmap, kmi);
771 if (!orig_kmi) {
772 orig_kmi = wm_keymap_find_item_equals_result(defaultmap, kmi);
773 }
774
775 if (orig_kmi) {
776 kmi->id = orig_kmi->id;
777 }
778 else {
779 kmi->id = -(km->kmi_id++);
780 }
781 }
782
783 km->flag |= KEYMAP_UPDATE; /* Update again to create diff. */
784 }
785 else {
786 km = wm_keymap_copy(defaultmap);
787 }
788
789 /* Add addon keymap items. */
790 if (addonmap) {
791 wm_keymap_addon_add(km, addonmap);
792 }
793
794 /* Tag as being user edited. */
795 if (usermap) {
797 }
798 km->flag |= KEYMAP_USER | expanded;
799
800 /* Apply user changes of diff keymap. */
801 if (usermap && (usermap->flag & KEYMAP_DIFF)) {
802 wm_keymap_patch(km, usermap);
803 }
804
805 /* Add to list. */
806 BLI_addtail(lb, km);
807
808 return km;
809}
810
812 wmKeyMap *defaultmap,
813 wmKeyMap *addonmap,
814 wmKeyMap *km)
815{
816 /* Create temporary default + addon keymap for diff. */
817 wmKeyMap *origmap = defaultmap;
818
819 if (addonmap) {
820 defaultmap = wm_keymap_copy(defaultmap);
821 wm_keymap_addon_add(defaultmap, addonmap);
822 }
823
824 /* Remove previous diff keymap in list, we will replace it. */
825 wmKeyMap *prevmap = WM_keymap_list_find(lb, km->idname, km->spaceid, km->regionid);
826 if (prevmap) {
827 WM_keymap_clear(prevmap);
828 BLI_freelinkN(lb, prevmap);
829 }
830
831 /* Create diff keymap. */
832 wmKeyMap *diffmap = wm_keymap_new(km->idname, km->spaceid, km->regionid);
833 diffmap->flag |= KEYMAP_DIFF;
834 if (defaultmap->flag & KEYMAP_MODAL) {
835 diffmap->flag |= KEYMAP_MODAL;
836 }
837 wm_keymap_diff(diffmap, defaultmap, km, origmap, addonmap);
838
839 /* Add to list if not empty. */
840 if (diffmap->diff_items.first) {
841 BLI_addtail(lb, diffmap);
842 }
843 else {
844 WM_keymap_clear(diffmap);
845 MEM_freeN(diffmap);
846 }
847
848 /* Free temporary default map. */
849 if (addonmap) {
850 WM_keymap_clear(defaultmap);
851 MEM_freeN(defaultmap);
852 }
853}
854
856
857/* -------------------------------------------------------------------- */
865
866wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid)
867{
868 LISTBASE_FOREACH (wmKeyMap *, km, lb) {
869 if (km->spaceid == spaceid && km->regionid == regionid) {
870 if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
871 return km;
872 }
873 }
874 }
875
876 return nullptr;
877}
878
880 const char *idname,
881 int spaceid,
882 int regionid)
883{
884 LISTBASE_FOREACH (wmKeyMap *, km, lb) {
885 if (ELEM(km->spaceid, spaceid, SPACE_EMPTY) && km->regionid == regionid) {
886 if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
887 return km;
888 }
889 }
890 }
891
892 return nullptr;
893}
894
895wmKeyMap *WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
896{
897 wmKeyMap *km = WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
898
899 if (km == nullptr) {
900 km = wm_keymap_new(idname, spaceid, regionid);
901 BLI_addtail(&keyconf->keymaps, km);
902
903 WM_keyconfig_update_tag(km, nullptr);
904 }
905
906 return km;
907}
908
909wmKeyMap *WM_keymap_find_all(wmWindowManager *wm, const char *idname, int spaceid, int regionid)
910{
911 return WM_keymap_list_find(&wm->runtime->userconf->keymaps, idname, spaceid, regionid);
912}
913
915 const char *idname,
916 int spaceid,
917 int regionid)
918{
920 &wm->runtime->userconf->keymaps, idname, spaceid, regionid);
921}
922
924
925/* -------------------------------------------------------------------- */
931
933 const char *idname,
934 const EnumPropertyItem *items)
935{
936 wmKeyMap *km = WM_keymap_ensure(keyconf, idname, SPACE_EMPTY, RGN_TYPE_WINDOW);
937 km->flag |= KEYMAP_MODAL;
938
939 /* Initialize modal items from default configuration. */
940 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
941 if (wm->runtime->defaultconf && wm->runtime->defaultconf != keyconf) {
942 wmKeyMap *defaultkm = WM_keymap_list_find(
943 &wm->runtime->defaultconf->keymaps, km->idname, SPACE_EMPTY, RGN_TYPE_WINDOW);
944
945 if (defaultkm) {
946 km->modal_items = defaultkm->modal_items;
947 km->poll = defaultkm->poll;
948 km->poll_modal_item = defaultkm->poll_modal_item;
949 }
950 }
951
952 if (items) {
953 km->modal_items = items;
954 }
955
956 return km;
957}
958
959wmKeyMap *WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
960{
961 LISTBASE_FOREACH (wmKeyMap *, km, &keyconf->keymaps) {
962 if (km->flag & KEYMAP_MODAL) {
963 if (STREQLEN(idname, km->idname, KMAP_MAX_NAME)) {
964 return km;
965 }
966 }
967 }
968
969 return nullptr;
970}
971
973{
974 wmKeyMapItem *kmi = MEM_callocN<wmKeyMapItem>("keymap entry");
975
976 BLI_addtail(&km->items, kmi);
977 kmi->propvalue = value;
978
980
981 keymap_item_set_id(km, kmi);
982
984
985 return kmi;
986}
987
990 const char *value)
991{
992 wmKeyMapItem *kmi = MEM_callocN<wmKeyMapItem>("keymap entry");
993
994 BLI_addtail(&km->items, kmi);
995 STRNCPY(kmi->propvalue_str, value);
996
998
999 keymap_item_set_id(km, kmi);
1000
1001 WM_keyconfig_update_tag(km, kmi);
1002
1003 return kmi;
1004}
1005
1007 const wmKeyMapItem *kmi,
1008 const int propvalue)
1009{
1010 if (km->flag & KEYMAP_MODAL) {
1011 kmi = static_cast<const wmKeyMapItem *>(kmi ? kmi->next : km->items.first);
1012 for (; kmi; kmi = kmi->next) {
1013 if (kmi->propvalue == propvalue) {
1014 return kmi;
1015 }
1016 }
1017 }
1018 else {
1019 BLI_assert_msg(0, "called with non modal keymap");
1020 }
1021
1022 return nullptr;
1023}
1024
1025const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
1026{
1027 return wm_modalkeymap_find_propvalue_iter(km, nullptr, propvalue);
1028}
1029
1030void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
1031{
1032 wmOperatorType *ot = WM_operatortype_find(opname, false);
1033
1034 if (ot) {
1035 ot->modalkeymap = km;
1036 }
1037 else {
1038 CLOG_ERROR(WM_LOG_OPERATORS, "unknown operator '%s' in modal keymap", opname);
1039 }
1040}
1041
1043{
1044 /* Here we convert propvalue string values delayed, due to python keymaps
1045 * being created before the actual modal keymaps, so no modal_items. */
1046
1047 if (km && (km->flag & KEYMAP_MODAL) && !km->modal_items) {
1048 if (wm->runtime->defaultconf == nullptr) {
1049 return;
1050 }
1051
1052 wmKeyMap *defaultkm = WM_keymap_list_find(
1053 &wm->runtime->defaultconf->keymaps, km->idname, SPACE_EMPTY, RGN_TYPE_WINDOW);
1054 if (!defaultkm) {
1055 return;
1056 }
1057
1058 km->modal_items = defaultkm->modal_items;
1059 km->poll = defaultkm->poll;
1060 km->poll_modal_item = defaultkm->poll_modal_item;
1061
1062 if (km->modal_items) {
1063 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
1064 if (kmi->propvalue_str[0]) {
1065 int propvalue;
1066 if (RNA_enum_value_from_id(static_cast<const EnumPropertyItem *>(km->modal_items),
1067 kmi->propvalue_str,
1068 &propvalue))
1069 {
1070 kmi->propvalue = propvalue;
1071 }
1072 kmi->propvalue_str[0] = '\0';
1073 }
1074 }
1075 }
1076 }
1077}
1078
1080
1081/* -------------------------------------------------------------------- */
1084
1085static const char *key_event_glyph_or_text(const int font_id,
1086 const char *text,
1087 const char *single_glyph)
1088{
1089 BLI_assert(single_glyph == nullptr || (BLI_strlen_utf8(single_glyph) == 1));
1090 return (single_glyph && BLF_has_glyph(font_id, BLI_str_utf8_as_unicode_or_error(single_glyph))) ?
1091 single_glyph :
1092 text;
1093}
1094
1095const char *WM_key_event_string(const short type, const bool compact)
1096{
1097 if (compact) {
1098 /* String storing a single unicode character or nullptr. */
1099 const char *single_glyph = nullptr;
1100 int font_id = BLF_default();
1101 const enum {
1102 UNIX,
1103 MACOS,
1104 MSWIN,
1105 } platform =
1106
1107#if defined(__APPLE__)
1108 MACOS
1109#elif defined(_WIN32)
1110 MSWIN
1111#else
1112 UNIX
1113#endif
1114 ;
1115
1116 switch (type) {
1117 case EVT_LEFTSHIFTKEY:
1118 case EVT_RIGHTSHIFTKEY: {
1119 if (platform == MACOS) {
1120 single_glyph = BLI_STR_UTF8_UPWARDS_WHITE_ARROW;
1121 }
1123 font_id, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Shift"), single_glyph);
1124 }
1125 case EVT_LEFTCTRLKEY:
1126 case EVT_RIGHTCTRLKEY:
1127 if (platform == MACOS) {
1129 }
1130 return IFACE_("Ctrl");
1131 case EVT_LEFTALTKEY:
1132 case EVT_RIGHTALTKEY: {
1133 if (platform == MACOS) {
1134 /* Option symbol on Mac keyboard. */
1135 single_glyph = BLI_STR_UTF8_OPTION_KEY;
1136 }
1137 return key_event_glyph_or_text(font_id, IFACE_("Alt"), single_glyph);
1138 }
1139 case EVT_OSKEY: {
1140 /* Keep these labels in sync with: `scripts/modules/rna_keymap_ui.py`. */
1141 if (platform == MACOS) {
1144 }
1145 if (platform == MSWIN) {
1148 }
1149 return IFACE_("OS");
1150 }
1151 case EVT_TABKEY:
1154 case EVT_BACKSPACEKEY:
1156 case EVT_ESCKEY:
1157 if (platform == MACOS) {
1159 }
1160 return key_event_glyph_or_text(font_id, IFACE_("Esc"), single_glyph);
1161 case EVT_RETKEY:
1163 case EVT_SPACEKEY:
1166 case EVT_LEFTARROWKEY:
1168 case EVT_UPARROWKEY:
1170 case EVT_RIGHTARROWKEY:
1172 case EVT_DOWNARROWKEY:
1174 }
1175 }
1176
1177 const EnumPropertyItem *it;
1178 const int i = RNA_enum_from_value(rna_enum_event_type_items, int(type));
1179
1180 if (i == -1) {
1181 return "";
1182 }
1184
1185 /* We first try enum items' description (abused as short-name here),
1186 * and fall back to usual name if empty. */
1187 if (compact && it->description[0]) {
1188 /* XXX No context for enum descriptions... In practice shall not be an issue though. */
1189 return IFACE_(it->description);
1190 }
1191
1193}
1194
1195std::optional<std::string> WM_keymap_item_raw_to_string(const int8_t shift,
1196 const int8_t ctrl,
1197 const int8_t alt,
1198 const int8_t oskey,
1199 const int8_t hyper,
1200 const short keymodifier,
1201 const short val,
1202 const short type,
1203 const bool compact)
1204{
1205 /* TODO: also support (some) value, like e.g. double-click? */
1207
1208 const char *space = " ";
1209
1210 /* When a modifier is #KM_ANY, it isn't shown as this would end up being overly verbose. */
1211
1212 if (shift == KM_MOD_HELD) {
1213 result_array.append(WM_key_event_string(EVT_LEFTSHIFTKEY, true));
1214 result_array.append(space);
1215 }
1216 if (ctrl == KM_MOD_HELD) {
1217 result_array.append(WM_key_event_string(EVT_LEFTCTRLKEY, true));
1218 result_array.append(space);
1219 }
1220 if (alt == KM_MOD_HELD) {
1221 result_array.append(WM_key_event_string(EVT_LEFTALTKEY, true));
1222 result_array.append(space);
1223 }
1224 if (oskey == KM_MOD_HELD) {
1225 result_array.append(WM_key_event_string(EVT_OSKEY, true));
1226 result_array.append(space);
1227 }
1228 if (hyper == KM_MOD_HELD) {
1229 result_array.append(WM_key_event_string(EVT_HYPER, true));
1230 result_array.append(space);
1231 }
1232
1233 if (keymodifier) {
1234 result_array.append(WM_key_event_string(keymodifier, compact));
1235 result_array.append(space);
1236 }
1237
1238 if (type) {
1239 if (val == KM_DBL_CLICK) {
1240 result_array.append(IFACE_("dbl-"));
1241 }
1242 else if (val == KM_PRESS_DRAG) {
1243 result_array.append(IFACE_("drag-"));
1244 }
1245 result_array.append(WM_key_event_string(type, compact));
1246 }
1247
1248 if (!result_array.is_empty() && (result_array.last() == space)) {
1249 result_array.remove_last();
1250 }
1251
1252 return fmt::to_string(fmt::join(result_array, ""));
1253}
1254
1255std::optional<std::string> WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
1256{
1258 kmi->ctrl,
1259 kmi->alt,
1260 kmi->oskey,
1261 kmi->hyper,
1262 kmi->keymodifier,
1263 kmi->val,
1264 kmi->type,
1265 compact);
1266}
1267
1268std::optional<std::string> WM_modalkeymap_items_to_string(const wmKeyMap *km,
1269 const int propvalue,
1270 const bool compact)
1271{
1272 const wmKeyMapItem *kmi;
1273 if (km == nullptr || (kmi = WM_modalkeymap_find_propvalue(km, propvalue)) == nullptr) {
1274 return std::nullopt;
1275 }
1276
1277 std::string result;
1278 do {
1279 result += WM_keymap_item_to_string(kmi, compact).value_or("");
1280
1281 if ((kmi = wm_modalkeymap_find_propvalue_iter(km, kmi, propvalue)) == nullptr) {
1282 break;
1283 }
1284 result += '/';
1285 } while (true);
1286
1287 return result;
1288}
1289
1291 const int propvalue,
1292 const bool compact)
1293{
1294 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
1295 wmKeyMap *keymap = WM_keymap_active(wm, ot->modalkeymap);
1296 return WM_modalkeymap_items_to_string(keymap, propvalue, compact);
1297}
1298
1300
1301/* -------------------------------------------------------------------- */
1304
1306 const char *opname,
1307 IDProperty *properties,
1308 const bool is_strict,
1310{
1311 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
1312 /* Skip disabled keymap items, see: #38447. */
1313 if (kmi->flag & KMI_INACTIVE) {
1314 continue;
1315 }
1316 if (!STREQ(kmi->idname, opname)) {
1317 continue;
1318 }
1319
1320 bool kmi_match = false;
1321 if (properties) {
1322/* Example of debugging keymaps. */
1323#if 0
1324 if (kmi->ptr) {
1325 if (STREQ("MESH_OT_rip_move", opname)) {
1326 printf("OPERATOR\n");
1327 IDP_print(properties);
1328 printf("KEYMAP\n");
1329 IDP_print(kmi->ptr->data);
1330 }
1331 }
1332#endif
1333
1334 if (kmi->ptr && IDP_EqualsProperties_ex(
1335 properties, static_cast<const IDProperty *>(kmi->ptr->data), is_strict))
1336 {
1337 kmi_match = true;
1338 }
1339 /* Debug only, helps spotting mismatches between menu entries and shortcuts! */
1340 else if (G.debug & G_DEBUG_WM) {
1341 if (is_strict && kmi->ptr) {
1342 wmOperatorType *ot = WM_operatortype_find(opname, true);
1343 if (ot) {
1344 /* Make a copy of the properties and set unset ones to their default values. */
1345 IDProperty *properties_default = IDP_CopyProperty(
1346 static_cast<const IDProperty *>(kmi->ptr->data));
1347
1348 PointerRNA opptr = RNA_pointer_create_discrete(nullptr, ot->srna, properties_default);
1349 WM_operator_properties_default(&opptr, true);
1350
1351 if (IDP_EqualsProperties_ex(properties, properties_default, is_strict)) {
1352 std::string kmi_str = WM_keymap_item_to_string(kmi, false).value_or("");
1353 /* NOTE: given properties could come from other things than menu entry. */
1354 printf(
1355 "%s: Some set values in menu entry match default op values, "
1356 "this might not be desired!\n",
1357 opname);
1358 printf("\tkm: '%s', kmi: '%s'\n", keymap->idname, kmi_str.c_str());
1359#ifndef NDEBUG
1360# ifdef WITH_PYTHON
1361 printf("OPERATOR\n");
1362 IDP_print(properties);
1363 printf("KEYMAP\n");
1364 IDP_print(static_cast<IDProperty *>(kmi->ptr->data));
1365# endif
1366#endif
1367 printf("\n");
1368 }
1369
1370 IDP_FreeProperty(properties_default);
1371 }
1372 }
1373 }
1374 }
1375 else {
1376 kmi_match = true;
1377 }
1378
1379 if (kmi_match) {
1380 if ((params == nullptr) || params->filter_fn(keymap, kmi, params->user_data)) {
1381 return kmi;
1382 }
1383 }
1384 }
1385 return nullptr;
1386}
1387
1389 wmWindowManager *wm,
1390 wmWindow *win,
1391 ListBase *handlers,
1392 const char *opname,
1393 blender::wm::OpCallContext /*opcontext*/,
1394 IDProperty *properties,
1395 const bool is_strict,
1397 wmKeyMap **r_keymap)
1398{
1399 /* Find keymap item in handlers. */
1400 LISTBASE_FOREACH (wmEventHandler *, handler_base, handlers) {
1401 if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
1402 wmEventHandler_Keymap *handler = (wmEventHandler_Keymap *)handler_base;
1404 WM_event_get_keymaps_from_handler(wm, win, handler, &km_result);
1405 for (int km_index = 0; km_index < km_result.keymaps_len; km_index++) {
1406 wmKeyMap *keymap = km_result.keymaps[km_index];
1407 if (WM_keymap_poll((bContext *)C, keymap)) {
1409 keymap, opname, properties, is_strict, params);
1410 if (kmi != nullptr) {
1411 if (r_keymap) {
1412 *r_keymap = keymap;
1413 }
1414 return kmi;
1415 }
1416 }
1417 }
1418 }
1419 }
1420 /* Ensure un-initialized keymap is never used. */
1421 if (r_keymap) {
1422 *r_keymap = nullptr;
1423 }
1424 return nullptr;
1425}
1426
1428 const char *opname,
1430 IDProperty *properties,
1431 const bool is_strict,
1433 wmKeyMap **r_keymap)
1434{
1436 wmWindow *win = CTX_wm_window(C);
1437 ScrArea *area = CTX_wm_area(C);
1438 ARegion *region = CTX_wm_region(C);
1439 wmKeyMapItem *found = nullptr;
1440
1441 /* Look into multiple handler lists to find the item. */
1442 if (win) {
1444 wm,
1445 win,
1446 &win->modalhandlers,
1447 opname,
1448 opcontext,
1449 properties,
1450 is_strict,
1451 params,
1452 r_keymap);
1453 if (found == nullptr) {
1455 C, wm, win, &win->handlers, opname, opcontext, properties, is_strict, params, r_keymap);
1456 }
1457 }
1458
1459 if (area && found == nullptr) {
1461 C, wm, win, &area->handlers, opname, opcontext, properties, is_strict, params, r_keymap);
1462 }
1463
1464 if (found == nullptr) {
1465 if (ELEM(opcontext,
1468 {
1469 if (area) {
1470 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
1472 }
1473
1474 if (region) {
1476 wm,
1477 win,
1478 &region->runtime->handlers,
1479 opname,
1480 opcontext,
1481 properties,
1482 is_strict,
1483 params,
1484 r_keymap);
1485 }
1486 }
1487 }
1488 else if (ELEM(opcontext,
1491 {
1492 if (!(region && region->regiontype == RGN_TYPE_CHANNELS)) {
1494 }
1495
1496 if (region) {
1498 wm,
1499 win,
1500 &region->runtime->handlers,
1501 opname,
1502 opcontext,
1503 properties,
1504 is_strict,
1505 params,
1506 r_keymap);
1507 }
1508 }
1509 else if (ELEM(opcontext,
1512 {
1513 if (!(region && region->regiontype == RGN_TYPE_PREVIEW)) {
1515 }
1516
1517 if (region) {
1519 wm,
1520 win,
1521 &region->runtime->handlers,
1522 opname,
1523 opcontext,
1524 properties,
1525 is_strict,
1526 params,
1527 r_keymap);
1528 }
1529 }
1530 else {
1531 if (region) {
1533 wm,
1534 win,
1535 &region->runtime->handlers,
1536 opname,
1537 opcontext,
1538 properties,
1539 is_strict,
1540 params,
1541 r_keymap);
1542 }
1543 }
1544 }
1545
1546 return found;
1547}
1548
1550 const char *opname,
1552 IDProperty *properties,
1553 bool is_strict,
1555 wmKeyMap **r_keymap)
1556{
1557 /* XXX Hack! Macro operators in menu entry have their whole props defined,
1558 * which is not the case for relevant keymap entries.
1559 * Could be good to check and harmonize this,
1560 * but for now always compare non-strict in this case. */
1561 wmOperatorType *ot = WM_operatortype_find(opname, true);
1562 if (ot) {
1563 is_strict = is_strict && ((ot->flag & OPTYPE_MACRO) == 0);
1564 }
1565
1567 C, opname, opcontext, properties, is_strict, params, r_keymap);
1568
1569 /* This block is *only* useful in one case: when op uses an enum menu in its prop member
1570 * (then, we want to rerun a comparison with that 'prop' unset). Note this remains brittle,
1571 * since now any enum prop may be used in UI (specified by name), ot->prop is not so much used...
1572 * Otherwise:
1573 * * If non-strict, unset properties always match set ones in IDP_EqualsProperties_ex.
1574 * * If strict, unset properties never match set ones in IDP_EqualsProperties_ex,
1575 * and we do not want that to change (else we get things like #41757)!
1576 * ...so in either case, re-running a comparison with unset props set to default is useless.
1577 */
1578 if (!found && properties) {
1579 if (ot && ot->prop) { /* XXX Shall we also check ot->prop is actually an enum? */
1580 /* Make a copy of the properties and unset the 'ot->prop' one if set. */
1581 IDProperty *properties_temp = IDP_CopyProperty(properties);
1582
1583 PointerRNA opptr = RNA_pointer_create_discrete(nullptr, ot->srna, properties_temp);
1584
1585 if (RNA_property_is_set(&opptr, ot->prop)) {
1586 /* For operator that has enum menu,
1587 * unset it so its value does not affect comparison result. */
1588 RNA_property_unset(&opptr, ot->prop);
1589
1591 C, opname, opcontext, properties_temp, is_strict, params, r_keymap);
1592 }
1593
1594 IDP_FreeProperty(properties_temp);
1595 }
1596 }
1597
1598 /* Debug only, helps spotting mismatches between menu entries and shortcuts! */
1599 if (G.debug & G_DEBUG_WM) {
1600 if (!found && is_strict && properties) {
1601 if (ot) {
1602 /* Make a copy of the properties and set unset ones to their default values. */
1603 IDProperty *properties_default = IDP_CopyProperty(properties);
1604
1605 PointerRNA opptr = RNA_pointer_create_discrete(nullptr, ot->srna, properties_default);
1606 WM_operator_properties_default(&opptr, true);
1607
1608 wmKeyMap *km;
1610 C, opname, opcontext, properties_default, is_strict, params, &km);
1611 if (kmi) {
1612 std::string kmi_str = WM_keymap_item_to_string(kmi, false).value_or("");
1613 printf(
1614 "%s: Some set values in keymap entry match default op values, "
1615 "this might not be desired!\n",
1616 opname);
1617 printf("\tkm: '%s', kmi: '%s'\n", km->idname, kmi_str.c_str());
1618#ifndef NDEBUG
1619# ifdef WITH_PYTHON
1620 printf("OPERATOR\n");
1621 IDP_print(properties);
1622 printf("KEYMAP\n");
1623 IDP_print(static_cast<IDProperty *>(kmi->ptr->data));
1624# endif
1625#endif
1626 printf("\n");
1627 }
1628
1629 IDP_FreeProperty(properties_default);
1630 }
1631 }
1632 }
1633
1634 return found;
1635}
1636
1637static bool kmi_filter_is_visible(const wmKeyMap * /*km*/,
1638 const wmKeyMapItem *kmi,
1639 void * /*user_data*/)
1640{
1641 return ((WM_key_event_string(kmi->type, false)[0] != '\0') &&
1642 (IS_EVENT_ACTIONZONE(kmi->type) == false));
1643}
1644
1645std::optional<std::string> WM_key_event_operator_string(const bContext *C,
1646 const char *opname,
1648 IDProperty *properties,
1649 const bool is_strict)
1650{
1652 params.filter_fn = kmi_filter_is_visible;
1653 params.user_data = nullptr;
1655 C, opname, opcontext, properties, is_strict, &params, nullptr);
1656 if (kmi) {
1657 return WM_keymap_item_to_string(kmi, false);
1658 }
1659
1660 return std::nullopt;
1661}
1662
1664 const wmKeyMapItem *kmi,
1665 void *user_data)
1666{
1667 short *mask_pair = static_cast<short int *>(user_data);
1668 return ((WM_event_type_mask_test(kmi->type, eEventType_Mask(mask_pair[0])) == true) &&
1669 (WM_event_type_mask_test(kmi->type, eEventType_Mask(mask_pair[1])) == false) &&
1670 kmi_filter_is_visible(km, kmi, user_data));
1671}
1672
1674 const char *opname,
1676 IDProperty *properties,
1677 const short include_mask,
1678 const short exclude_mask,
1679 wmKeyMap **r_keymap)
1680{
1681 short user_data_mask[2] = {include_mask, exclude_mask};
1682 bool use_mask = (include_mask != EVT_TYPE_MASK_ALL) || (exclude_mask != 0);
1685 params.user_data = use_mask ? user_data_mask : nullptr;
1686 return wm_keymap_item_find(C, opname, opcontext, properties, true, &params, r_keymap);
1687}
1688
1690 const char *opname,
1691 IDProperty *properties,
1692 const short include_mask,
1693 const short exclude_mask)
1694{
1695 short user_data_mask[2] = {include_mask, exclude_mask};
1696 bool use_mask = (include_mask != EVT_TYPE_MASK_ALL) || (exclude_mask != 0);
1699 params.user_data = use_mask ? user_data_mask : nullptr;
1700
1701 return wm_keymap_item_find_in_keymap(keymap, opname, properties, true, &params);
1702}
1703
1705{
1706 if (k1->flag & KMI_INACTIVE || k2->flag & KMI_INACTIVE) {
1707 return false;
1708 }
1709
1710 /* Take event mapping into account. */
1711 int k1type = WM_userdef_event_map(k1->type);
1712 int k2type = WM_userdef_event_map(k2->type);
1713
1714 if (k1type != KM_ANY && k2type != KM_ANY && k1type != k2type) {
1715 return false;
1716 }
1717
1718 if (k1->val != KM_ANY && k2->val != KM_ANY) {
1719 /* Take click, press, release conflict into account. */
1720 if (k1->val == KM_CLICK && ELEM(k2->val, KM_PRESS, KM_RELEASE, KM_CLICK) == 0) {
1721 return false;
1722 }
1723 if (k2->val == KM_CLICK && ELEM(k1->val, KM_PRESS, KM_RELEASE, KM_CLICK) == 0) {
1724 return false;
1725 }
1726 if (k1->val != k2->val) {
1727 return false;
1728 }
1729 if (k1->val == KM_PRESS_DRAG && (k1->direction != k2->direction)) {
1730 return false;
1731 }
1732 }
1733
1734 if (k1->shift != KM_ANY && k2->shift != KM_ANY && k1->shift != k2->shift) {
1735 return false;
1736 }
1737
1738 if (k1->ctrl != KM_ANY && k2->ctrl != KM_ANY && k1->ctrl != k2->ctrl) {
1739 return false;
1740 }
1741
1742 if (k1->alt != KM_ANY && k2->alt != KM_ANY && k1->alt != k2->alt) {
1743 return false;
1744 }
1745
1746 if (k1->oskey != KM_ANY && k2->oskey != KM_ANY && k1->oskey != k2->oskey) {
1747 return false;
1748 }
1749
1750 if (k1->hyper != KM_ANY && k2->hyper != KM_ANY && k1->hyper != k2->hyper) {
1751 return false;
1752 }
1753
1754 if (k1->keymodifier != k2->keymodifier) {
1755 return false;
1756 }
1757
1758 return true;
1759}
1760
1762
1763/* -------------------------------------------------------------------- */
1770
1771/* So operator removal can trigger update. */
1772enum {
1774
1775 /* Ensure all wmKeyMap have their operator types validated after removing an operator. */
1777
1779};
1780
1782
1784#ifndef NDEBUG
1786#endif
1787
1789{
1790 /* Quick tag to do delayed keymap updates. */
1792
1793 if (keymap) {
1794 keymap->flag |= KEYMAP_UPDATE;
1795 }
1796 if (kmi) {
1797 kmi->flag |= KMI_UPDATE;
1798 }
1799}
1800
1805
1806/* NOTE(@ideasman42): regarding suppressing updates.
1807 * If this becomes a common operation it would be better use something more general,
1808 * a key-map flag for example to signify that the key-map is stored outside of a #wmKeyConfig
1809 * and should not receive updates on modification. At the moment this has the down-side of
1810 * needing to be supported in quite a few places for something which isn't used much.
1811 * Since the use case for this is limited, add functions to begin/end suppression.
1812 * If these end up being used a lot we can consider alternatives. */
1813
1822
1832
1837
1842
1844{
1845 int update = (km->flag & KEYMAP_UPDATE);
1846 km->flag &= ~KEYMAP_UPDATE;
1847
1848 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
1849 update = update || (kmi->flag & KMI_UPDATE);
1850 kmi->flag &= ~KMI_UPDATE;
1851 }
1852
1853 return (update != 0);
1854}
1855
1857{
1858 BLI_assert(keyconf == WM_keyconfig_active(wm));
1859 wmKeyMap *keymap = WM_keymap_list_find(&keyconf->keymaps, km->idname, km->spaceid, km->regionid);
1860 if (!keymap && wm->runtime->defaultconf) {
1861 keymap = WM_keymap_list_find(
1862 &wm->runtime->defaultconf->keymaps, km->idname, km->spaceid, km->regionid);
1863 }
1864
1865 return keymap;
1866}
1867
1869{
1870 /* Ignore #WM_KEYMAP_UPDATE_OPERATORTYPE flag on startup,
1871 * it's likely to be enabled because it's set when registering any operator
1872 * however running this is unnecessary since the key-map hasn't been initialized.
1873 * It's harmless but would add redundant initialization every startup. */
1875
1876 WM_keyconfig_update_ex(wm, false);
1877}
1878
1880{
1881 WM_keyconfig_update_ex(wm, false);
1882}
1883
1884void WM_keyconfig_update_ex(wmWindowManager *wm, bool keep_properties)
1885{
1886 if (wm_keymap_update_flag == 0) {
1887 return;
1888 }
1889
1890 bool compat_update = false;
1891
1892 /* Update drop-boxes when the operators have been added or removed. While this isn't an ideal
1893 * place to update drop-boxes, they share characteristics with key-map items.
1894 * We could consider renaming this to API function so it's not only relating to keymaps. */
1895 bool dropbox_update = false;
1896
1897 /* Postpone update until after the key-map has been initialized
1898 * to ensure add-ons have been loaded, see: #113603. */
1900 return;
1901 }
1902
1904 /* One or more operator-types have been removed, this won't happen often
1905 * but when it does we have to check _every_ key-map item. */
1906 wm_keymap_item_properties_update_ot_from_list(&U.user_keymaps, keep_properties);
1907 LISTBASE_FOREACH (wmKeyConfig *, kc, &wm->runtime->keyconfigs) {
1908 wm_keymap_item_properties_update_ot_from_list(&kc->keymaps, keep_properties);
1909 }
1910
1911 /* An operator has been removed, refresh. */
1912 dropbox_update = true;
1913
1915 }
1916
1918 wmKeyConfig *kc_active = WM_keyconfig_active(wm);
1919
1920 /* Update operator properties for non-modal user keymaps. */
1921 LISTBASE_FOREACH (wmKeyMap *, km, &U.user_keymaps) {
1922 if ((km->flag & KEYMAP_MODAL) == 0) {
1923 LISTBASE_FOREACH (wmKeyMapDiffItem *, kmdi, &km->diff_items) {
1924 if (kmdi->add_item) {
1925 wm_keymap_item_properties_set(kmdi->add_item);
1926 }
1927 if (kmdi->remove_item) {
1928 wm_keymap_item_properties_set(kmdi->remove_item);
1929 }
1930 }
1931
1932 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &km->items) {
1934 }
1935 }
1936 }
1937
1938 /* Update `U.user_keymaps` with user key configuration changes. */
1939 LISTBASE_FOREACH (wmKeyMap *, km, &wm->runtime->userconf->keymaps) {
1940 /* Only diff if the user keymap was modified. */
1942 /* Find keymaps. */
1943 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, km);
1944 wmKeyMap *addonmap = WM_keymap_list_find(
1945 &wm->runtime->addonconf->keymaps, km->idname, km->spaceid, km->regionid);
1946
1947 /* Diff. */
1948 if (defaultmap) {
1949 wm_keymap_diff_update(&U.user_keymaps, defaultmap, addonmap, km);
1950 }
1951 }
1952 }
1953
1954 /* Create user key configuration from preset + addon + user preferences. */
1955 LISTBASE_FOREACH (wmKeyMap *, km, &wm->runtime->defaultconf->keymaps) {
1956 /* Find keymaps. */
1957 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, km);
1958 wmKeyMap *addonmap = WM_keymap_list_find(
1959 &wm->runtime->addonconf->keymaps, km->idname, km->spaceid, km->regionid);
1960 wmKeyMap *usermap = WM_keymap_list_find(
1961 &U.user_keymaps, km->idname, km->spaceid, km->regionid);
1962
1963 /* For now only the default map defines modal key-maps,
1964 * if we support modal keymaps for 'addonmap', these will need to be enabled too. */
1965 wm_user_modal_keymap_set_items(wm, defaultmap);
1966
1967 /* Add. */
1969 &wm->runtime->userconf->keymaps, defaultmap, addonmap, usermap);
1970
1971 if (kmn) {
1972 kmn->modal_items = km->modal_items;
1973 kmn->poll = km->poll;
1974 kmn->poll_modal_item = km->poll_modal_item;
1975 }
1976
1977 /* In case of old non-diff keymaps, force extra update to create diffs. */
1978 compat_update = compat_update || (usermap && !(usermap->flag & KEYMAP_DIFF));
1979 }
1980
1981 /* An operator may have been added, refresh. */
1982 dropbox_update = true;
1983
1985 }
1986
1988
1989 if (compat_update) {
1990 WM_keyconfig_update_tag(nullptr, nullptr);
1992 }
1993
1994 if (dropbox_update) {
1996 }
1997
1998 /* NOTE(@ideasman42): open preferences will contain "stale" #wmKeyMapItem data.
1999 *
2000 * The common case this solves is using Blender with the key-map editor open,
2001 * an action in the view-port for example may manipulate the key-map causing it to be rebuilt.
2002 * Later interaction with the key-map editor may then attempt to access freed data.
2003 *
2004 * Take care, this is _not_ fool proof because it's possible:
2005 * - Key-map options to be shown in any region (using scripts).
2006 * - Key-map re-generation could happen while the preferences is open,
2007 * where the data becomes stale before the UI has a chance to redraw.
2008 *
2009 * In practice both cases are quite unlikely though. */
2010 if (U.space_data.section_active == USER_SECTION_KEYMAP) {
2011 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2012 bScreen *screen = WM_window_get_active_screen(win);
2013 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
2014 if (area->spacetype == SPACE_USERPREF) {
2015 ED_area_tag_redraw(area);
2016 }
2017 }
2018 }
2019 }
2020}
2021
2023
2024/* -------------------------------------------------------------------- */
2030
2032{
2033 if (!keymap) {
2034 return nullptr;
2035 }
2036
2037 /* First user defined keymaps. */
2039 &wm->runtime->userconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
2040
2041 if (km) {
2042 return km;
2043 }
2044
2045 return keymap;
2046}
2047
2049
2050/* -------------------------------------------------------------------- */
2055
2057{
2058 if (!keymap) {
2059 return;
2060 }
2061
2062 /* Construct default keymap from preset + addons. */
2063 wmKeyConfig *kc_active = WM_keyconfig_active(wm);
2064 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, keymap);
2065 wmKeyMap *addonmap = WM_keymap_list_find(
2066 &wm->runtime->addonconf->keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
2067
2068 if (addonmap) {
2069 defaultmap = wm_keymap_copy(defaultmap);
2070 wm_keymap_addon_add(defaultmap, addonmap);
2071 }
2072
2073 /* Find original item. */
2074 wmKeyMapItem *orig = WM_keymap_item_find_id(defaultmap, kmi->id);
2075
2076 if (orig) {
2077 /* Restore to original. */
2078 if (!STREQ(orig->idname, kmi->idname)) {
2079 STRNCPY(kmi->idname, orig->idname);
2080 WM_keymap_item_properties_reset(kmi, nullptr);
2081 }
2082
2083 if (orig->properties) {
2084 if (kmi->properties) {
2086 kmi->properties = nullptr;
2087 }
2088
2090 if (kmi->ptr) {
2091 kmi->ptr->data = kmi->properties;
2092 }
2093 }
2094
2095 kmi->propvalue = orig->propvalue;
2096 kmi->type = orig->type;
2097 kmi->val = orig->val;
2098 kmi->shift = orig->shift;
2099 kmi->ctrl = orig->ctrl;
2100 kmi->alt = orig->alt;
2101 kmi->oskey = orig->oskey;
2102 kmi->hyper = orig->hyper;
2103 kmi->keymodifier = orig->keymodifier;
2104 kmi->maptype = orig->maptype;
2105 kmi->flag = (kmi->flag & ~(KMI_REPEAT_IGNORE | KMI_INACTIVE)) |
2106 (orig->flag & (KMI_REPEAT_IGNORE | KMI_INACTIVE));
2107
2108 WM_keyconfig_update_tag(keymap, kmi);
2109 }
2110
2111 /* Free temporary keymap. */
2112 if (addonmap) {
2113 WM_keymap_clear(defaultmap);
2114 MEM_freeN(defaultmap);
2115 }
2116}
2117
2119{
2120 /* Remove keymap from U.user_keymaps and update. */
2121 wmKeyMap *usermap = WM_keymap_list_find(
2122 &U.user_keymaps, keymap->idname, keymap->spaceid, keymap->regionid);
2123
2124 if (usermap) {
2125 WM_keymap_clear(usermap);
2126 BLI_freelinkN(&U.user_keymaps, usermap);
2127
2128 WM_keyconfig_update_tag(nullptr, nullptr);
2130 }
2131}
2132
2133const char *WM_bool_as_string(bool test)
2134{
2135 return test ? IFACE_("ON") : IFACE_("OFF");
2136}
2137
2139
2140/* -------------------------------------------------------------------- */
2143
2145{
2146 LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
2147 if (kmi->id == id) {
2148 return kmi;
2149 }
2150 }
2151
2152 return nullptr;
2153}
2154
2156 wmKeyMap *km_match,
2157 wmKeyMapItem *kmi_match,
2158 ReportList *reports)
2159{
2160 /* NOTE: this is called by RNA, some of the reports in this function
2161 * would be asserts when called from C++. */
2162
2163 if (wm_keymap_update_flag != 0) {
2164 /* NOTE: this could be limited to the key-maps marked for updating.
2165 * However #KEYMAP_UPDATE is only cleared for `wm->runtime->userconf`
2166 * so only check the global flag for now.
2167 *
2168 * Use a warning not an error because scripts cannot prevent other scripts from manipulating
2169 * key-map items, so we won't want scripts to create exceptions in unrelated scripts.
2170 * Ideally we could detect which key-maps have been modified. */
2171 BKE_reportf(reports,
2173 "KeyMap item result may be incorrect since an update is pending, call "
2174 "`context.window_manager.keyconfigs.update()` to ensure matches can be found.");
2175 }
2176
2177 if (km_base == km_match) {
2178 /* We could also return `kmi_match` (it's technically correct)
2179 * however this is almost certainly API misuse (as it's a no-op). */
2180 BKE_report(reports, RPT_ERROR, "KeyMaps are equal");
2181 return nullptr;
2182 }
2183
2184 const char *idname = km_base->idname;
2185 const short spaceid = km_base->spaceid;
2186 const short regionid = km_base->regionid;
2187
2188 if (!wm_keymap_is_match(km_base, km_match)) {
2190 reports, RPT_ERROR, "KeyMap \"%s\" does not match \"%s\"", idname, km_match->idname);
2191 return nullptr;
2192 }
2193
2194 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
2195 wmKeyConfig *kc_active = WM_keyconfig_active(wm);
2196
2197 /* NOTE: the key-maps could store this, it would simplify checks here. */
2198 enum {
2199 KM_TYPE_UNKNOWN = 0,
2200 KM_TYPE_USER,
2201 KM_TYPE_ADDON,
2202 KM_TYPE_ACTIVE,
2203 /* No support yet for preferences. */
2204 } base_type = KM_TYPE_UNKNOWN,
2205 match_type = KM_TYPE_UNKNOWN;
2206
2207 if (km_base->flag & KEYMAP_USER) {
2208 if (km_base == WM_keymap_list_find(&wm->runtime->userconf->keymaps, idname, spaceid, regionid))
2209 {
2210 base_type = KM_TYPE_USER;
2211 }
2212 }
2213
2214 if ((km_match->flag & KEYMAP_USER) == 0) {
2215 if (km_match ==
2216 WM_keymap_list_find(&wm->runtime->addonconf->keymaps, idname, spaceid, regionid))
2217 {
2218 match_type = KM_TYPE_ADDON;
2219 }
2220 else if (km_match == WM_keymap_list_find(&kc_active->keymaps, idname, spaceid, regionid)) {
2221 match_type = KM_TYPE_ACTIVE;
2222 }
2223 }
2224
2225 if (base_type == KM_TYPE_UNKNOWN) {
2226 BKE_reportf(reports, RPT_ERROR, "KeyMap \"%s\" (base) must be a user keymap", idname);
2227 return nullptr;
2228 }
2229
2230 if (match_type == KM_TYPE_UNKNOWN) {
2232 reports, RPT_ERROR, "KeyMap \"%s\" (other) must be an add-on or active keymap", idname);
2233 return nullptr;
2234 }
2235
2236 const int kmi_index = BLI_findindex(&km_match->items, kmi_match);
2237 if (kmi_index == -1) {
2238 BKE_reportf(reports, RPT_ERROR, "KeyMap \"%s\" item not part of the keymap", idname);
2239 return nullptr;
2240 }
2241
2242 int kmi_id;
2243 if (match_type == KM_TYPE_ADDON) {
2244 /* Perform the following lookup that calculates the ID that *would* be used
2245 * if the user key-map was re-created, see: #WM_keymap_item_restore_to_default.
2246 *
2247 * Find the index of the key-map item and add this to the `defaultmap`'s key-map index
2248 * since this is how the "user" key-map ID's are generated.
2249 *
2250 * This is needed so add-ons can show the user key-map items in preferences. */
2251
2252 wmKeyMap *defaultmap = wm_keymap_preset(wm, kc_active, km_base);
2253 if (defaultmap == nullptr) {
2254 /* This should practically never fail, it could be caused by failure
2255 * to refresh the user key-map after manipulating the add-on key-map. */
2256 return nullptr;
2257 }
2258 kmi_id = defaultmap->kmi_id + kmi_index + 1;
2259 }
2260 else {
2261 kmi_id = kmi_match->id;
2262 }
2263
2264 /* Returning null here isn't an error because it's possible there is no match. */
2265 return WM_keymap_item_find_id(km_base, kmi_id);
2266}
2267
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)
@ G_DEBUG_WM
#define G_MAIN
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1251
bool IDP_EqualsProperties_ex(const IDProperty *prop1, const IDProperty *prop2, bool is_strict) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:913
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:863
void IDP_print(const IDProperty *prop)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_ERROR
Definition BKE_report.hh:39
@ RPT_WARNING
Definition BKE_report.hh:38
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:846
bool BKE_workspace_owner_id_check(const WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
Definition workspace.cc:537
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:693
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:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
@ 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:693
Read Guarded memory(de)allocation.
@ RNA_EQ_UNSET_MATCH_NONE
#define C
Definition RandGen.cpp:29
#define KMI_PARAMS_MOD_FROM_ANY(mod)
Definition WM_keymap.hh:89
@ KM_CTRL
Definition WM_types.hh:279
@ KM_ALT
Definition WM_types.hh:280
@ KM_HYPER
Definition WM_types.hh:292
@ KM_OSKEY
Definition WM_types.hh:282
@ KM_SHIFT
Definition WM_types.hh:278
CLG_LogRef * WM_LOG_OPERATORS
@ KM_TEXTINPUT
Definition WM_types.hh:304
@ KM_NOTHING
Definition WM_types.hh:310
@ KM_ANY
Definition WM_types.hh:309
@ KM_PRESS
Definition WM_types.hh:311
@ KM_DBL_CLICK
Definition WM_types.hh:314
@ KM_PRESS_DRAG
Definition WM_types.hh:319
@ KM_RELEASE
Definition WM_types.hh:312
@ KM_CLICK
Definition WM_types.hh:313
CLG_LogRef * WM_LOG_EVENTS
@ OPTYPE_MACRO
Definition WM_types.hh:185
#define KM_MOD_HELD
Definition WM_types.hh:326
#define U
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
#define offsetof(t, d)
#define printf(...)
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
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:661
const char * description
Definition RNA_types.hh:663
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
WindowManagerRuntimeHandle * runtime
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:4237
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:537
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_key_event_operator_string(const bContext *C, const char *opname, blender::wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
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)
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:567
static wmKeyMap * wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKeyMap *addonmap, wmKeyMap *usermap)
Definition wm_keymap.cc:745
static wmKeyMapItem * wm_keymap_item_find_handlers(const bContext *C, wmWindowManager *wm, wmWindow *win, ListBase *handlers, const char *opname, blender::wm::OpCallContext, IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
wmKeyMap * WM_keymap_find_all_spaceid_or_empty(wmWindowManager *wm, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:914
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:932
wmKeyMap * WM_keymap_list_find_spaceid_or_empty(ListBase *lb, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:879
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:615
wmKeyMapItem * WM_keymap_item_find_id(wmKeyMap *keymap, int id)
wmKeyMapItem * WM_modalkeymap_add_item(wmKeyMap *km, const KeyMapItem_Params *params, int value)
Definition wm_keymap.cc:972
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:606
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:909
static void wm_keymap_patch(wmKeyMap *km, wmKeyMap *diff_km)
Definition wm_keymap.cc:682
@ WM_KEYMAP_UPDATE_POSTPONE
@ WM_KEYMAP_UPDATE_RECONFIGURE
@ WM_KEYMAP_UPDATE_OPERATORTYPE
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)
static wmKeyMapItem * wm_keymap_item_find(const bContext *C, const char *opname, blender::wm::OpCallContext opcontext, IDProperty *properties, bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
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:506
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:811
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:959
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_item_find_props(const bContext *C, const char *opname, blender::wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict, const wmKeyMapItemFind_Params *params, wmKeyMap **r_keymap)
static wmKeyMapItem * wm_keymap_find_item_equals_result(wmKeyMap *km, wmKeyMapItem *needle)
Definition wm_keymap.cc:626
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:548
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:895
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 void wm_keymap_diff(wmKeyMap *diff_km, wmKeyMap *from_km, wmKeyMap *to_km, wmKeyMap *orig_km, wmKeyMap *addon_km)
Definition wm_keymap.cc:637
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:866
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:988
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:580
bool WM_keymap_item_compare(const wmKeyMapItem *k1, const wmKeyMapItem *k2)
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:512
static void wm_keymap_item_properties_update_ot_from_list(ListBase *km_lb, const bool keep_properties)
Definition wm_keymap.cc:169
wmKeyMapItem * WM_key_event_operator(const bContext *C, const char *opname, blender::wm::OpCallContext opcontext, IDProperty *properties, const short include_mask, const short exclude_mask, wmKeyMap **r_keymap)
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)