Blender V5.3
wm_event_system.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
12
13#include <cstdlib>
14#include <cstring>
15#include <fmt/format.h>
16
17#include "AS_asset_library.hh"
19
20#include "DNA_listBase.h"
21#include "DNA_scene_types.h"
22#include "DNA_screen_types.h"
23#include "DNA_userdef_types.h"
25
26#include "MEM_guardedalloc.h"
27
28#include "CLG_log.h"
29
30#include "GHOST_ISystem.hh"
31
32#include "BLI_enum_flags.hh"
33#include "BLI_ghash.hh"
34#include "BLI_listbase.hh"
35#include "BLI_math_vector_c.hh"
36#include "BLI_string.hh"
37#include "BLI_string_utf8.hh"
38#include "BLI_timer.hh"
39
40#include "BKE_context.hh"
41#include "BKE_customdata.hh"
42#include "BKE_global.hh"
43#include "BKE_id_hash.hh"
44#include "BKE_idprop.hh"
45#include "BKE_layer.hh"
46#include "BKE_lib_remap.hh"
47#include "BKE_library.hh"
48#include "BKE_main.hh"
49#include "BKE_report.hh"
50#include "BKE_scene.hh"
51#include "BKE_screen.hh"
52#include "BKE_undo_system.hh"
53#include "BKE_workspace.hh"
54
55#include "BLT_translation.hh"
56
57#include "ED_asset.hh"
58#include "ED_fileselect.hh"
59#include "ED_geometry.hh"
60#include "ED_info.hh"
61#include "ED_markers.hh"
62#include "ED_render.hh"
63#include "ED_screen.hh"
64#include "ED_undo.hh"
65#include "ED_util.hh"
66#include "ED_view3d.hh"
67
68#include "GPU_context.hh"
69
70#include "PRF_profile.hh"
71
72#include "RNA_access.hh"
73
74#include "UI_interface.hh"
76#include "UI_view2d.hh"
77
78#include "WM_api.hh"
79#include "WM_keymap.hh"
80#include "WM_message.hh"
81#include "WM_toolsystem.hh"
82#include "WM_types.hh"
83
84#include "wm.hh"
85#include "wm_event_system.hh"
86#include "wm_event_types.hh"
87#include "wm_surface.hh"
88#include "wm_window.hh"
89#include "wm_window_private.hh"
90
91#include "DEG_depsgraph.hh"
93
94#include "RE_pipeline.h"
95
96namespace blender {
97
110#define USE_GIZMO_MOUSE_PRIORITY_HACK
111
112#ifdef WITH_INPUT_IME
113BLI_STATIC_ASSERT(sizeof(GHOST_TEventImeData) == sizeof(wmIMEData),
114 "These structs must match exactly!");
115#endif
116
128#define WM_HANDLER_CONTINUE ((eHandlerActionFlag)0)
129
130static void wm_notifier_clear(wmNotifier *note);
131static bool wm_notifier_is_clear(const wmNotifier *note);
132
134 wmOperatorType *ot,
135 PointerRNA *properties,
136 ReportList *reports,
137 const wm::OpCallContext context,
138 const bool poll_only,
139 const wmEvent *event);
140
141static bool wm_operator_check_locked_interface(bContext *C, wmOperatorType *ot);
142static wmEvent *wm_event_add_mousemove_to_head(wmWindow *win);
143static void wm_operator_free_for_fileselect(wmOperator *file_operator);
144
145static void wm_event_state_update_and_click_set_ex(wmEvent *event,
146 uint64_t event_time_ms,
147 wmEvent *event_state,
148 uint64_t *event_state_prev_press_time_ms_p,
149 const bool is_keyboard,
150 const bool check_double_click);
151
152/* -------------------------------------------------------------------- */
155
160static bool screen_temp_region_exists(const ARegion *region)
161{
162 /* TODO(@ideasman42): this function would ideally not be needed.
163 * It avoids problems restoring the #bContext::wm::region_popup
164 * when it's not known if the popup was removed, however it would be better to
165 * resolve this by ensuring the contexts previous state never references stale data.
166 *
167 * This could be done using a context "stack" allowing freeing windowing data to clear
168 * references at all levels in the stack. */
169
170 Main *bmain = G_MAIN;
171 for (bScreen &screen : bmain->screens) {
172 if (BLI_findindex(&screen.regionbase, region) != -1) {
173 return true;
174 }
175 }
176 return false;
177}
178
180
181/* -------------------------------------------------------------------- */
184
185static wmEvent *wm_event_add_intern(wmWindow *win, const wmEvent *event_to_add)
186{
187 wmEvent *event = MEM_new<wmEvent>(__func__);
188
189 *event = *event_to_add;
190
191 BLI_addtail(&win->runtime->event_queue, event);
192 return event;
193}
194
195wmEvent *WM_event_add(wmWindow *win, const wmEvent *event_to_add)
196{
197 return wm_event_add_intern(win, event_to_add);
198}
199
201{
202 if ((G.f & G_FLAG_EVENT_SIMULATE) == 0) {
204 return nullptr;
205 }
206 wmEvent *event = WM_event_add(win, event_to_add);
207
208 /* Logic for setting previous value is documented on the #wmEvent struct,
209 * see #wm_event_add_ghostevent for the implementation of logic this follows. */
210 copy_v2_v2_int(win->runtime->eventstate->xy, event->xy);
211
212 if (event->type == MOUSEMOVE) {
214 copy_v2_v2_int(event->prev_xy, win->runtime->eventstate->xy);
215 }
216 else if (ISKEYBOARD_OR_BUTTON(event->type)) {
217 /* Dummy time for simulated events. */
218 const uint64_t event_time_ms = UINT64_MAX;
219 uint64_t eventstate_prev_press_time_ms = 0;
221 event_time_ms,
222 win->runtime->eventstate,
223 &eventstate_prev_press_time_ms,
224 ISKEYBOARD(event->type),
225 false);
226 }
227 return event;
228}
229
230static void wm_event_custom_free(wmEvent *event)
231{
232 if ((event->customdata && event->customdata_free) == 0) {
233 return;
234 }
235
236 /* NOTE: pointer to #ListBaseT struct elsewhere. */
237 if (event->custom == EVT_DATA_DRAGDROP) {
238 ListBaseT<wmDrag> *lb = static_cast<ListBaseT<wmDrag> *>(event->customdata);
240 }
241 else {
243 }
244}
245
247{
248 event->custom = 0;
249 event->customdata = nullptr;
250 event->customdata_free = false;
251}
252
254{
255#ifndef NDEBUG
256 /* Don't use assert here because it's fairly harmless in most cases,
257 * more an issue of correctness, something we should avoid in general. */
258 if ((event->flag & WM_EVENT_IS_REPEAT) && !ISKEYBOARD(event->type)) {
259 printf("%s: 'is_repeat=true' for non-keyboard event, this should not happen.\n", __func__);
260 WM_event_print(event);
261 }
262 if (ISMOUSE_MOTION(event->type) && (event->val != KM_NOTHING)) {
263 printf("%s: 'val != NOTHING' for a cursor motion event, this should not happen.\n", __func__);
264 WM_event_print(event);
265 }
266#endif
267
269
270 MEM_delete(event);
271}
272
275{
276 /* Don't rely on this pointer being valid,
277 * callers should behave as if the memory has been freed.
278 * As this function should be interchangeable with #wm_event_free. */
279#ifndef NDEBUG
280 {
281 wmEvent *event_copy = MEM_dupalloc(event);
282 MEM_delete(event);
283 event = event_copy;
284 }
285#endif
286
287 if (win->runtime->event_last_handled) {
289 }
290
291 /* While not essential, these values are undefined, as the event is no longer in a list
292 * clear the linked-list pointers to avoid any confusion. */
293 event->next = event->prev = nullptr;
294
295 /* Don't store custom data in the last handled event as we don't have control how long this event
296 * will be stored and the referenced data may become invalid (also it's not needed currently). */
299 win->runtime->event_last_handled = event;
300}
301
303{
304 wmEvent *event = static_cast<wmEvent *>(BLI_poptail(&win->runtime->event_queue));
305 if (event != nullptr) {
306 wm_event_free(event);
307 }
308}
309
311{
312 while (wmEvent *event = static_cast<wmEvent *>(BLI_pophead(&win->runtime->event_queue))) {
313 wm_event_free(event);
314 }
315}
316
318{
319 *event = *(win->runtime->eventstate);
320}
321
323
324/* -------------------------------------------------------------------- */
327
328namespace bke {
333{
334 return get_default_hash(
335 note->reference, note->category, note->data, note->subtype, note->action);
336}
337
343{
344 return ((a->category | a->data | a->subtype | a->action) ==
345 (b->category | b->data | b->subtype | b->action)) &&
346 (a->reference == b->reference);
347}
348} // namespace bke
349
354
356 const wmWindow *win,
357 uint type,
358 void *reference)
359{
360 BLI_assert(wm != nullptr);
361
362 wmNotifier note_test = {nullptr};
363
364 note_test.window = win;
365
366 note_test.category = type & NOTE_CATEGORY;
367 note_test.data = type & NOTE_DATA;
368 note_test.subtype = type & NOTE_SUBTYPE;
369 note_test.action = type & NOTE_ACTION;
370 note_test.reference = reference;
371
372 BLI_assert(!wm_notifier_is_clear(&note_test));
373
374 wm->runtime->notifier_queue_set.lookup_key_or_add_cb(&note_test, [&]() {
375 wmNotifier *note = MEM_new<wmNotifier>("wm_event_add_notifier_intern");
376 *note = note_test;
377 BLI_addtail(&wm->runtime->notifier_queue, note);
378 return note;
379 });
380}
381
382void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
383{
384 if (wm == nullptr) {
385 /* There may be some cases where e.g. `G_MAIN` is not actually the real current main, but some
386 * other temporary one (e.g. during liboverride processing over linked data), leading to null
387 * window manager.
388 *
389 * This is fairly bad and weak, but unfortunately RNA does not have any way to operate over
390 * another main than G_MAIN currently. */
391 return;
392 }
393 wm_event_add_notifier_intern(wm, win, type, reference);
394}
395
396void WM_event_add_notifier(const bContext *C, uint type, void *reference)
397{
398 /* XXX: in future, which notifiers to send to other windows? */
399
401}
402
403void WM_main_add_notifier(uint type, void *reference)
404{
405 Main *bmain = G_MAIN;
406 wmWindowManager *wm = bmain->wm.first();
407
408 WM_event_add_notifier_ex(wm, nullptr, type, reference);
409}
410
411void WM_main_remove_notifier_reference(const void *reference)
412{
413 Main *bmain = G_MAIN;
414 wmWindowManager *wm = bmain->wm.first();
415
416 if (wm) {
417 for (wmNotifier &note : wm->runtime->notifier_queue.items_mutable()) {
418 if (note.reference == reference) {
419 wm->runtime->notifier_queue_set.remove_contained(&note);
420
421 /* Remove unless this is being iterated over by the caller.
422 * This is done to prevent `wm->runtime->notifier_queue` accumulating notifiers
423 * that aren't handled which can happen when notifiers are added from Python scripts.
424 * see #129323. */
425 if (wm->runtime->notifier_current == &note) {
426 /* Don't remove because this causes problems for #wm_event_do_notifiers
427 * which may be looping on the data (deleting screens). */
428 wm_notifier_clear(&note);
429 }
430 else {
431 BLI_remlink(&wm->runtime->notifier_queue, &note);
432 MEM_delete(&note);
433 }
434 }
435 }
436
437 /* Remap instead. */
438#if 0
439 if (wm->runtime->message_bus) {
440 WM_msg_id_remove(wm->runtime->message_bus, reference);
441 }
442#endif
443 }
444}
445
447{
448 Main *bmain = G_MAIN;
449
450 for (bScreen &screen : bmain->screens) {
451 for (ScrArea &area : screen.areabase) {
452 for (SpaceLink &sl : area.spacedata) {
453 ED_spacedata_id_remap(&area, &sl, mappings);
454 }
455 }
456 }
457
458 mappings.iter([](ID *old_id, ID *new_id) { ed::asset::list::storage_id_remap(old_id, new_id); });
459
460 if (wmWindowManager *wm = bmain->wm.first()) {
461 if (wmMsgBus *mbus = wm->runtime->message_bus) {
462 mappings.iter([&](ID *old_id, ID *new_id) {
463 if (new_id != nullptr) {
464 WM_msg_id_update(mbus, old_id, new_id);
465 }
466 else {
467 WM_msg_id_remove(mbus, old_id);
468 }
469 });
470 }
471 }
472
474}
475
477{
478 /* Clear the entire notifier, only leaving (`next`, `prev`) members intact. */
479 memset((reinterpret_cast<char *>(note)) + sizeof(Link), 0, sizeof(*note) - sizeof(Link));
481}
482
483static bool wm_notifier_is_clear(const wmNotifier *note)
484{
485 return note->category == NOTE_CATEGORY_TAG_CLEARED;
486}
487
488void wm_event_do_depsgraph(bContext *C, bool is_after_open_file)
489{
490 const Main *bmain = CTX_data_main(C);
492 /* The whole idea of locked interface is to prevent viewport and whatever thread from
493 * modifying the same data. Because of this, we can not perform dependency graph update. */
494 if (wm->runtime->is_interface_locked) {
495 return;
496 }
497 /* Combine data-masks so one window doesn't disable UVs in another #26448. */
498 CustomData_MeshMasks win_combine_v3d_datamask = {0};
499 for (wmWindow &win : wm->windows) {
500 const Scene *scene = WM_window_get_active_scene(&win);
501 ViewLayer *view_layer = WM_window_get_active_view_layer(&win);
502 const bScreen *screen = WM_window_get_active_screen(&win);
503
504 ED_view3d_screen_datamask(*bmain, scene, view_layer, screen, &win_combine_v3d_datamask);
505 }
506 /* Update all the dependency graphs of visible view layers. */
507 for (wmWindow &win : wm->windows) {
508 Scene *scene = WM_window_get_active_scene(&win);
509 ViewLayer *view_layer = WM_window_get_active_view_layer(&win);
510 Main *bmain = CTX_data_main(C);
511
512 /* Update dependency graph of sequencer scene. */
513 Scene *sequencer_scene = CTX_data_sequencer_scene(C);
514 if (sequencer_scene && sequencer_scene != scene) {
515 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(
516 bmain, sequencer_scene, BKE_view_layer_default_render(sequencer_scene));
517 if (is_after_open_file) {
519 DEG_tag_on_visible_update(bmain, depsgraph);
520 }
521 DEG_make_active(depsgraph);
522 BKE_scene_graph_update_tagged(depsgraph, bmain);
523 }
524
525 /* Copied to set's in #scene_update_tagged_recursive(). */
526 scene->customdata_mask = win_combine_v3d_datamask;
527 /* XXX, hack so operators can enforce data-masks #26482, GPU render. */
529 /* TODO(sergey): For now all dependency graphs which are evaluated from
530 * workspace are considered active. This will work all fine with "locked"
531 * view layer and time across windows. This is to be granted separately,
532 * and for until then we have to accept ambiguities when object is shared
533 * across visible view layers and has overrides on it. */
534 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
535 if (is_after_open_file) {
536 DEG_graph_tag_on_visible_update(depsgraph, true);
537 }
538 DEG_make_active(depsgraph);
539 BKE_scene_graph_update_tagged(depsgraph, bmain);
540 }
541
543}
544
546{
548 /* Cached: editor refresh callbacks now, they get context. */
549 for (wmWindow &win : wm->windows) {
550 const bScreen *screen = WM_window_get_active_screen(&win);
551
552 CTX_wm_window_set(C, &win);
553 for (ScrArea &area : screen->areabase) {
554 if (area.do_refresh) {
555 CTX_wm_area_set(C, &area);
556 ED_area_do_refresh(C, &area);
557 }
558 }
559 }
560
561 wm_event_do_depsgraph(C, false);
562
563 CTX_wm_window_set(C, nullptr);
564}
565
567{
569 if (wm == nullptr) [[unlikely]] {
570 return;
571 }
572
573 /* Set the first window as context, so that there is some minimal context. This avoids crashes
574 * when calling code that assumes that there is always a window in the context (which many
575 * operators do). */
576 CTX_wm_window_set(C, wm->windows.first());
578 CTX_wm_window_set(C, nullptr);
579}
580
582{
583 if (note.category == NC_ASSET) {
585 return true;
586 }
587 }
588 else if (note.category == NC_NODE) {
589 if (ELEM(note.data, ND_NODE_ASSET_DATA)) {
590 return true;
591 }
592 }
593 return false;
594}
595
597{
599 /* Ensure inside render boundary. */
601
602 /* Run the timer before assigning `wm` in the unlikely case a timer loads a file, see #80028. */
604
606 if (wm == nullptr) {
608 return;
609 }
610
611 /* Disable? - Keep for now since its used for window level notifiers. */
612#if 1
613 /* Cache & catch WM level notifiers, such as frame change, scene/screen set. */
614 for (wmWindow &win : wm->windows) {
615 Scene *scene = WM_window_get_active_scene(&win);
616 bool do_anim = false;
617 bool clear_info_stats = false;
618
619 CTX_wm_window_set(C, &win);
620
621 BLI_assert(wm->runtime->notifier_current == nullptr);
622 for (const wmNotifier *note = wm->runtime->notifier_queue.first(), *note_next = nullptr; note;
623 note = note_next)
624 {
625 if (wm_notifier_is_clear(note)) {
626 note_next = note->next;
627 MEM_delete(note);
628 continue;
629 }
630
631 wm->runtime->notifier_current = note;
632
633 if (note->category == NC_WM) {
634 if (ELEM(note->data, ND_FILEREAD, ND_FILESAVE)) {
635 wm->file_saved = 1;
637 }
638 else if (ELEM(note->data, ND_DATACHANGED, ND_PROJECT_CHANGED)) {
640 }
641 else if (note->data == ND_UNDO) {
643 }
644 }
645
648 }
649
650 if (note->window == &win) {
651 if (note->category == NC_SCREEN) {
652 if (note->data == ND_WORKSPACE_SET) {
653 WorkSpace *ref_ws = static_cast<WorkSpace *>(note->reference);
654
656
657 WM_window_set_active_workspace(C, &win, ref_ws);
658 if (G.debug & G_DEBUG_EVENTS) {
659 printf("%s: Workspace set %p\n", __func__, note->reference);
660 }
661 }
662 else if (note->data == ND_WORKSPACE_DELETE) {
663 WorkSpace *workspace = static_cast<WorkSpace *>(note->reference);
664
666 workspace, CTX_data_main(C), C, wm); /* XXX: hum, think this over! */
667 if (G.debug & G_DEBUG_EVENTS) {
668 printf("%s: Workspace delete %p\n", __func__, workspace);
669 }
670 }
671 else if (note->data == ND_LAYOUTBROWSE) {
673 static_cast<WorkSpaceLayout *>(note->reference));
674
675 /* Free popup handlers only #35434. */
677
678 ED_screen_change(C, ref_screen); /* XXX: hum, think this over! */
679 if (G.debug & G_DEBUG_EVENTS) {
680 printf("%s: screen set %p\n", __func__, note->reference);
681 }
682 }
683 else if (note->data == ND_LAYOUTDELETE) {
684 WorkSpace *workspace = WM_window_get_active_workspace(&win);
685 WorkSpaceLayout *layout = static_cast<WorkSpaceLayout *>(note->reference);
686
687 ED_workspace_layout_delete(workspace, layout, C); /* XXX: hum, think this over! */
688 if (G.debug & G_DEBUG_EVENTS) {
689 printf("%s: screen delete %p\n", __func__, note->reference);
690 }
691 }
692 }
693 }
694
695 if (note->window == &win ||
696 (note->window == nullptr && ELEM(note->reference, nullptr, scene)))
697 {
698 if (note->category == NC_SCENE) {
699 if (note->data == ND_FRAME) {
700 do_anim = true;
701 }
702 }
703 }
704 if (ELEM(note->category, NC_SCENE, NC_OBJECT, NC_GEOM, NC_WM)) {
705 clear_info_stats = true;
706 }
707
708 wm->runtime->notifier_current = nullptr;
709
710 note_next = note->next;
711 if (wm_notifier_is_clear(note)) {
712 BLI_remlink(&wm->runtime->notifier_queue, (void *)note);
713 MEM_delete(note);
714 }
715 }
716
717 if (clear_info_stats) {
718 /* Only do once since adding notifiers is slow when there are many. */
719 ViewLayer *view_layer = CTX_data_view_layer(C);
720 ED_info_stats_clear(wm, view_layer);
722 }
723
724 if (do_anim) {
725
726 /* XXX: quick frame changes can cause a crash if frame-change and rendering
727 * collide (happens on slow scenes), BKE_scene_graph_update_for_newframe can be called
728 * twice which can depsgraph update the same object at once. */
729 if (G.is_rendering == false) {
730 /* Depsgraph gets called, might send more notifiers. */
731 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
733 }
734 }
735 }
736
737 BLI_assert(wm->runtime->notifier_current == nullptr);
738
739 /* The notifiers are sent without context, to keep it clean. */
740 while (const wmNotifier *note = static_cast<const wmNotifier *>(
741 BLI_pophead(&wm->runtime->notifier_queue)))
742 {
743 if (wm_notifier_is_clear(note)) {
744 MEM_delete(note);
745 continue;
746 }
747 /* NOTE: no need to set `wm->runtime->notifier_current` since it's been removed from the queue.
748 */
749
750 wm->runtime->notifier_queue_set.remove_contained(note);
751 for (wmWindow &win : wm->windows) {
752 Scene *scene = WM_window_get_active_scene(&win);
753 bScreen *screen = WM_window_get_active_screen(&win);
754 WorkSpace *workspace = WM_window_get_active_workspace(&win);
755
756 /* Filter out notifiers. */
757 if (note->category == NC_SCREEN && note->reference && note->reference != screen &&
758 note->reference != workspace && note->reference != WM_window_get_active_layout(&win))
759 {
760 /* Pass. */
761 }
762 else if (note->category == NC_SCENE && note->reference &&
763 !ELEM(note->reference, scene, workspace->sequencer_scene))
764 {
765 /* Pass. */
766 }
767 else {
768 /* XXX context in notifiers? */
769 CTX_wm_window_set(C, &win);
770
771# if 0
772 printf("notifier win %d screen %s cat %x\n",
773 win->winid,
774 win->screen->id.name + 2,
775 note->category);
776# endif
778 ED_screen_do_listen(C, note);
779
780 for (ARegion &region : screen->regionbase) {
781 wmRegionListenerParams region_params{};
782 region_params.window = &win;
783 region_params.area = nullptr;
784 region_params.region = &region;
785 region_params.scene = scene;
786 region_params.notifier = note;
787
788 ED_region_do_listen(&region_params);
789 }
790
791 ED_screen_areas_iter (&win, screen, area) {
792 if ((note->category == NC_SPACE) && note->reference) {
793 /* Filter out notifiers sent to other spaces. RNA sets the reference to the owning ID
794 * though, the screen, so let notifiers through that reference the entire screen. */
795 if (!ELEM(note->reference, area->spacedata.first_, screen, scene)) {
796 continue;
797 }
798 }
799 wmSpaceTypeListenerParams area_params{};
800 area_params.window = &win;
801 area_params.area = area;
802 area_params.notifier = note;
803 area_params.scene = scene;
804 area_params.bmain = CTX_data_main(C);
805 ED_area_do_listen(&area_params);
806 for (ARegion &region : area->regionbase) {
807 wmRegionListenerParams region_params{};
808 region_params.window = &win;
809 region_params.area = area;
810 region_params.region = &region;
811 region_params.scene = scene;
812 region_params.notifier = note;
813 ED_region_do_listen(&region_params);
814 }
815 }
816 }
817 }
818
819 MEM_delete(note);
820 }
821#endif /* If 1 (postpone disabling for in favor of message-bus), eventually. */
822
823 /* Handle message bus. */
824 {
825 for (wmWindow &win : wm->windows) {
826 CTX_wm_window_set(C, &win);
827 WM_msgbus_handle(wm->runtime->message_bus, C);
828 }
829 CTX_wm_window_set(C, nullptr);
830 }
831
833
835
836 /* Status bar. */
837 if (wm->runtime->winactive) {
838 wmWindow *win = wm->runtime->winactive;
839 CTX_wm_window_set(C, win);
841 CTX_wm_window_set(C, nullptr);
842 }
843
844 /* Auto-run warning. */
846 /* Deprecation warning. */
848 /* Foreign File warning. */
850
852}
853
854static bool wm_event_always_pass(const wmEvent *event)
855{
856 /* Some events we always pass on, to ensure proper communication. */
857 return ISTIMER(event->type) || (event->type == WINDEACTIVATE);
858}
859
871 const wmEvent *event,
872 const eHandlerActionFlag action)
873{
874#ifndef NDEBUG
875 if (C == nullptr || CTX_wm_window(C)) {
877 "Return value for events that should always pass should never be BREAK.");
878 }
879#endif
880 UNUSED_VARS_NDEBUG(C, event, action);
881}
882
884
885/* -------------------------------------------------------------------- */
888
890 wmEventHandler_UI *handler,
891 const wmEvent *event,
892 const bool always_pass)
893{
894 ScrArea *area = CTX_wm_area(C);
895 ARegion *region = CTX_wm_region(C);
896 ARegion *region_popup = CTX_wm_region_popup(C);
897 static bool do_wheel_ui = true;
898 const bool is_wheel = ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN);
899
900 /* UI code doesn't handle return values - it just always returns break.
901 * to make the #DBL_CLICK conversion work, we just don't send this to UI, except mouse clicks. */
902 if (((handler->head.flag & WM_HANDLER_ACCEPT_DBL_CLICK) == 0) && !ISMOUSE_BUTTON(event->type) &&
903 (event->val == KM_DBL_CLICK))
904 {
905 return WM_HANDLER_CONTINUE;
906 }
907
908 /* UI is quite aggressive with swallowing events, like scroll-wheel. */
909 /* I realize this is not extremely nice code... when UI gets key-maps it can be maybe smarter. */
910 if (do_wheel_ui == false) {
911 if (is_wheel) {
912 return WM_HANDLER_CONTINUE;
913 }
914 if (!wm_event_always_pass(event)) {
915 do_wheel_ui = true;
916 }
917 }
918
919 /* Don't block file-select events. Those are triggered by a separate file browser window.
920 * See #75292. */
921 if (event->type == EVT_FILESELECT) {
922 return WM_HANDLER_CONTINUE;
923 }
924
925 /* We set context to where UI handler came from. */
926 if (handler->context.area) {
927 CTX_wm_area_set(C, handler->context.area);
928 }
929 if (handler->context.region) {
930 CTX_wm_region_set(C, handler->context.region);
931 }
932 if (handler->context.region_popup) {
933 BLI_assert(screen_temp_region_exists(handler->context.region_popup));
934 CTX_wm_region_popup_set(C, handler->context.region_popup);
935 }
936
937 int retval = handler->handle_fn(C, event, handler->user_data);
938
939 /* Putting back screen context. */
940 if ((retval != WM_UI_HANDLER_BREAK) || always_pass) {
941 CTX_wm_area_set(C, area);
942 CTX_wm_region_set(C, region);
943 BLI_assert((region_popup == nullptr) || screen_temp_region_exists(region_popup));
944 CTX_wm_region_popup_set(C, region_popup);
945 }
946 else {
947 /* This special cases is for areas and regions that get removed. */
948 CTX_wm_area_set(C, nullptr);
949 CTX_wm_region_set(C, nullptr);
950 CTX_wm_region_popup_set(C, nullptr);
951 }
952
953 if (retval == WM_UI_HANDLER_BREAK) {
954 return WM_HANDLER_BREAK;
955 }
956
957 /* Event not handled in UI, if wheel then we temporarily disable it. */
958 if (is_wheel) {
959 do_wheel_ui = false;
960 }
961
962 return WM_HANDLER_CONTINUE;
963}
964
966 wmWindow *win,
967 ARegion *region,
968 bool reactivate_button)
969{
970 if (!region) {
971 return;
972 }
973
974 for (wmEventHandler &handler_base : region->runtime->handlers.items_mutable()) {
975 if (handler_base.type == WM_HANDLER_TYPE_UI) {
976 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(&handler_base);
977 BLI_assert(handler->handle_fn != nullptr);
978 wmEvent event;
979 wm_event_init_from_window(win, &event);
980 event.type = EVT_BUT_CANCEL;
981 event.val = reactivate_button ? KM_NOTHING : KM_PRESS;
982 event.flag = eWM_EventFlag(0);
983 handler->handle_fn(C, &event, handler->user_data);
984 }
985 }
986}
987
989{
990 wmWindow *win = CTX_wm_window(C);
991 ARegion *region = CTX_wm_region(C);
992 wm_event_handler_ui_cancel_ex(C, win, region, true);
993}
994
996
997/* -------------------------------------------------------------------- */
1002
1004{
1005 if (win == nullptr) {
1006 win = wm->runtime->winactive;
1007 if (win == nullptr) {
1008 win = wm->windows.first();
1009 }
1010 }
1011
1012 ReportList *wm_reports = &wm->runtime->reports;
1013
1014 /* After adding reports to the global list, reset the report timer. */
1015 WM_event_timer_remove(wm, nullptr, wm_reports->reporttimer);
1016
1017 /* Records time since last report was added. */
1018 wm_reports->reporttimer = WM_event_timer_add(wm, win, TIMERREPORT, 0.05);
1019
1020 ReportTimerInfo *rti = MEM_new<ReportTimerInfo>(__func__);
1021 wm_reports->reporttimer->customdata = rti;
1022}
1023
1025{
1026 wmWindowManager *wm = bmain->wm.first();
1027 BKE_reports_clear(&wm->runtime->reports);
1028 WM_event_timer_remove(wm, nullptr, wm->runtime->reports.reporttimer);
1029}
1030
1031#ifdef WITH_INPUT_NDOF
1032void WM_ndof_deadzone_set(float deadzone)
1033{
1034 GHOST_ISystem *ghost_system = GHOST_ISystem::getSystem();
1035 ghost_system->setNDOFDeadZone(deadzone);
1036}
1037#endif
1038
1040{
1041 /* If the caller owns them, handle this. */
1042 if (!reports || reports->list.is_empty() || (reports->flag & RPT_OP_HOLD) != 0) {
1043 return;
1044 }
1045
1046 if (!wm) {
1047 wm = G_MAIN->wm.first();
1048 }
1049
1050 /* Add reports to the global list, otherwise they are not seen. */
1051 BKE_reports_move_to_reports(&wm->runtime->reports, reports);
1052
1053 WM_report_banner_show(wm, nullptr);
1054}
1055
1056void WM_global_report(eReportType type, const char *message)
1057{
1058 /* WARNING: in most cases #BKE_report should be used instead, see docstring for details. */
1059 ReportList reports;
1062 BKE_report(&reports, type, message);
1063
1064 WM_reports_from_reports_move(nullptr, &reports);
1065
1066 BKE_reports_free(&reports);
1067}
1068
1069void WM_global_reportf(eReportType type, const char *format, ...)
1070{
1071 /* WARNING: in most cases #BKE_reportf should be used instead, see docstring for details. */
1072
1073 va_list args;
1074
1075 format = RPT_(format);
1076
1077 va_start(args, format);
1078 char *str = BLI_vsprintfN(format, args);
1079 va_end(args);
1080
1081 WM_global_report(type, str);
1082 MEM_delete(str);
1083}
1084
1086
1087/* -------------------------------------------------------------------- */
1090
1095{
1096 if (wm->runtime->undo_stack) {
1097 return intptr_t(wm->runtime->undo_stack->step_active);
1098 }
1099 return -1;
1100}
1101
1103{
1104 if (wm->runtime->operators.last()) {
1105 return intptr_t(wm->runtime->operators.last());
1106 }
1107 return -1;
1108}
1109
1111{
1112 PRF_scope_with_name("Operator Call (poll)", ProfileCategory::Default);
1113 PRF_scope_set_dynamic_name("Op: %s", ot->idname);
1114
1115 for (wmOperatorTypeMacro &otmacro : ot->macro) {
1116 wmOperatorType *ot_macro = WM_operatortype_find(otmacro.idname, false);
1117
1118 if (!WM_operator_poll(C, ot_macro)) {
1119 return false;
1120 }
1121 }
1122
1123 /* Python needs operator type, so we added exception for it. */
1124 if (ot->pyop_poll) {
1125 return ot->pyop_poll(C, ot);
1126 }
1127 if (ot->poll) {
1128 return ot->poll(C);
1129 }
1130
1131 return true;
1132}
1133
1135{
1137 if (WM_operator_poll(C, ot)) {
1138 return true;
1139 }
1140 bool msg_free = false;
1141 const char *msg = CTX_wm_operator_poll_msg_get(C, &msg_free);
1142 BKE_reportf(reports,
1143 RPT_ERROR,
1144 RPT_("Invalid context: \"%s\", %s"),
1146 msg ? RPT_(msg) : RPT_("poll failed"));
1148 if (msg_free) {
1149 MEM_delete(msg);
1150 }
1151 return false;
1152}
1153
1155{
1156 /* Sets up the new context and calls #wm_operator_invoke() with poll_only. */
1157 return wm_operator_call_internal(C, ot, nullptr, nullptr, context, true, nullptr);
1158}
1159
1161{
1162 if (ot->macro.first() != nullptr) {
1163 /* For macros, check all have exec() we can call. */
1164 for (wmOperatorTypeMacro &otmacro : ot->macro) {
1165 wmOperatorType *otm = WM_operatortype_find(otmacro.idname, false);
1166 if (otm && WM_operator_ui_poll(otm, ptr)) {
1167 return true;
1168 }
1169 }
1170 return false;
1171 }
1172
1173 if (ot->ui) {
1174 if (ot->ui_poll) {
1175 return ot->ui_poll(ot, ptr);
1176 }
1177 return true;
1178 }
1179
1180 bool result = false;
1182 RNA_STRUCT_BEGIN (&op_ptr, prop) {
1183 int flag = RNA_property_flag(prop);
1184 if ((flag & PROP_HIDDEN) == 0) {
1185 result = true;
1186 break;
1187 }
1188 }
1190 return result;
1191}
1192
1194{
1195 ScrArea *area = CTX_wm_area(C);
1196 if (area) {
1197 ARegion *region = CTX_wm_region(C);
1198 if (region && region->regiontype == RGN_TYPE_WINDOW) {
1199 area->region_active_win = BLI_findindex(&area->regionbase, region);
1200 }
1201 }
1202}
1203
1208 wmOperator *op,
1209 const wmOperatorStatus retval,
1210 const bool caller_owns_reports)
1211{
1212 if (G.background == 0 && caller_owns_reports == false) { /* Popup. */
1213 if (op->reports->list.first()) {
1214 /* FIXME: temp setting window, see other call to #popup_menu_reports for why. */
1215 wmWindow *win_prev = CTX_wm_window(C);
1216 ScrArea *area_prev = CTX_wm_area(C);
1217 ARegion *region_prev = CTX_wm_region(C);
1218
1219 if (win_prev == nullptr) {
1220 CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first());
1221 }
1222
1224
1225 CTX_wm_window_set(C, win_prev);
1226 CTX_wm_area_set(C, area_prev);
1227 CTX_wm_region_set(C, region_prev);
1228 }
1229 }
1230
1231 std::string pystring = WM_operator_pystring(C, op, false, true);
1232
1233 if (retval & OPERATOR_FINISHED) {
1234 if (caller_owns_reports == false) {
1235 /* Print out reports to console.
1236 * When quiet, only show warnings, suppressing info and other non-essential warnings. */
1237 const eReportType level = CLG_quiet_get() ? RPT_WARNING : RPT_DEBUG;
1239 }
1240
1241 if (op->type->flag & OPTYPE_REGISTER) {
1242 if (G.background == 0) { /* Ends up printing these in the terminal, gets annoying. */
1243 /* Report the python string representation of the operator. */
1244 BKE_report(CTX_wm_reports(C), RPT_OPERATOR, pystring.c_str());
1245 }
1246 }
1247 }
1248
1250 /* Avoid logging very noisy hover/timer driven operators at info level. */
1252 (retval & OPERATOR_FINISHED) ? "Finished %s" : "Cancelled: %s",
1253 pystring.c_str());
1254
1255 /* Refresh Info Editor with reports immediately, even if op returned #OPERATOR_CANCELLED. */
1256 if ((retval & (OPERATOR_FINISHED | OPERATOR_CANCELLED)) && !op->reports->list.is_empty()) {
1258 }
1259 /* If the caller owns them, handle this. */
1261}
1262
1268{
1269 /* Check undo flag here since undo operators are also added to the list,
1270 * to support checking if the same operator is run twice. */
1271 return wm && (wm->op_undo_depth == 0) && (ot->flag & (OPTYPE_REGISTER | OPTYPE_UNDO));
1272}
1273
1280 wmOperator *op,
1281 const bool repeat,
1282 const bool store,
1283 const bool has_undo_step,
1284 const bool has_register)
1285{
1287 enum {
1288 NOP,
1289 SET,
1290 CLEAR,
1291 } hud_status = NOP;
1292 const bool do_register = (repeat == false) && wm_operator_register_check(wm, op->type);
1293
1294 op->customdata = nullptr;
1295
1296 if (store) {
1298 }
1299
1300 /* We don't want to do undo pushes for operators that are being
1301 * called from operators that already do an undo push. Usually
1302 * this will happen for python operators that call C operators. */
1303 if (wm->op_undo_depth == 0) {
1304 if (op->type->flag & OPTYPE_UNDO) {
1305 ED_undo_push_op(C, op);
1306 if (repeat == 0) {
1307 hud_status = CLEAR;
1308 }
1309 }
1310 else if (op->type->flag & OPTYPE_UNDO_GROUPED) {
1312 if (repeat == 0) {
1313 hud_status = CLEAR;
1314 }
1315 }
1316 else if (has_undo_step) {
1317 /* An undo step was added but the operator wasn't registered (and won't register itself),
1318 * therefore a redo panel wouldn't redo this action but the previous registered action,
1319 * causing the "redo" to remove/loose this operator. See: #101743.
1320 * Register check is needed so nested operator calls don't clear the HUD. See: #103587. */
1321 if (!(has_register || do_register)) {
1322 if (repeat == 0) {
1323 hud_status = CLEAR;
1324 }
1325 }
1326 }
1327 }
1328
1329 if (repeat == 0) {
1330 if (G.debug & G_DEBUG_WM) {
1331 std::string pystring = WM_operator_pystring(C, op, false, true);
1332 BKE_report(CTX_wm_reports(C), RPT_OPERATOR, pystring.c_str());
1333 }
1334
1335 if (do_register) {
1336 /* Take ownership of reports (in case python provided its own). */
1337 op->reports->flag |= RPT_FREE;
1338
1341
1342 if (WM_operator_last_redo(C) == op) {
1343 /* Show the redo panel. */
1344 hud_status = SET;
1345 }
1346 }
1347 else {
1348 WM_operator_free(op);
1349 }
1350 }
1351
1352 if (hud_status != NOP) {
1353 if (hud_status == SET) {
1354 ScrArea *area = CTX_wm_area(C);
1355 if (area && ((area->flag & AREA_FLAG_OFFSCREEN) == 0)) {
1357 }
1358 }
1359 else if (hud_status == CLEAR) {
1361 }
1362 else {
1364 }
1365 }
1366}
1367
1372 wmOperator *op,
1373 const bool repeat,
1374 const bool store)
1375{
1378
1380
1381 if (op == nullptr || op->type == nullptr) {
1382 return retval;
1383 }
1384
1385 if (0 == WM_operator_poll(C, op->type)) {
1386 return retval;
1387 }
1388
1389 const intptr_t undo_id_prev = wm_operator_undo_active_id(wm);
1390 const intptr_t register_id_prev = wm_operator_register_active_id(wm);
1391
1392 if (op->type->exec) {
1393 if (op->type->flag & OPTYPE_UNDO) {
1394 wm->op_undo_depth++;
1395 }
1396
1397 retval = op->type->exec(C, op);
1398 OPERATOR_RETVAL_CHECK(retval);
1399
1400 if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
1401 wm->op_undo_depth--;
1402 }
1403 }
1404
1405 /* XXX(@mont29): Disabled the repeat check to address part 2 of #31840.
1406 * Carefully checked all calls to wm_operator_exec and WM_operator_repeat, don't see any reason
1407 * why this was needed, but worth to note it in case something turns bad. */
1408 if (retval & (OPERATOR_FINISHED | OPERATOR_CANCELLED) /* && repeat == 0 */) {
1409 wm_operator_reports(C, op, retval, false);
1410 }
1411
1412 if (retval & OPERATOR_FINISHED) {
1413 const bool has_undo_step = (undo_id_prev != wm_operator_undo_active_id(wm));
1414 const bool has_register = (register_id_prev != wm_operator_register_active_id(wm));
1415
1417 C, op, repeat, store && wm->op_undo_depth == 0, has_undo_step, has_register);
1418 }
1419 else if (repeat == 0) {
1420 /* WARNING: modal from exec is bad practice, but avoid crashing. */
1421 if (retval & (OPERATOR_FINISHED | OPERATOR_CANCELLED)) {
1422 WM_operator_free(op);
1423 }
1424 }
1425
1426 return retval | OPERATOR_HANDLED;
1427}
1428
1433{
1435
1436 if (op == nullptr || op->type == nullptr || op->type->exec == nullptr) {
1437 return retval;
1438 }
1439
1440 retval = op->type->exec(C, op);
1441 OPERATOR_RETVAL_CHECK(retval);
1442
1443 return retval;
1444}
1445
1447{
1448 return wm_operator_exec(C, op, false, store);
1449}
1450
1452{
1453 return WM_operator_call_ex(C, op, false);
1454}
1455
1460
1462{
1463 const eOperator_Flag op_flag = OP_IS_REPEAT;
1464 op->flag |= op_flag;
1465 const wmOperatorStatus ret = wm_operator_exec(C, op, true, true);
1466 op->flag &= ~op_flag;
1467 return ret;
1468}
1470{
1471 const eOperator_Flag op_flag = OP_IS_REPEAT_LAST;
1472 op->flag |= op_flag;
1473 const wmOperatorStatus ret = wm_operator_exec(C, op, true, true);
1474 op->flag &= ~op_flag;
1475 return ret;
1476}
1478{
1479 if (op->type->exec != nullptr) {
1480 return true;
1481 }
1482 if (op->opm) {
1483 /* For macros, check all have exec() we can call. */
1484 for (wmOperatorTypeMacro &otmacro : op->opm->type->macro) {
1485 wmOperatorType *otm = WM_operatortype_find(otmacro.idname, false);
1486 if (otm && otm->exec == nullptr) {
1487 return false;
1488 }
1489 }
1490 return true;
1491 }
1492
1493 return false;
1494}
1495
1497{
1498 /* May be in the operators list or not. */
1499 wmOperator *op_prev;
1500 if (op->prev == nullptr && op->next == nullptr) {
1502 op_prev = wm->runtime->operators.last();
1503 }
1504 else {
1505 op_prev = op->prev;
1506 }
1507 return (op_prev && (op->type == op_prev->type));
1508}
1509
1511 wmOperatorType *ot,
1512 PointerRNA *properties,
1513 ReportList *reports)
1514{
1515 /* Operator-type names are static still (for C++ defined operators).
1516 * Pass to allocation name for debugging. */
1517 wmOperator *op = MEM_new<wmOperator>(ot->rna_ext.srna ? __func__ : ot->idname);
1518
1519 /* Adding new operator could be function, only happens here now. */
1520 op->type = ot;
1521 STRNCPY_UTF8(op->idname, ot->idname);
1522
1523 /* Initialize properties, either copy or create. */
1524 op->ptr = MEM_new<PointerRNA>("wmOperatorPtrRNA");
1525 if (properties && properties->data) {
1526 op->properties = IDP_CopyProperty(static_cast<const IDProperty *>(properties->data));
1527 }
1528 else {
1529 op->properties = bke::idprop::create_group("wmOperatorProperties").release();
1530 }
1531 *op->ptr = RNA_pointer_create_discrete(&wm->id, ot->srna, op->properties);
1532
1533 /* Initialize error reports. */
1534 if (reports) {
1535 op->reports = reports; /* Must be initialized already. */
1536 }
1537 else {
1538 op->reports = MEM_new<ReportList>("wmOperatorReportList");
1540 }
1541
1542 /* Recursive filling of operator macro list. */
1543 if (ot->macro.first()) {
1544 static wmOperator *motherop = nullptr;
1545 int root = 0;
1546
1547 /* Ensure all ops are in execution order in 1 list. */
1548 if (motherop == nullptr) {
1549 motherop = op;
1550 root = 1;
1551 }
1552
1553 /* If properties exist, it will contain everything needed. */
1554 if (properties) {
1555 wmOperatorTypeMacro *otmacro = ot->macro.first();
1556
1557 RNA_STRUCT_BEGIN (properties, prop) {
1558
1559 if (otmacro == nullptr) {
1560 break;
1561 }
1562
1563 /* Skip invalid properties. */
1564 if (STREQ(RNA_property_identifier(prop), otmacro->idname)) {
1565 wmOperatorType *otm = WM_operatortype_find(otmacro->idname, false);
1566 PointerRNA someptr = RNA_property_pointer_get(properties, prop);
1567 wmOperator *opm = wm_operator_create(wm, otm, &someptr, nullptr);
1568
1570
1571 BLI_addtail(&motherop->macro, opm);
1572 opm->opm = motherop; /* Pointer to mom, for modal(). */
1573
1574 otmacro = otmacro->next;
1575 }
1576 }
1578 }
1579 else {
1580 for (wmOperatorTypeMacro &otmacro : ot->macro) {
1581 wmOperatorType *otm = WM_operatortype_find(otmacro.idname, false);
1582 wmOperator *opm = wm_operator_create(wm, otm, otmacro.ptr, nullptr);
1583
1584 BLI_addtail(&motherop->macro, opm);
1585 opm->opm = motherop; /* Pointer to mom, for modal(). */
1586 }
1587 }
1588
1589 if (root) {
1590 motherop = nullptr;
1591 }
1592 }
1593
1595
1596 return op;
1597}
1598
1604{
1605
1606 bScreen *screen = WM_window_get_active_screen(win);
1607 /* Unlikely but not impossible as this runs after events have been handled. */
1608 if (screen == nullptr) [[unlikely]] {
1609 return;
1610 }
1611 ED_screen_areas_iter (win, screen, area) {
1612 for (ARegion &region : area->regionbase) {
1613 if (region.runtime->gizmo_map != nullptr) {
1615 ED_region_tag_redraw(&region);
1616 }
1617 }
1618 }
1619 }
1620}
1621
1623{
1624 ARegion *region = CTX_wm_region(C);
1625 if (region) {
1626 /* Compatibility convention. */
1627 event->mval[0] = event->xy[0] - region->winrct.xmin;
1628 event->mval[1] = event->xy[1] - region->winrct.ymin;
1629 }
1630 else {
1631 /* These values are invalid (avoid odd behavior by relying on old #wmEvent.mval values). */
1632 event->mval[0] = -1;
1633 event->mval[1] = -1;
1634 }
1635}
1636
1641 wmOperatorType *ot,
1642 const wmEvent *event,
1643 PointerRNA *properties,
1644 ReportList *reports,
1645 const bool poll_only,
1646 bool use_last_properties)
1647{
1649
1650 /* This is done because complicated setup is done to call this function
1651 * that is better not duplicated. */
1652 if (poll_only) {
1653 return wmOperatorStatus(WM_operator_poll(C, ot));
1654 }
1655
1656 if (WM_operator_poll(C, ot)) {
1657 PRF_scope_with_name("Operator Call (exec/invoke)", ProfileCategory::Default);
1658 PRF_scope_set_dynamic_name("Op: %s", ot->idname);
1660 const intptr_t undo_id_prev = wm_operator_undo_active_id(wm);
1661 const intptr_t register_id_prev = wm_operator_register_active_id(wm);
1662
1663 /* If `reports == nullptr`, they'll be initialized. */
1664 wmOperator *op = wm_operator_create(wm, ot, properties, reports);
1665
1667 /* Avoid logging very noisy hover/timer driven operators at info level. */
1669 "Started %s",
1670 WM_operator_pystring(C, op, false, true).c_str());
1671
1672 const bool is_nested_call = (wm->op_undo_depth != 0);
1673
1674 if (event != nullptr) {
1675 op->flag |= OP_IS_INVOKE;
1676 }
1677
1678 /* Initialize setting from previous run. */
1679 if (!is_nested_call && use_last_properties) { /* Not called by a Python script. */
1681 }
1682
1683 if ((event == nullptr) || (event->type != MOUSEMOVE)) {
1685 "Handle event %d win %p op %s",
1686 event ? event->type : 0,
1687 CTX_wm_screen(C)->active_region,
1688 ot->idname);
1689 }
1690
1691 if (op->type->invoke && event) {
1692 /* Make a copy of the event as it's `const` and the #wmEvent.mval to be written into. */
1693 wmEvent event_temp = *event;
1694 wm_region_mouse_co(C, &event_temp);
1695
1696 if (op->type->flag & OPTYPE_UNDO) {
1697 wm->op_undo_depth++;
1698 }
1699
1700 retval = op->type->invoke(C, op, &event_temp);
1701 OPERATOR_RETVAL_CHECK(retval);
1702
1703 if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
1704 wm->op_undo_depth--;
1705 }
1706 }
1707 else if (op->type->exec) {
1708 if (op->type->flag & OPTYPE_UNDO) {
1709 wm->op_undo_depth++;
1710 }
1711
1712 retval = op->type->exec(C, op);
1713 OPERATOR_RETVAL_CHECK(retval);
1714
1715 if (op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
1716 wm->op_undo_depth--;
1717 }
1718 }
1719 else {
1720 /* Debug, important to leave a while, should never happen. */
1721 CLOG_ERROR(WM_LOG_OPERATORS, "Invalid operator call '%s'", op->idname);
1722 }
1723
1724 /* NOTE: if the report is given as an argument then assume the caller will deal with displaying
1725 * them currently Python only uses this. */
1726 if (!(retval & OPERATOR_HANDLED) && (retval & (OPERATOR_FINISHED | OPERATOR_CANCELLED))) {
1727 /* Only show the report if the report list was not given in the function. */
1728 wm_operator_reports(C, op, retval, (reports != nullptr));
1729 }
1730
1731 if (retval & OPERATOR_HANDLED) {
1732 /* Do nothing, #wm_operator_exec() has been called somewhere. */
1733 }
1734 else if (retval & OPERATOR_FINISHED) {
1735 const bool has_undo_step = (undo_id_prev != wm_operator_undo_active_id(wm));
1736 const bool has_register = (register_id_prev != wm_operator_register_active_id(wm));
1737 const bool store = !is_nested_call && use_last_properties;
1738 wm_operator_finished(C, op, false, store, has_undo_step, has_register);
1739 }
1740 else if (retval & OPERATOR_RUNNING_MODAL) {
1741 /* Take ownership of reports (in case python provided its own). */
1742 op->reports->flag |= RPT_FREE;
1743
1744 /* Grab cursor during blocking modal operators (X11)
1745 * Also check for macro. */
1746 if (ot->flag & OPTYPE_BLOCKING || (op->opm && op->opm->type->flag & OPTYPE_BLOCKING)) {
1748 const rcti *wrap_region = nullptr;
1749
1750 if (event && (U.uiflag & USER_CONTINUOUS_MOUSE)) {
1751 const wmOperator *op_test = op->opm ? op->opm : op;
1752 const wmOperatorType *ot_test = op_test->type;
1753 if ((ot_test->flag & OPTYPE_GRAB_CURSOR_XY) || (op_test->flag & OP_IS_MODAL_GRAB_CURSOR))
1754 {
1756 }
1757 else if (ot_test->flag & OPTYPE_GRAB_CURSOR_X) {
1759 }
1760 else if (ot_test->flag & OPTYPE_GRAB_CURSOR_Y) {
1762 }
1763 }
1764
1765 if (wrap) {
1766 ARegion *region = CTX_wm_region(C);
1767 ScrArea *area = CTX_wm_area(C);
1768
1769 /* Wrap only in X for header. */
1770 if (region && RGN_TYPE_IS_HEADER_ANY(region->regiontype)) {
1771 /* Disable cursor wrapping/continuous grab when scrubbing playhead in scrubbing region.
1772 */
1775 }
1776
1777 if (region && region->regiontype == RGN_TYPE_WINDOW &&
1778 BLI_rcti_isect_pt_v(&region->winrct, event->xy))
1779 {
1780 wrap_region = &region->winrct;
1781 }
1782 else if (area && BLI_rcti_isect_pt_v(&area->totrct, event->xy)) {
1783 wrap_region = &area->totrct;
1784 }
1785 }
1786
1787 WM_cursor_grab_enable(CTX_wm_window(C), wrap, wrap_region, false);
1788 }
1789
1790 /* Cancel UI handlers, typically tool-tips that can hang around
1791 * while dragging the view or worse, that stay there permanently
1792 * after the modal operator has swallowed all events and passed
1793 * none to the UI handler. */
1795 }
1796 else {
1797 WM_operator_free(op);
1798 }
1799 }
1800
1801 return retval;
1802}
1803
1810 wmOperatorType *ot,
1811 PointerRNA *properties,
1812 ReportList *reports,
1813 const wm::OpCallContext context,
1814 const bool poll_only,
1815 const wmEvent *event)
1816{
1817 wmOperatorStatus retval;
1818
1820
1821 /* Dummy test. */
1822 if (ot) {
1823 wmWindow *window = CTX_wm_window(C);
1824
1825 if (event == nullptr) {
1826 switch (context) {
1833 /* Window is needed for invoke and cancel operators. */
1834 if (window == nullptr) {
1835 if (poll_only) {
1836 CTX_wm_operator_poll_msg_set(C, "Missing 'window' in context");
1837 }
1838 return wmOperatorStatus(0);
1839 }
1840 else {
1841 event = window->runtime->eventstate;
1842 }
1843 break;
1844 default:
1845 event = nullptr;
1846 break;
1847 }
1848 }
1849 else {
1850 switch (context) {
1857 event = nullptr;
1858 break;
1859 default:
1860 break;
1861 }
1862 }
1863
1864 switch (context) {
1871 /* Forces operator to go to the region window/channels/preview, for header menus,
1872 * but we stay in the same region if we are already in one. */
1873 ARegion *region = CTX_wm_region(C);
1874 ScrArea *area = CTX_wm_area(C);
1875 int type = RGN_TYPE_WINDOW;
1876
1877 switch (context) {
1880 type = RGN_TYPE_CHANNELS;
1881 break;
1882
1885 type = RGN_TYPE_PREVIEW;
1886 break;
1887
1890 default:
1891 type = RGN_TYPE_WINDOW;
1892 break;
1893 }
1894
1895 if (!(region && region->regiontype == type) && area) {
1896 ARegion *region_other = (type == RGN_TYPE_WINDOW) ?
1898 BKE_area_find_region_type(area, type);
1899 if (region_other) {
1900 CTX_wm_region_set(C, region_other);
1901 }
1902 }
1903
1904 retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true);
1905
1906 /* Set region back. */
1907 CTX_wm_region_set(C, region);
1908
1909 return retval;
1910 }
1913 /* Remove region from context. */
1914 ARegion *region = CTX_wm_region(C);
1915
1916 CTX_wm_region_set(C, nullptr);
1917 retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true);
1918 CTX_wm_region_set(C, region);
1919
1920 return retval;
1921 }
1924 /* Remove region + area from context. */
1925 ARegion *region = CTX_wm_region(C);
1926 ScrArea *area = CTX_wm_area(C);
1927
1928 CTX_wm_region_set(C, nullptr);
1929 CTX_wm_area_set(C, nullptr);
1930 retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true);
1931 CTX_wm_area_set(C, area);
1932 CTX_wm_region_set(C, region);
1933
1934 return retval;
1935 }
1938 return wm_operator_invoke(C, ot, event, properties, reports, poll_only, true);
1939 }
1940 }
1941
1942 return wmOperatorStatus(0);
1943}
1944
1946 wmOperatorType *ot,
1947 wm::OpCallContext context,
1948 PointerRNA *properties,
1949 ReportList *reports,
1950 const wmEvent *event)
1951{
1952 BLI_assert(ot == WM_operatortype_find(ot->idname, true));
1953 return wm_operator_call_internal(C, ot, properties, reports, context, false, event);
1954}
1955
1957 wmOperatorType *ot,
1958 wm::OpCallContext context,
1959 PointerRNA *properties,
1960 const wmEvent *event)
1961{
1962 return WM_operator_type_call_ptr_with_reports(C, ot, context, properties, nullptr, event);
1963}
1964
1966 const char *opstring,
1967 wm::OpCallContext context,
1968 PointerRNA *properties,
1969 const wmEvent *event)
1970{
1971 wmOperatorType *ot = WM_operatortype_find(opstring, false);
1972 if (ot) {
1973 return WM_operator_type_call_ptr_with_reports(C, ot, context, properties, nullptr, event);
1974 }
1975
1976 return wmOperatorStatus(0);
1977}
1978
1979bool WM_operator_name_poll(bContext *C, const char *opstring)
1980{
1981 wmOperatorType *ot = WM_operatortype_find(opstring, false);
1982 if (!ot) {
1983 return false;
1984 }
1985
1986 return WM_operator_poll(C, ot);
1987}
1988
1990 const char *opstring,
1991 wm::OpCallContext context,
1992 IDProperty *properties,
1993 const wmEvent *event)
1994{
1995 wmOperatorType *ot = WM_operatortype_find(opstring, false);
1997 &G_MAIN->wm.first()->id, ot->srna, properties);
1998 return WM_operator_type_call_ptr_with_reports(C, ot, context, &props_ptr, nullptr, event);
1999}
2000
2001void WM_menu_name_call(bContext *C, const char *menu_name, wm::OpCallContext context)
2002{
2003 wmOperatorType *ot = WM_operatortype_find("WM_OT_call_menu", false);
2005 RNA_string_set(&ptr, "name", menu_name);
2006 WM_operator_name_call_ptr(C, ot, static_cast<wm::OpCallContext>(context), &ptr, nullptr);
2008}
2009
2011 wmOperatorType *ot,
2012 wm::OpCallContext context,
2013 PointerRNA *properties,
2014 ReportList *reports,
2015 const bool is_undo)
2016{
2018 /* Not especially nice using undo depth here. It's used so Python never
2019 * triggers undo or stores an operator's last used state. */
2021 if (!is_undo && wm) {
2022 wm->op_undo_depth++;
2023 }
2024
2025 retval = wm_operator_call_internal(C, ot, properties, reports, context, false, nullptr);
2026
2027 if (!is_undo && wm && (wm == CTX_wm_manager(C))) {
2028 wm->op_undo_depth--;
2029 }
2030
2031 return retval;
2032}
2033
2035
2036/* -------------------------------------------------------------------- */
2043
2049
2050static void ui_handler_wait_for_input_remove(bContext *C, void *userdata)
2051{
2052 OperatorWaitForInput *opwait = static_cast<OperatorWaitForInput *>(userdata);
2053 if (opwait->optype_params.opptr) {
2054 if (*opwait->optype_params.opptr) {
2055 IDP_FreeProperty(static_cast<IDProperty *>(opwait->optype_params.opptr->data));
2056 }
2057 MEM_delete(opwait->optype_params.opptr);
2058 }
2059
2060 if (opwait->area != nullptr) {
2061 ED_area_status_text(opwait->area, nullptr);
2062 }
2063 else {
2064 ED_workspace_status_text(C, nullptr);
2065 }
2066
2067 MEM_delete(opwait);
2068}
2069
2070static int ui_handler_wait_for_input(bContext *C, const wmEvent *event, void *userdata)
2071{
2072 OperatorWaitForInput *opwait = static_cast<OperatorWaitForInput *>(userdata);
2073 enum { CONTINUE = 0, EXECUTE, CANCEL } state = CONTINUE;
2074 state = CONTINUE;
2075
2076 switch (event->type) {
2077 case LEFTMOUSE: {
2078 if (event->val == KM_PRESS) {
2079 state = EXECUTE;
2080 }
2081 break;
2082 }
2083 /* Useful if the operator isn't convenient to access while the mouse button is held.
2084 * If it takes numeric input for example. */
2085 case EVT_SPACEKEY:
2086 case EVT_RETKEY: {
2087 if (event->val == KM_PRESS) {
2088 state = EXECUTE;
2089 }
2090 break;
2091 }
2092 case RIGHTMOUSE: {
2093 if (event->val == KM_PRESS) {
2094 state = CANCEL;
2095 }
2096 break;
2097 }
2098 case EVT_ESCKEY: {
2099 if (event->val == KM_PRESS) {
2100 state = CANCEL;
2101 }
2102 break;
2103 }
2104 default: {
2105 break;
2106 }
2107 }
2108
2109 if (state != CONTINUE) {
2110 wmWindow *win = CTX_wm_window(C);
2112
2113 if (state == EXECUTE) {
2114 CTX_store_set(C, opwait->context ? &opwait->context.value() : nullptr);
2116 opwait->optype_params.optype,
2117 opwait->optype_params.opcontext,
2118 opwait->optype_params.opptr,
2119 event);
2120 CTX_store_set(C, nullptr);
2121 }
2122
2126 opwait,
2127 false);
2128
2130
2131 return WM_UI_HANDLER_BREAK;
2132 }
2133
2135}
2136
2138 wmOperatorType *ot,
2139 wm::OpCallContext opcontext,
2140 PointerRNA *properties,
2141 const wmEvent *event,
2142 const StringRef drawstr)
2143{
2144 bool depends_on_cursor = WM_operator_depends_on_cursor(*C, *ot, properties);
2145
2146 for (wmOperatorTypeMacro &otmacro : ot->macro) {
2147 if (wmOperatorType *otm = WM_operatortype_find(otmacro.idname, false)) {
2148 if (WM_operator_depends_on_cursor(*C, *otm, properties)) {
2149 depends_on_cursor = true;
2150 }
2151 }
2152 }
2153
2154 if (!depends_on_cursor) {
2155 WM_operator_name_call_ptr(C, ot, opcontext, properties, event);
2156 return;
2157 }
2158
2159 wmWindow *win = CTX_wm_window(C);
2160 /* The operator context is applied when the operator is called,
2161 * the check for the area needs to be explicitly limited here.
2162 * Useful so it's possible to screen-shot an area without drawing into it's header. */
2163 ScrArea *area = WM_OP_CONTEXT_HAS_AREA(opcontext) ? CTX_wm_area(C) : nullptr;
2164
2165 {
2166 std::string header_text = fmt::format(
2167 fmt::runtime(IFACE_("Input pending {}")),
2168 drawstr.is_empty() ? CTX_IFACE_(ot->translation_context, ot->name) : drawstr);
2169 if (area != nullptr) {
2170 ED_area_status_text(area, header_text.c_str());
2171 }
2172 else {
2173 ED_workspace_status_text(C, header_text.c_str());
2174 }
2175 }
2176
2178
2179 OperatorWaitForInput *opwait = MEM_new<OperatorWaitForInput>(__func__);
2180 opwait->optype_params.optype = ot;
2181 opwait->optype_params.opcontext = opcontext;
2182 opwait->optype_params.opptr = properties;
2183
2184 opwait->area = area;
2185
2186 if (properties) {
2187 opwait->optype_params.opptr = MEM_new<PointerRNA>(__func__);
2188 *opwait->optype_params.opptr = *properties;
2189 if (properties->data != nullptr) {
2191 static_cast<IDProperty *>(properties->data));
2192 }
2193 }
2194
2195 if (const bContextStore *store = CTX_store_get(C)) {
2196 opwait->context = *store;
2197 }
2198
2200 &win->runtime->modalhandlers,
2203 opwait,
2205}
2206
2208
2209/* -------------------------------------------------------------------- */
2214
2216{
2217 /* Future extra custom-data free? */
2218 MEM_delete(handler);
2219}
2220
2226 wmEventHandler_Op *handler,
2227 const wmEvent *event,
2228 ScrArea **r_area,
2229 ARegion **r_region)
2230{
2231 wmWindow *win = handler->context.win ? handler->context.win : CTX_wm_window(C);
2232 /* It's probably fine to always use #WM_window_get_active_screen() to get the screen. But this
2233 * code has been getting it through context since forever, so play safe and stick to that when
2234 * possible. */
2235 bScreen *screen = handler->context.win ? WM_window_get_active_screen(win) : CTX_wm_screen(C);
2236
2237 *r_area = nullptr;
2238 *r_region = nullptr;
2239
2240 if (screen == nullptr || handler->op == nullptr) {
2241 return;
2242 }
2243
2244 if (handler->context.area == nullptr) {
2245 /* Pass. */
2246 }
2247 else {
2248 ScrArea *area = nullptr;
2249
2250 ED_screen_areas_iter (win, screen, area_iter) {
2251 if (area_iter == handler->context.area) {
2252 area = area_iter;
2253 break;
2254 }
2255 }
2256
2257#ifdef WITH_XR_OPENXR
2258 /* Special case for XR operators, which are executed in an XR-specific offscreen area. */
2260 if (xr_context != nullptr) {
2261 ScrArea *xr_offscreen_area = CTX_wm_area(xr_context);
2262 if (handler->context.area == xr_offscreen_area) {
2263 area = xr_offscreen_area;
2264 }
2265 }
2266#endif
2267
2268 if (area == nullptr) {
2269 /* When changing screen layouts with running modal handlers (like render display), this
2270 * is not an error to print. */
2271 if (handler->op == nullptr) {
2273 "internal error: handler (%s) has invalid area",
2274 handler->op->type->idname);
2275 }
2276 }
2277 else {
2278 ARegion *region;
2279 wmOperator *op = handler->op ? (handler->op->opm ? handler->op->opm : handler->op) : nullptr;
2280 *r_area = area;
2281
2282 if (op && (op->flag & OP_IS_MODAL_CURSOR_REGION)) {
2283 region = BKE_area_find_region_xy(area, handler->context.region_type, event->xy);
2284 if (region) {
2285 handler->context.region = region;
2286 }
2287 }
2288 else {
2289 region = nullptr;
2290 }
2291
2292 if ((region == nullptr) && handler->context.region) {
2293 if (BLI_findindex(&area->regionbase, handler->context.region) != -1) {
2294 region = handler->context.region;
2295 }
2296 }
2297
2298 /* No warning print here, after full-area and back regions are remade. */
2299 if (region) {
2300 *r_region = region;
2301 }
2302 }
2303 }
2304}
2305
2306static void wm_handler_op_context(bContext *C, wmEventHandler_Op *handler, const wmEvent *event)
2307{
2308 ScrArea *area = nullptr;
2309 ARegion *region = nullptr;
2310 wm_handler_op_context_get_if_valid(C, handler, event, &area, &region);
2311 CTX_wm_area_set(C, area);
2312 CTX_wm_region_set(C, region);
2313}
2314
2315void WM_event_remove_handlers(bContext *C, ListBaseT<wmEventHandler> *handlers)
2316{
2318
2319 /* C is zero on freeing database, modal handlers then already were freed. */
2320 while (wmEventHandler *handler_base = static_cast<wmEventHandler *>(BLI_pophead(handlers))) {
2321 BLI_assert(handler_base->type != 0);
2322 if (handler_base->type == WM_HANDLER_TYPE_OP) {
2323 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(handler_base);
2324
2325 if (handler->op) {
2326 wmWindow *win = CTX_wm_window(C);
2327
2328 if (handler->is_fileselect) {
2329 /* Exit File Browsers referring to this handler/operator. */
2330 for (wmWindow &temp_win : wm->windows) {
2331 ScrArea *file_area = ED_fileselect_handler_area_find(&temp_win, handler->op);
2332 if (!file_area) {
2333 continue;
2334 }
2335 ED_area_exit(C, file_area);
2336 }
2337 }
2338
2339 if (handler->op->type->cancel) {
2340 ScrArea *area = CTX_wm_area(C);
2341 ARegion *region = CTX_wm_region(C);
2342
2343 wm_handler_op_context(C, handler, win->runtime->eventstate);
2344
2345 if (handler->op->type->flag & OPTYPE_UNDO) {
2346 wm->op_undo_depth++;
2347 }
2348
2349 handler->op->type->cancel(C, handler->op);
2350
2351 if (handler->op->type->flag & OPTYPE_UNDO) {
2352 wm->op_undo_depth--;
2353 }
2354
2355 CTX_wm_area_set(C, area);
2356 CTX_wm_region_set(C, region);
2357 }
2358
2359 WM_cursor_grab_disable(win, nullptr);
2360
2361 if (handler->is_fileselect) {
2363 }
2364 else {
2365 WM_operator_free(handler->op);
2366 }
2367 }
2368 }
2369 else if (handler_base->type == WM_HANDLER_TYPE_UI) {
2370 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(handler_base);
2371
2372 if (handler->remove_fn) {
2373 ScrArea *area_prev = CTX_wm_area(C);
2374 ARegion *region_prev = CTX_wm_region(C);
2375 ARegion *region_popup_prev = CTX_wm_region_popup(C);
2376
2377 if (handler->context.area) {
2378 CTX_wm_area_set(C, handler->context.area);
2379 }
2380 if (handler->context.region) {
2381 CTX_wm_region_set(C, handler->context.region);
2382 }
2383 if (handler->context.region_popup) {
2384 BLI_assert(screen_temp_region_exists(handler->context.region_popup));
2385 CTX_wm_region_popup_set(C, handler->context.region_popup);
2386 }
2387
2388 handler->remove_fn(C, handler->user_data);
2389
2390 /* Currently we don't have a practical way to check if this region
2391 * was a temporary region created by `handler`, so do a full lookup. */
2392 if (region_popup_prev && !screen_temp_region_exists(region_popup_prev)) {
2393 region_popup_prev = nullptr;
2394 }
2395
2396 CTX_wm_area_set(C, area_prev);
2397 CTX_wm_region_set(C, region_prev);
2398 CTX_wm_region_popup_set(C, region_popup_prev);
2399 }
2400 }
2401
2402 wm_event_free_handler(handler_base);
2403 }
2404}
2405
2406BLI_INLINE bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
2407{
2408 if (kmi->flag & KMI_INACTIVE) {
2409 return false;
2410 }
2411
2412 if (winevent->flag & WM_EVENT_IS_REPEAT) {
2413 if (kmi->flag & KMI_REPEAT_IGNORE) {
2414 return false;
2415 }
2416 }
2417
2418 const int kmitype = WM_userdef_event_map(kmi->type);
2419
2420 /* The matching rules. */
2421 if (kmitype == KM_TEXTINPUT) {
2422#ifdef WITH_INPUT_IME
2423 if (IS_EVENT_IME_ANY(winevent->type)) {
2424 return true;
2425 }
2426#endif
2427 if (winevent->val == KM_PRESS) { /* Prevent double clicks. */
2428 if (ISKEYBOARD(winevent->type) && winevent->utf8_buf[0]) {
2429 return true;
2430 }
2431 }
2432 }
2433
2434 if (kmitype != KM_ANY) {
2435 if (ELEM(kmitype, TABLET_STYLUS, TABLET_ERASER)) {
2436 const wmTabletData *wmtab = &winevent->tablet;
2437
2438 if (winevent->type != LEFTMOUSE) {
2439 /* Tablet events can occur on hover + key-press. */
2440 return false;
2441 }
2442 if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) {
2443 return false;
2444 }
2445 if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) {
2446 return false;
2447 }
2448 }
2449 else {
2450 if (winevent->type != kmitype) {
2451 return false;
2452 }
2453 }
2454 }
2455
2456 if (kmi->val != KM_ANY) {
2457 if (winevent->val != kmi->val) {
2458 return false;
2459 }
2460 }
2461
2462 if (kmi->val == KM_PRESS_DRAG) {
2463 if (kmi->direction != KM_ANY) {
2464 if (kmi->direction != winevent->direction) {
2465 return false;
2466 }
2467 }
2468 }
2469
2470 /* Account for rare case of when these keys are used as the 'type' not as modifiers. */
2471 if (kmi->shift != KM_ANY) {
2472 const int8_t shift = (winevent->modifier & KM_SHIFT) ? KM_MOD_HELD : KM_NOTHING;
2473 if ((shift != kmi->shift) && !ELEM(winevent->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY)) {
2474 return false;
2475 }
2476 }
2477 if (kmi->ctrl != KM_ANY) {
2478 const int8_t ctrl = (winevent->modifier & KM_CTRL) ? KM_MOD_HELD : KM_NOTHING;
2479 if ((ctrl != kmi->ctrl) && !ELEM(winevent->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY)) {
2480 return false;
2481 }
2482 }
2483 if (kmi->alt != KM_ANY) {
2484 const int8_t alt = (winevent->modifier & KM_ALT) ? KM_MOD_HELD : KM_NOTHING;
2485 if ((alt != kmi->alt) && !ELEM(winevent->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY)) {
2486 return false;
2487 }
2488 }
2489 if (kmi->oskey != KM_ANY) {
2490 const int8_t oskey = (winevent->modifier & KM_OSKEY) ? KM_MOD_HELD : KM_NOTHING;
2491 if ((oskey != kmi->oskey) && (winevent->type != EVT_OSKEY)) {
2492 return false;
2493 }
2494 }
2495 if (kmi->hyper != KM_ANY) {
2496 const int8_t hyper = (winevent->modifier & KM_HYPER) ? KM_MOD_HELD : KM_NOTHING;
2497 if ((hyper != kmi->hyper) && (winevent->type != EVT_HYPER)) {
2498 return false;
2499 }
2500 }
2501
2502 /* Only key-map entry with key-modifier is checked,
2503 * means all keys without modifier get handled too. */
2504 /* That is currently needed to make overlapping events work (when you press A - G fast or so). */
2505 if (kmi->keymodifier) {
2506 if (winevent->keymodifier != kmi->keymodifier) {
2507 return false;
2508 }
2509 }
2510
2511 return true;
2512}
2513
2515 wmOperator *op,
2516 const wmEvent *event)
2517{
2518 for (wmKeyMapItem &kmi : keymap->items) {
2519 /* Should already be handled by #wm_user_modal_keymap_set_items. */
2520 BLI_assert(kmi.propvalue_str[0] == '\0');
2521 if (wm_eventmatch(event, &kmi)) {
2522 if ((keymap->poll_modal_item == nullptr) || keymap->poll_modal_item(op, kmi.propvalue)) {
2523 return &kmi;
2524 }
2525 }
2526 }
2527 return nullptr;
2528}
2529
2536
2548 wmOperator *op,
2549 wmEvent *event,
2550 wmEvent_ModalMapStore *event_backup)
2551{
2552 BLI_assert(event->type != EVT_MODAL_MAP);
2553
2554 /* Support for modal key-map in macros. */
2555 if (op->opm) {
2556 op = op->opm;
2557 }
2558
2559 event_backup->dbl_click_disabled = false;
2560
2561 if (op->type->modalkeymap) {
2563 wmKeyMapItem *kmi = nullptr;
2564
2565 const wmEvent *event_match = nullptr;
2566 wmEvent event_no_dbl_click;
2567
2568 if ((kmi = wm_eventmatch_modal_keymap_items(keymap, op, event))) {
2569 event_match = event;
2570 }
2571 else if (event->val == KM_DBL_CLICK) {
2572 event_no_dbl_click = *event;
2573 event_no_dbl_click.val = KM_PRESS;
2574 if ((kmi = wm_eventmatch_modal_keymap_items(keymap, op, &event_no_dbl_click))) {
2575 event_match = &event_no_dbl_click;
2576 }
2577 }
2578
2579 if (event_match != nullptr) {
2580 event_backup->prev_type = event->prev_type;
2581 event_backup->prev_val = event->prev_val;
2582
2583 event->prev_type = event_match->type;
2584 event->prev_val = event_match->val;
2585 event->type = EVT_MODAL_MAP;
2586 event->val = kmi->propvalue;
2587
2588 /* Avoid double-click events even in the case of #EVT_MODAL_MAP,
2589 * since it's possible users configure double-click key-map items
2590 * which would break when modal functions expect press/release. */
2591 if (event->prev_val == KM_DBL_CLICK) {
2592 event->prev_val = KM_PRESS;
2593 event_backup->dbl_click_disabled = true;
2594 }
2595 }
2596 }
2597
2598 if (event->type != EVT_MODAL_MAP) {
2599 /* This bypass just disables support for double-click in modal handlers. */
2600 if (event->val == KM_DBL_CLICK) {
2601 event->val = KM_PRESS;
2602 event_backup->dbl_click_disabled = true;
2603 }
2604 }
2605}
2606
2614static void wm_event_modalkeymap_end(wmEvent *event, const wmEvent_ModalMapStore *event_backup)
2615{
2616 if (event->type == EVT_MODAL_MAP) {
2617 event->type = event->prev_type;
2618 event->val = event->prev_val;
2619
2620 event->prev_type = event_backup->prev_type;
2621 event->prev_val = event_backup->prev_val;
2622 }
2623
2624 if (event_backup->dbl_click_disabled) {
2625 event->val = KM_DBL_CLICK;
2626 }
2627}
2628
2633{
2634 if (!(handler->op->type->flag & OPTYPE_MODAL_PRIORITY)) {
2635 /* Keep priority operators in front. */
2636 wmEventHandler *last_priority_handler = nullptr;
2637 for (wmEventHandler &handler_iter : win->runtime->modalhandlers) {
2638 if (handler_iter.type == WM_HANDLER_TYPE_OP) {
2639 wmEventHandler_Op *handler_iter_op = reinterpret_cast<wmEventHandler_Op *>(&handler_iter);
2640 if (handler_iter_op->op != nullptr) {
2641 if (handler_iter_op->op->type->flag & OPTYPE_MODAL_PRIORITY) {
2642 last_priority_handler = &handler_iter;
2643 continue;
2644 }
2645 }
2646 }
2647
2648 /* Stop at other UI handlers like popups. We don't want to disturb the relative order
2649 * of modal operators from those popups, e.g. dragging in the color picker. See #162498.
2650 * Otherwise the popup UI handler may free data used by the modal operator.
2651 *
2652 * This means modal operator priority order is only preserved relative to other modal
2653 * operators, to prevent them from interfering with menus and popups. */
2654 break;
2655 }
2656
2657 if (last_priority_handler) {
2658 BLI_insertlinkafter(&win->runtime->modalhandlers, last_priority_handler, handler);
2659 return;
2660 }
2661 }
2662
2663 BLI_addhead(&win->runtime->modalhandlers, handler);
2664}
2665
2670 ListBaseT<wmEventHandler> *handlers,
2671 wmEventHandler *handler_base,
2672 wmEvent *event,
2673 PointerRNA *properties,
2674 const char *kmi_idname)
2675{
2677
2678 /* Derived, modal or blocking operator. */
2679 if ((handler_base->type == WM_HANDLER_TYPE_OP) &&
2680 ((reinterpret_cast<wmEventHandler_Op *>(handler_base))->op != nullptr))
2681 {
2682 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(handler_base);
2683 wmOperator *op = handler->op;
2684 wmOperatorType *ot = op->type;
2685
2687 /* Interface is locked and operator is not allowed to run,
2688 * nothing to do in this case. */
2689 }
2690 else if (ot->modal) {
2691 PRF_scope_with_name("Operator Call (modal)", ProfileCategory::Default);
2692 PRF_scope_set_dynamic_name("Op: %s", ot->idname);
2693 /* We set context to where modal handler came from. */
2695 wmWindow *win = CTX_wm_window(C);
2696 ScrArea *area = CTX_wm_area(C);
2697 ARegion *region = CTX_wm_region(C);
2698
2699 wm_handler_op_context(C, handler, event);
2700 wm_region_mouse_co(C, event);
2701
2702 wmEvent_ModalMapStore event_backup;
2703 wm_event_modalkeymap_begin(C, op, event, &event_backup);
2704
2705 const intptr_t undo_id_prev = wm_operator_undo_active_id(wm);
2706 const intptr_t register_id_prev = wm_operator_register_active_id(wm);
2707 if (ot->flag & OPTYPE_UNDO) {
2708 wm->op_undo_depth++;
2709 }
2710
2711 /* Warning, after this call all context data and 'event' may be freed. see check below. */
2712 retval = ot->modal(C, op, event);
2713 OPERATOR_RETVAL_CHECK(retval);
2714
2715 if (ot->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
2716 wm->op_undo_depth--;
2717 }
2718
2719 /* When the window changes the modal modifier may have loaded a new blend file
2720 * (the `system_demo_mode` add-on does this), so we have to assume the event,
2721 * operator, area, region etc have all been freed. */
2722 if (CTX_wm_window(C) == win) {
2723
2724 wm_event_modalkeymap_end(event, &event_backup);
2725
2726 if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
2727 wm_operator_reports(C, op, retval, false);
2728
2729 wmOperator *op_test = handler->op->opm ? handler->op->opm : handler->op;
2730 if (op_test->type->modalkeymap) {
2732 }
2733 }
2734 else {
2735 /* Not very common, but modal operators may report before finishing. */
2736 if (!op->reports->list.is_empty()) {
2739 }
2740 }
2741
2742 /* Important to run 'wm_operator_finished' before setting the context members to null. */
2743 if (retval & OPERATOR_FINISHED) {
2744 const bool has_undo_step = (undo_id_prev != wm_operator_undo_active_id(wm));
2745 const bool has_register = (register_id_prev != wm_operator_register_active_id(wm));
2746
2747 wm_operator_finished(C, op, false, true, has_undo_step, has_register);
2748 handler->op = nullptr;
2749 }
2750 else if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
2751 WM_operator_free(op);
2752 handler->op = nullptr;
2753 }
2754
2755 /* Putting back screen context, `reval` can pass through after modal failures! */
2756 if ((retval & OPERATOR_PASS_THROUGH) || wm_event_always_pass(event)) {
2757 CTX_wm_area_set(C, area);
2758 CTX_wm_region_set(C, region);
2759 }
2760 else {
2761 /* This special cases is for areas and regions that get removed. */
2762 CTX_wm_area_set(C, nullptr);
2763 CTX_wm_region_set(C, nullptr);
2764 }
2765
2766 /* Update gizmos during modal handlers. */
2767 wm_gizmomaps_handled_modal_update(C, event, handler);
2768
2769 /* Remove modal handler, operator itself should have been canceled and freed. */
2770 if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
2772
2773 BLI_remlink(handlers, handler);
2774 wm_event_free_handler(&handler->head);
2775
2776 /* Prevent silly errors from operator users. */
2777 // retval &= ~OPERATOR_PASS_THROUGH;
2778 }
2779 }
2780 }
2781 else {
2782 CLOG_ERROR(WM_LOG_EVENTS, "Missing modal '%s'", op->idname);
2783 }
2784 }
2785 else {
2786 wmOperatorType *ot = WM_operatortype_find(kmi_idname, false);
2787
2788 if (ot && wm_operator_check_locked_interface(C, ot)) {
2789 bool use_last_properties = true;
2790 PointerRNA tool_properties = {};
2791
2792 bToolRef *keymap_tool = nullptr;
2793 if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
2794 keymap_tool = (reinterpret_cast<wmEventHandler_Keymap *>(handler_base))->keymap_tool;
2795 }
2796 else if (handler_base->type == WM_HANDLER_TYPE_GIZMO) {
2797 wmGizmoMap *gizmo_map =
2798 (reinterpret_cast<wmEventHandler_Gizmo *>(handler_base))->gizmo_map;
2799 wmGizmo *gz = wm_gizmomap_highlight_get(gizmo_map);
2800 if (gz && (gz->flag & WM_GIZMO_OPERATOR_TOOL_INIT)) {
2801 keymap_tool = WM_toolsystem_ref_from_context(C);
2802 }
2803 }
2804
2805 const bool is_tool = (keymap_tool != nullptr);
2806 const bool use_tool_properties = is_tool;
2807
2808 if (use_tool_properties) {
2810 keymap_tool, &tool_properties, properties, ot);
2811 properties = &tool_properties;
2812 use_last_properties = false;
2813 }
2814
2815 retval = wm_operator_invoke(C, ot, event, properties, nullptr, false, use_last_properties);
2816
2817 if (use_tool_properties) {
2818 WM_operator_properties_free(&tool_properties);
2819 }
2820
2821 /* Link gizmo if #WM_GIZMOGROUPTYPE_TOOL_INIT is set. */
2822 if (retval & OPERATOR_FINISHED) {
2823 if (is_tool) {
2824 bToolRef_Runtime *tref_rt = keymap_tool->runtime;
2825 if (tref_rt->gizmo_group[0]) {
2826 const char *idname = tref_rt->gizmo_group;
2827 wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
2828 if (gzgt != nullptr) {
2829 if ((gzgt->flag & WM_GIZMOGROUPTYPE_TOOL_INIT) != 0) {
2830 ARegion *region = CTX_wm_region(C);
2831 if (region != nullptr) {
2833 WM_gizmo_group_type_ensure_ptr_ex(gzgt, gzmap_type);
2835 gzmap_type, gzgt, region);
2836 /* We can't rely on drawing to initialize gizmo's since disabling
2837 * overlays/gizmos will prevent pre-drawing setup calls, see #60905. */
2838 WM_gizmogroup_ensure_init(C, gzgroup);
2839 }
2840 }
2841 }
2842 }
2843 }
2844 }
2845 /* Done linking gizmo. */
2846 }
2847 }
2848
2849 /* Finished and pass through flag as handled. */
2850 if (retval == (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH)) {
2851 return WM_HANDLER_HANDLED;
2852 }
2853
2854 /* Modal unhandled, break. */
2857 }
2858
2859 if (retval & OPERATOR_PASS_THROUGH) {
2860 return WM_HANDLER_CONTINUE;
2861 }
2862
2863 return WM_HANDLER_BREAK;
2864}
2865
2867{
2868 for (bScreen &screen : G_MAIN->screens) {
2869 for (ScrArea &area : screen.areabase) {
2870 if (area.spacetype == SPACE_FILE) {
2871 SpaceFile *sfile = area.spacedata.first_as<SpaceFile>();
2872 if (sfile->op == file_operator) {
2873 sfile->op = nullptr;
2874 }
2875 }
2876 }
2877 }
2878
2879 WM_operator_free(file_operator);
2880}
2881
2887 ListBaseT<wmEventHandler> *handlers,
2888 wmEventHandler_Op *handler,
2889 int val)
2890{
2893
2894 switch (val) {
2896 /* Maximized file browser does not work for file browsing from popups, as switching the
2897 * screen closes it. */
2898 const int display_type = handler->is_fileselect_keep_popup ? USER_TEMP_SPACE_DISPLAY_WINDOW :
2899 U.filebrowser_display_type;
2901 C, IFACE_("Blender File View"), SPACE_FILE, display_type, true);
2902 if (!area) {
2903 BKE_report(&wm->runtime->reports, RPT_ERROR, "Failed to open file browser!");
2904 return WM_HANDLER_BREAK;
2905 }
2906
2907 ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
2909
2910 region_header->flag |= RGN_FLAG_HIDDEN;
2911 /* Header on bottom, #AZone triangle to toggle header looks misplaced at the top. */
2912 region_header->alignment = RGN_ALIGN_BOTTOM;
2913
2914 /* Settings for file-browser, #sfile is not operator owner but sends events. */
2915 SpaceFile *sfile = area->spacedata.first_as<SpaceFile>();
2916 sfile->op = handler->op;
2917
2919
2920 action = WM_HANDLER_BREAK;
2921 break;
2922 }
2923
2927 wmWindow *ctx_win = CTX_wm_window(C);
2928 wmEvent *eventstate = ctx_win->runtime->eventstate;
2929 /* The root window of the operation as determined in #WM_event_add_fileselect(). */
2930 wmWindow *root_win = handler->context.win;
2931
2932 /* Remove link now, for load file case before removing. */
2933 BLI_remlink(handlers, handler);
2934
2935 if (val == EVT_FILESELECT_EXTERNAL_CANCEL) {
2936 /* The window might have been freed already. */
2937 if (BLI_findindex(&wm->windows, handler->context.win) == -1) {
2938 handler->context.win = nullptr;
2939 }
2940 }
2941 else {
2942 ScrArea *ctx_area = CTX_wm_area(C);
2943
2944 wmWindow *temp_win = nullptr;
2945 for (wmWindow &win : wm->windows) {
2946 bScreen *screen = WM_window_get_active_screen(&win);
2947 ScrArea *file_area = screen->areabase.first();
2948
2949 if ((file_area->spacetype != SPACE_FILE) || !WM_window_is_temp_screen(&win)) {
2950 continue;
2951 }
2952
2953 if (file_area->full) {
2954 /* Users should not be able to maximize/full-screen an area in a temporary screen.
2955 * So if there's a maximized file browser in a temporary screen,
2956 * it was likely opened by #EVT_FILESELECT_FULL_OPEN. */
2957 continue;
2958 }
2959
2960 ED_fileselect_params_to_userdef(file_area->spacedata.first_as<SpaceFile>());
2961
2962 if (file_area->spacedata.is_single()) {
2963 BLI_assert(root_win != &win);
2964
2966
2967 /* #wm_window_close() sets the context's window to null. */
2968 CTX_wm_window_set(C, root_win);
2969
2970 /* Some operators expect a drawable context (for #EVT_FILESELECT_EXEC). */
2971 wm_window_make_drawable(wm, root_win);
2972 /* Ensure correct cursor position, otherwise, popups may close immediately after
2973 * opening (#BLOCK_MOVEMOUSE_QUIT). */
2974 int xy[2];
2975 if (wm_cursor_position_get(root_win, &xy[0], &xy[1])) {
2976 copy_v2_v2_int(eventstate->xy, xy);
2977 }
2978 wm->runtime->winactive = root_win; /* Reports use this... */
2979 }
2980 else if (file_area->full) {
2981 ED_screen_full_prevspace(C, file_area);
2982 }
2983 else {
2984 ED_area_prevspace(C, file_area);
2985 }
2986
2987 temp_win = &win;
2988 break;
2989 }
2990
2991 if (!temp_win && ctx_area->full) {
2993 ED_screen_full_prevspace(C, ctx_area);
2994 }
2995 }
2996
2997 CTX_wm_window_set(C, root_win);
2998 wm_handler_op_context(C, handler, eventstate);
2999 /* At this point context is supposed to match the root context determined by
3000 * #WM_event_add_fileselect(). */
3001 BLI_assert(!CTX_wm_area(C) || (CTX_wm_area(C) == handler->context.area));
3002 BLI_assert(!CTX_wm_region(C) || (CTX_wm_region(C) == handler->context.region));
3003
3004 ScrArea *handler_area = CTX_wm_area(C);
3005 /* Make sure new context area is ready, the operator callback may operate on it. */
3006 if (handler_area) {
3007 ED_area_do_refresh(C, handler_area);
3008 }
3009
3010 /* Needed for #popup_menu_reports. */
3011
3012 if (val == EVT_FILESELECT_EXEC) {
3013 if (handler->op->type->flag & OPTYPE_UNDO) {
3014 wm->op_undo_depth++;
3015 }
3016
3017 const wmOperatorStatus retval = handler->op->type->exec(C, handler->op);
3018 OPERATOR_RETVAL_CHECK(retval);
3019
3020 /* XXX check this carefully, `CTX_wm_manager(C) == wm` is a bit hackish. */
3021 if (handler->op->type->flag & OPTYPE_UNDO && CTX_wm_manager(C) == wm) {
3022 wm->op_undo_depth--;
3023 }
3024
3025 /* XXX check this carefully, `CTX_wm_manager(C) == wm` is a bit hackish. */
3026 if (retval & OPERATOR_FINISHED) {
3027 if (CTX_wm_manager(C) == wm && wm->op_undo_depth == 0) {
3028 if (handler->op->type->flag & OPTYPE_UNDO) {
3029 ED_undo_push_op(C, handler->op);
3030 }
3031 else if (handler->op->type->flag & OPTYPE_UNDO_GROUPED) {
3032 ED_undo_grouped_push_op(C, handler->op);
3033 }
3034 }
3035 }
3036
3037 if (handler->op->reports->list.first()) {
3038
3039 /* FIXME(@ideasman42): temp setting window, this is really bad!
3040 * only have because lib linking errors need to be seen by users :(
3041 * it can be removed without breaking anything but then no linking errors. */
3042 wmWindow *win_prev = CTX_wm_window(C);
3043 ScrArea *area_prev = CTX_wm_area(C);
3044 ARegion *region_prev = CTX_wm_region(C);
3045
3046 if (win_prev == nullptr) {
3047 CTX_wm_window_set(C, CTX_wm_manager(C)->windows.first());
3048 }
3049
3051 ui::popup_menu_reports(C, handler->op->reports);
3052
3054
3055 CTX_wm_window_set(C, win_prev);
3056 CTX_wm_area_set(C, area_prev);
3057 CTX_wm_region_set(C, region_prev);
3058 }
3059
3060 /* For #WM_operator_pystring only, custom report handling is done above. */
3061 wm_operator_reports(C, handler->op, retval, true);
3062
3063 if (retval & OPERATOR_FINISHED) {
3065 }
3066
3067 if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
3069 }
3070 }
3071 else {
3072 if (handler->op->type->cancel) {
3073 if (handler->op->type->flag & OPTYPE_UNDO) {
3074 wm->op_undo_depth++;
3075 }
3076
3077 handler->op->type->cancel(C, handler->op);
3078
3079 if (handler->op->type->flag & OPTYPE_UNDO) {
3080 wm->op_undo_depth--;
3081 }
3082 }
3084 }
3085
3086 CTX_wm_area_set(C, nullptr);
3087
3088 wm_event_free_handler(&handler->head);
3089
3090 action = WM_HANDLER_BREAK;
3091 break;
3092 }
3093 }
3094
3095 return action;
3096}
3097
3099 ListBaseT<wmEventHandler> *handlers,
3100 wmEventHandler_Op *handler,
3101 const wmEvent *event)
3102{
3104
3105 if (event->type != EVT_FILESELECT) {
3106 return action;
3107 }
3108 if (handler->op != static_cast<wmOperator *>(event->customdata)) {
3109 return action;
3110 }
3111
3112 return wm_handler_fileselect_do(C, handlers, handler, event->val);
3113}
3114
3116{
3117 return action == WM_HANDLER_CONTINUE || action == (WM_HANDLER_BREAK | WM_HANDLER_MODAL);
3118}
3119
3121{
3122 if (action & WM_HANDLER_BREAK) {
3123 return "handled";
3124 }
3125 if (action & WM_HANDLER_HANDLED) {
3126 return "handled (and pass on)";
3127 }
3128 return "un-handled";
3129}
3130
3131static std::optional<std::string> keymap_handler_log_kmi_event_str(const wmKeyMapItem *kmi)
3132{
3133 /* Short representation of the key that was pressed,
3134 * include this since it may differ from the event in minor details
3135 * which can help looking up the key-map definition. */
3136 return WM_keymap_item_to_string(kmi, false);
3137}
3138
3140{
3141 /* The key-map item properties can further help distinguish this item from others. */
3142 std::optional<std::string> kmi_props;
3143 if (kmi->properties != nullptr) {
3144 wmOperatorType *ot = WM_operatortype_find(kmi->idname, false);
3145 if (ot) {
3146 kmi_props = RNA_pointer_as_string_keywords(C, kmi->ptr, false, false, true, 512);
3147 }
3148 else { /* Fallback. */
3149 char *c_str = IDP_reprN(kmi->properties, nullptr);
3150 kmi_props = c_str;
3151 MEM_delete(c_str);
3152 }
3153 }
3154 return fmt::format("{}({})", kmi->idname, kmi_props.value_or(""));
3155}
3156
3157#define PRINT \
3158 if (do_debug_handler) \
3159 printf
3160
3162 /* From 'wm_handlers_do_intern'. */
3163 bContext *C,
3164 wmEvent *event,
3165 ListBaseT<wmEventHandler> *handlers,
3166 wmEventHandler_Keymap *handler,
3167 /* Additional. */
3168 wmKeyMap *keymap,
3169 const bool do_debug_handler)
3170{
3172
3173 if (keymap == nullptr) {
3174 /* Only callback is allowed to have nullptr key-maps. */
3175 BLI_assert(handler->dynamic.keymap_fn);
3176 }
3177 else {
3178 PRINT("%s: checking '%s' ...", __func__, keymap->idname);
3179
3180 if (WM_keymap_poll(C, keymap)) {
3181
3182 PRINT("pass\n");
3183
3184 for (wmKeyMapItem &kmi : keymap->items) {
3185 if (wm_eventmatch(event, &kmi)) {
3186 wmEventHandler_KeymapPost keymap_post = handler->post;
3187
3188 action |= wm_handler_operator_call(
3189 C, handlers, &handler->head, event, kmi.ptr, kmi.idname);
3190
3192 "Keymap '%s', %s, %s, event: %s",
3193 keymap->idname,
3194 keymap_handler_log_kmi_op_str(C, &kmi).c_str(),
3196 keymap_handler_log_kmi_event_str(&kmi).value_or("").c_str());
3197
3198 if (action & WM_HANDLER_BREAK) {
3199 /* Not always_pass here, it denotes removed handler_base. */
3200 if (keymap_post.post_fn != nullptr) {
3201 keymap_post.post_fn(keymap, &kmi, keymap_post.user_data);
3202 }
3203 break;
3204 }
3205 }
3206 }
3207 }
3208 else {
3209 PRINT("fail\n");
3210 }
3211 }
3212
3213 return action;
3214}
3215
3217 /* From #wm_handlers_do_intern. */
3218 bContext *C,
3219 wmEvent *event,
3220 ListBaseT<wmEventHandler> *handlers,
3221 wmEventHandler_Gizmo *handler,
3222 /* Additional. */
3223 wmGizmoGroup *gzgroup,
3224 wmKeyMap *keymap,
3225 const bool do_debug_handler,
3226 bool *r_keymap_poll)
3227{
3229 bool keymap_poll = false;
3230
3231 PRINT("%s: checking '%s' ...", __func__, keymap->idname);
3232
3233 if (WM_keymap_poll(C, keymap)) {
3234 keymap_poll = true;
3235 PRINT("pass\n");
3236 for (wmKeyMapItem &kmi : keymap->items) {
3237 if (wm_eventmatch(event, &kmi)) {
3238 PRINT("%s: item matched '%s'\n", __func__, kmi.idname);
3239
3240 CTX_wm_gizmo_group_set(C, gzgroup);
3241
3242 /* `handler->op` is called later, we want key-map op to be triggered here. */
3243 action |= wm_handler_operator_call(
3244 C, handlers, &handler->head, event, kmi.ptr, kmi.idname);
3245
3246 CTX_wm_gizmo_group_set(C, nullptr);
3247
3248 if (action & WM_HANDLER_BREAK) {
3249 if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) {
3250 printf("%s: handled - and pass on! '%s'\n", __func__, kmi.idname);
3251 }
3252 break;
3253 }
3254 if (action & WM_HANDLER_HANDLED) {
3255 if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) {
3256 printf("%s: handled - and pass on! '%s'\n", __func__, kmi.idname);
3257 }
3258 }
3259 else {
3260 PRINT("%s: un-handled '%s'\n", __func__, kmi.idname);
3261 }
3262 }
3263 }
3264 }
3265 else {
3266 PRINT("fail\n");
3267 }
3268
3269 if (r_keymap_poll) {
3270 *r_keymap_poll = keymap_poll;
3271 }
3272
3273 return action;
3274}
3275
3278 wmEventHandler_Gizmo *handler,
3279 wmEvent *event,
3280 const bool always_pass,
3281 ListBaseT<wmEventHandler> *handlers,
3282 const bool do_debug_handler)
3283{
3285
3286 /* NOTE(@ideasman42): early exit for always-pass events (typically timers)
3287 * which pass through from running modal operators which may have started them.
3288 * In the case of blocking modal operators, it's not expected that gizmos would
3289 * be used at the same time as navigating or painting for example.
3290 *
3291 * In principle these could be handled, however in practice:
3292 * `handle_highlight` & `handle_keymap` would be set to false for timers,
3293 * making this function do practically nothing.
3294 *
3295 * Early exit to avoid complicating checks below.
3296 * The early return can be replaced with checks that only run
3297 * necessary logic if these events need to be handled in the future.
3298 *
3299 * Without this, gizmos can become highlighted and the cursor changed
3300 * while navigating in the 3D viewport, see: #139681. */
3301 if (always_pass) {
3302 return action;
3303 }
3304
3305 /* Drag events use the previous click location to highlight the gizmos,
3306 * Get the highlight again in case the user dragged off the gizmo. */
3307 const bool is_event_drag = (event->val == KM_PRESS_DRAG);
3308 const bool is_event_modifier = ISKEYMODIFIER(event->type);
3309 /* Only keep the highlight if the gizmo becomes modal as result of event handling.
3310 * Without this check, even un-handled drag events will set the highlight if the drag
3311 * was initiated over a gizmo. */
3312 const bool restore_highlight_unless_activated = is_event_drag;
3313
3314 ScrArea *area = CTX_wm_area(C);
3315 ARegion *region = CTX_wm_region(C);
3316 wmGizmoMap *gzmap = handler->gizmo_map;
3317 BLI_assert(gzmap != nullptr);
3319
3320 if (gz && ISMOUSE(event->type) && event->val == KM_PRESS) {
3321 /* Remove any tooltips on mouse down. #83589 */
3323 }
3324
3325 /* Needed so UI blocks over gizmos don't let events fall through to the gizmos,
3326 * noticeable for the node editor - where dragging on a node should move it, see: #73212.
3327 * note we still allow for starting the gizmo drag outside, then travel 'inside' the node. */
3328 if (region->runtime->type->clip_gizmo_events_by_ui) {
3329 if (ui::region_block_find_mouse_over(region, event->xy, true)) {
3330 if (gz != nullptr && event->type != EVT_GIZMO_UPDATE) {
3331 if (restore_highlight_unless_activated == false) {
3333 wm_gizmomap_highlight_set(gzmap, C, nullptr, 0);
3334 }
3335 }
3336 return action;
3337 }
3338 }
3339
3340 struct PrevGizmoData {
3341 wmGizmo *gz_modal;
3342 wmGizmo *gz;
3343 int part;
3344 };
3345 PrevGizmoData prev{};
3346 prev.gz_modal = wm_gizmomap_modal_get(gzmap);
3347 prev.gz = gz;
3348 prev.part = gz ? gz->highlight_part : 0;
3349
3350 if (region->runtime->gizmo_map != handler->gizmo_map) {
3352 }
3353
3355 wm_region_mouse_co(C, event);
3356
3357 bool handle_highlight = false;
3358 bool handle_keymap = false;
3359
3360 /* Handle gizmo highlighting. */
3361 if ((prev.gz_modal == nullptr) &&
3362 ((event->type == MOUSEMOVE) || is_event_modifier || is_event_drag))
3363 {
3364 handle_highlight = true;
3365 if (is_event_modifier || is_event_drag) {
3366 handle_keymap = true;
3367 }
3368 }
3369 else {
3370 handle_keymap = true;
3371 }
3372
3373 /* There is no need to handle this event when the key-map isn't being applied
3374 * since any change to the highlight will be restored to the previous value. */
3375 if (restore_highlight_unless_activated) {
3376 if ((handle_highlight == true) && (handle_keymap == false)) {
3377 return action;
3378 }
3379 }
3380
3381 if (prev.gz_modal == nullptr) {
3382 if (handle_highlight == false && wm_gizmomap_highlight_pending(gzmap)) {
3383 handle_highlight = true;
3384 }
3385 }
3386
3387 if (handle_highlight) {
3388 int part = -1;
3389 gz = wm_gizmomap_highlight_find(gzmap, C, event, &part);
3390
3391 /* If no gizmos are/were active, don't clear tool-tips. */
3392 if (gz || prev.gz) {
3393 if ((prev.gz != gz) || (prev.part != part)) {
3395 }
3396 }
3397
3398 if (wm_gizmomap_highlight_set(gzmap, C, gz, part)) {
3399 if (gz != nullptr) {
3400 if ((U.flag & USER_TOOLTIPS) && (gz->flag & WM_GIZMO_NO_TOOLTIP) == 0) {
3402 }
3403 }
3404 }
3405
3407 }
3408
3409 /* Don't use from now on. */
3410 bool is_event_handle_all = gz && (gz->flag & WM_GIZMO_EVENT_HANDLE_ALL);
3411
3412 if (handle_keymap) {
3413 /* Handle highlight gizmo. */
3414 if ((gz != nullptr) && (gz->flag & WM_GIZMO_HIDDEN_KEYMAP) == 0) {
3415 bool keymap_poll = false;
3416 wmGizmoGroup *gzgroup = gz->parent_gzgroup;
3417 wmKeyMap *keymap = WM_keymap_active(wm, gz->keymap ? gz->keymap : gzgroup->type->keymap);
3419 C, event, handlers, handler, gzgroup, keymap, do_debug_handler, &keymap_poll);
3420
3421#ifdef USE_GIZMO_MOUSE_PRIORITY_HACK
3422 if (((action & WM_HANDLER_BREAK) == 0) && !is_event_handle_all && keymap_poll) {
3423 if ((event->val == KM_PRESS) && ELEM(event->type, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE)) {
3424
3425 wmEvent event_test_click = *event;
3426 event_test_click.val = KM_CLICK;
3427
3428 wmEvent event_test_press_drag = *event;
3429 event_test_press_drag.val = KM_PRESS_DRAG;
3430
3431 for (wmKeyMapItem &kmi : keymap->items) {
3432 if ((kmi.flag & KMI_INACTIVE) == 0) {
3433 if (wm_eventmatch(&event_test_click, &kmi) ||
3434 wm_eventmatch(&event_test_press_drag, &kmi))
3435 {
3436 wmOperatorType *ot = WM_operatortype_find(kmi.idname, false);
3437 const bool success = WM_operator_poll_context(
3439 if (success) {
3440 is_event_handle_all = true;
3441 break;
3442 }
3443 }
3444 }
3445 }
3446 }
3447 }
3448#endif /* `USE_GIZMO_MOUSE_PRIORITY_HACK` */
3449 }
3450
3451 /* Don't use from now on. */
3452 gz = nullptr;
3453
3454 /* Fall back to selected gizmo (when un-handled). */
3455 if ((action & WM_HANDLER_BREAK) == 0) {
3456 if (WM_gizmomap_is_any_selected(gzmap)) {
3457 const ListBaseT<wmGizmoGroup> *groups = WM_gizmomap_group_list(gzmap);
3458 for (wmGizmoGroup &gzgroup : *groups) {
3459 if (wm_gizmogroup_is_any_selected(&gzgroup)) {
3460 wmKeyMap *keymap = WM_keymap_active(wm, gzgroup.type->keymap);
3462 C, event, handlers, handler, &gzgroup, keymap, do_debug_handler, nullptr);
3463 if (action & WM_HANDLER_BREAK) {
3464 break;
3465 }
3466 }
3467 }
3468 }
3469 }
3470 }
3471
3472 if (handle_highlight) {
3473 if (restore_highlight_unless_activated) {
3474 /* Check handling the key-map didn't activate a gizmo. */
3475 wmGizmo *gz_modal = wm_gizmomap_modal_get(gzmap);
3476 if (!(gz_modal && (gz_modal != prev.gz_modal))) {
3477 wm_gizmomap_highlight_set(gzmap, C, prev.gz, prev.part);
3478 }
3479 }
3480 }
3481
3482 if (is_event_handle_all) {
3483 if (action == WM_HANDLER_CONTINUE) {
3485 }
3486 }
3487
3488 /* Restore the area. */
3489 CTX_wm_area_set(C, area);
3490 CTX_wm_region_set(C, region);
3491
3492 return action;
3493}
3494
3496
3497/* -------------------------------------------------------------------- */
3500
3502 wmWindow *win,
3503 wmEvent *event,
3504 ListBaseT<wmEventHandler> *handlers)
3505{
3506 const bool do_debug_handler =
3507 (G.debug & G_DEBUG_HANDLERS) &&
3508 /* Comment this out to flood the console! (if you really want to test). */
3509 !ISMOUSE_MOTION(event->type);
3510
3513
3514 if (handlers == nullptr) {
3515 wm_event_handler_return_value_check(C, event, action);
3516 return action;
3517 }
3518
3519 /* Modal handlers can get removed in this loop, we keep the loop this way.
3520 *
3521 * NOTE: check 'handlers->first' because in rare cases the handlers can be cleared
3522 * by the event that's called, for eg:
3523 *
3524 * Calling a python script which changes the area.type, see #32232. */
3525 for (wmEventHandler *handler_base = handlers->first(), *handler_base_next;
3526 handler_base && handlers->first();
3527 handler_base = handler_base_next)
3528 {
3529 handler_base_next = handler_base->next;
3530
3531 /* During this loop, UI handlers for nested menus can tag multiple handlers free. */
3532 if (handler_base->flag & WM_HANDLER_DO_FREE) {
3533 /* Pass. */
3534 }
3535 else if (handler_base->poll == nullptr ||
3536 handler_base->poll(win, CTX_wm_area(C), CTX_wm_region(C), event))
3537 {
3538 /* In advance to avoid access to freed event on window close. */
3539 const bool always_pass = wm_event_always_pass(event);
3540
3541 /* Modal+blocking handler_base. */
3542 if (handler_base->flag & WM_HANDLER_BLOCKING) {
3543 action |= WM_HANDLER_BREAK;
3544 }
3545
3546 /* Handle all types here. */
3547 if (handler_base->type == WM_HANDLER_TYPE_KEYMAP) {
3548 wmEventHandler_Keymap *handler = reinterpret_cast<wmEventHandler_Keymap *>(handler_base);
3550 WM_event_get_keymaps_from_handler(wm, win, handler, &km_result);
3552 /* Compute in advance, as event may be freed on WM_HANDLER_BREAK. */
3553 const bool event_is_timer = ISTIMER(event->type);
3554 for (int km_index = 0; km_index < km_result.keymaps_len; km_index++) {
3555 wmKeyMap *keymap = km_result.keymaps[km_index];
3557 C, event, handlers, handler, keymap, do_debug_handler);
3558 if (action_iter & WM_HANDLER_BREAK) {
3559 break;
3560 }
3561 }
3562 action |= action_iter;
3563
3564 /* Clear the tool-tip whenever a key binding is handled, without this tool-tips
3565 * are kept when a modal operators starts (annoying but otherwise harmless). */
3566 if (action & WM_HANDLER_BREAK && !event_is_timer) {
3567 /* Window may be gone after file read. */
3568 if (CTX_wm_window(C) != nullptr) {
3570 }
3571 }
3572 }
3573 else if (handler_base->type == WM_HANDLER_TYPE_UI) {
3574 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(handler_base);
3575 BLI_assert(handler->handle_fn != nullptr);
3576 if (!wm->runtime->is_interface_locked) {
3577 action |= wm_handler_ui_call(C, handler, event, always_pass);
3578 }
3579 }
3580 else if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) {
3581 wmEventHandler_Dropbox *handler = reinterpret_cast<wmEventHandler_Dropbox *>(handler_base);
3582 if (!wm->runtime->is_interface_locked && event->type == EVT_DROP) {
3583 for (wmDropBox &drop : *handler->dropboxes) {
3584 /* Other drop custom types allowed. */
3585 if (event->custom == EVT_DATA_DRAGDROP) {
3586 ListBaseT<wmDrag> *lb = static_cast<ListBaseT<wmDrag> *>(event->customdata);
3587 for (wmDrag &drag : lb->items_mutable()) {
3588 if (!wm_drag_asset_path_exists(&drag).value_or(true)) {
3589 continue;
3590 }
3591
3592 if (wmDragAsset *asset_data = WM_drag_get_asset_data(&drag, 0)) {
3593 if (asset_data->asset->is_online_only()) {
3595 RPT_ERROR,
3596 "Asset '%s' is still downloading",
3597 asset_data->asset->get_name().c_str());
3598 continue;
3599 }
3600 }
3601
3602 if (drop.poll(C, &drag, event)) {
3603 wm_drop_prepare(C, &drag, &drop);
3604
3605 /* Pass single matched #wmDrag onto the operator. */
3606 BLI_remlink(lb, &drag);
3607 ListBaseT<wmDrag> single_lb = {nullptr};
3608 BLI_addtail(&single_lb, &drag);
3609 event->customdata = &single_lb;
3610
3611 const wm::OpCallContext opcontext = wm_drop_operator_context_get(&drop);
3612 const wmOperatorStatus op_retval =
3614 C, drop.ot, drop.ptr, nullptr, opcontext, false, event) :
3616 OPERATOR_RETVAL_CHECK(op_retval);
3617
3618 if ((op_retval & OPERATOR_CANCELLED) && drop.cancel) {
3619 drop.cancel(CTX_data_main(C), &drag, &drop);
3620 }
3621
3622 action |= WM_HANDLER_BREAK;
3623
3624 /* Some of the values will have been freed when freeing the window-manger. */
3625 const bool is_file_read = CTX_wm_window(C) == nullptr;
3626
3627 /* Free the drags. */
3628 if (!is_file_read) {
3630 }
3631 WM_drag_free_list(&single_lb);
3632
3633 if (!is_file_read) {
3634 wm_event_custom_clear(event);
3635 }
3636
3637 wm_drop_end(C, &drag, &drop);
3638
3639 /* XXX file-read case. */
3640 if (is_file_read) {
3641 return action;
3642 }
3643
3644 /* Escape from drag loop, got freed. */
3645 break;
3646 }
3647 }
3648 /* Always exit all drags on a drop event, even if poll didn't succeed. */
3649 wm_drags_exit(wm, win);
3650 }
3651 }
3652 }
3653 }
3654 else if (handler_base->type == WM_HANDLER_TYPE_GIZMO) {
3655 wmEventHandler_Gizmo *handler = reinterpret_cast<wmEventHandler_Gizmo *>(handler_base);
3657 C, wm, handler, event, always_pass, handlers, do_debug_handler);
3658 }
3659 else if (handler_base->type == WM_HANDLER_TYPE_OP) {
3660 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(handler_base);
3661 if (handler->is_fileselect) {
3662 if (!wm->runtime->is_interface_locked) {
3663 /* Screen context changes here. */
3664 action |= wm_handler_fileselect_call(C, handlers, handler, event);
3665 }
3666 }
3667 else {
3668 action |= wm_handler_operator_call(C, handlers, handler_base, event, nullptr, nullptr);
3669 }
3670 }
3671 else {
3672 /* Unreachable (handle all types above). */
3674 }
3675
3676 if (action & WM_HANDLER_BREAK) {
3677 if (always_pass) {
3678 action &= ~WM_HANDLER_BREAK;
3679 }
3680 else {
3681 break;
3682 }
3683 }
3684 }
3685
3686 /* File-read case, if the wm is freed then the handler's
3687 * will have been too so the code below need not run. */
3688 if (CTX_wm_window(C) == nullptr) {
3689 return action;
3690 }
3691
3692 /* Code this for all modal ops, and ensure free only happens here. */
3693
3694 /* The handler Could be freed already by regular modal ops. */
3695 if (BLI_findindex(handlers, handler_base) != -1) {
3696 /* Modal UI handler can be tagged to be freed. */
3697 if (handler_base->flag & WM_HANDLER_DO_FREE) {
3698 BLI_remlink(handlers, handler_base);
3699 wm_event_free_handler(handler_base);
3700 }
3701 }
3702 }
3703
3704 if (action == (WM_HANDLER_BREAK | WM_HANDLER_MODAL)) {
3706 }
3707
3708 /* Do some extra sanity checking before returning the action. */
3709 wm_event_handler_return_value_check(C, event, action);
3710 return action;
3711}
3712
3713#undef PRINT
3714
3715/* This calls handlers twice - to solve (double-)click events. */
3717 wmEvent *event,
3718 ListBaseT<wmEventHandler> *handlers)
3719{
3720 eHandlerActionFlag action = wm_handlers_do_intern(C, CTX_wm_window(C), event, handlers);
3721
3722 /* Will be nullptr in the file read case. */
3723 wmWindow *win = CTX_wm_window(C);
3724 if (win == nullptr) {
3725 return action;
3726 }
3727
3728 if (ISMOUSE_MOTION(event->type)) {
3729 /* Test for #KM_PRESS_DRAG events. */
3730
3731 /* NOTE(@ideasman42): Needed so drag can be used for editors that support both click
3732 * selection and passing through the drag action to box select. See #WM_generic_select_modal.
3733 * Unlike click, accept `action` when break isn't set.
3734 * Operators can return `OPERATOR_FINISHED | OPERATOR_PASS_THROUGH` which results
3735 * in `action` setting #WM_HANDLER_HANDLED, but not #WM_HANDLER_BREAK. */
3736 if ((action & WM_HANDLER_BREAK) == 0 || wm_action_not_handled(action)) {
3737 if (win->event_queue_check_drag) {
3738 if ((event->flag & WM_EVENT_FORCE_DRAG_THRESHOLD) ||
3739 WM_event_drag_test(event, event->prev_press_xy))
3740 {
3742 const int direction = WM_event_drag_direction(event);
3743
3744 /* Intentionally leave `event->xy` as-is, event users are expected to use
3745 * `event->prev_press_xy` if they need to access the drag start location. */
3746 const short prev_val = event->val;
3747 const wmEventType prev_type = event->type;
3748 const wmEventModifierFlag prev_modifier = event->modifier;
3749 const wmEventType prev_keymodifier = event->keymodifier;
3750
3751 event->val = KM_PRESS_DRAG;
3752 event->type = event->prev_press_type;
3753 event->modifier = event->prev_press_modifier;
3754 event->keymodifier = event->prev_press_keymodifier;
3755 event->direction = direction;
3756
3757 CLOG_DEBUG(WM_LOG_EVENTS, "Handling CLICK_DRAG");
3758
3759 action |= wm_handlers_do_intern(C, win, event, handlers);
3760
3761 event->direction = 0;
3762 event->keymodifier = prev_keymodifier;
3763 event->modifier = prev_modifier;
3764 event->val = prev_val;
3765 event->type = prev_type;
3766
3767 win->event_queue_check_click = false;
3768 if (!((action & WM_HANDLER_BREAK) == 0 || wm_action_not_handled(action))) {
3769 /* Only disable when handled as other handlers may use this drag event. */
3770 CLOG_DEBUG(WM_LOG_EVENTS, "Canceling CLICK_DRAG: drag was generated & handled");
3771 win->event_queue_check_drag = false;
3772 }
3773 }
3774 }
3775 }
3776 else {
3777 if (win->event_queue_check_drag) {
3778 CLOG_DEBUG(WM_LOG_EVENTS, "Canceling CLICK_DRAG: motion event was handled");
3779 win->event_queue_check_drag = false;
3780 }
3781 }
3782 }
3783 else if (ISKEYBOARD_OR_BUTTON(event->type)) {
3784 /* All events that don't set #wmEvent.prev_type must be ignored. */
3785
3786 /* Test for CLICK events. */
3787 if (wm_action_not_handled(action)) {
3788 /* #wmWindow.eventstate stores if previous event was a #KM_PRESS, in case that
3789 * wasn't handled, the #KM_RELEASE will become a #KM_CLICK. */
3790
3791 if (event->val == KM_PRESS) {
3792 if ((event->flag & WM_EVENT_IS_REPEAT) == 0) {
3793 win->event_queue_check_click = true;
3794
3795 CLOG_DEBUG(WM_LOG_EVENTS, "Detecting CLICK_DRAG: press event detected");
3796 win->event_queue_check_drag = true;
3797
3798 win->event_queue_check_drag_handled = false;
3799 }
3800 }
3801 else if (event->val == KM_RELEASE) {
3802 if (win->event_queue_check_drag) {
3803 if ((event->prev_press_type != event->type) &&
3804 (ISKEYMODIFIER(event->type) || (event->type == event->prev_press_keymodifier)))
3805 {
3806 /* Support releasing modifier keys without canceling the drag event, see #89989. */
3807 }
3808 else {
3809 CLOG_DEBUG(WM_LOG_EVENTS, "Canceling CLICK_DRAG (release event didn't match press)");
3810 win->event_queue_check_drag = false;
3811 }
3812 }
3813 }
3814
3815 if (event->val == KM_RELEASE) {
3816 if (event->prev_press_type == event->type) {
3817 if (event->prev_val == KM_PRESS) {
3818 if (win->event_queue_check_click) {
3819 if (WM_event_drag_test(event, event->prev_press_xy)) {
3820 win->event_queue_check_click = false;
3821 if (win->event_queue_check_drag) {
3823 "Canceling CLICK_DRAG (key-release exceeds drag threshold)");
3824 win->event_queue_check_drag = false;
3825 }
3826 }
3827 else {
3828 /* Position is where the actual click happens, for more
3829 * accurate selecting in case the mouse drifts a little. */
3830 const int xy[2] = {UNPACK2(event->xy)};
3831
3832 copy_v2_v2_int(event->xy, event->prev_press_xy);
3833 event->val = KM_CLICK;
3834
3835 CLOG_DEBUG(WM_LOG_EVENTS, "Handling CLICK");
3836
3837 action |= wm_handlers_do_intern(C, win, event, handlers);
3838
3839 event->val = KM_RELEASE;
3840 copy_v2_v2_int(event->xy, xy);
3841 }
3842 }
3843 }
3844 }
3845 }
3846 else if (event->val == KM_DBL_CLICK) {
3847 /* The underlying event is a press, so try and handle this. */
3848 event->val = KM_PRESS;
3849 action |= wm_handlers_do_intern(C, win, event, handlers);
3850
3851 /* Revert value if not handled. */
3852 if (wm_action_not_handled(action)) {
3853 event->val = KM_DBL_CLICK;
3854 }
3855 }
3856 }
3857 else {
3858 win->event_queue_check_click = false;
3859
3860 if (win->event_queue_check_drag) {
3862 "Canceling CLICK_DRAG (button event was handled: value=%d)",
3863 event->val);
3864 win->event_queue_check_drag = false;
3865 }
3866 }
3867 }
3868 else if (ISMOUSE_WHEEL(event->type) || ISMOUSE_GESTURE(event->type)) {
3869 /* Modifiers which can trigger click event's,
3870 * however we don't want this if the mouse wheel has been used, see #74607. */
3871 if (wm_action_not_handled(action)) {
3872 /* Pass. */
3873 }
3874 else {
3875 if (ISKEYMODIFIER(event->prev_type)) {
3876 win->event_queue_check_click = false;
3877 }
3878 }
3879 }
3880
3881 wm_event_handler_return_value_check(C, event, action);
3882 return action;
3883}
3884
3886
3887/* -------------------------------------------------------------------- */
3892
3893static bool wm_event_inside_rect(const wmEvent *event, const rcti *rect)
3894{
3895 if (wm_event_always_pass(event)) {
3896 return true;
3897 }
3898 if (BLI_rcti_isect_pt_v(rect, event->xy)) {
3899 return true;
3900 }
3901 return false;
3902}
3903
3904static ScrArea *area_event_inside(bContext *C, const int xy[2])
3905{
3906 wmWindow *win = CTX_wm_window(C);
3907 bScreen *screen = CTX_wm_screen(C);
3908
3909 if (screen) {
3910 ED_screen_areas_iter (win, screen, area) {
3911 if (BLI_rcti_isect_pt_v(&area->totrct, xy)) {
3912 return area;
3913 }
3914 }
3915 }
3916 return nullptr;
3917}
3918
3919static ARegion *region_event_inside(bContext *C, const int xy[2])
3920{
3921 bScreen *screen = CTX_wm_screen(C);
3922 ScrArea *area = CTX_wm_area(C);
3923
3924 if (screen && area) {
3925 for (ARegion &region : area->regionbase) {
3926 if (BLI_rcti_isect_pt_v(&region.winrct, xy)) {
3927 return &region;
3928 }
3929 }
3930 }
3931 return nullptr;
3932}
3933
3935{
3936 if (region) {
3937 for (wmPaintCursor &pc : wm->runtime->paintcursors.items_mutable()) {
3938 if (pc.poll == nullptr || pc.poll(C)) {
3939 wmWindow *win = CTX_wm_window(C);
3940 WM_paint_cursor_tag_redraw(win, region);
3941 }
3942 }
3943 }
3944}
3945
3951static void wm_paintcursor_test(bContext *C, const wmEvent *event)
3952{
3954
3955 if (wm->runtime->paintcursors.first()) {
3956 const bScreen *screen = CTX_wm_screen(C);
3957 ARegion *region = screen ? screen->active_region : nullptr;
3958
3959 if (region) {
3960 ARegion *prev_region = CTX_wm_region(C);
3961
3962 CTX_wm_region_set(C, region);
3963 wm_paintcursor_tag(C, wm, region);
3964 CTX_wm_region_set(C, prev_region);
3965 }
3966
3967 /* If previous position was not in current region, we have to set a temp new context. */
3968 if (region == nullptr || !BLI_rcti_isect_pt_v(&region->winrct, event->prev_xy)) {
3969 ScrArea *prev_area = CTX_wm_area(C);
3970 ARegion *prev_region = CTX_wm_region(C);
3971
3974
3976
3977 CTX_wm_area_set(C, prev_area);
3978 CTX_wm_region_set(C, prev_region);
3979 }
3980 }
3981}
3982
3984 wmWindow *win,
3985 wmEvent *event)
3986{
3987 bScreen *screen = WM_window_get_active_screen(win);
3988
3989 if (wm->runtime->drags.is_empty()) {
3990 return WM_HANDLER_CONTINUE;
3991 }
3992
3993 if (event->type == MOUSEMOVE || ISKEYMODIFIER(event->type)) {
3994 screen->do_draw_drag = true;
3995 }
3996 else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
3997 wm_drags_exit(wm, win);
3998 WM_drag_free_list(&wm->runtime->drags);
3999
4000 screen->do_draw_drag = true;
4001
4002 return WM_HANDLER_BREAK;
4003 }
4004 else if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
4005 event->type = EVT_DROP;
4006
4007 /* Create custom-data, first free existing. */
4008 wm_event_custom_free(event);
4009 wm_event_custom_clear(event);
4010
4011 event->custom = EVT_DATA_DRAGDROP;
4012 event->customdata = &wm->runtime->drags;
4013 event->customdata_free = true;
4014
4015 /* Clear drop icon. */
4016 screen->do_draw_drag = true;
4017
4018 /* Restore cursor (disabled, see `wm_dragdrop.cc`). */
4019 // WM_cursor_modal_restore(win);
4020 }
4021
4022 return WM_HANDLER_CONTINUE;
4023}
4024
4028static bool wm_event_pie_filter(wmWindow *win, const wmEvent *event)
4029{
4030 if (win->pie_event_type_lock && win->pie_event_type_lock == event->type) {
4031 if (event->val == KM_RELEASE) {
4033 return false;
4034 }
4035 return true;
4036 }
4037 return false;
4038}
4039
4048{
4049 for (wmWindowManager &wm : G_MAIN->wm) {
4050 for (wmWindow &win : wm.windows) {
4051 if (BLI_remlink_safe(&win.runtime->event_queue, event)) {
4052 wm_event_free(event);
4053 return;
4054 }
4055 }
4056 }
4057}
4058
4060
4061/* -------------------------------------------------------------------- */
4066
4067#ifdef WITH_XR_OPENXR
4074
4075static bool wm_event_xr_handler_matches_actiondata(const wmEventHandler_Op *op_handler,
4076 const wmXrActionData *actiondata)
4077{
4078 if (op_handler->op == nullptr) {
4079 return false;
4080 }
4081
4082 const bool handler_op_type_match = (op_handler->op->type == actiondata->ot);
4083 const bool handler_op_properties_match = IDP_EqualsProperties(op_handler->op->properties,
4084 actiondata->op_properties);
4085
4086 return (handler_op_type_match && handler_op_properties_match);
4087}
4088
4089static void wm_event_handle_xrevent(wmWindowManager *wm,
4090 wmWindow *win,
4091 wmEvent *event,
4092 bContext *main_context)
4093{
4094 bContext *xr_context = WM_xr_session_context_ensure(&wm->xr, wm);
4095
4096 ScrArea *xr_area = CTX_wm_area(xr_context);
4097 ARegion *xr_region = CTX_wm_region(xr_context);
4098
4099 BLI_assert(xr_area && xr_area->spacetype == SPACE_VIEW3D && xr_area->spacedata.first_);
4100
4101 /* For operators using GPU-based selection. */
4102 BLI_assert(WM_region_use_viewport(xr_area, xr_region));
4103
4104 ListBaseT<wmEventHandler> *modalhandlers = &win->runtime->modalhandlers;
4105
4106 BLI_assert(event->custom == EVT_DATA_XR);
4107 BLI_assert(event->customdata);
4108 wmXrActionData *actiondata = static_cast<wmXrActionData *>(event->customdata);
4109
4110 /* Check if the XR context scene matches the main Blender context scene to counter-act possible
4111 * re-allocation on undo operator execution. */
4112 const uint xr_ctx_scene_uid = CTX_data_scene(xr_context)->id.session_uid;
4113 const uint main_ctx_scene_uid = CTX_data_scene(main_context)->id.session_uid;
4114 const bool ctx_xr_main_scene_match = (xr_ctx_scene_uid == main_ctx_scene_uid);
4115
4116 /* Only process XR operator handlers to prevent interferences with main window handlers.
4117 * NOTE: This is a stripped-down XR-specific version of #wm_handlers_do_intern. Changes made
4118 * in that function might also need to be reproduced here. */
4120 for (wmEventHandler &handler_base : *modalhandlers) {
4121 if (handler_base.type == WM_HANDLER_TYPE_OP) {
4122 BLI_assert((handler_base.flag & WM_HANDLER_DO_FREE) == 0);
4123
4124 if (handler_base.poll != nullptr && !handler_base.poll(win, xr_area, xr_region, event)) {
4125 continue;
4126 }
4127
4128 wmEventHandler_Op *op_handler = (wmEventHandler_Op *)&handler_base;
4129 /* Only execute operator handler matching the XR action data carried by the event. */
4130 if (wm_event_xr_handler_matches_actiondata(op_handler, actiondata)) {
4131 action = wm_handler_operator_call(
4132 xr_context, modalhandlers, &handler_base, event, nullptr, nullptr);
4133 }
4134
4135 if (action & WM_HANDLER_BREAK) {
4136 break;
4137 }
4138 }
4139 }
4140
4141 wm_event_handler_return_value_check(xr_context, event, action);
4142
4143 if ((action & WM_HANDLER_BREAK) == 0) {
4144 if (actiondata->ot->modal && event->val == KM_RELEASE) {
4145 /* Don't execute modal operators on release. */
4146 }
4147 else {
4148 PointerRNA properties{};
4149 properties.type = actiondata->ot->srna;
4150 properties.data = actiondata->op_properties;
4151 if (actiondata->ot->invoke) {
4152 /* Invoke operator, either executing operator or transferring responsibility to window
4153 * modal handlers. */
4154 wm_operator_invoke(xr_context,
4155 actiondata->ot,
4156 event,
4157 actiondata->op_properties ? &properties : nullptr,
4158 nullptr,
4159 false,
4160 false);
4161 }
4162 else {
4163 /* Execute operator. */
4165 wm, actiondata->ot, actiondata->op_properties ? &properties : nullptr, nullptr);
4166 if ((WM_operator_call(xr_context, op) & OPERATOR_HANDLED) == 0) {
4167 WM_operator_free(op);
4168 }
4169 }
4170 }
4171 }
4172
4173 /* The undo operator may have re-allocated the XR context Scene and Main data pointers.
4174 * Prevent dangling pointers in the main Blender context by re-assigning them as needed.
4175 *
4176 * This is the inverse of the re-anchoring in #WM_xr_session_context_ensure(). */
4177 CTX_data_main_set(main_context, CTX_data_main(xr_context));
4178 if (ctx_xr_main_scene_match) {
4179 CTX_data_scene_set(main_context, CTX_data_scene(xr_context));
4180 }
4181}
4182#endif /* WITH_XR_OPENXR */
4183
4185{
4186 if (region->runtime->type->do_lock) {
4187 /* If the region is locked, we ignore the events. Handling them can trigger depsgraph
4188 * evaluations in some cases which is not safe to do because another thread may evaluate the
4189 * depsgraph already. */
4190 if (wm_event_always_pass(event)) {
4191 return WM_HANDLER_CONTINUE;
4192 }
4193 return WM_HANDLER_BREAK;
4194 }
4195
4196 CTX_wm_region_set(C, region);
4197
4198 /* Call even on non mouse events, since the handlers may still use this value. */
4199 wm_region_mouse_co(C, event);
4200
4202 if (!wm->runtime->drags.is_empty()) {
4203 /* Does polls for drop regions and checks #uiButs. */
4204 /* Need to be here to make sure region context is true. */
4205 wm_drags_handle_events(C, event);
4206 }
4207
4208 return wm_handlers_do(
4209 C, event, static_cast<ListBaseT<wmEventHandler> *>(&region->runtime->handlers));
4210}
4211
4220 wmEvent *event,
4221 ScrArea *area)
4222{
4223 /* Case 1. */
4224 if (wm_event_always_pass(event)) {
4226
4227 for (ARegion &region : area->regionbase) {
4228 action |= wm_event_do_region_handlers(C, event, &region);
4229 }
4230
4231 wm_event_handler_return_value_check(C, event, action);
4232 return action;
4233 }
4234
4235 /* Case 2. */
4236 ARegion *region_hovered = ED_area_find_region_xy_visual(area, RGN_TYPE_ANY, event->xy);
4237 if (!region_hovered) {
4238 return WM_HANDLER_CONTINUE;
4239 }
4240
4241 return wm_event_do_region_handlers(C, event, region_hovered);
4242}
4243
4245{
4249
4250 wm->runtime->break_events_handling = false;
4251
4252 /* Begin GPU render boundary - Certain event handlers require GPU usage. */
4254
4255 /* Update key configuration before handling events. */
4258
4259 for (wmWindow &win : wm->windows) {
4260 /* Do the check at the start of the next iteration, to avoid by-passing it in case the
4261 * previous iteration has been early-terminated (using `continue;` e.g.). */
4262 if (wm->runtime->break_events_handling) {
4263 break;
4264 }
4265
4266 bScreen *screen = WM_window_get_active_screen(&win);
4267
4268 /* Some safety checks - these should always be set! */
4272
4273 if (screen == nullptr) {
4274 wm_event_free_all(&win);
4275 }
4276
4277 wmEvent *event;
4278 while ((event = win.runtime->event_queue.first())) {
4279 /* Do the check at the start of the next iteration, to avoid by-passing it in case the
4280 * previous iteration has been early-terminated (using `continue;` e.g.). */
4281 if (wm->runtime->break_events_handling) {
4282 break;
4283 }
4284
4286
4287 /* Force handling drag if a key is pressed even if the drag threshold has not been met.
4288 * Needed so tablet actions (which typically use a larger threshold) can click-drag
4289 * then press keys - activating the drag action early.
4290 * Limit to mouse-buttons drag actions interrupted by pressing any non-mouse button.
4291 * Otherwise pressing two keys on the keyboard will interpret this as a drag action. */
4292 if (win.event_queue_check_drag) {
4293 if ((event->val == KM_PRESS) && ((event->flag & WM_EVENT_IS_REPEAT) == 0) &&
4295 {
4296 event = wm_event_add_mousemove_to_head(&win);
4297 event->flag |= WM_EVENT_FORCE_DRAG_THRESHOLD;
4298 }
4299 }
4300 const bool event_queue_check_drag_prev = win.event_queue_check_drag;
4301
4302 {
4303 const bool is_consecutive = WM_event_consecutive_gesture_test(event);
4305 if (event->type == win.event_queue_consecutive_gesture_type) {
4306 event->flag |= WM_EVENT_IS_CONSECUTIVE;
4307 }
4308 else if (is_consecutive || WM_event_consecutive_gesture_test_break(&win, event)) {
4309 CLOG_DEBUG(WM_LOG_EVENTS, "Consecutive gesture break (%d)", event->type);
4312 }
4313 }
4314 else if (is_consecutive) {
4315 CLOG_DEBUG(WM_LOG_EVENTS, "Consecutive gesture begin (%d)", event->type);
4316 win.event_queue_consecutive_gesture_type = event->type;
4318 /* While this should not be set, it's harmless to free here. */
4320 }
4321 }
4322
4323 /* Active screen might change during handlers, update pointer. */
4324 screen = WM_window_get_active_screen(&win);
4325
4326 if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) && !ISMOUSE_MOTION(event->type)) {
4327 printf("\n%s: Handling event\n", __func__);
4328 WM_event_print(event);
4329 }
4330
4331 /* Take care of pie event filter. */
4332 if (wm_event_pie_filter(&win, event)) {
4333 if (!ISMOUSE_MOTION(event->type)) {
4334 CLOG_DEBUG(WM_LOG_EVENTS, "Event filtered due to pie button pressed");
4335 }
4336 BLI_remlink(&win.runtime->event_queue, event);
4337 wm_event_free_last_handled(&win, event);
4338 continue;
4339 }
4340
4341 CTX_wm_window_set(C, &win);
4342
4343#ifdef WITH_XR_OPENXR
4344 if (event->type == EVT_XR_ACTION) {
4345 wm_event_handle_xrevent(wm, &win, event, C);
4346 BLI_remlink(&win.runtime->event_queue, event);
4347 wm_event_free_last_handled(&win, event);
4348 /* Skip mouse event handling below, which is unnecessary for XR events. */
4349 continue;
4350 }
4351#endif
4352
4353 /* Clear tool-tip on mouse move. */
4354 if (screen->tool_tip && screen->tool_tip->exit_on_event) {
4355 if (ISMOUSE_MOTION(event->type)) {
4356 if (len_manhattan_v2v2_int(screen->tool_tip->event_xy, event->xy) >
4358 {
4359 WM_tooltip_clear(C, &win);
4360 }
4361 }
4362 }
4363
4364 /* We let modal handlers get active area/region, also wm_paintcursor_test needs it. */
4367
4368 /* MVC demands to not draw in event handlers...
4369 * but we need to leave it for GPU selecting etc. */
4371
4372 wm_region_mouse_co(C, event);
4373
4374 /* First we do priority handlers, modal + some limited key-maps. */
4375 action |= wm_handlers_do(C, event, &win.runtime->modalhandlers);
4376
4377 /* File-read case. */
4378 if (CTX_wm_window(C) == nullptr) {
4381 return;
4382 }
4383
4384 /* Check for a tool-tip. */
4385 if (screen == WM_window_get_active_screen(&win)) {
4386 if (screen->tool_tip && screen->tool_tip->timer) {
4387 if ((event->type == TIMER) && (event->customdata == screen->tool_tip->timer)) {
4388 WM_tooltip_init(C, &win);
4389 }
4390 }
4391 }
4392
4393 /* Check dragging, creates new event or frees, adds draw tag. */
4394 action |= wm_event_drag_and_drop_test(wm, &win, event);
4395
4396 if ((action & WM_HANDLER_BREAK) == 0) {
4397 /* NOTE: setting sub-window active should be done here,
4398 * after modal handlers have been done. */
4399 if (event->type == MOUSEMOVE) {
4400 /* State variables in screen, cursors.
4401 * Also used in `wm_draw.cc`, fails for modal handlers though. */
4402 ED_screen_set_active_region(C, &win, event->xy);
4403 /* For regions having custom cursors. */
4404 wm_paintcursor_test(C, event);
4405 }
4406 else if (ISKEYMODIFIER(event->type)) {
4407 /* Paint cursors may change appearance based on modifier keys,
4408 * e.g. blade tool in the sequencer. */
4409 wm_paintcursor_test(C, event);
4410 }
4411#ifdef WITH_INPUT_NDOF
4412 else if (event->type == NDOF_MOTION) {
4413 win.addmousemove = true;
4414 }
4415#endif
4416
4417 ED_screen_areas_iter (&win, screen, area) {
4418 /* After restoring a screen from SCREENMAXIMIZED we have to wait
4419 * with the screen handling till the region coordinates are updated. */
4420 if (screen->skip_handling) {
4421 /* Restore for the next iteration of wm_event_do_handlers. */
4422 screen->skip_handling = false;
4423 break;
4424 }
4425
4426 /* Update action-zones if needed,
4427 * done here because it needs to be independent from redraws. */
4428 if (area->flag & AREA_FLAG_ACTIONZONES_UPDATE) {
4429 ED_area_azones_update(area, event->xy);
4430 }
4431
4432 if (wm_event_inside_rect(event, &area->totrct)) {
4433 CTX_wm_area_set(C, area);
4434
4435 action |= wm_event_do_handlers_area_regions(C, event, area);
4436
4437 /* File-read case (Python), #29489. */
4438 if (CTX_wm_window(C) == nullptr) {
4441 return;
4442 }
4443
4444 CTX_wm_region_set(C, nullptr);
4445
4446 if ((action & WM_HANDLER_BREAK) == 0) {
4447 wm_region_mouse_co(C, event); /* Only invalidates `event->mval` in this case. */
4448 action |= wm_handlers_do(
4449 C, event, static_cast<ListBaseT<wmEventHandler> *>(&area->handlers));
4450 }
4451 CTX_wm_area_set(C, nullptr);
4452
4453 /* NOTE: do not escape on #WM_HANDLER_BREAK,
4454 * mouse-move needs handled for previous area. */
4455 }
4456 }
4457
4458 if ((action & WM_HANDLER_BREAK) == 0) {
4459 /* Also some non-modal handlers need active area/region. */
4462
4463 wm_region_mouse_co(C, event);
4464
4465 action |= wm_handlers_do(C, event, &win.runtime->handlers);
4466
4467 /* File-read case. */
4468 if (CTX_wm_window(C) == nullptr) {
4471 return;
4472 }
4473 }
4474 }
4475
4476 /* If press was handled, we don't want to do click. This way
4477 * press in tool key-map can override click in editor key-map. */
4478 if (ISMOUSE_BUTTON(event->type) && event->val == KM_PRESS && !wm_action_not_handled(action))
4479 {
4480 win.event_queue_check_click = false;
4481 }
4482
4483 /* If the drag even was handled, don't attempt to keep re-handing the same
4484 * drag event on every cursor motion, see: #87511. */
4486 win.event_queue_check_drag = false;
4488 }
4489
4490 if (event_queue_check_drag_prev && (win.event_queue_check_drag == false)) {
4492 }
4493
4494 /* Update previous mouse position for following events to use. */
4496
4497 /* Un-link and free here, Blender-quit then frees all. */
4498 BLI_remlink(&win.runtime->event_queue, event);
4499 wm_event_free_last_handled(&win, event);
4500 }
4501
4502 /* Only add mouse-move when the event queue was read entirely. */
4503 if (win.addmousemove && win.runtime->eventstate) {
4504 wmEvent tevent = *(win.runtime->eventstate);
4505 // printf("adding MOUSEMOVE %d %d\n", tevent.xy[0], tevent.xy[1]);
4506 tevent.type = MOUSEMOVE;
4507 tevent.val = KM_NOTHING;
4508 tevent.prev_xy[0] = tevent.xy[0];
4509 tevent.prev_xy[1] = tevent.xy[1];
4510 tevent.flag = eWM_EventFlag(0);
4511 wm_event_add_intern(&win, &tevent);
4512 win.addmousemove = 0;
4513 }
4514
4515 CTX_wm_window_set(C, nullptr);
4516 }
4517
4518 /* Update key configuration after handling events. */
4521
4522 /* End GPU render boundary. Certain event handlers require GPU usage. */
4524}
4525
4527
4528/* -------------------------------------------------------------------- */
4531
4532void WM_event_fileselect_event(wmWindowManager *wm, void *ophandle, const int eventval)
4533{
4534 /* Add to all windows! */
4535 for (wmWindow &win : wm->windows) {
4536 wmEvent event = *win.runtime->eventstate;
4537
4538 event.type = EVT_FILESELECT;
4539 event.val = eventval;
4540 event.flag = eWM_EventFlag(0);
4541 event.customdata = ophandle; /* Only as void pointer type check. */
4542
4543 WM_event_add(&win, &event);
4544 }
4545}
4546
4566{
4567 wmWindow *ctx_win = CTX_wm_window(C);
4568
4569 for (wmWindow *ctx_win_or_parent = ctx_win; ctx_win_or_parent;
4570 ctx_win_or_parent = ctx_win_or_parent->parent)
4571 {
4572 ScrArea *file_area = ED_fileselect_handler_area_find_any_with_op(ctx_win_or_parent);
4573
4574 if (!file_area) {
4575 return ctx_win_or_parent;
4576 }
4577
4578 if (file_area->full) {
4579 return ctx_win_or_parent;
4580 }
4581 }
4582
4583 /* Fall back to the first window. */
4586 return wm->windows.first();
4587}
4588
4589/* Operator is supposed to have a filled "path" property. */
4590/* Optional property: file-type (XXX enum?) */
4591
4593{
4595 wmWindow *ctx_win = CTX_wm_window(C);
4596
4597 /* The following vars define the root context. That is essentially the "parent" context of the
4598 * File Browser operation, to be restored for eventually executing the file operation. */
4600 /* Determined later. */
4601 ScrArea *root_area = nullptr;
4602 ARegion *root_region = nullptr;
4603
4604 if (!CLG_quiet_get()) {
4605 /* Perform some sanity checks.
4606 *
4607 * - Using the file-path sub-types is important because it's possible paths don't use
4608 * UTF8 compatible strings, the Python API only accounts for this for "path" sub-types.
4609 *
4610 * - The sub-types in the messages match the Python ID's
4611 * since this it's most likely Python developers will be encountering these messages.
4612 *
4613 * - These could be made into errors however that would break existing scripts.
4614 */
4615 const char *prefix = "fileselect_add";
4616 PropertyRNA *prop;
4617 const char *prop_id;
4618
4619 prop_id = "filepath";
4620 prop = RNA_struct_find_property(op->ptr, prop_id);
4621 if (prop) {
4622 if (!((RNA_property_type(prop) == PROP_STRING) &&
4624 {
4626 "%s: \"%s\" expected a string with a 'FILE_PATH' subtype.",
4627 prefix,
4628 prop_id);
4629 }
4630 }
4631 prop_id = "directory";
4632 prop = RNA_struct_find_property(op->ptr, prop_id);
4633 if (prop) {
4634 if (!((RNA_property_type(prop) == PROP_STRING) &&
4636 {
4638 "%s: \"%s\" expected a string with a 'DIR_PATH' subtype.",
4639 prefix,
4640 prop_id);
4641 }
4642 }
4643
4644 prop_id = "filename";
4645 prop = RNA_struct_find_property(op->ptr, prop_id);
4646 if (prop) {
4647 if (!((RNA_property_type(prop) == PROP_STRING) &&
4649 {
4651 "%s: \"%s\" expected a string with a 'FILE_NAME' subtype.",
4652 prefix,
4653 prop_id);
4654 }
4655 }
4656
4657 /* Other methods could be checked too `files`, `check_existing`, `filter_glob`... etc. */
4658 }
4659
4660 /* Setting the context window unsets the context area & screen. Avoid doing that, so operators
4661 * calling the file browser can operate in the context the browser was opened in. */
4662 if (ctx_win != root_win) {
4663 CTX_wm_window_set(C, root_win);
4664 }
4665
4666 /* The root window may already have a File Browser open. Cancel it if so, only 1 should be open
4667 * per window. The root context of this operation is also used for the new operation. */
4668 for (wmEventHandler &handler_base : root_win->runtime->modalhandlers.items_mutable()) {
4669 if (handler_base.type == WM_HANDLER_TYPE_OP) {
4670 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
4671 if (handler->is_fileselect == false) {
4672 continue;
4673 }
4674
4676 C, handler, ctx_win->runtime->eventstate, &root_area, &root_region);
4677
4678 ScrArea *file_area = ED_fileselect_handler_area_find(root_win, handler->op);
4679
4680 if (file_area) {
4681 CTX_wm_area_set(C, file_area);
4683 C, &root_win->runtime->modalhandlers, handler, EVT_FILESELECT_CANCEL);
4684 }
4685 /* If not found we stop the handler without changing the screen. */
4686 else {
4688 C, &root_win->runtime->modalhandlers, handler, EVT_FILESELECT_EXTERNAL_CANCEL);
4689 }
4690 }
4691 }
4692
4693 BLI_assert(root_win != nullptr);
4694 /* When not reusing the root context from a previous file browsing operation, use the current
4695 * area & region, if they are inside the root window. */
4696 if (!root_area && ctx_win == root_win) {
4697 root_area = CTX_wm_area(C);
4698 root_region = CTX_wm_region(C);
4699 }
4700
4702 handler->head.type = WM_HANDLER_TYPE_OP;
4703
4704 handler->is_fileselect = true;
4707 handler->op = op;
4708 handler->context.win = root_win;
4709 handler->context.area = root_area;
4710 handler->context.region = root_region;
4711
4712 wm_handler_operator_insert(root_win, handler);
4713
4714 /* Check props once before invoking if check is available
4715 * ensures initial properties are valid. */
4716 if (op->type->check) {
4717 op->type->check(C, op); /* Ignore return value. */
4718 }
4719
4721
4722 if (ctx_win != root_win) {
4723 CTX_wm_window_set(C, ctx_win);
4724 }
4725}
4726
4728
4729/* -------------------------------------------------------------------- */
4732
4737 char id[0];
4738};
4739
4740void *WM_event_consecutive_data_get(wmWindow *win, const char *id)
4741{
4743 if (cdata && STREQ(cdata->id, id)) {
4744 return cdata->custom_data;
4745 }
4746 return nullptr;
4747}
4748
4749void WM_event_consecutive_data_set(wmWindow *win, const char *id, void *custom_data)
4750{
4753 }
4754
4755 const size_t id_size = strlen(id) + 1;
4756 wmEvent_ConsecutiveData *cdata = static_cast<wmEvent_ConsecutiveData *>(
4757 MEM_new_uninitialized(sizeof(*cdata) + id_size, __func__));
4758 cdata->custom_data = custom_data;
4759 memcpy((cdata + 1), id, id_size);
4761}
4762
4764{
4766 if (cdata == nullptr) {
4767 return;
4768 }
4769
4770 if (cdata->custom_data) {
4772 }
4773 MEM_delete(cdata);
4775}
4776
4778
4779/* -------------------------------------------------------------------- */
4782
4783#if 0
4784/* Lets not expose struct outside wm? */
4785static void WM_event_set_handler_flag(wmEventHandler *handler, const int flag)
4786{
4787 handler->flag = flag;
4788}
4789#endif
4790
4792 ScrArea *area,
4793 ARegion *region,
4794 wmOperator *op)
4795{
4797 handler->head.type = WM_HANDLER_TYPE_OP;
4798
4799 /* Operator was part of macro. */
4800 if (op->opm) {
4801 /* Give the mother macro to the handler. */
4802 handler->op = op->opm;
4803 /* Mother macro `opm` becomes the macro element. */
4804 handler->op->opm = op;
4805 }
4806 else {
4807 handler->op = op;
4808 }
4809
4810 handler->context.area = area; /* Means frozen screen context for modal handlers! */
4811 handler->context.region = region;
4812 handler->context.region_type = handler->context.region ? handler->context.region->regiontype :
4813 -1;
4814
4815 wm_handler_operator_insert(win, handler);
4816
4817 if (op->type->modalkeymap) {
4819 }
4820
4821 return handler;
4822}
4823
4825{
4826 wmWindow *win = CTX_wm_window(C);
4827 ScrArea *area = CTX_wm_area(C);
4828 ARegion *region = CTX_wm_region(C);
4829 return WM_event_add_modal_handler_ex(win, area, region, op);
4830}
4831
4832void WM_event_remove_modal_handler(ListBaseT<wmEventHandler> *handlers,
4833 const wmOperator *op,
4834 const bool postpone)
4835{
4836 for (wmEventHandler &handler_base : *handlers) {
4837 if (handler_base.type == WM_HANDLER_TYPE_OP) {
4838 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
4839 if ((handler->op == op) || (op->opm && (handler->op == op->opm))) {
4840 /* Handlers will be freed in #wm_handlers_do(). */
4841 if (postpone) {
4842 handler->head.flag |= WM_HANDLER_DO_FREE;
4843 }
4844 else {
4845 BLI_remlink(handlers, handler);
4846 wm_event_free_handler(&handler->head);
4847 }
4848 break;
4849 }
4850 }
4851 }
4852}
4853
4854void WM_event_remove_modal_handler_all(const wmOperator *op, const bool postpone)
4855{
4856 Main *bmain = G_MAIN;
4857 wmWindowManager *wm = bmain->wm.first();
4858 for (wmWindow &win : wm->windows) {
4860 }
4861}
4862
4863void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area, ScrArea *new_area)
4864{
4865 for (wmEventHandler &handler_base : win->runtime->modalhandlers) {
4866 if (handler_base.type == WM_HANDLER_TYPE_OP) {
4867 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
4868 /* File-select handler is quite special.
4869 * it needs to keep old area stored in handler, so don't change it. */
4870 if ((handler->context.area == old_area) && (handler->is_fileselect == false)) {
4871 handler->context.area = new_area;
4872 }
4873 }
4874 }
4875}
4876
4878 const ARegion *old_region,
4879 ARegion *new_region)
4880{
4881 for (wmEventHandler &handler_base : win->runtime->modalhandlers) {
4882 if (handler_base.type == WM_HANDLER_TYPE_OP) {
4883 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
4884 /* File-select handler is quite special.
4885 * it needs to keep old region stored in handler, so don't change it. */
4886 if ((handler->context.region == old_region) && (handler->is_fileselect == false)) {
4887 handler->context.region = new_region;
4888 handler->context.region_type = new_region ? new_region->regiontype : int(RGN_TYPE_WINDOW);
4889 }
4890 }
4891 }
4892}
4893
4895 const ARegion *old_region,
4896 ARegion *new_region)
4897{
4898 for (wmEventHandler &handler_base : win->runtime->modalhandlers) {
4899 if (handler_base.type == WM_HANDLER_TYPE_UI) {
4900 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(&handler_base);
4901 if (handler->context.region_popup == old_region) {
4902 handler->context.region_popup = new_region;
4903 }
4904 }
4905 }
4906}
4907
4908wmEventHandler_Keymap *WM_event_add_keymap_handler(ListBaseT<wmEventHandler> *handlers,
4909 wmKeyMap *keymap)
4910{
4911 if (!keymap) {
4912 CLOG_WARN(WM_LOG_EVENTS, "called with nullptr key-map");
4913 return nullptr;
4914 }
4915
4916 /* Only allow same key-map once. */
4917 for (wmEventHandler &handler_base : *handlers) {
4918 if (handler_base.type == WM_HANDLER_TYPE_KEYMAP) {
4919 wmEventHandler_Keymap *handler = reinterpret_cast<wmEventHandler_Keymap *>(&handler_base);
4920 if (handler->keymap == keymap) {
4921 return handler;
4922 }
4923 }
4924 }
4925
4927 handler->head.type = WM_HANDLER_TYPE_KEYMAP;
4928 BLI_addtail(handlers, handler);
4929 handler->keymap = keymap;
4930
4931 return handler;
4932}
4933
4947 wmWindow *win,
4948 wmEventHandler_Keymap *handler,
4949 wmEventHandler_KeymapResult *km_result,
4950 /* Extra arguments. */
4951 const bool with_gizmos)
4952{
4953 memset(km_result, 0x0, sizeof(*km_result));
4954
4955 const char *keymap_id_list[BOUNDED_ARRAY_TYPE_SIZE<decltype(km_result->keymaps)>()];
4956 int keymap_id_list_len = 0;
4957
4958 /* NOTE(@ideasman42): If `win` is nullptr, this function may not behave as expected.
4959 * Assert since this should not happen in practice.
4960 * If it does, the window could be looked up in `wm` using the `area`.
4961 * Keep nullptr checks in run-time code since any crashes here are difficult to redo. */
4962 BLI_assert_msg(win != nullptr, "The window should always be set for tool interactions!");
4963 const Scene *scene = win ? win->scene : nullptr;
4964
4965 ScrArea *area = static_cast<ScrArea *>(handler->dynamic.user_data);
4966 handler->keymap_tool = nullptr;
4967 bToolRef_Runtime *tref_rt = area->runtime.tool ? area->runtime.tool->runtime : nullptr;
4968
4969 if (tref_rt && tref_rt->keymap[0]) {
4970 keymap_id_list[keymap_id_list_len++] = tref_rt->keymap;
4971 }
4972
4973 bool is_gizmo_visible = false;
4974 bool is_gizmo_highlight = false;
4975
4976 if ((tref_rt && tref_rt->keymap_fallback[0]) &&
4978 {
4979 bool add_keymap = false;
4980 /* Support for the gizmo owning the tool key-map. */
4981
4982 if (tref_rt->flag & TOOLREF_FLAG_FALLBACK_KEYMAP) {
4983 add_keymap = true;
4984 }
4985
4986 if (with_gizmos && (tref_rt->gizmo_group[0] != '\0')) {
4987 wmGizmoMap *gzmap = nullptr;
4988 wmGizmoGroup *gzgroup = nullptr;
4989 for (ARegion &region : area->regionbase) {
4990 if (region.runtime->gizmo_map != nullptr) {
4991 gzmap = region.runtime->gizmo_map;
4992 gzgroup = WM_gizmomap_group_find(gzmap, tref_rt->gizmo_group);
4993 if (gzgroup != nullptr) {
4994 break;
4995 }
4996 }
4997 }
4998 if (gzgroup != nullptr) {
5000 /* If all are hidden, don't override. */
5001 is_gizmo_visible = true;
5002 wmGizmo *highlight = wm_gizmomap_highlight_get(gzmap);
5003 if (highlight) {
5004 is_gizmo_highlight = true;
5005 }
5006 add_keymap = true;
5007 }
5008 }
5009 }
5010
5011 if (add_keymap) {
5012 keymap_id_list[keymap_id_list_len++] = tref_rt->keymap_fallback;
5013 }
5014 }
5015
5016 if (is_gizmo_visible && !is_gizmo_highlight) {
5017 if (keymap_id_list_len == 2) {
5018 std::swap(keymap_id_list[0], keymap_id_list[1]);
5019 }
5020 }
5021
5022 for (int i = 0; i < keymap_id_list_len; i++) {
5023 const char *keymap_id = keymap_id_list[i];
5024 BLI_assert(keymap_id && keymap_id[0]);
5025
5027 &wm->runtime->userconf->keymaps, keymap_id, area->spacetype, RGN_TYPE_WINDOW);
5028 /* We shouldn't use key-maps from unrelated spaces. */
5029 if (km == nullptr) {
5030 printf("Key-map: '%s' not found for tool '%s'\n", keymap_id, area->runtime.tool->idname);
5031 continue;
5032 }
5033 handler->keymap_tool = area->runtime.tool;
5034 km_result->keymaps[km_result->keymaps_len++] = km;
5035 }
5036}
5037
5045
5047 wmWindow *win,
5048 wmEventHandler_Keymap *handler,
5049 wmEventHandler_KeymapResult *km_result)
5050{
5051 wm_event_get_keymap_from_toolsystem_ex(wm, win, handler, km_result, false);
5052}
5053
5055 ListBaseT<wmEventHandler> *handlers, wmEventHandler_KeymapDynamicFn keymap_fn, void *user_data)
5056{
5057 if (!keymap_fn) {
5058 CLOG_WARN(WM_LOG_EVENTS, "called with nullptr keymap_fn");
5059 return nullptr;
5060 }
5061
5062 /* Only allow same key-map once. */
5063 for (wmEventHandler &handler_base : *handlers) {
5064 if (handler_base.type == WM_HANDLER_TYPE_KEYMAP) {
5065 wmEventHandler_Keymap *handler = reinterpret_cast<wmEventHandler_Keymap *>(&handler_base);
5066 if (handler->dynamic.keymap_fn == keymap_fn) {
5067 /* Maximizing the view needs to update the area. */
5068 handler->dynamic.user_data = user_data;
5069 return handler;
5070 }
5071 }
5072 }
5073
5075 handler->head.type = WM_HANDLER_TYPE_KEYMAP;
5076 BLI_addtail(handlers, handler);
5077 handler->dynamic.keymap_fn = keymap_fn;
5078 handler->dynamic.user_data = user_data;
5079
5080 return handler;
5081}
5082
5084 wmKeyMap *keymap,
5085 int /*priority*/)
5086{
5087 WM_event_remove_keymap_handler(handlers, keymap);
5088
5089 wmEventHandler_Keymap *handler = MEM_new_zeroed<wmEventHandler_Keymap>("event key-map handler");
5090 handler->head.type = WM_HANDLER_TYPE_KEYMAP;
5091
5092 BLI_addhead(handlers, handler);
5093 handler->keymap = keymap;
5094
5095 return handler;
5096}
5097
5098static bool event_or_prev_in_rect(const wmEvent *event, const rcti *rect)
5099{
5100 if (BLI_rcti_isect_pt_v(rect, event->xy)) {
5101 return true;
5102 }
5103 if (event->type == MOUSEMOVE && BLI_rcti_isect_pt_v(rect, event->prev_xy)) {
5104 return true;
5105 }
5106 return false;
5107}
5108
5110 const ScrArea * /*area*/,
5111 const ARegion *region,
5112 const wmEvent *event)
5113{
5114 if (wm_event_always_pass(event)) {
5115 return true;
5116 }
5117 rcti rect = region->v2d.mask;
5118 BLI_rcti_translate(&rect, region->winrct.xmin, region->winrct.ymin);
5119 return event_or_prev_in_rect(event, &rect);
5120}
5121
5123 const ScrArea *area,
5124 const ARegion *region,
5125 const wmEvent *event)
5126{
5127 if (!ED_markers_region_visible(area, region)) {
5128 return false;
5129 }
5130
5131 /* Check for markers in the current scene, noting that the VSE uses a special sequencer scene. */
5132 Scene *scene = WM_window_get_active_scene(win);
5133
5134 if (area->spacetype == SPACE_SEQ) {
5135 WorkSpace *workspace = WM_window_get_active_workspace(win);
5136 if (workspace && workspace->sequencer_scene) {
5137 scene = workspace->sequencer_scene;
5138 }
5139 else {
5140 return false;
5141 }
5142 }
5143
5144 /* FIXME: Ideally we should not have to use G_MAIN here, though practically this is probably fine
5145 * for now. */
5146 const ListBaseT<TimeMarker> *markers = ED_scene_markers_get_from_area(
5147 *G_MAIN, scene, WM_window_get_active_view_layer(win), area);
5148 if (markers->is_empty()) {
5149 return false;
5150 }
5151
5152 rcti rect = region->winrct;
5153 rect.ymax = rect.ymin + UI_MARKER_MARGIN_Y;
5154 /* TODO: investigate returning `event_or_prev_in_rect(event, &rect)` here.
5155 * The difference is subtle but correct so dragging away from the region works. */
5156 return BLI_rcti_isect_pt_v(&rect, event->xy);
5157}
5158
5160 const ScrArea *area,
5161 const ARegion *region,
5162 const wmEvent *event)
5163{
5164 if (!WM_event_handler_region_v2d_mask_poll(win, area, region, event)) {
5165 return false;
5166 }
5167 /* Casting away `const` is only needed for a non-constant return value. */
5168 /* FIXME: Ideally we should not have to use G_MAIN here, though practically this is probably fine
5169 * for now. */
5170 const ListBaseT<TimeMarker> *markers = ED_scene_markers_get_from_area(
5172 if (markers && !markers->is_empty()) {
5173 return !WM_event_handler_region_marker_poll(win, area, region, event);
5174 }
5175 return true;
5176}
5177
5178wmEventHandler_Keymap *WM_event_add_keymap_handler_poll(ListBaseT<wmEventHandler> *handlers,
5179 wmKeyMap *keymap,
5180 EventHandlerPoll poll)
5181{
5182 wmEventHandler_Keymap *handler = WM_event_add_keymap_handler(handlers, keymap);
5183 if (handler == nullptr) {
5184 return nullptr;
5185 }
5186
5187 handler->head.poll = poll;
5188 return handler;
5189}
5190
5192 wmKeyMap *keymap)
5193{
5195}
5196
5197void WM_event_remove_keymap_handler(ListBaseT<wmEventHandler> *handlers, wmKeyMap *keymap)
5198{
5199 for (wmEventHandler &handler_base : *handlers) {
5200 if (handler_base.type == WM_HANDLER_TYPE_KEYMAP) {
5201 wmEventHandler_Keymap *handler = reinterpret_cast<wmEventHandler_Keymap *>(&handler_base);
5202 if (handler->keymap == keymap) {
5203 BLI_remlink(handlers, handler);
5204 wm_event_free_handler(&handler->head);
5205 break;
5206 }
5207 }
5208 }
5209}
5210
5212 void(keymap_tag)(wmKeyMap *keymap,
5213 wmKeyMapItem *kmi,
5214 void *user_data),
5215 void *user_data)
5216{
5217 handler->post.post_fn = keymap_tag;
5218 handler->post.user_data = user_data;
5219}
5220
5222 ListBaseT<wmEventHandler> *handlers,
5223 wmUIHandlerFunc handle_fn,
5224 wmUIHandlerRemoveFunc remove_fn,
5225 void *user_data,
5226 const eWM_EventHandlerFlag flag)
5227{
5229 handler->head.type = WM_HANDLER_TYPE_UI;
5230 handler->handle_fn = handle_fn;
5231 handler->remove_fn = remove_fn;
5232 handler->user_data = user_data;
5233 if (C) {
5234 handler->context.area = CTX_wm_area(C);
5235 handler->context.region = CTX_wm_region(C);
5236 handler->context.region_popup = CTX_wm_region_popup(C);
5237 }
5238 else {
5239 handler->context.area = nullptr;
5240 handler->context.region = nullptr;
5241 handler->context.region_popup = nullptr;
5242 }
5243
5244 BLI_assert((flag & WM_HANDLER_DO_FREE) == 0);
5245 handler->head.flag = flag;
5246
5247 BLI_addhead(handlers, handler);
5248
5249 return handler;
5250}
5251
5252void WM_event_remove_ui_handler(ListBaseT<wmEventHandler> *handlers,
5253 wmUIHandlerFunc handle_fn,
5254 wmUIHandlerRemoveFunc remove_fn,
5255 void *user_data,
5256 const bool postpone)
5257{
5258 for (wmEventHandler &handler_base : *handlers) {
5259 if (handler_base.type == WM_HANDLER_TYPE_UI) {
5260 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(&handler_base);
5261 if ((handler->handle_fn == handle_fn) && (handler->remove_fn == remove_fn) &&
5262 (handler->user_data == user_data))
5263 {
5264 /* Handlers will be freed in #wm_handlers_do(). */
5265 if (postpone) {
5266 handler->head.flag |= WM_HANDLER_DO_FREE;
5267 }
5268 else {
5269 BLI_remlink(handlers, handler);
5270 wm_event_free_handler(&handler->head);
5271 }
5272 break;
5273 }
5274 }
5275 }
5276}
5277
5279 ListBaseT<wmEventHandler> *handlers,
5280 wmUIHandlerFunc handle_fn,
5281 wmUIHandlerRemoveFunc remove_fn)
5282{
5283 for (wmEventHandler &handler_base : handlers->items_mutable()) {
5284 if (handler_base.type == WM_HANDLER_TYPE_UI) {
5285 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(&handler_base);
5286 if ((handler->handle_fn == handle_fn) && (handler->remove_fn == remove_fn)) {
5287 remove_fn(C, handler->user_data);
5288 BLI_remlink(handlers, handler);
5289 wm_event_free_handler(&handler->head);
5290 }
5291 }
5292 }
5293}
5294
5295wmEventHandler_Dropbox *WM_event_add_dropbox_handler(ListBaseT<wmEventHandler> *handlers,
5296 ListBaseT<wmDropBox> *dropboxes)
5297{
5298 /* Only allow same dropbox once. */
5299 for (wmEventHandler &handler_base : *handlers) {
5300 if (handler_base.type == WM_HANDLER_TYPE_DROPBOX) {
5301 wmEventHandler_Dropbox *handler = reinterpret_cast<wmEventHandler_Dropbox *>(&handler_base);
5302 if (handler->dropboxes == dropboxes) {
5303 return handler;
5304 }
5305 }
5306 }
5307
5310
5311 /* Dropbox stored static, no free or copy. */
5312 handler->dropboxes = dropboxes;
5313 BLI_addhead(handlers, handler);
5314
5315 return handler;
5316}
5317
5318void WM_event_remove_handlers_by_area(ListBaseT<wmEventHandler> *handlers, const ScrArea *area)
5319{
5320 /* XXX(@ton): solution works, still better check the real cause. */
5321
5322 for (wmEventHandler &handler_base : handlers->items_mutable()) {
5323 if (handler_base.type == WM_HANDLER_TYPE_UI) {
5324 wmEventHandler_UI *handler = reinterpret_cast<wmEventHandler_UI *>(&handler_base);
5325 if (handler->context.area == area) {
5326 BLI_remlink(handlers, handler);
5327 wm_event_free_handler(&handler_base);
5328 }
5329 }
5330 }
5331}
5332
5334{
5335 for (wmEventHandler &handler_base : win->runtime->modalhandlers) {
5336 if (handler_base.type != WM_HANDLER_TYPE_OP) {
5337 continue;
5338 }
5339 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
5340 if (handler->op && handler->op->type == ot) {
5341 return handler->op;
5342 }
5343 }
5344 return nullptr;
5345}
5346
5347#if 0
5348static void WM_event_remove_handler(ListBaseT<wmEventHandler> *handlers, wmEventHandler *handler)
5349{
5350 BLI_remlink(handlers, handler);
5351 wm_event_free_handler(handler);
5352}
5353#endif
5354
5356{
5357 win->addmousemove = 1;
5358}
5359
5361
5362/* -------------------------------------------------------------------- */
5365
5366#ifdef WITH_INPUT_NDOF
5370static wmEventType wm_event_type_from_ndof_button(GHOST_NDOF_ButtonT button)
5371{
5372# define CASE_NDOF_BUTTON(button) \
5373 case GHOST_NDOF_BUTTON_##button: \
5374 return NDOF_BUTTON_##button
5375
5376# define CASE_NDOF_BUTTON_IGNORE(button) \
5377 case GHOST_NDOF_BUTTON_##button: \
5378 break;
5379
5380 switch (button) {
5381 CASE_NDOF_BUTTON(MENU);
5382 CASE_NDOF_BUTTON(FIT);
5383 CASE_NDOF_BUTTON(TOP);
5384 CASE_NDOF_BUTTON(LEFT);
5385 CASE_NDOF_BUTTON(RIGHT);
5386 CASE_NDOF_BUTTON(FRONT);
5387 CASE_NDOF_BUTTON(BOTTOM);
5388 CASE_NDOF_BUTTON(BACK);
5389 CASE_NDOF_BUTTON(ROLL_CW);
5390 CASE_NDOF_BUTTON(ROLL_CCW);
5391 CASE_NDOF_BUTTON(ISO1);
5392 CASE_NDOF_BUTTON(ISO2);
5393 CASE_NDOF_BUTTON(1);
5394 CASE_NDOF_BUTTON(2);
5395 CASE_NDOF_BUTTON(3);
5396 CASE_NDOF_BUTTON(4);
5397 CASE_NDOF_BUTTON(5);
5398 CASE_NDOF_BUTTON(6);
5399 CASE_NDOF_BUTTON(7);
5400 CASE_NDOF_BUTTON(8);
5401 CASE_NDOF_BUTTON(9);
5402 CASE_NDOF_BUTTON(10);
5403 CASE_NDOF_BUTTON(11);
5404 CASE_NDOF_BUTTON(12);
5405 CASE_NDOF_BUTTON(ROTATE);
5406 CASE_NDOF_BUTTON(PANZOOM);
5407 CASE_NDOF_BUTTON(DOMINANT);
5408 CASE_NDOF_BUTTON(PLUS);
5409 CASE_NDOF_BUTTON(MINUS);
5410 CASE_NDOF_BUTTON(SPIN_CW);
5411 CASE_NDOF_BUTTON(SPIN_CCW);
5412 CASE_NDOF_BUTTON(TILT_CW);
5413 CASE_NDOF_BUTTON(TILT_CCW);
5414 CASE_NDOF_BUTTON(V1);
5415 CASE_NDOF_BUTTON(V2);
5416 CASE_NDOF_BUTTON(V3);
5417 CASE_NDOF_BUTTON(SAVE_V1);
5418 CASE_NDOF_BUTTON(SAVE_V2);
5419 CASE_NDOF_BUTTON(SAVE_V3);
5420
5421 /* Disabled as GHOST converts these to keyboard events
5422 * which use regular keyboard event handling logic. */
5423 /* Keyboard emulation. */
5424 CASE_NDOF_BUTTON_IGNORE(ESC);
5425 CASE_NDOF_BUTTON_IGNORE(ENTER);
5426 CASE_NDOF_BUTTON_IGNORE(DELETE);
5427 CASE_NDOF_BUTTON_IGNORE(TAB);
5428 CASE_NDOF_BUTTON_IGNORE(SPACE);
5429 CASE_NDOF_BUTTON_IGNORE(ALT);
5430 CASE_NDOF_BUTTON_IGNORE(SHIFT);
5431 CASE_NDOF_BUTTON_IGNORE(CTRL);
5432
5433 CASE_NDOF_BUTTON_IGNORE(KBP_F1);
5434 CASE_NDOF_BUTTON_IGNORE(KBP_F2);
5435 CASE_NDOF_BUTTON_IGNORE(KBP_F3);
5436 CASE_NDOF_BUTTON_IGNORE(KBP_F4);
5437 CASE_NDOF_BUTTON_IGNORE(KBP_F5);
5438 CASE_NDOF_BUTTON_IGNORE(KBP_F6);
5439 CASE_NDOF_BUTTON_IGNORE(KBP_F7);
5440 CASE_NDOF_BUTTON_IGNORE(KBP_F8);
5441 CASE_NDOF_BUTTON_IGNORE(KBP_F9);
5442 CASE_NDOF_BUTTON_IGNORE(KBP_F10);
5443 CASE_NDOF_BUTTON_IGNORE(KBP_F11);
5444 CASE_NDOF_BUTTON_IGNORE(KBP_F12);
5445
5446 CASE_NDOF_BUTTON_IGNORE(NP_F1);
5447 CASE_NDOF_BUTTON_IGNORE(NP_F2);
5448 CASE_NDOF_BUTTON_IGNORE(NP_F3);
5449 CASE_NDOF_BUTTON_IGNORE(NP_F4);
5450
5451 /* Quiet switch warnings. */
5452 CASE_NDOF_BUTTON_IGNORE(NONE);
5453 CASE_NDOF_BUTTON_IGNORE(INVALID);
5454 CASE_NDOF_BUTTON_IGNORE(USER);
5455 }
5456
5457# undef CASE_NDOF_BUTTON
5458# undef CASE_NDOF_BUTTON_IGNORE
5459
5460 CLOG_WARN(WM_LOG_EVENTS, "unknown event type %d from ndof button", int(button));
5461 return EVENT_NONE;
5462}
5463
5464#endif /* WITH_INPUT_NDOF */
5465
5470{
5471 if (key >= GHOST_kKeyA && key <= GHOST_kKeyZ) {
5472 return wmEventType(EVT_AKEY + (int(key) - GHOST_kKeyA));
5473 }
5474 if (key >= GHOST_kKey0 && key <= GHOST_kKey9) {
5475 return wmEventType(EVT_ZEROKEY + (int(key) - GHOST_kKey0));
5476 }
5477 if (key >= GHOST_kKeyNumpad0 && key <= GHOST_kKeyNumpad9) {
5478 return wmEventType(EVT_PAD0 + (int(key) - GHOST_kKeyNumpad0));
5479 }
5480 if (key >= GHOST_kKeyF1 && key <= GHOST_kKeyF24) {
5481 return wmEventType(EVT_F1KEY + (int(key) - GHOST_kKeyF1));
5482 }
5483
5484 switch (key) {
5486 return EVT_BACKSPACEKEY;
5487 case GHOST_kKeyTab:
5488 return EVT_TABKEY;
5489 case GHOST_kKeyLinefeed:
5490 return EVT_LINEFEEDKEY;
5491 case GHOST_kKeyClear:
5492 return EVENT_NONE;
5493 case GHOST_kKeyEnter:
5494 return EVT_RETKEY;
5495
5496 case GHOST_kKeyEsc:
5497 return EVT_ESCKEY;
5498 case GHOST_kKeySpace:
5499 return EVT_SPACEKEY;
5500 case GHOST_kKeyQuote:
5501 return EVT_QUOTEKEY;
5502 case GHOST_kKeyComma:
5503 return EVT_COMMAKEY;
5504 case GHOST_kKeyMinus:
5505 return EVT_MINUSKEY;
5506 case GHOST_kKeyPlus:
5507 return EVT_PLUSKEY;
5508 case GHOST_kKeyPeriod:
5509 return EVT_PERIODKEY;
5510 case GHOST_kKeySlash:
5511 return EVT_SLASHKEY;
5512
5514 return EVT_SEMICOLONKEY;
5515 case GHOST_kKeyEqual:
5516 return EVT_EQUALKEY;
5517
5519 return EVT_LEFTBRACKETKEY;
5521 return EVT_RIGHTBRACKETKEY;
5523 return EVT_BACKSLASHKEY;
5525 return EVT_ACCENTGRAVEKEY;
5526
5528 return EVT_LEFTSHIFTKEY;
5530 return EVT_RIGHTSHIFTKEY;
5532 return EVT_LEFTCTRLKEY;
5534 return EVT_RIGHTCTRLKEY;
5535 case GHOST_kKeyLeftOS:
5536 case GHOST_kKeyRightOS:
5537 return EVT_OSKEY;
5540 return EVT_HYPER;
5541 case GHOST_kKeyLeftAlt:
5542 return EVT_LEFTALTKEY;
5543 case GHOST_kKeyRightAlt:
5544 return EVT_RIGHTALTKEY;
5545 case GHOST_kKeyApp:
5546 return EVT_APPKEY;
5547
5548 case GHOST_kKeyCapsLock:
5549 return EVT_CAPSLOCKKEY;
5550 case GHOST_kKeyNumLock:
5551 return EVENT_NONE;
5553 return EVENT_NONE;
5554
5556 return EVT_LEFTARROWKEY;
5558 return EVT_RIGHTARROWKEY;
5559 case GHOST_kKeyUpArrow:
5560 return EVT_UPARROWKEY;
5562 return EVT_DOWNARROWKEY;
5563
5565 return EVENT_NONE;
5566 case GHOST_kKeyPause:
5567 return EVT_PAUSEKEY;
5568
5569 case GHOST_kKeyInsert:
5570 return EVT_INSERTKEY;
5571 case GHOST_kKeyDelete:
5572 return EVT_DELKEY;
5573 case GHOST_kKeyHome:
5574 return EVT_HOMEKEY;
5575 case GHOST_kKeyEnd:
5576 return EVT_ENDKEY;
5577 case GHOST_kKeyUpPage:
5578 return EVT_PAGEUPKEY;
5579 case GHOST_kKeyDownPage:
5580 return EVT_PAGEDOWNKEY;
5581
5583 return EVT_PADPERIOD;
5585 return EVT_PADENTER;
5587 return EVT_PADPLUSKEY;
5589 return EVT_PADMINUS;
5591 return EVT_PADASTERKEY;
5593 return EVT_PADSLASHKEY;
5594
5595 case GHOST_kKeyGrLess:
5596 return EVT_GRLESSKEY;
5597
5599 return EVT_MEDIAPLAY;
5601 return EVT_MEDIASTOP;
5603 return EVT_MEDIAFIRST;
5605 return EVT_MEDIALAST;
5606
5607 case GHOST_kKeyUnknown:
5608 return EVT_UNKNOWNKEY;
5609
5610#if defined(__GNUC__) || defined(__clang__)
5611 /* Ensure all members of this enum are handled, otherwise generate a compiler warning.
5612 * Note that these members have been handled, these ranges are to satisfy the compiler. */
5613 case GHOST_kKeyF1 ... GHOST_kKeyF24:
5614 case GHOST_kKeyA ... GHOST_kKeyZ:
5616 case GHOST_kKey0 ... GHOST_kKey9: {
5618 break;
5619 }
5620#else
5621 default: {
5622 break;
5623 }
5624#endif
5625 }
5626
5627 CLOG_WARN(WM_LOG_EVENTS, "unknown event type %d from ghost", int(key));
5628 return EVENT_NONE;
5629}
5630
5635 const wmEventType fallback)
5636{
5637#define CASE_BUTTON(ghost_button, type) \
5638 case ghost_button: \
5639 return type
5640
5641 switch (button) {
5649 case GHOST_kButtonMaskNone: {
5651 }
5652 }
5653
5654#undef CASE_BUTTON
5655
5657 return fallback;
5658}
5659
5660static void wm_eventemulation(wmEvent *event, bool test_only)
5661{
5662 /* Store last middle-mouse event value to make emulation work
5663 * when modifier keys are released first.
5664 * This really should be in a data structure somewhere. */
5665 static int emulating_event = EVENT_NONE;
5666
5667 /* Middle-mouse emulation. */
5668 if (U.flag & USER_TWOBUTTONMOUSE) {
5669
5670 if (event->type == LEFTMOUSE) {
5671 const wmEventModifierFlag mod_test = (
5672#if !defined(WIN32)
5673 (U.mouse_emulate_3_button_modifier == USER_EMU_MMB_MOD_OSKEY) ? KM_OSKEY : KM_ALT
5674#else
5675 /* Disable for WIN32 for now because it accesses the start menu. */
5676 KM_ALT
5677#endif
5678 );
5679
5680 if (event->val == KM_PRESS) {
5681 if (event->modifier & mod_test) {
5682 event->modifier &= ~mod_test;
5683 event->type = MIDDLEMOUSE;
5684
5685 if (!test_only) {
5686 emulating_event = MIDDLEMOUSE;
5687 }
5688 }
5689 }
5690 else if (event->val == KM_RELEASE) {
5691 /* Only send middle-mouse release if emulated. */
5692 if (emulating_event == MIDDLEMOUSE) {
5693 event->type = MIDDLEMOUSE;
5694 event->modifier &= ~mod_test;
5695 }
5696
5697 if (!test_only) {
5698 emulating_event = EVENT_NONE;
5699 }
5700 }
5701 }
5702 }
5703
5704 /* Numeric-pad emulation. */
5705 if (U.flag & USER_NONUMPAD) {
5706 switch (event->type) {
5707 case EVT_ZEROKEY:
5708 event->type = EVT_PAD0;
5709 break;
5710 case EVT_ONEKEY:
5711 event->type = EVT_PAD1;
5712 break;
5713 case EVT_TWOKEY:
5714 event->type = EVT_PAD2;
5715 break;
5716 case EVT_THREEKEY:
5717 event->type = EVT_PAD3;
5718 break;
5719 case EVT_FOURKEY:
5720 event->type = EVT_PAD4;
5721 break;
5722 case EVT_FIVEKEY:
5723 event->type = EVT_PAD5;
5724 break;
5725 case EVT_SIXKEY:
5726 event->type = EVT_PAD6;
5727 break;
5728 case EVT_SEVENKEY:
5729 event->type = EVT_PAD7;
5730 break;
5731 case EVT_EIGHTKEY:
5732 event->type = EVT_PAD8;
5733 break;
5734 case EVT_NINEKEY:
5735 event->type = EVT_PAD9;
5736 break;
5737 case EVT_MINUSKEY:
5738 event->type = EVT_PADMINUS;
5739 break;
5740 case EVT_EQUALKEY:
5741 event->type = EVT_PADPLUSKEY;
5742 break;
5743 case EVT_BACKSLASHKEY:
5744 event->type = EVT_PADSLASHKEY;
5745 break;
5746 default: {
5747 break;
5748 }
5749 }
5750 }
5751}
5752
5754{
5755 wmTabletData tablet_data{};
5756 tablet_data.active = EVT_TABLET_NONE;
5757 tablet_data.pressure = 1.0f;
5758 tablet_data.tilt = float2(0.0f, 0.0f);
5759 tablet_data.is_motion_absolute = false;
5760 return tablet_data;
5761}
5762
5764{
5765 *tablet_data = wm_event_tablet_data_default();
5766}
5767
5769{
5770 if ((tablet_data != nullptr) && tablet_data->Active != GHOST_kTabletModeNone) {
5771 wmtab->active = int(tablet_data->Active);
5772 wmtab->pressure = wm_pressure_curve(tablet_data->Pressure);
5773 wmtab->tilt = float2(tablet_data->Xtilt, tablet_data->Ytilt);
5774 /* We could have a preference to support relative tablet motion (we can't detect that). */
5775 wmtab->is_motion_absolute = true;
5776 // printf("%s: using tablet %.5f\n", __func__, wmtab->pressure);
5777 }
5778 else {
5780 // printf("%s: not using tablet\n", __func__);
5781 }
5782}
5783
5784#ifdef WITH_INPUT_NDOF
5785/* Adds custom-data to event. */
5786static void attach_ndof_data(wmEvent *event, const GHOST_TEventNDOFMotionData *ghost)
5787{
5788 wmNDOFMotionData *data = MEM_new<wmNDOFMotionData>("Custom-data NDOF");
5789
5790 const float ts = U.ndof_translation_sensitivity;
5791 const float rs = U.ndof_rotation_sensitivity;
5792
5793 mul_v3_v3fl(data->tvec, &ghost->tx, ts);
5794 mul_v3_v3fl(data->rvec, &ghost->rx, rs);
5795
5796 data->time_delta = ghost->dt;
5797
5798 data->progress = (wmProgress)ghost->progress;
5799
5800 event->custom = EVT_DATA_NDOF_MOTION;
5801 event->customdata = data;
5802 event->customdata_free = true;
5803}
5804#endif /* WITH_INPUT_NDOF */
5805
5806/* Imperfect but probably usable... draw/enable drags to other windows. */
5808{
5809 /* If GHOST doesn't support window positioning, don't use this feature at all. */
5810 const static int8_t supports_window_position = (WM_capabilities_flag() &
5812 if (!supports_window_position) {
5813 return nullptr;
5814 }
5815
5816 if (wm->windows.first() == wm->windows.last()) {
5817 return nullptr;
5818 }
5819
5820 /* In order to use window size and mouse position (pixels), we have to use a WM function. */
5821
5822 /* Check if outside, include top window bar. */
5823 const int2 win_size = WM_window_native_pixel_size(win);
5824 int event_xy[2] = {UNPACK2(event->xy)};
5825 if (event_xy[0] < 0 || event_xy[1] < 0 || event_xy[0] > win_size[0] ||
5826 event_xy[1] > win_size[1] + 30)
5827 {
5828 /* Let's skip windows having modal handlers now. */
5829 /* Potential XXX ugly... I wouldn't have added a `modalhandlers` list
5830 * (introduced in rev 23331, ton). */
5831 for (wmEventHandler &handler : win->runtime->modalhandlers) {
5833 return nullptr;
5834 }
5835 }
5836
5837 wmWindow *win_other = WM_window_find_under_cursor(win, event_xy, event_xy);
5838 if (win_other && win_other != win) {
5839 copy_v2_v2_int(event->xy, event_xy);
5840 return win_other;
5841 }
5842 }
5843 return nullptr;
5844}
5845
5846static bool wm_event_is_double_click(const wmEvent *event,
5847 const uint64_t event_time_ms,
5848 const uint64_t event_prev_press_time_ms)
5849{
5850 if ((event->type == event->prev_type) && (event->prev_val == KM_RELEASE) &&
5851 (event->val == KM_PRESS))
5852 {
5853 if (ISMOUSE_BUTTON(event->type) && WM_event_drag_test(event, event->prev_press_xy)) {
5854 /* Pass. */
5855 }
5856 else {
5857 if ((event_time_ms - event_prev_press_time_ms) < uint64_t(U.dbl_click_time)) {
5858 return true;
5859 }
5860 }
5861 }
5862
5863 return false;
5864}
5865
5869static void wm_event_prev_values_set(wmEvent *event, wmEvent *event_state)
5870{
5871 event->prev_val = event_state->prev_val = event_state->val;
5872 event->prev_type = event_state->prev_type = event_state->type;
5873}
5874
5875static void wm_event_prev_click_set(uint64_t event_time_ms,
5876 wmEvent *event_state,
5877 uint64_t *r_event_state_prev_press_time_ms)
5878{
5879 event_state->prev_press_type = event_state->type;
5880 event_state->prev_press_modifier = event_state->modifier;
5881 event_state->prev_press_keymodifier = event_state->keymodifier;
5882 event_state->prev_press_xy[0] = event_state->xy[0];
5883 event_state->prev_press_xy[1] = event_state->xy[1];
5884 *r_event_state_prev_press_time_ms = event_time_ms;
5885}
5886
5888{
5889 wmEvent *event_last = win->runtime->event_queue.last();
5890
5891 /* Some painting operators want accurate mouse events, they can
5892 * handle in between mouse move moves, others can happily ignore
5893 * them for better performance. */
5894 if (event_last && event_last->type == MOUSEMOVE) {
5895 event_last->type = INBETWEEN_MOUSEMOVE;
5896 event_last->flag = eWM_EventFlag(0);
5897 }
5898
5899 wmEvent *event_new = wm_event_add_intern(win, event);
5900 if (event_last == nullptr) {
5901 event_last = win->runtime->eventstate;
5902 }
5903
5904 copy_v2_v2_int(event_new->prev_xy, event_last->xy);
5905 return event_new;
5906}
5907
5909{
5910 /* Use the last handled event instead of `win->runtime->eventstate` because the state of the
5911 * modifiers and previous values should be set based on the last state, not using values from the
5912 * future. So this gives an accurate simulation of mouse motion before the next event is handled.
5913 */
5914 const wmEvent *event_last = win->runtime->event_last_handled;
5915
5916 wmEvent tevent;
5917 if (event_last) {
5918 tevent = *event_last;
5919
5920 tevent.flag = eWM_EventFlag(0);
5921 tevent.utf8_buf[0] = '\0';
5922
5923 wm_event_custom_clear(&tevent);
5924 }
5925 else {
5926 memset(&tevent, 0x0, sizeof(tevent));
5927 }
5928
5929 tevent.type = MOUSEMOVE;
5930 tevent.val = KM_NOTHING;
5931 copy_v2_v2_int(tevent.prev_xy, tevent.xy);
5932
5933 wmEvent *event_new = wm_event_add_intern(win, &tevent);
5934 BLI_remlink(&win->runtime->event_queue, event_new);
5935 BLI_addhead(&win->runtime->event_queue, event_new);
5936
5937 return event_new;
5938}
5939
5940static wmEvent *wm_event_add_trackpad(wmWindow *win, const wmEvent *event, int deltax, int deltay)
5941{
5942 /* Ignore in between trackpad events for performance, we only need high accuracy
5943 * for painting with mouse moves, for navigation using the accumulated value is ok. */
5944 const wmEvent *event_last = win->runtime->event_queue.last();
5945 if (event_last && event_last->type == event->type) {
5946 deltax += event_last->xy[0] - event_last->prev_xy[0];
5947 deltay += event_last->xy[1] - event_last->prev_xy[1];
5948
5949 wm_event_free_last(win);
5950 }
5951
5952 /* Set prev_xy, the delta is computed from this in operators. */
5953 wmEvent *event_new = wm_event_add_intern(win, event);
5954 event_new->prev_xy[0] = event_new->xy[0] - deltax;
5955 event_new->prev_xy[1] = event_new->xy[1] - deltay;
5956
5957 return event_new;
5958}
5959
5967 const uint64_t event_time_ms,
5968 wmEvent *event_state,
5969 uint64_t *event_state_prev_press_time_ms_p,
5970 const bool is_keyboard,
5971 const bool check_double_click)
5972{
5975
5976 /* Only copy these flags into the `event_state`. */
5977 const eWM_EventFlag event_state_flag_mask = WM_EVENT_IS_REPEAT;
5978
5979 wm_event_prev_values_set(event, event_state);
5980
5981 /* Copy to event state. */
5982 event_state->val = event->val;
5983 event_state->type = event->type;
5984 /* It's important only to write into the `event_state` modifier for keyboard
5985 * events because emulate MMB clears one of the modifiers in `event->modifier`,
5986 * making the second press not behave as if the modifier is pressed, see #96279. */
5987 if (is_keyboard) {
5988 event_state->modifier = event->modifier;
5989 }
5990 event_state->flag = (event->flag & event_state_flag_mask);
5991 /* NOTE: It's important that `keymodifier` is handled in the keyboard event handling logic
5992 * since the `event_state` and the `event` are not kept in sync. */
5993
5994 /* Double click test. */
5995 if (check_double_click &&
5996 wm_event_is_double_click(event, event_time_ms, *event_state_prev_press_time_ms_p))
5997 {
5998 CLOG_DEBUG(WM_LOG_EVENTS, "Detected DBL_CLICK");
5999 event->val = KM_DBL_CLICK;
6000 }
6001 else if (event->val == KM_PRESS) {
6002 if ((event->flag & WM_EVENT_IS_REPEAT) == 0) {
6003 wm_event_prev_click_set(event_time_ms, event_state, event_state_prev_press_time_ms_p);
6004 }
6005 }
6006}
6007
6009 uint64_t event_time_ms,
6010 wmEvent *event_state,
6011 uint64_t *event_state_prev_press_time_ms_p,
6012 const GHOST_TEventType type)
6013{
6014 const bool is_keyboard = ELEM(type, GHOST_kEventKeyDown, GHOST_kEventKeyUp);
6015 const bool check_double_click = true;
6017 event_time_ms,
6018 event_state,
6019 event_state_prev_press_time_ms_p,
6020 is_keyboard,
6021 check_double_click);
6022}
6023
6024/* Returns true when the two events corresponds to a press of the same key with the same modifiers.
6025 */
6026static bool wm_event_is_same_key_press(const wmEvent &event_a, const wmEvent &event_b)
6027{
6028 if (event_a.val != KM_PRESS || event_b.val != KM_PRESS) {
6029 return false;
6030 }
6031
6032 if (event_a.modifier != event_b.modifier || event_a.type != event_b.type) {
6033 return false;
6034 }
6035
6036 return true;
6037}
6038
6047static bool wm_event_is_ignorable_key_press(const wmWindow *win, const wmEvent &event)
6048{
6049 if (win->runtime->event_queue.is_empty()) {
6050 /* If the queue is empty never ignore the event.
6051 * Empty queue at this point means that the events are handled fast enough, and there is no
6052 * reason to ignore anything. */
6053 return false;
6054 }
6055
6056 if ((event.flag & WM_EVENT_IS_REPEAT) == 0) {
6057 /* Only ignore repeat events from the keyboard, and allow accumulation of non-repeat events.
6058 *
6059 * The goal of this check is to allow events coming from a keyboard macro software, which can
6060 * generate events quicker than the main loop handles them. In this case we want all events to
6061 * be handled (unless the keyboard macro software tags them as repeat) because otherwise it
6062 * will become impossible to get reliable results of automated events testing. */
6063 return false;
6064 }
6065
6066 const wmEvent &last_event = *win->runtime->event_queue.last();
6067
6068 return wm_event_is_same_key_press(last_event, event);
6069}
6070
6072 wmWindow *win,
6073 const int type,
6074 const void *customdata,
6075 const uint64_t event_time_ms)
6076{
6077 if (G.f & G_FLAG_EVENT_SIMULATE) [[unlikely]] {
6078 return;
6079 }
6080
6091 wmEvent event, *event_state = win->runtime->eventstate;
6092 uint64_t *event_state_prev_press_time_ms_p = &win->runtime->eventstate_prev_press_time_ms;
6093
6094 /* Initialize and copy state (only mouse x y and modifiers). */
6095 event = *event_state;
6096 event.flag = eWM_EventFlag(0);
6097
6109 event.prev_type = event.type;
6110 event.prev_val = event.val;
6111
6112 /* Always use modifiers from the active window since
6113 * changes to modifiers aren't sent to inactive windows, see: #66088. */
6114 if ((wm->runtime->winactive != win) &&
6115 (wm->runtime->winactive && wm->runtime->winactive->runtime->eventstate))
6116 {
6117 event.modifier = wm->runtime->winactive->runtime->eventstate->modifier;
6118 event.keymodifier = wm->runtime->winactive->runtime->eventstate->keymodifier;
6119 }
6120
6121 /* Ensure the event state is correct, any deviation from this may cause bugs.
6122 *
6123 * NOTE: #EVENT_NONE is set when unknown keys are pressed,
6124 * while not common, avoid a false alarm. */
6125#ifndef NDEBUG
6126 if ((event_state->type || event_state->val) && /* Ignore cleared event state. */
6127 !(ISKEYBOARD_OR_BUTTON(event_state->type) || (event_state->type == EVENT_NONE)))
6128 {
6130 "Non-keyboard/mouse button found in 'win->runtime->eventstate->type = %d'",
6131 event_state->type);
6132 }
6133 if ((event_state->prev_type || event_state->prev_val) && /* Ignore cleared event state. */
6134 !(ISKEYBOARD_OR_BUTTON(event_state->prev_type) || (event_state->type == EVENT_NONE)))
6135 {
6137 "Non-keyboard/mouse button found in 'win->runtime->eventstate->prev_type = %d'",
6138 event_state->prev_type);
6139 }
6140#endif
6141
6142 switch (type) {
6143 /* Mouse move, also to inactive window (X11 does this). */
6145 const GHOST_TEventCursorData *cd = static_cast<const GHOST_TEventCursorData *>(customdata);
6146
6147 copy_v2_v2_int(event.xy, &cd->x);
6148 wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
6149
6152
6153 event.type = MOUSEMOVE;
6154 event.val = KM_NOTHING;
6155 {
6156 wmEvent *event_new = wm_event_add_mousemove(win, &event);
6157 copy_v2_v2_int(event_state->xy, event_new->xy);
6158 event_state->tablet.is_motion_absolute = event_new->tablet.is_motion_absolute;
6159 event_state->tablet.tilt = event.tablet.tilt;
6160 }
6161
6162 /* Also add to other window if event is there, this makes overdraws disappear nicely. */
6163 /* It remaps mouse-coord to other window in event. */
6164 wmWindow *win_other = wm_event_cursor_other_windows(wm, win, &event);
6165 if (win_other) {
6166 wmEvent event_other = *win_other->runtime->eventstate;
6167
6168 /* Use the modifier state of this window. */
6169 event_other.modifier = event.modifier;
6170 event_other.keymodifier = event.keymodifier;
6171
6172 /* See comment for this operation on `event` for details. */
6173 event_other.prev_type = event_other.type;
6174 event_other.prev_val = event_other.val;
6175
6176 copy_v2_v2_int(event_other.xy, event.xy);
6177 event_other.type = MOUSEMOVE;
6178 event_other.val = KM_NOTHING;
6179 {
6180 wmEvent *event_new = wm_event_add_mousemove(win_other, &event_other);
6181 copy_v2_v2_int(win_other->runtime->eventstate->xy, event_new->xy);
6183 event_new->tablet.is_motion_absolute;
6184 }
6185 }
6186
6187 break;
6188 }
6189 case GHOST_kEventTrackpad: {
6190 const GHOST_TEventTrackpadData *pd = static_cast<const GHOST_TEventTrackpadData *>(
6191 customdata);
6192
6193 int delta[2] = {pd->deltaX, -pd->deltaY};
6194 switch (pd->subtype) {
6196 event.type = MOUSEZOOM;
6197 delta[0] = -delta[0];
6198 delta[1] = -delta[1];
6199 break;
6201 event.type = MOUSESMARTZOOM;
6202 break;
6204 event.type = MOUSEROTATE;
6205 break;
6207 default:
6208 event.type = MOUSEPAN;
6209 break;
6210 }
6211
6212 copy_v2_v2_int(event.xy, &pd->x);
6213 wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
6214 copy_v2_v2_int(event_state->xy, event.xy);
6215 event.val = KM_NOTHING;
6216
6217 /* The direction is inverted from the device due to system preferences. */
6218 if (pd->isDirectionInverted) {
6219 event.flag |= WM_EVENT_SCROLL_INVERT;
6220 }
6221
6222#if !defined(WIN32) && !defined(__APPLE__)
6223 /* Ensure "auto" is used when supported. */
6224 char trackpad_scroll_direction = U.trackpad_scroll_direction;
6226 switch (eUserpref_TrackpadScrollDir(trackpad_scroll_direction)) {
6228 event.flag &= ~WM_EVENT_SCROLL_INVERT;
6229 break;
6230 }
6232 event.flag |= WM_EVENT_SCROLL_INVERT;
6233 break;
6234 }
6235 }
6236 }
6237#endif
6238
6239 wm_event_add_trackpad(win, &event, delta[0], delta[1]);
6240 break;
6241 }
6242 /* Mouse button. */
6244 case GHOST_kEventButtonUp: {
6245 const GHOST_TEventButtonData *bd = static_cast<const GHOST_TEventButtonData *>(customdata);
6246
6247 /* Get value and type from GHOST.
6248 *
6249 * NOTE(@ideasman42): Unknown mouse buttons are treated as middle-mouse (historic stuff).
6250 * GHOST should never generate unknown events and this logic can probably be removed. */
6251 event.val = (type == GHOST_kEventButtonDown) ? KM_PRESS : KM_RELEASE;
6253
6254 /* Get tablet data. */
6256
6257 wm_eventemulation(&event, false);
6259 event_time_ms,
6260 event_state,
6261 event_state_prev_press_time_ms_p,
6262 GHOST_TEventType(type));
6263
6264 /* Add to other window if event is there (not to both!). */
6265 wmWindow *win_other = wm_event_cursor_other_windows(wm, win, &event);
6266 if (win_other) {
6267 wmEvent event_other = *win_other->runtime->eventstate;
6268
6269 /* Use the modifier state of this window. */
6270 event_other.modifier = event.modifier;
6271 event_other.keymodifier = event.keymodifier;
6272
6273 /* See comment for this operation on `event` for details. */
6274 event_other.prev_type = event_other.type;
6275 event_other.prev_val = event_other.val;
6276
6277 copy_v2_v2_int(event_other.xy, event.xy);
6278
6279 event_other.type = event.type;
6280 event_other.val = event.val;
6281 event_other.tablet = event.tablet;
6282
6283 wm_event_add_intern(win_other, &event_other);
6284 }
6285 else {
6286 wm_event_add_intern(win, &event);
6287 }
6288
6289 break;
6290 }
6291 /* Keyboard. */
6293 case GHOST_kEventKeyUp: {
6294 const GHOST_TEventKeyData *kd = static_cast<const GHOST_TEventKeyData *>(customdata);
6295 event.type = wm_event_type_from_ghost_key(kd->key);
6296 if (event.type == EVENT_NONE) [[unlikely]] {
6297 break;
6298 }
6299
6300 /* Might be not null terminated. */
6301 memcpy(event.utf8_buf, kd->utf8_buf, sizeof(event.utf8_buf));
6302 if (kd->is_repeat) {
6303 event.flag |= WM_EVENT_IS_REPEAT;
6304 }
6305 event.val = (type == GHOST_kEventKeyDown) ? KM_PRESS : KM_RELEASE;
6306
6307 wm_eventemulation(&event, false);
6308
6309 /* Exclude arrow keys, escape, etc from text input. */
6310 if (type == GHOST_kEventKeyUp) {
6311 /* Ghost should do this already for key up. */
6312 if (event.utf8_buf[0]) {
6314 "ghost on your platform is misbehaving, utf8 events on key up!");
6315 }
6316 event.utf8_buf[0] = '\0';
6317 }
6318 else {
6319 /* Check for ASCII control characters.
6320 * Inline `iscntrl` because the users locale must not change behavior. */
6321 if ((event.utf8_buf[0] < 32 && event.utf8_buf[0] > 0) || (event.utf8_buf[0] == 127)) {
6322 event.utf8_buf[0] = '\0';
6323 }
6324 }
6325
6326 if (event.utf8_buf[0]) {
6327 /* NOTE(@ideasman42): Detect non-ASCII characters stored in `utf8_buf`,
6328 * ideally this would never happen but it can't be ruled out for X11 which has
6329 * special handling of Latin1 when building without UTF8 support.
6330 * Avoid regressions by adding this conversions, it should eventually be removed. */
6331 if ((event.utf8_buf[0] >= 0x80) && (event.utf8_buf[1] == '\0')) {
6332 const uint c = uint(event.utf8_buf[0]);
6333 int utf8_buf_len = BLI_str_utf8_from_unicode(c, event.utf8_buf, sizeof(event.utf8_buf));
6335 "ghost detected non-ASCII single byte character '%u', converting to utf8 "
6336 "('%.*s', length=%d)",
6337 c,
6338 utf8_buf_len,
6339 event.utf8_buf,
6340 utf8_buf_len);
6341 }
6342
6343 const int utf8_buf_len = BLI_str_utf8_size_or_error(event.utf8_buf);
6344 if (utf8_buf_len == -1) {
6346 "ghost detected an invalid unicode character '%d'",
6347 int(uchar(event.utf8_buf[0])));
6348 event.utf8_buf[0] = '\0';
6349 }
6350 else {
6351#ifndef NDEBUG
6352 /* Ensure callers don't accidentally treat this as a "string",
6353 * it's not null terminated. */
6354 if (utf8_buf_len > 0) {
6355 for (int i = utf8_buf_len; i < ARRAY_SIZE(event.utf8_buf); i++) {
6356 event.utf8_buf[i] = 0xff;
6357 }
6358 }
6359#endif /* !NDEBUG */
6360 }
6361 }
6362
6363 /* NOTE(@ideasman42): Setting the modifier state based on press/release
6364 * is technically incorrect.
6365 *
6366 * - The user might hold both left/right modifier keys, then only release one.
6367 *
6368 * This could be solved by storing a separate flag for the left/right modifiers,
6369 * and combine them into `event.modifiers`.
6370 *
6371 * - The user might have multiple keyboards (or keyboard + NDOF device)
6372 * where it's possible to press the same modifier key multiple times.
6373 *
6374 * This could be solved by tracking the number of held modifier keys,
6375 * (this is in fact what LIBXKB does), however doing this relies on all GHOST
6376 * back-ends properly reporting every press/release as any mismatch could result
6377 * in modifier keys being stuck (which is very bad!).
6378 *
6379 * To my knowledge users never reported a bug relating to these limitations so
6380 * it seems reasonable to keep the current logic. */
6381
6382 switch (event.type) {
6383 case EVT_LEFTSHIFTKEY:
6384 case EVT_RIGHTSHIFTKEY: {
6385 SET_FLAG_FROM_TEST(event.modifier, (event.val == KM_PRESS), KM_SHIFT);
6386 break;
6387 }
6388 case EVT_LEFTCTRLKEY:
6389 case EVT_RIGHTCTRLKEY: {
6390 SET_FLAG_FROM_TEST(event.modifier, (event.val == KM_PRESS), KM_CTRL);
6391 break;
6392 }
6393 case EVT_LEFTALTKEY:
6394 case EVT_RIGHTALTKEY: {
6395 SET_FLAG_FROM_TEST(event.modifier, (event.val == KM_PRESS), KM_ALT);
6396 break;
6397 }
6398 case EVT_OSKEY: {
6399 SET_FLAG_FROM_TEST(event.modifier, (event.val == KM_PRESS), KM_OSKEY);
6400 break;
6401 }
6402 case EVT_HYPER: {
6403 SET_FLAG_FROM_TEST(event.modifier, (event.val == KM_PRESS), KM_HYPER);
6404 break;
6405 }
6406 default: {
6407 if (event.val == KM_PRESS) {
6408 if (event.keymodifier == 0) {
6409 /* Only set in `eventstate`, for next event. */
6410 event_state->keymodifier = event.type;
6411 }
6412 }
6413 else {
6414 BLI_assert(event.val == KM_RELEASE);
6415 if (event.keymodifier == event.type) {
6416 event.keymodifier = event_state->keymodifier = EVENT_NONE;
6417 }
6418 }
6419
6420 /* This case happens on holding a key pressed,
6421 * it should not generate press events with the same key as modifier. */
6422 if (event.keymodifier == event.type) {
6423 event.keymodifier = EVENT_NONE;
6424 }
6425 else if (event.keymodifier == EVT_UNKNOWNKEY) {
6426 /* This case happens with an external number-pad, and also when using 'dead keys'
6427 * (to compose complex Latin characters e.g.), it's not really clear why.
6428 * Since it's impossible to map a key modifier to an unknown key,
6429 * it shouldn't harm to clear it. */
6430 event_state->keymodifier = event.keymodifier = EVENT_NONE;
6431 }
6432 break;
6433 }
6434 }
6435
6436 /* It's important `event.modifier` has been initialized first. */
6438 event_time_ms,
6439 event_state,
6440 event_state_prev_press_time_ms_p,
6441 GHOST_TEventType(type));
6442
6443 /* If test_break set, it catches this. Do not set with modifier presses.
6444 * Exclude modifiers because MS-Windows uses these to bring up the task manager.
6445 *
6446 * NOTE: in general handling events here isn't great design as
6447 * event handling should be managed by the event handling loop.
6448 * Make an exception for `G.is_break` as it ensures we can always cancel operations
6449 * such as rendering or baking no matter which operation is currently handling events. */
6450 if ((event.type == EVT_ESCKEY) && (event.val == KM_PRESS) && (event.modifier == 0)) {
6451 G.is_break = true;
6452 }
6453
6454 if (!wm_event_is_ignorable_key_press(win, event)) {
6455 wm_event_add_intern(win, &event);
6456 }
6457
6458 break;
6459 }
6460
6461 case GHOST_kEventWheel: {
6462 const GHOST_TEventWheelData *wheelData = static_cast<const GHOST_TEventWheelData *>(
6463 customdata);
6464
6465 int click_step;
6466 if (wheelData->axis == GHOST_kEventWheelAxisVertical) {
6467 if (wheelData->value > 0) {
6468 event.type = WHEELUPMOUSE;
6469 click_step = wheelData->value;
6470 }
6471 else {
6472 event.type = WHEELDOWNMOUSE;
6473 click_step = -wheelData->value;
6474 }
6475 }
6476 else {
6477 if (wheelData->value > 0) {
6478 event.type = WHEELRIGHTMOUSE;
6479 click_step = wheelData->value;
6480 }
6481 else {
6482 event.type = WHEELLEFTMOUSE;
6483 click_step = -wheelData->value;
6484 }
6485 }
6486 BLI_assert(click_step != 0);
6487
6488 /* Avoid generating a large number of events.
6489 * In practice this values is typically 1, sometimes 2-3, even 32 is very high
6490 * although this could happen if the system freezes. */
6491 click_step = std::min(click_step, 32);
6492
6493 /* TODO: support a wheel event that includes the number of steps
6494 * instead of generating multiple events. */
6495 event.val = KM_PRESS;
6496 for (int i = 0; i < click_step; i++) {
6497 wm_event_add_intern(win, &event);
6498 }
6499
6500 break;
6501 }
6502
6503#ifdef WITH_INPUT_NDOF
6504 case GHOST_kEventNDOFMotion: {
6505 event.type = NDOF_MOTION;
6506 event.val = KM_NOTHING;
6507 attach_ndof_data(&event, static_cast<const GHOST_TEventNDOFMotionData *>(customdata));
6508 wm_event_add_intern(win, &event);
6509
6510 CLOG_INFO(WM_LOG_EVENTS, "sending NDOF_MOTION, prev = %d %d", event.xy[0], event.xy[1]);
6511 break;
6512 }
6513
6514 case GHOST_kEventNDOFButton: {
6515 const GHOST_TEventNDOFButtonData *e = static_cast<const GHOST_TEventNDOFButtonData *>(
6516 customdata);
6517 event.type = wm_event_type_from_ndof_button(static_cast<GHOST_NDOF_ButtonT>(e->button));
6518
6519 switch (e->action) {
6520 case GHOST_kPress:
6521 event.val = KM_PRESS;
6522 break;
6523 case GHOST_kRelease:
6524 event.val = KM_RELEASE;
6525 break;
6526 default:
6528 }
6529
6530 event.custom = 0;
6531 event.customdata = nullptr;
6532
6534 event_time_ms,
6535 event_state,
6536 event_state_prev_press_time_ms_p,
6537 (GHOST_TEventType)type);
6538
6539 wm_event_add_intern(win, &event);
6540
6541 break;
6542 }
6543#endif /* WITH_INPUT_NDOF */
6544
6547 break;
6548
6550 event.type = WINDEACTIVATE;
6551 wm_event_add_intern(win, &event);
6552
6553 break;
6554 }
6555
6556#ifdef WITH_INPUT_IME
6558 event.val = KM_PRESS;
6559 BLI_assert(customdata != nullptr);
6560 /* We need to free the previously allocated data (if any). */
6561 MEM_delete(win->runtime->ime_data);
6562
6563 /* We make a copy of the ghost custom data as it is not certain that the pointer
6564 * will be valid after the event itself gets freed.
6565 */
6566 const wmIMEData *ghost_event_data = static_cast<const wmIMEData *>(customdata);
6567 win->runtime->ime_data = MEM_new<wmIMEData>(__func__, *ghost_event_data);
6568
6569 win->runtime->ime_data_is_composing = true;
6570 event.type = WM_IME_COMPOSITE_START;
6571 wm_event_add_intern(win, &event);
6572 break;
6573 }
6575 event.val = KM_PRESS;
6576 event.type = WM_IME_COMPOSITE_EVENT;
6577
6578 /* Update our copy of the ghost custom data. */
6579 MEM_delete(win->runtime->ime_data);
6580 const wmIMEData *ghost_event_data = static_cast<const wmIMEData *>(customdata);
6581 win->runtime->ime_data = MEM_new<wmIMEData>(__func__, *ghost_event_data);
6582
6583 wm_event_add_intern(win, &event);
6584 break;
6585 }
6587 event.val = KM_PRESS;
6588 win->runtime->ime_data_is_composing = false;
6589 event.type = WM_IME_COMPOSITE_END;
6590 wm_event_add_intern(win, &event);
6591 break;
6592 }
6593#endif /* WITH_INPUT_IME */
6594 }
6595
6596#if 0
6597 WM_event_print(&event);
6598#endif
6599}
6600
6601#ifdef WITH_XR_OPENXR
6602void wm_event_add_xrevent(wmWindow *win, wmXrActionData *actiondata, short val)
6603{
6605
6606 wmEvent event{};
6607 event.type = EVT_XR_ACTION;
6608 event.val = val;
6609 event.flag = (eWM_EventFlag)0;
6610 event.custom = EVT_DATA_XR;
6611 event.customdata = actiondata;
6612 event.customdata_free = true;
6613
6614 WM_event_add(win, &event);
6615}
6616#endif /* WITH_XR_OPENXR */
6617
6619
6620/* -------------------------------------------------------------------- */
6623
6629{
6631
6632 if (wm->runtime->is_interface_locked) {
6633 if ((ot->flag & OPTYPE_LOCK_BYPASS) == 0) {
6634 return false;
6635 }
6636 }
6637
6638 return true;
6639}
6640
6642{
6643 /* This will prevent events from being handled while interface is locked
6644 *
6645 * Use a "local" flag for now, because currently no other areas could
6646 * benefit of locked interface anyway (aka using G.is_interface_locked
6647 * wouldn't be useful anywhere outside of window manager, so let's not
6648 * pollute global context with such an information for now).
6649 */
6650 wm->runtime->is_interface_locked = (lock_flags != 0);
6651
6652 BKE_spacedata_draw_locks(static_cast<ARegionDrawLockFlags>(lock_flags));
6653}
6654
6659
6661
6662/* -------------------------------------------------------------------- */
6665
6667 wmWindow *win,
6668 wmEventHandler_Keymap *handler,
6669 wmEventHandler_KeymapResult *km_result)
6670{
6671 if (handler->dynamic.keymap_fn != nullptr) {
6672 handler->dynamic.keymap_fn(wm, win, handler, km_result);
6673 BLI_assert(handler->keymap == nullptr);
6674 }
6675 else {
6676 memset(km_result, 0x0, sizeof(*km_result));
6677 wmKeyMap *keymap = WM_keymap_active(wm, handler->keymap);
6678 BLI_assert(keymap != nullptr);
6679 if (keymap != nullptr) {
6680 km_result->keymaps[km_result->keymaps_len++] = keymap;
6681 }
6682 }
6683}
6684
6686{
6687 for (wmKeyMapItem &kmi : keymap->items) {
6688 if (wm_eventmatch(event, &kmi)) {
6689 wmOperatorType *ot = WM_operatortype_find(kmi.idname, false);
6691 return &kmi;
6692 }
6693 }
6694 }
6695 return nullptr;
6696}
6697
6700 wmWindow *win,
6701 ListBaseT<wmEventHandler> *handlers,
6702 const wmEvent *event)
6703{
6704 for (wmEventHandler &handler_base : *handlers) {
6705 /* During this loop, UI handlers for nested menus can tag multiple handlers free. */
6706 if (handler_base.flag & WM_HANDLER_DO_FREE) {
6707 /* Pass. */
6708 }
6709 else if (handler_base.poll == nullptr ||
6710 handler_base.poll(win, CTX_wm_area(C), CTX_wm_region(C), event))
6711 {
6712 if (handler_base.type == WM_HANDLER_TYPE_KEYMAP) {
6713 wmEventHandler_Keymap *handler = reinterpret_cast<wmEventHandler_Keymap *>(&handler_base);
6715 WM_event_get_keymaps_from_handler(wm, win, handler, &km_result);
6716 for (int km_index = 0; km_index < km_result.keymaps_len; km_index++) {
6717 wmKeyMap *keymap = km_result.keymaps[km_index];
6718 if (WM_keymap_poll(C, keymap)) {
6719 wmKeyMapItem *kmi = WM_event_match_keymap_item(C, keymap, event);
6720 if (kmi != nullptr) {
6721 return kmi;
6722 }
6723 }
6724 }
6725 }
6726 }
6727 }
6728 return nullptr;
6729}
6730
6731bool WM_event_match(const wmEvent *winevent, const wmKeyMapItem *kmi)
6732{
6733 return wm_eventmatch(winevent, kmi);
6734}
6735
6737 const wmKeyMapItem *kmi)
6738{
6739 /* The caller is expected to skip. */
6740 BLI_assert((kmi->flag & KMI_INACTIVE) == 0);
6741
6742 if (event_modifier == 0) {
6743 return false;
6744 }
6745 if (kmi->val != KM_PRESS) {
6746 return false;
6747 }
6748 switch (kmi->type) {
6749 case EVT_LEFTCTRLKEY:
6750 case EVT_RIGHTCTRLKEY: {
6751 return event_modifier & KM_CTRL;
6752 }
6753 case EVT_LEFTSHIFTKEY:
6754 case EVT_RIGHTSHIFTKEY: {
6755 return event_modifier & KM_SHIFT;
6756 }
6757 case EVT_LEFTALTKEY:
6758 case EVT_RIGHTALTKEY: {
6759 return event_modifier & KM_ALT;
6760 }
6761 case EVT_OSKEY: {
6762 return event_modifier & KM_OSKEY;
6763 }
6764 case EVT_HYPER: {
6765 return event_modifier & KM_HYPER;
6766 }
6767 default: {
6768 return false;
6769 }
6770 }
6771}
6772
6774
6775/* -------------------------------------------------------------------- */
6782
6791
6802
6804 const wmEvent *event,
6805 short space_type,
6806 short region_type,
6807 const bToolRef *tref)
6808{
6809 state->modifier = event->modifier;
6810 state->space_type = space_type;
6811 state->region_type = region_type;
6812 state->tref = tref ? *tref : bToolRef{};
6813}
6814
6816 int button_index,
6817 int type_index)
6818{
6819 if (win->runtime->cursor_keymap_status != nullptr) {
6821 const char *msg = cd->text[button_index][type_index];
6822 if (*msg) {
6823 return msg;
6824 }
6825 }
6826 return nullptr;
6827}
6828
6830{
6831 if (screen->state == SCREENFULL) {
6832 return nullptr;
6833 }
6834 ScrArea *area_statusbar = nullptr;
6835 for (ScrArea &area : win->global_areas.areabase) {
6836 if (area.spacetype == SPACE_STATUSBAR) {
6837 area_statusbar = &area;
6838 break;
6839 }
6840 }
6841 return area_statusbar;
6842}
6843
6845{
6846 bScreen *screen = WM_window_get_active_screen(win);
6847 ScrArea *area = WM_window_status_area_find(win, screen);
6848 if (area != nullptr) {
6849 ED_area_tag_redraw(area);
6850 }
6851}
6852
6854{
6855 if (win->runtime->cursor_keymap_status) {
6857 MEM_delete(cd);
6858 win->runtime->cursor_keymap_status = nullptr;
6859 }
6860}
6861
6863{
6864 const Main *bmain = CTX_data_main(C);
6865 bScreen *screen = WM_window_get_active_screen(win);
6866 ScrArea *area_statusbar = WM_window_status_area_find(win, screen);
6867 if (area_statusbar == nullptr) {
6869 return;
6870 }
6871
6872 CursorKeymapInfo *cd;
6873 if (win->runtime->cursor_keymap_status == nullptr) [[unlikely]] {
6874 win->runtime->cursor_keymap_status = MEM_new<CursorKeymapInfo>(__func__);
6875 }
6876 cd = static_cast<CursorKeymapInfo *>(win->runtime->cursor_keymap_status);
6877
6878 /* Detect unchanged state (early exit). */
6879 if (memcmp(&cd->state_event, win->runtime->eventstate, sizeof(wmEvent)) == 0) {
6880 return;
6881 }
6882
6883 /* Now perform more comprehensive check,
6884 * still keep this fast since it happens on mouse-move. */
6885 CursorKeymapInfo cd_prev = *(
6886 static_cast<CursorKeymapInfo *>(win->runtime->cursor_keymap_status));
6887 cd->state_event = *win->runtime->eventstate;
6888
6889 /* Find active region and associated area. */
6890 ARegion *region = screen->active_region;
6891 if (region == nullptr) {
6892 return;
6893 }
6894
6895 ScrArea *area = nullptr;
6896 ED_screen_areas_iter (win, screen, area_iter) {
6897 if (BLI_findindex(&area_iter->regionbase, region) != -1) {
6898 area = area_iter;
6899 break;
6900 }
6901 }
6902 if (area == nullptr) {
6903 return;
6904 }
6905
6906 /* Keep as-is. */
6908 return;
6909 }
6910 if (ELEM(region->regiontype,
6916 RGN_TYPE_HUD))
6917 {
6918 return;
6919 }
6920 /* Fall back to window. */
6923 }
6924
6925 /* Detect changes to the state. */
6926 {
6927 bToolRef *tref = nullptr;
6928 if ((region->regiontype == RGN_TYPE_WINDOW) &&
6929 ((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK))
6930 {
6931 const Scene *scene = WM_window_get_active_scene(win);
6932 ViewLayer *view_layer = WM_window_get_active_view_layer(win);
6933 WorkSpace *workspace = WM_window_get_active_workspace(win);
6934 bToolKey tkey{};
6935 tkey.space_type = area->spacetype;
6937 *bmain, scene, view_layer, area, area->spacetype);
6938 tref = WM_toolsystem_ref_find(workspace, &tkey);
6939 }
6941 &cd->state, win->runtime->eventstate, area->spacetype, region->regiontype, tref);
6942 if (memcmp(&cd->state, &cd_prev.state, sizeof(cd->state)) == 0) {
6943 return;
6944 }
6945 }
6946
6947 /* Changed context found, detect changes to key-map and refresh the status bar. */
6948 const struct {
6949 int button_index;
6950 int type_index; /* 0: press or click, 1: drag. */
6951 wmEventType event_type;
6952 int event_value;
6953 } event_data[] = {
6954 {0, 0, LEFTMOUSE, KM_PRESS},
6955 {0, 0, LEFTMOUSE, KM_CLICK},
6956 {0, 0, LEFTMOUSE, KM_PRESS_DRAG},
6957
6958 {1, 0, MIDDLEMOUSE, KM_PRESS},
6959 {1, 0, MIDDLEMOUSE, KM_CLICK},
6960 {1, 0, MIDDLEMOUSE, KM_PRESS_DRAG},
6961
6962 {2, 0, RIGHTMOUSE, KM_PRESS},
6963 {2, 0, RIGHTMOUSE, KM_CLICK},
6964 {2, 0, RIGHTMOUSE, KM_PRESS_DRAG},
6965 };
6966
6967 for (int button_index = 0; button_index < 3; button_index++) {
6968 cd->text[button_index][0][0] = '\0';
6969 cd->text[button_index][1][0] = '\0';
6970 }
6971
6972 CTX_wm_window_set(C, win);
6973 CTX_wm_area_set(C, area);
6974 CTX_wm_region_set(C, region);
6975
6976 ListBaseT<wmEventHandler> *handlers[] = {
6977 &region->runtime->handlers,
6978 &area->handlers,
6979 &win->runtime->handlers,
6980 };
6981
6983 for (int data_index = 0; data_index < ARRAY_SIZE(event_data); data_index++) {
6984 const int button_index = event_data[data_index].button_index;
6985 const int type_index = event_data[data_index].type_index;
6986 if (cd->text[button_index][type_index][0] != 0) {
6987 continue;
6988 }
6989 wmEvent test_event = *win->runtime->eventstate;
6990 test_event.type = event_data[data_index].event_type;
6991 test_event.val = event_data[data_index].event_value;
6992 test_event.flag = eWM_EventFlag(0);
6993 wm_eventemulation(&test_event, true);
6994 wmKeyMapItem *kmi = nullptr;
6995 for (int handler_index = 0; handler_index < ARRAY_SIZE(handlers); handler_index++) {
6997 C, wm, win, handlers[handler_index], &test_event);
6998 if (kmi) {
6999 break;
7000 }
7001 }
7002 if (kmi) {
7003 wmOperatorType *ot = WM_operatortype_find(kmi->idname, false);
7004 std::string name;
7005
7006 if (kmi->type == RIGHTMOUSE && kmi->val == KM_PRESS &&
7007 STR_ELEM(kmi->idname, "WM_OT_call_menu", "WM_OT_call_menu_pie", "WM_OT_call_panel"))
7008 {
7009 name = IFACE_("Options");
7010 }
7011 else if (ot) {
7012 /* Skip internal operators. */
7013 if (ot->flag & OPTYPE_INTERNAL) {
7014 continue;
7015 }
7016 name = WM_operatortype_name(ot, kmi->ptr);
7017 }
7018 else {
7019 name = kmi->idname;
7020 }
7021
7022 STRNCPY(cd->text[button_index][type_index], name.c_str());
7023 }
7024 }
7025
7026 if (memcmp(&cd_prev.text, &cd->text, sizeof(cd_prev.text)) != 0) {
7027 ED_area_tag_redraw(area_statusbar);
7028 }
7029
7030 CTX_wm_window_set(C, nullptr);
7031}
7032
7034
7035/* -------------------------------------------------------------------- */
7038
7040{
7042 wmKeyMap *keymap = nullptr;
7043 wmOperator *op = nullptr;
7044 for (wmEventHandler &handler_base : win->runtime->modalhandlers) {
7045 if (handler_base.type == WM_HANDLER_TYPE_OP) {
7046 wmEventHandler_Op *handler = reinterpret_cast<wmEventHandler_Op *>(&handler_base);
7047 if (handler->op != nullptr) {
7048 /* 'handler->keymap' could be checked too, seems not to be used. */
7049 wmOperator *op_test = handler->op->opm ? handler->op->opm : handler->op;
7050 wmKeyMap *keymap_test = WM_keymap_active(wm, op_test->type->modalkeymap);
7051 if (keymap_test && keymap_test->modal_items) {
7052 keymap = keymap_test;
7053 op = op_test;
7054 break;
7055 }
7056 }
7057 }
7058 }
7059 if (keymap == nullptr || keymap->modal_items == nullptr) {
7060 return false;
7061 }
7062 const EnumPropertyItem *items = static_cast<const EnumPropertyItem *>(keymap->modal_items);
7063
7064 ui::Layout &row = layout.row(true);
7065 for (int i = 0; items[i].identifier; i++) {
7066 if (!items[i].identifier[0]) {
7067 continue;
7068 }
7069 if ((keymap->poll_modal_item != nullptr) &&
7070 (keymap->poll_modal_item(op, items[i].value) == false))
7071 {
7072 continue;
7073 }
7074
7075 const int num_items_used = template_status_bar_modal_item(&row, op, keymap, items + i);
7076 if (num_items_used > 0) {
7077 /* Skip items in case consecutive items were merged. */
7078 i += num_items_used - 1;
7079 }
7080 else if (std::optional<std::string> str = WM_modalkeymap_operator_items_to_string(
7081 op->type, items[i].value, true))
7082 {
7083 /* Show text instead. */
7084 row.label(fmt::format("{}: {}", *str, items[i].name), ICON_NONE);
7085 }
7086 }
7087 return true;
7088}
7089
7091
7092} // namespace blender
Main runtime representation of an asset.
CustomData interface, see also DNA_customdata_types.h.
#define G_MAIN
#define UINT64_MAX
#define STR_ELEM(...)
#define STRNCPY_UTF8(dst, src)
#define RPT_(msgid)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define CTX_RPT_(context, msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
bool CLG_quiet_get()
Definition clog.cc:942
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
@ CLG_LEVEL_DEBUG
Definition CLG_log.h:62
@ CLG_LEVEL_INFO
Definition CLG_log.h:60
#define CLOG_AT_LEVEL(clg_ref, verbose_level,...)
Definition CLG_log.h:150
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
These structs are the foundation for all linked lists in the library system.
#define RGN_TYPE_ANY
#define RGN_TYPE_IS_HEADER_ANY(regiontype)
#define OPERATOR_RETVAL_CHECK(ret)
#define ED_screen_areas_iter(win, screen, area_name)
Definition ED_screen.hh:322
@ GHOST_kEventWheelAxisVertical
@ GHOST_kTrackpadEventMagnify
@ GHOST_kTrackpadEventSmartMagnify
@ GHOST_kTrackpadEventRotate
@ GHOST_kTrackpadEventScroll
GHOST_NDOF_ButtonT
GHOST_TEventType
@ GHOST_kEventWheel
@ GHOST_kEventImeComposition
@ GHOST_kEventCursorMove
@ GHOST_kEventButtonUp
@ GHOST_kEventTrackpad
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventButtonDown
@ GHOST_kEventKeyDown
@ GHOST_kEventImeCompositionStart
@ GHOST_kEventImeCompositionEnd
@ GHOST_kEventUnknown
@ GHOST_kEventKeyUp
@ GHOST_kTabletModeNone
GHOST_TKey
@ GHOST_kKeyLeftOS
@ GHOST_kKeyInsert
@ GHOST_kKeySemicolon
@ GHOST_kKeyMediaPlay
@ GHOST_kKeyZ
@ GHOST_kKeyQuote
@ GHOST_kKeyAccentGrave
@ GHOST_kKeyLeftAlt
@ GHOST_kKeyRightShift
@ GHOST_kKeyNumLock
@ GHOST_kKeyEnter
@ GHOST_kKeyNumpadSlash
@ GHOST_kKeyRightArrow
@ GHOST_kKeyF24
@ GHOST_kKeyPause
@ GHOST_kKeyCapsLock
@ GHOST_kKeyApp
@ GHOST_kKeyMinus
@ GHOST_kKeyMediaStop
@ GHOST_kKeyBackSpace
@ GHOST_kKey0
@ GHOST_kKeyDownPage
@ GHOST_kKeyGrLess
@ GHOST_kKeyDownArrow
@ GHOST_kKeyRightOS
@ GHOST_kKeyClear
@ GHOST_kKeyNumpadPeriod
@ GHOST_kKeyF1
@ GHOST_kKeyNumpadAsterisk
@ GHOST_kKeyPrintScreen
@ GHOST_kKeyLeftControl
@ GHOST_kKeyLeftBracket
@ GHOST_kKeyTab
@ GHOST_kKeyComma
@ GHOST_kKeyRightBracket
@ GHOST_kKeyBackslash
@ GHOST_kKeyLinefeed
@ GHOST_kKeyLeftHyper
@ GHOST_kKeyRightAlt
@ GHOST_kKeyPeriod
@ GHOST_kKeyNumpadPlus
@ GHOST_kKeyUpPage
@ GHOST_kKey9
@ GHOST_kKeyLeftArrow
@ GHOST_kKeyEqual
@ GHOST_kKeyHome
@ GHOST_kKeyNumpad9
@ GHOST_kKeyEnd
@ GHOST_kKeyUpArrow
@ GHOST_kKeyDelete
@ GHOST_kKeyNumpad0
@ GHOST_kKeyA
@ GHOST_kKeyMediaFirst
@ GHOST_kKeyRightControl
@ GHOST_kKeyEsc
@ GHOST_kKeyPlus
@ GHOST_kKeyUnknown
@ GHOST_kKeyScrollLock
@ GHOST_kKeySlash
@ GHOST_kKeyNumpadEnter
@ GHOST_kKeyNumpadMinus
@ GHOST_kKeyRightHyper
@ GHOST_kKeyLeftShift
@ GHOST_kKeyMediaLast
@ GHOST_kKeySpace
#define GHOST_kNumEventTypes
GHOST_TButton
@ GHOST_kButtonMaskRight
@ GHOST_kButtonMaskButton4
@ GHOST_kButtonMaskNone
@ GHOST_kButtonMaskLeft
@ GHOST_kButtonMaskButton7
@ GHOST_kButtonMaskButton6
@ GHOST_kButtonMaskButton5
@ GHOST_kButtonMaskMiddle
Read Blender memory allocation and freeing.
#define PRF_scope_with_name(ui_name, category)
#define PRF_scope(category)
#define PRF_scope_set_dynamic_name(fmt,...)
#define RNA_STRUCT_BEGIN(sptr, prop)
#define RNA_STRUCT_END
#define C
Definition RandGen.cpp:29
#define UI_MARKER_MARGIN_Y
Definition UI_view2d.hh:492
#define WM_TOOLSYSTEM_SPACE_MASK
#define ND_ASSET_LIST_READING
Definition WM_types.hh:593
#define ND_PROJECT_CHANGED
Definition WM_types.hh:436
#define NC_NODE
Definition WM_types.hh:407
#define ND_FILEREAD
Definition WM_types.hh:428
#define NC_GEOM
Definition WM_types.hh:406
#define WM_UI_HANDLER_CONTINUE
Definition WM_types.hh:361
#define ND_SPACE_INFO
Definition WM_types.hh:564
#define NC_WM
Definition WM_types.hh:387
#define WM_OP_CONTEXT_HAS_AREA(type)
Definition WM_types.hh:268
#define NOTE_ACTION
Definition WM_types.hh:633
#define ND_DATACHANGED
Definition WM_types.hh:430
#define NC_SCREEN
Definition WM_types.hh:390
#define NC_SCENE
Definition WM_types.hh:391
#define ND_WORKSPACE_DELETE
Definition WM_types.hh:446
#define NOTE_DATA
Definition WM_types.hh:425
#define ND_SPACE_INFO_REPORT
Definition WM_types.hh:563
#define ND_UNDO
Definition WM_types.hh:433
#define WM_EVENT_CURSOR_MOTION_THRESHOLD
Definition WM_types.hh:904
#define ND_FRAME
Definition WM_types.hh:453
#define NC_ASSET
Definition WM_types.hh:417
#define NOTE_SUBTYPE
Definition WM_types.hh:607
#define ND_FILESAVE
Definition WM_types.hh:429
#define ND_ASSET_LIST
Definition WM_types.hh:591
#define ND_WORKSPACE_SET
Definition WM_types.hh:445
#define NOTE_CATEGORY
Definition WM_types.hh:385
#define ND_LAYOUTBROWSE
Definition WM_types.hh:439
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_LAYOUTDELETE
Definition WM_types.hh:440
#define NOTE_CATEGORY_TAG_CLEARED
Definition WM_types.hh:386
#define ND_NODE_ASSET_DATA
Definition WM_types.hh:558
#define WM_UI_HANDLER_BREAK
Definition WM_types.hh:362
#define NC_SPACE
Definition WM_types.hh:405
#define KM_MOD_HELD
Definition WM_types.hh:339
volatile int lock
#define U
#define UNPACK2(a)
#define BLI_assert_unreachable()
#define BLI_STATIC_ASSERT(a, msg)
#define UNUSED_VARS_NDEBUG(...)
#define BLI_INLINE
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLI_assert(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
@ NONE
unsigned long long int uint64_t
#define PRINT(format,...)
Definition cache.cc:36
static GHOST_ISystem * getSystem()
void iter(FunctionRef< void(ID *old_id, ID *new_id)> func) const
constexpr bool is_empty() const
#define str(s)
const int state
#define SET(a, b, c, d, k, s, Ti)
ENUM_OPERATORS(Layer::Flags)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void storage_id_remap(ID *id_old, ID *id_new)
void register_node_group_operators(const bContext &C)
BLI_INLINE Texture * wrap(MTLTexture *texture)
void ED_area_type_hud_clear(wmWindowManager *wm, ScrArea *area_keep)
Block * region_block_find_mouse_over(const ARegion *region, const int xy[2], bool only_clip)
void popup_handlers_remove_all(bContext *C, ListBaseT< wmEventHandler > *handlers)
bool popup_region_from_operator(const bScreen *screen, const ARegion *region)
void popup_menu_reports(bContext *C, ReportList *reports) ATTR_NONNULL()
void ED_area_type_hud_ensure(bContext *C, ScrArea *area)
BMesh Iterators.
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:89
void WM_main_add_notifier(uint type, void *reference)
void WM_event_set_keymap_handler_post_callback(wmEventHandler_Keymap *handler, void(keymap_tag)(wmKeyMap *keymap, wmKeyMapItem *kmi, void *user_data), void *user_data)
void ED_workspace_do_listen(bContext *C, const wmNotifier *note)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool WM_event_match(const wmEvent *winevent, const wmKeyMapItem *kmi)
UserDef U
Definition blender.cc:58
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
bool WM_event_consecutive_gesture_test(const wmEvent *event)
bool wm_gizmomap_highlight_pending(const wmGizmoMap *gzmap)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ARegion * BKE_area_find_region_active_win(const ScrArea *area)
Definition screen.cc:1037
void wm_stereo3d_mouse_offset_apply(wmWindow *win, int r_mouse_xy[2])
Definition wm_stereo.cc:166
static void wm_event_prev_click_set(uint64_t event_time_ms, wmEvent *event_state, uint64_t *r_event_state_prev_press_time_ms)
void WM_global_reportf(eReportType type, const char *format,...)
static std::string keymap_handler_log_kmi_op_str(bContext *C, const wmKeyMapItem *kmi)
wmKeyMap * WM_keymap_list_find_spaceid_or_empty(ListBaseT< wmKeyMap > *lb, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:919
unsigned __int64 uint64_t
Definition BKE_text.h:91
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
ScrArea * CTX_wm_area(const bContext *C)
void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:705
static eHandlerActionFlag wm_handlers_do_gizmo_handler(bContext *C, wmWindowManager *wm, wmEventHandler_Gizmo *handler, wmEvent *event, const bool always_pass, ListBaseT< wmEventHandler > *handlers, const bool do_debug_handler)
void WM_report_banner_show(wmWindowManager *wm, wmWindow *win)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
char * STRNCPY(char(&dst)[N], const char *src)
void WM_operator_free(wmOperator *op)
Definition wm.cc:277
void WM_msg_id_update(wmMsgBus *mbus, ID *id_src, ID *id_dst)
void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2])
const ListBaseT< wmGizmoGroup > * WM_gizmomap_group_list(wmGizmoMap *gzmap)
void WM_main_remove_notifier_reference(const void *reference)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
static void wm_event_free_and_remove_from_queue_if_valid(wmEvent *event)
@ RPT_OPERATOR
Definition BKE_report.hh:38
@ RPT_WARNING
Definition BKE_report.hh:40
void ED_preview_restart_work(const bContext *C)
Scene * CTX_data_sequencer_scene(const bContext *C)
size_t BLI_str_utf8_from_unicode(unsigned int c, char *dst, size_t dst_maxncpy) ATTR_NONNULL(2)
static bool wm_action_not_handled(const eHandlerActionFlag action)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
wmDragAsset * WM_drag_get_asset_data(const wmDrag *drag, int idcode)
static void wm_event_free_last_handled(wmWindow *win, wmEvent *event)
void wm_drags_exit(wmWindowManager *wm, wmWindow *win)
bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
Definition wm_keymap.cc:485
void wm_event_free(wmEvent *event)
ListBaseT< TimeMarker > * ED_scene_markers_get_from_area(const Main &bmain, Scene *scene, ViewLayer *view_layer, const ScrArea *area)
unsigned int uint
Definition BKE_text.h:55
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
void * BLI_poptail(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:268
void ED_region_do_listen(wmRegionListenerParams *params)
Definition area.cc:102
static ScrArea * area_event_inside(bContext *C, const int xy[2])
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
ARegionDrawLockFlags
@ REGION_DRAW_LOCK_ALL
void BKE_report_print_level_set(ReportList *reports, eReportType level)
Definition report.cc:276
bool WM_operator_poll_or_report_error(bContext *C, wmOperatorType *ot, ReportList *reports)
@ RGN_TYPE_ASSET_SHELF_HEADER
@ EVT_DATA_NDOF_MOTION
wmEventHandler_UI * WM_event_add_ui_handler(const bContext *C, ListBaseT< wmEventHandler > *handlers, wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn, void *user_data, const eWM_EventHandlerFlag flag)
eWM_CursorWrapAxis
Definition WM_types.hh:238
@ WM_CURSOR_WRAP_Y
Definition WM_types.hh:241
@ WM_CURSOR_WRAP_X
Definition WM_types.hh:240
@ WM_CURSOR_WRAP_NONE
Definition WM_types.hh:239
@ WM_CURSOR_WRAP_XY
Definition WM_types.hh:242
wmOperator * WM_operator_find_modal_by_type(wmWindow *win, const wmOperatorType *ot)
ScrArea * WM_window_status_area_find(wmWindow *win, bScreen *screen)
wmKeyMapItem * WM_event_match_keymap_item(bContext *C, wmKeyMap *keymap, const wmEvent *event)
bool WM_window_modal_keymap_status_draw(bContext *C, wmWindow *win, ui::Layout &layout)
void wm_drop_end(bContext *C, wmDrag *, wmDropBox *)
void WM_operator_properties_free(PointerRNA *ptr)
static void wm_event_handler_ui_cancel(bContext *C)
int WM_toolsystem_mode_from_spacetype(const Main &bmain, const Scene *scene, ViewLayer *view_layer, ScrArea *area, int space_type)
void BKE_spacedata_draw_locks(ARegionDrawLockFlags lock_flags)
Definition screen.cc:558
bool wm_gizmogroup_is_any_selected(const wmGizmoGroup *gzgroup)
bool ED_undo_is_state_valid(bContext *C)
Definition ed_undo.cc:68
static bool wm_event_pie_filter(wmWindow *win, const wmEvent *event)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
static bool wm_notifier_is_clear(const wmNotifier *note)
const char * RNA_property_identifier(const PropertyRNA *prop)
static eHandlerActionFlag wm_handler_ui_call(bContext *C, wmEventHandler_UI *handler, const wmEvent *event, const bool always_pass)
static wmOperatorStatus wm_operator_exec_notest(bContext *C, wmOperator *op)
static wmOperatorStatus wm_operator_exec(bContext *C, wmOperator *op, const bool repeat, const bool store)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
static bool wm_event_inside_rect(const wmEvent *event, const rcti *rect)
static bool wm_operator_check_locked_interface(bContext *C, wmOperatorType *ot)
bool WM_region_use_viewport(ScrArea *area, ARegion *region)
Definition wm_draw.cc:585
wmEventHandler_Keymap * WM_event_add_keymap_handler_dynamic(ListBaseT< wmEventHandler > *handlers, wmEventHandler_KeymapDynamicFn keymap_fn, void *user_data)
wmOperatorStatus WM_operator_call(bContext *C, wmOperator *op)
void CTX_wm_window_set(bContext *C, wmWindow *win)
static wmEvent * wm_event_add_mousemove_to_head(wmWindow *win)
WorkSpaceLayout * WM_window_get_active_layout(const wmWindow *win)
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
static wmEventType wm_event_type_from_ghost_button(const GHOST_TButton button, const wmEventType fallback)
void ED_area_prevspace(bContext *C, ScrArea *area)
Definition area.cc:3111
void WM_cursor_modal_set(wmWindow *win, int val)
AZone * ED_area_azones_update(ScrArea *area, const int mouse_xy[2])
bool ED_markers_region_visible(const ScrArea *area, const ARegion *region)
void WM_keyconfig_update(wmWindowManager *wm)
bContext * WM_xr_session_context_get(const wmXrData *xr)
void wm_drop_prepare(bContext *C, wmDrag *drag, wmDropBox *drop)
static void wm_event_get_keymap_from_toolsystem_ex(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result, const bool with_gizmos)
static eHandlerActionFlag wm_handler_operator_call(bContext *C, ListBaseT< wmEventHandler > *handlers, wmEventHandler *handler_base, wmEvent *event, PointerRNA *properties, const char *kmi_idname)
static void wm_event_cursor_store(CursorKeymapInfo_State *state, const wmEvent *event, short space_type, short region_type, const bToolRef *tref)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
bToolRef * WM_toolsystem_ref_find(WorkSpace *workspace, const bToolKey *tkey)
static wmOperator * wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, PointerRNA *properties, ReportList *reports)
static bool wm_event_is_same_key_press(const wmEvent &event_a, const wmEvent &event_b)
static wmWindow * wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *win, wmEvent *event)
CLG_LogRef * WM_LOG_EVENTS
void WM_event_consecutive_data_set(wmWindow *win, const char *id, void *custom_data)
wmOperatorStatus WM_operator_call_notest(bContext *C, wmOperator *op)
int(*)(bContext *C, const wmEvent *event, void *userdata) wmUIHandlerFunc
Definition WM_api.hh:823
MINLINE int len_manhattan_v2v2_int(const int a[2], const int b[2]) ATTR_WARN_UNUSED_RESULT
void WM_event_print(const wmEvent *event)
wmWindow * CTX_wm_window(const bContext *C)
void WM_window_set_active_workspace(bContext *C, wmWindow *win, WorkSpace *workspace)
void BKE_reports_move_to_reports(ReportList *reports_dst, ReportList *reports_src)
Definition report.cc:150
static void wm_paintcursor_tag(bContext *C, wmWindowManager *wm, ARegion *region)
void BKE_reports_clear(ReportList *reports)
Definition report.cc:118
void GPU_render_begin()
constexpr wmTabletData wm_event_tablet_data_default()
wmGizmoGroupType * WM_gizmogrouptype_find(const StringRef idname, bool quiet)
void DEG_make_active(Depsgraph *depsgraph)
Definition depsgraph.cc:337
void wm_test_autorun_warning(bContext *C)
Definition wm_files.cc:4724
static void wm_paintcursor_test(bContext *C, const wmEvent *event)
void wm_event_do_notifiers(bContext *C)
void WM_tooltip_clear(bContext *C, wmWindow *win)
Definition wm_tooltip.cc:84
static wmEvent * wm_event_add_trackpad(wmWindow *win, const wmEvent *event, int deltax, int deltay)
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:553
static eHandlerActionFlag wm_handlers_do_intern(bContext *C, wmWindow *win, wmEvent *event, ListBaseT< wmEventHandler > *handlers)
void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap)
void WM_report_banners_cancel(Main *bmain)
@ TOOLREF_FLAG_FALLBACK_KEYMAP
void WM_msgbus_handle(wmMsgBus *mbus, bContext *C)
void(*)(bContext *C, void *userdata) wmUIHandlerRemoveFunc
Definition WM_api.hh:824
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
bool WM_gizmomap_tag_delay_refresh_for_tweak_check(wmGizmoMap *gzmap)
static void wm_event_state_update_and_click_set_ex(wmEvent *event, uint64_t event_time_ms, wmEvent *event_state, uint64_t *event_state_prev_press_time_ms_p, const bool is_keyboard, const bool check_double_click)
std::string WM_operator_pystring(bContext *C, wmOperator *op, const bool all_args, const bool macro_args)
void WM_event_free_ui_handler_all(bContext *C, ListBaseT< wmEventHandler > *handlers, wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn)
void MEM_delete_void(void *vmemh)
constexpr std::enable_if_t< blenlib_internal::IsBoundedArray< T >::value, size_t > BOUNDED_ARRAY_TYPE_SIZE() noexcept
void WM_tooltip_timer_init(bContext *C, wmWindow *win, ScrArea *area, ARegion *region, wmTooltipInitFn init)
Definition wm_tooltip.cc:66
ScrArea * ED_fileselect_handler_area_find(const wmWindow *win, const wmOperator *file_operator)
Definition filesel.cc:1480
static wmWindow * wm_event_find_fileselect_root_window_from_context(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
static eHandlerActionFlag wm_handlers_do_keymap_with_gizmo_handler(bContext *C, wmEvent *event, ListBaseT< wmEventHandler > *handlers, wmEventHandler_Gizmo *handler, wmGizmoGroup *gzgroup, wmKeyMap *keymap, const bool do_debug_handler, bool *r_keymap_poll)
bool(*)(const wmWindow *win, const ScrArea *area, const ARegion *region, const wmEvent *event) EventHandlerPoll
Definition WM_api.hh:719
wmEventModifierFlag
Definition WM_types.hh:290
void * WM_event_consecutive_data_get(wmWindow *win, const char *id)
void DEG_tag_on_visible_update(Main *bmain, bool do_time)
bool wm_gizmomap_highlight_handled(wmGizmoMap *gzmap)
@ EVT_FILESELECT_FULL_OPEN
@ EVT_FILESELECT_EXTERNAL_CANCEL
@ EVT_FILESELECT_CANCEL
void wm_event_free_all(wmWindow *win)
void wm_cursor_position_from_ghost_screen_coords(wmWindow *win, int *x, int *y)
@ INBETWEEN_MOUSEMOVE
@ WM_IME_COMPOSITE_END
@ WM_IME_COMPOSITE_START
@ WM_IME_COMPOSITE_EVENT
@ G_DEBUG_HANDLERS
@ G_DEBUG_EVENTS
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
void wm_tablet_data_from_ghost(const GHOST_TabletData *tablet_data, wmTabletData *wmtab)
Global G
Definition blender.cc:57
const bContextStore * CTX_store_get(const bContext *C)
bool WM_operator_name_poll(bContext *C, const char *opstring)
wmOperatorStatus WM_operator_call_py(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, ReportList *reports, const bool is_undo)
void ED_undo_grouped_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:561
void WM_locked_interface_set(wmWindowManager *wm, bool lock)
PropertyType RNA_property_type(PropertyRNA *prop)
static bool notifier_refreshes_node_group_operators(const wmNotifier &note)
void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area, ScrArea *new_area)
wmOperatorStatus WM_operator_call_ex(bContext *C, wmOperator *op, const bool store)
int WM_event_drag_direction(const wmEvent *event)
wmGizmo * wm_gizmomap_highlight_find(wmGizmoMap *gzmap, bContext *C, const wmEvent *event, int *r_part)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void WM_locked_interface_set_with_flags(wmWindowManager *wm, short lock_flags)
@ WM_EVENT_SCROLL_INVERT
Definition WM_types.hh:737
@ WM_EVENT_FORCE_DRAG_THRESHOLD
Definition WM_types.hh:757
@ WM_EVENT_IS_CONSECUTIVE
Definition WM_types.hh:752
@ WM_EVENT_IS_REPEAT
Definition WM_types.hh:744
void WM_event_remove_handlers(bContext *C, ListBaseT< wmEventHandler > *handlers)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
BLI_INLINE void wm_event_handler_return_value_check(const bContext *C, const wmEvent *event, const eHandlerActionFlag action)
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBaseT< wmEventHandler > *handlers, ListBaseT< wmDropBox > *dropboxes)
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
VecBase< int32_t, 2 > int2
Scene * WM_window_get_active_scene(const wmWindow *win)
VecBase< float, 2 > float2
bool ED_workspace_delete(WorkSpace *workspace, Main *bmain, bContext *C, wmWindowManager *wm) ATTR_NONNULL()
const char * WM_window_cursor_keymap_status_get(const wmWindow *win, int button_index, int type_index)
bool WM_operator_depends_on_cursor(bContext &C, wmOperatorType &ot, PointerRNA *properties)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
unsigned char uchar
Definition BKE_text.h:58
void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type, const void *customdata, const uint64_t event_time_ms)
@ PROP_STRING
Definition RNA_types.hh:213
bool WM_event_drag_test(const wmEvent *event, const int prev_xy[2])
void GPU_render_end()
void ED_fileselect_params_to_userdef(SpaceFile *sfile)
Definition filesel.cc:723
static void wm_operator_reports(bContext *C, wmOperator *op, const wmOperatorStatus retval, const bool caller_owns_reports)
void WM_cursor_grab_enable(wmWindow *win, const eWM_CursorWrapAxis wrap, const rcti *wrap_region, const bool hide)
static eHandlerActionFlag wm_handlers_do_keymap_with_keymap_handler(bContext *C, wmEvent *event, ListBaseT< wmEventHandler > *handlers, wmEventHandler_Keymap *handler, wmKeyMap *keymap, const bool do_debug_handler)
void wm_surfaces_do_depsgraph(bContext *C)
Definition wm_surface.cc:65
void WM_tooltip_init(bContext *C, wmWindow *win)
Definition wm_tooltip.cc:99
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void WM_main_remap_editor_id_reference(const bke::id::IDRemapper &mappings)
wmKeyMapItem * WM_event_match_keymap_item_from_handlers(bContext *C, wmWindowManager *wm, wmWindow *win, ListBaseT< wmEventHandler > *handlers, const wmEvent *event)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
eWM_EventHandlerFlag
Definition WM_api.hh:707
@ WM_HANDLER_DO_FREE
Definition WM_api.hh:715
@ WM_HANDLER_ACCEPT_DBL_CLICK
Definition WM_api.hh:711
@ WM_HANDLER_BLOCKING
Definition WM_api.hh:709
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
std::string RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, const bool as_function, const bool all_args, const bool nested_args, const int max_prop_length)
static bool event_or_prev_in_rect(const wmEvent *event, const rcti *rect)
void WM_event_remove_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
static void wm_event_timers_execute(bContext *C)
wmEventHandler_Keymap * WM_event_add_keymap_handler_v2d_mask(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
void ED_spacedata_id_remap(ScrArea *area, SpaceLink *sl, const bke::id::IDRemapper &mappings)
Definition ed_util.cc:452
wmWindowManager * CTX_wm_manager(const bContext *C)
void WM_event_tablet_data_default_set(wmTabletData *tablet_data)
wmOperatorStatus WM_operator_repeat(bContext *C, wmOperator *op)
static void wm_region_tag_draw_on_gizmo_delay_refresh_for_tweak(wmWindow *win)
static void wm_handler_operator_insert(wmWindow *win, wmEventHandler_Op *handler)
BLI_INLINE bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi)
static ARegion * region_event_inside(bContext *C, const int xy[2])
float wm_pressure_curve(float raw_pressure)
unsigned char uint8_t
Definition BKE_text.h:79
void wm_window_close_request(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:483
static wmEvent * wm_event_add_intern(wmWindow *win, const wmEvent *event_to_add)
void WM_menu_name_call(bContext *C, const char *menu_name, wm::OpCallContext context)
void wm_event_do_depsgraph(bContext *C, bool is_after_open_file)
void ED_area_exit(bContext *C, ScrArea *area)
static void ui_handler_wait_for_input_remove(bContext *C, void *userdata)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
int RNA_property_flag(PropertyRNA *prop)
void WM_window_cursor_keymap_status_free(wmWindow *win)
static void wm_handler_op_context_get_if_valid(bContext *C, wmEventHandler_Op *handler, const wmEvent *event, ScrArea **r_area, ARegion **r_region)
void WM_gizmoconfig_update(Main *bmain)
void WM_window_cursor_keymap_status_refresh(bContext *C, wmWindow *win)
void WM_cursor_modal_restore(wmWindow *win)
static bool wm_event_always_pass(const wmEvent *event)
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool wm_gizmomap_highlight_set(wmGizmoMap *gzmap, const bContext *C, wmGizmo *gz, int part)
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
void WM_gizmogroup_ensure_init(const bContext *C, wmGizmoGroup *gzgroup)
static const char * keymap_handler_log_action_str(const eHandlerActionFlag action)
bool WM_operator_last_properties_init(wmOperator *op)
static void wm_region_mouse_co(bContext *C, wmEvent *event)
bContext * WM_xr_session_context_ensure(wmXrData *xr, const wmWindowManager *wm)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int WM_userdef_event_map(int kmitype)
static eHandlerActionFlag wm_event_drag_and_drop_test(wmWindowManager *wm, wmWindow *win, wmEvent *event)
void WM_global_report(eReportType type, const char *message)
bool WM_event_handler_region_v2d_mask_no_marker_poll(const wmWindow *win, const ScrArea *area, const ARegion *region, const wmEvent *event)
@ USER_TRACKPAD_SCROLL_DIR_TRADITIONAL
@ USER_TRACKPAD_SCROLL_DIR_NATURAL
void WM_window_status_area_tag_redraw(wmWindow *win)
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
void ED_area_do_refresh(bContext *C, ScrArea *area)
Definition area.cc:148
void WM_event_ui_handler_region_popup_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
void WM_event_get_keymap_from_toolsystem_with_gizmos(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
bool WM_operator_poll_context(bContext *C, wmOperatorType *ot, wm::OpCallContext context)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
static void wm_event_custom_free(wmEvent *event)
const char int BLI_str_utf8_size_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
@ WM_HANDLER_TYPE_DROPBOX
@ WM_HANDLER_TYPE_KEYMAP
@ WM_HANDLER_TYPE_GIZMO
void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
wmEventHandler_Op * WM_event_add_modal_handler_ex(wmWindow *win, ScrArea *area, ARegion *region, wmOperator *op)
ScrArea * ED_screen_temp_space_open(bContext *C, const char *title, eSpace_Type space_type, int display_type, bool dialog) ATTR_NONNULL(1)
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
static wmOperatorStatus wm_operator_invoke(bContext *C, wmOperatorType *ot, const wmEvent *event, PointerRNA *properties, ReportList *reports, const bool poll_only, bool use_last_properties)
char * IDP_reprN(const IDProperty *prop, uint *r_len)
CLG_LogRef * WM_LOG_OPERATORS
static intptr_t wm_operator_undo_active_id(const wmWindowManager *wm)
void WM_event_fileselect_event(wmWindowManager *wm, void *ophandle, const int eventval)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_operator_region_active_win_set(bContext *C)
wmGizmo * wm_gizmomap_modal_get(wmGizmoMap *gzmap)
bool WM_event_modifier_flag_match_kmi_press(const wmEventModifierFlag event_modifier, const wmKeyMapItem *kmi)
bool WM_event_handler_region_marker_poll(const wmWindow *win, const ScrArea *area, const ARegion *region, const wmEvent *event)
static void wm_event_modalkeymap_end(wmEvent *event, const wmEvent_ModalMapStore *event_backup)
static bool wm_event_is_ignorable_key_press(const wmWindow *win, const wmEvent &event)
@ SCE_WORKSPACE_TOOL_FALLBACK
wm::OpCallContext wm_drop_operator_context_get(const wmDropBox *)
wmEventHandler_Keymap * WM_event_add_keymap_handler_poll(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap, EventHandlerPoll poll)
@ KM_TEXTINPUT
Definition WM_types.hh:317
static eHandlerActionFlag wm_event_do_handlers_area_regions(bContext *C, wmEvent *event, ScrArea *area)
void WM_event_remove_modal_handler(ListBaseT< wmEventHandler > *handlers, const wmOperator *op, const bool postpone)
std::optional< std::string > WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
@ WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP
@ WM_GIZMOGROUPTYPE_TOOL_INIT
void AS_asset_library_remap_ids(const bke::id::IDRemapper &mappings)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
@ WM_GIZMO_OPERATOR_TOOL_INIT
@ WM_GIZMO_NO_TOOLTIP
@ WM_GIZMO_EVENT_HANDLE_ALL
@ WM_GIZMO_HIDDEN_KEYMAP
@ WM_CAPABILITY_TRACKPAD_PHYSICAL_DIRECTION
Definition WM_api.hh:241
@ WM_CAPABILITY_WINDOW_POSITION
Definition WM_api.hh:222
void wm_gizmomap_handler_context_gizmo(bContext *, wmEventHandler_Gizmo *)
wmEvent * WM_event_add(wmWindow *win, const wmEvent *event_to_add)
void wm_test_foreign_file_warning(bContext *C)
Definition wm_files.cc:4754
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
PropertySubType RNA_property_subtype(PropertyRNA *prop)
wmOperatorStatus WM_operator_name_call_with_properties(bContext *C, const char *opstring, wm::OpCallContext context, IDProperty *properties, const wmEvent *event)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_toolsystem_ref_properties_init_for_keymap(bToolRef *tref, PointerRNA *dst_ptr, PointerRNA *src_ptr, wmOperatorType *ot)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void(*)(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result) wmEventHandler_KeymapDynamicFn
Definition WM_api.hh:773
void WM_msg_id_remove(wmMsgBus *mbus, const ID *id)
void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
static void wm_operator_finished(bContext *C, wmOperator *op, const bool repeat, const bool store, const bool has_undo_step, const bool has_register)
void ED_fileselect_set_params_from_userdef(SpaceFile *sfile)
Definition filesel.cc:688
static void wm_event_free_last(wmWindow *win)
ARegion * ED_area_find_region_xy_visual(const ScrArea *area, int regiontype, const int event_xy[2])
void WM_event_handling_break(const bContext &C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
wmOperatorStatus WM_operator_type_call_ptr_with_reports(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, ReportList *reports, const wmEvent *event)
@ USER_TEMP_SPACE_DISPLAY_WINDOW
static void wm_event_modalkeymap_begin(const bContext *C, wmOperator *op, wmEvent *event, wmEvent_ModalMapStore *event_backup)
void ED_screen_full_prevspace(bContext *C, ScrArea *area)
static void wm_event_add_notifier_intern(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void ED_info_stats_clear(wmWindowManager *wm, ViewLayer *view_layer)
@ G_FLAG_EVENT_SIMULATE
Main * CTX_data_main(const bContext *C)
void WM_reports_from_reports_move(wmWindowManager *wm, ReportList *reports)
static std::optional< std::string > keymap_handler_log_kmi_event_str(const wmKeyMapItem *kmi)
bToolRef * WM_toolsystem_ref_from_context(const bContext *C)
void WM_event_consecutive_data_free(wmWindow *win)
static bool wm_event_is_double_click(const wmEvent *event, const uint64_t event_time_ms, const uint64_t event_prev_press_time_ms)
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
void wm_test_gpu_backend_fallback(bContext *C)
int2 WM_window_native_pixel_size(const wmWindow *win)
void BLI_timer_execute()
Definition BLI_timer.cc:120
eWM_CapabilitiesFlag WM_capabilities_flag()
bScreen * BKE_workspace_layout_screen_get(const WorkSpaceLayout *layout) GETTER_ATTRS
Definition workspace.cc:709
void WM_window_title_refresh(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:718
void WM_event_remove_ui_handler(ListBaseT< wmEventHandler > *handlers, wmUIHandlerFunc handle_fn, wmUIHandlerRemoveFunc remove_fn, void *user_data, const bool postpone)
wmEventHandler_Keymap * WM_event_add_keymap_handler_priority(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap, int)
bool WM_gizmo_group_type_ensure_ptr_ex(wmGizmoGroupType *gzgt, wmGizmoMapType *gzmap_type)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
@ PROP_HIDDEN
Definition RNA_types.hh:408
ARegion * CTX_wm_region_popup(const bContext *C)
wmGizmoMapType * WM_gizmomaptype_ensure(const wmGizmoMapType_Params *gzmap_params)
void DEG_graph_relations_update(Depsgraph *graph)
wmOperator * WM_operator_last_redo(const bContext *C)
wmGizmoGroup * WM_gizmomap_group_find(wmGizmoMap *gzmap, const char *idname)
void wm_operator_register(bContext *C, wmOperator *op)
Definition wm.cc:350
bool WM_operator_repeat_check(const bContext *, wmOperator *op)
@ KM_NOTHING
Definition WM_types.hh:323
@ KM_PRESS_DRAG
Definition WM_types.hh:332
@ KM_DBL_CLICK
Definition WM_types.hh:327
@ KM_RELEASE
Definition WM_types.hh:325
void WM_event_remove_handlers_by_area(ListBaseT< wmEventHandler > *handlers, const ScrArea *area)
static void wm_event_state_update_and_click_set(wmEvent *event, uint64_t event_time_ms, wmEvent *event_state, uint64_t *event_state_prev_press_time_ms_p, const GHOST_TEventType type)
static eHandlerActionFlag wm_event_do_region_handlers(bContext *C, wmEvent *event, ARegion *region)
static void wm_event_custom_clear(wmEvent *event)
static wmEventType wm_event_type_from_ghost_key(GHOST_TKey key)
bool ED_screen_change(bContext *C, bScreen *screen)
Change the active screen.
bool BLI_remlink_safe(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:161
bool WM_event_consecutive_gesture_test_break(const wmWindow *win, const wmEvent *event)
bool WM_operator_is_repeat(const bContext *C, const wmOperator *op)
static bool screen_temp_region_exists(const ARegion *region)
Scene * CTX_data_scene(const bContext *C)
std::optional< bool > wm_drag_asset_path_exists(const wmDrag *drag)
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
void CTX_data_main_set(bContext *C, Main *bmain)
void WM_event_modal_handler_region_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
static bool wm_operator_register_check(wmWindowManager *wm, wmOperatorType *ot)
bool WM_operator_ui_poll(wmOperatorType *ot, PointerRNA *ptr)
char char * BLI_vsprintfN(const char *__restrict format, va_list args) ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
void WM_event_get_keymaps_from_handler(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
static wmKeyMapItem * wm_eventmatch_modal_keymap_items(const wmKeyMap *keymap, wmOperator *op, const wmEvent *event)
@ OPTYPE_MODAL_PRIORITY
Definition WM_types.hh:231
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_UNDO_GROUPED
Definition WM_types.hh:215
@ OPTYPE_LOCK_BYPASS
Definition WM_types.hh:213
@ OPTYPE_GRAB_CURSOR_Y
Definition WM_types.hh:200
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:196
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
@ OPTYPE_GRAB_CURSOR_X
Definition WM_types.hh:198
static eHandlerActionFlag wm_handler_fileselect_call(bContext *C, ListBaseT< wmEventHandler > *handlers, wmEventHandler_Op *handler, const wmEvent *event)
void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
void wm_drags_handle_events(bContext *C, const wmEvent *event)
ARegion * WM_gizmomap_tooltip_init(bContext *C, ARegion *region, int *, double *, bool *r_exit_on_event)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
void wm_gizmomaps_handled_modal_update(bContext *C, wmEvent *event, wmEventHandler_Op *handler)
bool WM_event_handler_region_v2d_mask_poll(const wmWindow *, const ScrArea *, const ARegion *region, const wmEvent *event)
@ RPT_OP_HOLD
Definition BKE_report.hh:60
wmGizmo * wm_gizmomap_highlight_get(wmGizmoMap *gzmap)
void CTX_store_set(bContext *C, const bContextStore *store)
@ PROP_FILENAME
Definition RNA_types.hh:286
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_DIRPATH
Definition RNA_types.hh:285
wmEvent * WM_event_add_simulate(wmWindow *win, const wmEvent *event_to_add)
static intptr_t wm_operator_register_active_id(const wmWindowManager *wm)
ScrArea * ED_fileselect_handler_area_find_any_with_op(const wmWindow *win)
Definition filesel.cc:1497
ReportList * CTX_wm_reports(const bContext *C)
std::optional< std::string > WM_modalkeymap_operator_items_to_string(wmOperatorType *ot, const int propvalue, const bool compact)
void WM_event_add_mousemove(wmWindow *win)
static void wm_handler_op_context(bContext *C, wmEventHandler_Op *handler, const wmEvent *event)
ViewLayer * BKE_view_layer_default_render(const Scene *scene)
static void wm_notifier_clear(wmNotifier *note)
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
static void wm_eventemulation(wmEvent *event, bool test_only)
bool WM_operator_last_properties_store(wmOperator *op)
bScreen * WM_window_get_active_screen(const wmWindow *win)
static wmEvent * wm_event_add_mousemove(wmWindow *win, const wmEvent *event)
void ED_view3d_screen_datamask(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const bScreen *screen, CustomData_MeshMasks *r_cddata_masks)
void ED_screen_do_listen(bContext *C, const wmNotifier *note)
bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event)
void CTX_wm_operator_poll_msg_clear(bContext *C)
void CTX_wm_gizmo_group_set(bContext *C, wmGizmoGroup *gzgroup)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
ARegion * CTX_wm_region(const bContext *C)
void WM_drag_free_list(ListBaseT< wmDrag > *lb)
void WM_event_get_keymap_from_toolsystem(wmWindowManager *wm, wmWindow *win, wmEventHandler_Keymap *handler, wmEventHandler_KeymapResult *km_result)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
static void wm_event_prev_values_set(wmEvent *event, wmEvent *event_state)
bool IDP_EqualsProperties(const IDProperty *prop1, const IDProperty *prop2) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:1127
wmGizmoGroup * WM_gizmomaptype_group_init_runtime_with_region(wmGizmoMapType *gzmap_type, wmGizmoGroupType *gzgt, ARegion *region)
static eHandlerActionFlag wm_handlers_do(bContext *C, wmEvent *event, ListBaseT< wmEventHandler > *handlers)
void DEG_graph_tag_on_visible_update(Depsgraph *depsgraph, bool do_time)
bool WM_gizmomap_is_any_selected(const wmGizmoMap *gzmap)
void BKE_reports_log(ReportList *reports, eReportType level, CLG_LogRef *log)
Definition report.cc:354
static int ui_handler_wait_for_input(bContext *C, const wmEvent *event, void *userdata)
wmOperatorStatus WM_operator_repeat_last(bContext *C, wmOperator *op)
bool ED_workspace_layout_delete(WorkSpace *workspace, WorkSpaceLayout *layout_old, bContext *C) ATTR_NONNULL()
static void wm_operator_free_for_fileselect(wmOperator *file_operator)
void CTX_data_scene_set(bContext *C, Scene *scene)
void wm_event_do_handlers(bContext *C)
void wm_event_init_from_window(wmWindow *win, wmEvent *event)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void WM_event_remove_modal_handler_all(const wmOperator *op, const bool postpone)
static eHandlerActionFlag wm_handler_fileselect_do(bContext *C, ListBaseT< wmEventHandler > *handlers, wmEventHandler_Op *handler, int val)
void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *)
Definition wm_draw.cc:1698
void WM_event_add_fileselect(bContext *C, wmOperator *op)
signed char int8_t
Definition BKE_text.h:76
bool WM_window_is_temp_screen(const wmWindow *win)
@ AREA_FLAG_ACTIONZONES_UPDATE
void wm_event_free_handler(wmEventHandler *handler)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
_W64 int intptr_t
Definition BKE_text.h:119
static wmOperatorStatus wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports, const wm::OpCallContext context, const bool poll_only, const wmEvent *event)
void wm_event_handler_ui_cancel_ex(bContext *C, wmWindow *win, ARegion *region, bool reactivate_button)
void ED_area_do_listen(wmSpaceTypeListenerParams *params)
Definition area.cc:140
void CTX_wm_area_set(bContext *C, ScrArea *area)
ARegion * BKE_area_find_region_xy(const ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
Definition screen.cc:1053
void WM_operator_name_call_ptr_with_depends_on_cursor(bContext *C, wmOperatorType *ot, wm::OpCallContext opcontext, PointerRNA *properties, const wmEvent *event, const StringRef drawstr)
GHOST_TabletData tablet
GHOST_TabletData tablet
GHOST_TTrackpadEventSubTypes subtype
GHOST_TEventWheelAxis axis
GHOST_TTabletMode Active
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
eRegion_Type regiontype
CursorKeymapInfo_State state
char name[258]
Definition DNA_ID.h:433
unsigned int session_uid
Definition DNA_ID.h:463
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< bScreen > screens
Definition BKE_main.hh:400
std::optional< bContextStore > context
wmOperatorCallParams optype_params
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< Report > list
Definition BKE_report.hh:79
wmTimer * reporttimer
Definition BKE_report.hh:86
struct CustomData_MeshMasks customdata_mask
struct CustomData_MeshMasks customdata_mask_modal
struct ToolSettings * toolsettings
ListBaseT< ScrArea > areabase
ListBaseT< struct wmEventHandler > handlers
ListBaseT< ARegion > regionbase
ScrArea_Runtime runtime
ListBaseT< SpaceLink > spacedata
struct wmOperator * op
struct Scene * sequencer_scene
eScreen_State state
struct ARegion * active_region
ListBaseT< struct ScrArea > areabase
ListBaseT< ARegion > regionbase
struct wmTooltipState * tool_tip
ebToolRef_Runtime_Flag flag
bToolRef_Runtime * runtime
ListBaseT< wmEventHandler > handlers
struct ARegionType * type
ListBaseT< wmEventHandler > handlers
ListBaseT< wmEvent > event_queue
ListBaseT< wmEventHandler > modalhandlers
bool operator()(const wmNotifier *a, const wmNotifier *b) const
uint64_t operator()(const wmNotifier *note) const
void label(StringRef name, int icon)
Layout & row(bool align)
PointerRNA * ptr
Definition WM_types.hh:1524
bool(*) poll(bContext *C, wmDrag *drag, const wmEvent *event)
Definition WM_types.hh:1456
void(*) cancel(Main *bmain, wmDrag *drag, wmDropBox *drop)
Definition WM_types.hh:1481
wmOperatorType * ot
Definition WM_types.hh:1517
ListBaseT< wmDropBox > * dropboxes
wmEventHandler_KeymapDynamicFn keymap_fn
void(*) post_fn(wmKeyMap *keymap, wmKeyMapItem *kmi, void *user_data)
wmEventHandler_KeymapDynamic dynamic
wmEventHandler_KeymapPost post
struct blender::wmEventHandler_Op::@170112141227310273104305047374063031143165303304 context
wmUIHandlerRemoveFunc remove_fn
struct blender::wmEventHandler_UI::@165375040344237356134256072003335247104031320105 context
eWM_EventHandlerFlag flag
eWM_EventHandlerType type
wmEventType prev_press_type
Definition WM_types.hh:885
eWM_EventFlag flag
Definition WM_types.hh:848
wmTabletData tablet
Definition WM_types.hh:846
int prev_press_xy[2]
Definition WM_types.hh:890
wmEventModifierFlag prev_press_modifier
Definition WM_types.hh:892
wmEventType keymodifier
Definition WM_types.hh:843
wmEventType type
Definition WM_types.hh:817
wmEventType prev_type
Definition WM_types.hh:872
short customdata_free
Definition WM_types.hh:854
wmEventType prev_press_keymodifier
Definition WM_types.hh:894
wmEventModifierFlag modifier
Definition WM_types.hh:834
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupType * type
wmGizmoGroup * parent_gzgroup
eWM_GizmoFlag flag
bool(*) poll_modal_item(const struct wmOperator *op, int value)
ListBaseT< wmKeyMapItem > items
unsigned int action
Definition WM_types.hh:371
const wmWindow * window
Definition WM_types.hh:369
unsigned int subtype
Definition WM_types.hh:371
unsigned int category
Definition WM_types.hh:371
unsigned int data
Definition WM_types.hh:371
wm::OpCallContext opcontext
Definition WM_types.hh:1246
struct wmOperatorTypeMacro * next
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) check(bContext *C, wmOperator *op)
Definition WM_types.hh:1133
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
ListBaseT< wmOperatorTypeMacro > macro
Definition WM_types.hh:1218
const char * translation_context
Definition WM_types.hh:1113
bool(*) pyop_poll(bContext *C, wmOperatorType *ot) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1224
bool(*) ui_poll(wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1181
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
ListBaseT< wmOperator > macro
struct ReportList * reports
struct wmOperatorType * type
bke::WindowManagerRuntime * runtime
bke::WindowRuntime * runtime
struct wmEvent_ConsecutiveData * event_queue_consecutive_gesture_data
DNA_DEPRECATED struct bScreen * screen
#define CASE_BUTTON(ghost_button, type)
#define WM_HANDLER_CONTINUE
#define ISMOUSE_BUTTON(event_type)
#define ISKEYBOARD_OR_BUTTON(event_type)
#define ISMOUSE_MOTION(event_type)
#define ISMOUSE_WHEEL(event_type)
#define ISKEYMODIFIER(event_type)
#define ISTIMER(event_type)
#define ISMOUSE_GESTURE(event_type)
#define ISKEYBOARD(event_type)
#define IS_EVENT_IME_ANY(event_type)
#define ISMOUSE(event_type)