display_server_windows.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /**************************************************************************/
  2. /* display_server_windows.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef DISPLAY_SERVER_WINDOWS_H
  31. #define DISPLAY_SERVER_WINDOWS_H
  32. #include "crash_handler_windows.h"
  33. #include "joypad_windows.h"
  34. #include "key_mapping_windows.h"
  35. #include "tts_windows.h"
  36. #include "core/config/project_settings.h"
  37. #include "core/input/input.h"
  38. #include "core/os/os.h"
  39. #include "drivers/unix/ip_unix.h"
  40. #include "drivers/wasapi/audio_driver_wasapi.h"
  41. #include "drivers/winmidi/midi_driver_winmidi.h"
  42. #include "servers/audio_server.h"
  43. #include "servers/display_server.h"
  44. #include "servers/rendering/renderer_compositor.h"
  45. #include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
  46. #include "servers/rendering_server.h"
  47. #ifdef XAUDIO2_ENABLED
  48. #include "drivers/xaudio2/audio_driver_xaudio2.h"
  49. #endif
  50. #if defined(RD_ENABLED)
  51. #include "servers/rendering/rendering_device.h"
  52. #endif
  53. #if defined(GLES3_ENABLED)
  54. #include "gl_manager_windows_angle.h"
  55. #include "gl_manager_windows_native.h"
  56. #endif // GLES3_ENABLED
  57. #include "native_menu_windows.h"
  58. #include <io.h>
  59. #include <stdio.h>
  60. #define WIN32_LEAN_AND_MEAN
  61. #include <windows.h>
  62. #include <windowsx.h>
  63. // WinTab API
  64. #define WT_PACKET 0x7FF0
  65. #define WT_PROXIMITY 0x7FF5
  66. #define WT_INFOCHANGE 0x7FF6
  67. #define WT_CSRCHANGE 0x7FF7
  68. #define WTI_DEFSYSCTX 4
  69. #define WTI_DEVICES 100
  70. #define DVC_NPRESSURE 15
  71. #define DVC_TPRESSURE 16
  72. #define DVC_ORIENTATION 17
  73. #define DVC_ROTATION 18
  74. #define CXO_MESSAGES 0x0004
  75. #define PK_STATUS 0x0002
  76. #define PK_NORMAL_PRESSURE 0x0400
  77. #define PK_TANGENT_PRESSURE 0x0800
  78. #define PK_ORIENTATION 0x1000
  79. #define TPS_INVERT 0x0010 /* 1.1 */
  80. typedef struct tagLOGCONTEXTW {
  81. WCHAR lcName[40];
  82. UINT lcOptions;
  83. UINT lcStatus;
  84. UINT lcLocks;
  85. UINT lcMsgBase;
  86. UINT lcDevice;
  87. UINT lcPktRate;
  88. DWORD lcPktData;
  89. DWORD lcPktMode;
  90. DWORD lcMoveMask;
  91. DWORD lcBtnDnMask;
  92. DWORD lcBtnUpMask;
  93. LONG lcInOrgX;
  94. LONG lcInOrgY;
  95. LONG lcInOrgZ;
  96. LONG lcInExtX;
  97. LONG lcInExtY;
  98. LONG lcInExtZ;
  99. LONG lcOutOrgX;
  100. LONG lcOutOrgY;
  101. LONG lcOutOrgZ;
  102. LONG lcOutExtX;
  103. LONG lcOutExtY;
  104. LONG lcOutExtZ;
  105. DWORD lcSensX;
  106. DWORD lcSensY;
  107. DWORD lcSensZ;
  108. BOOL lcSysMode;
  109. int lcSysOrgX;
  110. int lcSysOrgY;
  111. int lcSysExtX;
  112. int lcSysExtY;
  113. DWORD lcSysSensX;
  114. DWORD lcSysSensY;
  115. } LOGCONTEXTW;
  116. typedef struct tagAXIS {
  117. LONG axMin;
  118. LONG axMax;
  119. UINT axUnits;
  120. DWORD axResolution;
  121. } AXIS;
  122. typedef struct tagORIENTATION {
  123. int orAzimuth;
  124. int orAltitude;
  125. int orTwist;
  126. } ORIENTATION;
  127. typedef struct tagPACKET {
  128. int pkStatus;
  129. int pkNormalPressure;
  130. int pkTangentPressure;
  131. ORIENTATION pkOrientation;
  132. } PACKET;
  133. typedef HANDLE(WINAPI *WTOpenPtr)(HWND p_window, LOGCONTEXTW *p_ctx, BOOL p_enable);
  134. typedef BOOL(WINAPI *WTClosePtr)(HANDLE p_ctx);
  135. typedef UINT(WINAPI *WTInfoPtr)(UINT p_category, UINT p_index, LPVOID p_output);
  136. typedef BOOL(WINAPI *WTPacketPtr)(HANDLE p_ctx, UINT p_param, LPVOID p_packets);
  137. typedef BOOL(WINAPI *WTEnablePtr)(HANDLE p_ctx, BOOL p_enable);
  138. enum PreferredAppMode {
  139. APPMODE_DEFAULT = 0,
  140. APPMODE_ALLOWDARK = 1,
  141. APPMODE_FORCEDARK = 2,
  142. APPMODE_FORCELIGHT = 3,
  143. APPMODE_MAX = 4
  144. };
  145. typedef const char *(CDECL *WineGetVersionPtr)(void);
  146. typedef bool(WINAPI *ShouldAppsUseDarkModePtr)();
  147. typedef DWORD(WINAPI *GetImmersiveColorFromColorSetExPtr)(UINT dwImmersiveColorSet, UINT dwImmersiveColorType, bool bIgnoreHighContrast, UINT dwHighContrastCacheMode);
  148. typedef int(WINAPI *GetImmersiveColorTypeFromNamePtr)(const WCHAR *name);
  149. typedef int(WINAPI *GetImmersiveUserColorSetPreferencePtr)(bool bForceCheckRegistry, bool bSkipCheckOnFail);
  150. typedef HRESULT(WINAPI *RtlGetVersionPtr)(OSVERSIONINFOW *lpVersionInformation);
  151. typedef bool(WINAPI *AllowDarkModeForAppPtr)(bool darkMode);
  152. typedef PreferredAppMode(WINAPI *SetPreferredAppModePtr)(PreferredAppMode appMode);
  153. typedef void(WINAPI *RefreshImmersiveColorPolicyStatePtr)();
  154. typedef void(WINAPI *FlushMenuThemesPtr)();
  155. // Windows Ink API
  156. #ifndef POINTER_STRUCTURES
  157. #define POINTER_STRUCTURES
  158. typedef DWORD POINTER_INPUT_TYPE;
  159. typedef UINT32 POINTER_FLAGS;
  160. typedef UINT32 PEN_FLAGS;
  161. typedef UINT32 PEN_MASK;
  162. #ifndef PEN_FLAG_INVERTED
  163. #define PEN_FLAG_INVERTED 0x00000002
  164. #endif
  165. #ifndef PEN_FLAG_ERASER
  166. #define PEN_FLAG_ERASER 0x00000004
  167. #endif
  168. #ifndef PEN_MASK_PRESSURE
  169. #define PEN_MASK_PRESSURE 0x00000001
  170. #endif
  171. #ifndef PEN_MASK_TILT_X
  172. #define PEN_MASK_TILT_X 0x00000004
  173. #endif
  174. #ifndef PEN_MASK_TILT_Y
  175. #define PEN_MASK_TILT_Y 0x00000008
  176. #endif
  177. #ifndef POINTER_MESSAGE_FLAG_FIRSTBUTTON
  178. #define POINTER_MESSAGE_FLAG_FIRSTBUTTON 0x00000010
  179. #endif
  180. #ifndef POINTER_MESSAGE_FLAG_SECONDBUTTON
  181. #define POINTER_MESSAGE_FLAG_SECONDBUTTON 0x00000020
  182. #endif
  183. #ifndef POINTER_MESSAGE_FLAG_THIRDBUTTON
  184. #define POINTER_MESSAGE_FLAG_THIRDBUTTON 0x00000040
  185. #endif
  186. #ifndef POINTER_MESSAGE_FLAG_FOURTHBUTTON
  187. #define POINTER_MESSAGE_FLAG_FOURTHBUTTON 0x00000080
  188. #endif
  189. #ifndef POINTER_MESSAGE_FLAG_FIFTHBUTTON
  190. #define POINTER_MESSAGE_FLAG_FIFTHBUTTON 0x00000100
  191. #endif
  192. #ifndef IS_POINTER_FLAG_SET_WPARAM
  193. #define IS_POINTER_FLAG_SET_WPARAM(wParam, flag) (((DWORD)HIWORD(wParam) & (flag)) == (flag))
  194. #endif
  195. #ifndef IS_POINTER_FIRSTBUTTON_WPARAM
  196. #define IS_POINTER_FIRSTBUTTON_WPARAM(wParam) IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FIRSTBUTTON)
  197. #endif
  198. #ifndef IS_POINTER_SECONDBUTTON_WPARAM
  199. #define IS_POINTER_SECONDBUTTON_WPARAM(wParam) IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_SECONDBUTTON)
  200. #endif
  201. #ifndef IS_POINTER_THIRDBUTTON_WPARAM
  202. #define IS_POINTER_THIRDBUTTON_WPARAM(wParam) IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_THIRDBUTTON)
  203. #endif
  204. #ifndef IS_POINTER_FOURTHBUTTON_WPARAM
  205. #define IS_POINTER_FOURTHBUTTON_WPARAM(wParam) IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FOURTHBUTTON)
  206. #endif
  207. #ifndef IS_POINTER_FIFTHBUTTON_WPARAM
  208. #define IS_POINTER_FIFTHBUTTON_WPARAM(wParam) IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FIFTHBUTTON)
  209. #endif
  210. #ifndef GET_POINTERID_WPARAM
  211. #define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam))
  212. #endif
  213. #if WINVER < 0x0602
  214. enum tagPOINTER_INPUT_TYPE {
  215. PT_POINTER = 0x00000001,
  216. PT_TOUCH = 0x00000002,
  217. PT_PEN = 0x00000003,
  218. PT_MOUSE = 0x00000004,
  219. PT_TOUCHPAD = 0x00000005
  220. };
  221. typedef enum tagPOINTER_BUTTON_CHANGE_TYPE {
  222. POINTER_CHANGE_NONE,
  223. POINTER_CHANGE_FIRSTBUTTON_DOWN,
  224. POINTER_CHANGE_FIRSTBUTTON_UP,
  225. POINTER_CHANGE_SECONDBUTTON_DOWN,
  226. POINTER_CHANGE_SECONDBUTTON_UP,
  227. POINTER_CHANGE_THIRDBUTTON_DOWN,
  228. POINTER_CHANGE_THIRDBUTTON_UP,
  229. POINTER_CHANGE_FOURTHBUTTON_DOWN,
  230. POINTER_CHANGE_FOURTHBUTTON_UP,
  231. POINTER_CHANGE_FIFTHBUTTON_DOWN,
  232. POINTER_CHANGE_FIFTHBUTTON_UP,
  233. } POINTER_BUTTON_CHANGE_TYPE;
  234. typedef struct tagPOINTER_INFO {
  235. POINTER_INPUT_TYPE pointerType;
  236. UINT32 pointerId;
  237. UINT32 frameId;
  238. POINTER_FLAGS pointerFlags;
  239. HANDLE sourceDevice;
  240. HWND hwndTarget;
  241. POINT ptPixelLocation;
  242. POINT ptHimetricLocation;
  243. POINT ptPixelLocationRaw;
  244. POINT ptHimetricLocationRaw;
  245. DWORD dwTime;
  246. UINT32 historyCount;
  247. INT32 InputData;
  248. DWORD dwKeyStates;
  249. UINT64 PerformanceCount;
  250. POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
  251. } POINTER_INFO;
  252. typedef struct tagPOINTER_PEN_INFO {
  253. POINTER_INFO pointerInfo;
  254. PEN_FLAGS penFlags;
  255. PEN_MASK penMask;
  256. UINT32 pressure;
  257. UINT32 rotation;
  258. INT32 tiltX;
  259. INT32 tiltY;
  260. } POINTER_PEN_INFO;
  261. #endif
  262. #endif //POINTER_STRUCTURES
  263. #ifndef WM_POINTERUPDATE
  264. #define WM_POINTERUPDATE 0x0245
  265. #endif
  266. #ifndef WM_POINTERENTER
  267. #define WM_POINTERENTER 0x0249
  268. #endif
  269. #ifndef WM_POINTERLEAVE
  270. #define WM_POINTERLEAVE 0x024A
  271. #endif
  272. #ifndef WM_POINTERDOWN
  273. #define WM_POINTERDOWN 0x0246
  274. #endif
  275. #ifndef WM_POINTERUP
  276. #define WM_POINTERUP 0x0247
  277. #endif
  278. typedef BOOL(WINAPI *GetPointerTypePtr)(uint32_t p_id, POINTER_INPUT_TYPE *p_type);
  279. typedef BOOL(WINAPI *GetPointerPenInfoPtr)(uint32_t p_id, POINTER_PEN_INFO *p_pen_info);
  280. typedef BOOL(WINAPI *LogicalToPhysicalPointForPerMonitorDPIPtr)(HWND hwnd, LPPOINT lpPoint);
  281. typedef BOOL(WINAPI *PhysicalToLogicalPointForPerMonitorDPIPtr)(HWND hwnd, LPPOINT lpPoint);
  282. typedef HRESULT(WINAPI *SHLoadIndirectStringPtr)(PCWSTR pszSource, PWSTR pszOutBuf, UINT cchOutBuf, void **ppvReserved);
  283. typedef struct {
  284. BYTE bWidth; // Width, in pixels, of the image
  285. BYTE bHeight; // Height, in pixels, of the image
  286. BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
  287. BYTE bReserved; // Reserved ( must be 0)
  288. WORD wPlanes; // Color Planes
  289. WORD wBitCount; // Bits per pixel
  290. DWORD dwBytesInRes; // How many bytes in this resource?
  291. DWORD dwImageOffset; // Where in the file is this image?
  292. } ICONDIRENTRY, *LPICONDIRENTRY;
  293. typedef struct {
  294. WORD idReserved; // Reserved (must be 0)
  295. WORD idType; // Resource Type (1 for icons)
  296. WORD idCount; // How many images?
  297. ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
  298. } ICONDIR, *LPICONDIR;
  299. typedef enum _SHC_PROCESS_DPI_AWARENESS {
  300. SHC_PROCESS_DPI_UNAWARE = 0,
  301. SHC_PROCESS_SYSTEM_DPI_AWARE = 1,
  302. SHC_PROCESS_PER_MONITOR_DPI_AWARE = 2,
  303. } SHC_PROCESS_DPI_AWARENESS;
  304. class DisplayServerWindows : public DisplayServer {
  305. // No need to register with GDCLASS, it's platform-specific and nothing is added.
  306. _THREAD_SAFE_CLASS_
  307. // UXTheme API
  308. static bool dark_title_available;
  309. static bool use_legacy_dark_mode_before_20H1;
  310. static bool ux_theme_available;
  311. static ShouldAppsUseDarkModePtr ShouldAppsUseDarkMode;
  312. static GetImmersiveColorFromColorSetExPtr GetImmersiveColorFromColorSetEx;
  313. static GetImmersiveColorTypeFromNamePtr GetImmersiveColorTypeFromName;
  314. static GetImmersiveUserColorSetPreferencePtr GetImmersiveUserColorSetPreference;
  315. // WinTab API
  316. static bool wintab_available;
  317. static WTOpenPtr wintab_WTOpen;
  318. static WTClosePtr wintab_WTClose;
  319. static WTInfoPtr wintab_WTInfo;
  320. static WTPacketPtr wintab_WTPacket;
  321. static WTEnablePtr wintab_WTEnable;
  322. // Windows Ink API
  323. static bool winink_available;
  324. static GetPointerTypePtr win8p_GetPointerType;
  325. static GetPointerPenInfoPtr win8p_GetPointerPenInfo;
  326. // DPI conversion API
  327. static LogicalToPhysicalPointForPerMonitorDPIPtr win81p_LogicalToPhysicalPointForPerMonitorDPI;
  328. static PhysicalToLogicalPointForPerMonitorDPIPtr win81p_PhysicalToLogicalPointForPerMonitorDPI;
  329. // Shell API
  330. static SHLoadIndirectStringPtr load_indirect_string;
  331. void _update_tablet_ctx(const String &p_old_driver, const String &p_new_driver);
  332. String tablet_driver;
  333. Vector<String> tablet_drivers;
  334. enum TimerID {
  335. TIMER_ID_MOVE_REDRAW = 1,
  336. TIMER_ID_WINDOW_ACTIVATION = 2,
  337. };
  338. enum {
  339. KEY_EVENT_BUFFER_SIZE = 512
  340. };
  341. struct KeyEvent {
  342. WindowID window_id;
  343. bool alt, shift, control, meta, altgr;
  344. UINT uMsg;
  345. WPARAM wParam;
  346. LPARAM lParam;
  347. };
  348. WindowID window_mouseover_id = INVALID_WINDOW_ID;
  349. KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE];
  350. int key_event_pos;
  351. bool old_invalid;
  352. int old_x, old_y;
  353. Point2i center;
  354. #if defined(GLES3_ENABLED)
  355. GLManagerANGLE_Windows *gl_manager_angle = nullptr;
  356. GLManagerNative_Windows *gl_manager_native = nullptr;
  357. #endif
  358. #if defined(RD_ENABLED)
  359. RenderingContextDriver *rendering_context = nullptr;
  360. RenderingDevice *rendering_device = nullptr;
  361. #endif
  362. RBMap<int, Vector2> touch_state;
  363. int pressrc;
  364. HINSTANCE hInstance; // Holds The Instance Of The Application
  365. String rendering_driver;
  366. bool app_focused = false;
  367. bool keep_screen_on = false;
  368. HANDLE power_request;
  369. TTS_Windows *tts = nullptr;
  370. NativeMenuWindows *native_menu = nullptr;
  371. struct WindowData {
  372. HWND hWnd;
  373. Vector<Vector2> mpath;
  374. bool create_completed = false;
  375. bool pre_fs_valid = false;
  376. RECT pre_fs_rect;
  377. bool maximized = false;
  378. bool maximized_fs = false;
  379. bool minimized = false;
  380. bool fullscreen = false;
  381. bool multiwindow_fs = false;
  382. bool borderless = false;
  383. bool resizable = true;
  384. bool window_focused = false;
  385. int activate_state = 0;
  386. bool was_maximized = false;
  387. bool always_on_top = false;
  388. bool no_focus = false;
  389. bool exclusive = false;
  390. bool context_created = false;
  391. bool mpass = false;
  392. // Used to transfer data between events using timer.
  393. WPARAM saved_wparam;
  394. LPARAM saved_lparam;
  395. // Timers.
  396. uint32_t move_timer_id = 0U;
  397. uint32_t activate_timer_id = 0U;
  398. HANDLE wtctx;
  399. LOGCONTEXTW wtlc;
  400. int min_pressure;
  401. int max_pressure;
  402. bool tilt_supported;
  403. bool pen_inverted = false;
  404. bool block_mm = false;
  405. int last_pressure_update;
  406. float last_pressure;
  407. Vector2 last_tilt;
  408. bool last_pen_inverted = false;
  409. Size2 min_size;
  410. Size2 max_size;
  411. int width = 0, height = 0;
  412. Size2 window_rect;
  413. Point2 last_pos;
  414. ObjectID instance_id;
  415. // IME
  416. HIMC im_himc;
  417. Vector2 im_position;
  418. bool ime_active = false;
  419. bool ime_in_progress = false;
  420. bool ime_suppress_next_keyup = false;
  421. bool layered_window = false;
  422. Callable rect_changed_callback;
  423. Callable event_callback;
  424. Callable input_event_callback;
  425. Callable input_text_callback;
  426. Callable drop_files_callback;
  427. WindowID transient_parent = INVALID_WINDOW_ID;
  428. HashSet<WindowID> transient_children;
  429. bool is_popup = false;
  430. Rect2i parent_safe_rect;
  431. };
  432. JoypadWindows *joypad = nullptr;
  433. HHOOK mouse_monitor = nullptr;
  434. List<WindowID> popup_list;
  435. uint64_t time_since_popup = 0;
  436. Ref<Image> icon;
  437. WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect, bool p_exclusive, WindowID p_transient_parent);
  438. WindowID window_id_counter = MAIN_WINDOW_ID;
  439. RBMap<WindowID, WindowData> windows;
  440. WindowID last_focused_window = INVALID_WINDOW_ID;
  441. WindowID last_mouse_button_down_window = INVALID_WINDOW_ID;
  442. HCURSOR hCursor;
  443. WNDPROC user_proc = nullptr;
  444. struct IndicatorData {
  445. RID menu_rid;
  446. Callable callback;
  447. };
  448. IndicatorID indicator_id_counter = 0;
  449. HashMap<IndicatorID, IndicatorData> indicators;
  450. struct FileDialogData {
  451. HWND hwnd_owner = 0;
  452. Rect2i wrect;
  453. String appid;
  454. String title;
  455. String current_directory;
  456. String root;
  457. String filename;
  458. bool show_hidden = false;
  459. DisplayServer::FileDialogMode mode = FileDialogMode::FILE_DIALOG_MODE_OPEN_ANY;
  460. Vector<String> filters;
  461. TypedArray<Dictionary> options;
  462. WindowID window_id = DisplayServer::INVALID_WINDOW_ID;
  463. Callable callback;
  464. bool options_in_cb = false;
  465. Thread listener_thread;
  466. SafeFlag close_requested;
  467. SafeFlag finished;
  468. };
  469. Mutex file_dialog_mutex;
  470. List<FileDialogData *> file_dialogs;
  471. HashMap<HWND, FileDialogData *> file_dialog_wnd;
  472. struct FileDialogCallback {
  473. Callable callback;
  474. Variant status;
  475. Variant files;
  476. Variant index;
  477. Variant options;
  478. bool opt_in_cb = false;
  479. };
  480. List<FileDialogCallback> pending_cbs;
  481. void process_file_dialog_callbacks();
  482. static void _thread_fd_monitor(void *p_ud);
  483. HashMap<int64_t, MouseButton> pointer_prev_button;
  484. HashMap<int64_t, MouseButton> pointer_button;
  485. HashMap<int64_t, LONG> pointer_down_time;
  486. HashMap<int64_t, Vector2> pointer_last_pos;
  487. void _send_window_event(const WindowData &wd, WindowEvent p_event);
  488. void _get_window_style(bool p_main_window, bool p_fullscreen, bool p_multiwindow_fs, bool p_borderless, bool p_resizable, bool p_maximized, bool p_maximized_fs, bool p_no_activate_focus, DWORD &r_style, DWORD &r_style_ex);
  489. MouseMode mouse_mode;
  490. int restore_mouse_trails = 0;
  491. bool use_raw_input = false;
  492. bool drop_events = false;
  493. bool in_dispatch_input_event = false;
  494. WNDCLASSEXW wc;
  495. HBRUSH window_bkg_brush = nullptr;
  496. uint32_t window_bkg_brush_color = 0;
  497. HCURSOR cursors[CURSOR_MAX] = { nullptr };
  498. CursorShape cursor_shape = CursorShape::CURSOR_ARROW;
  499. RBMap<CursorShape, Vector<Variant>> cursors_cache;
  500. Callable system_theme_changed;
  501. void _drag_event(WindowID p_window, float p_x, float p_y, int idx);
  502. void _touch_event(WindowID p_window, bool p_pressed, float p_x, float p_y, int idx);
  503. bool _is_always_on_top_recursive(WindowID p_window) const;
  504. void _update_window_style(WindowID p_window, bool p_repaint = true);
  505. void _update_window_mouse_passthrough(WindowID p_window);
  506. void _update_real_mouse_position(WindowID p_window);
  507. void _set_mouse_mode_impl(MouseMode p_mode);
  508. WindowID _get_focused_window_or_popup() const;
  509. void _register_raw_input_devices(WindowID p_target_window);
  510. void _process_activate_event(WindowID p_window_id);
  511. void _process_key_events();
  512. static void _dispatch_input_events(const Ref<InputEvent> &p_event);
  513. void _dispatch_input_event(const Ref<InputEvent> &p_event);
  514. LRESULT _handle_early_window_message(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  515. Point2i _get_screens_origin() const;
  516. enum class WinKeyModifierMask {
  517. ALT_GR = (1 << 1),
  518. SHIFT = (1 << 2),
  519. ALT = (1 << 3),
  520. META = (1 << 4),
  521. CTRL = (1 << 5),
  522. };
  523. BitField<WinKeyModifierMask> _get_mods() const;
  524. Error _file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback, bool p_options_in_cb);
  525. String _get_keyboard_layout_display_name(const String &p_klid) const;
  526. String _get_klid(HKL p_hkl) const;
  527. public:
  528. LRESULT WndProcFileDialog(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  529. LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  530. LRESULT MouseProc(int code, WPARAM wParam, LPARAM lParam);
  531. void popup_open(WindowID p_window);
  532. void popup_close(WindowID p_window);
  533. virtual bool has_feature(Feature p_feature) const override;
  534. virtual String get_name() const override;
  535. virtual bool tts_is_speaking() const override;
  536. virtual bool tts_is_paused() const override;
  537. virtual TypedArray<Dictionary> tts_get_voices() const override;
  538. virtual void tts_speak(const String &p_text, const String &p_voice, int p_volume = 50, float p_pitch = 1.f, float p_rate = 1.f, int p_utterance_id = 0, bool p_interrupt = false) override;
  539. virtual void tts_pause() override;
  540. virtual void tts_resume() override;
  541. virtual void tts_stop() override;
  542. virtual bool is_dark_mode_supported() const override;
  543. virtual bool is_dark_mode() const override;
  544. virtual Color get_accent_color() const override;
  545. virtual Color get_base_color() const override;
  546. virtual void set_system_theme_change_callback(const Callable &p_callable) override;
  547. virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) override;
  548. virtual Error file_dialog_with_options_show(const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, bool p_show_hidden, FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback) override;
  549. virtual void mouse_set_mode(MouseMode p_mode) override;
  550. virtual MouseMode mouse_get_mode() const override;
  551. virtual void warp_mouse(const Point2i &p_position) override;
  552. virtual Point2i mouse_get_position() const override;
  553. virtual BitField<MouseButtonMask> mouse_get_button_state() const override;
  554. virtual void clipboard_set(const String &p_text) override;
  555. virtual String clipboard_get() const override;
  556. virtual Ref<Image> clipboard_get_image() const override;
  557. virtual bool clipboard_has() const override;
  558. virtual bool clipboard_has_image() const override;
  559. virtual int get_screen_count() const override;
  560. virtual int get_primary_screen() const override;
  561. virtual int get_keyboard_focus_screen() const override;
  562. virtual Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  563. virtual Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  564. virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  565. virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  566. virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  567. virtual Color screen_get_pixel(const Point2i &p_position) const override;
  568. virtual Ref<Image> screen_get_image(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
  569. virtual void screen_set_keep_on(bool p_enable) override; //disable screensaver
  570. virtual bool screen_is_kept_on() const override;
  571. virtual Vector<DisplayServer::WindowID> get_window_list() const override;
  572. virtual WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i(), bool p_exclusive = false, WindowID p_transient_parent = INVALID_WINDOW_ID) override;
  573. virtual void show_window(WindowID p_window) override;
  574. virtual void delete_sub_window(WindowID p_window) override;
  575. virtual WindowID window_get_active_popup() const override;
  576. virtual void window_set_popup_safe_rect(WindowID p_window, const Rect2i &p_rect) override;
  577. virtual Rect2i window_get_popup_safe_rect(WindowID p_window) const override;
  578. virtual int64_t window_get_native_handle(HandleType p_handle_type, WindowID p_window = MAIN_WINDOW_ID) const override;
  579. virtual WindowID get_window_at_screen_position(const Point2i &p_position) const override;
  580. virtual void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override;
  581. virtual ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override;
  582. virtual void gl_window_make_current(DisplayServer::WindowID p_window_id) override;
  583. virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  584. virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  585. virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  586. virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  587. virtual void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override;
  588. virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override;
  589. virtual Size2i window_get_title_size(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) const override;
  590. virtual void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID) override;
  591. virtual int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override;
  592. virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override;
  593. virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override;
  594. virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override;
  595. virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override;
  596. virtual void window_set_transient(WindowID p_window, WindowID p_parent) override;
  597. virtual void window_set_exclusive(WindowID p_window, bool p_exclusive) override;
  598. virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  599. virtual Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  600. virtual void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  601. virtual Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  602. virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override;
  603. virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override;
  604. virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override;
  605. virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override;
  606. virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override;
  607. virtual bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const override;
  608. virtual void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) override;
  609. virtual bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const override;
  610. virtual void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) override;
  611. virtual void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) override;
  612. virtual bool window_is_focused(WindowID p_window = MAIN_WINDOW_ID) const override;
  613. virtual WindowID get_focused_window() const override;
  614. virtual bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const override;
  615. virtual bool can_any_window_draw() const override;
  616. virtual void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID) override;
  617. virtual void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID) override;
  618. virtual Point2i ime_get_selection() const override;
  619. virtual String ime_get_text() const override;
  620. virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override;
  621. virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
  622. virtual void cursor_set_shape(CursorShape p_shape) override;
  623. virtual CursorShape cursor_get_shape() const override;
  624. virtual void cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) override;
  625. virtual bool get_swap_cancel_ok() override;
  626. virtual void enable_for_stealing_focus(OS::ProcessID pid) override;
  627. virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) override;
  628. virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) override;
  629. virtual int keyboard_get_layout_count() const override;
  630. virtual int keyboard_get_current_layout() const override;
  631. virtual void keyboard_set_current_layout(int p_index) override;
  632. virtual String keyboard_get_layout_language(int p_index) const override;
  633. virtual String keyboard_get_layout_name(int p_index) const override;
  634. virtual Key keyboard_get_keycode_from_physical(Key p_keycode) const override;
  635. virtual Key keyboard_get_label_from_physical(Key p_keycode) const override;
  636. virtual int tablet_get_driver_count() const override;
  637. virtual String tablet_get_driver_name(int p_driver) const override;
  638. virtual String tablet_get_current_driver() const override;
  639. virtual void tablet_set_current_driver(const String &p_driver) override;
  640. virtual void process_events() override;
  641. virtual void force_process_and_drop_events() override;
  642. virtual void release_rendering_thread() override;
  643. virtual void swap_buffers() override;
  644. virtual void set_native_icon(const String &p_filename) override;
  645. virtual void set_icon(const Ref<Image> &p_icon) override;
  646. virtual IndicatorID create_status_indicator(const Ref<Texture2D> &p_icon, const String &p_tooltip, const Callable &p_callback) override;
  647. virtual void status_indicator_set_icon(IndicatorID p_id, const Ref<Texture2D> &p_icon) override;
  648. virtual void status_indicator_set_tooltip(IndicatorID p_id, const String &p_tooltip) override;
  649. virtual void status_indicator_set_menu(IndicatorID p_id, const RID &p_rid) override;
  650. virtual void status_indicator_set_callback(IndicatorID p_id, const Callable &p_callback) override;
  651. virtual Rect2 status_indicator_get_rect(IndicatorID p_id) const override;
  652. virtual void delete_status_indicator(IndicatorID p_id) override;
  653. virtual void set_context(Context p_context) override;
  654. virtual bool is_window_transparency_available() const override;
  655. static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
  656. static Vector<String> get_rendering_drivers_func();
  657. static void register_windows_driver();
  658. DisplayServerWindows(const String &p_rendering_driver, WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error);
  659. ~DisplayServerWindows();
  660. };
  661. #endif // DISPLAY_SERVER_WINDOWS_H