1 /* SPDX-FileCopyrightText: 2007 Blender Authors
3 * SPDX-License-Identifier: GPL-2.0-or-later */
9 * Overview of WM structs
10 * ======================
12 * - #wmWindowManager.windows -> #wmWindow <br>
13 * Window manager stores a list of windows.
15 * - #wmWindow.screen -> #bScreen <br>
16 * Window has an active screen.
18 * - #bScreen.areabase -> #ScrArea <br>
21 * - #ScrArea.spacedata <br>
22 * Stores multiple spaces via space links.
25 * Base struct for space data for all different space types.
27 * - #ScrArea.regionbase -> #ARegion <br>
28 * Stores multiple regions.
30 * - #bScreen.regionbase -> #ARegion <br>
31 * Global screen level regions, e.g. popups, popovers, menus.
33 * - #wmWindow.global_areas -> #ScrAreaMap <br>
34 * Global screen via 'areabase', e.g. top-bar & status-bar.
42 * +----------------------------------------------------------+
43 * |+-----------------------------------------+-------------+ |
44 * ||ScrArea (links to 3D view) |ScrArea | |
45 * ||+-------++----------+-------------------+|(links to | |
46 * |||ARegion|| |ARegion (quad view)|| properties) | |
47 * |||(tools)|| | || | |
51 * ||| |+----------+-------------------+| | |
57 * ||+-------++----------+-------------------+| | |
58 * |+-----------------------------------------+-------------+ |
59 * +----------------------------------------------------------+
66 * ScrArea's store a list of space data (SpaceLinks), each of unique type.
67 * The first one is the displayed in the UI, others are added as needed.
69 * +----------------------------+ <-- area->spacedata.first;
71 * | |---+ <-- other inactive SpaceLink's stored.
78 * +----------------------------+ | |
80 * +-----------------------------+ |
82 * +------------------------------+
85 * A common way to get the space from the ScrArea:
87 * if (area->spacetype == SPACE_VIEW3D) {
88 * View3D *v3d = area->spacedata.first;
101 struct GreasePencilLayerTreeNode
;
107 struct wmWindowManager
;
112 #include "BLI_compiler_attrs.h"
113 #include "BLI_utildefines.h"
114 #include "BLI_vector.hh"
116 #include "DNA_listBase.h"
117 #include "DNA_uuid_types.h"
118 #include "DNA_vec_types.h"
119 #include "DNA_xr_types.h"
121 #include "BKE_wm_runtime.hh" // IWYU pragma: export
123 #include "RNA_types.hh"
125 /* Exported types for WM. */
126 #include "gizmo/WM_gizmo_types.hh" // IWYU pragma: export
127 #include "wm_cursors.hh" // IWYU pragma: export
128 #include "wm_event_types.hh" // IWYU pragma: export
130 /* Include external gizmo API's. */
131 #include "gizmo/WM_gizmo_api.hh" // IWYU pragma: export
133 namespace blender::asset_system
{
134 class AssetRepresentation
;
136 using AssetRepresentationHandle
= blender::asset_system::AssetRepresentation
;
138 using wmGenericUserDataFreeFn
= void (*)(void *data
);
140 struct wmGenericUserData
{
142 /** When NULL, use #MEM_freeN. */
143 wmGenericUserDataFreeFn free_fn
;
147 using wmGenericCallbackFn
= void (*)(bContext
*C
, void *user_data
);
149 struct wmGenericCallback
{
150 wmGenericCallbackFn exec
;
152 wmGenericUserDataFreeFn free_user_data
;
155 /* ************** wmOperatorType ************************ */
157 /** #wmOperatorType.flag */
160 * Register operators in stack after finishing (needed for redo).
162 * \note Typically this flag should be enabled along with #OPTYPE_UNDO.
163 * There is an exception to this, some operators can perform an undo push indirectly.
164 * (`UI_OT_reset_default_button` for example).
166 * In this case, register needs to be enabled so as not to clear the "Redo" panel, see #133761.
167 * Unless otherwise stated, any operators that register without the undo flag
168 * can be assumed to be creating undo steps indirectly (potentially at least).
170 OPTYPE_REGISTER
= (1 << 0),
171 /** Do an undo push after the operator runs. */
172 OPTYPE_UNDO
= (1 << 1),
173 /** Let Blender grab all input from the WM (X11). */
174 OPTYPE_BLOCKING
= (1 << 2),
175 OPTYPE_MACRO
= (1 << 3),
177 /** Grabs the cursor and optionally enables continuous cursor wrapping. */
178 OPTYPE_GRAB_CURSOR_XY
= (1 << 4),
179 /** Only warp on the X axis. */
180 OPTYPE_GRAB_CURSOR_X
= (1 << 5),
181 /** Only warp on the Y axis. */
182 OPTYPE_GRAB_CURSOR_Y
= (1 << 6),
184 /** Show preset menu. */
185 OPTYPE_PRESET
= (1 << 7),
188 * Some operators are mainly for internal use and don't make sense
189 * to be accessed from the search menu, even if poll() returns true.
190 * Currently only used for the search toolbox.
192 OPTYPE_INTERNAL
= (1 << 8),
194 /** Allow operator to run when interface is locked. */
195 OPTYPE_LOCK_BYPASS
= (1 << 9),
196 /** Special type of undo which doesn't store itself multiple times. */
197 OPTYPE_UNDO_GROUPED
= (1 << 10),
200 * Depends on the cursor location, when activated from a menu wait for mouse press.
202 * In practice these operators often end up being accessed:
203 * - Directly from key bindings.
204 * - As tools in the toolbar.
206 * Even so, accessing from the menu should behave usefully.
208 OPTYPE_DEPENDS_ON_CURSOR
= (1 << 11),
210 /** Handle events before modal operators without this flag. */
211 OPTYPE_MODAL_PRIORITY
= (1 << 12),
214 /** For #WM_cursor_grab_enable wrap axis. */
215 enum eWM_CursorWrapAxis
{
216 WM_CURSOR_WRAP_NONE
= 0,
223 * Context to call operator in for #WM_operator_name_call.
224 * rna_ui.cc contains EnumPropertyItem's of these, keep in sync.
226 enum wmOperatorCallContext
{
227 /* If there's invoke, call it, otherwise exec. */
228 WM_OP_INVOKE_DEFAULT
,
229 WM_OP_INVOKE_REGION_WIN
,
230 WM_OP_INVOKE_REGION_CHANNELS
,
231 WM_OP_INVOKE_REGION_PREVIEW
,
234 /* Only call exec. */
236 WM_OP_EXEC_REGION_WIN
,
237 WM_OP_EXEC_REGION_CHANNELS
,
238 WM_OP_EXEC_REGION_PREVIEW
,
243 #define WM_OP_CONTEXT_HAS_AREA(type) \
244 (CHECK_TYPE_INLINE(type, wmOperatorCallContext), \
245 !ELEM(type, WM_OP_INVOKE_SCREEN, WM_OP_EXEC_SCREEN))
246 #define WM_OP_CONTEXT_HAS_REGION(type) \
247 (WM_OP_CONTEXT_HAS_AREA(type) && !ELEM(type, WM_OP_INVOKE_AREA, WM_OP_EXEC_AREA))
249 /** Property tags for #RNA_OperatorProperties. */
250 enum eOperatorPropTags
{
251 OP_PROP_TAG_ADVANCED
= (1 << 0),
253 #define OP_PROP_TAG_ADVANCED ((eOperatorPropTags)OP_PROP_TAG_ADVANCED)
255 /* -------------------------------------------------------------------- */
256 /** \name #wmKeyMapItem
260 * Modifier keys, not actually used for #wmKeyMapItem (never stored in DNA), used for:
261 * - #wmEvent.modifier without the `KM_*_ANY` flags.
262 * - #WM_keymap_add_item & #WM_modalkeymap_add_item
268 /** Use for Windows-Key on MS-Windows, Command-key on macOS and Super on Linux. */
271 /* Used for key-map item creation function arguments. */
272 KM_SHIFT_ANY
= (1 << 4),
273 KM_CTRL_ANY
= (1 << 5),
274 KM_ALT_ANY
= (1 << 6),
275 KM_OSKEY_ANY
= (1 << 7),
278 /* `KM_MOD_*` flags for #wmKeyMapItem and `wmEvent.alt/shift/oskey/ctrl`. */
279 /* Note that #KM_ANY and #KM_NOTHING are used with these defines too. */
280 #define KM_MOD_HELD 1
284 * NOTE: most types are defined in `wm_event_types.hh`.
290 /** #wmKeyMapItem.val */
299 * \note The cursor location at the point dragging starts is set to #wmEvent.prev_press_xy
300 * some operators such as box selection should use this location instead of #wmEvent.xy.
306 * #wmKeyMapItem.direction
308 * Direction set for #KM_CLICK_DRAG key-map items. #KM_ANY (-1) to ignore direction.
323 /* ************** UI Handler ***************** */
325 #define WM_UI_HANDLER_CONTINUE 0
326 #define WM_UI_HANDLER_BREAK 1
328 /* ************** Notifiers ****************** */
331 wmNotifier
*next
, *prev
;
333 const wmWindow
*window
;
335 unsigned int category
, data
, subtype
, action
;
342 * 0xFF000000; category
344 * 0x0000FF00; data subtype (unused?)
349 #define NOTE_CATEGORY 0xFF000000
350 #define NOTE_CATEGORY_TAG_CLEARED NOTE_CATEGORY
351 #define NC_WM (1 << 24)
352 #define NC_WINDOW (2 << 24)
353 #define NC_WORKSPACE (3 << 24)
354 #define NC_SCREEN (4 << 24)
355 #define NC_SCENE (5 << 24)
356 #define NC_OBJECT (6 << 24)
357 #define NC_MATERIAL (7 << 24)
358 #define NC_TEXTURE (8 << 24)
359 #define NC_LAMP (9 << 24)
360 #define NC_GROUP (10 << 24)
361 #define NC_IMAGE (11 << 24)
362 #define NC_BRUSH (12 << 24)
363 #define NC_TEXT (13 << 24)
364 #define NC_WORLD (14 << 24)
365 #define NC_ANIMATION (15 << 24)
366 /* When passing a space as reference data with this (e.g. `WM_event_add_notifier(..., space)`),
367 * the notifier will only be sent to this space. That avoids unnecessary updates for unrelated
369 #define NC_SPACE (16 << 24)
370 #define NC_GEOM (17 << 24)
371 #define NC_NODE (18 << 24)
372 #define NC_ID (19 << 24)
373 #define NC_PAINTCURVE (20 << 24)
374 #define NC_MOVIECLIP (21 << 24)
375 #define NC_MASK (22 << 24)
376 #define NC_GPENCIL (23 << 24)
377 #define NC_LINESTYLE (24 << 24)
378 #define NC_CAMERA (25 << 24)
379 #define NC_LIGHTPROBE (26 << 24)
380 /* Changes to asset data in the current .blend. */
381 #define NC_ASSET (27 << 24)
382 /* Changes to the active viewer path. */
383 #define NC_VIEWER_PATH (28 << 24)
385 /* Data type, 256 entries is enough, it can overlap. */
386 #define NOTE_DATA 0x00FF0000
388 /* NC_WM (window-manager). */
389 #define ND_FILEREAD (1 << 16)
390 #define ND_FILESAVE (2 << 16)
391 #define ND_DATACHANGED (3 << 16)
392 #define ND_HISTORY (4 << 16)
393 #define ND_JOB (5 << 16)
394 #define ND_UNDO (6 << 16)
395 #define ND_XR_DATA_CHANGED (7 << 16)
396 #define ND_LIB_OVERRIDE_CHANGED (8 << 16)
399 #define ND_LAYOUTBROWSE (1 << 16)
400 #define ND_LAYOUTDELETE (2 << 16)
401 #define ND_ANIMPLAY (4 << 16)
402 #define ND_GPENCIL (5 << 16)
403 #define ND_LAYOUTSET (6 << 16)
404 #define ND_SKETCH (7 << 16)
405 #define ND_WORKSPACE_SET (8 << 16)
406 #define ND_WORKSPACE_DELETE (9 << 16)
408 /* NC_SCENE Scene. */
409 #define ND_SCENEBROWSE (1 << 16)
410 #define ND_MARKERS (2 << 16)
411 #define ND_FRAME (3 << 16)
412 #define ND_RENDER_OPTIONS (4 << 16)
413 #define ND_NODES (5 << 16)
414 #define ND_SEQUENCER (6 << 16)
415 /* NOTE: If an object was added, removed, merged/joined, ..., it is not enough to notify with
416 * this. This affects the layer so also send a layer change notifier (e.g. ND_LAYER_CONTENT)! */
417 #define ND_OB_ACTIVE (7 << 16)
418 /* See comment on ND_OB_ACTIVE. */
419 #define ND_OB_SELECT (8 << 16)
420 #define ND_OB_VISIBLE (9 << 16)
421 #define ND_OB_RENDER (10 << 16)
422 #define ND_MODE (11 << 16)
423 #define ND_RENDER_RESULT (12 << 16)
424 #define ND_COMPO_RESULT (13 << 16)
425 #define ND_KEYINGSET (14 << 16)
426 #define ND_TOOLSETTINGS (15 << 16)
427 #define ND_LAYER (16 << 16)
428 #define ND_FRAME_RANGE (17 << 16)
429 #define ND_WORLD (92 << 16)
430 #define ND_LAYER_CONTENT (101 << 16)
432 /* NC_OBJECT Object. */
433 #define ND_TRANSFORM (18 << 16)
434 #define ND_OB_SHADING (19 << 16)
435 #define ND_POSE (20 << 16)
436 #define ND_BONE_ACTIVE (21 << 16)
437 #define ND_BONE_SELECT (22 << 16)
438 #define ND_DRAW (23 << 16)
439 #define ND_MODIFIER (24 << 16)
440 #define ND_KEYS (25 << 16)
441 #define ND_CONSTRAINT (26 << 16)
442 #define ND_PARTICLE (27 << 16)
443 #define ND_POINTCACHE (28 << 16)
444 #define ND_PARENT (29 << 16)
445 #define ND_LOD (30 << 16)
446 /** For camera & sequencer viewport update, also with #NC_SCENE. */
447 #define ND_DRAW_RENDER_VIEWPORT (31 << 16)
448 #define ND_SHADERFX (32 << 16)
449 /* For updating motion paths in 3dview. */
450 #define ND_DRAW_ANIMVIZ (33 << 16)
451 #define ND_BONE_COLLECTION (34 << 16)
453 /* NC_MATERIAL Material. */
454 #define ND_SHADING (30 << 16)
455 #define ND_SHADING_DRAW (31 << 16)
456 #define ND_SHADING_LINKS (32 << 16)
457 #define ND_SHADING_PREVIEW (33 << 16)
460 #define ND_LIGHTING (40 << 16)
461 #define ND_LIGHTING_DRAW (41 << 16)
463 /* NC_WORLD World. */
464 #define ND_WORLD_DRAW (45 << 16)
467 #define ND_CURSOR (50 << 16)
468 #define ND_DISPLAY (51 << 16)
470 /* NC_ANIMATION Animato. */
471 #define ND_KEYFRAME (70 << 16)
472 #define ND_KEYFRAME_PROP (71 << 16)
473 #define ND_ANIMCHAN (72 << 16)
474 #define ND_NLA (73 << 16)
475 #define ND_NLA_ACTCHANGE (74 << 16)
476 #define ND_FCURVES_ORDER (75 << 16)
477 #define ND_NLA_ORDER (76 << 16)
478 #define ND_KEYFRAME_AUTO (77 << 16)
481 #define ND_GPENCIL_EDITMODE (85 << 16)
483 /* NC_GEOM Geometry. */
484 /* Mesh, Curve, MetaBall, Armature, etc. */
485 #define ND_SELECT (90 << 16)
486 #define ND_DATA (91 << 16)
487 #define ND_VERTEX_GROUP (92 << 16)
491 /* Influences which menus node assets are included in. */
492 #define ND_NODE_ASSET_DATA (1 << 16)
493 #define ND_NODE_GIZMO (2 << 16)
496 #define ND_SPACE_CONSOLE (1 << 16) /* General redraw. */
497 #define ND_SPACE_INFO_REPORT (2 << 16) /* Update for reports, could specify type. */
498 #define ND_SPACE_INFO (3 << 16)
499 #define ND_SPACE_IMAGE (4 << 16)
500 #define ND_SPACE_FILE_PARAMS (5 << 16)
501 #define ND_SPACE_FILE_LIST (6 << 16)
502 #define ND_SPACE_ASSET_PARAMS (7 << 16)
503 #define ND_SPACE_NODE (8 << 16)
504 #define ND_SPACE_OUTLINER (9 << 16)
505 #define ND_SPACE_VIEW3D (10 << 16)
506 #define ND_SPACE_PROPERTIES (11 << 16)
507 #define ND_SPACE_TEXT (12 << 16)
508 #define ND_SPACE_TIME (13 << 16)
509 #define ND_SPACE_GRAPH (14 << 16)
510 #define ND_SPACE_DOPESHEET (15 << 16)
511 #define ND_SPACE_NLA (16 << 16)
512 #define ND_SPACE_SEQUENCER (17 << 16)
513 #define ND_SPACE_NODE_VIEW (18 << 16)
514 /* Sent to a new editor type after it's replaced an old one. */
515 #define ND_SPACE_CHANGED (19 << 16)
516 #define ND_SPACE_CLIP (20 << 16)
517 #define ND_SPACE_FILE_PREVIEW (21 << 16)
518 #define ND_SPACE_SPREADSHEET (22 << 16)
519 /* Not a space itself, but a part of another space. */
520 #define ND_REGIONS_ASSET_SHELF (23 << 16)
523 /* Denotes that the AssetList is done reading some previews. NOT that the preview generation of
525 #define ND_ASSET_LIST (1 << 16)
526 #define ND_ASSET_LIST_PREVIEW (2 << 16)
527 #define ND_ASSET_LIST_READING (3 << 16)
528 /* Catalog data changed, requiring a redraw of catalog UIs. Note that this doesn't denote a
529 * reloading of asset libraries & their catalogs should happen. That only happens on explicit user
531 #define ND_ASSET_CATALOGS (4 << 16)
533 /* Subtype, 256 entries too. */
534 #define NOTE_SUBTYPE 0x0000FF00
536 /* Subtype scene mode. */
537 #define NS_MODE_OBJECT (1 << 8)
539 #define NS_EDITMODE_MESH (2 << 8)
540 #define NS_EDITMODE_CURVE (3 << 8)
541 #define NS_EDITMODE_SURFACE (4 << 8)
542 #define NS_EDITMODE_TEXT (5 << 8)
543 #define NS_EDITMODE_MBALL (6 << 8)
544 #define NS_EDITMODE_LATTICE (7 << 8)
545 #define NS_EDITMODE_ARMATURE (8 << 8)
546 #define NS_MODE_POSE (9 << 8)
547 #define NS_MODE_PARTICLE (10 << 8)
548 #define NS_EDITMODE_CURVES (11 << 8)
549 #define NS_EDITMODE_GREASE_PENCIL (12 << 8)
550 #define NS_EDITMODE_POINT_CLOUD (13 << 8)
552 /* Subtype 3d view editing. */
553 #define NS_VIEW3D_GPU (16 << 8)
554 #define NS_VIEW3D_SHADING (17 << 8)
556 /* Subtype layer editing. */
557 #define NS_LAYER_COLLECTION (24 << 8)
559 /* Action classification. */
560 #define NOTE_ACTION (0x000000FF)
562 #define NA_EVALUATED 2
566 #define NA_SELECTED 6
567 #define NA_ACTIVATED 7
568 #define NA_PAINTING 8
569 #define NA_JOB_FINISHED 9
571 /* ************** Gesture Manager data ************** */
573 namespace blender::wm::gesture
{
574 constexpr float POLYLINE_CLICK_RADIUS
= 15.0f
;
577 /** #wmGesture::type */
578 #define WM_GESTURE_LINES 1
579 #define WM_GESTURE_RECT 2
580 #define WM_GESTURE_CROSS_RECT 3
581 #define WM_GESTURE_LASSO 4
582 #define WM_GESTURE_CIRCLE 5
583 #define WM_GESTURE_STRAIGHTLINE 6
584 #define WM_GESTURE_POLYLINE 7
587 * wmGesture is registered to #wmWindow.gesture, handled by operator callbacks.
590 wmGesture
*next
, *prev
;
591 /** #wmEvent.type. */
593 /** #wmEvent.modifier. */
594 uint8_t event_modifier
;
595 /** #wmEvent.keymodifier. */
596 short event_keymodifier
;
597 /** Gesture type define. */
599 /** Bounds of region to draw gesture within. */
601 /** Optional, amount of points stored. */
603 /** Optional, maximum amount of points stored. */
606 /** Optional, draw the active side of the straight-line gesture. */
607 bool draw_active_side
;
608 /** Latest mouse position relative to area. Currently only used by lasso drawing code. */
612 * For modal operators which may be running idle, waiting for an event to activate the gesture.
613 * Typically this is set when the user is click-dragging the gesture
614 * (box and circle select for eg).
617 /** Previous value of is-active (use to detect first run & edge cases). */
618 uint is_active_prev
: 1;
619 /** Use for gestures that support both immediate or delayed activation. */
620 uint wait_for_input
: 1;
621 /** Use for gestures that can be moved, like box selection. */
623 /** For gestures that support snapping, stores if snapping is enabled using the modal keymap
626 /** For gestures that support flip, stores if flip is enabled using the modal keymap
629 /** For gestures that support smoothing, stores if smoothing is enabled using the modal keymap
635 * - for border is a #rcti.
636 * - for circle is #rcti, (`xmin`, `ymin`) is center, `xmax` radius.
637 * - for lasso is short array.
638 * - for straight line is a #rcti: (`xmin`, `ymin`) is start, (`xmax`, `ymax`) is end.
642 /** Free pointer to use for operator allocations (if set, its freed on exit). */
643 wmGenericUserData user_data
;
646 /* ************** wmEvent ************************ */
650 * True if the operating system inverted the delta x/y values and resulting
651 * `prev_xy` values, for natural scroll direction.
652 * For absolute scroll direction, the delta must be negated again.
654 WM_EVENT_SCROLL_INVERT
= (1 << 0),
656 * Generated by auto-repeat, note that this must only ever be set for keyboard events
657 * where `ISKEYBOARD(event->type) == true`.
659 * See #KMI_REPEAT_IGNORE for details on how key-map handling uses this.
661 WM_EVENT_IS_REPEAT
= (1 << 1),
663 * Generated for consecutive trackpad or NDOF-motion events,
664 * the repeat chain is broken by key/button events,
665 * or cursor motion exceeding #WM_EVENT_CURSOR_MOTION_THRESHOLD.
667 * Changing the type of trackpad or gesture event also breaks the chain.
669 WM_EVENT_IS_CONSECUTIVE
= (1 << 2),
671 * Mouse-move events may have this flag set to force creating a click-drag event
672 * even when the threshold has not been met.
674 WM_EVENT_FORCE_DRAG_THRESHOLD
= (1 << 3),
676 ENUM_OPERATORS(eWM_EventFlag
, WM_EVENT_FORCE_DRAG_THRESHOLD
);
678 struct wmTabletData
{
679 /** 0=EVT_TABLET_NONE, 1=EVT_TABLET_STYLUS, 2=EVT_TABLET_ERASER. */
681 /** Range 0.0 (not touching) to 1.0 (full pressure). */
683 /** Range 0.0 (upright) to 1.0 (tilted fully against the tablet surface). */
687 /** Interpret mouse motion as absolute as typical for tablets. */
688 char is_motion_absolute
;
692 * Each event should have full modifier state.
693 * event comes from event manager and from keymap.
696 * Previous State (`prev_*`)
697 * =========================
699 * Events hold information about the previous event.
701 * - Previous values are only set for events types that generate #KM_PRESS.
702 * See: #ISKEYBOARD_OR_BUTTON.
704 * - Previous x/y are exceptions: #wmEvent.prev
705 * these are set on mouse motion, see #MOUSEMOVE & trackpad events.
707 * - Modal key-map handling sets `prev_val` & `prev_type` to `val` & `type`,
708 * this allows modal keys-maps to check the original values (needed in some cases).
711 * Press State (`prev_press_*`)
712 * ============================
714 * Events hold information about the state when the last #KM_PRESS event was added.
715 * This is used for generating #KM_CLICK, #KM_DBL_CLICK & #KM_CLICK_DRAG events.
716 * See #wm_handlers_do for the implementation.
718 * - Previous values are only set when a #KM_PRESS event is detected.
719 * See: #ISKEYBOARD_OR_BUTTON.
721 * - The reason to differentiate between "press" and the previous event state is
722 * the previous event may be set by key-release events. In the case of a single key click
723 * this isn't a problem however releasing other keys such as modifiers prevents click/click-drag
724 * events from being detected, see: #89989.
726 * - Mouse-wheel events are excluded even though they generate #KM_PRESS
727 * as clicking and dragging don't make sense for mouse wheel events.
730 wmEvent
*next
, *prev
;
732 /** Event code itself (short, is also in key-map). */
734 /** Press, release, scroll-value. */
736 /** Mouse pointer position, screen coord. */
738 /** Region relative mouse position (name convention before Blender 2.5). */
741 * A single UTF8 encoded character.
743 * - Not null terminated although it may not be set `(utf8_buf[0] == '\0')`.
744 * - #BLI_str_utf8_size_or_error() must _always_ return a valid value,
745 * check when assigning so we don't need to check on every access after.
749 /** Modifier states: #KM_SHIFT, #KM_CTRL, #KM_ALT & #KM_OSKEY. */
752 /** The direction (for #KM_CLICK_DRAG events only). */
756 * Raw-key modifier (allow using any key as a modifier).
757 * Compatible with values in `type`.
761 /** Tablet info, available for mouse move and button events. */
768 /** Custom data type, stylus, 6-DOF, see `wm_event_types.hh`. */
770 short customdata_free
;
772 * The #wmEvent::type implies the following #wmEvent::custodata.
774 * - #EVT_ACTIONZONE_AREA / #EVT_ACTIONZONE_FULLSCREEN / #EVT_ACTIONZONE_FULLSCREEN:
775 * Uses #sActionzoneData.
776 * - #EVT_DROP: uses #ListBase of #wmDrag (also #wmEvent::custom == #EVT_DATA_DRAGDROP).
777 * Typically set to #wmWindowManger::drags.
778 * - #EVT_FILESELECT: uses #wmOperator.
779 * - #EVT_XR_ACTION: uses #wmXrActionData (also #wmEvent::custom == #EVT_DATA_XR).
780 * - #NDOF_MOTION: uses #wmNDOFMotionData (also #wmEvent::custom == #EVT_DATA_NDOF_MOTION).
781 * - #TIMER: uses #wmTimer (also #wmEvent::custom == #EVT_DATA_TIMER).
785 /* Previous State. */
787 /** The previous value of `type`. */
789 /** The previous value of `val`. */
792 * The previous value of #wmEvent.xy,
793 * Unlike other previous state variables, this is set on any mouse motion.
794 * Use `prev_press_*` for the value at time of pressing.
798 /* Previous Press State (when `val == KM_PRESS`). */
800 /** The `type` at the point of the press action. */
801 short prev_press_type
;
803 * The location when the key is pressed.
804 * used to enforce drag threshold & calculate the `direction`.
806 int prev_press_xy
[2];
807 /** The `modifier` at the point of the press action. */
808 uint8_t prev_press_modifier
;
809 /** The `keymodifier` at the point of the press action. */
810 short prev_press_keymodifier
;
814 * Values below are ignored when detecting if the user intentionally moved the cursor.
815 * Keep this very small since it's used for selection cycling for eg,
816 * where we want intended adjustments to pass this threshold and select new items.
818 * Always check for <= this value since it may be zero.
820 #define WM_EVENT_CURSOR_MOTION_THRESHOLD ((float)U.move_threshold * UI_SCALE_FAC)
822 /** Motion progress, for modal handlers. */
825 P_STARTING
, /* <-- */
826 P_IN_PROGRESS
, /* <-- only these are sent for NDOF motion. */
827 P_FINISHING
, /* <-- */
831 #ifdef WITH_INPUT_NDOF
832 struct wmNDOFMotionData
{
833 /* Awfully similar to #GHOST_TEventNDOFMotionData. */
835 * Each component normally ranges from -1 to +1, but can exceed that.
836 * These use blender standard view coordinates,
837 * with positive rotations being CCW about the axis.
843 * axis = (rx,ry,rz).normalized.
844 * amount = (rx,ry,rz).magnitude [in revolutions, 1.0 = 360 deg]
848 /** Time since previous NDOF Motion event. */
850 /** Is this the first event, the last, or one of many in between? */
853 #endif /* WITH_INPUT_NDOF */
855 #ifdef WITH_XR_OPENXR
856 /* Similar to GHOST_XrPose. */
859 /* Blender convention (w, x, y, z). */
860 float orientation_quat
[4];
863 struct wmXrActionState
{
867 float state_vector2f
[2];
870 int type
; /* #eXrActionType. */
873 struct wmXrActionData
{
874 /** Action set name. */
878 /** User path. E.g. "/user/hand/left". */
880 /** Other user path, for bimanual actions. E.g. "/user/hand/right". */
881 char user_path_other
[64];
884 /** State. Set appropriately based on type. */
886 /** State of the other sub-action path for bimanual actions. */
887 float state_other
[2];
889 /** Input threshold for float/vector2f actions. */
890 float float_threshold
;
892 /** Controller aim pose corresponding to the action's sub-action path. */
893 float controller_loc
[3];
894 float controller_rot
[4];
895 /** Controller aim pose of the other sub-action path for bimanual actions. */
896 float controller_loc_other
[3];
897 float controller_rot_other
[4];
901 IDProperty
*op_properties
;
903 /** Whether bimanual interaction is occurring. */
910 /** Do not attempt to free custom-data pointer even if non-NULL. */
911 WM_TIMER_NO_FREE_CUSTOM_DATA
= 1 << 0,
913 /* Internal flags, should not be used outside of WM code. */
914 /** This timer has been tagged for removal and deletion, handled by WM code to ensure timers are
915 * deleted in a safe context. */
916 WM_TIMER_TAGGED_FOR_REMOVAL
= 1 << 16,
918 ENUM_OPERATORS(wmTimerFlags
, WM_TIMER_TAGGED_FOR_REMOVAL
)
921 wmTimer
*next
, *prev
;
923 /** Window this timer is attached to (optional). */
926 /** Set by timer user. */
928 /** Set by timer user, goes to event system. */
930 /** Various flags controlling timer options, see below. */
932 /** Set by timer user, to allow custom values. */
935 /** Total running time in seconds. */
936 double time_duration
;
937 /** Time since previous step in seconds. */
940 /** Internal, last time timer was activated. */
942 /** Internal, next time we want to activate the timer. */
944 /** Internal, when the timer started. */
946 /** Internal, put timers to sleep when needed. */
951 WM_POPUP_SIZE_SMALL
= 0,
955 enum wmPopupPosition
{
956 WM_POPUP_POSITION_MOUSE
= 0,
957 WM_POPUP_POSITION_CENTER
,
961 * Communication/status data owned by the wmJob, and passed to the worker code when calling
962 * `startjob` callback.
964 * 'OUTPUT' members mean that they are defined by the worker thread, and read/used by the wmJob
965 * management code from the main thread. And vice-versa for `INPUT' members.
967 * \warning There is currently no thread-safety or synchronization when accessing these values.
968 * This is fine as long as:
969 * - All members are independent of each other, value-wise.
970 * - Each member is 'simple enough' that accessing it or setting it can be considered as atomic.
971 * - There is no requirement of immediate synchronization of these values between the main
972 * controlling thread (i.e. wmJob management code) and the worker thread.
974 struct wmJobWorkerStatus
{
976 * OUTPUT - Set to true by the worker to request update processing from the main thread (as part
977 * of the wmJob 'event loop', see #wm_jobs_timer).
982 * INPUT - Set by the wmJob management code to request a worker to stop/abort its processing.
984 * \note Some job types (rendering or baking ones e.g.) also use the #Global.is_break flag to
985 * cancel their processing.
989 /** OUTPUT - Progress as reported by the worker, from `0.0f` to `1.0f`. */
993 * OUTPUT - Storage of reports generated during this job's run. Contains its own locking for
999 struct wmOperatorType
{
1000 /** Text for UI, undo (should not exceed #OP_MAX_TYPENAME). */
1002 /** Unique identifier (must not exceed #OP_MAX_TYPENAME). */
1004 /** Translation context (must not exceed #BKE_ST_MAXNAME). */
1005 const char *translation_context
;
1006 /** Use for tooltips and Python docs. */
1007 const char *description
;
1008 /** Identifier to group operators together. */
1009 const char *undo_group
;
1012 * This callback executes the operator without any interactive input,
1013 * parameters may be provided through operator properties. cannot use
1014 * any interface code or input device state.
1015 * See defines below for return values.
1017 int (*exec
)(bContext
*C
, wmOperator
*op
) ATTR_WARN_UNUSED_RESULT
;
1020 * This callback executes on a running operator whenever as property
1021 * is changed. It can correct its own properties or report errors for
1022 * invalid settings in exceptional cases.
1023 * Boolean return value, True denotes a change has been made and to redraw.
1025 bool (*check
)(bContext
*C
, wmOperator
*op
);
1028 * For modal temporary operators, initially invoke is called, then
1029 * any further events are handled in #modal. If the operation is
1030 * canceled due to some external reason, cancel is called
1031 * See defines below for return values.
1033 int (*invoke
)(bContext
*C
, wmOperator
*op
, const wmEvent
*event
) ATTR_WARN_UNUSED_RESULT
;
1036 * Called when a modal operator is canceled (not used often).
1037 * Internal cleanup can be done here if needed.
1039 void (*cancel
)(bContext
*C
, wmOperator
*op
);
1042 * Modal is used for operators which continuously run. Fly mode, knife tool, circle select are
1043 * all examples of modal operators. Modal operators can handle events which would normally invoke
1044 * or execute other operators. They keep running until they don't return
1045 * `OPERATOR_RUNNING_MODAL`.
1047 int (*modal
)(bContext
*C
, wmOperator
*op
, const wmEvent
*event
) ATTR_WARN_UNUSED_RESULT
;
1050 * Verify if the operator can be executed in the current context. Note
1051 * that the operator may still fail to execute even if this returns true.
1053 bool (*poll
)(bContext
*C
) ATTR_WARN_UNUSED_RESULT
;
1056 * Used to check if properties should be displayed in auto-generated UI.
1057 * Use 'check' callback to enforce refreshing.
1059 bool (*poll_property
)(const bContext
*C
,
1061 const PropertyRNA
*prop
) ATTR_WARN_UNUSED_RESULT
;
1063 /** Optional panel for redo and repeat, auto-generated if not set. */
1064 void (*ui
)(bContext
*C
, wmOperator
*op
);
1066 * Optional check for whether the #ui callback should be called (usually to create the redo
1069 bool (*ui_poll
)(wmOperatorType
*ot
, PointerRNA
*ptr
);
1072 * Return a different name to use in the user interface, based on property values.
1073 * The returned string is expected to be translated if needed.
1075 * WARNING: This callback does not currently work as expected in most common usage cases (e.g.
1076 * any definition of an operator button through the layout API will fail to execute it). See
1077 * #112253 for details.
1079 std::string (*get_name
)(wmOperatorType
*ot
, PointerRNA
*ptr
);
1082 * Return a different description to use in the user interface, based on property values.
1083 * The returned string is expected to be translated if needed.
1085 std::string (*get_description
)(bContext
*C
, wmOperatorType
*ot
, PointerRNA
*ptr
);
1087 /** A dynamic version of #OPTYPE_DEPENDS_ON_CURSOR which can depend on operator properties. */
1088 bool (*depends_on_cursor
)(bContext
&C
, wmOperatorType
&ot
, PointerRNA
*ptr
);
1090 /** RNA for properties. */
1093 /** Previous settings - for initializing on re-use. */
1094 IDProperty
*last_properties
;
1097 * Default rna property to use for generic invoke functions.
1098 * menus, enum search... etc. Example: Enum 'type' for a Delete menu.
1100 * When assigned a string/number property,
1101 * immediately edit the value when used in a popup. see: #UI_BUT_ACTIVATE_ON_INIT.
1105 /** #wmOperatorTypeMacro. */
1108 /** Pointer to modal keymap. Do not free! */
1109 wmKeyMap
*modalkeymap
;
1111 /** Python needs the operator type as well. */
1112 bool (*pyop_poll
)(bContext
*C
, wmOperatorType
*ot
) ATTR_WARN_UNUSED_RESULT
;
1114 /** RNA integration. */
1115 ExtensionRNA rna_ext
;
1117 /** Cursor to use when waiting for cursor input, see: #OPTYPE_DEPENDS_ON_CURSOR. */
1120 /** Flag last for padding. */
1125 * Wrapper to reference a #wmOperatorType together with some set properties and other relevant
1126 * information to invoke the operator in a customizable way.
1128 struct wmOperatorCallParams
{
1129 wmOperatorType
*optype
;
1131 wmOperatorCallContext opcontext
;
1134 #ifdef WITH_INPUT_IME
1135 /* *********** Input Method Editor (IME) *********** */
1137 * \warning this is a duplicate of #GHOST_TEventImeData.
1138 * All members must remain aligned and the struct size match!
1141 size_t result_len
, composite_len
;
1143 /** UTF8 encoding. */
1145 /** UTF8 encoding. */
1146 char *str_composite
;
1148 /** Cursor position in the IME composition. */
1150 /** Beginning of the selection. */
1152 /** End of the selection. */
1157 /* **************** Paint Cursor ******************* */
1159 using wmPaintCursorDraw
= void (*)(bContext
*C
, int, int, void *customdata
);
1161 /* *************** Drag and drop *************** */
1163 enum eWM_DragDataType
{
1166 /** The user is dragging multiple assets. This is only supported in few specific cases, proper
1167 * multi-item support for dragging isn't supported well yet. Therefore this is kept separate from
1168 * #WM_DRAG_ASSET. */
1174 * Arbitrary text such as dragging from a text editor,
1175 * this is also used when dragging a URL from a browser.
1177 * An #std::string expected to be UTF8 encoded.
1178 * Callers that require valid UTF8 sequences must validate the text.
1183 WM_DRAG_ASSET_CATALOG
,
1184 WM_DRAG_GREASE_PENCIL_LAYER
,
1185 WM_DRAG_GREASE_PENCIL_GROUP
,
1186 WM_DRAG_NODE_TREE_INTERFACE
,
1187 WM_DRAG_BONE_COLLECTION
,
1190 enum eWM_DragFlags
{
1192 WM_DRAG_FREE_DATA
= 1,
1194 ENUM_OPERATORS(eWM_DragFlags
, WM_DRAG_FREE_DATA
)
1196 /* NOTE: structs need not exported? */
1199 wmDragID
*next
, *prev
;
1204 struct wmDragAsset
{
1205 int import_method
; /* #eAssetImportMethod. */
1206 const AssetRepresentationHandle
*asset
;
1209 struct wmDragAssetCatalog
{
1210 bUUID drag_catalog_id
;
1214 * For some specific cases we support dragging multiple assets (#WM_DRAG_ASSET_LIST). There is no
1215 * proper support for dragging multiple items in the `wmDrag`/`wmDrop` API yet, so this is really
1216 * just to enable specific features for assets.
1218 * This struct basically contains a tagged union to either store a local ID pointer, or information
1219 * about an externally stored asset.
1221 struct wmDragAssetListItem
{
1222 wmDragAssetListItem
*next
, *prev
;
1226 wmDragAsset
*external_info
;
1233 blender::Vector
<std::string
> paths
;
1234 /* File type of each path in #paths. */
1235 blender::Vector
<int> file_types
; /* #eFileSel_File_Types. */
1236 /* Bit flag of file types in #paths. */
1237 int file_types_bit_flag
; /* #eFileSel_File_Types. */
1238 std::string tooltip
;
1241 struct wmDragGreasePencilLayer
{
1242 GreasePencil
*grease_pencil
;
1243 GreasePencilLayerTreeNode
*node
;
1246 using WMDropboxTooltipFunc
= std::string (*)(bContext
*C
,
1251 struct wmDragActiveDropState
{
1252 wmDragActiveDropState();
1253 ~wmDragActiveDropState();
1256 * Informs which dropbox is activated with the drag item.
1257 * When this value changes, the #on_enter() and #on_exit() dropbox callbacks are triggered.
1259 wmDropBox
*active_dropbox
;
1262 * If `active_dropbox` is set, the area it successfully polled in.
1263 * To restore the context of it as needed.
1267 * If `active_dropbox` is set, the region it successfully polled in.
1268 * To restore the context of it as needed.
1270 ARegion
*region_from
;
1273 * If `active_dropbox` is set, additional context provided by the active (i.e. hovered) button.
1274 * Activated before context sensitive operations (polling, drawing, dropping).
1276 std::unique_ptr
<bContextStore
> ui_context
;
1279 * Text to show when a dropbox poll succeeds (so the dropbox itself is available) but the
1280 * operator poll fails. Typically the message the operator set with
1281 * #CTX_wm_operator_poll_msg_set().
1283 const char *disabled_info
;
1284 bool free_disabled_info
;
1286 std::string tooltip
;
1290 wmDrag
*next
, *prev
;
1293 eWM_DragDataType type
;
1296 /** If no small icon but imbuf should be drawn around cursor. */
1299 /** If #imb is not set, draw this as a big preview instead of the small #icon. */
1300 int preview_icon_id
; /* BIFIconID */
1302 wmDragActiveDropState drop_state
;
1304 eWM_DragFlags flags
;
1306 /** List of wmDragIDs, all are guaranteed to have the same ID type. */
1308 /** List of `wmDragAssetListItem`s. */
1309 ListBase asset_items
;
1313 * Drop-boxes are like key-maps, part of the screen/area/region definition.
1314 * Allocation and free is on startup and exit.
1316 * The operator is polled and invoked with the current context (#WM_OP_INVOKE_DEFAULT), there is no
1317 * way to override that (by design, since drop-boxes should act on the exact mouse position).
1318 * So the drop-boxes are supposed to check the required area and region context in their poll.
1321 wmDropBox
*next
, *prev
;
1323 /** Test if the dropbox is active. */
1324 bool (*poll
)(bContext
*C
, wmDrag
*drag
, const wmEvent
*event
);
1326 /** Called when the drag action starts. Can be used to prefetch data for previews.
1327 * \note The dropbox that will be called eventually is not known yet when starting the drag.
1328 * So this callback is called on every dropbox that is registered in the current screen. */
1329 void (*on_drag_start
)(bContext
*C
, wmDrag
*drag
);
1331 /** Called when poll returns true the first time. Typically used to setup some drawing data. */
1332 void (*on_enter
)(wmDropBox
*drop
, wmDrag
*drag
);
1334 /** Called when poll returns false the first time or when the drag event ends (successful drop or
1335 * canceled). Typically used to cleanup resources or end drawing. */
1336 void (*on_exit
)(wmDropBox
*drop
, wmDrag
*drag
);
1338 /** Before exec, this copies drag info to #wmDrop properties. */
1339 void (*copy
)(bContext
*C
, wmDrag
*drag
, wmDropBox
*drop
);
1342 * If the operator is canceled (returns `OPERATOR_CANCELLED`), this can be used for cleanup of
1343 * `copy()` resources.
1345 void (*cancel
)(Main
*bmain
, wmDrag
*drag
, wmDropBox
*drop
);
1348 * Override the default cursor overlay drawing function.
1349 * Can be used to draw text or thumbnails. IE a tooltip for drag and drop.
1350 * \param xy: Cursor location in window coordinates (#wmEvent.xy compatible).
1352 void (*draw_droptip
)(bContext
*C
, wmWindow
*win
, wmDrag
*drag
, const int xy
[2]);
1355 * Called with the draw buffer (#GPUViewport) set up for drawing into the region's view.
1356 * \note Only setups the drawing buffer for drawing in view, not the GPU transform matrices.
1357 * The callback has to do that itself, with for example #UI_view2d_view_ortho.
1358 * \param xy: Cursor location in window coordinates (#wmEvent.xy compatible).
1360 void (*draw_in_view
)(bContext
*C
, wmWindow
*win
, wmDrag
*drag
, const int xy
[2]);
1362 /** Custom data for drawing. */
1365 /** Custom tooltip shown during dragging. */
1366 WMDropboxTooltipFunc tooltip
;
1369 * If poll succeeds, operator is called.
1370 * Not saved in file, so can be pointer.
1371 * This may be null when the operator has been unregistered,
1372 * where `opname` can be used to re-initialize it.
1375 /** #wmOperatorType::idname, needed for re-registration. */
1378 /** Operator properties, assigned to ptr->data and can be written to a file. */
1379 IDProperty
*properties
;
1380 /** RNA pointer to access properties. */
1385 * Struct to store tool-tip timer and possible creation if the time is reached.
1386 * Allows UI code to call #WM_tooltip_timer_init without each user having to handle the timer.
1388 struct wmTooltipState
{
1389 /** Create tooltip on this event. */
1391 /** The area the tooltip is created in. */
1393 /** The region the tooltip is created in. */
1394 ARegion
*region_from
;
1395 /** The tooltip region. */
1397 /** Create the tooltip region (assign to 'region'). */
1399 bContext
*C
, ARegion
*region
, int *pass
, double *pass_delay
, bool *r_exit_on_event
);
1400 /** Exit on any event, not needed for buttons since their highlight state is used. */
1402 /** Cursor location at the point of tooltip creation. */
1404 /** Pass, use when we want multiple tips, count down to zero. */
1408 /* *************** migrated stuff, clean later? ************** */
1411 RecentFile
*next
, *prev
;
1417 /* `wm_init_exit.cc`. */
1419 extern CLG_LogRef
*WM_LOG_OPERATORS
;
1420 extern CLG_LogRef
*WM_LOG_HANDLERS
;
1421 extern CLG_LogRef
*WM_LOG_EVENTS
;
1422 extern CLG_LogRef
*WM_LOG_KEYMAPS
;
1423 extern CLG_LogRef
*WM_LOG_TOOLS
;
1424 extern CLG_LogRef
*WM_LOG_MSGBUS_PUB
;
1425 extern CLG_LogRef
*WM_LOG_MSGBUS_SUB
;