Blender V5.3
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
31#include "GHOST_IContext.hh"
32#include "GHOST_IEvent.hh"
33#include "GHOST_ISystem.hh"
34#include "GHOST_IWindow.hh"
35#include "GHOST_Types.hh"
36
37#include "BLI_enum_flags.hh"
38#include "BLI_fileops.hh"
39#include "BLI_listbase.hh"
40#include "BLI_math_vector_c.hh"
41#include "BLI_path_utils.hh"
42#include "BLI_rect.hh"
43#include "BLI_string.hh"
44#include "BLI_string_utf8.hh"
45#include "BLI_system.hh"
46#include "BLI_time.hh"
47
48#include "BLT_translation.hh"
49
50#include "BKE_autoexec.hh"
51#include "BKE_blender_version.h"
52#include "BKE_context.hh"
53#include "BKE_global.hh"
54#include "BKE_icons.hh"
55#include "BKE_layer.hh"
56#include "BKE_main.hh"
57#include "BKE_recents.hh"
58#include "BKE_report.hh"
59#include "BKE_screen.hh"
60#include "BKE_wm_runtime.hh"
61#include "BKE_workspace.hh"
62
63#include "PRF_profile.hh"
64
65#include "RNA_access.hh"
66#include "RNA_enum_types.hh"
67
68#include "WM_api.hh"
69#include "WM_keymap.hh"
70#include "WM_types.hh"
71#include "wm.hh"
72#include "wm_draw.hh"
73#include "wm_event_system.hh"
74#include "wm_files.hh"
75#include "wm_window.hh"
76#include "wm_window_private.hh"
77#ifdef WITH_XR_OPENXR
78# include "wm_xr.hh"
79#endif
80
81#include "ED_anim_api.hh"
82#include "ED_fileselect.hh"
83#include "ED_render.hh"
84#include "ED_scene.hh"
85#include "ED_screen.hh"
86
87#include "IMB_imbuf.hh"
88#include "IMB_imbuf_types.hh"
89
90#include "UI_interface.hh"
91#include "UI_interface_icons.hh"
93
94#include "BLF_api.hh"
95#include "GPU_capabilities.hh"
96#include "GPU_context.hh"
97#include "GPU_framebuffer.hh"
98#include "GPU_init_exit.hh"
99
100#include "UI_resources.hh"
101
102#ifdef WITH_GHOST_WAYLAND
103# include "wm_window_icon.hh"
104#endif
105
106/* For assert. */
107#ifndef NDEBUG
108# include "BLI_threads.hh"
109#endif
110
111namespace blender {
112
114
115/* The global to talk to GHOST. */
116static GHOST_ISystem *g_system = nullptr;
117#if !(defined(WIN32) || defined(__APPLE__))
118static const char *g_system_backend_id = nullptr;
119#endif
120
121#ifdef WITH_GHOST_CSD
122static bool g_system_use_csd = false;
123#endif
124
125static CLG_LogRef LOG_GHOST_SYSTEM = {"ghost.system"};
126
132
133#define GHOST_WINDOW_STATE_DEFAULT GHOST_kWindowStateMaximized
134
160
161/* -------------------------------------------------------------------- */
164
165static const struct {
169} g_modifier_table[] = {
170 {KM_SHIFT,
173 {KM_CTRL,
176 {KM_ALT,
179 {KM_OSKEY,
182 {KM_HYPER,
186
191
193
194/* -------------------------------------------------------------------- */
197
198static void wm_window_set_drawable(wmWindowManager *wm, wmWindow *win, bool activate);
199static bool wm_window_timers_process(const bContext *C, int *sleep_us_p);
200static uint8_t wm_ghost_modifier_query(const enum ModSide side);
201
202bool wm_get_screensize(int r_size[2])
203{
204 uint32_t uiwidth = 0;
205 uint32_t uiheight = 0;
206 g_system->getMainDisplayDimensions(uiwidth, uiheight);
207
208 if (uiwidth == 0 && uiheight == 0) {
209 return false;
210 }
211
212 r_size[0] = uiwidth;
213 r_size[1] = uiheight;
214 return true;
215}
216
217bool wm_get_desktopsize(int r_size[2])
218{
219 uint32_t uiwidth = 0;
220 uint32_t uiheight = 0;
221 g_system->getAllDisplayDimensions(uiwidth, uiheight);
222
223 if (uiwidth == 0 && uiheight == 0) {
224 return false;
225 }
226
227 r_size[0] = uiwidth;
228 r_size[1] = uiheight;
229 return true;
230}
231
233static void wm_window_check_size(rcti *rect)
234{
235 int2 scr_size;
236 if (wm_get_screensize(scr_size)) {
237 if (BLI_rcti_size_x(rect) > scr_size[0]) {
238 BLI_rcti_resize_x(rect, scr_size[0]);
239 }
240 if (BLI_rcti_size_y(rect) > scr_size[1]) {
241 BLI_rcti_resize_y(rect, scr_size[1]);
242 }
243 }
244}
245
247{
248 if (!win->runtime->ghostwin) [[unlikely]] {
249 return;
250 }
251
252 /* Prevents non-drawable state of main windows (bugs #22967,
253 * #25071 and possibly #22477 too). Always clear it even if
254 * this window was not the drawable one, because we mess with
255 * drawing context to discard the GW context. */
257
258 if (win == wm->runtime->winactive) {
259 wm->runtime->winactive = nullptr;
260 }
261
262 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
263
264 /* We need this window's GPU context active to discard it. */
265 ghost_window->activateDrawingContext();
266 GPU_context_active_set(static_cast<GPUContext *>(win->runtime->gpuctx));
267
268 /* Delete local GPU context. */
269 GPU_context_discard(static_cast<GPUContext *>(win->runtime->gpuctx));
270
271 g_system->disposeWindow(ghost_window);
272 win->runtime->ghostwin = nullptr;
273 win->runtime->gpuctx = nullptr;
274}
275
277{
278 /* Update context. */
279 if (C) {
282
283 if (CTX_wm_window(C) == win) {
284 CTX_wm_window_set(C, nullptr);
285 }
286 }
287
289
290 /* End running jobs, a job end also removes its timer. */
291 for (wmTimer &wt : wm->runtime->timers.items_mutable()) {
292 if (wt.flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
293 continue;
294 }
295 if (wt.win == win && wt.event_type == TIMERJOBS) {
296 wm_jobs_timer_end(wm, &wt);
297 }
298 }
299
300 /* Timer removing, need to call this API function. */
301 for (wmTimer &wt : wm->runtime->timers.items_mutable()) {
302 if (wt.flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
303 continue;
304 }
305 if (wt.win == win) {
306 WM_event_timer_remove(wm, win, &wt);
307 }
308 }
310
311 if (win->runtime->eventstate) {
312 MEM_delete(win->runtime->eventstate);
313 }
314 if (win->runtime->event_last_handled) {
315 MEM_delete(win->runtime->event_last_handled);
316 }
319 }
320
322
324
326
328
330 MEM_delete(win->stereo3d_format);
331
332 MEM_delete(win->runtime);
333 MEM_delete(win);
334}
335
337{
338 int id = 1;
339
340 for (wmWindow &win : wm->windows) {
341 if (id <= win.winid) {
342 id = win.winid + 1;
343 }
344 }
345 return id;
346}
347
348wmWindow *wm_window_new(const Main *bmain, wmWindowManager *wm, wmWindow *parent, bool dialog)
349{
350 wmWindow *win = MEM_new<wmWindow>("window");
351
352 BLI_addtail(&wm->windows, win);
353 win->winid = find_free_winid(wm);
354
355 /* Dialogs may have a child window as parent. Otherwise, a child must not be a parent too. */
356 win->parent = (!dialog && parent && parent->parent) ? parent->parent : parent;
357 win->stereo3d_format = MEM_new<Stereo3dFormat>("Stereo 3D Format (window)");
359 win->runtime = MEM_new<bke::WindowRuntime>(__func__);
360
361 return win;
362}
363
366 wmWindow *win_src,
367 const bool duplicate_layout,
368 const bool child)
369{
370 const GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win_src->runtime->ghostwin);
371 wmWindow *win_parent = (child) ? win_src : win_src->parent;
372 wmWindow *win_dst = wm_window_new(bmain, wm, win_parent, ghost_window->isDialog());
373 WorkSpace *workspace = WM_window_get_active_workspace(win_src);
374 WorkSpaceLayout *layout_old = WM_window_get_active_layout(win_src);
375
376 win_dst->posx = win_src->posx + 10;
377 win_dst->posy = win_src->posy;
378 win_dst->sizex = win_src->sizex;
379 win_dst->sizey = win_src->sizey;
380
381 win_dst->scene = win_src->scene;
382 STRNCPY_UTF8(win_dst->view_layer_name, win_src->view_layer_name);
383 BKE_workspace_active_set(win_dst->workspace_hook, workspace);
384 WorkSpaceLayout *layout_new = duplicate_layout ? ED_workspace_layout_duplicate(
385 bmain, workspace, layout_old, win_dst) :
386 layout_old;
387 BKE_workspace_active_layout_set(win_dst->workspace_hook, win_dst->winid, workspace, layout_new);
388
389 *win_dst->stereo3d_format = *win_src->stereo3d_format;
390
391 return win_dst;
392}
393
395 wmWindow *win_src,
396 const bool duplicate_layout,
397 const bool child)
398{
399 Main *bmain = CTX_data_main(C);
401
402 wmWindow *win_dst = wm_window_copy(bmain, wm, win_src, duplicate_layout, child);
403
404 WM_check(C);
405
406 if (win_dst->runtime->ghostwin) {
408 return win_dst;
409 }
410 wm_window_close(C, wm, win_dst);
411 return nullptr;
412}
413
415
416/* -------------------------------------------------------------------- */
419
420static void wm_save_file_on_quit_dialog_callback(bContext *C, void * /*user_data*/)
421{
423}
424
430{
431 wmGenericCallback *action = MEM_new<wmGenericCallback>(__func__);
433 wm_close_file_dialog(C, action);
434}
435
437{
438 wmWindow *win_ctx = CTX_wm_window(C);
439
440 /* The popup will be displayed in the context window which may not be set
441 * here (this function gets called outside of normal event handling loop). */
442 CTX_wm_window_set(C, win);
443
444 if (U.uiflag & USER_SAVE_PROMPT) {
446 !G.background)
447 {
448 wm_window_raise(win);
450 }
451 else {
453 }
454 }
455 else {
457 }
458
459 CTX_wm_window_set(C, win_ctx);
460}
461
463
464/* -------------------------------------------------------------------- */
467
469{
470 if (win->parent) {
471 return false;
472 }
473 wmWindow *win_other;
474 for (win_other = wm->windows.first(); win_other; win_other = win_other->next) {
475 if (win_other != win && win_other->parent == nullptr && !WM_window_is_temp_screen(win_other)) {
476 return false;
477 }
478 }
479 /* This window is the last. */
480 return true;
481}
482
484{
485 /* First check if there is another main window remaining. */
488 return;
489 }
490
492 /* While unlikely, don't crash if the window wasn't initialized properly. */
493 (win->runtime->ghostwin != nullptr))
494 {
496 if (screen && screen->temp && BLI_listbase_is_single(&screen->areabase)) {
497 if (!win->runtime->recents_storage_key.empty()) {
498 /* Get DPI and scale from parent window, if there is one. */
499 WM_window_dpi_set_userdef(win->parent ? win->parent : win);
500
501 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
502 const float fac = ghost_window->getNativePixelSize() / UI_SCALE_FAC;
503
504 std::vector<float> bounds = {float(win->posx) * fac,
505 float(win->posx) * fac + float(win->sizex) * fac,
506 float(win->posy) * fac,
507 float(win->posy) * fac + float(win->sizey) * fac};
508
509 recents::Section("temp.window.dimensions").set(win->runtime->recents_storage_key, bounds);
510 }
511 }
512 }
513
514 wm_window_close(C, wm, win);
515}
516
518{
520
521 /* Close child windows. */
522 for (wmWindow &iter_win : wm->windows.items_mutable()) {
523 if (iter_win.parent == win) {
524 wm_window_close(C, wm, &iter_win);
525 }
526 }
527
530
531 BLI_remlink(&wm->windows, win);
532
533 CTX_wm_window_set(C, win); /* Needed by handlers. */
535
537
538 /* For regular use this will _never_ be nullptr,
539 * however we may be freeing an improperly initialized window. */
540 if (screen) {
541 ED_screen_exit(C, win, screen);
542 }
543 const bool is_single_editor = !WM_window_is_main_top_level(win) &&
544 (screen && BLI_listbase_is_single(&screen->areabase));
545
546 wm_window_free(C, wm, win);
547
548 /* If temp screen, delete it after window free (it stops jobs that can access it).
549 * Also delete windows with single editor. If required, they are easy to restore, see: !132978.
550 */
551 if ((screen && screen->temp) || is_single_editor) {
552 Main *bmain = CTX_data_main(C);
553
555 BKE_workspace_layout_remove(bmain, workspace, layout);
557 }
558
560}
561
563static void wm_window_title_project_append(fmt::memory_buffer &win_title)
564{
566 win_title.append(StringRef(" - "));
567 win_title.append(project->get_name());
568 }
569}
570
582 wmWindow *win,
583 std::optional<FunctionRef<void(const char *)>> window_filepath_fn,
584 fmt::memory_buffer &win_title)
585{
586 if (win->parent || WM_window_is_temp_screen(win)) {
587 /* Not a main window. */
589 const bool is_single = screen && BLI_listbase_is_single(&screen->areabase);
590 ScrArea *area = (screen) ? screen->areabase.first() : nullptr;
591 if (is_single && area && area->spacetype != SPACE_EMPTY) {
592 win_title.append(StringRef(IFACE_(ED_area_name(area).c_str())));
593
594 /* Append the project name to the Project Settings editor. */
595 if (area->spacetype == SPACE_PROJECT) {
597 }
598 }
599 else {
600 win_title.append(StringRef("Blender"));
601 }
602 return;
603 }
604
605 /* This path may contain invalid UTF8 byte sequences on UNIX systems,
606 * use `filepath` for display which is sanitized as needed. */
607 const char *filepath_as_bytes = BKE_main_blendfile_path_from_global();
608
609 char _filepath_utf8_buf[FILE_MAX];
610 /* Allow non-UTF8 characters on systems that support it.
611 *
612 * On Wayland, invalid UTF8 characters will disconnect
613 * from the server - exiting immediately. */
614 const char *filepath = (OS_MAC || OS_WINDOWS) ?
615 filepath_as_bytes :
617 strlen(filepath_as_bytes),
618 '?',
619 _filepath_utf8_buf,
620 sizeof(_filepath_utf8_buf));
621
622 const char *filename = BLI_path_basename(filepath);
623 const bool has_filepath = filepath[0] != '\0';
624 const bool native_filepath_display = (window_filepath_fn != std::nullopt);
625 if (native_filepath_display) {
626 (*window_filepath_fn)(filepath_as_bytes);
627 }
628 const bool include_filepath = has_filepath && (filepath != filename) && !native_filepath_display;
629
630 /* File saved state. */
631 if (!wm->file_saved) {
632 win_title.append(StringRef("* "));
633 }
634
635 /* File name. Show the file extension if the full file path is not included in the title. */
636 if (include_filepath) {
637 const char *filename_no_ext_end = BLI_path_extension_or_end(filename);
638 win_title.append(filename, filename_no_ext_end);
639 }
640 else if (has_filepath) {
641 win_title.append(StringRef(filename));
642 }
643 /* New / Unsaved file default title. Shows "Untitled" on macOS following the Apple HIGs. */
644 else {
645#ifdef __APPLE__
646 win_title.append(StringRef(IFACE_("Untitled")));
647#else
648 win_title.append(StringRef(IFACE_("(Unsaved)")));
649#endif
650 }
651
652 if (G_MAIN->recovered) {
653 win_title.append(StringRef(IFACE_(" (Recovered)")));
654 }
655
656 if (include_filepath) {
657 bool add_filepath = true;
658 if ((OS_MAC || OS_WINDOWS) == 0) {
659 /* Notes:
660 * - Relies on the `filepath_as_bytes` & `filepath` being aligned and the same length.
661 * If that changes (if we implement surrogate escape for example)
662 * then the substitution would need to be performed before validating UTF8.
663 * - This file-path is already normalized
664 * so there is no need to use a comparison that normalizes both.
665 *
666 * See !141059 for more general support for "My Documents", "Downloads" etc,
667 * this also caches the result, which doesn't seem necessary at the moment. */
668 if (const char *home_dir = BLI_dir_home()) {
669 size_t home_dir_len = strlen(home_dir);
670 /* Strip trailing slash (if it exists). */
671 while (home_dir_len && home_dir[home_dir_len - 1] == SEP) {
672 home_dir_len--;
673 }
674 if ((home_dir_len > 0) && BLI_path_ncmp(home_dir, filepath_as_bytes, home_dir_len) == 0) {
675 if (filepath_as_bytes[home_dir_len] == SEP) {
676 win_title.append(StringRef(" [~"));
677 win_title.append(StringRef(filepath + home_dir_len));
678 win_title.push_back(']');
679 add_filepath = false;
680 }
681 }
682 }
683 }
684 if (add_filepath) {
685 win_title.append(StringRef(" ["));
686 win_title.append(StringRef(filepath));
687 win_title.push_back(']');
688 }
689 }
690
691 /* If a project is active, display its name. */
693
694 win_title.append(StringRef(" — Blender "));
695 win_title.append(StringRef(BKE_blender_version_string()));
696}
697
699{
700 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
701
702 /* Informs GHOST of unsaved changes to set the window modified visual indicator (macOS)
703 * and to give a hint of unsaved changes for a user warning mechanism in case of OS application
704 * terminate request (e.g., OS Shortcut Alt+F4, Command+Q, (...) or session end). */
705 ghost_window->setModifiedState(!wm->file_saved);
706}
707
708void WM_window_title_set(wmWindow *win, const char *title)
709{
710 if (win->runtime->ghostwin == nullptr) {
711 return;
712 }
713
714 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
715 ghost_window->setTitle(title);
716}
717
719{
720 if (win->runtime->ghostwin == nullptr) {
721 return;
722 }
723
724 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
725 auto window_filepath_fn = (WM_capabilities_flag() & WM_CAPABILITY_WINDOW_PATH) ?
726 std::optional([&ghost_window](const char *filepath) {
727 ghost_window->setPath(filepath);
728 }) :
729 std::nullopt;
730 fmt::memory_buffer win_title;
731 wm_window_title_text(wm, win, window_filepath_fn, win_title);
732 win_title.push_back('\0');
733 ghost_window->setTitle(win_title.data());
735}
736
738{
739 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
740 float auto_dpi = ghost_window->getDPIHint();
741
742 /* Clamp auto DPI to 96, since our font/interface drawing does not work well
743 * with lower sizes. The main case we are interested in supporting is higher
744 * DPI. If a smaller UI is desired it is still possible to adjust UI scale. */
745 auto_dpi = max_ff(auto_dpi, 96.0f);
746
747 /* Lazily init UI scale size, preserving backwards compatibility by
748 * computing UI scale from ratio of previous DPI and auto DPI. */
749 if (U.ui_scale == 0) {
750 int virtual_pixel = (U.virtual_pixel == VIRTUAL_PIXEL_NATIVE) ? 1 : 2;
751
752 if (U.dpi == 0) {
753 U.ui_scale = virtual_pixel;
754 }
755 else {
756 U.ui_scale = (virtual_pixel * U.dpi * 96.0f) / (auto_dpi * 72.0f);
757 }
758
759 CLAMP(U.ui_scale, 0.25f, 4.0f);
760 }
761
762 /* Blender's UI drawing assumes DPI 72 as a good default following macOS
763 * while Windows and Linux use DPI 96. GHOST assumes a default 96 so we
764 * remap the DPI to Blender's convention. */
765 auto_dpi *= ghost_window->getNativePixelSize();
766 U.dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f);
767
768 /* Automatically set larger pixel size for high DPI. */
769 int pixelsize = max_ii(1, (U.dpi / 64));
770 /* User adjustment for pixel size. */
771 pixelsize = max_ii(1, pixelsize + U.ui_line_width);
772
773 /* Set user preferences globals for drawing, and for forward compatibility. */
774 U.pixelsize = pixelsize;
775 U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE;
776 U.scale_factor = U.dpi / 72.0f;
777 U.inv_scale_factor = 1.0f / U.scale_factor;
778
779 /* Widget unit is 20 pixels at 1X scale. This consists of 18 user-scaled units plus
780 * left and right borders of line-width (pixel-size). */
781 U.widget_unit = int(roundf(18.0f * U.scale_factor)) + (2 * pixelsize);
782}
783
785{
786 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
787
788 const uint16_t dpi_base = 96;
789 const uint16_t dpi_fixed = std::max<uint16_t>(dpi_base, ghost_window->getDPIHint());
790
791 float dpi = float(dpi_fixed);
792 if (OS_MAC) {
793 dpi *= ghost_window->getNativePixelSize();
794 }
795
796 return dpi / float(dpi_base);
797}
798
800
801/* -------------------------------------------------------------------- */
804
806{
807 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
808 const GHOST_TWindowDecorationStyleFlags ghost_style_flags =
809 ghost_window->getWindowDecorationStyleFlags();
810
812
813 if (ghost_style_flags & GHOST_kDecorationColoredTitleBar) {
815 }
816
817 return wm_style_flags;
818}
819
822{
824 uint ghost_style_flags = GHOST_kDecorationNone;
825
827 ghost_style_flags |= GHOST_kDecorationColoredTitleBar;
828 }
829
830 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
831 ghost_window->setWindowDecorationStyleFlags(
832 static_cast<GHOST_TWindowDecorationStyleFlags>(ghost_style_flags));
833}
834
836{
837 /* NOTE: screen may be null. In which case, only the window is used as a theme provider. */
838
839 /* For main windows, use the top-bar color. */
842 }
843 /* For single editor floating windows, use the editor header color. */
844 else if (screen && BLI_listbase_is_single(&screen->areabase)) {
845 const ScrArea *main_area = screen->areabase.first();
847 }
848 /* For floating window with multiple editors/areas, use the default space color. */
849 else {
851 }
852}
853
854static void wm_window_decoration_style_set_from_theme(const wmWindow *win, const bScreen *screen)
855{
856 /* Set the decoration style settings from the current theme colors. */
857 GHOST_WindowDecorationStyleSettings decoration_settings = {};
858
859 /* Colored TitleBar Decoration. */
861
862 float titlebar_bg_color[3];
863 ui::theme::get_color_3fv(TH_BACK, titlebar_bg_color);
864 copy_v3_v3(decoration_settings.colored_titlebar_bg_color, titlebar_bg_color);
865
866 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
867 ghost_window->setWindowDecorationStyleSettings(decoration_settings);
868}
869
878
890 wmWindow *win,
891 const uint64_t event_time_ms)
892{
893 const uint8_t keymodifier_sided[2] = {
896 };
897 const uint8_t keymodifier = keymodifier_sided[0] | keymodifier_sided[1];
898 const uint8_t keymodifier_eventstate = win->runtime->eventstate->modifier;
899 if (keymodifier != keymodifier_eventstate) {
900 GHOST_TEventKeyData kdata{};
901 kdata.key = GHOST_kKeyUnknown;
902 kdata.utf8_buf[0] = '\0';
903 kdata.is_repeat = false;
904 for (int i = 0; i < ARRAY_SIZE(g_modifier_table); i++) {
905 if (keymodifier_eventstate & g_modifier_table[i].flag) {
906 if ((keymodifier & g_modifier_table[i].flag) == 0) {
907 for (int side = 0; side < 2; side++) {
908 if ((keymodifier_sided[side] & g_modifier_table[i].flag) == 0) {
909 kdata.key = g_modifier_table[i].ghost_key_pair[side];
910 wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata, event_time_ms);
911 /* Only ever send one release event
912 * (currently releasing multiple isn't needed and only confuses logic). */
913 break;
914 }
915 }
916 }
917 }
918 else {
919 if (keymodifier & g_modifier_table[i].flag) {
920 for (int side = 0; side < 2; side++) {
921 if (keymodifier_sided[side] & g_modifier_table[i].flag) {
922 kdata.key = g_modifier_table[i].ghost_key_pair[side];
923 wm_event_add_ghostevent(wm, win, GHOST_kEventKeyDown, &kdata, event_time_ms);
924 }
925 }
926 }
927 }
928 }
929 }
930}
931
945 wmWindow *win,
946 const uint64_t event_time_ms)
947{
948 /* Release all held modifiers before de-activating the window. */
949 if (win->runtime->eventstate->modifier != 0) {
950 const uint8_t keymodifier_eventstate = win->runtime->eventstate->modifier;
951 const uint8_t keymodifier_l = wm_ghost_modifier_query(MOD_SIDE_LEFT);
952 const uint8_t keymodifier_r = wm_ghost_modifier_query(MOD_SIDE_RIGHT);
953 /* NOTE(@ideasman42): when non-zero, there are modifiers held in
954 * `win->runtime->eventstate` which are not considered held by the GHOST internal state.
955 * While this should not happen, it's important all modifier held in event-state
956 * receive release events. Without this, so any events generated while the window
957 * is *not* active will have modifiers held. */
958 const uint8_t keymodifier_unhandled = keymodifier_eventstate &
959 ~(keymodifier_l | keymodifier_r);
960 const uint8_t keymodifier_sided[2] = {
961 uint8_t(keymodifier_l | keymodifier_unhandled),
962 keymodifier_r,
963 };
964 GHOST_TEventKeyData kdata{};
965 kdata.key = GHOST_kKeyUnknown;
966 kdata.utf8_buf[0] = '\0';
967 kdata.is_repeat = false;
968 for (int i = 0; i < ARRAY_SIZE(g_modifier_table); i++) {
969 if (keymodifier_eventstate & g_modifier_table[i].flag) {
970 for (int side = 0; side < 2; side++) {
971 if ((keymodifier_sided[side] & g_modifier_table[i].flag) == 0) {
972 kdata.key = g_modifier_table[i].ghost_key_pair[side];
973 wm_event_add_ghostevent(wm, win, GHOST_kEventKeyUp, &kdata, event_time_ms);
974 }
975 }
976 }
977 }
978 }
979}
980
982{
983 /* Update mouse position when a window is activated. */
984 int xy[2];
985 if (wm_cursor_position_get(win, &xy[0], &xy[1])) {
987 }
988}
989
991{
992 if (win->runtime->eventstate) {
993 return;
994 }
995
996 win->runtime->eventstate = MEM_new<wmEvent>("window event state");
998}
999
1000static bool wm_window_update_size_position(wmWindow *win);
1001
1002/* Belongs to below. */
1004 const char *title,
1005 wmWindow *win,
1006 bool is_dialog)
1007{
1008 /* A new window is created when page-flip mode is required for a window. */
1009 GHOST_GPUSettings gpu_settings = {0};
1011 gpu_settings.flags |= GHOST_gpuStereoVisual;
1012 }
1013
1014 if (G.debug & G_DEBUG_GPU) {
1015 gpu_settings.flags |= GHOST_gpuDebugContext;
1016 }
1017 if (G.debug & G_DEBUG_GPU_NO_HW_RAYTRACING) {
1018 gpu_settings.flags |= GHOST_gpuNoHWRaytracing;
1019 }
1020
1022 gpu_settings.context_type = wm_ghost_drawing_context_type(gpu_backend);
1025 gpu_settings.flags |= GHOST_gpuVSyncIsOverridden;
1027 }
1028
1029 int posx = 0;
1030 int posy = 0;
1031
1033 int2 scr_size;
1034 if (wm_get_desktopsize(scr_size)) {
1035 posx = win->posx;
1036 posy = (scr_size[1] - win->posy - win->sizey);
1037 }
1038 }
1039
1040 /* Clear drawable so we can set the new window. */
1041 wmWindow *prev_windrawable = wm->runtime->windrawable;
1043 GHOST_IWindow *ghost_window = g_system->createWindow(
1044 title,
1045 posx,
1046 posy,
1047 win->sizex,
1048 win->sizey,
1050 gpu_settings,
1051 false,
1052 is_dialog,
1053 static_cast<GHOST_IWindow *>((win->parent) ? win->parent->runtime->ghostwin : nullptr));
1054
1055 if (ghost_window) {
1056 win->runtime->gpuctx = GPU_context_create(ghost_window, ghost_window->getDrawingContext());
1058
1059 /* Needed so we can detect the graphics card below. */
1060 GPU_init();
1061
1062 /* Set window as drawable upon creation. Note this has already been
1063 * it has already been activated by GHOST_CreateWindow. */
1064 wm_window_set_drawable(wm, win, false);
1065
1066 win->runtime->ghostwin = ghost_window;
1067 ghost_window->setUserData(win); /* Pointer back. */
1068
1070
1071 /* Store actual window size in blender window. */
1072 /* WIN32: gives undefined window size when minimized. */
1073 if (ghost_window->getState() != GHOST_kWindowStateMinimized) {
1075 }
1076
1077#ifndef __APPLE__
1078 /* Set the state here, so minimized state comes up correct on windows. */
1080 ghost_window->setState(GHOST_TWindowState(win->windowstate));
1081 }
1082#endif
1083
1084 /* Get the window background color from the current theme. Using the title-bar
1085 * background theme color to match with the colored title-bar decoration style. */
1086 float window_bg_color[3];
1088 ui::theme::get_color_3fv(TH_BACK, window_bg_color);
1089
1090 /* Until screens get drawn, draw a default background using the window theme color. */
1092 GPU_clear_color(window_bg_color[0], window_bg_color[1], window_bg_color[2], 1.0f);
1093
1094 /* Needed here, because it's used before it reads #UserDef. */
1096
1097#ifdef WITH_GHOST_CSD
1098 /* This background is presented before anything else is drawn, so it needs its corners cut
1099 * away too. Without this the window opens as a hard edged rectangle and visibly rounds off
1100 * once the editors first draw. */
1101 if (WM_window_is_csd(win)) {
1103 }
1104#endif
1105
1107
1108 /* Clear double buffer to avoids flickering of new windows on certain drivers, see #97600. */
1109 GPU_clear_color(window_bg_color[0], window_bg_color[1], window_bg_color[2], 1.0f);
1110#ifdef WITH_GHOST_CSD
1111 if (WM_window_is_csd(win)) {
1113 }
1114#endif
1115
1117 }
1118 else {
1119 if (prev_windrawable != nullptr) {
1120 wm_window_set_drawable(wm, prev_windrawable, false);
1121 }
1122 }
1123}
1124
1125static void wm_window_ghostwindow_ensure(wmWindowManager *wm, wmWindow *win, bool is_dialog)
1126{
1127 bool new_window = false;
1128 char win_filepath[FILE_MAX];
1129 win_filepath[0] = '\0';
1130
1131 if (win->runtime->ghostwin == nullptr) {
1132 new_window = true;
1133 if ((win->sizex == 0) || (wm_init_state.override_flag & WIN_OVERRIDE_GEOM)) {
1134 win->posx = wm_init_state.start[0];
1135 win->posy = wm_init_state.start[1];
1136 win->sizex = wm_init_state.size[0];
1137 win->sizey = wm_init_state.size[1];
1138
1142 }
1143 else {
1145 }
1146 }
1147
1151 }
1152
1153 /* Without this, cursor restore may fail, see: #45456. */
1154 if (win->cursor == 0) {
1156 }
1157
1158 /* As the window has not yet been created: #GHOST_IWindow::setPath cannot be called yet.
1159 * Use this callback to store the file-path path which is used later in this function
1160 * after the window has been created. */
1161 auto window_filepath_fn = (WM_capabilities_flag() & WM_CAPABILITY_WINDOW_PATH) ?
1162 std::optional([&win_filepath](const char *filepath) {
1163 STRNCPY(win_filepath, filepath);
1164 }) :
1165 std::nullopt;
1166 fmt::memory_buffer win_title;
1167 wm_window_title_text(wm, win, window_filepath_fn, win_title);
1168 win_title.push_back('\0');
1169 wm_window_ghostwindow_add(wm, win_title.data(), win, is_dialog);
1170 }
1171
1172 if (win->runtime->ghostwin != nullptr) {
1173 /* If we have no `ghostwin` this is a buggy window that should be removed.
1174 * However we still need to initialize it correctly so the screen doesn't hang. */
1175
1176 /* Happens after file-read. */
1178
1180
1182 /* Only decoration style we have for now. */
1185 }
1186 }
1187
1188 /* Add key-map handlers (1 handler for all keys in map!). */
1189 wmKeyMap *keymap = WM_keymap_ensure(
1190 wm->runtime->defaultconf, "Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
1192
1193 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Screen", SPACE_EMPTY, RGN_TYPE_WINDOW);
1195
1196 keymap = WM_keymap_ensure(
1197 wm->runtime->defaultconf, "Screen Editing", SPACE_EMPTY, RGN_TYPE_WINDOW);
1199
1200 /* Add drop boxes. */
1201 {
1202 ListBaseT<wmDropBox> *lb = WM_dropboxmap_find("Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
1204 }
1205
1206 if (new_window) {
1207 if (win->runtime->ghostwin != nullptr) {
1208 if (win_filepath[0]) {
1209 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1210 ghost_window->setPath(win_filepath);
1211 }
1213 }
1214 }
1215 else {
1217 }
1218
1219 /* Add top-bar. */
1221}
1222
1224{
1225 BLI_assert(G.background == false);
1226
1227 /* No command-line prefsize? then we set this.
1228 * Note that these values will be used only
1229 * when there is no startup.blend yet.
1230 */
1231 if (wm_init_state.size[0] == 0) {
1232 if (!wm_get_screensize(wm_init_state.size)) [[unlikely]] {
1233 /* Use fallback values. */
1234 wm_init_state.size = int2(0);
1235 }
1236
1237 /* NOTE: this isn't quite correct, active screen maybe offset 1000s if PX,
1238 * we'd need a #wm_get_screensize like function that gives offset,
1239 * in practice the window manager will likely move to the correct monitor. */
1241 }
1242
1243 for (wmWindow &win : wm->windows) {
1244 wm_window_ghostwindow_ensure(wm, &win, false);
1245 }
1246}
1247
1249{
1250 BLI_assert(G.background == false);
1251
1252 for (wmWindow &win : wm->windows.items_mutable()) {
1253 if (win.runtime->ghostwin == nullptr) {
1254 wm_window_close(C, wm, &win);
1255 }
1256 }
1257}
1258
1259/* Update window size and position based on data from GHOST window. */
1261{
1262 const GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1263
1264 GHOST_Rect client_rect;
1265 ghost_window->getClientBounds(client_rect);
1266
1267 int sizex = client_rect.getWidth();
1268 int sizey = client_rect.getHeight();
1269
1270 int posx = 0;
1271 int posy = 0;
1272
1274 int2 scr_size;
1275 if (wm_get_desktopsize(scr_size)) {
1276 posx = client_rect.l_;
1277 posy = scr_size[1] - client_rect.t_ - win->sizey;
1278 }
1279 }
1280
1281 if (win->sizex != sizex || win->sizey != sizey || win->posx != posx || win->posy != posy) {
1282 win->sizex = sizex;
1283 win->sizey = sizey;
1284 win->posx = posx;
1285 win->posy = posy;
1286 return true;
1287 }
1288 return false;
1289}
1290
1292 const char *title,
1293 const rcti *rect_unscaled,
1294 int space_type,
1295 bool toplevel,
1296 bool dialog,
1297 bool temp,
1298 eWindowAlignment alignment,
1299 void (*area_setup_fn)(bScreen *screen, ScrArea *area, void *user_data),
1300 void *area_setup_user_data)
1301{
1302 Main *bmain = CTX_data_main(C);
1304 wmWindow *win_prev = CTX_wm_window(C);
1305 Scene *scene = CTX_data_scene(C);
1306 ViewLayer *view_layer = CTX_data_view_layer(C);
1307 int x = rect_unscaled->xmin;
1308 int y = rect_unscaled->ymin;
1309 /* Duplicated windows are created at Area size, so duplicated
1310 * minimized areas can init at 2 pixels high before being
1311 * resized at the end of window creation. Therefore minimums. */
1312 int sizex = std::max(BLI_rcti_size_x(rect_unscaled), 200);
1313 int sizey = std::max(BLI_rcti_size_y(rect_unscaled), 150);
1314 rcti rect;
1315
1316 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win_prev->runtime->ghostwin);
1317 const float native_pixel_size = ghost_window ? ghost_window->getNativePixelSize() : 1.0f;
1318 /* Convert to native OS window coordinates. */
1319 rect.xmin = x / native_pixel_size;
1320 rect.ymin = y / native_pixel_size;
1321 sizex /= native_pixel_size;
1322 sizey /= native_pixel_size;
1323
1324 if (alignment == WIN_ALIGN_LOCATION_CENTER) {
1325 /* Window centered around x,y location. */
1326 rect.xmin += win_prev->posx - (sizex / 2);
1327 rect.ymin += win_prev->posy - (sizey / 2);
1328 }
1329 else if (alignment == WIN_ALIGN_PARENT_CENTER) {
1330 /* Centered within parent. X,Y as offsets from there. */
1331 rect.xmin += win_prev->posx + ((win_prev->sizex - sizex) / 2);
1332 rect.ymin += win_prev->posy + ((win_prev->sizey - sizey) / 2);
1333 }
1334 else if (alignment == WIN_ALIGN_ABSOLUTE) {
1335 /* Positioned absolutely in desktop coordinates. */
1336 }
1337
1338 rect.xmax = rect.xmin + sizex;
1339 rect.ymax = rect.ymin + sizey;
1340
1341 /* Changes rect to fit within desktop. */
1342 wm_window_check_size(&rect);
1343
1344 /* Reuse temporary windows when they share the same single area. */
1345 wmWindow *win = nullptr;
1346 if (temp) {
1347 for (wmWindow &win_iter : wm->windows) {
1348 const bScreen *screen = WM_window_get_active_screen(&win_iter);
1349 if (screen && screen->temp && BLI_listbase_is_single(&screen->areabase)) {
1350 ScrArea *area = screen->areabase.first();
1351 if (space_type == (area->butspacetype ? area->butspacetype : area->spacetype)) {
1352 win = &win_iter;
1353 break;
1354 }
1355 }
1356 }
1357 }
1358
1359 if (win != nullptr) {
1360 /* If reusing a window that is currently minimized we need to
1361 * restore it now, before dealing with any resizing. #153569. */
1362 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1363 if (ghost_window->getState() == GHOST_kWindowStateMinimized) {
1364 ghost_window->setState(GHOST_kWindowStateNormal);
1365 }
1366 }
1367
1368 /* Add new window? */
1369 if (win == nullptr) {
1370 win = wm_window_new(bmain, wm, toplevel ? nullptr : win_prev, dialog);
1371 win->posx = rect.xmin;
1372 win->posy = rect.ymin;
1373 win->sizex = BLI_rcti_size_x(&rect);
1374 win->sizey = BLI_rcti_size_y(&rect);
1375 *win->stereo3d_format = *win_prev->stereo3d_format;
1376 }
1377
1378 bScreen *screen = WM_window_get_active_screen(win);
1379
1380 if (WM_window_get_active_workspace(win) == nullptr) {
1381 WorkSpace *workspace = WM_window_get_active_workspace(win_prev);
1383 }
1384
1385 if (screen == nullptr) {
1386 /* Add new screen layout. */
1387 WorkSpace *workspace = WM_window_get_active_workspace(win);
1388 WorkSpaceLayout *layout = ED_workspace_layout_add(bmain, workspace, win, "temp");
1389
1390 screen = BKE_workspace_layout_screen_get(layout);
1391 WM_window_set_active_layout(win, workspace, layout);
1392 }
1393
1394 /* Set scene and view layer to match original window. */
1395 STRNCPY_UTF8(win->view_layer_name, view_layer->name);
1396 if (WM_window_get_active_scene(win) != scene) {
1397 /* No need to refresh the tool-system as the window has not yet finished being setup. */
1398 ED_screen_scene_change(C, win, scene, false);
1399 }
1400
1401 screen->temp = temp;
1402
1403 /* Make window active, and validate/resize. */
1404 CTX_wm_window_set(C, win);
1405 const bool new_window = (win->runtime->ghostwin == nullptr);
1406
1407 if (area_setup_fn) {
1408 /* When the caller is setting up the area, it should always be empty
1409 * because it's expected the callback sets the type. */
1410 BLI_assert(space_type == SPACE_EMPTY);
1411 /* NOTE(@ideasman42): passing in a callback to setup the `area` is admittedly awkward.
1412 * This is done so #ED_screen_refresh has a valid area to initialize,
1413 * otherwise it will attempt to make the empty area usable via #ED_area_init.
1414 * While refreshing the window could be postponed this makes the state of the
1415 * window less predictable to the caller. */
1416 ScrArea *area = screen->areabase.first();
1417 area_setup_fn(screen, area, area_setup_user_data);
1418 CTX_wm_area_set(C, area);
1419 }
1420 else if (space_type != SPACE_EMPTY) {
1421 /* Ensure it shows the right space-type editor. */
1422 ScrArea *area = screen->areabase.first();
1423 CTX_wm_area_set(C, area);
1424 ED_area_newspace(C, area, space_type, false);
1425 }
1426
1427 if (new_window) {
1428 wm_window_ghostwindow_ensure(wm, win, dialog);
1429 }
1430 WM_check(C);
1431
1432 /* It's possible `win->runtime->ghostwin == nullptr`.
1433 * instead of attempting to cleanup here (in a half finished state),
1434 * finish setting up the screen, then free it at the end of the function,
1435 * to avoid having to take into account a partially-created window.
1436 */
1437 ED_screen_change(C, screen);
1438
1439 if (!new_window) {
1440 /* Set size in GHOST window and then update size and position from GHOST,
1441 * in case they where changed by GHOST to fit the monitor/screen. */
1442 wm_window_set_size(win, win->sizex, win->sizey);
1444 }
1445
1446 /* Refresh screen dimensions, after the effective window size is known. */
1447 ED_screen_refresh(C, wm, win);
1448
1449 if (win->runtime->ghostwin) {
1450 wm_window_raise(win);
1451 if (title) {
1452 WM_window_title_set(win, title);
1453 }
1454 else {
1456 }
1457 return win;
1458 }
1459
1460 /* Very unlikely! but opening a new window can fail. */
1461 wm_window_close(C, wm, win);
1462 CTX_wm_window_set(C, win_prev);
1463
1464 return nullptr;
1465}
1466
1467wmWindow *WM_window_open_temp(bContext *C, const char *title, int space_type, bool dialog)
1468{
1469 rcti rect;
1471 eWindowAlignment align;
1472
1473 const int index = RNA_enum_from_value(rna_enum_space_type_items, space_type);
1474 BLI_assert(index != -1);
1476
1477 std::string key = item.identifier;
1478 auto bounds = recents::Section("temp.window.dimensions").get<std::vector<float>>(key);
1479
1480 const bool bounds_valid = (bounds.size() == 4 && (bounds[1] - bounds[0] > 150.0f) &&
1481 (bounds[3] - bounds[2] > 100.0f));
1482 const bool mm_placement = WM_capabilities_flag() & WM_CAPABILITY_MULTIMONITOR_PLACEMENT;
1483 if (bounds_valid && mm_placement) {
1484 rect.xmin = int(bounds[0] * UI_SCALE_FAC);
1485 rect.xmax = int(bounds[1] * UI_SCALE_FAC);
1486 rect.ymin = int(bounds[2] * UI_SCALE_FAC);
1487 rect.ymax = int(bounds[3] * UI_SCALE_FAC);
1488 align = WIN_ALIGN_ABSOLUTE;
1489 }
1490 else {
1491 wmWindow *win_cur = CTX_wm_window(C);
1492 const int width = int((bounds_valid ? int(bounds[1] - bounds[0]) : 800.0f) * UI_SCALE_FAC);
1493 const int height = int((bounds_valid ? int(bounds[3] - bounds[2]) : 600.0f) * UI_SCALE_FAC);
1494 /* Use eventstate, not event from _invoke, so this can be called through exec(). */
1495 const wmEvent *event = win_cur->runtime->eventstate;
1496 rect.xmin = event->xy[0];
1497 rect.ymin = event->xy[1];
1498 rect.xmax = event->xy[0] + width;
1499 rect.ymax = event->xy[1] + height;
1501 }
1502
1503 wmWindow *win = WM_window_open(
1504 C, title, &rect, space_type, false, dialog, true, align, nullptr, nullptr);
1505 if (win) {
1506 win->runtime->recents_storage_key = std::move(key);
1507 }
1508 return win;
1509}
1510
1512
1513/* -------------------------------------------------------------------- */
1516
1524
1526{
1527 wmWindow *win_src = CTX_wm_window(C);
1529 const rcti window_rect = {
1530 /*xmin*/ 0,
1531 /*xmax*/ int(win_src->sizex * 0.95f),
1532 /*ymin*/ 0,
1533 /*ymax*/ int(win_src->sizey * 0.9f),
1534 };
1535
1536 bool ok = (WM_window_open(C,
1537 nullptr,
1538 &window_rect,
1539 area->spacetype,
1540 false,
1541 false,
1542 false,
1544 nullptr,
1545 nullptr) != nullptr);
1546
1547 if (!ok) {
1548 BKE_report(op->reports, RPT_ERROR, "Failed to create window");
1549 return OPERATOR_CANCELLED;
1550 }
1551 return OPERATOR_FINISHED;
1552}
1553
1555{
1556 wmWindow *win_src = CTX_wm_window(C);
1557
1558 bool ok = (wm_window_copy_test(C, win_src, true, false) != nullptr);
1559 if (!ok) {
1560 BKE_report(op->reports, RPT_ERROR, "Failed to create window");
1561 return OPERATOR_CANCELLED;
1562 }
1563 return OPERATOR_FINISHED;
1564}
1565
1567{
1568 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(CTX_wm_window(C)->runtime->ghostwin);
1569
1570 if (G.background) {
1571 return OPERATOR_CANCELLED;
1572 }
1573
1574 GHOST_TWindowState state = ghost_window->getState();
1577 }
1578 else {
1579 ghost_window->setState(GHOST_kWindowStateNormal);
1580 }
1581
1582 return OPERATOR_FINISHED;
1583}
1584
1586
1587/* -------------------------------------------------------------------- */
1590
1592{
1593 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1594 const float fac = ghost_window->getNativePixelSize();
1595
1596 *x *= fac;
1597 *y = (win->sizey - 1) - *y;
1598 *y *= fac;
1599}
1600
1602{
1603 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1604 const float fac = ghost_window->getNativePixelSize();
1605
1606 *x /= fac;
1607 *y /= fac;
1608 *y = win->sizey - *y - 1;
1609}
1610
1612{
1613 const GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1614 ghost_window->screenToClient(*x, *y, *x, *y);
1615
1617}
1618
1620{
1622
1623 const GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1624 ghost_window->clientToScreen(*x, *y, *x, *y);
1625}
1626
1627bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
1628{
1629 if (G.f & G_FLAG_EVENT_SIMULATE) [[unlikely]] {
1630 *r_x = win->runtime->eventstate->xy[0];
1631 *r_y = win->runtime->eventstate->xy[1];
1632 return true;
1633 }
1634
1635 const GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1636 if (g_system->getCursorPositionClientRelative(ghost_window, *r_x, *r_y)) {
1638 return true;
1639 }
1640
1641 return false;
1642}
1643
1646{
1647 uint8_t result = 0;
1648 for (int i = 0; i < ARRAY_SIZE(g_modifier_table); i++) {
1649 bool val = false;
1650 g_system->getModifierKeyState(g_modifier_table[i].ghost_mask_pair[side], val);
1651 if (val) {
1652 result |= g_modifier_table[i].flag;
1653 }
1654 }
1655 return result;
1656}
1657
1659{
1660 BLI_assert(ELEM(wm->runtime->windrawable, nullptr, win));
1661
1662 wm->runtime->windrawable = win;
1663 if (activate) {
1664 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
1665 ghost_window->activateDrawingContext();
1666 GPU_context_active_set(static_cast<GPUContext *>(win->runtime->gpuctx));
1667 }
1668}
1669
1671{
1672 if (wm->runtime->windrawable) {
1673 wm->runtime->windrawable = nullptr;
1674 GPU_context_active_set(nullptr);
1675 }
1676}
1677
1679{
1681
1682 if (win != wm->runtime->windrawable && win->runtime->ghostwin) {
1683 // win->lmbut = 0; /* Keeps hanging when mouse-pressed while other window opened. */
1685
1686 if (G.debug & G_DEBUG_EVENTS) {
1687 printf("%s: set drawable %d\n", __func__, win->winid);
1688 }
1689
1690 wm_window_set_drawable(wm, win, true);
1691 }
1692
1693 if (win->runtime->ghostwin) {
1694 /* This can change per window. */
1696 }
1697}
1698
1700{
1703 wmWindowManager *wm = G_MAIN->wm.first();
1704
1705 if (wm == nullptr) {
1706 return;
1707 }
1708 wmWindow *win = wm->runtime->windrawable;
1709
1710 if (win && win->runtime->ghostwin) {
1712 wm_window_set_drawable(wm, win, true);
1713 }
1714}
1715
1716#ifndef NDEBUG
1722{
1723 /* NOTE: The following time constants can be tweaked if they're reporting false positives. */
1724
1725 /* The reference event time-stamp must have happened in this time-frame. */
1726 constexpr uint64_t event_time_ok_ms = 1000;
1727 /* The current event time-stamp must be outside this time-frame to be considered an error. */
1728 constexpr uint64_t event_time_error_ms = 5000;
1729
1730 static uint64_t event_ms_ref_last = std::numeric_limits<uint64_t>::max();
1731 const uint64_t event_ms = ghost_event->getTime();
1732 const uint64_t event_ms_ref = event_ms_ref_last;
1733
1734 /* Assign first (allow early returns). */
1735 event_ms_ref_last = event_ms;
1736
1737 if (event_ms_ref == std::numeric_limits<uint64_t>::max()) {
1738 return;
1739 }
1740 /* Check the events are recent enough to be used for testing. */
1741 const uint64_t now_ms = g_system->getMilliSeconds();
1742 /* Ensure the reference time occurred in the last #event_time_ok_ms.
1743 * If not, the reference time it's self may be a bad time-stamp. */
1744 if (event_ms_ref < event_time_error_ms || (event_ms_ref < (now_ms - event_time_ok_ms)) ||
1745 (event_ms_ref > (now_ms + event_time_ok_ms)))
1746 {
1747 /* Skip, the reference time not recent enough to be used. */
1748 return;
1749 }
1750
1751 /* NOTE: Regarding time-stamps from the future.
1752 * Generally this shouldn't happen but may do depending on the kinds of events.
1753 * Different input methods may detect and trigger events in a way that wont ensure
1754 * monotonic event times, so only consider this an error for large time deltas. */
1755 double time_delta = 0.0;
1756 if (event_ms < (event_ms_ref - event_time_error_ms)) {
1757 /* New event time is after (to be expected). */
1758 time_delta = double(now_ms - event_ms) / -1000.0;
1759 }
1760 else if (event_ms > (event_ms_ref + event_time_error_ms)) {
1761 /* New event time is before (unexpected but not an error). */
1762 time_delta = double(event_ms - now_ms) / 1000.0;
1763 }
1764 else {
1765 /* Time is in range. */
1766 return;
1767 }
1768
1769 const char *time_unit = "seconds";
1770 const struct {
1771 const char *unit;
1772 double scale;
1773 } unit_table[] = {{"minutes", 60}, {"hours", 60}, {"days", 24}, {"weeks", 7}, {"years", 52}};
1774 for (int i = 0; i < ARRAY_SIZE(unit_table); i++) {
1775 if (std::abs(time_delta) <= unit_table[i].scale) {
1776 break;
1777 }
1778 time_delta /= unit_table[i].scale;
1779 time_unit = unit_table[i].unit;
1780 }
1781
1783 "GHOST: suspicious time-stamp from far in the %s: %.2f %s, "
1784 "absolute value is %" PRIu64 ", current time is %" PRIu64 ", for type %d",
1785 time_delta < 0.0f ? "past" : "future",
1786 std::abs(time_delta),
1787 time_unit,
1788 event_ms,
1789 now_ms,
1790 int(ghost_event->getType()));
1791}
1792#endif /* !NDEBUG */
1793
1799static bool ghost_event_proc(const GHOST_IEvent *ghost_event, GHOST_TUserDataPtr C_void_ptr)
1800{
1801 bContext *C = static_cast<bContext *>(C_void_ptr);
1803
1804 const GHOST_TEventType type = ghost_event->getType();
1805 GHOST_IWindow *ghost_window = ghost_event->getWindow();
1806
1807#ifndef NDEBUG
1809#endif
1810
1811 if (type == GHOST_kEventQuitRequest) {
1812 /* Find an active window to display quit dialog in. */
1813 wmWindow *win;
1814 if (ghost_window && g_system->validWindow(ghost_window)) {
1815 win = static_cast<wmWindow *>(ghost_window->getUserData());
1816 }
1817 else {
1818 win = wm->runtime->winactive;
1819 }
1820
1821 /* Display quit dialog or quit immediately. */
1822 if (win) {
1824 }
1825 else {
1827 }
1828 return true;
1829 }
1830
1831 GHOST_TEventDataPtr data = ghost_event->getData();
1832 const uint64_t event_time_ms = ghost_event->getTime();
1833
1834 /* Ghost now can call this function for life resizes,
1835 * but it should return if WM didn't initialize yet.
1836 * Can happen on file read (especially full size window). */
1837 if ((wm->init_flag & WM_INIT_FLAG_WINDOW) == 0) {
1838 return true;
1839 }
1840 if (!ghost_window) {
1841 /* XXX: should be checked, why are we getting an event here, and what is it? */
1842 puts("<!> event has no window");
1843 return true;
1844 }
1845 if (!g_system->validWindow(ghost_window)) {
1846 /* XXX: should be checked, why are we getting an event here, and what is it? */
1847 puts("<!> event has invalid window");
1848 return true;
1849 }
1850
1851 wmWindow *win = static_cast<wmWindow *>(ghost_window->getUserData());
1852
1853 switch (type) {
1856
1857 wm_event_add_ghostevent(wm, win, type, data, event_time_ms);
1858 win->active = 0;
1860 break;
1861 }
1863 /* Ensure the event state matches modifiers (window was inactive). */
1864 wm_window_update_eventstate_modifiers(wm, win, event_time_ms);
1865
1866 /* Entering window, update mouse position (without sending an event). */
1868
1869 /* No context change! `C->wm->runtime->windrawable` is drawable, or for area queues. */
1870 wm->runtime->winactive = win;
1871 win->active = 1;
1873
1874 /* Zero the `keymodifier`, it hangs on hotkeys that open windows otherwise. */
1876
1877 win->addmousemove = 1; /* Enables highlighted buttons. */
1878
1880
1881 /* NOTE(@sergey): Window might be focused by mouse click in configuration of window manager
1882 * when focus is not following mouse
1883 * click could have been done on a button and depending on window manager settings
1884 * click would be passed to blender or not, but in any case button under cursor
1885 * should be activated, so at max next click on button without moving mouse
1886 * would trigger its handle function
1887 * currently it seems to be common practice to generate new event for, but probably
1888 * we'll need utility function for this?
1889 */
1890 wmEvent event;
1891 wm_event_init_from_window(win, &event);
1892 event.type = MOUSEMOVE;
1893 event.val = KM_NOTHING;
1894 copy_v2_v2_int(event.prev_xy, event.xy);
1895 event.flag = eWM_EventFlag(0);
1896
1897 WM_event_add(win, &event);
1898
1899 break;
1900 }
1903 break;
1904 }
1906 if (G.debug & G_DEBUG_EVENTS) {
1907 printf("%s: ghost redraw %d\n", __func__, win->winid);
1908 }
1909
1911 WM_event_add_notifier_ex(wm, win, NC_WINDOW, nullptr);
1912
1913 break;
1914 }
1916 if (G.debug & G_DEBUG_EVENTS) {
1917 printf("%s: ghost redraw decor %d\n", __func__, win->winid);
1918 }
1919 /* Update state here to make sure that out CSD maximize/un-maximize buttons
1920 * show the correct state. */
1921 win->windowstate = ghost_window->getState();
1922
1924
1925 /* When using CSD, the un-maximized state and maximized state has different padding.
1926 * We need to redraw the content of the window to make sure it fits with the new padding. */
1929
1930 break;
1931 }
1934 GHOST_TWindowState state = ghost_window->getState();
1935 win->windowstate = state;
1936
1938
1939 /* WIN32: gives undefined window size when minimized. */
1941 /*
1942 * Ghost sometimes send size or move events when the window hasn't changed.
1943 * One case of this is using COMPIZ on Linux.
1944 * To alleviate the problem we ignore all such event here.
1945 *
1946 * It might be good to eventually do that at GHOST level, but that is for another time.
1947 */
1949 const bScreen *screen = WM_window_get_active_screen(win);
1950
1951 /* Debug prints. */
1952 if (G.debug & G_DEBUG_EVENTS) {
1953 const char *state_str;
1954 state = ghost_window->getState();
1955
1957 state_str = "normal";
1958 }
1959 else if (state == GHOST_kWindowStateMinimized) {
1960 state_str = "minimized";
1961 }
1962 else if (state == GHOST_kWindowStateMaximized) {
1963 state_str = "maximized";
1964 }
1965 else if (state == GHOST_kWindowStateFullScreen) {
1966 state_str = "full-screen";
1967 }
1968 else {
1969 state_str = "<unknown>";
1970 }
1971
1972 printf("%s: window %d state = %s\n", __func__, win->winid, state_str);
1973
1974 if (type != GHOST_kEventWindowSize) {
1975 printf("win move event pos %d %d size %d %d\n",
1976 win->posx,
1977 win->posy,
1978 win->sizex,
1979 win->sizey);
1980 }
1981 }
1982
1984 BKE_icon_changed(screen->id.icon_id);
1987
1988#if defined(__APPLE__) || defined(WIN32)
1989 /* MACOS and WIN32 don't return to the main-loop while resize. */
1990 int dummy_sleep_ms = 0;
1991 wm_window_timers_process(C, &dummy_sleep_ms);
1995#endif
1996 }
1997 }
1998 break;
1999 }
2000
2003 /* Font's are stored at each DPI level, without this we can easy load 100's of fonts. */
2005
2006 WM_main_add_notifier(NC_WINDOW, nullptr); /* Full redraw. */
2007 WM_main_add_notifier(NC_SCREEN | NA_EDITED, nullptr); /* Refresh region sizes. */
2008 break;
2009 }
2010
2012 const char *path = static_cast<const char *>(data);
2013
2014 if (path && path[0] != '\0') {
2015 wmOperatorType *ot = WM_operatortype_find("WM_OT_open_mainfile", false);
2016 /* Operator needs a valid window in context, ensures it is correctly set. */
2017 CTX_wm_window_set(C, win);
2018
2020 RNA_string_set(&props_ptr, "filepath", path);
2021 RNA_boolean_set(&props_ptr, "display_file_selector", false);
2022 /* There is no file selector to show the "Trusted Source" option, use its default. */
2023 RNA_boolean_set(&props_ptr,
2024 "use_scripts",
2026 {
2027 .skip_overrides = false,
2028 .canonicalize = true,
2029 .strip_filename = true,
2030 }));
2032 WM_operator_properties_free(&props_ptr);
2033
2034 CTX_wm_window_set(C, nullptr);
2035 }
2036 break;
2037 }
2039 const GHOST_TEventDragnDropData *ddd = static_cast<const GHOST_TEventDragnDropData *>(data);
2040
2041 /* Ensure the event state matches modifiers (window was inactive). */
2042 wm_window_update_eventstate_modifiers(wm, win, event_time_ms);
2043 /* Entering window, update mouse position (without sending an event). */
2045
2046 wmEvent event;
2047 wm_event_init_from_window(win, &event); /* Copy last state, like mouse coords. */
2048
2049 /* Activate region. */
2050 event.type = MOUSEMOVE;
2051 event.val = KM_NOTHING;
2052 copy_v2_v2_int(event.prev_xy, event.xy);
2053
2054 copy_v2_v2_int(event.xy, &ddd->x);
2055 wm_cursor_position_from_ghost_screen_coords(win, &event.xy[0], &event.xy[1]);
2056
2057 /* The values from #wm_window_update_eventstate may not match (under WAYLAND they don't)
2058 * Write this into the event state. */
2059 copy_v2_v2_int(win->runtime->eventstate->xy, event.xy);
2060
2061 event.flag = eWM_EventFlag(0);
2062
2063 /* No context change! `C->wm->runtime->windrawable` is drawable, or for area queues. */
2064 wm->runtime->winactive = win;
2065 win->active = 1;
2067
2068 WM_event_add(win, &event);
2069
2070 /* Make blender drop event with custom data pointing to wm drags. */
2071 event.type = EVT_DROP;
2072 event.val = KM_RELEASE;
2073 event.custom = EVT_DATA_DRAGDROP;
2074 event.customdata = &wm->runtime->drags;
2075 event.customdata_free = true;
2076
2077 WM_event_add(win, &event);
2078
2079 // printf("Drop detected\n");
2080
2081 /* Add drag data to wm for paths. */
2082
2084 const GHOST_TStringArray *stra = static_cast<const GHOST_TStringArray *>(ddd->data);
2085
2086 if (stra->count) {
2087 CLOG_INFO(WM_LOG_EVENTS, "Drop %d files:", stra->count);
2088 for (const char *path : Span(reinterpret_cast<char **>(stra->strings), stra->count)) {
2089 CLOG_INFO(WM_LOG_EVENTS, "%s", path);
2090 }
2091 /* Try to get icon type from extension of the first path. */
2092 int icon = ED_file_extension_icon(reinterpret_cast<char *>(stra->strings[0]));
2094 Span(reinterpret_cast<char **>(stra->strings), stra->count));
2095 WM_event_start_drag(C, icon, WM_DRAG_PATH, path_data, WM_DRAG_NOP);
2096 /* Void pointer should point to string, it makes a copy. */
2097 }
2098 }
2099 else if (ddd->dataType == GHOST_kDragnDropTypeString) {
2100 /* Drop an arbitrary string. */
2101 std::string *str = MEM_new<std::string>(__func__, static_cast<const char *>(ddd->data));
2103 }
2104
2105 break;
2106 }
2108 /* Only update if the actual pixel size changes. */
2109 float prev_pixelsize = U.pixelsize;
2111
2112 if (U.pixelsize != prev_pixelsize) {
2114
2115 /* Close all popups since they are positioned with the pixel
2116 * size baked in and it's difficult to correct them. */
2117 CTX_wm_window_set(C, win);
2119 CTX_wm_window_set(C, nullptr);
2120
2122
2125 }
2126
2127 break;
2128 }
2130 case GHOST_kEventButtonUp: {
2131 if (win->active == 0) {
2132 /* Entering window, update cursor/tablet state & modifiers.
2133 * (ghost sends win-activate *after* the mouse-click in window!). */
2134 wm_window_update_eventstate_modifiers(wm, win, event_time_ms);
2136 }
2137
2138 wm_event_add_ghostevent(wm, win, type, data, event_time_ms);
2139 break;
2140 }
2141 default: {
2142 wm_event_add_ghostevent(wm, win, type, data, event_time_ms);
2143 break;
2144 }
2145 }
2146
2147 return true;
2148}
2149
2159static bool wm_window_timers_process(const bContext *C, int *sleep_us_p)
2160{
2161 Main *bmain = CTX_data_main(C);
2163 const double time = BLI_time_now_seconds();
2164 bool has_event = false;
2165
2166 const int sleep_us = *sleep_us_p;
2167 /* The nearest time an active timer is scheduled to run. */
2168 double ntime_min = DBL_MAX;
2169
2170 /* Mutable in case the timer gets removed. */
2171 for (wmTimer &wt : wm->runtime->timers.items_mutable()) {
2172 if (wt.flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
2173 continue;
2174 }
2175 if (wt.sleep == true) {
2176 continue;
2177 }
2178
2179 /* Future timer, update nearest time & skip. */
2180 if (wt.time_next >= time) {
2181 if ((has_event == false) && (sleep_us != 0)) {
2182 /* The timer is not ready to run but may run shortly. */
2183 ntime_min = std::min(wt.time_next, ntime_min);
2184 }
2185 continue;
2186 }
2187
2188 wt.time_delta = time - wt.time_last;
2189 wt.time_duration += wt.time_delta;
2190 wt.time_last = time;
2191
2192 wt.time_next = wt.time_start;
2193 if (wt.time_step != 0.0f) {
2194 wt.time_next += wt.time_step * ceil(wt.time_duration / wt.time_step);
2195 }
2196
2197 if (wt.event_type == TIMERJOBS) {
2198 wm_jobs_timer(wm, &wt);
2199 }
2200 else if (wt.event_type == TIMERAUTOSAVE) {
2201 wm_autosave_timer(bmain, wm, &wt);
2202 }
2203 else if (wt.event_type == TIMERNOTIFIER) {
2204 WM_main_add_notifier(POINTER_AS_UINT(wt.customdata), nullptr);
2205 }
2206 else if (wmWindow *win = wt.win) {
2207 wmEvent event;
2208 wm_event_init_from_window(win, &event);
2209
2210 event.type = wt.event_type;
2211 event.val = KM_NOTHING;
2212 event.keymodifier = EVENT_NONE;
2213 event.flag = eWM_EventFlag(0);
2214 event.custom = EVT_DATA_TIMER;
2215 event.customdata = &wt;
2216 WM_event_add(win, &event);
2217
2218 has_event = true;
2219 }
2220 }
2221
2222 if ((has_event == false) && (sleep_us != 0) && (ntime_min != DBL_MAX)) {
2223 /* Clamp the sleep time so next execution runs earlier (if necessary).
2224 * Use `ceil` so the timer is guarantee to be ready to run (not always the case with rounding).
2225 * Even though using `floor` or `round` is more responsive,
2226 * it causes CPU intensive loops that may run until the timer is reached, see: #111579. */
2227 const double microseconds = 1000000.0;
2228 const double sleep_sec = double(sleep_us) / microseconds;
2229 const double sleep_sec_next = ntime_min - time;
2230
2231 if (sleep_sec_next < sleep_sec) {
2232 *sleep_us_p = int(std::ceil(sleep_sec_next * microseconds));
2233 }
2234 }
2235
2236 /* Effectively delete all timers marked for removal. */
2238
2239 return has_event;
2240}
2241
2243{
2247
2248 bool has_event = g_system->processEvents(false); /* `false` is no wait. */
2249
2250 if (has_event) {
2252 }
2253
2255
2256 /* When there is no event, sleep 5 milliseconds not to use too much CPU when idle. */
2257 const int sleep_us_default = 5000;
2258 int sleep_us = has_event ? 0 : sleep_us_default;
2259 has_event |= wm_window_timers_process(C, &sleep_us);
2260#ifdef WITH_XR_OPENXR
2261 /* XR events don't use the regular window queues. So here we don't only trigger
2262 * processing/dispatching but also handling. */
2263 has_event |= wm_xr_events_handle(CTX_wm_manager(C));
2264#endif
2266
2267 /* Skip sleeping when simulating events so tests don't idle unnecessarily as simulated
2268 * events are typically generated from a timer that runs in the main loop. */
2269 if ((has_event == false) && (sleep_us != 0) && !(G.f & G_FLAG_EVENT_SIMULATE)) {
2270 BLI_time_sleep_precise_us(sleep_us);
2271 }
2272}
2273
2275
2276/* -------------------------------------------------------------------- */
2279
2280#ifdef WITH_GHOST_CSD
2281static int32_t wm_window_csd_layout_callback(const int32_t window_size[2],
2282 const int32_t fractional_scale[2],
2283 GHOST_TWindowState window_state,
2284 const GHOST_CSD_Layout *csd_layout,
2285 GHOST_CSD_Elem *csd_elems)
2286{
2288 window_size, fractional_scale, char(window_state), csd_layout, csd_elems);
2289}
2290
2292{
2293 if (g_system_use_csd == false) {
2294 return;
2295 }
2296
2297 GHOST_CSD_Params csd_params = {
2298 /*layout_callback*/ wm_window_csd_layout_callback,
2299
2300 /*cursor_drag_threshold*/ U.drag_threshold_mouse,
2301 /*cursor_double_click_ms*/ U.dbl_click_time,
2302 /*resize_margin_size*/ WM_WINDOW_CSD_RESIZE_MARGIN_SIZE,
2303 /*corner_radius*/ WM_WINDOW_CSD_CORNER_RADIUS,
2304 };
2305 g_system->setWindowCSD(csd_params);
2306}
2307
2308const GHOST_CSD_Layout *WM_window_csd_layout_get()
2309{
2310 return &g_system->getWindowCSD_Layout();
2311}
2312
2313#endif /* WITH_GHOST_CSD */
2314
2316{
2317 if (g_system) {
2318 return;
2319 }
2320
2321 BLI_assert(C != nullptr);
2322 BLI_assert_msg(!G.background, "Use wm_ghost_init_background instead");
2323
2324 GHOST_CallbackEventConsumer *ghost_event_consumer = new GHOST_CallbackEventConsumer(
2328
2332
2333 if (g_system == nullptr) [[unlikely]] {
2334 /* GHOST will have reported the back-ends that failed to load. */
2335 CLOG_STR_ERROR(&LOG_GHOST_SYSTEM, "Unable to initialize GHOST, exiting!");
2336 /* This will leak memory, it's preferable to crashing. */
2337 exit(EXIT_FAILURE);
2338 }
2339#if !(defined(WIN32) || defined(__APPLE__))
2341#endif
2342
2343 GHOST_Debug debug = {0};
2344 if (G.debug & G_DEBUG_GHOST) {
2345 debug.flags |= GHOST_kDebugDefault;
2346 }
2347 if (G.debug & G_DEBUG_WINTAB) {
2348 debug.flags |= GHOST_kDebugWintab;
2349 }
2351
2352 g_system->addEventConsumer(ghost_event_consumer);
2353
2356 }
2357
2359
2360#ifdef WITH_GHOST_WAYLAND
2362#endif
2363
2364#ifdef WITH_GHOST_CSD
2367 {
2368 g_system_use_csd = true;
2370 }
2371#endif /* WITH_GHOST_CSD */
2372}
2373
2375{
2376 /* TODO: move this to `wm_init_exit.cc`. */
2377
2378 if (g_system) {
2379 return;
2380 }
2381
2383
2387
2388 GHOST_Debug debug = {0};
2389 if (G.debug & G_DEBUG_GHOST) {
2390 debug.flags |= GHOST_kDebugDefault;
2391 }
2393}
2394
2396{
2397 if (g_system) {
2399 }
2400 g_system = nullptr;
2401}
2402
2403const char *WM_ghost_backend()
2404{
2405#if !(defined(WIN32) || defined(__APPLE__))
2406 return g_system_backend_id ? g_system_backend_id : "NONE";
2407#else
2408 /* While this could be supported, at the moment it's only needed with GHOST X11/WAYLAND
2409 * to check which was selected and the API call may be removed after that's no longer needed.
2410 * Use dummy values to prevent this being used on other systems. */
2411 return g_system ? "DEFAULT" : "NONE";
2412#endif
2413}
2414
2416{
2417 switch (gpu_backend) {
2418 case GPU_BACKEND_NONE:
2420 case GPU_BACKEND_ANY:
2421 case GPU_BACKEND_OPENGL:
2422#ifdef WITH_OPENGL_BACKEND
2423 return GHOST_kDrawingContextTypeOpenGL;
2424#endif
2427 case GPU_BACKEND_VULKAN:
2428#ifdef WITH_VULKAN_BACKEND
2429 return GHOST_kDrawingContextTypeVulkan;
2430#endif
2433 case GPU_BACKEND_METAL:
2434#ifdef WITH_METAL_BACKEND
2435 return GHOST_kDrawingContextTypeMetal;
2436#endif
2439 }
2440
2441 /* Avoid control reaches end of non-void function compilation warning, which could be promoted
2442 * to error. */
2445}
2446
2448{
2449 if (!bool(G.f & G_FLAG_GPU_BACKEND_FALLBACK)) {
2450 return;
2451 }
2452
2453 /* Have we already shown a message during this Blender session. */
2454 if (bool(G.f & G_FLAG_GPU_BACKEND_FALLBACK_QUIET)) {
2455 return;
2456 }
2458
2460 wmWindow *win = static_cast<wmWindow *>((wm->runtime->winactive) ? wm->runtime->winactive :
2461 wm->windows.first());
2462
2463 if (win) {
2464 /* We want this warning on the Main window, not a child window even if active. See #118765. */
2465 if (win->parent) {
2466 win = win->parent;
2467 }
2468
2469 wmWindow *prevwin = CTX_wm_window(C);
2470 CTX_wm_window_set(C, win);
2471 std::string message = RPT_("Updating GPU drivers may solve this issue.");
2472 message += RPT_(
2473 "The graphics backend can be changed in the System section of the Preferences.");
2474 alert(C,
2475 RPT_("Failed to load using Vulkan, using OpenGL instead."),
2476 message,
2478 false);
2479 CTX_wm_window_set(C, prevwin);
2480 }
2481}
2482
2484{
2486 if (flag != 0) {
2487 return flag;
2488 }
2490
2491 /* NOTE(@ideasman42): Regarding tests.
2492 * Some callers of this function may run from tests where GHOST's hasn't been initialized.
2493 * In such cases it may be necessary to check `!G.background` which is acceptable in most cases.
2494 * At time of writing this is the case for `bl_animation_keyframing`.
2495 *
2496 * While this function *could* early-exit when in background mode, don't do this as GHOST
2497 * may be initialized in background mode for GPU rendering and in this case we may want to
2498 * query GHOST/GPU related capabilities. */
2499
2500 const GHOST_TCapabilityFlag ghost_flag = g_system->getCapabilities();
2501 if (ghost_flag & GHOST_kCapabilityCursorWarp) {
2503 }
2504 if (ghost_flag & GHOST_kCapabilityWindowPosition) {
2506 }
2507 if (ghost_flag & GHOST_kCapabilityClipboardPrimary) {
2509 }
2510 if (ghost_flag & GHOST_kCapabilityGPUReadFrontBuffer) {
2512 }
2513 if (ghost_flag & GHOST_kCapabilityClipboardImage) {
2515 }
2516 if (ghost_flag & GHOST_kCapabilityDesktopSample) {
2518 }
2519 if (ghost_flag & GHOST_kCapabilityInputIME) {
2521 }
2524 }
2525 if (ghost_flag & GHOST_kCapabilityWindowDecorationStyles) {
2527 }
2528 if (ghost_flag & GHOST_kCapabilityKeyboardHyperKey) {
2530 }
2531 if (ghost_flag & GHOST_kCapabilityCursorRGBA) {
2533 }
2534 if (ghost_flag & GHOST_kCapabilityCursorGenerator) {
2536 }
2537 if (ghost_flag & GHOST_kCapabilityMultiMonitorPlacement) {
2539 }
2540 if (ghost_flag & GHOST_kCapabilityWindowPath) {
2542 }
2545 }
2546 return flag;
2547}
2548
2550
2551/* -------------------------------------------------------------------- */
2554
2555void WM_event_timer_sleep(wmWindowManager *wm, wmWindow * /*win*/, wmTimer *timer, bool do_sleep)
2556{
2557 /* Extra security check. */
2558 if (BLI_findindex(&wm->runtime->timers, timer) == -1) {
2559 return;
2560 }
2561 /* It's disputable if this is needed, when tagged for removal,
2562 * the sleep value won't be used anyway. */
2563 if (timer->flags & WM_TIMER_TAGGED_FOR_REMOVAL) {
2564 return;
2565 }
2566 timer->sleep = do_sleep;
2567}
2568
2570 wmWindow *win,
2571 const wmEventType event_type,
2572 const double time_step)
2573{
2574 BLI_assert(ISTIMER(event_type));
2575
2576 wmTimer *wt = MEM_new_zeroed<wmTimer>("window timer");
2577 BLI_assert(time_step >= 0.0f);
2578
2579 wt->event_type = event_type;
2581 wt->time_next = wt->time_last + time_step;
2582 wt->time_start = wt->time_last;
2583 wt->time_step = time_step;
2584 wt->win = win;
2585
2586 BLI_addtail(&wm->runtime->timers, wt);
2587
2588 return wt;
2589}
2590
2592 wmWindow *win,
2593 const uint type,
2594 const double time_step)
2595{
2596 wmTimer *wt = MEM_new_zeroed<wmTimer>("window timer");
2597 BLI_assert(time_step >= 0.0f);
2598
2601 wt->time_next = wt->time_last + time_step;
2602 wt->time_start = wt->time_last;
2603 wt->time_step = time_step;
2604 wt->win = win;
2605 wt->customdata = POINTER_FROM_UINT(type);
2607
2608 BLI_addtail(&wm->runtime->timers, wt);
2609
2610 return wt;
2611}
2612
2614{
2615 for (wmTimer &wt : wm->runtime->timers.items_mutable()) {
2616 if ((wt.flags & WM_TIMER_TAGGED_FOR_REMOVAL) == 0) {
2617 continue;
2618 }
2619
2620 /* Actual removal and freeing of the timer. */
2621 BLI_remlink(&wm->runtime->timers, &wt);
2622 MEM_delete(&wt);
2623 }
2624}
2625
2627{
2628 if (timer->customdata != nullptr && (timer->flags & WM_TIMER_NO_FREE_CUSTOM_DATA) == 0) {
2630 timer->customdata = nullptr;
2631 }
2632}
2633
2635{
2636 /* Extra security check. */
2637 if (BLI_findindex(&wm->runtime->timers, timer) == -1) {
2638 return;
2639 }
2640
2642
2643 /* Clear existing references to the timer. */
2644 if (wm->runtime->reports.reporttimer == timer) {
2645 wm->runtime->reports.reporttimer = nullptr;
2646 }
2647 /* There might be events in queue with this timer as customdata. */
2648 for (wmWindow &win : wm->windows) {
2649 for (wmEvent &event : win.runtime->event_queue) {
2650 if (event.customdata == timer) {
2651 event.customdata = nullptr;
2652 event.type = EVENT_NONE; /* Timer users customdata, don't want `nullptr == nullptr`. */
2653 }
2654 }
2655 }
2656
2657 /* Immediately free `customdata` if requested, so that invalid usages of that data after
2658 * calling `WM_event_timer_remove` can be easily spotted (through ASAN errors e.g.). */
2660}
2661
2663{
2664 timer->customdata = nullptr;
2665 WM_event_timer_remove(wm, win, timer);
2666}
2667
2669
2670/* -------------------------------------------------------------------- */
2677
2678struct {
2679 char *buffers[2];
2681
2683{
2684 if (g_wm_clipboard_text_simulate == nullptr) {
2685 return;
2686 }
2687 for (int i = 0; i < ARRAY_SIZE(g_wm_clipboard_text_simulate->buffers); i++) {
2688 char *buf = g_wm_clipboard_text_simulate->buffers[i];
2689 if (buf) {
2690 MEM_delete(buf);
2691 }
2692 }
2693 MEM_delete(g_wm_clipboard_text_simulate);
2695}
2696
2697static char *wm_clipboard_text_get_impl(bool selection)
2698{
2699 if (G.f & G_FLAG_EVENT_SIMULATE) [[unlikely]] {
2700 if (g_wm_clipboard_text_simulate == nullptr) {
2701 return nullptr;
2702 }
2703 const char *buf_src = g_wm_clipboard_text_simulate->buffers[int(selection)];
2704 if (buf_src == nullptr) {
2705 return nullptr;
2706 }
2707 size_t size = strlen(buf_src) + 1;
2708 char *buf = static_cast<char *>(malloc(size));
2709 memcpy(buf, buf_src, size);
2710 return buf;
2711 }
2712
2713 return g_system->getClipboard(selection);
2714}
2715
2716static void wm_clipboard_text_set_impl(const char *buf, bool selection)
2717{
2718 if (G.f & G_FLAG_EVENT_SIMULATE) [[unlikely]] {
2719 if (g_wm_clipboard_text_simulate == nullptr) {
2721 MEM_new_zeroed<std::remove_pointer_t<decltype(g_wm_clipboard_text_simulate)>>(__func__);
2722 }
2723 char **buf_src_p = &(g_wm_clipboard_text_simulate->buffers[int(selection)]);
2724 MEM_SAFE_DELETE(*buf_src_p);
2725 *buf_src_p = BLI_strdup(buf);
2726 return;
2727 }
2728
2729 g_system->putClipboard(buf, selection);
2730}
2731
2733
2734/* -------------------------------------------------------------------- */
2737
2738static char *wm_clipboard_text_get_ex(bool selection,
2739 int *r_len,
2740 const bool ensure_utf8,
2741 const bool firstline)
2742{
2743 if (G.background) {
2744 *r_len = 0;
2745 return nullptr;
2746 }
2747
2748 char *buf = wm_clipboard_text_get_impl(selection);
2749 if (!buf) {
2750 *r_len = 0;
2751 return nullptr;
2752 }
2753
2754 int buf_len = strlen(buf);
2755
2756 if (ensure_utf8) {
2757 /* TODO(@ideasman42): It would be good if unexpected byte sequences could be interpreted
2758 * instead of stripped - so mixed in characters (typically Latin1) aren't ignored.
2759 * Check on how Python bytes this, see: #PyC_UnicodeFromBytesAndSize,
2760 * there are clever ways to handle this although they increase the size of the buffer. */
2761 buf_len -= BLI_str_utf8_invalid_strip(buf, buf_len);
2762 }
2763
2764 /* Always convert from `\r\n` to `\n`. */
2765 char *newbuf = MEM_new_array_uninitialized<char>(size_t(buf_len) + 1, __func__);
2766 char *p2 = newbuf;
2767
2768 if (firstline) {
2769 /* Will return an over-allocated value in the case there are newlines. */
2770 for (char *p = buf; *p; p++) {
2771 if (!ELEM(*p, '\n', '\r')) {
2772 *(p2++) = *p;
2773 }
2774 else {
2775 break;
2776 }
2777 }
2778 }
2779 else {
2780 for (char *p = buf; *p; p++) {
2781 if (*p != '\r') {
2782 *(p2++) = *p;
2783 }
2784 }
2785 }
2786
2787 *p2 = '\0';
2788
2789 free(buf); /* GHOST uses regular malloc. */
2790
2791 *r_len = (p2 - newbuf);
2792
2793 return newbuf;
2794}
2795
2796char *WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
2797{
2798 return wm_clipboard_text_get_ex(selection, r_len, ensure_utf8, false);
2799}
2800
2801char *WM_clipboard_text_get_firstline(bool selection, bool ensure_utf8, int *r_len)
2802{
2803 return wm_clipboard_text_get_ex(selection, r_len, ensure_utf8, true);
2804}
2805
2806void WM_clipboard_text_set(const char *buf, bool selection)
2807{
2808 if (!G.background) {
2809#ifdef _WIN32
2810 /* Do conversion from `\n` to `\r\n` on Windows. */
2811 const char *p;
2812 char *p2, *newbuf;
2813 int newlen = 0;
2814
2815 for (p = buf; *p; p++) {
2816 if (*p == '\n') {
2817 newlen += 2;
2818 }
2819 else {
2820 newlen++;
2821 }
2822 }
2823
2824 newbuf = MEM_new_array_zeroed<char>(newlen + 1, "WM_clipboard_text_set");
2825
2826 for (p = buf, p2 = newbuf; *p; p++, p2++) {
2827 if (*p == '\n') {
2828 *(p2++) = '\r';
2829 *p2 = '\n';
2830 }
2831 else {
2832 *p2 = *p;
2833 }
2834 }
2835 *p2 = '\0';
2836
2837 wm_clipboard_text_set_impl(newbuf, selection);
2838 MEM_delete(newbuf);
2839#else
2840 wm_clipboard_text_set_impl(buf, selection);
2841#endif
2842 }
2843}
2844
2846{
2847 if (G.background) {
2848 return false;
2849 }
2850 return bool(g_system->hasClipboardImage());
2851}
2852
2854{
2855 if (G.background) {
2856 return nullptr;
2857 }
2858
2859 int width, height;
2860
2861 uint8_t *rgba = reinterpret_cast<uint8_t *>(g_system->getClipboardImage(&width, &height));
2862 if (!rgba) {
2863 return nullptr;
2864 }
2865
2866 ImBuf *ibuf = IMB_allocFromBuffer(rgba, nullptr, width, height, 4);
2867 free(rgba);
2868
2869 return ibuf;
2870}
2871
2873{
2874 if (G.background) {
2875 return false;
2876 }
2877 if (ibuf->byte_data() == nullptr) {
2878 return false;
2879 }
2880
2881 bool success = bool(g_system->putClipboardImage(
2882 reinterpret_cast<uint *>(ibuf->byte_data_for_write()), ibuf->x, ibuf->y));
2883
2884 return success;
2885}
2886
2888
2889/* -------------------------------------------------------------------- */
2892
2893void WM_progress_set(wmWindow *win, float progress)
2894{
2895 /* In background mode we may have windows, but not actual GHOST windows. */
2896 if (win->runtime->ghostwin) {
2897 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2898 ghost_window->setProgressBar(progress);
2899 }
2900}
2901
2903{
2904 if (win->runtime->ghostwin) {
2905 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2906 ghost_window->endProgressBar();
2907 }
2908}
2909
2911
2912/* -------------------------------------------------------------------- */
2915
2916void wm_window_set_size(wmWindow *win, int width, int height)
2917{
2918 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2919 ghost_window->setClientSize(width, height);
2920}
2921
2923
2924/* -------------------------------------------------------------------- */
2927
2929{
2930 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2931 ghost_window->setOrder(GHOST_kWindowOrderBottom);
2932}
2933
2935{
2936 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2937 /* Restore window if minimized. */
2938 if (ghost_window->getState() == GHOST_kWindowStateMinimized) {
2939 ghost_window->setState(GHOST_kWindowStateNormal);
2940 }
2941 ghost_window->setOrder(GHOST_kWindowOrderTop);
2942}
2943
2945
2946/* -------------------------------------------------------------------- */
2949
2951{
2952 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2953 ghost_window->swapBufferAcquire();
2954}
2955
2957{
2958 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2959 ghost_window->swapBufferRelease();
2960}
2961
2963{
2964 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2965 ghost_window->setSwapInterval(interval);
2966}
2967
2968bool wm_window_get_swap_interval(wmWindow *win, int *r_interval)
2969{
2970 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
2971 return ghost_window->getSwapInterval(*r_interval);
2972}
2973
2975
2976/* -------------------------------------------------------------------- */
2979
2981 const int event_xy[2],
2982 int r_event_xy_other[2])
2983{
2985 /* Window positions are unsupported, so this function can't work as intended.
2986 * Perform the bare minimum, return the active window if the event is within it. */
2987 rcti rect;
2988 WM_window_rect_calc(win, &rect);
2989 if (!BLI_rcti_isect_pt_v(&rect, event_xy)) {
2990 return nullptr;
2991 }
2992 copy_v2_v2_int(r_event_xy_other, event_xy);
2993 return win;
2994 }
2995
2996 int temp_xy[2];
2997 copy_v2_v2_int(temp_xy, event_xy);
2998 wm_cursor_position_to_ghost_screen_coords(win, &temp_xy[0], &temp_xy[1]);
2999
3000 const GHOST_IWindow *ghost_window = g_system->getWindowUnderCursor(temp_xy[0], temp_xy[1]);
3001
3002 if (!ghost_window) {
3003 return nullptr;
3004 }
3005
3006 wmWindow *win_other = static_cast<wmWindow *>(ghost_window->getUserData());
3007 wm_cursor_position_from_ghost_screen_coords(win_other, &temp_xy[0], &temp_xy[1]);
3008 copy_v2_v2_int(r_event_xy_other, temp_xy);
3009 return win_other;
3010}
3011
3013{
3014 for (wmWindow &win : wm->windows) {
3016 if (BLI_findindex(&sc->areabase, area) != -1) {
3017 return &win;
3018 }
3019 }
3020 return nullptr;
3021}
3022
3024
3025/* -------------------------------------------------------------------- */
3028
3029void WM_init_state_size_set(int stax, int stay, int sizx, int sizy)
3030{
3031 wm_init_state.start = int2(stax, stay); /* Left hand bottom position. */
3032 wm_init_state.size = int2(std::max(sizx, 640), std::max(sizy, 480));
3034}
3035
3041
3047
3053
3058
3060{
3062}
3063
3065{
3067}
3068
3070{
3072}
3073
3075
3076/* -------------------------------------------------------------------- */
3079
3081{
3082 if (!g_system) [[unlikely]] {
3083 return;
3084 }
3085
3087
3088 switch (U.tablet_api) {
3089 case USER_TABLET_NATIVE:
3091 break;
3092 case USER_TABLET_WINTAB:
3094 break;
3096 default:
3098 break;
3099 }
3100}
3101
3102void WM_cursor_warp(wmWindow *win, int x, int y)
3103{
3104 /* This function requires access to the GHOST System Handle (`g_system`). */
3105 if (!(win && win->runtime->ghostwin)) {
3106 return;
3107 }
3108
3109 int oldx = x, oldy = y;
3110
3112
3113 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3115
3116 win->runtime->eventstate->prev_xy[0] = oldx;
3117 win->runtime->eventstate->prev_xy[1] = oldy;
3118
3119 win->runtime->eventstate->xy[0] = oldx;
3120 win->runtime->eventstate->xy[1] = oldy;
3121}
3122
3123uint WM_cursor_preferred_logical_size(const bool hardware_cursor)
3124{
3125 if (OS_MAC) {
3126 if (hardware_cursor) {
3127 /* On macOS 21 logical pixels is the expected "default", so follow this here.
3128 *
3129 * NOTE(@ideasman42): visually Blender's cursors do look bigger then the systems
3130 * when set to #WM_CURSOR_DEFAULT_LOGICAL_SIZE, so use macOS's default size. */
3131 return 21;
3132 }
3133 }
3134
3136}
3137
3139
3140/* -------------------------------------------------------------------- */
3143
3145{
3146 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3147 const float fac = ghost_window ? ghost_window->getNativePixelSize() : 1.0f;
3148
3149 return int(fac * float(win->sizex));
3150}
3152{
3153 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3154 const float fac = ghost_window ? ghost_window->getNativePixelSize() : 1.0f;
3155
3156 return int(fac * float(win->sizey));
3157}
3158
3160{
3161 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3162 const float fac = ghost_window ? ghost_window->getNativePixelSize() : 1.0f;
3163
3164 return int2(int(fac * float(win->sizex)), int(fac * float(win->sizey)));
3165}
3166
3167void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
3168{
3169 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3170 const float fac = ghost_window ? ghost_window->getNativePixelSize() : 1.0f;
3171
3172 *x *= fac;
3173 *y *= fac;
3174}
3175
3177{
3178 /* Redraw the title bar if necessary. */
3179#ifdef WITH_GHOST_CSD
3180 if (WM_window_is_csd(win)) {
3181 WM_event_add_notifier_ex(wm, win, NC_WINDOW, nullptr);
3182 }
3183#else
3184 UNUSED_VARS(wm, win);
3185#endif
3186}
3187
3189{
3190#ifdef WITH_GHOST_CSD
3191 return g_system_use_csd;
3192#else
3193 return false;
3194#endif
3195}
3196
3198{
3199#ifdef WITH_GHOST_CSD
3200 if (g_system_use_csd && !WM_window_is_fullscreen(win)) {
3201 return true;
3202 }
3203#else
3204 UNUSED_VARS(win);
3205#endif
3206 return false;
3207}
3208
3209void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
3210{
3211#ifdef WITH_GHOST_CSD
3212 if (WM_window_is_csd(win) &&
3213 /* This will be null when creating the window.
3214 * So we can't calculate CSD here. */
3215 (win->runtime->ghostwin != nullptr))
3216 {
3217 WM_window_csd_rect_calc(win, r_rect);
3218 return;
3219 }
3220#endif /* WITH_GHOST_CSD */
3221
3222 const int2 win_size = WM_window_native_pixel_size(win);
3223 BLI_rcti_init(r_rect, 0, win_size[0], 0, win_size[1]);
3224}
3226{
3227 rcti window_rect, screen_rect;
3228
3229 WM_window_rect_calc(win, &window_rect);
3230 screen_rect = window_rect;
3231
3232 /* Subtract global areas from screen rectangle. */
3233 for (ScrArea &global_area : win->global_areas.areabase) {
3234 int height = ED_area_global_size_y(&global_area) - 1;
3235
3236 if (global_area.global->flag & GLOBAL_AREA_IS_HIDDEN) {
3237 continue;
3238 }
3239
3240 switch (global_area.global->align) {
3242 screen_rect.ymax -= height;
3243 break;
3245 screen_rect.ymin += height;
3246 break;
3247 default:
3249 break;
3250 }
3251 }
3252
3253 BLI_assert(BLI_rcti_is_valid(&screen_rect));
3254
3255 *r_rect = screen_rect;
3256}
3257
3259{
3261}
3262
3264{
3266}
3267
3269{
3275 if ((win->parent != nullptr) || screen->temp) {
3276 return false;
3277 }
3278 return true;
3279}
3280
3282{
3283 if (!GPU_hdr_support() || !win->runtime->ghostwin) {
3284 return false;
3285 }
3286
3287 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3288 return ghost_window->getHDRInfo().hdr_enabled;
3289}
3290
3292
3293/* -------------------------------------------------------------------- */
3296
3297void WM_windows_scene_data_sync(const ListBaseT<wmWindow> *win_lb, Scene *scene)
3298{
3299 for (wmWindow &win : *win_lb) {
3300 if (WM_window_get_active_scene(&win) == scene) {
3302 }
3303 }
3304}
3305
3307{
3308 for (wmWindow &win : wm->windows) {
3309 if (WM_window_get_active_screen(&win) == screen) {
3310 return WM_window_get_active_scene(&win);
3311 }
3312 }
3313
3314 return nullptr;
3315}
3316
3318{
3319 for (wmWindow &win : wm->windows) {
3320 if (WM_window_get_active_screen(&win) == screen) {
3322 }
3323 }
3324
3325 return nullptr;
3326}
3327
3329{
3330 for (wmWindow &win : wm->windows) {
3331 if (WM_window_get_active_screen(&win) == screen) {
3332 return WM_window_get_active_workspace(&win);
3333 }
3334 }
3335 return nullptr;
3336}
3337
3339{
3340 return win->scene;
3341}
3342
3344{
3346 wmWindow *win_parent = (win->parent) ? win->parent : win;
3347 bool changed = false;
3348
3349 /* Set scene in parent and its child windows. */
3350 if (win_parent->scene != scene) {
3351 ED_screen_scene_change(C, win_parent, scene, true);
3352 changed = true;
3353 }
3354
3355 for (wmWindow &win_child : wm->windows) {
3356 if (win_child.parent == win_parent && win_child.scene != scene) {
3357 ED_screen_scene_change(C, &win_child, scene, true);
3358 changed = true;
3359 }
3360 }
3361
3362 if (changed) {
3363 /* Update depsgraph and renderers for scene change. */
3364 ViewLayer *view_layer = WM_window_get_active_view_layer(win_parent);
3365 ED_scene_change_update(bmain, scene, view_layer);
3366
3367 /* Complete redraw. */
3369 }
3370}
3371
3373{
3374 Scene *scene = WM_window_get_active_scene(win);
3375 if (scene == nullptr) {
3376 return nullptr;
3377 }
3378
3379 ViewLayer *view_layer = BKE_view_layer_find(scene, win->view_layer_name);
3380 if (view_layer) {
3381 return view_layer;
3382 }
3383
3384 view_layer = BKE_view_layer_default_view(scene);
3385 if (view_layer) {
3386 WM_window_set_active_view_layer(const_cast<wmWindow *>(win), view_layer);
3387 }
3388
3389 return view_layer;
3390}
3391
3393{
3394 BLI_assert(BKE_view_layer_find(WM_window_get_active_scene(win), view_layer->name) != nullptr);
3395 Main *bmain = G_MAIN;
3396
3397 wmWindowManager *wm = bmain->wm.first();
3398 wmWindow *win_parent = (win->parent) ? win->parent : win;
3399
3400 /* Set view layer in parent and child windows. */
3401 for (wmWindow &win_iter : wm->windows) {
3402 if ((&win_iter == win_parent) || (win_iter.parent == win_parent)) {
3403 STRNCPY_UTF8(win_iter.view_layer_name, view_layer->name);
3405 ED_render_view_layer_changed(bmain, screen);
3406 }
3407 }
3408}
3409
3411{
3412 /* Update layer name is correct after scene changes, load without UI, etc. */
3413 Scene *scene = WM_window_get_active_scene(win);
3414
3415 if (scene && BKE_view_layer_find(scene, win->view_layer_name) == nullptr) {
3416 ViewLayer *view_layer = BKE_view_layer_default_view(scene);
3417 STRNCPY_UTF8(win->view_layer_name, view_layer->name);
3418 }
3419}
3420
3425
3427{
3429 wmWindow *win_parent = (win->parent) ? win->parent : win;
3430
3431 ED_workspace_change(workspace, C, wm, win);
3432
3433 for (wmWindow &win_child : wm->windows) {
3434 if (win_child.parent == win_parent) {
3435 bScreen *screen = WM_window_get_active_screen(&win_child);
3436 /* Don't change temporary screens, they only serve a single purpose. */
3437 if (screen->temp) {
3438 continue;
3439 }
3440 ED_workspace_change(workspace, C, wm, &win_child);
3441 }
3442 }
3443}
3444
3446{
3447 const WorkSpace *workspace = WM_window_get_active_workspace(win);
3448 return (LIKELY(workspace != nullptr) ? BKE_workspace_active_layout_get(win->workspace_hook) :
3449 nullptr);
3450}
3452{
3453 BKE_workspace_active_layout_set(win->workspace_hook, win->winid, workspace, layout);
3454}
3455
3457{
3458 const WorkSpace *workspace = WM_window_get_active_workspace(win);
3459 /* May be null in rare cases like closing Blender. */
3460 return (LIKELY(workspace != nullptr) ? BKE_workspace_active_screen_get(win->workspace_hook) :
3461 nullptr);
3462}
3464{
3465 BKE_workspace_active_screen_set(win->workspace_hook, win->winid, workspace, screen);
3466}
3467
3469{
3470 const bScreen *screen = WM_window_get_active_screen(win);
3471 return (screen && screen->temp != 0);
3472}
3473
3475
3476/* -------------------------------------------------------------------- */
3479
3480#ifdef WITH_INPUT_IME
3482static void wm_window_ime_position_set(
3483 wmWindow *win, int x, int y, int w, int h, const bool complete)
3484{
3485 BLI_assert(win);
3486
3487 /* Convert to native OS window coordinates. */
3488 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3489 const float fac = ghost_window->getNativePixelSize();
3490 x /= fac;
3491 y /= fac;
3492 w /= fac;
3493 h /= fac;
3494 ghost_window->beginIME(x, win->sizey - y, w, h, complete);
3495}
3496
3497void WM_window_IME_begin(
3498 wmWindow *win, int x, int y, int w, int h, const bke::wmIMEOwnerType owner)
3499{
3501 return;
3502 }
3503 win->runtime->ime_owner = owner;
3504 wm_window_ime_position_set(win, x, y, w, h, true);
3505}
3506
3507void WM_window_IME_reposition(wmWindow *win, int x, int y, int w, int h)
3508{
3510 return;
3511 }
3512 /* Callers only reposition a session they know exists. */
3513 BLI_assert(win->runtime->ime_owner.has_value());
3514 /* `complete = false` moves the IME window without completing the composition. */
3515 wm_window_ime_position_set(win, x, y, w, h, false);
3516}
3517
3518void WM_window_IME_end(wmWindow *win)
3519{
3521 return;
3522 }
3523
3524 BLI_assert(win);
3525
3526 if (win->runtime->ime_data_is_composing) {
3527 /* NOTE: ending cancels the composition, however editors have no reliable signal to erase
3528 * their preview. The GHOST "composite end" event is dispatched at the mouse, which may be
3529 * over another region by now. #ED_region_tag_redraw would seem the obvious alternative,
3530 * although it can't be used as this may run from #ED_region_do_draw.
3531 * Cancels are rare, so a coarse redraw is acceptable. */
3533 }
3534 win->runtime->ime_owner = std::nullopt;
3535 /* NOTE(@ideasman42): on WAYLAND and Windows a call to "begin" must be closed by an "end" call.
3536 * Even if no IME events were generated (which assigned `ime_data`).
3537 * TODO: check if #GHOST_EndIME can run on APPLE without causing problems. */
3538# ifdef __APPLE__
3539 /* Null when no IME events occurred since the last "end",
3540 * common as callers end without checking an IME editor exists,
3541 * see #WM_window_IME_region_refresh. */
3542 if (win->runtime->ime_data == nullptr) {
3543 return;
3544 }
3545# endif
3546
3547 GHOST_IWindow *ghost_window = static_cast<GHOST_IWindow *>(win->runtime->ghostwin);
3548 ghost_window->endIME();
3549
3550 MEM_delete(win->runtime->ime_data);
3551 win->runtime->ime_data = nullptr;
3552 win->runtime->ime_data_is_composing = false;
3553}
3554
3555bool WM_window_IME_region_refresh(wmWindow *win,
3556 const ScrArea *area,
3557 const ARegion *region,
3558 const bool keep_composing,
3559 ARegionIMECursor *r_cursor)
3560{
3561 if (win->runtime->ime_owner == bke::wmIMEOwnerType::Button) {
3562 /* A text button owns the session, possibly in a popup over this region,
3563 * see #textedit_ime_begin. */
3564 return false;
3565 }
3566
3567 /* A temporary popup is modal, it takes precedence over the region below it,
3568 * otherwise any redraw while the popup is open re-enables the IME, see #ED_region_do_draw.
3569 * Tool-tips are excluded, they take no input and may outlive the cursor leaving
3570 * their region (gizmo tool-tips for e.g.), which would prevent beginning the IME. */
3571 const bScreen *screen = WM_window_get_active_screen(win);
3572 const ARegion *tooltip_region = screen->tool_tip ? screen->tool_tip->region : nullptr;
3573 for (const ARegion &region_iter : screen->regionbase) {
3574 if ((region_iter.regiontype == RGN_TYPE_TEMPORARY) && (&region_iter != tooltip_region)) {
3575 return false;
3576 }
3577 }
3578
3579 /* NOTE: ending mid-composition cancels it, so the draw-time refresh opts out via
3580 * `keep_composing`. Other callers keep end + begin so that the composition doesn't follow
3581 * the mouse into another editor.
3582 *
3583 * Composing while the session has no `Region` owner is unlikely. Treat it as not composing
3584 * so the end + begin below still runs, otherwise the candidate window is never positioned. */
3585 const bool composing = keep_composing && win->runtime->ime_data_is_composing &&
3586 (win->runtime->ime_owner == bke::wmIMEOwnerType::Region) && region &&
3587 region->runtime->type->cursor_ime;
3588
3589 if (!composing) {
3590 WM_window_IME_end(win);
3591
3592 if (!region || !region->runtime->type->cursor_ime) {
3593 return false;
3594 }
3595 }
3596
3597 ARegionIMECursor cursor;
3598 const std::optional<ARegionIMECursorState> cursor_state = region->runtime->type->cursor_ime(
3599 win, area, region, &cursor);
3600 if (!cursor_state) {
3601 /* The region stopped accepting IME (e.g. exited edit mode), end the session when composing.
3602 * Leaving it open would keep the OS IME enabled with input silently dropped. */
3603 if (composing) {
3604 WM_window_IME_end(win);
3605 }
3606 return false;
3607 }
3608 if (*cursor_state != ARegionIMECursorState::PositionSet) {
3609 /* Pending because of a transient lack of position, so keep the session where it is. */
3610 return false;
3611 }
3612 if (r_cursor) {
3613 *r_cursor = cursor;
3614 }
3615
3616 /* Convert to window coordinates, clamped to the region so a cursor scrolled out of view
3617 * keeps the IME window at the region edge. */
3618 const int x = region->winrct.xmin +
3619 std::clamp(cursor.rect.xmin, 0, BLI_rcti_size_x(&region->winrct));
3620 const int y = region->winrct.ymin +
3621 std::clamp(cursor.rect.ymin, 0, BLI_rcti_size_y(&region->winrct));
3622 /* A caret has no width, its height is the preview's, see #ARegionType::cursor_ime. */
3623 BLI_assert(BLI_rcti_size_x(&cursor.rect) == 0);
3624 BLI_assert(BLI_rcti_size_y(&cursor.rect) != 0);
3625 const int w = 0;
3626 const int h = BLI_rcti_size_y(&cursor.rect);
3627
3628 if (composing) {
3629 WM_window_IME_reposition(win, x, y, w, h);
3630 }
3631 else {
3632 /* #WM_window_IME_end above ended any session, so this is always a fresh begin. */
3633 WM_window_IME_begin(win, x, y, w, h, bke::wmIMEOwnerType::Region);
3634 }
3635 return true;
3636}
3637
3638const wmIMEData *WM_window_IME_data_get(const wmWindow *win, const ARegion *region)
3639{
3640 if (!win->runtime->ime_data_is_composing) {
3641 return nullptr;
3642 }
3643 /* The IME state is per-window, so don't preview a composition a text button owns,
3644 * as it may be in a popup over this region. */
3645 if (win->runtime->ime_owner != bke::wmIMEOwnerType::Region) {
3646 return nullptr;
3647 }
3648 /* Only the focused region previews, otherwise every editor showing the same data would.
3649 * The screen may be null while tearing down, see #WM_window_get_active_screen. */
3650 const bScreen *screen = WM_window_get_active_screen(win);
3651 if (!screen || region != screen->active_region) {
3652 return nullptr;
3653 }
3654 const wmIMEData *ime_data = win->runtime->ime_data;
3655 if (ime_data == nullptr || ime_data->composite.empty()) {
3656 return nullptr;
3657 }
3658 return ime_data;
3659}
3660
3661std::optional<IndexRange> WM_window_IME_composite_select_range(const wmIMEData *ime_data)
3662{
3663 BLI_assert(ime_data != nullptr);
3664 if ((ime_data->sel_start == -1) || (ime_data->sel_end == -1)) {
3665 return std::nullopt;
3666 }
3667 const int composite_len = int(ime_data->composite.size());
3668 const int sel_start = std::clamp(ime_data->sel_start, 0, composite_len);
3669 const int sel_end = std::clamp(ime_data->sel_end, 0, composite_len);
3670 if (sel_start >= sel_end) {
3671 return std::nullopt;
3672 }
3673 return IndexRange::from_begin_end(sel_start, sel_end);
3674}
3675#endif /* WITH_INPUT_IME */
3676
3678
3679/* -------------------------------------------------------------------- */
3682
3684{
3685 /* On Windows there is a problem creating contexts that share resources (almost any object,
3686 * including legacy display lists, but also textures) with a context which is current in another
3687 * thread. This is a documented and behavior of both `::wglCreateContextAttribsARB()` and
3688 * `::wglShareLists()`.
3689 *
3690 * Other platforms might successfully share resources from context which is active somewhere
3691 * else, but to keep our code behave the same on all platform we expect contexts to only be
3692 * created from the main thread. */
3693
3696
3697 GHOST_GPUSettings gpu_settings = {0};
3698 const GPUBackendType gpu_backend = GPU_backend_type_selection_get();
3699 gpu_settings.context_type = wm_ghost_drawing_context_type(gpu_backend);
3700 if (G.debug & G_DEBUG_GPU) {
3701 gpu_settings.flags |= GHOST_gpuDebugContext;
3702 }
3703 if (G.debug & G_DEBUG_GPU_NO_HW_RAYTRACING) {
3704 gpu_settings.flags |= GHOST_gpuNoHWRaytracing;
3705 }
3708 gpu_settings.flags |= GHOST_gpuVSyncIsOverridden;
3710 }
3711
3712 return g_system->createOffscreenContext(gpu_settings);
3713}
3714
3720
3722{
3724 context->activateDrawingContext();
3725}
3726
3728{
3730 context->releaseDrawingContext();
3731}
3732
3733void WM_ghost_show_message_box(const char *title,
3734 const char *message,
3735 const char *help_label,
3736 const char *continue_label,
3737 const char *link,
3738 GHOST_DialogOptions dialog_options)
3739{
3741 g_system->showMessageBox(title, message, help_label, continue_label, link, dialog_options);
3742}
3743
3745
3746} // namespace blender
#define G_MAIN
#define OS_WINDOWS
#define OS_MAC
#define ENUM_OPERATORS(_enum_type)
File and directory operations.
#define BLI_path_ncmp
#define FILE_MAX
#define STRNCPY_UTF8(dst, src)
Platform independent time functions.
#define RPT_(msgid)
#define IFACE_(msgid)
#define CLOG_STR_ERROR(clg_ref, str)
Definition CLG_log.h:196
#define CLOG_INFO_NOCHECK(clg_ref, format,...)
Definition CLG_log.h:204
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
These structs are the foundation for all linked lists in the library system.
#define SPACE_TYPE_ANY
#define UI_SCALE_FAC
void * GHOST_TUserDataPtr
const void * GHOST_TEventDataPtr
GHOST_TWindowState
@ GHOST_kWindowStateMinimized
@ GHOST_kWindowStateMaximized
@ GHOST_kWindowStateNormal
@ GHOST_kWindowStateFullScreen
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
@ GHOST_kCapabilityWindowDecorationServerSide
@ GHOST_kCapabilityWindowPosition
@ GHOST_kCapabilityClipboardPrimary
@ GHOST_kCapabilityKeyboardHyperKey
@ GHOST_kCapabilityCursorRGBA
@ GHOST_kCapabilityGPUReadFrontBuffer
@ GHOST_kCapabilityCursorWarp
@ GHOST_kCapabilityInputIME
@ GHOST_kCapabilityCursorGenerator
@ GHOST_kCapabilityWindowPath
@ GHOST_kCapabilityTrackpadPhysicalDirection
@ GHOST_kCapabilityMultiMonitorPlacement
@ GHOST_kCapabilityClipboardImage
@ 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
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_gpuVSyncIsOverridden
@ GHOST_gpuNoHWRaytracing
@ GHOST_gpuStereoVisual
@ GHOST_gpuDebugContext
@ GHOST_kDragnDropTypeFilenames
@ GHOST_kDragnDropTypeString
GHOST_TVSyncModes
@ GHOST_kTabletAutomatic
@ GHOST_kTabletWinPointer
@ GHOST_kTabletWintab
GHOST_DialogOptions
GHOST_TWindowDecorationStyleFlags
@ GHOST_kDecorationNone
@ GHOST_kDecorationColoredTitleBar
Read Blender memory allocation and freeing.
#define PRF_scope(category)
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_SCREEN
Definition WM_types.hh:390
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define NA_REMOVED
Definition WM_types.hh:637
#define ND_LAYOUTDELETE
Definition WM_types.hh:440
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define POINTER_AS_UINT(i)
#define BLI_assert(a)
#define ELEM(...)
#define POINTER_FROM_UINT(i)
#define BLI_assert_msg(a, msg)
#define LIKELY(x)
void activate(bool forceActivation=false) const
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
GHOST_CallbackEventConsumer(GHOST_EventCallbackProcPtr eventCallback, GHOST_TUserDataPtr user_data)
virtual GHOST_TEventType getType() const =0
virtual GHOST_TEventDataPtr getData() const =0
virtual GHOST_IWindow * getWindow() const =0
virtual uint64_t getTime() const =0
static GHOST_ISystem * getSystem()
virtual void putClipboard(const char *buffer, bool selection) const =0
static GHOST_TSuccess createSystem(bool verbose=true, bool background=false)
virtual GHOST_TSuccess getModifierKeyState(GHOST_TModifierKey mask, bool &is_down) const =0
static void setUseWindowFrame(bool use_window_frame)
static void setBacktraceFn(GHOST_TBacktraceFn backtrace_fn)
virtual GHOST_TSuccess showMessageBox(const char *, const char *, const char *, const char *, const char *, GHOST_DialogOptions) const =0
virtual void initDebug(GHOST_Debug debug)=0
virtual void setTabletAPI(GHOST_TTabletAPI api)=0
virtual char * getClipboard(bool selection) const =0
virtual GHOST_TSuccess setCursorPositionClientRelative(GHOST_IWindow *window, int32_t x, int32_t y)=0
virtual void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const =0
virtual GHOST_TSuccess hasClipboardImage() const =0
virtual bool validWindow(GHOST_IWindow *window)=0
virtual GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpu_settings, const bool exclusive=false, const bool is_dialog=false, const GHOST_IWindow *parent_window=nullptr)=0
virtual void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const =0
virtual uint * getClipboardImage(int *r_width, int *r_height) const =0
virtual GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpu_settings)=0
virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer *consumer)=0
virtual void useWindowFocus(const bool use_focus)=0
virtual GHOST_TSuccess disposeContext(GHOST_IContext *context)=0
virtual bool useNativePixel()=0
static GHOST_TSuccess disposeSystem()
virtual void setMultitouchGestures(const bool use)=0
virtual void dispatchEvents()=0
virtual void setIconGenerator(const GHOST_IconGenerator *icon_generator)=0
static const char * getSystemBackend()
virtual const GHOST_CSD_Layout & getWindowCSD_Layout() const =0
virtual GHOST_TCapabilityFlag getCapabilities() const =0
virtual uint32_t getCursorPreferredLogicalSize() const =0
virtual GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const =0
virtual void setWindowCSD(const GHOST_CSD_Params &params)=0
virtual GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window, int32_t &x, int32_t &y) const =0
virtual uint64_t getMilliSeconds() const =0
virtual GHOST_TSuccess disposeWindow(GHOST_IWindow *window)=0
virtual GHOST_IWindow * getWindowUnderCursor(int32_t x, int32_t y)=0
virtual bool processEvents(bool waitForEvent)=0
static GHOST_TSuccess createSystemBackground()
virtual void setTitle(const char *title)=0
virtual void getClientBounds(GHOST_Rect &bounds) const =0
virtual GHOST_TSuccess activateDrawingContext()=0
virtual GHOST_TSuccess endProgressBar()=0
virtual void setWindowDecorationStyleSettings(GHOST_WindowDecorationStyleSettings decoration_settings)=0
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order)=0
virtual void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const =0
virtual GHOST_TSuccess setProgressBar(float progress)=0
virtual GHOST_TSuccess swapBufferRelease()=0
virtual bool isDialog() const =0
virtual GHOST_WindowHDRInfo getHDRInfo()=0
virtual GHOST_TSuccess setClientSize(uint32_t width, uint32_t height)=0
virtual GHOST_TSuccess applyWindowDecorationStyle()=0
virtual GHOST_TSuccess setState(GHOST_TWindowState state)=0
virtual float getNativePixelSize()=0
virtual GHOST_IContext * getDrawingContext()=0
virtual GHOST_TSuccess getSwapInterval(int &interval_out)=0
virtual void setPath(const char *filepath)=0
virtual void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const =0
virtual GHOST_TSuccess swapBufferAcquire()=0
virtual void setUserData(const GHOST_TUserDataPtr user_data)=0
virtual GHOST_TWindowDecorationStyleFlags getWindowDecorationStyleFlags()=0
virtual GHOST_TSuccess setSwapInterval(int interval)=0
virtual GHOST_TUserDataPtr getUserData() const =0
virtual void setWindowDecorationStyleFlags(GHOST_TWindowDecorationStyleFlags style_flags)=0
virtual uint16_t getDPIHint()=0
virtual GHOST_TWindowState getState() const =0
virtual GHOST_TSuccess setModifiedState(bool is_unsaved_changes)=0
int32_t t_
virtual int32_t getHeight() const
int32_t l_
virtual int32_t getWidth() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr Span()=default
constexpr StringRef()
T get(const std::string &item_key) const
Definition recents.cc:224
void set(const std::string &item_key, const T &value)
Definition recents.cc:285
#define roundf(x)
#define str(s)
#define ceil
float3x3 scale(float3x3 mat, float2 scale)
#define PRIu64
Definition inttypes.h:132
const int state
void free(Subdiv *subdiv)
Definition subdiv.cc:192
std::string filename(const std::string_view &str, size_t pos)
void get_color_3fv(int colorid, float col[3])
void theme_set(int spacetype, int regionid)
void popup_handlers_remove_all(bContext *C, ListBaseT< wmEventHandler > *handlers)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
const char * BLI_str_utf8_invalid_substitute_if_needed(const char *str, size_t str_len, const char substitute, char *buf, const size_t buf_maxncpy) ATTR_NONNULL(1
UserDef U
Definition blender.cc:58
WorkSpaceLayout * ED_workspace_layout_duplicate(Main *bmain, WorkSpace *workspace, const WorkSpaceLayout *layout_old, wmWindow *win) ATTR_NONNULL()
bool BLI_rcti_is_valid(const struct rcti *rect)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool wm_get_screensize(int r_size[2])
Definition wm_window.cc:202
void WM_window_set_active_scene(Main *bmain, bContext *C, wmWindow *win, Scene *scene)
void WM_gestures_free_all(wmWindow *win)
unsigned __int64 uint64_t
Definition BKE_text.h:91
const char * BLI_path_extension_or_end(const char *filepath) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
gpu::FrameBuffer * GPU_framebuffer_active_get()
void wm_cursor_position_to_ghost_client_coords(wmWindow *win, int *x, int *y)
wmWindow * wm_window_new(const Main *bmain, wmWindowManager *wm, wmWindow *parent, bool dialog)
Definition wm_window.cc:348
eWM_WindowDecorationStyleFlag WM_window_decoration_style_flags_get(const wmWindow *win)
Definition wm_window.cc:805
void WM_event_timer_free_data(wmTimer *timer)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
ImBuf * WM_clipboard_image_get()
void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) SETTER_ATTRS
Definition workspace.cc:637
char * STRNCPY(char(&dst)[N], const char *src)
ViewLayer * WM_windows_view_layer_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference)
void WM_event_timer_sleep(wmWindowManager *wm, wmWindow *, wmTimer *timer, bool do_sleep)
void ED_screen_scene_change(bContext *C, wmWindow *win, Scene *scene, bool refresh_toolsystem)
const char * WM_ghost_backend()
void BLI_rcti_resize_y(struct rcti *rect, int y)
Definition rct.cc:629
wmOperatorStatus wm_window_new_exec(bContext *C, wmOperator *op)
void wm_window_set_swap_interval(wmWindow *win, int interval)
void ED_render_view_layer_changed(Main *bmain, bScreen *screen)
const EnumPropertyItem rna_enum_space_type_items[]
Definition rna_space.cc:91
void WM_window_decoration_style_flags_set(const wmWindow *win, eWM_WindowDecorationStyleFlag style_flags)
Definition wm_window.cc:820
void wm_window_events_process(const bContext *C)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static CLG_LogRef LOG_GHOST_SYSTEM
Definition wm_window.cc:125
void wm_window_lower(wmWindow *win)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void WM_event_start_drag(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
void GPU_clear_color(float red, float green, float blue, float alpha)
int WM_window_csd_layout_callback(const int window_size[2], const int fractional_scale[2], const char window_state, const GHOST_CSD_Layout *csd_layout, GHOST_CSD_Elem *csd_elems)
static char * wm_clipboard_text_get_impl(bool selection)
GPUContext * GPU_context_create(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context)
int WM_window_native_pixel_y(const wmWindow *win)
void WM_operator_properties_free(PointerRNA *ptr)
void WM_init_window_frame_set(bool do_it)
@ GLOBAL_AREA_ALIGN_BOTTOM
bool WM_clipboard_image_available()
void WM_event_timer_remove_notifier(wmWindowManager *wm, wmWindow *win, wmTimer *timer)
static void wm_window_ensure_eventstate(wmWindow *win)
Definition wm_window.cc:990
void WM_init_state_maximized_set()
void wm_ghost_exit()
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bke::BlenderProject * BKE_blender_project_get(const Main *bmain)
void BKE_workspace_active_screen_set(WorkSpaceInstanceHook *hook, int winid, WorkSpace *workspace, bScreen *screen) SETTER_ATTRS
Definition workspace.cc:688
void wm_cursor_position_from_ghost_client_coords(wmWindow *win, int *x, int *y)
void wm_window_ghostwindows_remove_invalid(bContext *C, wmWindowManager *wm)
void BKE_screen_area_map_free(ScrAreaMap *area_map) ATTR_NONNULL()
Definition screen.cc:799
void CTX_wm_window_set(bContext *C, wmWindow *win)
WorkSpaceLayout * WM_window_get_active_layout(const wmWindow *win)
void WM_init_window_focus_set(bool do_it)
wmWindow * WM_window_find_under_cursor(wmWindow *win, const int event_xy[2], int r_event_xy_other[2])
void wm_window_timers_delete_removed(wmWindowManager *wm)
uint WM_cursor_preferred_logical_size(const bool hardware_cursor)
void wm_ghost_init(bContext *C)
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)
static void wm_window_decoration_style_set_from_theme(const wmWindow *win, const bScreen *screen)
Definition wm_window.cc:854
void WM_window_decoration_style_apply(const wmWindow *win, const bScreen *screen)
Definition wm_window.cc:870
void WM_init_native_pixels(bool do_it)
StringRefNull ED_area_name(const ScrArea *area)
wmWindow * wm_window_copy_test(bContext *C, wmWindow *win_src, const bool duplicate_layout, const bool child)
Definition wm_window.cc:394
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
@ WM_DRAG_STRING
Definition WM_types.hh:1311
@ WM_DRAG_PATH
Definition WM_types.hh:1302
static void wm_window_update_eventstate_modifiers_clear(wmWindowManager *wm, wmWindow *win, const uint64_t event_time_ms)
Definition wm_window.cc:944
wmOperatorStatus wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *)
static void wm_window_ghostwindow_ensure(wmWindowManager *wm, wmWindow *win, bool is_dialog)
void WM_window_title_set(wmWindow *win, const char *title)
Definition wm_window.cc:708
void WM_window_set_active_layout(wmWindow *win, WorkSpace *workspace, WorkSpaceLayout *layout)
CLG_LogRef * WM_LOG_EVENTS
void BLI_rcti_resize_x(struct rcti *rect, int x)
Definition rct.cc:623
void WM_system_gpu_context_release(GHOST_IContext *context)
void ED_area_newspace(bContext *C, ScrArea *area, int type, bool skip_region_exit)
Definition area.cc:2929
void wm_cursor_position_to_ghost_screen_coords(wmWindow *win, int *x, int *y)
wmWindow * CTX_wm_window(const bContext *C)
void WM_window_set_active_workspace(bContext *C, wmWindow *win, WorkSpace *workspace)
void wm_clipboard_free()
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:1063
MINLINE int max_ii(int a, int b)
int ED_file_extension_icon(const char *path)
Definition filelist.cc:1946
int GPU_backend_vsync_get()
void GPU_render_begin()
int WM_window_native_pixel_x(const wmWindow *win)
void WM_progress_clear(wmWindow *win)
void GPU_context_active_set(GPUContext *)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
void wm_event_do_notifiers(bContext *C)
GHOST_IContext * WM_system_gpu_context_create()
static bool wm_window_is_last_main_window(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:468
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
void ED_screen_global_areas_refresh(wmWindow *win)
eWindowAlignment
Definition WM_api.hh:483
@ WIN_ALIGN_ABSOLUTE
Definition WM_api.hh:484
@ WIN_ALIGN_PARENT_CENTER
Definition WM_api.hh:486
@ WIN_ALIGN_LOCATION_CENTER
Definition WM_api.hh:485
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void MEM_delete_void(void *vmemh)
static GHOST_ISystem * g_system
Definition wm_window.cc:116
void WM_init_state_normal_set()
ViewLayer * BKE_view_layer_default_view(const Scene *scene)
ViewLayer * CTX_data_view_layer(const bContext *C)
wmTimer * WM_event_timer_add_notifier(wmWindowManager *wm, wmWindow *win, const uint type, const double time_step)
void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
WorkSpace * BKE_workspace_active_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:633
@ WIN_OVERRIDE_GEOM
Definition wm_window.cc:128
@ WIN_OVERRIDE_WINSTATE
Definition wm_window.cc:129
bool wm_file_or_session_data_has_unsaved_changes(const Main *bmain, const wmWindowManager *wm)
Definition wm_files.cc:198
void wm_event_free_all(wmWindow *win)
void wm_window_reset_drawable()
void wm_cursor_position_from_ghost_screen_coords(wmWindow *win, int *x, int *y)
eWM_WindowDecorationStyleFlag
Definition WM_api.hh:549
@ WM_WINDOW_DECORATION_STYLE_COLORED_TITLEBAR
Definition WM_api.hh:553
@ WM_WINDOW_DECORATION_STYLE_NONE
Definition WM_api.hh:551
@ G_DEBUG_GPU_NO_HW_RAYTRACING
@ G_DEBUG_EVENTS
@ G_DEBUG_WINTAB
@ G_DEBUG_GHOST
const char * BLI_dir_home()
Definition storage.cc:99
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
Global G
Definition blender.cc:57
void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
unsigned short uint16_t
Definition BKE_text.h:80
static uint8_t wm_ghost_modifier_query(const enum ModSide side)
void BKE_workspace_instance_hook_free(const Main *bmain, WorkSpaceInstanceHook *hook)
Definition workspace.cc:400
static void wm_window_check_size(rcti *rect)
Definition wm_window.cc:233
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
unsigned int uint32_t
Definition BKE_text.h:81
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void WM_system_gpu_context_dispose(GHOST_IContext *context)
wmWindow * WM_window_find_by_area(wmWindowManager *wm, const ScrArea *area)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
void GPU_init()
void WM_event_remove_handlers(bContext *C, ListBaseT< wmEventHandler > *handlers)
wmOperatorStatus wm_window_close_exec(bContext *C, wmOperator *)
void WM_window_rect_calc(const wmWindow *win, rcti *r_rect)
static void wm_window_set_drawable(wmWindowManager *wm, wmWindow *win, bool activate)
bool WM_window_support_hdr_color(const wmWindow *win)
void WM_window_native_pixel_coords(const wmWindow *win, int *x, int *y)
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBaseT< wmEventHandler > *handlers, ListBaseT< wmDropBox > *dropboxes)
bool wm_cursor_position_get(wmWindow *win, int *r_x, int *r_y)
void BKE_icon_changed(int icon_id)
Definition icons.cc:215
VecBase< int32_t, 2 > int2
Scene * WM_window_get_active_scene(const wmWindow *win)
void WM_init_state_size_set(int stax, int stay, int sizx, int sizy)
void WM_window_ensure_active_view_layer(wmWindow *win)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void wm_window_ghostwindows_ensure(wmWindowManager *wm)
void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, const int type, const void *customdata, const uint64_t event_time_ms)
void GPU_render_end()
GPUBackendType GPU_backend_type_selection_get()
char * WM_clipboard_text_get_firstline(bool selection, bool ensure_utf8, int *r_len)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static void wm_window_title_project_append(fmt::memory_buffer &win_title)
Definition wm_window.cc:563
BMesh const char void * data
void wm_window_swap_buffer_acquire(wmWindow *win)
Push rendered buffer to the screen.
bool WM_window_is_maximized(const wmWindow *win)
static struct blender::wmInitStruct wm_init_state
void WM_progress_set(wmWindow *win, float progress)
void BKE_workspace_active_layout_set(WorkSpaceInstanceHook *hook, int winid, WorkSpace *workspace, WorkSpaceLayout *layout) SETTER_ATTRS
Activate a layout.
Definition workspace.cc:675
wmWindowManager * CTX_wm_manager(const bContext *C)
bool wm_window_get_swap_interval(wmWindow *win, int *r_interval)
gpu::FrameBuffer * GPU_framebuffer_back_get()
@ MOD_SIDE_LEFT
Definition wm_window.cc:188
@ MOD_SIDE_RIGHT
Definition wm_window.cc:189
const GHOST_CSD_Layout * WM_window_csd_layout_get()
void wm_window_set_size(wmWindow *win, int width, int height)
unsigned char uint8_t
Definition BKE_text.h:79
static void wm_window_title_state_refresh(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:698
void wm_window_close_request(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:483
static void wm_confirm_quit(bContext *C)
Definition wm_window.cc:429
void wm_quit_with_optional_confirmation_prompt(bContext *C, wmWindow *win)
Definition wm_window.cc:436
WorkSpaceLayout * ED_workspace_layout_add(Main *bmain, WorkSpace *workspace, wmWindow *win, const char *name) ATTR_NONNULL()
void WM_init_input_devices()
void WM_window_cursor_keymap_status_free(wmWindow *win)
bool GPU_hdr_support()
bool WM_clipboard_image_set_byte_buffer(ImBuf *ibuf)
static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wmWindow *win, bool is_dialog)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
WorkSpace * WM_window_get_active_workspace(const wmWindow *win)
@ WM_TIMER_NO_FREE_CUSTOM_DATA
Definition WM_types.hh:1011
@ WM_TIMER_TAGGED_FOR_REMOVAL
Definition WM_types.hh:1018
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
int BLI_thread_is_main()
Definition threads.cc:184
void WM_window_csd_draw_corner_mask(const wmWindow *win)
void wm_window_raise(wmWindow *win)
void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *)
Definition wm_files.cc:2477
void wm_window_clear_drawable(wmWindowManager *wm)
void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:517
bool ED_workspace_change(WorkSpace *workspace_new, bContext *C, wmWindowManager *wm, wmWindow *win) ATTR_NONNULL()
Change the active workspace.
static void wm_save_file_on_quit_dialog_callback(bContext *C, void *)
Definition wm_window.cc:420
static void wm_window_csd_title_redraw_tag(wmWindowManager *wm, wmWindow *win)
int ED_area_global_size_y(const ScrArea *area)
Definition area.cc:4429
bool WM_window_is_main_top_level(const wmWindow *win)
bool WM_window_csd_is_active()
wmOperatorStatus wm_window_new_main_exec(bContext *C, wmOperator *op)
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
void wm_window_titlebar_theme_context_set(const wmWindow *win, const bScreen *screen)
Definition wm_window.cc:835
void WM_system_gpu_context_activate(GHOST_IContext *context)
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1324
@ WM_DRAG_NOP
Definition WM_types.hh:1323
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool WM_init_window_frame_get()
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool wm_get_desktopsize(int r_size[2])
Definition wm_window.cc:217
static void wm_window_update_eventstate_modifiers(wmWindowManager *wm, wmWindow *win, const uint64_t event_time_ms)
Definition wm_window.cc:889
static void ghost_event_proc_timestamp_warning(const GHOST_IEvent *ghost_event)
void wm_exit_schedule_delayed(const bContext *C)
static void wm_window_title_text(wmWindowManager *wm, wmWindow *win, std::optional< FunctionRef< void(const char *)> > window_filepath_fn, fmt::memory_buffer &win_title)
Definition wm_window.cc:581
static bool ghost_event_proc(const GHOST_IEvent *ghost_event, GHOST_TUserDataPtr ps_void_ptr)
wmWindow * WM_window_open_temp(bContext *C, const char *title, int space_type, bool dialog)
void wm_jobs_timer(wmWindowManager *wm, wmTimer *wt)
Definition wm_jobs.cc:718
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
void WM_windows_scene_data_sync(const ListBaseT< wmWindow > *win_lb, Scene *scene)
eWM_CapabilitiesFlag
Definition WM_api.hh:206
@ WM_CAPABILITY_CURSOR_RGBA
Definition WM_api.hh:247
@ WM_CAPABILITY_WINDOW_DECORATION_SERVER_SIDE
Definition WM_api.hh:255
@ WM_CAPABILITY_GPU_FRONT_BUFFER_READ
Definition WM_api.hh:233
@ WM_CAPABILITY_MULTIMONITOR_PLACEMENT
Definition WM_api.hh:251
@ WM_CAPABILITY_CLIPBOARD_IMAGE
Definition WM_api.hh:235
@ WM_CAPABILITY_CURSOR_GENERATOR
Definition WM_api.hh:249
@ WM_CAPABILITY_TRACKPAD_PHYSICAL_DIRECTION
Definition WM_api.hh:241
@ WM_CAPABILITY_KEYBOARD_HYPER_KEY
Definition WM_api.hh:245
@ WM_CAPABILITY_WINDOW_DECORATION_STYLES
Definition WM_api.hh:243
@ WM_CAPABILITY_WINDOW_POSITION
Definition WM_api.hh:222
@ WM_CAPABILITY_DESKTOP_SAMPLE
Definition WM_api.hh:237
@ WM_CAPABILITY_INITIALIZED
Definition WM_api.hh:257
@ WM_CAPABILITY_WINDOW_PATH
Definition WM_api.hh:253
@ WM_CAPABILITY_INPUT_IME
Definition WM_api.hh:239
@ WM_CAPABILITY_CLIPBOARD_PRIMARY
Definition WM_api.hh:227
@ WM_CAPABILITY_CURSOR_WARP
Definition WM_api.hh:208
void wm_window_swap_buffer_release(wmWindow *win)
wmEvent * WM_event_add(wmWindow *win, const wmEvent *event_to_add)
WorkSpaceInstanceHook * BKE_workspace_instance_hook_create(const Main *bmain, int winid)
Definition workspace.cc:387
ViewLayer * BKE_view_layer_find(const Scene *scene, const char *layer_name)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
WorkSpace * WM_windows_workspace_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
void BLI_system_backtrace(FILE *fp)
Definition system.cc:112
bool WM_window_is_csd(const wmWindow *win)
static const char * g_system_backend_id
Definition wm_window.cc:118
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
@ G_FLAG_GPU_BACKEND_FALLBACK_QUIET
@ G_FLAG_EVENT_SIMULATE
@ G_FLAG_GPU_BACKEND_FALLBACK
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void WM_event_consecutive_data_free(wmWindow *win)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
void wm_test_gpu_backend_fallback(bContext *C)
void BLI_time_sleep_precise_us(int us)
Definition time.cc:101
int2 WM_window_native_pixel_size(const wmWindow *win)
bool BKE_autoexec_default_trust_source(const char *path, const AutoExec_Params &params)
Definition autoexec.cc:103
GHOST_TDrawingContextType wm_ghost_drawing_context_type(const GPUBackendType gpu_backend)
eWM_CapabilitiesFlag WM_capabilities_flag()
bScreen * BKE_workspace_layout_screen_get(const WorkSpaceLayout *layout) GETTER_ATTRS
Definition workspace.cc:709
MINLINE float max_ff(float a, float b)
@ USER_NO_MULTITOUCH_GESTURES
void WM_window_title_refresh(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:718
void BLF_cache_clear()
Definition blf.cc:100
Scene * WM_windows_scene_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
ImBuf * IMB_allocFromBuffer(const uint8_t *byte_buffer, const float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
void WM_clipboard_text_set(const char *buf, bool selection)
static bool wm_window_update_size_position(wmWindow *win)
void BKE_workspace_layout_remove(Main *bmain, WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL()
Definition workspace.cc:472
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool GPU_backend_vsync_is_overridden()
void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:276
static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win)
Definition wm_window.cc:246
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
Definition screen.cc:1189
struct blender::@256065377070330042333064353146222061270000364150 * g_wm_clipboard_text_simulate
void WM_init_state_fullscreen_set()
static void wm_clipboard_text_set_impl(const char *buf, bool selection)
@ KM_NOTHING
Definition WM_types.hh:323
@ KM_RELEASE
Definition WM_types.hh:325
static char * wm_clipboard_text_get_ex(bool selection, int *r_len, const bool ensure_utf8, const bool firstline)
void WM_window_csd_params_update()
double BLI_time_now_seconds()
Definition time.cc:30
static int find_free_winid(wmWindowManager *wm)
Definition wm_window.cc:336
WorkSpaceLayout * BKE_workspace_active_layout_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:657
void GPU_backend_ghost_system_set(GHOST_ISystem *ghost_system_handle)
bool ED_screen_change(bContext *C, bScreen *screen)
Change the active screen.
void ED_scene_change_update(Main *bmain, Scene *scene, ViewLayer *layer) ATTR_NONNULL()
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)
Scene * CTX_data_scene(const bContext *C)
void ED_screen_refresh(bContext *C, wmWindowManager *wm, wmWindow *win)
bScreen * CTX_wm_screen(const bContext *C)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
GHOST_GPUDevice GPU_backend_preferred_device_get()
bool wm_xr_events_handle(wmWindowManager *wm)
Definition wm_xr.cc:164
void wm_draw_update(bContext *C)
Definition wm_draw.cc:1706
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
wmDragPath * WM_drag_create_path_data(Span< const char * > paths)
void wm_close_file_dialog(bContext *C, wmGenericCallback *post_action)
Definition wm_files.cc:5318
ListBaseT< wmDropBox > * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
constexpr char SEP
float WM_window_dpi_get_scale(const wmWindow *win)
Definition wm_window.cc:784
void WM_check(bContext *C)
Definition wm.cc:493
void WM_window_csd_rect_calc(const wmWindow *win, rcti *r_rect)
void WM_cursor_warp(wmWindow *win, int x, int y)
void wm_jobs_timer_end(wmWindowManager *wm, wmTimer *wt)
Definition wm_jobs.cc:693
void WM_window_screen_rect_calc(const wmWindow *win, rcti *r_rect)
static void wm_window_update_eventstate(wmWindow *win)
Definition wm_window.cc:981
bScreen * WM_window_get_active_screen(const wmWindow *win)
void ED_workspace_scene_data_sync(WorkSpaceInstanceHook *hook, Scene *scene) ATTR_NONNULL()
void WM_window_dpi_set_userdef(const wmWindow *win)
Definition wm_window.cc:737
static bool wm_window_timers_process(const bContext *C, int *sleep_us_p)
wmWindow * wm_window_copy(Main *bmain, wmWindowManager *wm, wmWindow *win_src, const bool duplicate_layout, const bool child)
Definition wm_window.cc:364
int BLI_str_utf8_invalid_strip(char *str, size_t str_len) ATTR_NONNULL(1)
const char * BKE_blender_version_string()
Definition blender.cc:147
void wm_event_do_handlers(bContext *C)
void wm_event_init_from_window(wmWindow *win, wmEvent *event)
bool WM_window_is_temp_screen(const wmWindow *win)
bool WM_window_is_fullscreen(const wmWindow *win)
void WM_window_set_active_view_layer(wmWindow *win, ViewLayer *view_layer)
void GPU_context_discard(GPUContext *)
void wm_ghost_init_background()
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static const struct blender::@150207350170167056111015034026075334247243372331 g_modifier_table[]
void wm_jobs_handle_finished(const bContext *C)
Definition wm_jobs.cc:750
void void BLI_INLINE bool BLI_listbase_is_single(const ListBase *lb)
void CTX_wm_area_set(bContext *C, ScrArea *area)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
GHOST_TVSyncModes vsync
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
GHOST_TDragnDropTypes dataType
GHOST_TDragnDropDataPtr data
std::optional< ARegionIMECursorState >(*) cursor_ime(wmWindow *win, const ScrArea *area, const ARegion *region, ARegionIMECursor *r_cursor)
bke::ARegionRuntime * runtime
int icon_id
Definition DNA_ID.h:445
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
ListBaseT< wmWindowManager > wm
Definition BKE_main.hh:415
ListBaseT< ScrArea > areabase
ScrGlobalAreaData * global
eStereoDisplayMode display_mode
GHOST_TModifierKey ghost_mask_pair[2]
ListBaseT< struct ScrArea > areabase
struct ARegionType * type
ListBaseT< wmEventHandler > handlers
ListBaseT< wmEvent > event_queue
ListBaseT< wmEventHandler > modalhandlers
wmEventType keymodifier
Definition WM_types.hh:843
wmEventModifierFlag modifier
Definition WM_types.hh:834
wmGenericCallbackFn exec
Definition WM_types.hh:158
eWinOverrideFlag override_flag
Definition wm_window.cc:154
GHOST_TWindowState windowstate
Definition wm_window.cc:153
struct ReportList * reports
wmEventType event_type
Definition WM_types.hh:1031
wmTimerFlags flags
Definition WM_types.hh:1033
wmWindow * win
Definition WM_types.hh:1026
bke::WindowRuntime * runtime
struct wmEvent_ConsecutiveData * event_queue_consecutive_gesture_data
struct WorkSpaceInstanceHook * workspace_hook
struct Stereo3dFormat * stereo3d_format
#define ISTIMER(event_type)
#define GHOST_WINDOW_STATE_DEFAULT
Definition wm_window.cc:133
const GHOST_IconGenerator wm_ghost_icon_generator
#define WM_WINDOW_CSD_CORNER_RADIUS
#define WM_WINDOW_CSD_RESIZE_MARGIN_SIZE