(Win32) Move global state to struct

This commit is contained in:
twinaphex 2020-03-12 17:47:49 +01:00
parent ee92c6d679
commit dfa1288988

View File

@ -111,6 +111,10 @@
#define WM_POINTERUP 0x0247 #define WM_POINTERUP 0x0247
#endif #endif
#ifndef MAX_MONITORS
#define MAX_MONITORS 9
#endif
const GUID GUID_DEVINTERFACE_HID = { 0x4d1e55b2, 0xf16f, 0x11Cf, { 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } }; const GUID GUID_DEVINTERFACE_HID = { 0x4d1e55b2, 0xf16f, 0x11Cf, { 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x501 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x501
static HDEVNOTIFY notification_handler; static HDEVNOTIFY notification_handler;
@ -136,14 +140,17 @@ typedef struct DISPLAYCONFIG_2DREGION_CUSTOM {
UINT32 cy; UINT32 cy;
} DISPLAYCONFIG_2DREGION_CUSTOM; } DISPLAYCONFIG_2DREGION_CUSTOM;
typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM { typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM
{
UINT64 pixelRate; UINT64 pixelRate;
DISPLAYCONFIG_RATIONAL_CUSTOM hSyncFreq; DISPLAYCONFIG_RATIONAL_CUSTOM hSyncFreq;
DISPLAYCONFIG_RATIONAL_CUSTOM vSyncFreq; DISPLAYCONFIG_RATIONAL_CUSTOM vSyncFreq;
DISPLAYCONFIG_2DREGION_CUSTOM activeSize; DISPLAYCONFIG_2DREGION_CUSTOM activeSize;
DISPLAYCONFIG_2DREGION_CUSTOM totalSize; DISPLAYCONFIG_2DREGION_CUSTOM totalSize;
union { union
struct { {
struct
{
UINT32 videoStandard :16; UINT32 videoStandard :16;
UINT32 vSyncFreqDivider :6; UINT32 vSyncFreqDivider :6;
UINT32 reserved :10; UINT32 reserved :10;
@ -153,16 +160,20 @@ typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM {
UINT32 scanLineOrdering; UINT32 scanLineOrdering;
} DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM; } DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM;
typedef struct DISPLAYCONFIG_TARGET_MODE_CUSTOM { typedef struct DISPLAYCONFIG_TARGET_MODE_CUSTOM
{
DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM targetVideoSignalInfo; DISPLAYCONFIG_VIDEO_SIGNAL_INFO_CUSTOM targetVideoSignalInfo;
} DISPLAYCONFIG_TARGET_MODE_CUSTOM; } DISPLAYCONFIG_TARGET_MODE_CUSTOM;
typedef struct DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM { typedef struct DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM
{
LUID adapterId; LUID adapterId;
UINT32 id; UINT32 id;
union { union
{
UINT32 modeInfoIdx; UINT32 modeInfoIdx;
struct { struct
{
UINT32 cloneGroupId :16; UINT32 cloneGroupId :16;
UINT32 sourceModeInfoIdx :16; UINT32 sourceModeInfoIdx :16;
} dummystructname; } dummystructname;
@ -170,36 +181,43 @@ typedef struct DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM {
UINT32 statusFlags; UINT32 statusFlags;
} DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM; } DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM;
typedef struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO_CUSTOM { typedef struct DISPLAYCONFIG_DESKTOP_IMAGE_INFO_CUSTOM
{
POINTL PathSourceSize; POINTL PathSourceSize;
RECTL DesktopImageRegion; RECTL DesktopImageRegion;
RECTL DesktopImageClip; RECTL DesktopImageClip;
} DISPLAYCONFIG_DESKTOP_IMAGE_INFO_CUSTOM; } DISPLAYCONFIG_DESKTOP_IMAGE_INFO_CUSTOM;
typedef struct DISPLAYCONFIG_SOURCE_MODE_CUSTOM { typedef struct DISPLAYCONFIG_SOURCE_MODE_CUSTOM
{
UINT32 width; UINT32 width;
UINT32 height; UINT32 height;
UINT32 pixelFormat; UINT32 pixelFormat;
POINTL position; POINTL position;
} DISPLAYCONFIG_SOURCE_MODE_CUSTOM; } DISPLAYCONFIG_SOURCE_MODE_CUSTOM;
typedef struct DISPLAYCONFIG_MODE_INFO_CUSTOM { typedef struct DISPLAYCONFIG_MODE_INFO_CUSTOM
{
UINT32 infoType; UINT32 infoType;
UINT32 id; UINT32 id;
LUID adapterId; LUID adapterId;
union { union
{
DISPLAYCONFIG_TARGET_MODE_CUSTOM targetMode; DISPLAYCONFIG_TARGET_MODE_CUSTOM targetMode;
DISPLAYCONFIG_SOURCE_MODE_CUSTOM sourceMode; DISPLAYCONFIG_SOURCE_MODE_CUSTOM sourceMode;
DISPLAYCONFIG_DESKTOP_IMAGE_INFO_CUSTOM desktopImageInfo; DISPLAYCONFIG_DESKTOP_IMAGE_INFO_CUSTOM desktopImageInfo;
} dummyunionname; } dummyunionname;
} DISPLAYCONFIG_MODE_INFO_CUSTOM; } DISPLAYCONFIG_MODE_INFO_CUSTOM;
typedef struct DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM { typedef struct DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM
{
LUID adapterId; LUID adapterId;
UINT32 id; UINT32 id;
union { union
{
UINT32 modeInfoIdx; UINT32 modeInfoIdx;
struct { struct
{
UINT32 desktopModeInfoIdx :16; UINT32 desktopModeInfoIdx :16;
UINT32 targetModeInfoIdx :16; UINT32 targetModeInfoIdx :16;
} dummystructname; } dummystructname;
@ -213,7 +231,8 @@ typedef struct DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM {
UINT32 statusFlags; UINT32 statusFlags;
} DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM; } DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM;
typedef struct DISPLAYCONFIG_PATH_INFO_CUSTOM { typedef struct DISPLAYCONFIG_PATH_INFO_CUSTOM
{
DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM sourceInfo; DISPLAYCONFIG_PATH_SOURCE_INFO_CUSTOM sourceInfo;
DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM targetInfo; DISPLAYCONFIG_PATH_TARGET_INFO_CUSTOM targetInfo;
UINT32 flags; UINT32 flags;
@ -222,22 +241,45 @@ typedef struct DISPLAYCONFIG_PATH_INFO_CUSTOM {
typedef LONG (WINAPI *QUERYDISPLAYCONFIG)(UINT32, UINT32*, DISPLAYCONFIG_PATH_INFO_CUSTOM*, UINT32*, DISPLAYCONFIG_MODE_INFO_CUSTOM*, UINT32*); typedef LONG (WINAPI *QUERYDISPLAYCONFIG)(UINT32, UINT32*, DISPLAYCONFIG_PATH_INFO_CUSTOM*, UINT32*, DISPLAYCONFIG_MODE_INFO_CUSTOM*, UINT32*);
typedef LONG (WINAPI *GETDISPLAYCONFIGBUFFERSIZES)(UINT32, UINT32*, UINT32*); typedef LONG (WINAPI *GETDISPLAYCONFIGBUFFERSIZES)(UINT32, UINT32*, UINT32*);
static bool g_win32_resized = false; typedef struct win32_common_state
bool g_win32_restore_desktop = false; {
static bool doubleclick_on_titlebar = false; bool resized;
static bool taskbar_is_created = false; bool doubleclick_on_titlebar;
bool g_win32_inited = false; bool taskbar_is_created;
static bool g_win32_quit = false; bool quit;
static int g_win32_pos_x = CW_USEDEFAULT; int pos_x;
static int g_win32_pos_y = CW_USEDEFAULT; int pos_y;
static unsigned g_win32_pos_width = 0; unsigned pos_width;
static unsigned g_win32_pos_height = 0; unsigned pos_height;
unsigned taskbar_message;
unsigned monitor_count;
HMONITOR monitor_last;
HMONITOR monitor_all[MAX_MONITORS];
} win32_common_state_t;
static win32_common_state_t win32_common_st =
{
false, /* resized */
false, /* doubleclick_on_titlebar */
false, /* taskbar_is_created */
false, /* quit */
CW_USEDEFAULT, /* pos_x */
CW_USEDEFAULT, /* pos_y */
0, /* pos_width */
0, /* pos_height */
0, /* taskbar_message */
0, /* monitor_count */
NULL, /* monitor_last */
};
bool g_win32_restore_desktop = false;
bool g_win32_inited = false;
unsigned g_win32_resize_width = 0; unsigned g_win32_resize_width = 0;
unsigned g_win32_resize_height = 0; unsigned g_win32_resize_height = 0;
static unsigned g_taskbar_message = 0;
static unsigned win32_monitor_count = 0;
static void *curD3D = NULL; static void *curD3D = NULL;
@ -280,32 +322,29 @@ typedef enum _POWER_REQUEST_TYPE
typedef REASON_CONTEXT POWER_REQUEST_CONTEXT, *PPOWER_REQUEST_CONTEXT, *LPPOWER_REQUEST_CONTEXT; typedef REASON_CONTEXT POWER_REQUEST_CONTEXT, *PPOWER_REQUEST_CONTEXT, *LPPOWER_REQUEST_CONTEXT;
#endif #endif
#ifndef MAX_MONITORS
#define MAX_MONITORS 9
#endif
#if defined(_MSC_VER) && _MSC_VER <= 1200 #if defined(_MSC_VER) && _MSC_VER <= 1200
#define INT_PTR_COMPAT int #define INT_PTR_COMPAT int
#else #else
#define INT_PTR_COMPAT INT_PTR #define INT_PTR_COMPAT INT_PTR
#endif #endif
static HMONITOR win32_monitor_last;
static HMONITOR win32_monitor_all[MAX_MONITORS];
bool win32_taskbar_is_created(void) bool win32_taskbar_is_created(void)
{ {
return taskbar_is_created; win32_common_state_t *g_win32 = &win32_common_st;
return g_win32->taskbar_is_created;
} }
bool doubleclick_on_titlebar_pressed(void) bool doubleclick_on_titlebar_pressed(void)
{ {
return doubleclick_on_titlebar; win32_common_state_t *g_win32 = &win32_common_st;
return g_win32->doubleclick_on_titlebar;
} }
void unset_doubleclick_on_titlebar(void) void unset_doubleclick_on_titlebar(void)
{ {
doubleclick_on_titlebar = false; win32_common_state_t *g_win32 = &win32_common_st;
g_win32->doubleclick_on_titlebar = false;
} }
static INT_PTR_COMPAT CALLBACK PickCoreProc( static INT_PTR_COMPAT CALLBACK PickCoreProc(
@ -375,20 +414,23 @@ static INT_PTR_COMPAT CALLBACK PickCoreProc(
static BOOL CALLBACK win32_monitor_enum_proc(HMONITOR hMonitor, static BOOL CALLBACK win32_monitor_enum_proc(HMONITOR hMonitor,
HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{ {
win32_monitor_all[win32_monitor_count++] = hMonitor; win32_common_state_t *g_win32 = &win32_common_st;
g_win32->monitor_all[g_win32->monitor_count++] = hMonitor;
return TRUE; return TRUE;
} }
void win32_monitor_from_window(void) void win32_monitor_from_window(void)
{ {
#ifndef _XBOX #ifndef _XBOX
ui_window_t *window = NULL; win32_common_state_t
*g_win32 = &win32_common_st;
ui_window_t *window = (ui_window_t*)
ui_companion_driver_get_window_ptr();
win32_monitor_last = g_win32->monitor_last =
MonitorFromWindow(main_window.hwnd, MONITOR_DEFAULTTONEAREST); MonitorFromWindow(main_window.hwnd, MONITOR_DEFAULTTONEAREST);
window = (ui_window_t*)ui_companion_driver_get_window_ptr();
if (window) if (window)
window->destroy(&main_window); window->destroy(&main_window);
#endif #endif
@ -410,11 +452,14 @@ int win32_change_display_settings(const char *str, void *devmode_data,
void win32_monitor_get_info(void) void win32_monitor_get_info(void)
{ {
MONITORINFOEX current_mon; MONITORINFOEX current_mon;
win32_common_state_t
*g_win32 = &win32_common_st;
memset(&current_mon, 0, sizeof(current_mon)); memset(&current_mon, 0, sizeof(current_mon));
current_mon.cbSize = sizeof(MONITORINFOEX); current_mon.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(win32_monitor_last, (LPMONITORINFO)&current_mon); GetMonitorInfo(g_win32->monitor_last,
(LPMONITORINFO)&current_mon);
win32_change_display_settings(current_mon.szDevice, NULL, 0); win32_change_display_settings(current_mon.szDevice, NULL, 0);
} }
@ -425,25 +470,27 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id)
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
MONITORINFOEX *mon = (MONITORINFOEX*)data; MONITORINFOEX *mon = (MONITORINFOEX*)data;
HMONITOR *hm_to_use = (HMONITOR*)hm_data; HMONITOR *hm_to_use = (HMONITOR*)hm_data;
win32_common_state_t
*g_win32 = &win32_common_st;
unsigned fs_monitor = settings->uints.video_monitor_index; unsigned fs_monitor = settings->uints.video_monitor_index;
if (!win32_monitor_last) if (!g_win32->monitor_last)
win32_monitor_last = MonitorFromWindow(GetDesktopWindow(), g_win32->monitor_last = MonitorFromWindow(GetDesktopWindow(),
MONITOR_DEFAULTTONEAREST); MONITOR_DEFAULTTONEAREST);
*hm_to_use = win32_monitor_last; *hm_to_use = g_win32->monitor_last;
if (fs_monitor && fs_monitor <= win32_monitor_count if (fs_monitor && fs_monitor <= g_win32->monitor_count
&& win32_monitor_all[fs_monitor - 1]) && g_win32->monitor_all[fs_monitor - 1])
{ {
*hm_to_use = win32_monitor_all[fs_monitor - 1]; *hm_to_use = g_win32->monitor_all[fs_monitor - 1];
*mon_id = fs_monitor - 1; *mon_id = fs_monitor - 1;
} }
else else
{ {
for (i = 0; i < win32_monitor_count; i++) for (i = 0; i < g_win32->monitor_count; i++)
{ {
if (win32_monitor_all[i] != *hm_to_use) if (g_win32->monitor_all[i] != *hm_to_use)
continue; continue;
*mon_id = i; *mon_id = i;
@ -579,6 +626,8 @@ static void win32_save_position(void)
{ {
RECT rect; RECT rect;
WINDOWPLACEMENT placement; WINDOWPLACEMENT placement;
win32_common_state_t
*g_win32 = &win32_common_st;
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
int title_bar_height = GetSystemMetrics(SM_CYCAPTION); int title_bar_height = GetSystemMetrics(SM_CYCAPTION);
int menu_bar_height = GetSystemMetrics(SM_CYMENU); int menu_bar_height = GetSystemMetrics(SM_CYMENU);
@ -589,17 +638,17 @@ static void win32_save_position(void)
memset(&placement, 0, sizeof(placement)); memset(&placement, 0, sizeof(placement));
placement.length = sizeof(placement); placement.length = sizeof(placement);
GetWindowPlacement(main_window.hwnd, &placement); GetWindowPlacement(main_window.hwnd, &placement);
g_win32_pos_x = placement.rcNormalPosition.left; g_win32->pos_x = placement.rcNormalPosition.left;
g_win32_pos_y = placement.rcNormalPosition.top; g_win32->pos_y = placement.rcNormalPosition.top;
if (GetWindowRect(main_window.hwnd, &rect)) if (GetWindowRect(main_window.hwnd, &rect))
{ {
g_win32_pos_width = rect.right - rect.left; g_win32->pos_width = rect.right - rect.left;
g_win32_pos_height = rect.bottom - rect.top; g_win32->pos_height = rect.bottom - rect.top;
} }
if (window_save_positions) if (window_save_positions)
{ {
@ -607,10 +656,14 @@ static void win32_save_position(void)
!retroarch_is_forced_fullscreen() && !retroarch_is_forced_fullscreen() &&
!retroarch_is_switching_display_mode()) !retroarch_is_switching_display_mode())
{ {
settings->uints.window_position_x = g_win32_pos_x; settings->uints.window_position_x = g_win32->pos_x;
settings->uints.window_position_y = g_win32_pos_y; settings->uints.window_position_y = g_win32->pos_y;
settings->uints.window_position_width = g_win32_pos_width - border_thickness * 2; settings->uints.window_position_width = g_win32->pos_width -
settings->uints.window_position_height = g_win32_pos_height - border_thickness * 2 - title_bar_height - (ui_menubar_enable ? menu_bar_height : 0); border_thickness * 2;
settings->uints.window_position_height = g_win32->pos_height -
border_thickness * 2 -
title_bar_height -
(ui_menubar_enable ? menu_bar_height : 0);
} }
} }
} }
@ -824,11 +877,13 @@ static LRESULT CALLBACK WndProcCommon(bool *quit, HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam) WPARAM wparam, LPARAM lparam)
{ {
bool keydown = true; bool keydown = true;
win32_common_state_t
*g_win32 = &win32_common_st;
switch (message) switch (message)
{ {
case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDBLCLK:
doubleclick_on_titlebar = true; g_win32->doubleclick_on_titlebar = true;
break; break;
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
/* Prevent screensavers, etc, while running. */ /* Prevent screensavers, etc, while running. */
@ -934,7 +989,7 @@ static LRESULT CALLBACK WndProcCommon(bool *quit, HWND hwnd, UINT message,
case WM_CLOSE: case WM_CLOSE:
case WM_DESTROY: case WM_DESTROY:
case WM_QUIT: case WM_QUIT:
g_win32_quit = true; g_win32->quit = true;
*quit = true; *quit = true;
/* fall-through */ /* fall-through */
case WM_MOVE: case WM_MOVE:
@ -950,7 +1005,7 @@ static LRESULT CALLBACK WndProcCommon(bool *quit, HWND hwnd, UINT message,
{ {
g_win32_resize_width = LOWORD(lparam); g_win32_resize_width = LOWORD(lparam);
g_win32_resize_height = HIWORD(lparam); g_win32_resize_height = HIWORD(lparam);
g_win32_resized = true; g_win32->resized = true;
} }
} }
*quit = true; *quit = true;
@ -972,7 +1027,9 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam) WPARAM wparam, LPARAM lparam)
{ {
LRESULT ret; LRESULT ret;
bool quit = false; bool quit = false;
win32_common_state_t
*g_win32 = &win32_common_st;
switch (message) switch (message)
{ {
@ -984,8 +1041,8 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL: case WM_MOUSEHWHEEL:
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
#ifdef HAVE_DINPUT #ifdef HAVE_DINPUT
if (input_get_ptr() == &input_dinput) if (input_get_ptr() == &input_dinput)
@ -998,10 +1055,10 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
#endif #endif
break; break;
case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDBLCLK:
doubleclick_on_titlebar = true; g_win32->doubleclick_on_titlebar = true;
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
case WM_DROPFILES: case WM_DROPFILES:
@ -1021,8 +1078,8 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
if (quit) if (quit)
return ret; return ret;
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
case WM_CREATE: case WM_CREATE:
@ -1047,6 +1104,8 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
{ {
LRESULT ret; LRESULT ret;
bool quit = false; bool quit = false;
win32_common_state_t
*g_win32 = &win32_common_st;
switch (message) switch (message)
{ {
@ -1058,8 +1117,8 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL: case WM_MOUSEHWHEEL:
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
#ifdef HAVE_DINPUT #ifdef HAVE_DINPUT
if (dinput_wgl && dinput_handle_message(dinput_wgl, if (dinput_wgl && dinput_handle_message(dinput_wgl,
@ -1068,10 +1127,10 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
#endif #endif
break; break;
case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDBLCLK:
doubleclick_on_titlebar = true; g_win32->doubleclick_on_titlebar = true;
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
case WM_DROPFILES: case WM_DROPFILES:
@ -1092,12 +1151,12 @@ LRESULT CALLBACK WndProcWGL(HWND hwnd, UINT message,
if (quit) if (quit)
return ret; return ret;
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
case WM_CREATE: case WM_CREATE:
create_graphics_context(hwnd, &g_win32_quit); create_graphics_context(hwnd, &g_win32->quit);
if (DragAcceptFiles_func) if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true); DragAcceptFiles_func(hwnd, true);
return 0; return 0;
@ -1113,6 +1172,8 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
{ {
LRESULT ret; LRESULT ret;
bool quit = false; bool quit = false;
win32_common_state_t
*g_win32 = &win32_common_st;
switch (message) switch (message)
{ {
@ -1124,8 +1185,8 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL: case WM_MOUSEHWHEEL:
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
#ifdef HAVE_DINPUT #ifdef HAVE_DINPUT
if (dinput_gdi && dinput_handle_message(dinput_gdi, if (dinput_gdi && dinput_handle_message(dinput_gdi,
@ -1134,10 +1195,10 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
#endif #endif
break; break;
case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDBLCLK:
doubleclick_on_titlebar = true; g_win32->doubleclick_on_titlebar = true;
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
case WM_PAINT: case WM_PAINT:
@ -1174,8 +1235,8 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
} }
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
} }
@ -1196,12 +1257,12 @@ LRESULT CALLBACK WndProcGDI(HWND hwnd, UINT message,
if (quit) if (quit)
return ret; return ret;
#if _WIN32_WINNT >= 0x0500 /* 2K */ #if _WIN32_WINNT >= 0x0500 /* 2K */
if (g_taskbar_message && message == g_taskbar_message) if (g_win32->taskbar_message && message == g_win32->taskbar_message)
taskbar_is_created = true; g_win32->taskbar_is_created = true;
#endif #endif
break; break;
case WM_CREATE: case WM_CREATE:
create_gdi_context(hwnd, &g_win32_quit); create_gdi_context(hwnd, &g_win32->quit);
if (DragAcceptFiles_func) if (DragAcceptFiles_func)
DragAcceptFiles_func(hwnd, true); DragAcceptFiles_func(hwnd, true);
return 0; return 0;
@ -1225,17 +1286,19 @@ bool win32_window_create(void *data, unsigned style,
bool window_save_positions = settings->bools.video_window_save_positions; bool window_save_positions = settings->bools.video_window_save_positions;
unsigned user_width = width; unsigned user_width = width;
unsigned user_height = height; unsigned user_height = height;
win32_common_state_t
*g_win32 = &win32_common_st;
if (window_save_positions && !fullscreen) if (window_save_positions && !fullscreen)
{ {
user_width = g_win32_pos_width; user_width = g_win32->pos_width;
user_height= g_win32_pos_height; user_height= g_win32->pos_height;
} }
main_window.hwnd = CreateWindowEx(0, main_window.hwnd = CreateWindowEx(0,
msg_hash_to_str(MSG_PROGRAM), msg_hash_to_str(MSG_PROGRAM), msg_hash_to_str(MSG_PROGRAM), msg_hash_to_str(MSG_PROGRAM),
style, style,
fullscreen ? mon_rect->left : g_win32_pos_x, fullscreen ? mon_rect->left : g_win32->pos_x,
fullscreen ? mon_rect->top : g_win32_pos_y, fullscreen ? mon_rect->top : g_win32->pos_y,
user_width, user_width,
user_height, user_height,
NULL, NULL, NULL, data); NULL, NULL, NULL, data);
@ -1243,7 +1306,7 @@ bool win32_window_create(void *data, unsigned style,
return false; return false;
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */ #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */
g_taskbar_message = RegisterWindowMessage("TaskbarButtonCreated"); g_win32->taskbar_message = RegisterWindowMessage("TaskbarButtonCreated");
memset(&notification_filter, 0, sizeof(notification_filter)); memset(&notification_filter, 0, sizeof(notification_filter));
notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); notification_filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
@ -1323,11 +1386,14 @@ bool win32_get_metrics(void *data,
void win32_monitor_init(void) void win32_monitor_init(void)
{ {
#if !defined(_XBOX) #if !defined(_XBOX)
win32_monitor_count = 0; win32_common_state_t
*g_win32 = &win32_common_st;
g_win32->monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, EnumDisplayMonitors(NULL, NULL,
win32_monitor_enum_proc, 0); win32_monitor_enum_proc, 0);
#endif #endif
g_win32_quit = false; g_win32->quit = false;
} }
static bool win32_monitor_set_fullscreen( static bool win32_monitor_set_fullscreen(
@ -1367,17 +1433,19 @@ void win32_check_window(bool *quit, bool *resize,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
#if !defined(_XBOX) #if !defined(_XBOX)
win32_common_state_t
*g_win32 = &win32_common_st;
bool video_is_threaded = video_driver_is_threaded(); bool video_is_threaded = video_driver_is_threaded();
if (video_is_threaded) if (video_is_threaded)
ui_companion_win32.application->process_events(); ui_companion_win32.application->process_events();
*quit = g_win32_quit; *quit = g_win32->quit;
if (g_win32_resized) if (g_win32->resized)
{ {
*resize = true; *resize = true;
*width = g_win32_resize_width; *width = g_win32_resize_width;
*height = g_win32_resize_height; *height = g_win32_resize_width;
g_win32_resized = false; g_win32->resized = false;
} }
#endif #endif
} }
@ -1474,6 +1542,7 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
unsigned window_position_y = settings->uints.window_position_y; unsigned window_position_y = settings->uints.window_position_y;
unsigned window_position_width = settings->uints.window_position_width; unsigned window_position_width = settings->uints.window_position_width;
unsigned window_position_height = settings->uints.window_position_height; unsigned window_position_height = settings->uints.window_position_height;
win32_common_state_t *g_win32 = &win32_common_st;
if (fullscreen) if (fullscreen)
{ {
@ -1514,24 +1583,27 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
if (video_window_save_positions) if (video_window_save_positions)
{ {
/* Set position from config */ /* Set position from config */
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
int title_bar_height = GetSystemMetrics(SM_CYCAPTION); int title_bar_height = GetSystemMetrics(SM_CYCAPTION);
win32_common_state_t
*g_win32 = &win32_common_st;
g_win32_pos_x = window_position_x; g_win32->pos_x = window_position_x;
g_win32_pos_y = window_position_y; g_win32->pos_y = window_position_y;
g_win32_pos_width = window_position_width g_win32->pos_width = window_position_width
+ border_thickness * 2; + border_thickness * 2;
g_win32_pos_height = window_position_height g_win32->pos_height = window_position_height
+ border_thickness * 2 + title_bar_height; + border_thickness * 2 + title_bar_height;
if (g_win32_pos_width != 0 && g_win32_pos_height != 0) if ( (g_win32->pos_width != 0) &&
(g_win32->pos_height != 0))
position_set_from_config = true; position_set_from_config = true;
} }
if (position_set_from_config) if (position_set_from_config)
{ {
g_win32_resize_width = *width = g_win32_pos_width; g_win32_resize_width = *width = g_win32->pos_width;
g_win32_resize_height = *height = g_win32_pos_height; g_win32_resize_height = *height = g_win32->pos_height;
} }
else else
{ {
@ -1594,6 +1666,8 @@ bool win32_set_video_mode(void *data,
int res = 0; int res = 0;
unsigned mon_id = 0; unsigned mon_id = 0;
HMONITOR hm_to_use = NULL; HMONITOR hm_to_use = NULL;
win32_common_state_t
*g_win32 = &win32_common_st;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
bool windowed_full = settings->bools.video_windowed_fullscreen; bool windowed_full = settings->bools.video_windowed_fullscreen;
@ -1620,7 +1694,7 @@ bool win32_set_video_mode(void *data,
/* Wait until context is created (or failed to do so ...). /* Wait until context is created (or failed to do so ...).
* Please don't remove the (res = ) as GetMessage can return -1. */ * Please don't remove the (res = ) as GetMessage can return -1. */
while (!g_win32_inited && !g_win32_quit while (!g_win32_inited && !g_win32->quit
&& (res = GetMessage(&msg, main_window.hwnd, 0, 0)) != 0) && (res = GetMessage(&msg, main_window.hwnd, 0, 0)) != 0)
{ {
if (res == -1) if (res == -1)
@ -1633,7 +1707,7 @@ bool win32_set_video_mode(void *data,
DispatchMessage(&msg); DispatchMessage(&msg);
} }
if (g_win32_quit) if (g_win32->quit)
return false; return false;
#endif #endif
@ -1677,8 +1751,10 @@ HWND win32_get_window(void)
void win32_window_reset(void) void win32_window_reset(void)
{ {
g_win32_quit = false; win32_common_state_t *g_win32 = &win32_common_st;
g_win32_restore_desktop = false;
g_win32->quit = false;
g_win32_restore_desktop = false;
} }
void win32_destroy_window(void) void win32_destroy_window(void)