Blender V4.5
wm_window.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved. 2007 Blender Authors.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <algorithm>
12#include <chrono>
13#include <cmath>
14#include <cstdio>
15#include <cstdlib>
16#include <cstring>
17#include <thread>
18
19#include <fmt/format.h>
20
21#include "CLG_log.h"
22
23#include "DNA_listBase.h"
24#include "DNA_screen_types.h"
26#include "DNA_workspace_types.h"
27
28#include "MEM_guardedalloc.h"
29
30#include "GHOST_C-api.h"
31
32#include "BLI_listbase.h"
33#include "BLI_math_vector.h"
34#include "BLI_path_utils.hh"
35#include "BLI_rect.h"
36#include "BLI_string.h"
37#include "BLI_string_utf8.h"
38#include "BLI_system.h"
39#include "BLI_time.h"
40#include "BLI_utildefines.h"
41
42#include "BLT_translation.hh"
43
44#include "BKE_autoexec.hh"
45#include "BKE_blender_version.h"
46#include "BKE_context.hh"
47#include "BKE_global.hh"
48#include "BKE_icons.h"
49#include "BKE_layer.hh"
50#include "BKE_main.hh"
51#include "BKE_report.hh"
52#include "BKE_screen.hh"
53#include "BKE_wm_runtime.hh"
54#include "BKE_workspace.hh"
55
56#include "RNA_access.hh"
57#include "RNA_enum_types.hh"
58
59#include "WM_api.hh"
60#include "WM_keymap.hh"
61#include "WM_types.hh"
62#include "wm.hh"
63#include "wm_draw.hh"
64#include "wm_event_system.hh"
65#include "wm_files.hh"
66#include "wm_window.hh"
67#include "wm_window_private.hh"
68#ifdef WITH_XR_OPENXR
69# include "wm_xr.hh"
70#endif
71
72#include "ED_anim_api.hh"
73#include "ED_fileselect.hh"
74#include "ED_render.hh"
75#include "ED_scene.hh"
76#include "ED_screen.hh"
77
78#include "IMB_imbuf.hh"
79#include "IMB_imbuf_types.hh"
80
81#include "UI_interface.hh"
82#include "UI_interface_icons.hh"
83
84#include "BLF_api.hh"
85#include "GPU_context.hh"
86#include "GPU_framebuffer.hh"
87#include "GPU_init_exit.hh"
88
89#include "UI_resources.hh"
90
91/* For assert. */
92#ifndef NDEBUG
93# include "BLI_threads.h"
94#endif
95
96/* The global to talk to GHOST. */
97static GHOST_SystemHandle g_system = nullptr;
98#if !(defined(WIN32) || defined(__APPLE__))
99static const char *g_system_backend_id = nullptr;
100#endif
101
107
108#define GHOST_WINDOW_STATE_DEFAULT GHOST_kWindowStateMaximized
109
134
135/* -------------------------------------------------------------------- */
138
139static const struct {
140 uint8_t flag;
143} g_modifier_table[] = {
144 {KM_SHIFT,
147 {KM_CTRL,
150 {KM_ALT,
153 {KM_OSKEY,
156 {KM_HYPER,
160
165
167
168/* -------------------------------------------------------------------- */
171
172static void wm_window_set_drawable(wmWindowManager *wm, wmWindow *win, bool activate);
173static bool wm_window_timers_process(const bContext *C, int *sleep_us_p);
174static uint8_t wm_ghost_modifier_query(const enum ModSide side);
175
176bool wm_get_screensize(int r_size[2])
177{
178 uint32_t uiwidth, uiheight;
179 if (GHOST_GetMainDisplayDimensions(g_system, &uiwidth, &uiheight) == GHOST_kFailure) {
180 return false;
181 }
182 r_size[0] = uiwidth;
183 r_size[1] = uiheight;
184 return true;
185}
186
187bool wm_get_desktopsize(int r_size[2])
188{
189 uint32_t uiwidth, uiheight;
190 if (GHOST_GetAllDisplayDimensions(g_system, &uiwidth, &uiheight) == GHOST_kFailure) {
191 return false;
192 }
193 r_size[0] = uiwidth;
194 r_size[1] = uiheight;
195 return true;
196}
197
199static void wm_window_check_size(rcti *rect)
200{
201 blender::int2 scr_size;
202 if (wm_get_screensize(scr_size)) {
203 if (BLI_rcti_size_x(rect) > scr_size[0]) {
204 BLI_rcti_resize_x(rect, scr_size[0]);
205 }
206 if (BLI_rcti_size_y(rect) > scr_size[1]) {
207 BLI_rcti_resize_y(rect, scr_size[1]);
208 }
209 }
210}
211
213{
214 if (UNLIKELY(!win->ghostwin)) {
215 return;
216 }
217
218 /* Prevents non-drawable state of main windows (bugs #22967,
219 * #25071 and possibly #22477 too). Always clear it even if
220 * this window was not the drawable one, because we mess with
221 * drawing context to discard the GW context. */
223
224 if (win == wm->winactive) {
225 wm->winactive = nullptr;
226 }
227
228 /* We need this window's GPU context active to discard it. */
229 GHOST_ActivateWindowDrawingContext(static_cast<GHOST_WindowHandle>(win->ghostwin));
230 GPU_context_active_set(static_cast<GPUContext *>(win->gpuctx));
231
232 /* Delete local GPU context. */
233 GPU_context_discard(static_cast<GPUContext *>(win->gpuctx));
234
235 GHOST_DisposeWindow(g_system, static_cast<GHOST_WindowHandle>(win->ghostwin));
236 win->ghostwin = nullptr;
237 win->gpuctx = nullptr;
238}
239
241{
242 /* Update context. */
243 if (C) {
246
247 if (CTX_wm_window(C) == win) {
248 CTX_wm_window_set(C, nullptr);
249 }
250 }
251
253
254 /* End running jobs, a job end also removes its timer. */
256 if (wt->flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
257 continue;
258 }
259 if (wt->win == win && wt->event_type == TIMERJOBS) {
260 wm_jobs_timer_end(wm, wt);
261 }
262 }
263
264 /* Timer removing, need to call this API function. */
266 if (wt->flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
267 continue;
268 }
269 if (wt->win == win) {
270 WM_event_timer_remove(wm, win, wt);
271 }
272 }
274
275 if (win->eventstate) {
276 MEM_freeN(win->eventstate);
277 }
278 if (win->event_last_handled) {
280 }
283 }
284
285 if (win->cursor_keymap_status) {
287 }
288
290
292
293 wm_ghostwindow_destroy(wm, win);
294
295 /* May be null for a window that was not completely read from an invalid file. */
296 if (win->workspace_hook) {
298 }
300
301 MEM_delete(win->runtime);
302 MEM_freeN(win);
303}
304
306{
307 int id = 1;
308
309 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
310 if (id <= win->winid) {
311 id = win->winid + 1;
312 }
313 }
314 return id;
315}
316
317wmWindow *wm_window_new(const Main *bmain, wmWindowManager *wm, wmWindow *parent, bool dialog)
318{
319 wmWindow *win = MEM_callocN<wmWindow>("window");
320
321 BLI_addtail(&wm->windows, win);
322 win->winid = find_free_winid(wm);
323
324 /* Dialogs may have a child window as parent. Otherwise, a child must not be a parent too. */
325 win->parent = (!dialog && parent && parent->parent) ? parent->parent : parent;
326 win->stereo3d_format = MEM_callocN<Stereo3dFormat>("Stereo 3D Format (window)");
328 win->runtime = MEM_new<blender::bke::WindowRuntime>(__func__);
329
330 return win;
331}
332
334 wmWindowManager *wm,
335 wmWindow *win_src,
336 const bool duplicate_layout,
337 const bool child)
338{
339 const bool is_dialog = GHOST_IsDialogWindow(static_cast<GHOST_WindowHandle>(win_src->ghostwin));
340 wmWindow *win_parent = (child) ? win_src : win_src->parent;
341 wmWindow *win_dst = wm_window_new(bmain, wm, win_parent, is_dialog);
342 WorkSpace *workspace = WM_window_get_active_workspace(win_src);
343 WorkSpaceLayout *layout_old = WM_window_get_active_layout(win_src);
344
345 win_dst->posx = win_src->posx + 10;
346 win_dst->posy = win_src->posy;
347 win_dst->sizex = win_src->sizex;
348 win_dst->sizey = win_src->sizey;
349
350 win_dst->scene = win_src->scene;
351 STRNCPY(win_dst->view_layer_name, win_src->view_layer_name);
352 BKE_workspace_active_set(win_dst->workspace_hook, workspace);
353 WorkSpaceLayout *layout_new = duplicate_layout ? ED_workspace_layout_duplicate(
354 bmain, workspace, layout_old, win_dst) :
355 layout_old;
356 BKE_workspace_active_layout_set(win_dst->workspace_hook, win_dst->winid, workspace, layout_new);
357
358 *win_dst->stereo3d_format = *win_src->stereo3d_format;
359
360 return win_dst;
361}
362
364 wmWindow *win_src,
365 const bool duplicate_layout,
366 const bool child)
367{
368 Main *bmain = CTX_data_main(C);
370
371 wmWindow *win_dst = wm_window_copy(bmain, wm, win_src, duplicate_layout, child);
372
373 WM_check(C);
374
375 if (win_dst->ghostwin) {
377 return win_dst;
378 }
379 wm_window_close(C, wm, win_dst);
380 return nullptr;
381}
382
384
385/* -------------------------------------------------------------------- */
388
389static void wm_save_file_on_quit_dialog_callback(bContext *C, void * /*user_data*/)
390{
392}
393
404
406{
407 wmWindow *win_ctx = CTX_wm_window(C);
408
409 /* The popup will be displayed in the context window which may not be set
410 * here (this function gets called outside of normal event handling loop). */
411 CTX_wm_window_set(C, win);
412
413 if (U.uiflag & USER_SAVE_PROMPT) {
415 !G.background)
416 {
417 wm_window_raise(win);
419 }
420 else {
422 }
423 }
424 else {
426 }
427
428 CTX_wm_window_set(C, win_ctx);
429}
430
432
433/* -------------------------------------------------------------------- */
436
438{
439 wmWindow *win_other;
440
441 /* First check if there is another main window remaining. */
442 for (win_other = static_cast<wmWindow *>(wm->windows.first); win_other;
443 win_other = win_other->next)
444 {
445 if (win_other != win && win_other->parent == nullptr && !WM_window_is_temp_screen(win_other)) {
446 break;
447 }
448 }
449
450 if (win->parent == nullptr && win_other == nullptr) {
452 return;
453 }
454
455 /* Close child windows. */
456 LISTBASE_FOREACH_MUTABLE (wmWindow *, iter_win, &wm->windows) {
457 if (iter_win->parent == win) {
458 wm_window_close(C, wm, iter_win);
459 }
460 }
461
465
466 BLI_remlink(&wm->windows, win);
467
468 CTX_wm_window_set(C, win); /* Needed by handlers. */
470
472
473 /* For regular use this will _never_ be nullptr,
474 * however we may be freeing an improperly initialized window. */
475 if (screen) {
476 ED_screen_exit(C, win, screen);
477 }
478
479 wm_window_free(C, wm, win);
480
481 /* If temp screen, delete it after window free (it stops jobs that can access it). */
482 if (screen && screen->temp) {
483 Main *bmain = CTX_data_main(C);
484
486 BKE_workspace_layout_remove(bmain, workspace, layout);
488 }
489
491}
492
493void WM_window_title(wmWindowManager *wm, wmWindow *win, const char *title)
494{
495 if (win->ghostwin == nullptr) {
496 return;
497 }
498
499 GHOST_WindowHandle handle = static_cast<GHOST_WindowHandle>(win->ghostwin);
500
501 if (title) {
502 GHOST_SetTitle(handle, title);
503 return;
504 }
505
506 if (win->parent || WM_window_is_temp_screen(win)) {
507 /* Not a main window. */
509 const bool is_single = screen && BLI_listbase_is_single(&screen->areabase);
510 ScrArea *area = (screen) ? static_cast<ScrArea *>(screen->areabase.first) : nullptr;
511 const char *name = "Blender";
512 if (is_single && area && area->spacetype != SPACE_EMPTY) {
513 name = IFACE_(ED_area_name(area).c_str());
514 }
515 GHOST_SetTitle(handle, name);
516 return;
517 }
518
519 /* This path may contain invalid UTF8 byte sequences on UNIX systems,
520 * use `filepath` for display which is sanitized as needed. */
521 const char *filepath_as_bytes = BKE_main_blendfile_path_from_global();
522
523 char _filepath_utf8_buf[FILE_MAX];
524 /* Allow non-UTF8 characters on systems that support it.
525 *
526 * On Wayland, invalid UTF8 characters will disconnect
527 * from the server - exiting immediately. */
528 const char *filepath = (OS_MAC || OS_WINDOWS) ?
529 filepath_as_bytes :
531 strlen(filepath_as_bytes),
532 '?',
533 _filepath_utf8_buf,
534 sizeof(_filepath_utf8_buf));
535
536 const char *filename = BLI_path_basename(filepath);
537 const bool has_filepath = filepath[0] != '\0';
538 const bool native_filepath_display = GHOST_SetPath(handle, filepath_as_bytes) == GHOST_kSuccess;
539 const bool include_filepath = has_filepath && (filepath != filename) && !native_filepath_display;
540
541 /* File saved state. */
542 std::string win_title = wm->file_saved ? "" : "* ";
543
544 /* File name. Show the file extension if the full file path is not included in the title. */
545 if (include_filepath) {
546 const size_t filename_no_ext_len = BLI_path_extension_or_end(filename) - filename;
547 win_title.append(filename, filename_no_ext_len);
548 }
549 else if (has_filepath) {
550 win_title.append(filename);
551 }
552 /* New / Unsaved file default title. Shows "Untitled" on macOS following the Apple HIGs. */
553 else {
554#ifdef __APPLE__
555 win_title.append(IFACE_("Untitled"));
556#else
557 win_title.append(IFACE_("(Unsaved)"));
558#endif
559 }
560
561 if (G_MAIN->recovered) {
562 win_title.append(IFACE_(" (Recovered)"));
563 }
564
565 if (include_filepath) {
566 win_title.append(fmt::format(" [{}]", filepath));
567 }
568
569 win_title.append(fmt::format(" - Blender {}", BKE_blender_version_string()));
570
571 GHOST_SetTitle(handle, win_title.c_str());
572
573 /* Informs GHOST of unsaved changes to set the window modified visual indicator (macOS)
574 * and to give a hint of unsaved changes for a user warning mechanism in case of OS application
575 * terminate request (e.g., OS Shortcut Alt+F4, Command+Q, (...) or session end). */
577}
578
580{
581 float auto_dpi = GHOST_GetDPIHint(static_cast<GHOST_WindowHandle>(win->ghostwin));
582
583 /* Clamp auto DPI to 96, since our font/interface drawing does not work well
584 * with lower sizes. The main case we are interested in supporting is higher
585 * DPI. If a smaller UI is desired it is still possible to adjust UI scale. */
586 auto_dpi = max_ff(auto_dpi, 96.0f);
587
588 /* Lazily init UI scale size, preserving backwards compatibility by
589 * computing UI scale from ratio of previous DPI and auto DPI. */
590 if (U.ui_scale == 0) {
591 int virtual_pixel = (U.virtual_pixel == VIRTUAL_PIXEL_NATIVE) ? 1 : 2;
592
593 if (U.dpi == 0) {
594 U.ui_scale = virtual_pixel;
595 }
596 else {
597 U.ui_scale = (virtual_pixel * U.dpi * 96.0f) / (auto_dpi * 72.0f);
598 }
599
600 CLAMP(U.ui_scale, 0.25f, 4.0f);
601 }
602
603 /* Blender's UI drawing assumes DPI 72 as a good default following macOS
604 * while Windows and Linux use DPI 96. GHOST assumes a default 96 so we
605 * remap the DPI to Blender's convention. */
606 auto_dpi *= GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
607 U.dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f);
608
609 /* Automatically set larger pixel size for high DPI. */
610 int pixelsize = max_ii(1, (U.dpi / 64));
611 /* User adjustment for pixel size. */
612 pixelsize = max_ii(1, pixelsize + U.ui_line_width);
613
614 /* Set user preferences globals for drawing, and for forward compatibility. */
615 U.pixelsize = pixelsize;
616 U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE;
617 U.scale_factor = U.dpi / 72.0f;
618 U.inv_scale_factor = 1.0f / U.scale_factor;
619
620 /* Widget unit is 20 pixels at 1X scale. This consists of 18 user-scaled units plus
621 * left and right borders of line-width (pixel-size). */
622 U.widget_unit = int(roundf(18.0f * U.scale_factor)) + (2 * pixelsize);
623}
624
626
627/* -------------------------------------------------------------------- */
630
632{
634 static_cast<GHOST_WindowHandle>(win->ghostwin));
635
637
638 if (ghost_style_flags & GHOST_kDecorationColoredTitleBar) {
640 }
641
642 return wm_style_flags;
643}
644
647{
649 uint ghost_style_flags = GHOST_kDecorationNone;
650
652 ghost_style_flags |= GHOST_kDecorationColoredTitleBar;
653 }
654
656 static_cast<GHOST_WindowHandle>(win->ghostwin),
657 static_cast<GHOST_TWindowDecorationStyleFlags>(ghost_style_flags));
658}
659
660static void wm_window_decoration_style_set_from_theme(const wmWindow *win, const bScreen *screen)
661{
662 /* Set the decoration style settings from the current theme colors.
663 * NOTE: screen may be null. In which case, only the window is used as a theme provider. */
664 GHOST_WindowDecorationStyleSettings decoration_settings = {};
665
666 /* Colored TitleBar Decoration. */
667 /* For main windows, use the top-bar color. */
670 }
671 /* For single editor floating windows, use the editor header color. */
672 else if (screen && BLI_listbase_is_single(&screen->areabase)) {
673 const ScrArea *main_area = static_cast<ScrArea *>(screen->areabase.first);
675 }
676 /* For floating window with multiple editors/areas, use the default space color. */
677 else {
679 }
680
681 float titlebar_bg_color[3], titlebar_fg_color[3];
682 UI_GetThemeColor3fv(TH_BACK, titlebar_bg_color);
683 UI_GetThemeColor3fv(TH_BUTBACK_TEXT, titlebar_fg_color);
684 copy_v3_v3(decoration_settings.colored_titlebar_bg_color, titlebar_bg_color);
685 copy_v3_v3(decoration_settings.colored_titlebar_fg_color, titlebar_fg_color);
686
687 GHOST_SetWindowDecorationStyleSettings(static_cast<GHOST_WindowHandle>(win->ghostwin),
688 decoration_settings);
689}
690
697
709 wmWindow *win,
710 const uint64_t event_time_ms)
711{
712 const uint8_t keymodifier_sided[2] = {
715 };
716 const uint8_t keymodifier = keymodifier_sided[0] | keymodifier_sided[1];
717 const uint8_t keymodifier_eventstate = win->eventstate->modifier;
718 if (keymodifier != keymodifier_eventstate) {
719 GHOST_TEventKeyData kdata{};
720 kdata.key = GHOST_kKeyUnknown;
721 kdata.utf8_buf[0] = '\0';
722 kdata.is_repeat = false;
723 for (int i = 0; i < ARRAY_SIZE(g_modifier_table); i++) {
724 if (keymodifier_eventstate & g_modifier_table[i].flag) {
725 if ((keymodifier & g_modifier_table[i].flag) == 0) {
726 for (int side = 0; side < 2; side++) {
727 if ((keymodifier_sided[side] & g_modifier_table[i].flag) == 0) {
728 kdata.key = g_modifier_table[i].ghost_key_pair[side];
729 wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata, event_time_ms);
730 /* Only ever send one release event
731 * (currently releasing multiple isn't needed and only confuses logic). */
732 break;
733 }
734 }
735 }
736 }
737 else {
738 if (keymodifier & g_modifier_table[i].flag) {
739 for (int side = 0; side < 2; side++) {
740 if (keymodifier_sided[side] & g_modifier_table[i].flag) {
741 kdata.key = g_modifier_table[i].ghost_key_pair[side];
742 wm_event_add_ghostevent(wm, win, GHOST_kEventKeyDown, &kdata, event_time_ms);
743 }
744 }
745 }
746 }
747 }
748 }
749}
750
764 wmWindow *win,
765 const uint64_t event_time_ms)
766{
767 /* Release all held modifiers before de-activating the window. */
768 if (win->eventstate->modifier != 0) {
769 const uint8_t keymodifier_eventstate = win->eventstate->modifier;
770 const uint8_t keymodifier_l = wm_ghost_modifier_query(MOD_SIDE_LEFT);
771 const uint8_t keymodifier_r = wm_ghost_modifier_query(MOD_SIDE_RIGHT);
772 /* NOTE(@ideasman42): when non-zero, there are modifiers held in
773 * `win->eventstate` which are not considered held by the GHOST internal state.
774 * While this should not happen, it's important all modifier held in event-state
775 * receive release events. Without this, so any events generated while the window
776 * is *not* active will have modifiers held. */
777 const uint8_t keymodifier_unhandled = keymodifier_eventstate &
778 ~(keymodifier_l | keymodifier_r);
779 const uint8_t keymodifier_sided[2] = {
780 uint8_t(keymodifier_l | keymodifier_unhandled),
781 keymodifier_r,
782 };
783 GHOST_TEventKeyData kdata{};
784 kdata.key = GHOST_kKeyUnknown;
785 kdata.utf8_buf[0] = '\0';
786 kdata.is_repeat = false;
787 for (int i = 0; i < ARRAY_SIZE(g_modifier_table); i++) {
788 if (keymodifier_eventstate & g_modifier_table[i].flag) {
789 for (int side = 0; side < 2; side++) {
790 if ((keymodifier_sided[side] & g_modifier_table[i].flag) == 0) {
791 kdata.key = g_modifier_table[i].ghost_key_pair[side];
792 wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata, event_time_ms);
793 }
794 }
795 }
796 }
797 }
798}
799
801{
802 /* Update mouse position when a window is activated. */
803 int xy[2];
804 if (wm_cursor_position_get(win, &xy[0], &xy[1])) {
805 copy_v2_v2_int(win->eventstate->xy, xy);
806 }
807}
808
810{
811 if (win->eventstate) {
812 return;
813 }
814
815 win->eventstate = MEM_callocN<wmEvent>("window event state");
817}
818
820
821/* Belongs to below. */
823 const char *title,
824 wmWindow *win,
825 bool is_dialog)
826{
827 /* A new window is created when page-flip mode is required for a window. */
828 GHOST_GPUSettings gpuSettings = {0};
830 gpuSettings.flags |= GHOST_gpuStereoVisual;
831 }
832
833 if (G.debug & G_DEBUG_GPU) {
834 gpuSettings.flags |= GHOST_gpuDebugContext;
835 }
836
838 gpuSettings.context_type = wm_ghost_drawing_context_type(gpu_backend);
839 gpuSettings.preferred_device.index = U.gpu_preferred_index;
840 gpuSettings.preferred_device.vendor_id = U.gpu_preferred_vendor_id;
841 gpuSettings.preferred_device.device_id = U.gpu_preferred_device_id;
842
843 int posx = 0;
844 int posy = 0;
845
847 blender::int2 scr_size;
848 if (wm_get_desktopsize(scr_size)) {
849 posx = win->posx;
850 posy = (scr_size[1] - win->posy - win->sizey);
851 }
852 }
853
854 /* Clear drawable so we can set the new window. */
855 wmWindow *prev_windrawable = wm->windrawable;
857
858 GHOST_WindowHandle ghostwin = GHOST_CreateWindow(
859 g_system,
860 static_cast<GHOST_WindowHandle>((win->parent) ? win->parent->ghostwin : nullptr),
861 title,
862 posx,
863 posy,
864 win->sizex,
865 win->sizey,
867 is_dialog,
868 gpuSettings);
869
870 if (ghostwin) {
871 win->gpuctx = GPU_context_create(ghostwin, nullptr);
873
874 /* Needed so we can detect the graphics card below. */
875 GPU_init();
876
877 /* Set window as drawable upon creation. Note this has already been
878 * it has already been activated by GHOST_CreateWindow. */
879 wm_window_set_drawable(wm, win, false);
880
881 win->ghostwin = ghostwin;
882 GHOST_SetWindowUserData(ghostwin, win); /* Pointer back. */
883
885
886 /* Store actual window size in blender window. */
887 /* WIN32: gives undefined window size when minimized. */
888 if (GHOST_GetWindowState(static_cast<GHOST_WindowHandle>(win->ghostwin)) !=
890 {
892 }
893
894#ifndef __APPLE__
895 /* Set the state here, so minimized state comes up correct on windows. */
898 }
899#endif
900
901 /* Get the window background color from the current theme. Using the top-bar header
902 * background theme color to match with the colored title-bar decoration style. */
903 float window_bg_color[3];
905 UI_GetThemeColor3fv(TH_BACK, window_bg_color);
906
907 /* Until screens get drawn, draw a default background using the window theme color. */
908 GPU_clear_color(window_bg_color[0], window_bg_color[1], window_bg_color[2], 1.0f);
909
910 /* Needed here, because it's used before it reads #UserDef. */
912
914
915 /* Clear double buffer to avoids flickering of new windows on certain drivers, see #97600. */
916 GPU_clear_color(window_bg_color[0], window_bg_color[1], window_bg_color[2], 1.0f);
917
919 }
920 else {
921 wm_window_set_drawable(wm, prev_windrawable, false);
922 }
923}
924
925static void wm_window_ghostwindow_ensure(wmWindowManager *wm, wmWindow *win, bool is_dialog)
926{
927 if (win->ghostwin == nullptr) {
928 if ((win->sizex == 0) || (wm_init_state.override_flag & WIN_OVERRIDE_GEOM)) {
929 win->posx = wm_init_state.start[0];
930 win->posy = wm_init_state.start[1];
931 win->sizex = wm_init_state.size[0];
932 win->sizey = wm_init_state.size[1];
933
937 }
938 else {
940 }
941 }
942
946 }
947
948 /* Without this, cursor restore may fail, see: #45456. */
949 if (win->cursor == 0) {
951 }
952
953 wm_window_ghostwindow_add(wm, "Blender", win, is_dialog);
954 }
955
956 if (win->ghostwin != nullptr) {
957 /* If we have no `ghostwin` this is a buggy window that should be removed.
958 * However we still need to initialize it correctly so the screen doesn't hang. */
959
960 /* Happens after file-read. */
962
964
966 /* Only decoration style we have for now. */
969 }
970 }
971
972 /* Add key-map handlers (1 handler for all keys in map!). */
975
978
979 keymap = WM_keymap_ensure(wm->defaultconf, "Screen Editing", SPACE_EMPTY, RGN_TYPE_WINDOW);
981
982 /* Add drop boxes. */
983 {
986 }
987 WM_window_title(wm, win);
988
989 /* Add top-bar. */
991}
992
994{
995 BLI_assert(G.background == false);
996
997 /* No command-line prefsize? then we set this.
998 * Note that these values will be used only
999 * when there is no startup.blend yet.
1000 */
1001 if (wm_init_state.size[0] == 0) {
1003 /* Use fallback values. */
1005 }
1006
1007 /* NOTE: this isn't quite correct, active screen maybe offset 1000s if PX,
1008 * we'd need a #wm_get_screensize like function that gives offset,
1009 * in practice the window manager will likely move to the correct monitor. */
1011 }
1012
1013 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
1014 wm_window_ghostwindow_ensure(wm, win, false);
1015 }
1016}
1017
1019{
1020 BLI_assert(G.background == false);
1021
1023 if (win->ghostwin == nullptr) {
1024 wm_window_close(C, wm, win);
1025 }
1026 }
1027}
1028
1029/* Update window size and position based on data from GHOST window. */
1031{
1032 GHOST_RectangleHandle client_rect = GHOST_GetClientBounds(
1033 static_cast<GHOST_WindowHandle>(win->ghostwin));
1034 int l, t, r, b;
1035 GHOST_GetRectangle(client_rect, &l, &t, &r, &b);
1036
1037 GHOST_DisposeRectangle(client_rect);
1038
1039 int sizex = r - l;
1040 int sizey = b - t;
1041
1042 int posx = 0;
1043 int posy = 0;
1044
1046 blender::int2 scr_size;
1047 if (wm_get_desktopsize(scr_size)) {
1048 posx = l;
1049 posy = scr_size[1] - t - win->sizey;
1050 }
1051 }
1052
1053 if (win->sizex != sizex || win->sizey != sizey || win->posx != posx || win->posy != posy) {
1054 win->sizex = sizex;
1055 win->sizey = sizey;
1056 win->posx = posx;
1057 win->posy = posy;
1058 return true;
1059 }
1060 return false;
1061}
1062
1064 const char *title,
1065 const rcti *rect_unscaled,
1066 int space_type,
1067 bool toplevel,
1068 bool dialog,
1069 bool temp,
1070 eWindowAlignment alignment,
1071 void (*area_setup_fn)(bScreen *screen, ScrArea *area, void *user_data),
1072 void *area_setup_user_data)
1073{
1074 Main *bmain = CTX_data_main(C);
1076 wmWindow *win_prev = CTX_wm_window(C);
1077 Scene *scene = CTX_data_scene(C);
1078 ViewLayer *view_layer = CTX_data_view_layer(C);
1079 int x = rect_unscaled->xmin;
1080 int y = rect_unscaled->ymin;
1081 /* Duplicated windows are created at Area size, so duplicated
1082 * minimized areas can init at 2 pixels high before being
1083 * resized at the end of window creation. Therefore minimums. */
1084 int sizex = std::max(BLI_rcti_size_x(rect_unscaled), 200);
1085 int sizey = std::max(BLI_rcti_size_y(rect_unscaled), 150);
1086 rcti rect;
1087
1088 const float native_pixel_size = GHOST_GetNativePixelSize(
1089 static_cast<GHOST_WindowHandle>(win_prev->ghostwin));
1090 /* Convert to native OS window coordinates. */
1091 rect.xmin = win_prev->posx + (x / native_pixel_size);
1092 rect.ymin = win_prev->posy + (y / native_pixel_size);
1093 sizex /= native_pixel_size;
1094 sizey /= native_pixel_size;
1095
1096 if (alignment == WIN_ALIGN_LOCATION_CENTER) {
1097 /* Window centered around x,y location. */
1098 rect.xmin -= sizex / 2;
1099 rect.ymin -= sizey / 2;
1100 }
1101 else if (alignment == WIN_ALIGN_PARENT_CENTER) {
1102 /* Centered within parent. X,Y as offsets from there. */
1103 rect.xmin += (win_prev->sizex - sizex) / 2;
1104 rect.ymin += (win_prev->sizey - sizey) / 2;
1105 }
1106 else {
1107 /* Positioned absolutely within parent bounds. */
1108 }
1109
1110 rect.xmax = rect.xmin + sizex;
1111 rect.ymax = rect.ymin + sizey;
1112
1113 /* Changes rect to fit within desktop. */
1114 wm_window_check_size(&rect);
1115
1116 /* Reuse temporary windows when they share the same single area. */
1117 wmWindow *win = nullptr;
1118 if (temp) {
1119 LISTBASE_FOREACH (wmWindow *, win_iter, &wm->windows) {
1120 const bScreen *screen = WM_window_get_active_screen(win_iter);
1121 if (screen && screen->temp && BLI_listbase_is_single(&screen->areabase)) {
1122 ScrArea *area = static_cast<ScrArea *>(screen->areabase.first);
1123 if (space_type == (area->butspacetype ? area->butspacetype : area->spacetype)) {
1124 win = win_iter;
1125 break;
1126 }
1127 }
1128 }
1129 }
1130
1131 /* Add new window? */
1132 if (win == nullptr) {
1133 win = wm_window_new(bmain, wm, toplevel ? nullptr : win_prev, dialog);
1134 win->posx = rect.xmin;
1135 win->posy = rect.ymin;
1136 win->sizex = BLI_rcti_size_x(&rect);
1137 win->sizey = BLI_rcti_size_y(&rect);
1138 *win->stereo3d_format = *win_prev->stereo3d_format;
1139 }
1140
1141 bScreen *screen = WM_window_get_active_screen(win);
1142
1143 if (WM_window_get_active_workspace(win) == nullptr) {
1144 WorkSpace *workspace = WM_window_get_active_workspace(win_prev);
1146 }
1147
1148 if (screen == nullptr) {
1149 /* Add new screen layout. */
1150 WorkSpace *workspace = WM_window_get_active_workspace(win);
1151 WorkSpaceLayout *layout = ED_workspace_layout_add(bmain, workspace, win, "temp");
1152
1153 screen = BKE_workspace_layout_screen_get(layout);
1154 WM_window_set_active_layout(win, workspace, layout);
1155 }
1156
1157 /* Set scene and view layer to match original window. */
1158 STRNCPY(win->view_layer_name, view_layer->name);
1159 if (WM_window_get_active_scene(win) != scene) {
1160 /* No need to refresh the tool-system as the window has not yet finished being setup. */
1161 ED_screen_scene_change(C, win, scene, false);
1162 }
1163
1164 screen->temp = temp;
1165
1166 /* Make window active, and validate/resize. */
1167 CTX_wm_window_set(C, win);
1168 const bool new_window = (win->ghostwin == nullptr);
1169 if (new_window) {
1170 wm_window_ghostwindow_ensure(wm, win, dialog);
1171 }
1172 WM_check(C);
1173
1174 /* It's possible `win->ghostwin == nullptr`.
1175 * instead of attempting to cleanup here (in a half finished state),
1176 * finish setting up the screen, then free it at the end of the function,
1177 * to avoid having to take into account a partially-created window.
1178 */
1179
1180 if (area_setup_fn) {
1181 /* When the caller is setting up the area, it should always be empty
1182 * because it's expected the callback sets the type. */
1183 BLI_assert(space_type == SPACE_EMPTY);
1184 /* NOTE(@ideasman42): passing in a callback to setup the `area` is admittedly awkward.
1185 * This is done so #ED_screen_refresh has a valid area to initialize,
1186 * otherwise it will attempt to make the empty area usable via #ED_area_init.
1187 * While refreshing the window could be postponed this makes the state of the
1188 * window less predictable to the caller. */
1189 ScrArea *area = static_cast<ScrArea *>(screen->areabase.first);
1190 area_setup_fn(screen, area, area_setup_user_data);
1191 CTX_wm_area_set(C, area);
1192 }
1193 else if (space_type != SPACE_EMPTY) {
1194 /* Ensure it shows the right space-type editor. */
1195 ScrArea *area = static_cast<ScrArea *>(screen->areabase.first);
1196 CTX_wm_area_set(C, area);
1197 ED_area_newspace(C, area, space_type, false);
1198 }
1199
1200 ED_screen_change(C, screen);
1201
1202 if (!new_window) {
1203 /* Set size in GHOST window and then update size and position from GHOST,
1204 * in case they where changed by GHOST to fit the monitor/screen. */
1205 wm_window_set_size(win, win->sizex, win->sizey);
1207 }
1208
1209 /* Refresh screen dimensions, after the effective window size is known. */
1210 ED_screen_refresh(C, wm, win);
1211
1212 if (win->ghostwin) {
1213 wm_window_raise(win);
1214 WM_window_title(wm, win, title);
1215 return win;
1216 }
1217
1218 /* Very unlikely! but opening a new window can fail. */
1219 wm_window_close(C, wm, win);
1220 CTX_wm_window_set(C, win_prev);
1221
1222 return nullptr;
1223}
1224
1226
1227/* -------------------------------------------------------------------- */
1230
1238
1240{
1241 wmWindow *win_src = CTX_wm_window(C);
1243 const rcti window_rect = {
1244 /*xmin*/ 0,
1245 /*xmax*/ int(win_src->sizex * 0.95f),
1246 /*ymin*/ 0,
1247 /*ymax*/ int(win_src->sizey * 0.9f),
1248 };
1249
1250 bool ok = (WM_window_open(C,
1251 nullptr,
1252 &window_rect,
1253 area->spacetype,
1254 false,
1255 false,
1256 false,
1258 nullptr,
1259 nullptr) != nullptr);
1260
1261 if (!ok) {
1262 BKE_report(op->reports, RPT_ERROR, "Failed to create window");
1263 return OPERATOR_CANCELLED;
1264 }
1265 return OPERATOR_FINISHED;
1266}
1267
1269{
1270 wmWindow *win_src = CTX_wm_window(C);
1271
1272 bool ok = (wm_window_copy_test(C, win_src, true, false) != nullptr);
1273 if (!ok) {
1274 BKE_report(op->reports, RPT_ERROR, "Failed to create window");
1275 return OPERATOR_CANCELLED;
1276 }
1277 return OPERATOR_FINISHED;
1278}
1279
1281{
1282 wmWindow *window = CTX_wm_window(C);
1283
1284 if (G.background) {
1285 return OPERATOR_CANCELLED;
1286 }
1287
1289 static_cast<GHOST_WindowHandle>(window->ghostwin));
1291 GHOST_SetWindowState(static_cast<GHOST_WindowHandle>(window->ghostwin),
1293 }
1294 else {
1295 GHOST_SetWindowState(static_cast<GHOST_WindowHandle>(window->ghostwin),
1297 }
1298
1299 return OPERATOR_FINISHED;
1300}
1301
1303
1304/* -------------------------------------------------------------------- */
1307
1309{
1310 float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
1311 *x *= fac;
1312
1313 *y = (win->sizey - 1) - *y;
1314 *y *= fac;
1315}
1316
1318{
1319 float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
1320
1321 *x /= fac;
1322 *y /= fac;
1323 *y = win->sizey - *y - 1;
1324}
1325
1327{
1328 GHOST_ScreenToClient(static_cast<GHOST_WindowHandle>(win->ghostwin), *x, *y, x, y);
1330}
1331
1333{
1335 GHOST_ClientToScreen(static_cast<GHOST_WindowHandle>(win->ghostwin), *x, *y, x, y);
1336}
1337
1338bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
1339{
1340 if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) {
1341 *r_x = win->eventstate->xy[0];
1342 *r_y = win->eventstate->xy[1];
1343 return true;
1344 }
1345
1347 g_system, static_cast<GHOST_WindowHandle>(win->ghostwin), r_x, r_y) == GHOST_kSuccess)
1348 {
1350 return true;
1351 }
1352
1353 return false;
1354}
1355
1357static uint8_t wm_ghost_modifier_query(const enum ModSide side)
1358{
1359 uint8_t result = 0;
1360 for (int i = 0; i < ARRAY_SIZE(g_modifier_table); i++) {
1361 bool val = false;
1362 GHOST_GetModifierKeyState(g_system, g_modifier_table[i].ghost_mask_pair[side], &val);
1363 if (val) {
1364 result |= g_modifier_table[i].flag;
1365 }
1366 }
1367 return result;
1368}
1369
1371{
1372 BLI_assert(ELEM(wm->windrawable, nullptr, win));
1373
1374 wm->windrawable = win;
1375 if (activate) {
1376 GHOST_ActivateWindowDrawingContext(static_cast<GHOST_WindowHandle>(win->ghostwin));
1377 }
1378 GPU_context_active_set(static_cast<GPUContext *>(win->gpuctx));
1379}
1380
1382{
1383 if (wm->windrawable) {
1384 wm->windrawable = nullptr;
1385 }
1386}
1387
1389{
1391
1392 if (win != wm->windrawable && win->ghostwin) {
1393 // win->lmbut = 0; /* Keeps hanging when mouse-pressed while other window opened. */
1395
1396 if (G.debug & G_DEBUG_EVENTS) {
1397 printf("%s: set drawable %d\n", __func__, win->winid);
1398 }
1399
1400 wm_window_set_drawable(wm, win, true);
1401 }
1402
1403 if (win->ghostwin) {
1404 /* This can change per window. */
1405 WM_window_set_dpi(win);
1406 }
1407}
1408
1410{
1413 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
1414
1415 if (wm == nullptr) {
1416 return;
1417 }
1418 wmWindow *win = wm->windrawable;
1419
1420 if (win && win->ghostwin) {
1422 wm_window_set_drawable(wm, win, true);
1423 }
1424}
1425
1426#ifndef NDEBUG
1431static void ghost_event_proc_timestamp_warning(GHOST_EventHandle ghost_event)
1432{
1433 /* NOTE: The following time constants can be tweaked if they're reporting false positives. */
1434
1435 /* The reference event time-stamp must have happened in this time-frame. */
1436 constexpr uint64_t event_time_ok_ms = 1000;
1437 /* The current event time-stamp must be outside this time-frame to be considered an error. */
1438 constexpr uint64_t event_time_error_ms = 5000;
1439
1440 static uint64_t event_ms_ref_last = std::numeric_limits<uint64_t>::max();
1441 const uint64_t event_ms = GHOST_GetEventTime(ghost_event);
1442 const uint64_t event_ms_ref = event_ms_ref_last;
1443
1444 /* Assign first (allow early returns). */
1445 event_ms_ref_last = event_ms;
1446
1447 if (event_ms_ref == std::numeric_limits<uint64_t>::max()) {
1448 return;
1449 }
1450 /* Check the events are recent enough to be used for testing. */
1451 const uint64_t now_ms = GHOST_GetMilliSeconds(g_system);
1452 /* Ensure the reference time occurred in the last #event_time_ok_ms.
1453 * If not, the reference time it's self may be a bad time-stamp. */
1454 if (event_ms_ref < event_time_error_ms || (event_ms_ref < (now_ms - event_time_ok_ms)) ||
1455 (event_ms_ref > (now_ms + event_time_ok_ms)))
1456 {
1457 /* Skip, the reference time not recent enough to be used. */
1458 return;
1459 }
1460
1461 /* NOTE: Regarding time-stamps from the future.
1462 * Generally this shouldn't happen but may do depending on the kinds of events.
1463 * Different input methods may detect and trigger events in a way that wont ensure
1464 * monotonic event times, so only consider this an error for large time deltas. */
1465 double time_delta = 0.0;
1466 if (event_ms < (event_ms_ref - event_time_error_ms)) {
1467 /* New event time is after (to be expected). */
1468 time_delta = double(now_ms - event_ms) / -1000.0;
1469 }
1470 else if (event_ms > (event_ms_ref + event_time_error_ms)) {
1471 /* New event time is before (unexpected but not an error). */
1472 time_delta = double(event_ms - now_ms) / 1000.0;
1473 }
1474 else {
1475 /* Time is in range. */
1476 return;
1477 }
1478
1479 const char *time_unit = "seconds";
1480 const struct {
1481 const char *unit;
1482 double scale;
1483 } unit_table[] = {{"minutes", 60}, {"hours", 60}, {"days", 24}, {"weeks", 7}, {"years", 52}};
1484 for (int i = 0; i < ARRAY_SIZE(unit_table); i++) {
1485 if (std::abs(time_delta) <= unit_table[i].scale) {
1486 break;
1487 }
1488 time_delta /= unit_table[i].scale;
1489 time_unit = unit_table[i].unit;
1490 }
1491
1492 fprintf(stderr,
1493 "GHOST: suspicious time-stamp from far in the %s: %.2f %s, "
1494 "absolute value is %" PRIu64 ", current time is %" PRIu64 ", for type %d\n",
1495 time_delta < 0.0f ? "past" : "future",
1496 std::abs(time_delta),
1497 time_unit,
1498 event_ms,
1499 now_ms,
1500 int(GHOST_GetEventType(ghost_event)));
1501}
1502#endif /* !NDEBUG */
1503
1509static bool ghost_event_proc(GHOST_EventHandle ghost_event, GHOST_TUserDataPtr C_void_ptr)
1510{
1511 bContext *C = static_cast<bContext *>(C_void_ptr);
1513 GHOST_TEventType type = GHOST_GetEventType(ghost_event);
1514
1515 GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(ghost_event);
1516
1517#ifndef NDEBUG
1519#endif
1520
1521 if (type == GHOST_kEventQuitRequest) {
1522 /* Find an active window to display quit dialog in. */
1523 wmWindow *win;
1524 if (ghostwin && GHOST_ValidWindow(g_system, ghostwin)) {
1525 win = static_cast<wmWindow *>(GHOST_GetWindowUserData(ghostwin));
1526 }
1527 else {
1528 win = wm->winactive;
1529 }
1530
1531 /* Display quit dialog or quit immediately. */
1532 if (win) {
1534 }
1535 else {
1537 }
1538 return true;
1539 }
1540
1542 const uint64_t event_time_ms = GHOST_GetEventTime(ghost_event);
1543
1544 /* Ghost now can call this function for life resizes,
1545 * but it should return if WM didn't initialize yet.
1546 * Can happen on file read (especially full size window). */
1547 if ((wm->init_flag & WM_INIT_FLAG_WINDOW) == 0) {
1548 return true;
1549 }
1550 if (!ghostwin) {
1551 /* XXX: should be checked, why are we getting an event here, and what is it? */
1552 puts("<!> event has no window");
1553 return true;
1554 }
1555 if (!GHOST_ValidWindow(g_system, ghostwin)) {
1556 /* XXX: should be checked, why are we getting an event here, and what is it? */
1557 puts("<!> event has invalid window");
1558 return true;
1559 }
1560
1561 wmWindow *win = static_cast<wmWindow *>(GHOST_GetWindowUserData(ghostwin));
1562
1563 switch (type) {
1565 wm_window_update_eventstate_modifiers_clear(wm, win, event_time_ms);
1566
1567 wm_event_add_ghostevent(wm, win, type, data, event_time_ms);
1568 win->active = 0;
1569 break;
1570 }
1572 /* Ensure the event state matches modifiers (window was inactive). */
1573 wm_window_update_eventstate_modifiers(wm, win, event_time_ms);
1574
1575 /* Entering window, update mouse position (without sending an event). */
1577
1578 /* No context change! `C->wm->windrawable` is drawable, or for area queues. */
1579 wm->winactive = win;
1580 win->active = 1;
1581
1582 /* Zero the `keymodifier`, it hangs on hotkeys that open windows otherwise. */
1584
1585 win->addmousemove = 1; /* Enables highlighted buttons. */
1586
1587 wm_window_make_drawable(wm, win);
1588
1589 /* NOTE(@sergey): Window might be focused by mouse click in configuration of window manager
1590 * when focus is not following mouse
1591 * click could have been done on a button and depending on window manager settings
1592 * click would be passed to blender or not, but in any case button under cursor
1593 * should be activated, so at max next click on button without moving mouse
1594 * would trigger its handle function
1595 * currently it seems to be common practice to generate new event for, but probably
1596 * we'll need utility function for this?
1597 */
1598 wmEvent event;
1599 wm_event_init_from_window(win, &event);
1600 event.type = MOUSEMOVE;
1601 event.val = KM_NOTHING;
1602 copy_v2_v2_int(event.prev_xy, event.xy);
1603 event.flag = eWM_EventFlag(0);
1604
1605 WM_event_add(win, &event);
1606
1607 break;
1608 }
1610 wm_window_close(C, wm, win);
1611 break;
1612 }
1614 if (G.debug & G_DEBUG_EVENTS) {
1615 printf("%s: ghost redraw %d\n", __func__, win->winid);
1616 }
1617
1618 wm_window_make_drawable(wm, win);
1619 WM_event_add_notifier_ex(wm, win, NC_WINDOW, nullptr);
1620
1621 break;
1622 }
1624 if (G.debug & G_DEBUG_EVENTS) {
1625 printf("%s: ghost redraw decor %d\n", __func__, win->winid);
1626 }
1627
1628 wm_window_make_drawable(wm, win);
1629#if 0
1630 /* NOTE(@ideasman42): Ideally we could swap-buffers to avoid a full redraw.
1631 * however this causes window flickering on resize with LIBDECOR under WAYLAND. */
1633#else
1634 WM_event_add_notifier_ex(wm, win, NC_WINDOW, nullptr);
1635#endif
1636
1637 break;
1638 }
1642 static_cast<GHOST_WindowHandle>(win->ghostwin));
1643 win->windowstate = state;
1644
1645 WM_window_set_dpi(win);
1646
1647 /* WIN32: gives undefined window size when minimized. */
1649 /*
1650 * Ghost sometimes send size or move events when the window hasn't changed.
1651 * One case of this is using COMPIZ on Linux.
1652 * To alleviate the problem we ignore all such event here.
1653 *
1654 * It might be good to eventually do that at GHOST level, but that is for another time.
1655 */
1657 const bScreen *screen = WM_window_get_active_screen(win);
1658
1659 /* Debug prints. */
1660 if (G.debug & G_DEBUG_EVENTS) {
1661 const char *state_str;
1662 state = GHOST_GetWindowState(static_cast<GHOST_WindowHandle>(win->ghostwin));
1663
1665 state_str = "normal";
1666 }
1667 else if (state == GHOST_kWindowStateMinimized) {
1668 state_str = "minimized";
1669 }
1670 else if (state == GHOST_kWindowStateMaximized) {
1671 state_str = "maximized";
1672 }
1673 else if (state == GHOST_kWindowStateFullScreen) {
1674 state_str = "full-screen";
1675 }
1676 else {
1677 state_str = "<unknown>";
1678 }
1679
1680 printf("%s: window %d state = %s\n", __func__, win->winid, state_str);
1681
1682 if (type != GHOST_kEventWindowSize) {
1683 printf("win move event pos %d %d size %d %d\n",
1684 win->posx,
1685 win->posy,
1686 win->sizex,
1687 win->sizey);
1688 }
1689 }
1690
1691 wm_window_make_drawable(wm, win);
1692 BKE_icon_changed(screen->id.icon_id);
1693 WM_event_add_notifier_ex(wm, win, NC_SCREEN | NA_EDITED, nullptr);
1694 WM_event_add_notifier_ex(wm, win, NC_WINDOW | NA_EDITED, nullptr);
1695
1696#if defined(__APPLE__) || defined(WIN32)
1697 /* MACOS and WIN32 don't return to the main-loop while resize. */
1698 int dummy_sleep_ms = 0;
1699 wm_window_timers_process(C, &dummy_sleep_ms);
1703#endif
1704 }
1705 }
1706 break;
1707 }
1708
1710 WM_window_set_dpi(win);
1711 /* Font's are stored at each DPI level, without this we can easy load 100's of fonts. */
1713
1714 WM_main_add_notifier(NC_WINDOW, nullptr); /* Full redraw. */
1715 WM_main_add_notifier(NC_SCREEN | NA_EDITED, nullptr); /* Refresh region sizes. */
1716 break;
1717 }
1718
1720 const char *path = static_cast<const char *>(data);
1721
1722 if (path) {
1723 wmOperatorType *ot = WM_operatortype_find("WM_OT_open_mainfile", false);
1724 /* Operator needs a valid window in context, ensures it is correctly set. */
1725 CTX_wm_window_set(C, win);
1726
1727 PointerRNA props_ptr;
1728 WM_operator_properties_create_ptr(&props_ptr, ot);
1729 RNA_string_set(&props_ptr, "filepath", path);
1730 RNA_boolean_set(&props_ptr, "display_file_selector", false);
1731 /* There is no file selector to show the "Trusted Source" option, use its default. */
1732 RNA_boolean_set(&props_ptr, "use_scripts", BKE_autoexec_default_trust_source(path));
1733 WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr, nullptr);
1734 WM_operator_properties_free(&props_ptr);
1735
1736 CTX_wm_window_set(C, nullptr);
1737 }
1738 break;
1739 }
1741 const GHOST_TEventDragnDropData *ddd = static_cast<const GHOST_TEventDragnDropData *>(data);
1742
1743 /* Ensure the event state matches modifiers (window was inactive). */
1744 wm_window_update_eventstate_modifiers(wm, win, event_time_ms);
1745 /* Entering window, update mouse position (without sending an event). */
1747
1748 wmEvent event;
1749 wm_event_init_from_window(win, &event); /* Copy last state, like mouse coords. */
1750
1751 /* Activate region. */
1752 event.type = MOUSEMOVE;
1753 event.val = KM_NOTHING;
1754 copy_v2_v2_int(event.prev_xy, event.xy);
1755
1756 copy_v2_v2_int(event.xy, &ddd->x);
1757 wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
1758
1759 /* The values from #wm_window_update_eventstate may not match (under WAYLAND they don't)
1760 * Write this into the event state. */
1761 copy_v2_v2_int(win->eventstate->xy, event.xy);
1762
1763 event.flag = eWM_EventFlag(0);
1764
1765 /* No context change! `C->wm->windrawable` is drawable, or for area queues. */
1766 wm->winactive = win;
1767 win->active = 1;
1768
1769 WM_event_add(win, &event);
1770
1771 /* Make blender drop event with custom data pointing to wm drags. */
1772 event.type = EVT_DROP;
1773 event.val = KM_RELEASE;
1774 event.custom = EVT_DATA_DRAGDROP;
1775 event.customdata = &wm->drags;
1776 event.customdata_free = true;
1777
1778 WM_event_add(win, &event);
1779
1780 // printf("Drop detected\n");
1781
1782 /* Add drag data to wm for paths. */
1783
1785 const GHOST_TStringArray *stra = static_cast<const GHOST_TStringArray *>(ddd->data);
1786
1787 if (stra->count) {
1788 CLOG_INFO(WM_LOG_EVENTS, 1, "Drop %d files:", stra->count);
1789 for (const char *path : blender::Span((char **)stra->strings, stra->count)) {
1790 CLOG_INFO(WM_LOG_EVENTS, 1, "%s", path);
1791 }
1792 /* Try to get icon type from extension of the first path. */
1793 int icon = ED_file_extension_icon((char *)stra->strings[0]);
1795 blender::Span((char **)stra->strings, stra->count));
1796 WM_event_start_drag(C, icon, WM_DRAG_PATH, path_data, WM_DRAG_NOP);
1797 /* Void pointer should point to string, it makes a copy. */
1798 }
1799 }
1800 else if (ddd->dataType == GHOST_kDragnDropTypeString) {
1801 /* Drop an arbitrary string. */
1802 std::string *str = MEM_new<std::string>(__func__, static_cast<const char *>(ddd->data));
1804 }
1805
1806 break;
1807 }
1809 /* Only update if the actual pixel size changes. */
1810 float prev_pixelsize = U.pixelsize;
1811 WM_window_set_dpi(win);
1812
1813 if (U.pixelsize != prev_pixelsize) {
1815
1816 /* Close all popups since they are positioned with the pixel
1817 * size baked in and it's difficult to correct them. */
1818 CTX_wm_window_set(C, win);
1820 CTX_wm_window_set(C, nullptr);
1821
1822 wm_window_make_drawable(wm, win);
1823
1824 WM_event_add_notifier_ex(wm, win, NC_SCREEN | NA_EDITED, nullptr);
1825 WM_event_add_notifier_ex(wm, win, NC_WINDOW | NA_EDITED, nullptr);
1826 }
1827
1828 break;
1829 }
1831 case GHOST_kEventButtonUp: {
1832 if (win->active == 0) {
1833 /* Entering window, update cursor/tablet state & modifiers.
1834 * (ghost sends win-activate *after* the mouse-click in window!). */
1835 wm_window_update_eventstate_modifiers(wm, win, event_time_ms);
1837 }
1838
1839 wm_event_add_ghostevent(wm, win, type, data, event_time_ms);
1840 break;
1841 }
1842 default: {
1843 wm_event_add_ghostevent(wm, win, type, data, event_time_ms);
1844 break;
1845 }
1846 }
1847
1848 return true;
1849}
1850
1860static bool wm_window_timers_process(const bContext *C, int *sleep_us_p)
1861{
1862 Main *bmain = CTX_data_main(C);
1864 const double time = BLI_time_now_seconds();
1865 bool has_event = false;
1866
1867 const int sleep_us = *sleep_us_p;
1868 /* The nearest time an active timer is scheduled to run. */
1869 double ntime_min = DBL_MAX;
1870
1871 /* Mutable in case the timer gets removed. */
1873 if (wt->flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
1874 continue;
1875 }
1876 if (wt->sleep == true) {
1877 continue;
1878 }
1879
1880 /* Future timer, update nearest time & skip. */
1881 if (wt->time_next >= time) {
1882 if ((has_event == false) && (sleep_us != 0)) {
1883 /* The timer is not ready to run but may run shortly. */
1884 ntime_min = std::min(wt->time_next, ntime_min);
1885 }
1886 continue;
1887 }
1888
1889 wt->time_delta = time - wt->time_last;
1890 wt->time_duration += wt->time_delta;
1891 wt->time_last = time;
1892
1893 wt->time_next = wt->time_start;
1894 if (wt->time_step != 0.0f) {
1895 wt->time_next += wt->time_step * ceil(wt->time_duration / wt->time_step);
1896 }
1897
1898 if (wt->event_type == TIMERJOBS) {
1899 wm_jobs_timer(wm, wt);
1900 }
1901 else if (wt->event_type == TIMERAUTOSAVE) {
1902 wm_autosave_timer(bmain, wm, wt);
1903 }
1904 else if (wt->event_type == TIMERNOTIFIER) {
1905 WM_main_add_notifier(POINTER_AS_UINT(wt->customdata), nullptr);
1906 }
1907 else if (wmWindow *win = wt->win) {
1908 wmEvent event;
1909 wm_event_init_from_window(win, &event);
1910
1911 event.type = wt->event_type;
1912 event.val = KM_NOTHING;
1913 event.keymodifier = EVENT_NONE;
1914 event.flag = eWM_EventFlag(0);
1915 event.custom = EVT_DATA_TIMER;
1916 event.customdata = wt;
1917 WM_event_add(win, &event);
1918
1919 has_event = true;
1920 }
1921 }
1922
1923 if ((has_event == false) && (sleep_us != 0) && (ntime_min != DBL_MAX)) {
1924 /* Clamp the sleep time so next execution runs earlier (if necessary).
1925 * Use `ceil` so the timer is guarantee to be ready to run (not always the case with rounding).
1926 * Even though using `floor` or `round` is more responsive,
1927 * it causes CPU intensive loops that may run until the timer is reached, see: #111579. */
1928 const double microseconds = 1000000.0;
1929 const double sleep_sec = double(sleep_us) / microseconds;
1930 const double sleep_sec_next = ntime_min - time;
1931
1932 if (sleep_sec_next < sleep_sec) {
1933 *sleep_us_p = int(std::ceil(sleep_sec_next * microseconds));
1934 }
1935 }
1936
1937 /* Effectively delete all timers marked for removal. */
1939
1940 return has_event;
1941}
1942
1944{
1947
1948 bool has_event = GHOST_ProcessEvents(g_system, false); /* `false` is no wait. */
1949
1950 if (has_event) {
1952 }
1953
1954 /* When there is no event, sleep 5 milliseconds not to use too much CPU when idle. */
1955 const int sleep_us_default = 5000;
1956 int sleep_us = has_event ? 0 : sleep_us_default;
1957 has_event |= wm_window_timers_process(C, &sleep_us);
1958#ifdef WITH_XR_OPENXR
1959 /* XR events don't use the regular window queues. So here we don't only trigger
1960 * processing/dispatching but also handling. */
1961 has_event |= wm_xr_events_handle(CTX_wm_manager(C));
1962#endif
1964
1965 /* Skip sleeping when simulating events so tests don't idle unnecessarily as simulated
1966 * events are typically generated from a timer that runs in the main loop. */
1967 if ((has_event == false) && (sleep_us != 0) && !(G.f & G_FLAG_EVENT_SIMULATE)) {
1968 if (sleep_us == sleep_us_default) {
1969 /* NOTE(@ideasman42): prefer #BLI_time_sleep_ms over `sleep_for(..)` in the common case
1970 * because this function uses lower resolution (millisecond) resolution sleep timers
1971 * which are tried & true for the idle loop. We could move to C++ `sleep_for(..)`
1972 * if this works well on all platforms but this needs further testing. */
1973 BLI_time_sleep_ms(sleep_us_default / 1000);
1974 }
1975 else {
1976 /* The time was shortened to resume for the upcoming timer, use a high resolution sleep.
1977 * Mainly happens during animation playback but could happen immediately before any timer.
1978 *
1979 * NOTE(@ideasman42): At time of writing Windows-10-22H2 doesn't give higher precision sleep.
1980 * Keep the functionality as it doesn't have noticeable down sides either. */
1981 std::this_thread::sleep_for(std::chrono::microseconds(sleep_us));
1982 }
1983 }
1984}
1985
1987
1988/* -------------------------------------------------------------------- */
1991
1993{
1994 if (g_system) {
1995 return;
1996 }
1997
1998 BLI_assert(C != nullptr);
1999 BLI_assert_msg(!G.background, "Use wm_ghost_init_background instead");
2000
2001 GHOST_EventConsumerHandle consumer;
2002
2004
2006
2009
2010 if (UNLIKELY(g_system == nullptr)) {
2011 /* GHOST will have reported the back-ends that failed to load. */
2012 fprintf(stderr, "GHOST: unable to initialize, exiting!\n");
2013 /* This will leak memory, it's preferable to crashing. */
2014 exit(EXIT_FAILURE);
2015 }
2016#if !(defined(WIN32) || defined(__APPLE__))
2018#endif
2019
2020 GHOST_Debug debug = {0};
2021 if (G.debug & G_DEBUG_GHOST) {
2022 debug.flags |= GHOST_kDebugDefault;
2023 }
2024 if (G.debug & G_DEBUG_WINTAB) {
2025 debug.flags |= GHOST_kDebugWintab;
2026 }
2028
2030
2033 }
2034
2036}
2037
2039{
2040 /* TODO: move this to `wm_init_exit.cc`. */
2041
2042 if (g_system) {
2043 return;
2044 }
2045
2047
2050
2051 GHOST_Debug debug = {0};
2052 if (G.debug & G_DEBUG_GHOST) {
2053 debug.flags |= GHOST_kDebugDefault;
2054 }
2056}
2057
2059{
2060 if (g_system) {
2062 }
2063 g_system = nullptr;
2064}
2065
2066const char *WM_ghost_backend()
2067{
2068#if !(defined(WIN32) || defined(__APPLE__))
2069 return g_system_backend_id ? g_system_backend_id : "NONE";
2070#else
2071 /* While this could be supported, at the moment it's only needed with GHOST X11/WAYLAND
2072 * to check which was selected and the API call may be removed after that's no longer needed.
2073 * Use dummy values to prevent this being used on other systems. */
2074 return g_system ? "DEFAULT" : "NONE";
2075#endif
2076}
2077
2079{
2080 switch (gpu_backend) {
2081 case GPU_BACKEND_NONE:
2083 case GPU_BACKEND_ANY:
2084 case GPU_BACKEND_OPENGL:
2085#ifdef WITH_OPENGL_BACKEND
2086 return GHOST_kDrawingContextTypeOpenGL;
2087#endif
2090 case GPU_BACKEND_VULKAN:
2091#ifdef WITH_VULKAN_BACKEND
2092 return GHOST_kDrawingContextTypeVulkan;
2093#endif
2096 case GPU_BACKEND_METAL:
2097#ifdef WITH_METAL_BACKEND
2098 return GHOST_kDrawingContextTypeMetal;
2099#endif
2102 }
2103
2104 /* Avoid control reaches end of non-void function compilation warning, which could be promoted
2105 * to error. */
2108}
2109
2111{
2112 uiBlock *block = UI_block_begin(
2113 C, region, "autorun_warning_popup", blender::ui::EmbossType::Emboss);
2116
2117 const char *title = RPT_("Python script uses OpenGL for drawing");
2118 const char *message1 = RPT_("This may lead to unexpected behavior");
2119 const char *message2 = RPT_(
2120 "One of the add-ons or scripts is using OpenGL and will not work correct on Metal");
2121 const char *message3 = RPT_(
2122 "Please contact the developer of the add-on to migrate to use 'gpu' module");
2123 const char *message4 = RPT_("See system tab in preferences to switch to OpenGL backend");
2124
2125 /* Measure strings to find the longest. */
2126 const uiStyle *style = UI_style_get_dpi();
2127 UI_fontstyle_set(&style->widget);
2128 int text_width = int(BLF_width(style->widget.uifont_id, title, BLF_DRAW_STR_DUMMY_MAX));
2129 text_width = std::max(text_width,
2130 int(BLF_width(style->widget.uifont_id, message1, BLF_DRAW_STR_DUMMY_MAX)));
2131 text_width = std::max(text_width,
2132 int(BLF_width(style->widget.uifont_id, message2, BLF_DRAW_STR_DUMMY_MAX)));
2133 text_width = std::max(text_width,
2134 int(BLF_width(style->widget.uifont_id, message3, BLF_DRAW_STR_DUMMY_MAX)));
2135 text_width = std::max(text_width,
2136 int(BLF_width(style->widget.uifont_id, message4, BLF_DRAW_STR_DUMMY_MAX)));
2137
2138 const int dialog_width = std::max(int(400.0f * UI_SCALE_FAC),
2139 text_width + int(style->columnspace * 2.5));
2140
2141 const short icon_size = 40 * UI_SCALE_FAC;
2142 uiLayout *layout = uiItemsAlertBox(
2143 block, style, dialog_width + icon_size, ALERT_ICON_ERROR, icon_size);
2144
2145 uiLayout *col = &layout->column(false);
2146 uiLayoutSetScaleY(col, 0.9f);
2147
2148 /* Title and explanation text. */
2149 uiItemL_ex(col, title, ICON_NONE, true, false);
2151
2152 uiLayout *messages = &col->column(false);
2153 uiLayoutSetScaleY(messages, 0.8f);
2154
2155 messages->label(message1, ICON_NONE);
2156 messages->label(message2, ICON_NONE);
2157 messages->label(message3, ICON_NONE);
2158 if (G.opengl_deprecation_usage_filename) {
2159 char location[1024];
2160 SNPRINTF(
2161 location, "%s:%d", G.opengl_deprecation_usage_filename, G.opengl_deprecation_usage_lineno);
2162 messages->label(location, ICON_NONE);
2163 }
2164 messages->label(message4, ICON_NONE);
2165
2167
2169
2170 return block;
2171}
2172
2174{
2175 static bool message_shown = false;
2176
2177 /* Exit when no failure detected. */
2178 if (!G.opengl_deprecation_usage_detected) {
2179 return;
2180 }
2181
2182 /* Have we already shown a message during this Blender session. `bgl` calls are done in a draw
2183 * handler that will run many times. */
2184 if (message_shown) {
2185 return;
2186 }
2187
2189 wmWindow *win = static_cast<wmWindow *>((wm->winactive) ? wm->winactive : wm->windows.first);
2190
2191 BKE_report(&wm->runtime->reports,
2192 RPT_ERROR,
2193 "One of the add-ons or scripts is using OpenGL and will not work correct on Metal. "
2194 "Please contact the developer of the add-on to migrate to use 'gpu' module");
2195
2196 if (win) {
2197 /* We want this warning on the Main window, not a child window even if active. See #118765. */
2198 if (win->parent) {
2199 win = win->parent;
2200 }
2201
2202 wmWindow *prevwin = CTX_wm_window(C);
2203 CTX_wm_window_set(C, win);
2205 CTX_wm_window_set(C, prevwin);
2206 }
2207
2208 message_shown = true;
2209}
2210
2212{
2213 uiBlock *block = UI_block_begin(
2214 C, region, "autorun_warning_popup", blender::ui::EmbossType::Emboss);
2217
2218 uiLayout *layout = uiItemsAlertBox(block, 44, ALERT_ICON_ERROR);
2219
2220 /* Title and explanation text. */
2221 uiLayout *col = &layout->column(false);
2222 uiLayoutSetScaleY(col, 0.8f);
2223 uiItemL_ex(
2224 col, RPT_("Failed to load using Vulkan, using OpenGL instead."), ICON_NONE, true, false);
2226
2227 col->label(RPT_("Updating GPU drivers may solve this issue."), ICON_NONE);
2228 col->label(RPT_("The graphics backend can be changed in the System section of the Preferences."),
2229 ICON_NONE);
2230
2232
2233 return block;
2234}
2235
2237{
2238 if (!bool(G.f & G_FLAG_GPU_BACKEND_FALLBACK)) {
2239 return;
2240 }
2241
2242 /* Have we already shown a message during this Blender session. */
2243 if (bool(G.f & G_FLAG_GPU_BACKEND_FALLBACK_QUIET)) {
2244 return;
2245 }
2247
2249 wmWindow *win = static_cast<wmWindow *>((wm->winactive) ? wm->winactive : wm->windows.first);
2250
2251 if (win) {
2252 /* We want this warning on the Main window, not a child window even if active. See #118765. */
2253 if (win->parent) {
2254 win = win->parent;
2255 }
2256
2257 wmWindow *prevwin = CTX_wm_window(C);
2258 CTX_wm_window_set(C, win);
2260 CTX_wm_window_set(C, prevwin);
2261 }
2262}
2263
2265{
2267 if (flag != 0) {
2268 return flag;
2269 }
2271
2272 /* NOTE(@ideasman42): Regarding tests.
2273 * Some callers of this function may run from tests where GHOST's hasn't been initialized.
2274 * In such cases it may be necessary to check `!G.background` which is acceptable in most cases.
2275 * At time of writing this is the case for `bl_animation_keyframing`.
2276 *
2277 * While this function *could* early-exit when in background mode, don't do this as GHOST
2278 * may be initialized in background mode for GPU rendering and in this case we may want to
2279 * query GHOST/GPU related capabilities. */
2280
2281 const GHOST_TCapabilityFlag ghost_flag = GHOST_GetCapabilities();
2282 if (ghost_flag & GHOST_kCapabilityCursorWarp) {
2284 }
2285 if (ghost_flag & GHOST_kCapabilityWindowPosition) {
2287 }
2288 if (ghost_flag & GHOST_kCapabilityPrimaryClipboard) {
2290 }
2291 if (ghost_flag & GHOST_kCapabilityGPUReadFrontBuffer) {
2293 }
2294 if (ghost_flag & GHOST_kCapabilityClipboardImages) {
2296 }
2297 if (ghost_flag & GHOST_kCapabilityDesktopSample) {
2299 }
2300 if (ghost_flag & GHOST_kCapabilityInputIME) {
2302 }
2305 }
2306 if (ghost_flag & GHOST_kCapabilityWindowDecorationStyles) {
2308 }
2309 if (ghost_flag & GHOST_kCapabilityKeyboardHyperKey) {
2311 }
2312
2313 return flag;
2314}
2315
2317
2318/* -------------------------------------------------------------------- */
2321
2322void WM_event_timer_sleep(wmWindowManager *wm, wmWindow * /*win*/, wmTimer *timer, bool do_sleep)
2323{
2324 /* Extra security check. */
2325 if (BLI_findindex(&wm->timers, timer) == -1) {
2326 return;
2327 }
2328 /* It's disputable if this is needed, when tagged for removal,
2329 * the sleep value won't be used anyway. */
2330 if (timer->flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
2331 return;
2332 }
2333 timer->sleep = do_sleep;
2334}
2335
2337 wmWindow *win,
2338 const wmEventType event_type,
2339 const double time_step)
2340{
2341 BLI_assert(ISTIMER(event_type));
2342
2343 wmTimer *wt = MEM_callocN<wmTimer>("window timer");
2344 BLI_assert(time_step >= 0.0f);
2345
2346 wt->event_type = event_type;
2348 wt->time_next = wt->time_last + time_step;
2349 wt->time_start = wt->time_last;
2350 wt->time_step = time_step;
2351 wt->win = win;
2352
2353 BLI_addtail(&wm->timers, wt);
2354
2355 return wt;
2356}
2357
2359 wmWindow *win,
2360 const uint type,
2361 const double time_step)
2362{
2363 wmTimer *wt = MEM_callocN<wmTimer>("window timer");
2364 BLI_assert(time_step >= 0.0f);
2365
2368 wt->time_next = wt->time_last + time_step;
2369 wt->time_start = wt->time_last;
2370 wt->time_step = time_step;
2371 wt->win = win;
2372 wt->customdata = POINTER_FROM_UINT(type);
2374
2375 BLI_addtail(&wm->timers, wt);
2376
2377 return wt;
2378}
2379
2381{
2383 if ((wt->flags & WM_TIMER_TAGGED_FOR_REMOVAL) == 0) {
2384 continue;
2385 }
2386
2387 /* Actual removal and freeing of the timer. */
2388 BLI_remlink(&wm->timers, wt);
2389 MEM_freeN(wt);
2390 }
2391}
2392
2394{
2395 if (timer->customdata != nullptr && (timer->flags & WM_TIMER_NO_FREE_CUSTOM_DATA) == 0) {
2396 MEM_freeN(timer->customdata);
2397 timer->customdata = nullptr;
2398 }
2399}
2400
2402{
2404 "This should only be called when freeing the window-manager");
2405 while (wmTimer *timer = static_cast<wmTimer *>(BLI_pophead(&wm->timers))) {
2407 MEM_freeN(timer);
2408 }
2409}
2410
2412{
2413 /* Extra security check. */
2414 if (BLI_findindex(&wm->timers, timer) == -1) {
2415 return;
2416 }
2417
2419
2420 /* Clear existing references to the timer. */
2421 if (wm->runtime->reports.reporttimer == timer) {
2422 wm->runtime->reports.reporttimer = nullptr;
2423 }
2424 /* There might be events in queue with this timer as customdata. */
2425 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2426 LISTBASE_FOREACH (wmEvent *, event, &win->runtime->event_queue) {
2427 if (event->customdata == timer) {
2428 event->customdata = nullptr;
2429 event->type = EVENT_NONE; /* Timer users customdata, don't want `nullptr == nullptr`. */
2430 }
2431 }
2432 }
2433
2434 /* Immediately free `customdata` if requested, so that invalid usages of that data after
2435 * calling `WM_event_timer_remove` can be easily spotted (through ASAN errors e.g.). */
2437}
2438
2440{
2441 timer->customdata = nullptr;
2442 WM_event_timer_remove(wm, win, timer);
2443}
2444
2446
2447/* -------------------------------------------------------------------- */
2454
2455struct {
2456 char *buffers[2];
2458
2460{
2461 if (g_wm_clipboard_text_simulate == nullptr) {
2462 return;
2463 }
2464 for (int i = 0; i < ARRAY_SIZE(g_wm_clipboard_text_simulate->buffers); i++) {
2465 char *buf = g_wm_clipboard_text_simulate->buffers[i];
2466 if (buf) {
2467 MEM_freeN(buf);
2468 }
2469 }
2472}
2473
2474static char *wm_clipboard_text_get_impl(bool selection)
2475{
2476 if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) {
2477 if (g_wm_clipboard_text_simulate == nullptr) {
2478 return nullptr;
2479 }
2480 const char *buf_src = g_wm_clipboard_text_simulate->buffers[int(selection)];
2481 if (buf_src == nullptr) {
2482 return nullptr;
2483 }
2484 size_t size = strlen(buf_src) + 1;
2485 char *buf = static_cast<char *>(malloc(size));
2486 memcpy(buf, buf_src, size);
2487 return buf;
2488 }
2489
2490 return GHOST_getClipboard(selection);
2491}
2492
2493static void wm_clipboard_text_set_impl(const char *buf, bool selection)
2494{
2495 if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) {
2496 if (g_wm_clipboard_text_simulate == nullptr) {
2498 MEM_callocN<std::remove_pointer_t<decltype(g_wm_clipboard_text_simulate)>>(__func__);
2499 }
2500 char **buf_src_p = &(g_wm_clipboard_text_simulate->buffers[int(selection)]);
2501 MEM_SAFE_FREE(*buf_src_p);
2502 *buf_src_p = BLI_strdup(buf);
2503 return;
2504 }
2505
2506 GHOST_putClipboard(buf, selection);
2507}
2508
2510
2511/* -------------------------------------------------------------------- */
2514
2515static char *wm_clipboard_text_get_ex(bool selection,
2516 int *r_len,
2517 const bool ensure_utf8,
2518 const bool firstline)
2519{
2520 if (G.background) {
2521 *r_len = 0;
2522 return nullptr;
2523 }
2524
2525 char *buf = wm_clipboard_text_get_impl(selection);
2526 if (!buf) {
2527 *r_len = 0;
2528 return nullptr;
2529 }
2530
2531 int buf_len = strlen(buf);
2532
2533 if (ensure_utf8) {
2534 /* TODO(@ideasman42): It would be good if unexpected byte sequences could be interpreted
2535 * instead of stripped - so mixed in characters (typically Latin1) aren't ignored.
2536 * Check on how Python bytes this, see: #PyC_UnicodeFromBytesAndSize,
2537 * there are clever ways to handle this although they increase the size of the buffer. */
2538 buf_len -= BLI_str_utf8_invalid_strip(buf, buf_len);
2539 }
2540
2541 /* Always convert from `\r\n` to `\n`. */
2542 char *newbuf = MEM_malloc_arrayN<char>(size_t(buf_len + 1), __func__);
2543 char *p2 = newbuf;
2544
2545 if (firstline) {
2546 /* Will return an over-allocated value in the case there are newlines. */
2547 for (char *p = buf; *p; p++) {
2548 if (!ELEM(*p, '\n', '\r')) {
2549 *(p2++) = *p;
2550 }
2551 else {
2552 break;
2553 }
2554 }
2555 }
2556 else {
2557 for (char *p = buf; *p; p++) {
2558 if (*p != '\r') {
2559 *(p2++) = *p;
2560 }
2561 }
2562 }
2563
2564 *p2 = '\0';
2565
2566 free(buf); /* GHOST uses regular malloc. */
2567
2568 *r_len = (p2 - newbuf);
2569
2570 return newbuf;
2571}
2572
2573char *WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
2574{
2575 return wm_clipboard_text_get_ex(selection, r_len, ensure_utf8, false);
2576}
2577
2578char *WM_clipboard_text_get_firstline(bool selection, bool ensure_utf8, int *r_len)
2579{
2580 return wm_clipboard_text_get_ex(selection, r_len, ensure_utf8, true);
2581}
2582
2583void WM_clipboard_text_set(const char *buf, bool selection)
2584{
2585 if (!G.background) {
2586#ifdef _WIN32
2587 /* Do conversion from `\n` to `\r\n` on Windows. */
2588 const char *p;
2589 char *p2, *newbuf;
2590 int newlen = 0;
2591
2592 for (p = buf; *p; p++) {
2593 if (*p == '\n') {
2594 newlen += 2;
2595 }
2596 else {
2597 newlen++;
2598 }
2599 }
2600
2601 newbuf = MEM_calloc_arrayN<char>(newlen + 1, "WM_clipboard_text_set");
2602
2603 for (p = buf, p2 = newbuf; *p; p++, p2++) {
2604 if (*p == '\n') {
2605 *(p2++) = '\r';
2606 *p2 = '\n';
2607 }
2608 else {
2609 *p2 = *p;
2610 }
2611 }
2612 *p2 = '\0';
2613
2614 wm_clipboard_text_set_impl(newbuf, selection);
2615 MEM_freeN(newbuf);
2616#else
2617 wm_clipboard_text_set_impl(buf, selection);
2618#endif
2619 }
2620}
2621
2623{
2624 if (G.background) {
2625 return false;
2626 }
2627 return bool(GHOST_hasClipboardImage());
2628}
2629
2631{
2632 if (G.background) {
2633 return nullptr;
2634 }
2635
2636 int width, height;
2637
2638 uint8_t *rgba = (uint8_t *)GHOST_getClipboardImage(&width, &height);
2639 if (!rgba) {
2640 return nullptr;
2641 }
2642
2643 ImBuf *ibuf = IMB_allocFromBuffer(rgba, nullptr, width, height, 4);
2644 free(rgba);
2645
2646 return ibuf;
2647}
2648
2650{
2651 if (G.background) {
2652 return false;
2653 }
2654 if (ibuf->byte_buffer.data == nullptr) {
2655 return false;
2656 }
2657
2658 bool success = bool(GHOST_putClipboardImage((uint *)ibuf->byte_buffer.data, ibuf->x, ibuf->y));
2659
2660 return success;
2661}
2662
2664
2665/* -------------------------------------------------------------------- */
2668
2670{
2671 /* In background mode we may have windows, but not actual GHOST windows. */
2672 if (win->ghostwin) {
2673 GHOST_SetProgressBar(static_cast<GHOST_WindowHandle>(win->ghostwin), progress);
2674 }
2675}
2676
2678{
2679 if (win->ghostwin) {
2680 GHOST_EndProgressBar(static_cast<GHOST_WindowHandle>(win->ghostwin));
2681 }
2682}
2683
2685
2686/* -------------------------------------------------------------------- */
2689
2690void wm_window_set_size(wmWindow *win, int width, int height)
2691{
2692 GHOST_SetClientSize(static_cast<GHOST_WindowHandle>(win->ghostwin), width, height);
2693}
2694
2696
2697/* -------------------------------------------------------------------- */
2700
2702{
2703 GHOST_SetWindowOrder(static_cast<GHOST_WindowHandle>(win->ghostwin), GHOST_kWindowOrderBottom);
2704}
2705
2707{
2708 /* Restore window if minimized. */
2709 if (GHOST_GetWindowState(static_cast<GHOST_WindowHandle>(win->ghostwin)) ==
2711 {
2712 GHOST_SetWindowState(static_cast<GHOST_WindowHandle>(win->ghostwin), GHOST_kWindowStateNormal);
2713 }
2714 GHOST_SetWindowOrder(static_cast<GHOST_WindowHandle>(win->ghostwin), GHOST_kWindowOrderTop);
2715}
2716
2718
2719/* -------------------------------------------------------------------- */
2722
2724{
2725 GHOST_SwapWindowBuffers(static_cast<GHOST_WindowHandle>(win->ghostwin));
2726}
2727
2729{
2730 GHOST_SetSwapInterval(static_cast<GHOST_WindowHandle>(win->ghostwin), interval);
2731}
2732
2733bool wm_window_get_swap_interval(wmWindow *win, int *r_interval)
2734{
2735 return GHOST_GetSwapInterval(static_cast<GHOST_WindowHandle>(win->ghostwin), r_interval);
2736}
2737
2739
2740/* -------------------------------------------------------------------- */
2743
2745 const int event_xy[2],
2746 int r_event_xy_other[2])
2747{
2749 /* Window positions are unsupported, so this function can't work as intended.
2750 * Perform the bare minimum, return the active window if the event is within it. */
2751 rcti rect;
2752 WM_window_rect_calc(win, &rect);
2753 if (!BLI_rcti_isect_pt_v(&rect, event_xy)) {
2754 return nullptr;
2755 }
2756 copy_v2_v2_int(r_event_xy_other, event_xy);
2757 return win;
2758 }
2759
2760 int temp_xy[2];
2761 copy_v2_v2_int(temp_xy, event_xy);
2762 wm_cursor_position_to_ghost_screen_coords(win, &temp_xy[0], &temp_xy[1]);
2763
2764 GHOST_WindowHandle ghostwin = GHOST_GetWindowUnderCursor(g_system, temp_xy[0], temp_xy[1]);
2765
2766 if (!ghostwin) {
2767 return nullptr;
2768 }
2769
2770 wmWindow *win_other = static_cast<wmWindow *>(GHOST_GetWindowUserData(ghostwin));
2771 wm_cursor_position_from_ghost_screen_coords(win_other, &temp_xy[0], &temp_xy[1]);
2772 copy_v2_v2_int(r_event_xy_other, temp_xy);
2773 return win_other;
2774}
2775
2777{
2778 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2780 if (BLI_findindex(&sc->areabase, area) != -1) {
2781 return win;
2782 }
2783 }
2784 return nullptr;
2785}
2786
2788
2789/* -------------------------------------------------------------------- */
2792
2793void WM_init_state_size_set(int stax, int stay, int sizx, int sizy)
2794{
2795 wm_init_state.start = blender::int2(stax, stay); /* Left hand bottom position. */
2796 wm_init_state.size = blender::int2(std::max(sizx, 640), std::max(sizy, 480));
2798}
2799
2805
2811
2817
2819{
2821}
2822
2824{
2826}
2827
2829
2830/* -------------------------------------------------------------------- */
2833
2835{
2836 if (UNLIKELY(!g_system)) {
2837 return;
2838 }
2839
2841
2842 switch (U.tablet_api) {
2843 case USER_TABLET_NATIVE:
2845 break;
2846 case USER_TABLET_WINTAB:
2848 break;
2850 default:
2852 break;
2853 }
2854}
2855
2856void WM_cursor_warp(wmWindow *win, int x, int y)
2857{
2858 /* This function requires access to the GHOST_SystemHandle (`g_system`). */
2859
2860 if (!(win && win->ghostwin)) {
2861 return;
2862 }
2863
2864 int oldx = x, oldy = y;
2865
2867 GHOST_SetCursorPosition(g_system, static_cast<GHOST_WindowHandle>(win->ghostwin), x, y);
2868
2869 win->eventstate->prev_xy[0] = oldx;
2870 win->eventstate->prev_xy[1] = oldy;
2871
2872 win->eventstate->xy[0] = oldx;
2873 win->eventstate->xy[1] = oldy;
2874}
2875
2880
2882
2883/* -------------------------------------------------------------------- */
2886
2888{
2889 const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
2890
2891 return int(fac * float(win->sizex));
2892}
2894{
2895 const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
2896
2897 return int(fac * float(win->sizey));
2898}
2899
2901{
2902 const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
2903
2904 return blender::int2(int(fac * float(win->sizex)), int(fac * float(win->sizey)));
2905}
2906
2907void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
2908{
2909 const float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
2910
2911 *x *= fac;
2912 *y *= fac;
2913}
2914
2915void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
2916{
2917 const blender::int2 win_size = WM_window_native_pixel_size(win);
2918 BLI_rcti_init(r_rect, 0, win_size[0], 0, win_size[1]);
2919}
2921{
2922 rcti window_rect, screen_rect;
2923
2924 WM_window_rect_calc(win, &window_rect);
2925 screen_rect = window_rect;
2926
2927 /* Subtract global areas from screen rectangle. */
2928 LISTBASE_FOREACH (ScrArea *, global_area, &win->global_areas.areabase) {
2929 int height = ED_area_global_size_y(global_area) - 1;
2930
2931 if (global_area->global->flag & GLOBAL_AREA_IS_HIDDEN) {
2932 continue;
2933 }
2934
2935 switch (global_area->global->align) {
2937 screen_rect.ymax -= height;
2938 break;
2940 screen_rect.ymin += height;
2941 break;
2942 default:
2944 break;
2945 }
2946 }
2947
2948 BLI_assert(BLI_rcti_is_valid(&screen_rect));
2949
2950 *r_rect = screen_rect;
2951}
2952
2954{
2956}
2957
2959{
2961}
2962
2964{
2970 if ((win->parent != nullptr) || screen->temp) {
2971 return false;
2972 }
2973 return true;
2974}
2975
2977
2978/* -------------------------------------------------------------------- */
2981
2982void WM_windows_scene_data_sync(const ListBase *win_lb, Scene *scene)
2983{
2984 LISTBASE_FOREACH (wmWindow *, win, win_lb) {
2985 if (WM_window_get_active_scene(win) == scene) {
2986 ED_workspace_scene_data_sync(win->workspace_hook, scene);
2987 }
2988 }
2989}
2990
2992{
2993 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
2994 if (WM_window_get_active_screen(win) == screen) {
2995 return WM_window_get_active_scene(win);
2996 }
2997 }
2998
2999 return nullptr;
3000}
3001
3003{
3004 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
3005 if (WM_window_get_active_screen(win) == screen) {
3007 }
3008 }
3009
3010 return nullptr;
3011}
3012
3014{
3015 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
3016 if (WM_window_get_active_screen(win) == screen) {
3018 }
3019 }
3020 return nullptr;
3021}
3022
3024{
3025 return win->scene;
3026}
3027
3029{
3031 wmWindow *win_parent = (win->parent) ? win->parent : win;
3032 bool changed = false;
3033
3034 /* Set scene in parent and its child windows. */
3035 if (win_parent->scene != scene) {
3036 ED_screen_scene_change(C, win_parent, scene, true);
3037 changed = true;
3038 }
3039
3040 LISTBASE_FOREACH (wmWindow *, win_child, &wm->windows) {
3041 if (win_child->parent == win_parent && win_child->scene != scene) {
3042 ED_screen_scene_change(C, win_child, scene, true);
3043 changed = true;
3044 }
3045 }
3046
3047 if (changed) {
3048 /* Update depsgraph and renderers for scene change. */
3049 ViewLayer *view_layer = WM_window_get_active_view_layer(win_parent);
3050 ED_scene_change_update(bmain, scene, view_layer);
3051
3052 /* Complete redraw. */
3054 }
3055}
3056
3058{
3059 Scene *scene = WM_window_get_active_scene(win);
3060 if (scene == nullptr) {
3061 return nullptr;
3062 }
3063
3064 ViewLayer *view_layer = BKE_view_layer_find(scene, win->view_layer_name);
3065 if (view_layer) {
3066 return view_layer;
3067 }
3068
3069 view_layer = BKE_view_layer_default_view(scene);
3070 if (view_layer) {
3071 WM_window_set_active_view_layer((wmWindow *)win, view_layer);
3072 }
3073
3074 return view_layer;
3075}
3076
3078{
3079 BLI_assert(BKE_view_layer_find(WM_window_get_active_scene(win), view_layer->name) != nullptr);
3080 Main *bmain = G_MAIN;
3081
3082 wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
3083 wmWindow *win_parent = (win->parent) ? win->parent : win;
3084
3085 /* Set view layer in parent and child windows. */
3086 LISTBASE_FOREACH (wmWindow *, win_iter, &wm->windows) {
3087 if ((win_iter == win_parent) || (win_iter->parent == win_parent)) {
3088 STRNCPY(win_iter->view_layer_name, view_layer->name);
3089 bScreen *screen = BKE_workspace_active_screen_get(win_iter->workspace_hook);
3090 ED_render_view_layer_changed(bmain, screen);
3091 }
3092 }
3093}
3094
3096{
3097 /* Update layer name is correct after scene changes, load without UI, etc. */
3098 Scene *scene = WM_window_get_active_scene(win);
3099
3100 if (scene && BKE_view_layer_find(scene, win->view_layer_name) == nullptr) {
3101 ViewLayer *view_layer = BKE_view_layer_default_view(scene);
3102 STRNCPY(win->view_layer_name, view_layer->name);
3103 }
3104}
3105
3110
3112{
3114 wmWindow *win_parent = (win->parent) ? win->parent : win;
3115
3116 ED_workspace_change(workspace, C, wm, win);
3117
3118 LISTBASE_FOREACH (wmWindow *, win_child, &wm->windows) {
3119 if (win_child->parent == win_parent) {
3120 bScreen *screen = WM_window_get_active_screen(win_child);
3121 /* Don't change temporary screens, they only serve a single purpose. */
3122 if (screen->temp) {
3123 continue;
3124 }
3125 ED_workspace_change(workspace, C, wm, win_child);
3126 }
3127 }
3128}
3129
3131{
3132 const WorkSpace *workspace = WM_window_get_active_workspace(win);
3133 return (LIKELY(workspace != nullptr) ? BKE_workspace_active_layout_get(win->workspace_hook) :
3134 nullptr);
3135}
3137{
3138 BKE_workspace_active_layout_set(win->workspace_hook, win->winid, workspace, layout);
3139}
3140
3142{
3143 const WorkSpace *workspace = WM_window_get_active_workspace(win);
3144 /* May be null in rare cases like closing Blender. */
3145 return (LIKELY(workspace != nullptr) ? BKE_workspace_active_screen_get(win->workspace_hook) :
3146 nullptr);
3147}
3149{
3150 BKE_workspace_active_screen_set(win->workspace_hook, win->winid, workspace, screen);
3151}
3152
3154{
3155 const bScreen *screen = WM_window_get_active_screen(win);
3156 return (screen && screen->temp != 0);
3157}
3158
3160
3161/* -------------------------------------------------------------------- */
3164
3165#ifdef WITH_INPUT_IME
3166void wm_window_IME_begin(wmWindow *win, int x, int y, int w, int h, bool complete)
3167{
3168 /* NOTE: Keep in mind #wm_window_IME_begin is also used to reposition the IME window. */
3169
3170 BLI_assert(win);
3172 return;
3173 }
3174
3175 /* Convert to native OS window coordinates. */
3176 float fac = GHOST_GetNativePixelSize(static_cast<GHOST_WindowHandle>(win->ghostwin));
3177 x /= fac;
3178 y /= fac;
3180 static_cast<GHOST_WindowHandle>(win->ghostwin), x, win->sizey - y, w, h, complete);
3181}
3182
3183void wm_window_IME_end(wmWindow *win)
3184{
3186 return;
3187 }
3188
3189 BLI_assert(win);
3190 /* NOTE(@ideasman42): on WAYLAND and Windows a call to "begin" must be closed by an "end" call.
3191 * Even if no IME events were generated (which assigned `ime_data`).
3192 * TODO: check if #GHOST_EndIME can run on APPLE without causing problems. */
3193# ifdef __APPLE__
3194 BLI_assert(win->runtime->ime_data);
3195# endif
3196 GHOST_EndIME(static_cast<GHOST_WindowHandle>(win->ghostwin));
3197 MEM_delete(win->runtime->ime_data);
3198 win->runtime->ime_data = nullptr;
3199 win->runtime->ime_data_is_composing = false;
3200}
3201#endif /* WITH_INPUT_IME */
3202
3204
3205/* -------------------------------------------------------------------- */
3208
3210{
3211 /* On Windows there is a problem creating contexts that share resources (almost any object,
3212 * including legacy display lists, but also textures) with a context which is current in another
3213 * thread. This is a documented and behavior of both `::wglCreateContextAttribsARB()` and
3214 * `::wglShareLists()`.
3215 *
3216 * Other platforms might successfully share resources from context which is active somewhere
3217 * else, but to keep our code behave the same on all platform we expect contexts to only be
3218 * created from the main thread. */
3219
3222
3223 GHOST_GPUSettings gpuSettings = {0};
3224 const eGPUBackendType gpu_backend = GPU_backend_type_selection_get();
3225 gpuSettings.context_type = wm_ghost_drawing_context_type(gpu_backend);
3226 if (G.debug & G_DEBUG_GPU) {
3227 gpuSettings.flags |= GHOST_gpuDebugContext;
3228 }
3229 gpuSettings.preferred_device.index = U.gpu_preferred_index;
3230 gpuSettings.preferred_device.vendor_id = U.gpu_preferred_vendor_id;
3231 gpuSettings.preferred_device.device_id = U.gpu_preferred_device_id;
3232
3233 return GHOST_CreateGPUContext(g_system, gpuSettings);
3234}
3235
3237{
3239 GHOST_DisposeGPUContext(g_system, (GHOST_ContextHandle)context);
3240}
3241
3243{
3245 GHOST_ActivateGPUContext((GHOST_ContextHandle)context);
3246}
3247
3249{
3251 GHOST_ReleaseGPUContext((GHOST_ContextHandle)context);
3252}
3253
3254void WM_ghost_show_message_box(const char *title,
3255 const char *message,
3256 const char *help_label,
3257 const char *continue_label,
3258 const char *link,
3259 GHOST_DialogOptions dialog_options)
3260{
3262 GHOST_ShowMessageBox(g_system, title, message, help_label, continue_label, link, dialog_options);
3263}
3264
bool BKE_autoexec_default_trust_source(const char *filepath)
Definition autoexec.cc:55
const char * BKE_blender_version_string(void)
Definition blender.cc:143
bScreen * CTX_wm_screen(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
void CTX_wm_window_set(bContext *C, wmWindow *win)
Main * CTX_data_main(const bContext *C)
void CTX_wm_area_set(bContext *C, ScrArea *area)
wmWindowManager * CTX_wm_manager(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
@ G_FLAG_EVENT_SIMULATE
@ G_FLAG_GPU_BACKEND_FALLBACK_QUIET
@ G_FLAG_GPU_BACKEND_FALLBACK
@ G_DEBUG_GPU
@ G_DEBUG_GHOST
@ G_DEBUG_WINTAB
@ G_DEBUG_EVENTS
#define G_MAIN
void BKE_icon_changed(int icon_id)
Definition icons.cc:204
ViewLayer * BKE_view_layer_default_view(const Scene *scene)
ViewLayer * BKE_view_layer_find(const Scene *scene, const char *layer_name)
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:882
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
void BKE_screen_area_map_free(ScrAreaMap *area_map) ATTR_NONNULL()
Definition screen.cc:655
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Definition screen.cc:945
WorkSpaceInstanceHook * BKE_workspace_instance_hook_create(const Main *bmain, int winid)
Definition workspace.cc:337
void BKE_workspace_instance_hook_free(const Main *bmain, WorkSpaceInstanceHook *hook)
Definition workspace.cc:351
bScreen * BKE_workspace_layout_screen_get(const WorkSpaceLayout *layout) GETTER_ATTRS
Definition workspace.cc:637
void BKE_workspace_active_screen_set(WorkSpaceInstanceHook *hook, int winid, WorkSpace *workspace, bScreen *screen) SETTER_ATTRS
Definition workspace.cc:616
void BKE_workspace_layout_remove(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL()
Definition workspace.cc:397
void BKE_workspace_active_layout_set(WorkSpaceInstanceHook *hook, int winid, WorkSpace *workspace, WorkSpaceLayout *layout) SETTER_ATTRS
Activate a layout.
Definition workspace.cc:603
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:612
WorkSpace * BKE_workspace_active_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:561
void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS
Definition workspace.cc:565
WorkSpaceLayout * BKE_workspace_active_layout_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:585
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:468
void BLF_cache_clear()
Definition blf.cc:98
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:805
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
#define OS_WINDOWS
#define OS_MAC
void BLI_kdtree_nd_ free(KDTree *tree)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:252
void void BLI_INLINE bool BLI_listbase_is_single(const ListBase *lb)
MINLINE float max_ff(float a, float b)
MINLINE int max_ii(int a, int b)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
#define FILE_MAX
const char * BLI_path_extension_or_end(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:198
bool BLI_rcti_is_valid(const struct rcti *rect)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:414
void BLI_rcti_resize_y(struct rcti *rect, int y)
Definition rct.cc:615
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:194
void BLI_rcti_resize_x(struct rcti *rect, int x)
Definition rct.cc:609
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
const char * BLI_str_utf8_invalid_substitute_as_needed(const char *str, size_t str_len, const char substitute, char *buf, const size_t buf_maxncpy) ATTR_NONNULL(1
int BLI_str_utf8_invalid_strip(char *str, size_t str_len) ATTR_NONNULL(1)
unsigned int uint
void BLI_system_backtrace(FILE *fp)
Definition system.cc:102
int BLI_thread_is_main(void)
Definition threads.cc:179
Platform independent time functions.
void BLI_time_sleep_ms(int ms)
Definition time.cc:85
double BLI_time_now_seconds(void)
Definition time.cc:65
#define CLAMP(a, b, c)
#define ARRAY_SIZE(arr)
#define ENUM_OPERATORS(_type, _max)
#define POINTER_AS_UINT(i)
#define UNLIKELY(x)
#define ELEM(...)
#define POINTER_FROM_UINT(i)
#define LIKELY(x)
#define RPT_(msgid)
#define IFACE_(msgid)
#define CLOG_INFO(clg_ref, level,...)
Definition CLG_log.h:179
These structs are the foundation for all linked lists in the library system.
@ S3D_DISPLAY_PAGEFLIP
@ GLOBAL_AREA_IS_HIDDEN
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ GLOBAL_AREA_ALIGN_BOTTOM
@ GLOBAL_AREA_ALIGN_TOP
@ SPACE_TOPBAR
@ SPACE_EMPTY
#define SPACE_TYPE_ANY
#define UI_SCALE_FAC
@ USER_SAVE_PROMPT
@ USER_NO_MULTITOUCH_GESTURES
@ USER_TABLET_NATIVE
@ USER_TABLET_AUTOMATIC
@ USER_TABLET_WINTAB
@ VIRTUAL_PIXEL_NATIVE
@ VIRTUAL_PIXEL_DOUBLE
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ WM_INIT_FLAG_WINDOW
int ED_file_extension_icon(const char *path)
Definition filelist.cc:2842
void ED_render_view_layer_changed(Main *bmain, bScreen *screen)
void ED_scene_change_update(Main *bmain, Scene *scene, ViewLayer *layer) ATTR_NONNULL()
void ED_area_newspace(bContext *C, ScrArea *area, int type, bool skip_region_exit)
Definition area.cc:2693
WorkSpaceLayout * ED_workspace_layout_add(Main *bmain, WorkSpace *workspace, wmWindow *win, const char *name) ATTR_NONNULL()
int ED_area_global_size_y(const ScrArea *area)
Definition area.cc:3785
void ED_screen_scene_change(bContext *C, wmWindow *win, Scene *scene, bool refresh_toolsystem)
void ED_screen_refresh(bContext *C, wmWindowManager *wm, wmWindow *win)
void ED_screen_global_areas_refresh(wmWindow *win)
bool ED_screen_change(bContext *C, bScreen *screen)
Change the active screen.
void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
blender::StringRefNull ED_area_name(const ScrArea *area)
void ED_workspace_scene_data_sync(WorkSpaceInstanceHook *hook, Scene *scene) ATTR_NONNULL()
WorkSpaceLayout * ED_workspace_layout_duplicate(Main *bmain, WorkSpace *workspace, const WorkSpaceLayout *layout_old, wmWindow *win) ATTR_NONNULL()
bool ED_workspace_change(WorkSpace *workspace_new, bContext *C, wmWindowManager *wm, wmWindow *win) ATTR_NONNULL()
Change the active workspace.
GHOST C-API function and type declarations.
GHOST_TWindowState GHOST_GetWindowState(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_putClipboardImage(uint *rgba, int width, int height)
void GHOST_SetWindowDecorationStyleSettings(GHOST_WindowHandle windowhandle, GHOST_WindowDecorationStyleSettings decorationSettings)
GHOST_TSuccess GHOST_GetCursorPosition(const GHOST_SystemHandle systemhandle, const GHOST_WindowHandle windowhandle, int32_t *x, int32_t *y)
GHOST_ContextHandle GHOST_CreateGPUContext(GHOST_SystemHandle systemhandle, GHOST_GPUSettings gpuSettings)
GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle, GHOST_TWindowOrder order)
GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_SetClientSize(GHOST_WindowHandle windowhandle, uint32_t width, uint32_t height)
GHOST_TSuccess GHOST_hasClipboardImage(void)
void GHOST_SetWindowDecorationStyleFlags(GHOST_WindowHandle windowhandle, GHOST_TWindowDecorationStyleFlags styleFlags)
GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle, int32_t x, int32_t y)
void GHOST_ShowMessageBox(GHOST_SystemHandle systemhandle, const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options)
void GHOST_ClientToScreen(GHOST_WindowHandle windowhandle, int32_t inX, int32_t inY, int32_t *outX, int32_t *outY)
GHOST_TCapabilityFlag GHOST_GetCapabilities(void)
GHOST_WindowHandle GHOST_GetWindowUnderCursor(GHOST_SystemHandle systemhandle, int32_t x, int32_t y)
GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr user_data)
GHOST_SystemHandle GHOST_CreateSystem(void)
GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
GHOST_SystemHandle GHOST_CreateSystemBackground(void)
GHOST_TSuccess GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle, uint32_t *r_width, uint32_t *r_height)
uint16_t GHOST_GetDPIHint(GHOST_WindowHandle windowhandle)
uint32_t GHOST_GetCursorPreferredLogicalSize(const GHOST_SystemHandle systemhandle)
void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle)
GHOST_TSuccess GHOST_SetPath(GHOST_WindowHandle windowhandle, const char *filepath)
void GHOST_UseWindowFocus(bool use_focus)
bool GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, bool waitForEvent)
void GHOST_SetTitle(GHOST_WindowHandle windowhandle, const char *title)
void GHOST_BeginIME(GHOST_WindowHandle windowhandle, int32_t x, int32_t y, int32_t w, int32_t h, bool complete)
GHOST_TSuccess GHOST_ReleaseGPUContext(GHOST_ContextHandle contexthandle)
void GHOST_ScreenToClient(GHOST_WindowHandle windowhandle, int32_t inX, int32_t inY, int32_t *outX, int32_t *outY)
char * GHOST_getClipboard(bool selection)
uint64_t GHOST_GetEventTime(GHOST_EventHandle eventhandle)
GHOST_TSuccess GHOST_SetProgressBar(GHOST_WindowHandle windowhandle, float progress)
GHOST_TSuccess GHOST_SetWindowModifiedState(GHOST_WindowHandle windowhandle, bool isUnsavedChanges)
GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_ActivateGPUContext(GHOST_ContextHandle contexthandle)
GHOST_TSuccess GHOST_SetWindowState(GHOST_WindowHandle windowhandle, GHOST_TWindowState state)
void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn)
void GHOST_SetTabletAPI(GHOST_SystemHandle systemhandle, GHOST_TTabletAPI api)
GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
void GHOST_SetMultitouchGestures(GHOST_SystemHandle systemhandle, const bool use)
GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle)
uint * GHOST_getClipboardImage(int *r_width, int *r_height)
GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle, GHOST_TModifierKey mask, bool *r_is_down)
GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle parent_windowhandle, const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, bool is_dialog, GHOST_GPUSettings gpuSettings)
bool GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle)
float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle)
GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
bool GHOST_IsDialogWindow(GHOST_WindowHandle windowhandle)
void GHOST_SystemInitDebug(GHOST_SystemHandle systemhandle, GHOST_Debug debug)
GHOST_TSuccess GHOST_ApplyWindowDecorationStyle(GHOST_WindowHandle windowhandle)
void GHOST_putClipboard(const char *buffer, bool selection)
void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr user_data)
const char * GHOST_SystemBackend(void)
GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
void GHOST_GetRectangle(GHOST_RectangleHandle rectanglehandle, int32_t *l, int32_t *t, int32_t *r, int32_t *b)
GHOST_TWindowDecorationStyleFlags GHOST_GetWindowDecorationStyleFlags(GHOST_WindowHandle windowhandle)
void GHOST_EndIME(GHOST_WindowHandle windowhandle)
bool GHOST_UseNativePixels(void)
void GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
GHOST_TSuccess GHOST_DisposeGPUContext(GHOST_SystemHandle systemhandle, GHOST_ContextHandle contexthandle)
GHOST_TSuccess GHOST_EndProgressBar(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_SetSwapInterval(GHOST_WindowHandle windowhandle, int interval)
GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
uint64_t GHOST_GetMilliSeconds(GHOST_SystemHandle systemhandle)
GHOST_TSuccess GHOST_GetSwapInterval(GHOST_WindowHandle windowhandle, int *r_interval)
GHOST_TSuccess GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle, uint32_t *r_width, uint32_t *r_height)
GHOST_TWindowState
@ GHOST_kWindowStateMinimized
@ GHOST_kWindowStateMaximized
@ GHOST_kWindowStateNormal
@ GHOST_kWindowStateFullScreen
void * GHOST_TUserDataPtr
Definition GHOST_Types.h:78
GHOST_TEventType
@ GHOST_kEventWindowClose
@ GHOST_kEventWindowMove
@ GHOST_kEventWindowSize
@ GHOST_kEventDraggingDropDone
@ GHOST_kEventNativeResolutionChange
@ GHOST_kEventOpenMainFile
@ GHOST_kEventButtonUp
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdateDecor
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventButtonDown
@ GHOST_kEventKeyDown
@ GHOST_kEventWindowDPIHintChanged
@ GHOST_kEventKeyUp
@ GHOST_kEventQuitRequest
@ GHOST_kDebugDefault
@ GHOST_kDebugWintab
GHOST_TCapabilityFlag
Definition GHOST_Types.h:89
@ GHOST_kCapabilityWindowPosition
Definition GHOST_Types.h:97
@ GHOST_kCapabilityKeyboardHyperKey
@ GHOST_kCapabilityGPUReadFrontBuffer
@ GHOST_kCapabilityCursorWarp
Definition GHOST_Types.h:93
@ GHOST_kCapabilityInputIME
@ GHOST_kCapabilityTrackpadPhysicalDirection
@ GHOST_kCapabilityClipboardImages
@ GHOST_kCapabilityPrimaryClipboard
@ GHOST_kCapabilityWindowDecorationStyles
@ GHOST_kCapabilityDesktopSample
GHOST_TKey
@ GHOST_kKeyLeftOS
@ GHOST_kKeyLeftAlt
@ GHOST_kKeyRightShift
@ GHOST_kKeyRightOS
@ GHOST_kKeyLeftControl
@ GHOST_kKeyLeftHyper
@ GHOST_kKeyRightAlt
@ GHOST_kKeyRightControl
@ GHOST_kKeyUnknown
@ GHOST_kKeyRightHyper
@ GHOST_kKeyLeftShift
const void * GHOST_TEventDataPtr
GHOST_TDrawingContextType
@ GHOST_kDrawingContextTypeNone
@ GHOST_kWindowOrderTop
@ GHOST_kWindowOrderBottom
GHOST_TModifierKey
@ GHOST_kModifierKeyRightControl
@ GHOST_kModifierKeyLeftControl
@ GHOST_kModifierKeyRightHyper
@ GHOST_kModifierKeyRightAlt
@ GHOST_kModifierKeyRightShift
@ GHOST_kModifierKeyLeftAlt
@ GHOST_kModifierKeyLeftShift
@ GHOST_kModifierKeyLeftOS
@ GHOST_kModifierKeyRightOS
@ GHOST_kModifierKeyLeftHyper
@ GHOST_kFailure
Definition GHOST_Types.h:80
@ GHOST_kSuccess
Definition GHOST_Types.h:80
@ GHOST_gpuStereoVisual
Definition GHOST_Types.h:69
@ GHOST_gpuDebugContext
Definition GHOST_Types.h:70
void(*) GHOST_TBacktraceFn(void *file_handle)
Definition GHOST_Types.h:56
@ GHOST_kDragnDropTypeFilenames
@ GHOST_kDragnDropTypeString
@ GHOST_kTabletAutomatic
@ GHOST_kTabletWinPointer
@ GHOST_kTabletWintab
GHOST_DialogOptions
Definition GHOST_Types.h:73
GHOST_TWindowDecorationStyleFlags
@ GHOST_kDecorationNone
@ GHOST_kDecorationColoredTitleBar
void GPU_render_end()
GPUContext * GPU_context_create(void *ghost_window, void *ghost_context)
void GPU_render_begin()
eGPUBackendType GPU_backend_type_selection_get()
void GPU_context_discard(GPUContext *)
void GPU_context_active_set(GPUContext *)
void GPU_backend_ghost_system_set(void *ghost_system_handle)
GPUFrameBuffer * GPU_framebuffer_active_get()
void GPU_clear_color(float red, float green, float blue, float alpha)
GPUFrameBuffer * GPU_framebuffer_back_get()
void GPU_init()
ImBuf * IMB_allocFromBuffer(const uint8_t *byte_buffer, const float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
void UI_block_emboss_set(uiBlock *block, blender::ui::EmbossType emboss)
void UI_block_theme_style_set(uiBlock *block, char theme_style)
uiBlock * UI_block_begin(const bContext *C, ARegion *region, std::string name, blender::ui::EmbossType emboss)
@ UI_BLOCK_THEME_STYLE_POPUP
void UI_popup_block_invoke(bContext *C, uiBlockCreateFunc func, void *arg, uiFreeArgFunc arg_free)
const uiStyle * UI_style_get_dpi()
void UI_fontstyle_set(const uiFontStyle *fs)
void UI_block_bounds_set_centered(uiBlock *block, int addval)
Definition interface.cc:667
void UI_popup_handlers_remove_all(bContext *C, ListBase *handlers)
@ ALERT_ICON_ERROR
uiLayout * uiItemsAlertBox(uiBlock *block, const uiStyle *style, const int dialog_width, const eAlertIcon icon, const int icon_size)
void uiLayoutSetScaleY(uiLayout *layout, float scale)
uiBut * uiItemL_ex(uiLayout *layout, blender::StringRef name, int icon, bool highlight, bool redalert)
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_BACK
@ TH_BUTBACK_TEXT
void UI_SetTheme(int spacetype, int regionid)
eWindowAlignment
Definition WM_api.hh:360
@ WIN_ALIGN_LOCATION_CENTER
Definition WM_api.hh:362
@ WIN_ALIGN_PARENT_CENTER
Definition WM_api.hh:363
eWM_CapabilitiesFlag
Definition WM_api.hh:166
@ WM_CAPABILITY_PRIMARY_CLIPBOARD
Definition WM_api.hh:187
@ WM_CAPABILITY_WINDOW_POSITION
Definition WM_api.hh:182
@ WM_CAPABILITY_CURSOR_WARP
Definition WM_api.hh:168
@ WM_CAPABILITY_INITIALIZED
Definition WM_api.hh:205
@ WM_CAPABILITY_TRACKPAD_PHYSICAL_DIRECTION
Definition WM_api.hh:199
@ WM_CAPABILITY_WINDOW_DECORATION_STYLES
Definition WM_api.hh:201
@ WM_CAPABILITY_GPU_FRONT_BUFFER_READ
Definition WM_api.hh:191
@ WM_CAPABILITY_KEYBOARD_HYPER_KEY
Definition WM_api.hh:203
@ WM_CAPABILITY_CLIPBOARD_IMAGES
Definition WM_api.hh:193
@ WM_CAPABILITY_DESKTOP_SAMPLE
Definition WM_api.hh:195
@ WM_CAPABILITY_INPUT_IME
Definition WM_api.hh:197
eWM_WindowDecorationStyleFlag
Definition WM_api.hh:407
@ WM_WINDOW_DECORATION_STYLE_COLORED_TITLEBAR
Definition WM_api.hh:411
@ WM_WINDOW_DECORATION_STYLE_NONE
Definition WM_api.hh:409
#define NC_WINDOW
Definition WM_types.hh:372
@ KM_CTRL
Definition WM_types.hh:276
@ KM_ALT
Definition WM_types.hh:277
@ KM_HYPER
Definition WM_types.hh:289
@ KM_OSKEY
Definition WM_types.hh:279
@ KM_SHIFT
Definition WM_types.hh:275
eWM_EventFlag
Definition WM_types.hh:668
@ WM_DRAG_NOP
Definition WM_types.hh:1225
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1226
CLG_LogRef * WM_LOG_EVENTS
#define NC_SCREEN
Definition WM_types.hh:374
#define NA_ADDED
Definition WM_types.hh:583
#define NA_EDITED
Definition WM_types.hh:581
#define NA_REMOVED
Definition WM_types.hh:584
@ WM_OP_INVOKE_DEFAULT
Definition WM_types.hh:238
@ WM_DRAG_PATH
Definition WM_types.hh:1205
@ WM_DRAG_STRING
Definition WM_types.hh:1214
float progress
Definition WM_types.hh:1019
@ WM_TIMER_TAGGED_FOR_REMOVAL
Definition WM_types.hh:945
@ WM_TIMER_NO_FREE_CUSTOM_DATA
Definition WM_types.hh:940
@ KM_NOTHING
Definition WM_types.hh:307
@ KM_RELEASE
Definition WM_types.hh:309
#define ND_LAYOUTDELETE
Definition WM_types.hh:420
#define U
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void activate(bool forceActivation=false) const
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define str(s)
#define ceil
#define printf(...)
#define MEM_SAFE_FREE(v)
#define PRIu64
Definition inttypes.h:132
const int state
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
#define G(x, y, z)
VecBase< int32_t, 2 > int2
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
GHOST_TDragnDropTypes dataType
GHOST_TDragnDropDataPtr data
int icon_id
Definition DNA_ID.h:426
ImBufByteBuffer byte_buffer
void * first
ListBase wm
Definition BKE_main.hh:276
ListBase areabase
char name[64]
GHOST_TWindowState windowstate
Definition wm_window.cc:128
blender::int2 size
Definition wm_window.cc:125
blender::int2 start
Definition wm_window.cc:126
eWinOverrideFlag override_flag
Definition wm_window.cc:129
bool window_focus
Definition wm_window.cc:131
bool native_pixels
Definition wm_window.cc:132
Wrapper for bScreen.
GHOST_TModifierKey ghost_mask_pair[2]
GHOST_TKey ghost_key_pair[2]
ListBase areabase
int ymin
int ymax
int xmin
int xmax
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
uiFontStyle widget
short columnspace
wmEventModifierFlag modifier
Definition WM_types.hh:771
int xy[2]
Definition WM_types.hh:758
int prev_xy[2]
Definition WM_types.hh:817
wmEventType keymodifier
Definition WM_types.hh:780
wmGenericCallbackFn exec
Definition WM_types.hh:150
struct ReportList * reports
wmTimerFlags flags
Definition WM_types.hh:960
bool sleep
Definition WM_types.hh:976
double time_next
Definition WM_types.hh:972
void * customdata
Definition WM_types.hh:962
wmWindow * win
Definition WM_types.hh:953
double time_start
Definition WM_types.hh:974
double time_step
Definition WM_types.hh:956
double time_last
Definition WM_types.hh:970
wmEventType event_type
Definition WM_types.hh:958
struct wmKeyConfig * defaultconf
WindowManagerRuntimeHandle * runtime
struct wmWindow * winactive
struct wmWindow * windrawable
struct wmWindow * parent
WindowRuntimeHandle * runtime
struct wmEvent * eventstate
struct wmEvent * event_last_handled
struct Scene * scene
struct wmEvent_ConsecutiveData * event_queue_consecutive_gesture_data
struct wmWindow * next
ScrAreaMap global_areas
struct WorkSpaceInstanceHook * workspace_hook
struct Stereo3dFormat * stereo3d_format
i
Definition text_draw.cc:230
void WM_check(bContext *C)
Definition wm.cc:473
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:15
wmDragPath * WM_drag_create_path_data(blender::Span< const char * > paths)
void WM_event_start_drag(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
ListBase * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
void wm_draw_update(bContext *C)
Definition wm_draw.cc:1581
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes)
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
void wm_event_do_handlers(bContext *C)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
void WM_event_consecutive_data_free(wmWindow *win)
void WM_main_add_notifier(uint type, void *reference)
void wm_event_free_all(wmWindow *win)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
wmEvent * WM_event_add(wmWindow *win, const wmEvent *event_to_add)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void wm_event_do_notifiers(bContext *C)
void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type, const void *customdata, const uint64_t event_time_ms)
void wm_event_init_from_window(wmWindow *win, wmEvent *event)
void WM_event_remove_handlers(bContext *C, ListBase *handlers)
@ EVT_DATA_DRAGDROP
@ EVT_DATA_TIMER
wmEventType
@ TIMERNOTIFIER
@ TIMERJOBS
@ TIMERAUTOSAVE
@ EVENT_NONE
@ MOUSEMOVE
@ EVT_DROP
#define ISTIMER(event_type)
bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWindowManager *wm)
Definition wm_files.cc:184
void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *)
Definition wm_files.cc:2386
void wm_close_file_dialog(bContext *C, wmGenericCallback *post_action)
Definition wm_files.cc:4868
void WM_gestures_free_all(wmWindow *win)
void wm_exit_schedule_delayed(const bContext *C)
void wm_jobs_timer_end(wmWindowManager *wm, wmTimer *wt)
Definition wm_jobs.cc:649
void wm_jobs_timer(wmWindowManager *wm, wmTimer *wt)
Definition wm_jobs.cc:657
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:893
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
void WM_operator_properties_free(PointerRNA *ptr)
static bool ghost_event_proc(GHOST_EventHandle ghost_event, GHOST_TUserDataPtr ps_void_ptr)
static void ghost_event_proc_timestamp_warning(GHOST_EventHandle ghost_event)
ViewLayer * WM_windows_view_layer_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
blender::int2 WM_window_native_pixel_size(const wmWindow *win)
eWinOverrideFlag
Definition wm_window.cc:102
@ WIN_OVERRIDE_WINSTATE
Definition wm_window.cc:104
@ WIN_OVERRIDE_GEOM
Definition wm_window.cc:103
wmWindow * wm_window_copy(Main *bmain, wmWindowManager *wm, wmWindow *win_src, const bool duplicate_layout, const bool child)
Definition wm_window.cc:333
static void wm_window_ghostwindow_ensure(wmWindowManager *wm, wmWindow *win, bool is_dialog)
Definition wm_window.cc:925
ModSide
Definition wm_window.cc:161
@ MOD_SIDE_RIGHT
Definition wm_window.cc:163
@ MOD_SIDE_LEFT
Definition wm_window.cc:162
void WM_window_set_active_scene(Main *bmain, bContext *C, wmWindow *win, Scene *scene)
wmOperatorStatus wm_window_new_exec(bContext *C, wmOperator *op)
eWM_WindowDecorationStyleFlag WM_window_decoration_style_flags_get(const wmWindow *win)
Definition wm_window.cc:631
void wm_cursor_position_from_ghost_screen_coords(wmWindow *win, int *x, int *y)
static GHOST_SystemHandle g_system
Definition wm_window.cc:97
wmWindow * wm_window_new(const Main *bmain, wmWindowManager *wm, wmWindow *parent, bool dialog)
Definition wm_window.cc:317
static void wm_clipboard_text_set_impl(const char *buf, bool selection)
void WM_clipboard_text_set(const char *buf, bool selection)
void wm_window_raise(wmWindow *win)
void WM_window_ensure_active_view_layer(wmWindow *win)
static char * wm_clipboard_text_get_impl(bool selection)
static void wm_window_check_size(rcti *rect)
Definition wm_window.cc:199
void wm_window_swap_buffers(wmWindow *win)
Push rendered buffer to the screen.
ImBuf * WM_clipboard_image_get()
Scene * WM_windows_scene_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
void WM_init_input_devices()
#define GHOST_WINDOW_STATE_DEFAULT
Definition wm_window.cc:108
void WM_init_state_maximized_set()
void WM_window_set_active_workspace(bContext *C, wmWindow *win, WorkSpace *workspace)
bool WM_window_is_main_top_level(const wmWindow *win)
void wm_cursor_position_to_ghost_client_coords(wmWindow *win, int *x, int *y)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
void wm_cursor_position_from_ghost_client_coords(wmWindow *win, int *x, int *y)
void wm_test_gpu_backend_fallback(bContext *C)
void wm_cursor_position_to_ghost_screen_coords(wmWindow *win, int *x, int *y)
void wm_ghost_exit()
char * WM_clipboard_text_get_firstline(bool selection, bool ensure_utf8, int *r_len)
static char * wm_clipboard_text_get_ex(bool selection, int *r_len, const bool ensure_utf8, const bool firstline)
static struct WMInitStruct wm_init_state
static void wm_window_ensure_eventstate(wmWindow *win)
Definition wm_window.cc:809
struct @127032272312020020264064310203323227024013067203 * g_wm_clipboard_text_simulate
void wm_quit_with_optional_confirmation_prompt(bContext *C, wmWindow *win)
Definition wm_window.cc:405
void * WM_system_gpu_context_create()
static uint8_t wm_ghost_modifier_query(const enum ModSide side)
void WM_cursor_warp(wmWindow *win, int x, int y)
void wm_window_reset_drawable()
void WM_event_timers_free_all(wmWindowManager *wm)
bool wm_get_screensize(int r_size[2])
Definition wm_window.cc:176
static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wmWindow *win, bool is_dialog)
Definition wm_window.cc:822
void wm_window_events_process(const bContext *C)
WorkSpaceLayout * WM_window_get_active_layout(const wmWindow *win)
void WM_system_gpu_context_dispose(void *context)
void WM_event_timer_free_data(wmTimer *timer)
void WM_event_timer_sleep(wmWindowManager *wm, wmWindow *, wmTimer *timer, bool do_sleep)
void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
void wm_test_opengl_deprecation_warning(bContext *C)
static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:212
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
bool WM_window_is_fullscreen(const wmWindow *win)
void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:437
void wm_window_set_swap_interval(wmWindow *win, int interval)
static void wm_window_update_eventstate_modifiers(wmWindowManager *wm, wmWindow *win, const uint64_t event_time_ms)
Definition wm_window.cc:708
void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
static bool wm_window_timers_process(const bContext *C, int *sleep_us_p)
static void wm_confirm_quit(bContext *C)
Definition wm_window.cc:398
wmOperatorStatus wm_window_close_exec(bContext *C, wmOperator *)
void WM_init_native_pixels(bool do_it)
void wm_window_set_size(wmWindow *win, int width, int height)
void WM_window_set_dpi(const wmWindow *win)
Definition wm_window.cc:579
void wm_ghost_init_background()
WorkSpace * WM_windows_workspace_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
int WM_window_native_pixel_y(const wmWindow *win)
int WM_window_native_pixel_x(const wmWindow *win)
bool wm_window_get_swap_interval(wmWindow *win, int *r_interval)
void wm_clipboard_free()
wmTimer * WM_event_timer_add_notifier(wmWindowManager *wm, wmWindow *win, const uint type, const double time_step)
void wm_window_ghostwindows_remove_invalid(bContext *C, wmWindowManager *wm)
wmWindow * WM_window_open(bContext *C, const char *title, const rcti *rect_unscaled, int space_type, bool toplevel, bool dialog, bool temp, eWindowAlignment alignment, void(*area_setup_fn)(bScreen *screen, ScrArea *area, void *user_data), void *area_setup_user_data)
void WM_system_gpu_context_activate(void *context)
void WM_event_timer_remove_notifier(wmWindowManager *wm, wmWindow *win, wmTimer *timer)
void wm_window_clear_drawable(wmWindowManager *wm)
static uiBlock * block_create_gpu_backend_fallback(bContext *C, ARegion *region, void *)
static const struct @063115102034100037007115104355064154354352365327 g_modifier_table[]
wmOperatorStatus wm_window_new_main_exec(bContext *C, wmOperator *op)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
static int find_free_winid(wmWindowManager *wm)
Definition wm_window.cc:305
void WM_progress_clear(wmWindow *win)
void WM_init_state_size_set(int stax, int stay, int sizx, int sizy)
static void wm_window_decoration_style_set_from_theme(const wmWindow *win, const bScreen *screen)
Definition wm_window.cc:660
void WM_progress_set(wmWindow *win, float progress)
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
wmWindow * wm_window_copy_test(bContext *C, wmWindow *win_src, const bool duplicate_layout, const bool child)
Definition wm_window.cc:363
static bool wm_window_update_size_position(wmWindow *win)
bool WM_clipboard_image_available()
static uiBlock * block_create_opengl_usage_warning(bContext *C, ARegion *region, void *)
const char * WM_ghost_backend()
bool WM_window_is_temp_screen(const wmWindow *win)
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
eWM_CapabilitiesFlag WM_capabilities_flag()
bool WM_window_is_maximized(const wmWindow *win)
uint WM_cursor_preferred_logical_size()
void WM_window_set_active_layout(wmWindow *win, WorkSpace *workspace, WorkSpaceLayout *layout)
wmWindow * WM_window_find_by_area(wmWindowManager *wm, const ScrArea *area)
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
void WM_window_set_active_view_layer(wmWindow *win, ViewLayer *view_layer)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
void WM_init_state_fullscreen_set()
static void wm_window_update_eventstate(wmWindow *win)
Definition wm_window.cc:800
void WM_init_state_normal_set()
Scene * WM_window_get_active_scene(const wmWindow *win)
static void wm_save_file_on_quit_dialog_callback(bContext *C, void *)
Definition wm_window.cc:389
static const char * g_system_backend_id
Definition wm_window.cc:99
static void wm_window_update_eventstate_modifiers_clear(wmWindowManager *wm, wmWindow *win, const uint64_t event_time_ms)
Definition wm_window.cc:763
static void wm_window_set_drawable(wmWindowManager *wm, wmWindow *win, bool activate)
void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:240
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
void WM_window_title(wmWindowManager *wm, wmWindow *win, const char *title)
Definition wm_window.cc:493
void wm_ghost_init(bContext *C)
GHOST_TDrawingContextType wm_ghost_drawing_context_type(const eGPUBackendType gpu_backend)
bool WM_clipboard_image_set_byte_buffer(ImBuf *ibuf)
void WM_windows_scene_data_sync(const ListBase *win_lb, Scene *scene)
void wm_window_ghostwindows_ensure(wmWindowManager *wm)
Definition wm_window.cc:993
void WM_init_window_focus_set(bool do_it)
void WM_window_decoration_style_flags_set(const wmWindow *win, eWM_WindowDecorationStyleFlag style_flags)
Definition wm_window.cc:645
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
bool wm_get_desktopsize(int r_size[2])
Definition wm_window.cc:187
void wm_window_timers_delete_removed(wmWindowManager *wm)
wmOperatorStatus wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *)
void wm_window_lower(wmWindow *win)
void WM_ghost_show_message_box(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options)
void WM_system_gpu_context_release(void *context)
bScreen * WM_window_get_active_screen(const wmWindow *win)
void WM_window_decoration_style_apply(const wmWindow *win, const bScreen *screen)
Definition wm_window.cc:691
bool wm_xr_events_handle(wmWindowManager *wm)
Definition wm_xr.cc:142