Blender V5.3
GHOST_WindowWin32.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "GHOST_ContextD3D.hh"
12#include "GHOST_ContextNone.hh"
14#include "GHOST_SystemWin32.hh"
16#include "GHOST_WindowWin32.hh"
17#include "utf_winfunc.hh"
18#include "utfconv.hh"
19
20#ifdef WITH_OPENGL_BACKEND
21# include "GHOST_ContextWGL.hh"
22#endif
23#ifdef WITH_VULKAN_BACKEND
24# include "GHOST_ContextVK.hh"
25#endif
26
27#ifdef WIN32
28# include "BLI_path_utils.hh"
29#endif
30
31#include <Dwmapi.h>
32
33#include <assert.h>
34#include <math.h>
35#include <propkey.h>
36#include <propvarutil.h>
37#include <shellapi.h>
38#include <shellscalingapi.h>
39#include <string.h>
40#include <windowsx.h>
41
42#ifndef GET_POINTERID_WPARAM
43# define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam))
44#endif /* GET_POINTERID_WPARAM */
45
46const wchar_t *GHOST_WindowWin32::s_windowClassName = L"GHOST_WindowClass";
47const int GHOST_WindowWin32::s_maxTitleLength = 128;
48
49/* force NVidia OPTIMUS to used dedicated graphics */
50extern "C" {
51__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
52}
53
55 const char *title,
56 int32_t left,
57 int32_t top,
58 uint32_t width,
59 uint32_t height,
62 const GHOST_ContextParams &context_params,
63 GHOST_WindowWin32 *parent_window,
64 bool dialog,
65 const GHOST_GPUDevice &preferred_device)
66 : GHOST_Window(width, height, state, context_params, false),
67 mouse_present_(false),
68 in_live_resize_(false),
69 system_(system),
70 drop_target_(nullptr),
71 h_wnd_(0),
72 h_DC_(0),
73 is_dialog_(dialog),
74 preferred_device_(preferred_device),
75 has_mouse_captured_(false),
76 has_grab_mouse_(false),
77 n_pressed_buttons_(0),
78 custom_cursor_(0),
79 bar_(nullptr),
80 wintab_(nullptr),
81 last_pointer_tablet_data_(GHOST_TABLET_DATA_NONE),
82 normal_state_(GHOST_kWindowStateNormal),
83 user32_(::LoadLibrary("user32.dll")),
84 parent_window_hwnd_(parent_window ? parent_window->h_wnd_ : HWND_DESKTOP),
85 direct_manipulation_helper_(nullptr)
86{
87 DWORD style = parent_window ?
88 WS_POPUPWINDOW | WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX :
89 WS_OVERLAPPEDWINDOW;
90
92 style |= WS_MAXIMIZE;
93 }
94
95 /* Forces owned windows onto taskbar and allows minimization. */
96 DWORD extended_style = parent_window ? WS_EX_APPWINDOW : 0;
97
98 if (dialog) {
99 /* When we are ready to make windows of this type:
100 * style = WS_POPUPWINDOW | WS_CAPTION
101 * extended_style = WS_EX_DLGMODALFRAME | WS_EX_TOPMOST
102 */
103 }
104
105 RECT win_rect = {left, top, long(left + width), long(top + height)};
106 adjustWindowRectForClosestMonitor(&win_rect, style, extended_style);
107
108 wchar_t *title_16 = alloc_utf16_from_8((char *)title, 0);
109 h_wnd_ = ::CreateWindowExW(extended_style, /* window extended style */
110 s_windowClassName, /* pointer to registered class name */
111 title_16, /* pointer to window name */
112 style, /* window style */
113 win_rect.left, /* horizontal position of window */
114 win_rect.top, /* vertical position of window */
115 win_rect.right - win_rect.left, /* window width */
116 win_rect.bottom - win_rect.top, /* window height */
117 parent_window_hwnd_, /* handle to parent or owner window */
118 0, /* handle to menu or child-window identifier */
119 ::GetModuleHandle(0), /* handle to application instance */
120 0); /* pointer to window-creation data */
121 free(title_16);
122
123 if (h_wnd_ == nullptr) {
124 return;
125 }
126
127 registerWindowAppUserModelProperties();
128
129 /* Store the device context. */
130 h_DC_ = ::GetDC(h_wnd_);
131
132 if (!setDrawingContextType(type)) {
133 if (type == GHOST_kDrawingContextTypeOpenGL) {
134 const char *title = "Blender - Unsupported Graphics Card Configuration";
135 const char *text = "";
136#if defined(WIN32)
137 if (strncmp(blender::BLI_getenv("PROCESSOR_IDENTIFIER"), "ARM", 3) == 0 &&
138 strstr(blender::BLI_getenv("PROCESSOR_IDENTIFIER"), "Qualcomm") != NULL)
139 {
140 text =
141 "A driver with support for OpenGL 4.3 or higher is required.\n\n"
142 "Qualcomm devices require the \"OpenCL™, OpenGL®, and Vulkan® Compatibility Pack\" "
143 "from the Microsoft Store.\n\n"
144 "Devices using processors older than a Qualcomm Snapdragon 8cx Gen3 are incompatible, "
145 "but may be able to run an emulated x64 copy of Blender, such as a 3.x LTS release.";
146 }
147 else
148#endif
149 {
150 text =
151 "A graphics card and driver with support for OpenGL 4.3 or higher is "
152 "required.\n\nInstalling the latest driver for your graphics card might resolve the "
153 "issue.";
154 if (GetSystemMetrics(SM_CMONITORS) > 1) {
155 text =
156 "A graphics card and driver with support for OpenGL 4.3 or higher is "
157 "required.\n\nPlugging all monitors into your primary graphics card might resolve "
158 "this issue. Installing the latest driver for your graphics card could also help.";
159 }
160 }
161 MessageBox(h_wnd_, text, title, MB_OK | MB_ICONERROR);
162 }
163 ::ReleaseDC(h_wnd_, h_DC_);
164 ::DestroyWindow(h_wnd_);
165 h_wnd_ = nullptr;
166 return;
167 }
168
169 RegisterTouchWindow(h_wnd_, 0);
170
171 /* Register as drop-target. #OleInitialize(0) required first, done in GHOST_SystemWin32. */
172 drop_target_ = new GHOST_DropTargetWin32(this, system_);
173 ::RegisterDragDrop(h_wnd_, drop_target_);
174
175 /* Store a pointer to this class in the window structure. */
176 ::SetWindowLongPtr(h_wnd_, GWLP_USERDATA, (LONG_PTR)this);
177
178 if (!system_->window_focus_) {
179 /* If we don't want focus then lower to bottom. */
180 ::SetWindowPos(h_wnd_, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
181 }
182
183 if (parent_window) {
184 /* Release any parent capture to allow immediate interaction (#90110). */
185 ::ReleaseCapture();
186 parent_window->lostMouseCapture();
187 }
188
189 /* Show the window. */
190 int nCmdShow;
191 switch (state) {
194 nCmdShow = SW_SHOWMAXIMIZED;
195 break;
197 nCmdShow = (system_->window_focus_) ? SW_SHOWMINIMIZED : SW_SHOWMINNOACTIVE;
198 break;
200 default:
201 nCmdShow = (system_->window_focus_) ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE;
202 break;
203 }
204
205 ThemeRefresh();
206
207 ::ShowWindow(h_wnd_, nCmdShow);
208
209 /* Initialize WINTAB. */
210 if (system->getTabletAPI() != GHOST_kTabletWinPointer) {
212 }
213
214 /* Allow the showing of a progress bar on the taskbar. */
215 CoCreateInstance(
216 CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID *)&bar_);
217
218 /* Initialize Direct Manipulation. */
219 direct_manipulation_helper_ = GHOST_DirectManipulationHelper::create(h_wnd_, getDPIHint());
220
221 /* Initialize HDR info. */
223}
224
226{
227 if (!direct_manipulation_helper_) {
228 return;
229 }
230
231 direct_manipulation_helper_->update();
232}
233
235{
236 /* Only #DM_POINTERHITTEST can be the first message of input sequence of touch-pad input. */
237
238 if (!direct_manipulation_helper_) {
239 return;
240 }
241
242 UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
243 POINTER_INPUT_TYPE pointerType;
244 if (GetPointerType(pointerId, &pointerType) && pointerType == PT_TOUCHPAD) {
245 direct_manipulation_helper_->onPointerHitTest(pointerId);
246 }
247}
248
250{
251 if (!direct_manipulation_helper_) {
252 return {0, 0, 0};
253 }
254
255 return direct_manipulation_helper_->getTrackpadInfo();
256}
257
259{
260 if (h_wnd_) {
261 unregisterWindowAppUserModelProperties();
262 }
263
264 if (bar_) {
265 bar_->SetProgressState(h_wnd_, TBPF_NOPROGRESS);
266 bar_->Release();
267 bar_ = nullptr;
268 }
269
270 closeWintab();
271
272 if (user32_) {
273 FreeLibrary(user32_);
274 user32_ = nullptr;
275 }
276
277 if (custom_cursor_) {
278 DestroyCursor(custom_cursor_);
279 custom_cursor_ = nullptr;
280 }
281
282 if (h_wnd_ != nullptr && h_DC_ != nullptr && releaseNativeHandles()) {
283 ::ReleaseDC(h_wnd_, h_DC_);
284 h_DC_ = nullptr;
285 }
286
287 if (h_wnd_) {
288 /* If this window is referenced by others as parent, clear that relation or windows will free
289 * the handle while we still reference it. */
290 for (GHOST_IWindow *iter_win : system_->getWindowManager()->getWindows()) {
291 GHOST_WindowWin32 *iter_winwin = (GHOST_WindowWin32 *)iter_win;
292 if (iter_winwin->parent_window_hwnd_ == h_wnd_) {
293 ::SetWindowLongPtr(iter_winwin->h_wnd_, GWLP_HWNDPARENT, 0);
294 iter_winwin->parent_window_hwnd_ = 0;
295 }
296 }
297
298 if (drop_target_) {
299 /* Disable DragDrop. */
300 RevokeDragDrop(h_wnd_);
301 /* Release our reference of the DropTarget and it will delete itself eventually. */
302 drop_target_->Release();
303 drop_target_ = nullptr;
304 }
305 ::SetWindowLongPtr(h_wnd_, GWLP_USERDATA, 0);
306 ::DestroyWindow(h_wnd_);
307 h_wnd_ = 0;
308 }
309
310 delete direct_manipulation_helper_;
311 direct_manipulation_helper_ = nullptr;
312}
313
315 DWORD dwStyle,
316 DWORD dwExStyle)
317{
318 /* Get Details of the closest monitor. */
319 HMONITOR hmonitor = MonitorFromRect(win_rect, MONITOR_DEFAULTTONEAREST);
320 MONITORINFOEX monitor;
321 monitor.cbSize = sizeof(MONITORINFOEX);
322 monitor.dwFlags = 0;
323 GetMonitorInfo(hmonitor, &monitor);
324
325 /* Constrain requested size and position to fit within this monitor. */
326 LONG width = std::min(monitor.rcWork.right - monitor.rcWork.left,
327 win_rect->right - win_rect->left);
328 LONG height = std::min(monitor.rcWork.bottom - monitor.rcWork.top,
329 win_rect->bottom - win_rect->top);
330 win_rect->left = std::min(std::max(monitor.rcWork.left, win_rect->left),
331 monitor.rcWork.right - width);
332 win_rect->right = win_rect->left + width;
333 win_rect->top = std::min(std::max(monitor.rcWork.top, win_rect->top),
334 monitor.rcWork.bottom - height);
335 win_rect->bottom = win_rect->top + height;
336
337 /* With Windows 10 and newer we can adjust for chrome that differs with DPI and scale. */
338 GHOST_WIN32_AdjustWindowRectExForDpi fpAdjustWindowRectExForDpi = nullptr;
339 if (user32_) {
340 fpAdjustWindowRectExForDpi = (GHOST_WIN32_AdjustWindowRectExForDpi)::GetProcAddress(
341 user32_, "AdjustWindowRectExForDpi");
342 }
343
344 /* Adjust to allow for caption, borders, shadows, scaling, etc. Resulting values can be
345 * correctly outside of monitor bounds. NOTE: You cannot specify #WS_OVERLAPPED when calling. */
346 if (fpAdjustWindowRectExForDpi) {
347 UINT dpiX, dpiY;
348 GetDpiForMonitor(hmonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
349 fpAdjustWindowRectExForDpi(win_rect, dwStyle & ~WS_OVERLAPPED, FALSE, dwExStyle, dpiX);
350 }
351 else {
352 AdjustWindowRectEx(win_rect, dwStyle & ~WS_OVERLAPPED, FALSE, dwExStyle);
353 }
354
355 /* But never allow a top position that can hide part of the title bar. */
356 win_rect->top = std::max(monitor.rcWork.top, win_rect->top);
357}
358
360{
361 return GHOST_Window::getValid() && h_wnd_ != 0 && h_DC_ != 0;
362}
363
365{
366 return h_wnd_;
367}
368
370{
371 return (void *)h_wnd_;
372}
373
374void GHOST_WindowWin32::setTitle(const char *title)
375{
376 wchar_t *title_16 = alloc_utf16_from_8((char *)title, 0);
377 ::SetWindowTextW(h_wnd_, (wchar_t *)title_16);
378 free(title_16);
379}
380
382{
383 std::wstring wtitle(::GetWindowTextLengthW(h_wnd_) + 1, L'\0');
384 ::GetWindowTextW(h_wnd_, &wtitle[0], wtitle.capacity());
385
386 std::string title(count_utf_8_from_16(wtitle.c_str()) + 1, '\0');
387 conv_utf_16_to_8(wtitle.c_str(), &title[0], title.capacity());
388
389 return title;
390}
391
393{
394 /* DWMWINDOWATTRIBUTE::DWMWA_CAPTION_COLOR */
395 constexpr DWORD caption_color_attr = 35;
396
399 const COLORREF colorref = RGB(
400 char(color[0] * 255.0f), char(color[1] * 255.0f), char(color[2] * 255.0f));
401 if (!SUCCEEDED(DwmSetWindowAttribute(h_wnd_, caption_color_attr, &colorref, sizeof(colorref))))
402 {
403 return GHOST_kFailure;
404 }
405 }
406 return GHOST_kSuccess;
407}
408
410{
411 RECT rect;
412 ::GetWindowRect(h_wnd_, &rect);
413 bounds.b_ = rect.bottom;
414 bounds.l_ = rect.left;
415 bounds.r_ = rect.right;
416 bounds.t_ = rect.top;
417}
418
420{
421 RECT rect;
422 POINT coord;
423 if (!IsIconic(h_wnd_)) {
424 ::GetClientRect(h_wnd_, &rect);
425
426 coord.x = rect.left;
427 coord.y = rect.top;
428 ::ClientToScreen(h_wnd_, &coord);
429
430 bounds.l_ = coord.x;
431 bounds.t_ = coord.y;
432
433 coord.x = rect.right;
434 coord.y = rect.bottom;
435 ::ClientToScreen(h_wnd_, &coord);
436
437 bounds.r_ = coord.x;
438 bounds.b_ = coord.y;
439 }
440 else {
441 bounds.b_ = 0;
442 bounds.l_ = 0;
443 bounds.r_ = 0;
444 bounds.t_ = 0;
445 }
446}
447
449{
450 GHOST_TSuccess success;
451 GHOST_Rect cBnds, wBnds;
452 getClientBounds(cBnds);
453 if (cBnds.getWidth() != int32_t(width)) {
454 getWindowBounds(wBnds);
455 int cx = wBnds.getWidth() + width - cBnds.getWidth();
456 int cy = wBnds.getHeight();
457 success = ::SetWindowPos(h_wnd_, HWND_TOP, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER) ?
460 }
461 else {
462 success = GHOST_kSuccess;
463 }
464 return success;
465}
466
468{
469 GHOST_TSuccess success;
470 GHOST_Rect cBnds, wBnds;
471 getClientBounds(cBnds);
472 if (cBnds.getHeight() != int32_t(height)) {
473 getWindowBounds(wBnds);
474 int cx = wBnds.getWidth();
475 int cy = wBnds.getHeight() + height - cBnds.getHeight();
476 success = ::SetWindowPos(h_wnd_, HWND_TOP, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER) ?
479 }
480 else {
481 success = GHOST_kSuccess;
482 }
483 return success;
484}
485
486GHOST_TSuccess GHOST_WindowWin32::setClientSize(uint32_t width, uint32_t height)
487{
488 GHOST_TSuccess success;
489 GHOST_Rect cBnds, wBnds;
490 getClientBounds(cBnds);
491 if ((cBnds.getWidth() != int32_t(width)) || (cBnds.getHeight() != int32_t(height))) {
492 getWindowBounds(wBnds);
493 int cx = wBnds.getWidth() + width - cBnds.getWidth();
494 int cy = wBnds.getHeight() + height - cBnds.getHeight();
495 success = ::SetWindowPos(h_wnd_, HWND_TOP, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER) ?
498 }
499 else {
500 success = GHOST_kSuccess;
501 }
502 return success;
503}
504
506{
507 if (::IsIconic(h_wnd_)) {
509 }
510 else if (::IsZoomed(h_wnd_)) {
511 LONG_PTR result = ::GetWindowLongPtr(h_wnd_, GWL_STYLE);
512 return (result & WS_CAPTION) ? GHOST_kWindowStateMaximized : GHOST_kWindowStateFullScreen;
513 }
515}
516
518 int32_t inY,
519 int32_t &outX,
520 int32_t &outY) const
521{
522 POINT point = {inX, inY};
523 ::ScreenToClient(h_wnd_, &point);
524 outX = point.x;
525 outY = point.y;
526}
527
529 int32_t inY,
530 int32_t &outX,
531 int32_t &outY) const
532{
533 POINT point = {inX, inY};
534 ::ClientToScreen(h_wnd_, &point);
535 outX = point.x;
536 outY = point.y;
537}
538
540{
541 GHOST_TWindowState curstate = getState();
542 LONG_PTR style = GetWindowLongPtr(h_wnd_, GWL_STYLE) | WS_CAPTION;
543 WINDOWPLACEMENT wp;
544 wp.length = sizeof(WINDOWPLACEMENT);
545 ::GetWindowPlacement(h_wnd_, &wp);
546
547 switch (state) {
549 wp.showCmd = SW_MINIMIZE;
550 break;
552 wp.showCmd = SW_SHOWMAXIMIZED;
553 break;
555 if (curstate != state && curstate != GHOST_kWindowStateMinimized) {
556 normal_state_ = curstate;
557 }
558 wp.showCmd = SW_SHOWMAXIMIZED;
559 wp.ptMaxPosition.x = 0;
560 wp.ptMaxPosition.y = 0;
561 style &= ~(WS_CAPTION | WS_MAXIMIZE);
562 break;
564 default:
565 if (curstate == GHOST_kWindowStateFullScreen && normal_state_ == GHOST_kWindowStateMaximized)
566 {
567 wp.showCmd = SW_SHOWMAXIMIZED;
568 normal_state_ = GHOST_kWindowStateNormal;
569 }
570 else {
571 wp.showCmd = SW_SHOWNORMAL;
572 }
573 break;
574 }
575 ::SetWindowLongPtr(h_wnd_, GWL_STYLE, style);
576 /* #SetWindowLongPtr Docs:
577 * Frame changes not visible until #SetWindowPos with #SWP_FRAMECHANGED. */
578 ::SetWindowPos(h_wnd_, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
579 return ::SetWindowPlacement(h_wnd_, &wp) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
580}
581
583{
584 HWND hWndInsertAfter, hWndToRaise;
585
586 if (order == GHOST_kWindowOrderBottom) {
587 hWndInsertAfter = HWND_BOTTOM;
588 hWndToRaise = ::GetWindow(h_wnd_, GW_HWNDNEXT); /* the window to raise */
589 }
590 else {
593 }
594 hWndInsertAfter = HWND_TOP;
595 hWndToRaise = nullptr;
596 }
597
598 if (::SetWindowPos(h_wnd_, hWndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE) == FALSE) {
599 return GHOST_kFailure;
600 }
601
602 if (hWndToRaise &&
603 ::SetWindowPos(hWndToRaise, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE) == FALSE)
604 {
605 return GHOST_kFailure;
606 }
607 return GHOST_kSuccess;
608}
609
611{
612 GHOST_TSuccess success;
613 if (h_wnd_) {
614 success = ::InvalidateRect(h_wnd_, 0, FALSE) != 0 ? GHOST_kSuccess : GHOST_kFailure;
615 }
616 else {
617 success = GHOST_kFailure;
618 }
619 return success;
620}
621
622GHOST_Context *GHOST_WindowWin32::newDrawingContext(GHOST_TDrawingContextType type)
623{
624 switch (type) {
625#ifdef WITH_VULKAN_BACKEND
626 case GHOST_kDrawingContextTypeVulkan: {
627 GHOST_Context *context = new GHOST_ContextVK(
628 want_context_params_, h_wnd_, 1, 1, preferred_device_, &hdr_info_);
629 if (context->initializeDrawingContext()) {
630 return context;
631 }
632 delete context;
633 return nullptr;
634 }
635#endif
636
637#ifdef WITH_OPENGL_BACKEND
638 case GHOST_kDrawingContextTypeOpenGL: {
639 for (int minor = 6; minor >= 3; --minor) {
640 GHOST_Context *context = new GHOST_ContextWGL(
642 false,
643 h_wnd_,
644 h_DC_,
645 WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
646 4,
647 minor,
648 (want_context_params_.is_debug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
650
651 if (context->initializeDrawingContext()) {
652 return context;
653 }
654 delete context;
655 }
656 return nullptr;
657 }
658#endif
659
660 case GHOST_kDrawingContextTypeD3D: {
661 GHOST_Context *context = new GHOST_ContextD3D(want_context_params_, h_wnd_);
662
663 if (context->initializeDrawingContext()) {
664 return context;
665 }
666 delete context;
667 return nullptr;
668 }
669
670 default:
671 /* Unsupported backend. */
672 return nullptr;
673 }
674}
675
677{
678 if (has_mouse_captured_) {
679 has_grab_mouse_ = false;
680 n_pressed_buttons_ = 0;
681 has_mouse_captured_ = false;
682 }
683}
684
686{
687 return is_dialog_;
688}
689
691{
692 switch (event) {
693 case MousePressed:
694 n_pressed_buttons_++;
695 break;
696 case MouseReleased:
697 if (n_pressed_buttons_) {
698 n_pressed_buttons_--;
699 }
700 break;
701 case OperatorGrab:
702 has_grab_mouse_ = true;
703 break;
704 case OperatorUngrab:
705 has_grab_mouse_ = false;
706 break;
707 }
708
709 if (!n_pressed_buttons_ && !has_grab_mouse_ && has_mouse_captured_) {
710 ::ReleaseCapture();
711 has_mouse_captured_ = false;
712 }
713 else if ((n_pressed_buttons_ || has_grab_mouse_) && !has_mouse_captured_) {
714 ::SetCapture(h_wnd_);
715 has_mouse_captured_ = true;
716 }
717}
718
720{
721 /* Convert GHOST cursor to Windows OEM cursor. */
722 HANDLE cursor = nullptr;
723 uint32_t flags = LR_SHARED | LR_DEFAULTSIZE;
724 int cx = 0, cy = 0;
725
726 switch (shape) {
728 if (custom_cursor_) {
729 return custom_cursor_;
730 }
731 else {
732 return nullptr;
733 }
735 cursor = ::LoadImage(nullptr, IDC_SIZEALL, IMAGE_CURSOR, cx, cy, flags);
736 break;
738 cursor = ::LoadImage(nullptr, IDC_HELP, IMAGE_CURSOR, cx, cy, flags);
739 break; /* Arrow and question mark */
741 cursor = ::LoadImage(nullptr, IDC_WAIT, IMAGE_CURSOR, cx, cy, flags);
742 break; /* Hourglass */
744 cursor = ::LoadImage(nullptr, IDC_IBEAM, IMAGE_CURSOR, cx, cy, flags);
745 break; /* I-beam */
747 cursor = ::LoadImage(nullptr, IDC_UPARROW, IMAGE_CURSOR, cx, cy, flags);
748 break; /* Vertical arrow */
750 cursor = ::LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, cx, cy, flags);
751 break;
753 cursor = ::LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, cx, cy, flags);
754 break;
756 cursor = ::LoadImage(nullptr, IDC_SIZENWSE, IMAGE_CURSOR, cx, cy, flags);
757 break;
759 cursor = ::LoadImage(nullptr, IDC_SIZENESW, IMAGE_CURSOR, cx, cy, flags);
760 break;
762 cursor = nullptr;
763 break;
764 default:
765 return nullptr;
766 }
767
768 if (cursor == nullptr) {
769 cursor = ::LoadImage(nullptr, IDC_ARROW, IMAGE_CURSOR, cx, cy, flags);
770 }
771
772 return (HCURSOR)cursor;
773}
774
776{
777 if (!visible) {
778 while (::ShowCursor(FALSE) >= 0) {
779 /* Pass. */
780 }
781 }
782 else {
783 while (::ShowCursor(TRUE) < 0) {
784 /* Pass. */
785 }
786 }
787
788 HCURSOR cursor = getStandardCursor(shape);
789 if (cursor == nullptr) {
791 }
792 ::SetCursor(cursor);
793}
794
795GHOST_TSuccess GHOST_WindowWin32::setWindowCursorVisibility(bool visible)
796{
797 if (::GetForegroundWindow() == h_wnd_) {
798 loadCursor(visible, getCursorShape());
799 }
800
801 return GHOST_kSuccess;
802}
803
804GHOST_TSuccess GHOST_WindowWin32::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
805{
806 if (mode != GHOST_kGrabDisable) {
807 if (mode != GHOST_kGrabNormal) {
808 system_->getCursorPosition(cursor_grab_init_pos_[0], cursor_grab_init_pos_[1]);
809 setCursorGrabAccum(0, 0);
810
811 if (mode == GHOST_kGrabHide) {
812 setWindowCursorVisibility(false);
813 }
814 }
816 }
817 else {
819 system_->setCursorPosition(cursor_grab_init_pos_[0], cursor_grab_init_pos_[1]);
820 setWindowCursorVisibility(true);
821 }
823 /* Use to generate a mouse move event, otherwise the last event
824 * blender gets can be outside the screen causing menus not to show
825 * properly unless the user moves the mouse. */
826 int32_t pos[2];
827 system_->getCursorPosition(pos[0], pos[1]);
828 system_->setCursorPosition(pos[0], pos[1]);
829 }
830
831 /* Almost works without but important otherwise the mouse GHOST location
832 * can be incorrect on exit. */
833 setCursorGrabAccum(0, 0);
834 cursor_grab_bounds_.l_ = cursor_grab_bounds_.r_ = -1; /* disable */
836 }
837
838 return GHOST_kSuccess;
839}
840
841GHOST_TSuccess GHOST_WindowWin32::setWindowCursorShape(GHOST_TStandardCursor cursor_shape)
842{
843 if (::GetForegroundWindow() == h_wnd_) {
844 loadCursor(getCursorVisibility(), cursor_shape);
845 }
846
847 return GHOST_kSuccess;
848}
849
850GHOST_TSuccess GHOST_WindowWin32::hasCursorShape(GHOST_TStandardCursor cursor_shape)
851{
852 return (getStandardCursor(cursor_shape)) ? GHOST_kSuccess : GHOST_kFailure;
853}
854
856 std::vector<GHOST_PointerInfoWin32> &outPointerInfo, WPARAM wParam, LPARAM /*lParam*/)
857{
858 int32_t pointerId = GET_POINTERID_WPARAM(wParam);
859 int32_t isPrimary = IS_POINTER_PRIMARY_WPARAM(wParam);
861 uint32_t outCount = 0;
862
863 if (!(GetPointerPenInfoHistory(pointerId, &outCount, nullptr))) {
864 return GHOST_kFailure;
865 }
866
867 std::vector<POINTER_PEN_INFO> pointerPenInfo(outCount);
868 outPointerInfo.resize(outCount);
869
870 if (!(GetPointerPenInfoHistory(pointerId, &outCount, pointerPenInfo.data()))) {
871 return GHOST_kFailure;
872 }
873
874 for (uint32_t i = 0; i < outCount; i++) {
875 POINTER_INFO pointerApiInfo = pointerPenInfo[i].pointerInfo;
876 /* Obtain the basic information from the event. */
877 outPointerInfo[i].pointerId = pointerId;
878 outPointerInfo[i].isPrimary = isPrimary;
879
880 switch (pointerApiInfo.ButtonChangeType) {
881 case POINTER_CHANGE_FIRSTBUTTON_DOWN:
882 case POINTER_CHANGE_FIRSTBUTTON_UP:
883 outPointerInfo[i].buttonMask = GHOST_kButtonMaskLeft;
884 break;
885 case POINTER_CHANGE_SECONDBUTTON_DOWN:
886 case POINTER_CHANGE_SECONDBUTTON_UP:
887 outPointerInfo[i].buttonMask = GHOST_kButtonMaskRight;
888 break;
889 case POINTER_CHANGE_THIRDBUTTON_DOWN:
890 case POINTER_CHANGE_THIRDBUTTON_UP:
891 outPointerInfo[i].buttonMask = GHOST_kButtonMaskMiddle;
892 break;
893 case POINTER_CHANGE_FOURTHBUTTON_DOWN:
894 case POINTER_CHANGE_FOURTHBUTTON_UP:
895 outPointerInfo[i].buttonMask = GHOST_kButtonMaskButton4;
896 break;
897 case POINTER_CHANGE_FIFTHBUTTON_DOWN:
898 case POINTER_CHANGE_FIFTHBUTTON_UP:
899 outPointerInfo[i].buttonMask = GHOST_kButtonMaskButton5;
900 break;
901 default:
902 break;
903 }
904
905 outPointerInfo[i].pixelLocation = pointerApiInfo.ptPixelLocation;
906 outPointerInfo[i].tabletData.Active = GHOST_kTabletModeStylus;
907 outPointerInfo[i].tabletData.Pressure = 1.0f;
908 outPointerInfo[i].tabletData.Xtilt = 0.0f;
909 outPointerInfo[i].tabletData.Ytilt = 0.0f;
910 outPointerInfo[i].time = system->performanceCounterToMillis(pointerApiInfo.PerformanceCount);
911
912 if (pointerPenInfo[i].penMask & PEN_MASK_PRESSURE) {
913 outPointerInfo[i].tabletData.Pressure = pointerPenInfo[i].pressure / 1024.0f;
914 }
915
916 if (pointerPenInfo[i].penFlags & PEN_FLAG_ERASER) {
917 outPointerInfo[i].tabletData.Active = GHOST_kTabletModeEraser;
918 }
919
920 if (pointerPenInfo[i].penMask & PEN_MASK_TILT_X) {
921 /* Input value is a range of -90 to +90, with a positive value
922 * indicating a tilt to the right. Convert to what Blender
923 * expects: -1.0f (left) to +1.0f (right). */
924 outPointerInfo[i].tabletData.Xtilt = std::clamp(
925 pointerPenInfo[i].tiltX / 90.0f, -1.0f, 1.0f);
926 }
927
928 if (pointerPenInfo[i].penMask & PEN_MASK_TILT_Y) {
929 /* Input value is a range of -90 to +90, with a positive value
930 * indicating a tilt toward the user. Convert to what Blender
931 * expects: -1.0f (away from user) to +1.0f (toward user). */
932 outPointerInfo[i].tabletData.Ytilt = std::clamp(
933 pointerPenInfo[i].tiltY / 90.0f, -1.0f, 1.0f);
934 }
935 }
936
937 if (!outPointerInfo.empty()) {
938 last_pointer_tablet_data_ = outPointerInfo.back().tabletData;
939 }
940
941 return GHOST_kSuccess;
942}
943
945{
946 last_pointer_tablet_data_ = GHOST_TABLET_DATA_NONE;
947}
948
950{
951 return wintab_;
952}
953
955{
956 if (!wintab_) {
957 WINTAB_PRINTF("Loading Wintab for window %p\n", h_wnd_);
958 if ((wintab_ = GHOST_Wintab::loadWintab(h_wnd_))) {
959 if (enable) {
960 wintab_->enable();
961
962 /* Focus Wintab if cursor is inside this window. This ensures Wintab is enabled when the
963 * tablet is used to change the Tablet API. */
964 int32_t x, y;
965 if (system_->getCursorPosition(x, y)) {
966 GHOST_Rect rect;
967 getClientBounds(rect);
968
969 if (rect.isInside(x, y)) {
970 wintab_->gainFocus();
971 }
972 }
973 }
974 }
975 }
976}
977
979{
980 WINTAB_PRINTF("Closing Wintab for window %p\n", h_wnd_);
981 delete wintab_;
982 wintab_ = nullptr;
983}
984
986{
987 if (system_->getTabletAPI() == api) {
988 return true;
989 }
990 else if (system_->getTabletAPI() == GHOST_kTabletAutomatic) {
991 if (wintab_ && wintab_->devicesPresent()) {
992 return api == GHOST_kTabletWintab;
993 }
994 else {
995 return api == GHOST_kTabletWinPointer;
996 }
997 }
998 else {
999 return false;
1000 }
1001}
1002
1004{
1006 return wintab_ ? wintab_->getLastTabletData() : GHOST_TABLET_DATA_NONE;
1007 }
1008 else {
1009 return last_pointer_tablet_data_;
1010 }
1011}
1012
1014{
1015 DWORD lightMode;
1016 DWORD pcbData = sizeof(lightMode);
1017 if (RegGetValueW(HKEY_CURRENT_USER,
1018 L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\\",
1019 L"AppsUseLightTheme",
1020 RRF_RT_REG_DWORD,
1021 nullptr,
1022 &lightMode,
1023 &pcbData) == ERROR_SUCCESS)
1024 {
1025 BOOL DarkMode = !lightMode;
1026
1027 /* `20 == DWMWA_USE_IMMERSIVE_DARK_MODE` in Windows 11 SDK.
1028 * This value was undocumented for Windows 10 versions 2004 and later,
1029 * supported for Windows 11 Build 22000 and later. */
1030 DwmSetWindowAttribute(this->h_wnd_, 20, &DarkMode, sizeof(DarkMode));
1031 }
1032}
1033
1035{
1036 if (direct_manipulation_helper_) {
1037 direct_manipulation_helper_->setDPI(getDPIHint());
1038 }
1039}
1040
1042{
1043 if (user32_ && system_->native_pixel_) {
1044 GHOST_WIN32_GetDpiForWindow fpGetDpiForWindow = (GHOST_WIN32_GetDpiForWindow)::GetProcAddress(
1045 user32_, "GetDpiForWindow");
1046
1047 if (fpGetDpiForWindow) {
1048 return fpGetDpiForWindow(this->h_wnd_);
1049 }
1050 }
1051
1052 return USER_DEFAULT_SCREEN_DPI;
1053}
1054
1056static uint8_t uns8ReverseBits(uint8_t ch)
1057{
1058 ch = ((ch >> 1) & 0x55) | ((ch << 1) & 0xAA);
1059 ch = ((ch >> 2) & 0x33) | ((ch << 2) & 0xCC);
1060 ch = ((ch >> 4) & 0x0F) | ((ch << 4) & 0xF0);
1061 return ch;
1062}
1063
1064#if 0 /* UNUSED */
1066static uint16_t uns16ReverseBits(uint16_t shrt)
1067{
1068 shrt = ((shrt >> 1) & 0x5555) | ((shrt << 1) & 0xAAAA);
1069 shrt = ((shrt >> 2) & 0x3333) | ((shrt << 2) & 0xCCCC);
1070 shrt = ((shrt >> 4) & 0x0F0F) | ((shrt << 4) & 0xF0F0);
1071 shrt = ((shrt >> 8) & 0x00FF) | ((shrt << 8) & 0xFF00);
1072 return shrt;
1073}
1074#endif
1075
1076GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(const uint8_t *bitmap,
1077 const uint8_t *mask,
1078 const int size[2],
1079 const int hot_spot[2],
1080 bool /*can_invert_color*/)
1081{
1082 if (mask) {
1083 /* Old 1bpp XBitMap bitmap and mask. */
1084 uint32_t andData[32];
1085 uint32_t xorData[32];
1086 uint32_t fullBitRow, fullMaskRow;
1087 int x, y, cols;
1088
1089 cols = size[0] / 8; /* Number of whole bytes per row (width of bitmap/mask). */
1090 if (size[0] % 8) {
1091 cols++;
1092 }
1093
1094 HCURSOR previous_cursor = custom_cursor_;
1095
1096 memset(&andData, 0xFF, sizeof(andData));
1097 memset(&xorData, 0, sizeof(xorData));
1098
1099 for (y = 0; y < size[1]; y++) {
1100 fullBitRow = 0;
1101 fullMaskRow = 0;
1102 for (x = cols - 1; x >= 0; x--) {
1103 fullBitRow <<= 8;
1104 fullMaskRow <<= 8;
1105 fullBitRow |= uns8ReverseBits(bitmap[cols * y + x]);
1106 fullMaskRow |= uns8ReverseBits(mask[cols * y + x]);
1107 }
1108 xorData[y] = fullBitRow & fullMaskRow;
1109 andData[y] = ~fullMaskRow;
1110 }
1111
1112 custom_cursor_ = ::CreateCursor(
1113 ::GetModuleHandle(0), hot_spot[0], hot_spot[1], 32, 32, andData, xorData);
1114
1115 if (!custom_cursor_) {
1116 return GHOST_kFailure;
1117 }
1118
1119 if (::GetForegroundWindow() == h_wnd_) {
1121 }
1122
1123 if (previous_cursor) {
1124 DestroyCursor(previous_cursor);
1125 }
1126
1127 return GHOST_kSuccess;
1128 }
1129
1130 /* RGBA bitmap, size up to 255x255. This limit may differ on other
1131 * platforms. Requesting larger does not give an error, just results
1132 * in a smaller, empty result. */
1133
1134 BITMAPV5HEADER header;
1135 memset(&header, 0, sizeof(BITMAPV5HEADER));
1136 header.bV5Size = sizeof(BITMAPV5HEADER);
1137 header.bV5Width = (LONG)size[0];
1138 header.bV5Height = (LONG)size[1];
1139 header.bV5Planes = 1;
1140 header.bV5BitCount = 32;
1141 header.bV5Compression = BI_BITFIELDS;
1142 header.bV5RedMask = 0x00FF0000;
1143 header.bV5GreenMask = 0x0000FF00;
1144 header.bV5BlueMask = 0x000000FF;
1145 header.bV5AlphaMask = 0xFF000000;
1146
1147 HDC hdc = GetDC(h_wnd_);
1148 void *bits = nullptr;
1149 HBITMAP bmp = CreateDIBSection(
1150 hdc, (BITMAPINFO *)&header, DIB_RGB_COLORS, (void **)&bits, NULL, (DWORD)0);
1151 ReleaseDC(NULL, hdc);
1152
1153 uint32_t *ptr = (uint32_t *)bits;
1154 char w = size[0];
1155 char h = size[1];
1156 for (int y = h - 1; y >= 0; y--) {
1157 for (int x = 0; x < w; x++) {
1158 int i = (y * w * 4) + (x * 4);
1159 uint32_t r = bitmap[i];
1160 uint32_t g = bitmap[i + 1];
1161 uint32_t b = bitmap[i + 2];
1162 uint32_t a = bitmap[i + 3];
1163 *ptr++ = (a << 24) | (r << 16) | (g << 8) | b;
1164 }
1165 }
1166
1167 HBITMAP empty_mask = CreateBitmap(size[0], size[1], 1, 1, NULL);
1168 ICONINFO icon_info;
1169 icon_info.fIcon = FALSE;
1170 icon_info.xHotspot = (DWORD)hot_spot[0];
1171 icon_info.yHotspot = (DWORD)hot_spot[1];
1172 icon_info.hbmMask = empty_mask;
1173 icon_info.hbmColor = bmp;
1174
1175 HCURSOR previous_cursor = custom_cursor_;
1176
1177 custom_cursor_ = CreateIconIndirect(&icon_info);
1178 DeleteObject(bmp);
1179 DeleteObject(empty_mask);
1180
1181 if (!custom_cursor_) {
1182 return GHOST_kFailure;
1183 }
1184
1185 if (::GetForegroundWindow() == h_wnd_) {
1187 }
1188
1189 if (previous_cursor) {
1190 DestroyCursor(previous_cursor);
1191 }
1192
1193 return GHOST_kSuccess;
1194}
1195
1197{
1198 /* #SetProgressValue sets state to #TBPF_NORMAL automatically. */
1199 if (bar_ && S_OK == bar_->SetProgressValue(h_wnd_, 10000 * progress, 10000)) {
1200 return GHOST_kSuccess;
1201 }
1202
1203 return GHOST_kFailure;
1204}
1205
1207{
1208 if (bar_ && S_OK == bar_->SetProgressState(h_wnd_, TBPF_NOPROGRESS)) {
1209 return GHOST_kSuccess;
1210 }
1211
1212 return GHOST_kFailure;
1213}
1214
1215#ifdef WITH_INPUT_IME
1216void GHOST_WindowWin32::beginIME(int32_t x, int32_t y, int32_t /*w*/, int32_t h, bool completed)
1217{
1218 ime_input_.BeginIME(h_wnd_, GHOST_Rect(x, y - h, x, y), completed);
1219}
1220
1221void GHOST_WindowWin32::endIME()
1222{
1223 ime_input_.EndIME(h_wnd_);
1224}
1225#endif /* WITH_INPUT_IME */
1226
1227void GHOST_WindowWin32::registerWindowAppUserModelProperties()
1228{
1229 IPropertyStore *pstore;
1230 char blender_path[MAX_PATH];
1231 wchar_t shell_command[MAX_PATH];
1232
1233 /* Find the current executable, and see if it's blender.exe if not bail out. */
1234 GetModuleFileName(0, blender_path, sizeof(blender_path));
1235 char *blender_app = strstr(blender_path, "blender.exe");
1236 if (!blender_app) {
1237 return;
1238 }
1239
1240 HRESULT hr = SHGetPropertyStoreForWindow(h_wnd_, IID_PPV_ARGS(&pstore));
1241 if (!SUCCEEDED(hr)) {
1242 return;
1243 }
1244
1245 /* Set the launcher as the shell command so the console window will not flash.
1246 * when people pin blender to the taskbar. */
1247 strcpy(blender_app, "blender-launcher.exe");
1248 wsprintfW(shell_command, L"\"%S\"", blender_path);
1249 UTF16_ENCODE(BLENDER_WIN_APPID);
1250 UTF16_ENCODE(BLENDER_WIN_APPID_FRIENDLY_NAME);
1251 PROPVARIANT propvar;
1252 hr = InitPropVariantFromString(BLENDER_WIN_APPID_16, &propvar);
1253 hr = pstore->SetValue(PKEY_AppUserModel_ID, propvar);
1254 hr = InitPropVariantFromString(shell_command, &propvar);
1255 hr = pstore->SetValue(PKEY_AppUserModel_RelaunchCommand, propvar);
1256 hr = InitPropVariantFromString(BLENDER_WIN_APPID_FRIENDLY_NAME_16, &propvar);
1257 hr = pstore->SetValue(PKEY_AppUserModel_RelaunchDisplayNameResource, propvar);
1258 pstore->Release();
1259 UTF16_UN_ENCODE(BLENDER_WIN_APPID_FRIENDLY_NAME);
1260 UTF16_UN_ENCODE(BLENDER_WIN_APPID);
1261}
1262
1263/* as per MSDN: Any property not cleared before closing the window, will be leaked and NOT be
1264 * returned to the OS. */
1265void GHOST_WindowWin32::unregisterWindowAppUserModelProperties()
1266{
1267 IPropertyStore *pstore;
1268 HRESULT hr = SHGetPropertyStoreForWindow(h_wnd_, IID_PPV_ARGS(&pstore));
1269 if (SUCCEEDED(hr)) {
1270 PROPVARIANT value;
1271 PropVariantInit(&value);
1272 pstore->SetValue(PKEY_AppUserModel_ID, value);
1273 pstore->SetValue(PKEY_AppUserModel_RelaunchCommand, value);
1274 pstore->SetValue(PKEY_AppUserModel_RelaunchDisplayNameResource, value);
1275 pstore->Release();
1276 }
1277}
1278
1279/* We call this from a few window event changes, but actually none of them immediately
1280 * respond to SDR white level changes in the system. That requires using the WinRT API,
1281 * which we don't do so far. */
1283{
1284 /* Get monitor from window. */
1285 HMONITOR hmonitor = ::MonitorFromWindow(h_wnd_, MONITOR_DEFAULTTONEAREST);
1286 if (!hmonitor) {
1287 return;
1288 }
1289
1290 MONITORINFOEXW monitor_info = {};
1291 monitor_info.cbSize = sizeof(MONITORINFOEXW);
1292 if (!::GetMonitorInfoW(hmonitor, &monitor_info)) {
1293 return;
1294 }
1295
1296 /* Get active display paths and modes. */
1297 UINT32 path_count = 0;
1298 UINT32 mode_count = 0;
1299 if (::GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &path_count, &mode_count) !=
1300 ERROR_SUCCESS)
1301 {
1302 return;
1303 }
1304
1305 std::vector<DISPLAYCONFIG_PATH_INFO> paths(path_count);
1306 std::vector<DISPLAYCONFIG_MODE_INFO> modes(mode_count);
1307 if (::QueryDisplayConfig(
1308 QDC_ONLY_ACTIVE_PATHS, &path_count, paths.data(), &mode_count, modes.data(), nullptr) !=
1309 ERROR_SUCCESS)
1310 {
1311 return;
1312 }
1313
1315
1316 /* Find the display path matching the monitor. */
1317 for (const DISPLAYCONFIG_PATH_INFO &path : paths) {
1318 DISPLAYCONFIG_SOURCE_DEVICE_NAME device_name = {};
1319 device_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME;
1320 device_name.header.size = sizeof(device_name);
1321 device_name.header.adapterId = path.sourceInfo.adapterId;
1322 device_name.header.id = path.sourceInfo.id;
1323
1324 if (::DisplayConfigGetDeviceInfo(&device_name.header) != ERROR_SUCCESS) {
1325 continue;
1326 }
1327 if (wcscmp(monitor_info.szDevice, device_name.viewGdiDeviceName) != 0) {
1328 continue;
1329 }
1330
1331 /* Query HDR status. */
1332 DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO color_info = {};
1333 color_info.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO;
1334 color_info.header.size = sizeof(color_info);
1335 color_info.header.adapterId = path.targetInfo.adapterId;
1336 color_info.header.id = path.targetInfo.id;
1337
1338 if (::DisplayConfigGetDeviceInfo(&color_info.header) == ERROR_SUCCESS) {
1339 /* This particular combination indicates HDR mode is enabled. This is undocumented but
1340 * used by WinRT. When wideColorEnforced is true we are in SDR mode with advanced color. */
1341 info.wide_gamut_enabled = color_info.advancedColorSupported &&
1342 color_info.advancedColorEnabled;
1343 info.hdr_enabled = info.wide_gamut_enabled && !color_info.wideColorEnforced;
1344 }
1345
1346 if (info.hdr_enabled) {
1347 /* Query SDR white level. */
1348 DISPLAYCONFIG_SDR_WHITE_LEVEL white_level = {};
1349 white_level.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL;
1350 white_level.header.size = sizeof(white_level);
1351 white_level.header.adapterId = path.targetInfo.adapterId;
1352 white_level.header.id = path.targetInfo.id;
1353
1354 if (::DisplayConfigGetDeviceInfo(&white_level.header) == ERROR_SUCCESS) {
1355 if (white_level.SDRWhiteLevel > 0) {
1356 /* Windows assumes 1.0 = 80 nits, so multiply by that to get the absolute
1357 * value in nits if we need it in the future. */
1358 info.sdr_white_level = static_cast<float>(white_level.SDRWhiteLevel) / 1000.0f;
1359 }
1360 }
1361 }
1362
1363 hdr_info_ = info;
1364 }
1365}
#define GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY
@ TBPF_NOPROGRESS
const GUID CLSID_TaskbarList
GHOST_TWindowState
@ GHOST_kWindowStateMinimized
@ GHOST_kWindowStateMaximized
@ GHOST_kWindowStateNormal
@ GHOST_kWindowStateFullScreen
GHOST_TStandardCursor
@ GHOST_kStandardCursorBottomLeftCorner
@ GHOST_kStandardCursorHelp
@ GHOST_kStandardCursorWait
@ GHOST_kStandardCursorTopSide
@ GHOST_kStandardCursorCustom
@ GHOST_kStandardCursorTopLeftCorner
@ GHOST_kStandardCursorMove
@ GHOST_kStandardCursorBottomRightCorner
@ GHOST_kStandardCursorDefault
@ GHOST_kStandardCursorTopRightCorner
@ GHOST_kStandardCursorText
@ GHOST_kTabletModeEraser
@ GHOST_kTabletModeStylus
GHOST_TDrawingContextType
GHOST_TWindowOrder
@ GHOST_kWindowOrderBottom
GHOST_TSuccess
@ GHOST_kFailure
@ GHOST_kSuccess
#define GHOST_WINDOW_HDR_INFO_NONE
GHOST_TGrabCursorMode
@ GHOST_kGrabDisable
@ GHOST_kGrabHide
@ GHOST_kGrabNormal
@ GHOST_kButtonMaskRight
@ GHOST_kButtonMaskButton4
@ GHOST_kButtonMaskLeft
@ GHOST_kButtonMaskButton5
@ GHOST_kButtonMaskMiddle
GHOST_TTabletAPI
@ GHOST_kTabletAutomatic
@ GHOST_kTabletWinPointer
@ GHOST_kTabletWintab
@ GHOST_kDecorationColoredTitleBar
#define GET_POINTERID_WPARAM(wParam)
static uint8_t uns8ReverseBits(uint8_t ch)
__declspec(dllexport) DWORD NvOptimusEnablement=0x00000001
UINT(API *) GHOST_WIN32_GetDpiForWindow(HWND)
BOOL(API *) GHOST_WIN32_AdjustWindowRectExForDpi(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi)
GHOST_MouseCaptureEventWin32
@ MousePressed
@ OperatorUngrab
@ MouseReleased
@ OperatorGrab
#define WINTAB_PRINTF(x,...)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
GHOST_ContextD3D(const GHOST_ContextParams &context_params, HWND hWnd)
GHOST_ContextVK(const GHOST_ContextParams &context_params, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, const GHOST_GPUDevice &preferred_device, const GHOST_WindowHDRInfo *hdr_info_=nullptr)
GHOST_ContextWGL(const GHOST_ContextParams &context_params, bool alphaBackground, HWND hWnd, HDC hDC, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
static GHOST_DirectManipulationHelper * create(HWND hWnd, uint16_t dpi)
GHOST_DropTargetWin32(GHOST_WindowWin32 *window, GHOST_SystemWin32 *system)
static GHOST_ISystem * getSystem()
virtual bool getCursorVisibility() const =0
int32_t t_
virtual bool isInside(int32_t x, int32_t y) const
int32_t r_
virtual int32_t getHeight() const
int32_t b_
int32_t l_
virtual int32_t getWidth() const
GHOST_Rect(int32_t l=0, int32_t t=0, int32_t r=0, int32_t b=0)
Definition GHOST_Rect.hh:29
uint64_t performanceCounterToMillis(__int64 perf_ticks) const
GHOST_TTabletAPI getTabletAPI()
GHOST_TSuccess setClientSize(uint32_t width, uint32_t height) override
std::string getTitle() const override
GHOST_TSuccess setState(GHOST_TWindowState state) override
uint16_t getDPIHint() override
GHOST_TTrackpadInfo getTrackpadInfo()
GHOST_TSuccess setOrder(GHOST_TWindowOrder order) override
bool getValid() const override
GHOST_TSuccess invalidate() override
GHOST_TSuccess applyWindowDecorationStyle() override
void getClientBounds(GHOST_Rect &bounds) const override
GHOST_TSuccess endProgressBar() override
void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
bool usingTabletAPI(GHOST_TTabletAPI api) const
GHOST_TSuccess getPointerInfo(std::vector< GHOST_PointerInfoWin32 > &outPointerInfo, WPARAM wParam, LPARAM lParam)
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
void setTitle(const char *title) override
void loadWintab(bool enable)
GHOST_TabletData getTabletData()
GHOST_Wintab * getWintab() const
HCURSOR getStandardCursor(GHOST_TStandardCursor shape) const
void updateMouseCapture(GHOST_MouseCaptureEventWin32 event)
GHOST_TWindowState getState() const override
GHOST_TSuccess setProgressBar(float progress) override
void onPointerHitTest(WPARAM wParam)
void getWindowBounds(GHOST_Rect &bounds) const override
void * getOSWindow() const override
GHOST_TSuccess setClientHeight(uint32_t height) override
GHOST_WindowWin32(GHOST_SystemWin32 *system, const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type, const GHOST_ContextParams &context_params, GHOST_WindowWin32 *parent_window, bool dialog, const GHOST_GPUDevice &preferred_device)
bool isDialog() const override
void loadCursor(bool visible, GHOST_TStandardCursor cursor_shape) const
GHOST_TSuccess setClientWidth(uint32_t width) override
void adjustWindowRectForClosestMonitor(LPRECT win_rect, DWORD dwStyle, DWORD dwExStyle)
GHOST_ContextParams want_context_params_
void setCursorGrabAccum(int32_t x, int32_t y)
GHOST_WindowDecorationStyleSettings window_decoration_style_settings_
GHOST_TStandardCursor getCursorShape() const override
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) override
int32_t cursor_grab_init_pos_[2]
GHOST_TSuccess releaseNativeHandles()
GHOST_TWindowDecorationStyleFlags window_decoration_style_flags_
bool getValid() const override
GHOST_Window(uint32_t width, uint32_t height, GHOST_TWindowState state, const GHOST_ContextParams &context_params, const bool exclusive=false)
GHOST_Rect cursor_grab_bounds_
GHOST_WindowHDRInfo hdr_info_
GHOST_TGrabCursorMode cursor_grab_
static GHOST_Wintab * loadWintab(HWND hwnd)
const int state
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define L
int size(const AssetLibraryReference *library_reference)
int context(const bContext *C, const char *member, bContextDataResult *result)
unsigned short uint16_t
Definition BKE_text.h:80
unsigned int uint32_t
Definition BKE_text.h:81
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)
Definition utfconv.cc:294
size_t count_utf_8_from_16(const wchar_t *string16)
Definition utfconv.cc:11
int conv_utf_16_to_8(const wchar_t *in16, char *out8, size_t size8)
Definition utfconv.cc:116
#define UTF16_ENCODE(in8str)
Definition utfconv.hh:80
#define UTF16_UN_ENCODE(in8str)
Definition utfconv.hh:84