diff options
| -rw-r--r-- | src/window_win32.c | 91 |
1 files changed, 41 insertions, 50 deletions
diff --git a/src/window_win32.c b/src/window_win32.c index d97f51b..5426f90 100644 --- a/src/window_win32.c +++ b/src/window_win32.c @@ -261,8 +261,7 @@ static void set_keycodes_for_win32(void) Global.keycodes[VK_RWIN] = STELA_KEY_RIGHT_SUPER; } -//MONITORENUMPROC MonitorInfoProc; -BOOL __stdcall MonitorInfoProc(HMONITOR Monitor, HDC DeviceContext, LPRECT Rect, LPARAM UserData) +static BOOL __stdcall MonitorInfoProc(HMONITOR Monitor, HDC DeviceContext, LPRECT Rect, LPARAM UserData) { struct stl_monitor_win32 *monitor = al_alloc_object(struct stl_monitor_win32); (void)DeviceContext; @@ -284,7 +283,10 @@ bool stl_global_init(bool skip_graphics) Global.ModuleHandle = GetModuleHandleW(NULL); HMODULE NTModule = LoadLibraryA("ntdll.dll"); - if (!NTModule) return false; + if (!NTModule) { + return false; + } + if (GetProcAddress(NTModule, "wine_get_version") != NULL) { log_info("Wine detected; using Windows-incompatible window move method."); Global.IsWine = TRUE; @@ -373,25 +375,9 @@ void stl_global_close(void) al_array_free(Global.monitors); } -#ifdef STELA_API_OPENGL -// https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions -static void *GetAnyGLFuncAddress(const char *Name) -{ - void *p = (void *)wglGetProcAddress(Name); - if (p == 0 || p == (void *)0x1 || p == (void *)0x2 || p == (void *)0x3 || p == (void *)-1) { - HMODULE GLModule = LoadLibraryA("opengl32.dll"); - p = (void *)GetProcAddress(GLModule, Name); - } - return p; -} - -typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const s32 *); -typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(s32); -#endif - //#define LOG_ALL_WND_MESSAGES #ifdef LOG_ALL_WND_MESSAGES -// https://en.wikichip.org/wiki/List_of_Windows_Messages_-_Win32 +// https://web.archive.org/web/20141104213010/https://en.wikichip.org/wiki/List_of_Windows_Messages_-_Win32 #define MESSAGE_CASE_STR(value) case value: return #value; static const char *WndMessageString(UINT Message) { @@ -725,7 +711,7 @@ static LRESULT CALLBACK DisplayWndProc(HWND Window, UINT Message, WPARAM WParam, */ // https://stackoverflow.com/a/35522584, incredible... // https://gitlab.winehq.org/agusev/wine/-/blob/wine-971221/windows/nonclient.c#L1773 - // This works on Wine but not Windows. Everything works the same except on Windows + // This works on Wine but not Windows. Everything works the same, except on Windows // it seems there is a special case for LBUTTON. SendMessageW(w32->Window, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, LParam); } @@ -839,6 +825,20 @@ intercept: } #ifdef STELA_API_OPENGL +// https://www.khronos.org/opengl/wiki/Load_OpenGL_Functions +static void *GetAnyGLFuncAddress(const char *Name) +{ + void *p = (void *)wglGetProcAddress(Name); + if (p == 0 || p == (void *)0x1 || p == (void *)0x2 || p == (void *)0x3 || p == (void *)-1) { + HMODULE GLModule = LoadLibraryA("opengl32.dll"); + p = (void *)GetProcAddress(GLModule, Name); + } + return p; +} + +typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const s32 *); +typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(s32); + static bool CreateWGLContext(struct stl_window_win32 *w32) { #define STELA_INCLUDE_DEPTH_BUFFER @@ -885,10 +885,10 @@ static bool CreateWGLContext(struct stl_window_win32 *w32) wglMakeCurrent(w32->DeviceContext, FakeContext); PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; - CreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB"); + CreateContextAttribsARB = (void *)GetAnyGLFuncAddress("wglCreateContextAttribsARB"); PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; - SwapIntervalEXT = (void *)wglGetProcAddress("wglSwapIntervalEXT"); + SwapIntervalEXT = (void *)GetAnyGLFuncAddress("wglSwapIntervalEXT"); w32->GLContext = NULL; if (CreateContextAttribsARB) { @@ -964,7 +964,7 @@ static bool window_win32_create_window(struct stl_window *window, u32 width, u32 WindowClass.style = 0; RegisterClassExW(&WindowClass); - // Add in window decorations so width and height reference the client area. + // Add in window decorations so the stored width and height reference the client area. RECT Overlap = { 0, 0, width, height }; AdjustWindowRect(&Overlap, WS_OVERLAPPEDWINDOW, FALSE); @@ -1040,9 +1040,6 @@ static struct stl_monitor_win32 *get_monitor_from_handle(HMONITOR Handle) return NULL; } -// @TODO: -// - Separate decorations and transparent background. -// - Fix jump on toggle. static void set_decorations(struct stl_window_win32 *w32, bool enabled) { if (!enabled && w32->Decorated) { // Voodoo... @@ -1054,9 +1051,11 @@ static void set_decorations(struct stl_window_win32 *w32, bool enabled) Style &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU); //ExStyle |= WS_EX_LAYERED; SetWindowLong(w32->Window, GWL_STYLE, Style); - //SetWindowLong(w32->Window, GWL_EXSTYLE, ExStyle); - //SetLayeredWindowAttributes(w32->Window, 0, 255, LWA_ALPHA); - //SetLayeredWindowAttributes(w32->Window, RGB(0, 0, 0), 0, LWA_COLORKEY); + SetWindowLong(w32->Window, GWL_EXSTYLE, ExStyle); + /* + SetLayeredWindowAttributes(w32->Window, 0, 255, LWA_ALPHA); + SetLayeredWindowAttributes(w32->Window, RGB(0, 0, 0), 0, LWA_COLORKEY); + */ /* SetLayeredWindowAttributes(w32->Window, 0, 0, LWA_ALPHA); BLENDFUNCTION blend = { 0 }; @@ -1126,35 +1125,27 @@ static void window_win32_set_decorations(struct stl_window *window, bool enabled struct stl_window_win32 *w32 = (struct stl_window_win32 *)window; w32->UserDecorated = enabled; if (!w32->w.fullscreen) { - s32 cx, cy, dx = 0, dy = 0; + s32 x, y, cx, cy; if (!enabled) { RECT Prev; GetWindowRect(w32->Window, &Prev); - w32->Prev.X = Prev.left; - w32->Prev.Y = Prev.top; - w32->Prev.Width = Prev.right - Prev.left; - w32->Prev.Height = Prev.bottom - Prev.top; - //RECT Over = { 0, 0, w32->w.width, w32->w.height }; - //AdjustWindowRect(&Over, WS_OVERLAPPEDWINDOW, FALSE); - cx = w32->w.width; + cx = w32->w.width; // Width and height with no window decorations. cy = w32->w.height; - // @TODO: What is 8? - dx = ((Prev.right - Prev.left) - cx) - 8; - dy = ((Prev.bottom - Prev.top) - cy) - 8; - dx = Prev.left + dx; - dy = Prev.top + dy; + x = Prev.left + (((Prev.right - Prev.left) - cx) - 8); + y = Prev.top + ( ((Prev.bottom - Prev.top) - cy) - 8); } else { - RECT Over = { 0, 0, w32->w.width, w32->w.height }; + RECT Prev; + GetWindowRect(w32->Window, &Prev); + RECT Over = Prev; AdjustWindowRect(&Over, WS_OVERLAPPEDWINDOW, FALSE); - cx = w32->Prev.Width; - cy = w32->Prev.Height; - dx = w32->Prev.X; - dy = w32->Prev.Y; + cx = Over.right - Over.left; + cy = Over.bottom - Over.top; + x = Over.left; + y = Over.top; } set_decorations(w32, enabled); - //UINT Flags = SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOACTIVATE; UINT Flags = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOACTIVATE; - SetWindowPos(w32->Window, 0, dx, dy, cx, cy, Flags); + SetWindowPos(w32->Window, 0, x, y, cx, cy, Flags); } } |