1 /* 2 * gdkdisplay-win32.h 3 * 4 * Copyright 2014 Chun-wei Fan <fanc999@yahoo.com.tw> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public 17 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "gdkdisplayprivate.h" 21 22 #ifndef __GDK_DISPLAY__WIN32_H__ 23 #define __GDK_DISPLAY__WIN32_H__ 24 25 #include "gdkwin32screen.h" 26 #include "gdkwin32cursor.h" 27 28 #ifdef GDK_WIN32_ENABLE_EGL 29 # include <epoxy/egl.h> 30 #endif 31 32 /* Define values used to set DPI-awareness */ 33 typedef enum _GdkWin32ProcessDpiAwareness { 34 PROCESS_DPI_UNAWARE = 0, 35 PROCESS_SYSTEM_DPI_AWARE = 1, 36 PROCESS_PER_MONITOR_DPI_AWARE = 2, 37 PROCESS_PER_MONITOR_DPI_AWARE_V2 = 3, /* Newer HiDPI type for Windows 10 1607+ */ 38 } GdkWin32ProcessDpiAwareness; 39 40 /* From https://docs.microsoft.com/en-US/windows/win32/hidpi/dpi-awareness-context */ 41 /* DPI_AWARENESS_CONTEXT is declared by DEFINE_HANDLE */ 42 #ifndef DPI_AWARENESS_CONTEXT_UNAWARE 43 #define DPI_AWARENESS_CONTEXT_UNAWARE (HANDLE)-1 44 #endif 45 46 #ifndef DPI_AWARENESS_CONTEXT_SYSTEM_AWARE 47 #define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE (HANDLE)-2 48 #endif 49 50 #ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 51 #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 (HANDLE)-4 52 #endif 53 54 typedef enum _GdkWin32MonitorDpiType { 55 MDT_EFFECTIVE_DPI = 0, 56 MDT_ANGULAR_DPI = 1, 57 MDT_RAW_DPI = 2, 58 MDT_DEFAULT = MDT_EFFECTIVE_DPI 59 } GdkWin32MonitorDpiType; 60 61 /* APIs from shcore.dll */ 62 typedef HRESULT (WINAPI *funcSetProcessDpiAwareness) (GdkWin32ProcessDpiAwareness value); 63 typedef HRESULT (WINAPI *funcGetProcessDpiAwareness) (HANDLE handle, GdkWin32ProcessDpiAwareness *awareness); 64 typedef HRESULT (WINAPI *funcGetDpiForMonitor) (HMONITOR monitor, 65 GdkWin32MonitorDpiType dpi_type, 66 UINT *dpi_x, 67 UINT *dpi_y); 68 69 typedef struct _GdkWin32ShcoreFuncs 70 { 71 HMODULE hshcore; 72 funcSetProcessDpiAwareness setDpiAwareFunc; 73 funcGetProcessDpiAwareness getDpiAwareFunc; 74 funcGetDpiForMonitor getDpiForMonitorFunc; 75 } GdkWin32ShcoreFuncs; 76 77 /* DPI awareness APIs from user32.dll */ 78 typedef BOOL (WINAPI *funcSetProcessDPIAware) (void); 79 typedef BOOL (WINAPI *funcIsProcessDPIAware) (void); 80 81 /* 82 * funcSPDAC is SetProcessDpiAwarenessContext() and 83 * funcGTDAC is GetThreadDpiAwarenessContext() and 84 * funcADACE is AreDpiAwarenessContextsEqual() provided by user32.dll, on 85 * Windows 10 Creator Edition and later. 86 * Treat HANDLE as void*, for convenience, since DPI_AWARENESS_CONTEXT is 87 * declared using DEFINE_HANDLE. 88 */ 89 typedef BOOL (WINAPI *funcSPDAC) (void *); 90 typedef HANDLE (WINAPI *funcGTDAC) (void); 91 typedef BOOL (WINAPI *funcADACE) (void *, void *); 92 93 typedef struct _GdkWin32User32DPIFuncs 94 { 95 funcSetProcessDPIAware setDpiAwareFunc; 96 funcIsProcessDPIAware isDpiAwareFunc; 97 funcSPDAC setPDAC; 98 funcGTDAC getTDAC; 99 funcADACE areDACEqual; 100 } GdkWin32User32DPIFuncs; 101 102 typedef enum { 103 GDK_WIN32_TABLET_INPUT_API_NONE, 104 GDK_WIN32_TABLET_INPUT_API_WINTAB, 105 GDK_WIN32_TABLET_INPUT_API_WINPOINTER 106 } GdkWin32TabletInputAPI; 107 108 /* Detect running architecture */ 109 typedef BOOL (WINAPI *funcIsWow64Process2) (HANDLE, USHORT *, USHORT *); 110 typedef struct _GdkWin32KernelCPUFuncs 111 { 112 funcIsWow64Process2 isWow64Process2; 113 } GdkWin32KernelCPUFuncs; 114 115 typedef struct 116 { 117 HDC hdc; 118 HGLRC hglrc; 119 } GdkWin32GLDummyContextWGL; 120 121 struct _GdkWin32Display 122 { 123 GdkDisplay display; 124 125 GdkWin32Screen *screen; 126 127 Win32CursorTheme *cursor_theme; 128 char *cursor_theme_name; 129 int cursor_theme_size; 130 131 HWND hwnd; 132 133 /* WGL/OpenGL Items */ 134 GdkWin32GLDummyContextWGL dummy_context_wgl; 135 int wgl_pixel_format; 136 guint gl_version; 137 138 #ifdef GDK_WIN32_ENABLE_EGL 139 /* EGL (Angle) Items */ 140 guint egl_version; 141 EGLDisplay egl_disp; 142 EGLConfig egl_config; 143 HDC hdc_egl_temp; 144 #endif 145 146 GListModel *monitors; 147 148 guint hasWglARBCreateContext : 1; 149 guint hasWglEXTSwapControl : 1; 150 guint hasWglOMLSyncControl : 1; 151 guint hasWglARBPixelFormat : 1; 152 guint hasWglARBmultisample : 1; 153 154 #ifdef GDK_WIN32_ENABLE_EGL 155 guint hasEglKHRCreateContext : 1; 156 guint hasEglSurfacelessContext : 1; 157 EGLint egl_min_swap_interval; 158 #endif 159 160 /* HiDPI Items */ 161 guint have_at_least_win81 : 1; 162 GdkWin32ProcessDpiAwareness dpi_aware_type; 163 guint has_fixed_scale : 1; 164 guint surface_scale; 165 166 GdkWin32ShcoreFuncs shcore_funcs; 167 GdkWin32User32DPIFuncs user32_dpi_funcs; 168 169 GdkWin32TabletInputAPI tablet_input_api; 170 171 /* Cursor Items (GdkCursor->GdkWin32HCursor) */ 172 GHashTable *cursors; 173 /* The cursor that is used by current grab (if any) */ 174 GdkWin32HCursor *grab_cursor; 175 /* HCURSOR -> GdkWin32HCursorTableEntry */ 176 GHashTable *cursor_reftable; 177 /* ID of the idle callback scheduled to destroy cursors */ 178 guint idle_cursor_destructor_id; 179 180 /* A list of cursor handles slated for destruction. */ 181 GList *cursors_for_destruction; 182 183 /* Message filters */ 184 GList *filters; 185 186 /* Running CPU items */ 187 guint running_on_arm64 : 1; 188 GdkWin32KernelCPUFuncs cpu_funcs; 189 }; 190 191 struct _GdkWin32DisplayClass 192 { 193 GdkDisplayClass display_class; 194 }; 195 196 void _gdk_win32_display_init_monitors (GdkWin32Display *display); 197 198 GPtrArray *_gdk_win32_display_get_monitor_list (GdkWin32Display *display); 199 200 void gdk_win32_display_check_composited (GdkWin32Display *display); 201 202 guint gdk_win32_display_get_monitor_scale_factor (GdkWin32Display *display_win32, 203 GdkSurface *surface, 204 HMONITOR hmonitor); 205 206 typedef struct _GdkWin32MessageFilter GdkWin32MessageFilter; 207 208 struct _GdkWin32MessageFilter 209 { 210 GdkWin32MessageFilterFunc function; 211 gpointer data; 212 gboolean removed; 213 guint ref_count; 214 }; 215 216 #endif /* __GDK_DISPLAY__WIN32_H__ */ 217