diff --git a/src/input.c b/src/input.c index 64986ce17..40a5e1175 100644 --- a/src/input.c +++ b/src/input.c @@ -234,12 +234,12 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods) void _glfwInputPenPressure(_GLFWwindow* window, double pressure, int x, int y) { - window->penPressure = pressure; - window->penXposition = x; - window->penYposition = y; + window->penPressure = pressure; + window->penXposition = x; + window->penYposition = y; - if (window->callbacks.penPressure) - window->callbacks.penPressure((GLFWwindow*)window, pressure, x, y); + if (window->callbacks.penPressure) + window->callbacks.penPressure((GLFWwindow*)window, pressure, x, y); } void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos) @@ -527,12 +527,12 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button) /***************************PEN**************************************************/ GLFWAPI double glfwGetPenPressure(GLFWwindow* handle) { - _GLFWwindow* window = (_GLFWwindow*)handle; - assert(window != NULL); + _GLFWwindow* window = (_GLFWwindow*)handle; + assert(window != NULL); - _GLFW_REQUIRE_INIT_OR_RETURN(0); + _GLFW_REQUIRE_INIT_OR_RETURN(0); - return window->penPressure; + return window->penPressure; } /**************************PEN***************************************************/ @@ -732,14 +732,14 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle, } GLFWAPI GLFWpenpressurefun glfwSetPenPressureCallback(GLFWwindow* handle, - GLFWpenpressurefun cbfun) + GLFWpenpressurefun cbfun) { - _GLFWwindow* window = (_GLFWwindow*)handle; - assert(window != NULL); + _GLFWwindow* window = (_GLFWwindow*)handle; + assert(window != NULL); - _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - _GLFW_SWAP_POINTERS(window->callbacks.penPressure, cbfun); - return cbfun; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + _GLFW_SWAP_POINTERS(window->callbacks.penPressure, cbfun); + return cbfun; } GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle, diff --git a/src/internal.h b/src/internal.h index 2f8b18045..34657e01d 100644 --- a/src/internal.h +++ b/src/internal.h @@ -84,8 +84,8 @@ typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*); typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*); #define GL_VERSION 0x1f02 -#define GL_NONE 0 -#define GL_COLOR_BUFFER_BIT 0x00004000 +#define GL_NONE 0 +#define GL_COLOR_BUFFER_BIT 0x00004000 #define GL_UNSIGNED_BYTE 0x1401 #define GL_EXTENSIONS 0x1f03 #define GL_NUM_EXTENSIONS 0x821d @@ -102,7 +102,7 @@ typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*); #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc #define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008 -typedef int GLint; +typedef int GLint; typedef unsigned int GLuint; typedef unsigned int GLenum; typedef unsigned int GLbitfield; @@ -419,9 +419,9 @@ struct _GLFWwindow GLFWbool stickyKeys; GLFWbool stickyMouseButtons; - double penPressure; - int penXposition; - int penYposition; + double penPressure; + int penXposition; + int penYposition; int cursorMode; char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; char keys[GLFW_KEY_LAST + 1]; @@ -439,8 +439,8 @@ struct _GLFWwindow GLFWwindowiconifyfun iconify; GLFWwindowmaximizefun maximize; GLFWframebuffersizefun fbsize; - GLFWmousebuttonfun mouseButton; - GLFWpenpressurefun penPressure; + GLFWmousebuttonfun mouseButton; + GLFWpenpressurefun penPressure; GLFWcursorposfun cursorPos; GLFWcursorenterfun cursorEnter; GLFWscrollfun scroll; diff --git a/src/win32_platform.h b/src/win32_platform.h index 273c4e402..e9525cd71 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -285,7 +285,7 @@ BOOL IsWindowsVersionOrGreater(WORD major, WORD minor, WORD sp); // HACK: Define macros that some dinput.h variants don't #ifndef DIDFT_OPTIONAL - #define DIDFT_OPTIONAL 0x80000000 + #define DIDFT_OPTIONAL 0x80000000 #endif // winmm.dll function pointer typedefs diff --git a/src/win32_window.c b/src/win32_window.c index 16ac96961..382e3b99f 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -44,975 +44,975 @@ static DWORD getWindowStyle(const _GLFWwindow* window) { DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; - if (window->monitor) - style |= WS_POPUP; - else - { - style |= WS_SYSMENU | WS_MINIMIZEBOX; + if (window->monitor) + style |= WS_POPUP; + else + { + style |= WS_SYSMENU | WS_MINIMIZEBOX; - if (window->decorated) - { - style |= WS_CAPTION; + if (window->decorated) + { + style |= WS_CAPTION; - if (window->resizable) - style |= WS_MAXIMIZEBOX | WS_THICKFRAME; - } - else - style |= WS_POPUP; - } + if (window->resizable) + style |= WS_MAXIMIZEBOX | WS_THICKFRAME; + } + else + style |= WS_POPUP; + } - return style; + return style; } // Returns the extended window style for the specified window // static DWORD getWindowExStyle(const _GLFWwindow* window) { - DWORD style = WS_EX_APPWINDOW; + DWORD style = WS_EX_APPWINDOW; - if (window->monitor || window->floating) - style |= WS_EX_TOPMOST; + if (window->monitor || window->floating) + style |= WS_EX_TOPMOST; - return style; + return style; } // Returns the image whose area most closely matches the desired one // static const GLFWimage* chooseImage(int count, const GLFWimage* images, - int width, int height) + int width, int height) { - int i, leastDiff = INT_MAX; - const GLFWimage* closest = NULL; + int i, leastDiff = INT_MAX; + const GLFWimage* closest = NULL; - for (i = 0; i < count; i++) - { - const int currDiff = abs(images[i].width * images[i].height - - width * height); - if (currDiff < leastDiff) - { - closest = images + i; - leastDiff = currDiff; - } - } + for (i = 0; i < count; i++) + { + const int currDiff = abs(images[i].width * images[i].height - + width * height); + if (currDiff < leastDiff) + { + closest = images + i; + leastDiff = currDiff; + } + } - return closest; + return closest; } // Creates an RGBA icon or cursor // static HICON createIcon(const GLFWimage* image, - int xhot, int yhot, GLFWbool icon) + int xhot, int yhot, GLFWbool icon) { - int i; - HDC dc; - HICON handle; - HBITMAP color, mask; - BITMAPV5HEADER bi; - ICONINFO ii; - unsigned char* target = NULL; - unsigned char* source = image->pixels; + int i; + HDC dc; + HICON handle; + HBITMAP color, mask; + BITMAPV5HEADER bi; + ICONINFO ii; + unsigned char* target = NULL; + unsigned char* source = image->pixels; - ZeroMemory(&bi, sizeof(bi)); - bi.bV5Size = sizeof(bi); - bi.bV5Width = image->width; - bi.bV5Height = -image->height; - bi.bV5Planes = 1; - bi.bV5BitCount = 32; - bi.bV5Compression = BI_BITFIELDS; - bi.bV5RedMask = 0x00ff0000; - bi.bV5GreenMask = 0x0000ff00; - bi.bV5BlueMask = 0x000000ff; - bi.bV5AlphaMask = 0xff000000; + ZeroMemory(&bi, sizeof(bi)); + bi.bV5Size = sizeof(bi); + bi.bV5Width = image->width; + bi.bV5Height = -image->height; + bi.bV5Planes = 1; + bi.bV5BitCount = 32; + bi.bV5Compression = BI_BITFIELDS; + bi.bV5RedMask = 0x00ff0000; + bi.bV5GreenMask = 0x0000ff00; + bi.bV5BlueMask = 0x000000ff; + bi.bV5AlphaMask = 0xff000000; - dc = GetDC(NULL); - color = CreateDIBSection(dc, - (BITMAPINFO*)&bi, - DIB_RGB_COLORS, - (void**)&target, - NULL, - (DWORD)0); - ReleaseDC(NULL, dc); + dc = GetDC(NULL); + color = CreateDIBSection(dc, + (BITMAPINFO*)&bi, + DIB_RGB_COLORS, + (void**)&target, + NULL, + (DWORD)0); + ReleaseDC(NULL, dc); - if (!color) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to create RGBA bitmap"); - return NULL; - } + if (!color) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create RGBA bitmap"); + return NULL; + } - mask = CreateBitmap(image->width, image->height, 1, 1, NULL); - if (!mask) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to create mask bitmap"); - DeleteObject(color); - return NULL; - } + mask = CreateBitmap(image->width, image->height, 1, 1, NULL); + if (!mask) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create mask bitmap"); + DeleteObject(color); + return NULL; + } - for (i = 0; i < image->width * image->height; i++) - { - target[0] = source[2]; - target[1] = source[1]; - target[2] = source[0]; - target[3] = source[3]; - target += 4; - source += 4; - } + for (i = 0; i < image->width * image->height; i++) + { + target[0] = source[2]; + target[1] = source[1]; + target[2] = source[0]; + target[3] = source[3]; + target += 4; + source += 4; + } - ZeroMemory(&ii, sizeof(ii)); - ii.fIcon = icon; - ii.xHotspot = xhot; - ii.yHotspot = yhot; - ii.hbmMask = mask; - ii.hbmColor = color; + ZeroMemory(&ii, sizeof(ii)); + ii.fIcon = icon; + ii.xHotspot = xhot; + ii.yHotspot = yhot; + ii.hbmMask = mask; + ii.hbmColor = color; - handle = CreateIconIndirect(&ii); + handle = CreateIconIndirect(&ii); - DeleteObject(color); - DeleteObject(mask); + DeleteObject(color); + DeleteObject(mask); - if (!handle) - { - if (icon) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to create icon"); - } - else - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to create cursor"); - } - } + if (!handle) + { + if (icon) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create icon"); + } + else + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create cursor"); + } + } - return handle; + return handle; } // Translate client window size to full window size according to styles // static void getFullWindowSize(DWORD style, DWORD exStyle, - int clientWidth, int clientHeight, - int* fullWidth, int* fullHeight) + int clientWidth, int clientHeight, + int* fullWidth, int* fullHeight) { - RECT rect = { 0, 0, clientWidth, clientHeight }; - AdjustWindowRectEx(&rect, style, FALSE, exStyle); - *fullWidth = rect.right - rect.left; - *fullHeight = rect.bottom - rect.top; + RECT rect = { 0, 0, clientWidth, clientHeight }; + AdjustWindowRectEx(&rect, style, FALSE, exStyle); + *fullWidth = rect.right - rect.left; + *fullHeight = rect.bottom - rect.top; } // Enforce the client rect aspect ratio based on which edge is being dragged // static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area) { - int xoff, yoff; - const float ratio = (float)window->numer / (float)window->denom; + int xoff, yoff; + const float ratio = (float)window->numer / (float)window->denom; - getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), - 0, 0, &xoff, &yoff); + getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), + 0, 0, &xoff, &yoff); - if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT || - edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT) - { - area->bottom = area->top + yoff + - (int)((area->right - area->left - xoff) / ratio); - } - else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT) - { - area->top = area->bottom - yoff - - (int)((area->right - area->left - xoff) / ratio); - } - else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM) - { - area->right = area->left + xoff + - (int)((area->bottom - area->top - yoff) * ratio); - } + if (edge == WMSZ_LEFT || edge == WMSZ_BOTTOMLEFT || + edge == WMSZ_RIGHT || edge == WMSZ_BOTTOMRIGHT) + { + area->bottom = area->top + yoff + + (int)((area->right - area->left - xoff) / ratio); + } + else if (edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT) + { + area->top = area->bottom - yoff - + (int)((area->right - area->left - xoff) / ratio); + } + else if (edge == WMSZ_TOP || edge == WMSZ_BOTTOM) + { + area->right = area->left + xoff + + (int)((area->bottom - area->top - yoff) * ratio); + } } // Centers the cursor over the window client area // static void centerCursor(_GLFWwindow* window) { - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); } // Returns whether the cursor is in the client area of the specified window // static GLFWbool cursorInClientArea(_GLFWwindow* window) { - RECT area; - POINT pos; + RECT area; + POINT pos; - if (!GetCursorPos(&pos)) - return GLFW_FALSE; + if (!GetCursorPos(&pos)) + return GLFW_FALSE; - if (WindowFromPoint(pos) != window->win32.handle) - return GLFW_FALSE; + if (WindowFromPoint(pos) != window->win32.handle) + return GLFW_FALSE; - GetClientRect(window->win32.handle, &area); - ClientToScreen(window->win32.handle, (POINT*)&area.left); - ClientToScreen(window->win32.handle, (POINT*)&area.right); + GetClientRect(window->win32.handle, &area); + ClientToScreen(window->win32.handle, (POINT*)&area.left); + ClientToScreen(window->win32.handle, (POINT*)&area.right); - return PtInRect(&area, pos); + return PtInRect(&area, pos); } // Updates the cursor image according to its cursor mode // static void updateCursorImage(_GLFWwindow* window) { - if (window->cursorMode == GLFW_CURSOR_NORMAL) - { - if (window->cursor) - SetCursor(window->cursor->win32.handle); - else - SetCursor(LoadCursorW(NULL, IDC_ARROW)); - } - else - SetCursor(NULL); + if (window->cursorMode == GLFW_CURSOR_NORMAL) + { + if (window->cursor) + SetCursor(window->cursor->win32.handle); + else + SetCursor(LoadCursorW(NULL, IDC_ARROW)); + } + else + SetCursor(NULL); } // Updates the cursor clip rect // static void updateClipRect(_GLFWwindow* window) { - if (window) - { - RECT clipRect; - GetClientRect(window->win32.handle, &clipRect); - ClientToScreen(window->win32.handle, (POINT*)&clipRect.left); - ClientToScreen(window->win32.handle, (POINT*)&clipRect.right); - ClipCursor(&clipRect); - } - else - ClipCursor(NULL); + if (window) + { + RECT clipRect; + GetClientRect(window->win32.handle, &clipRect); + ClientToScreen(window->win32.handle, (POINT*)&clipRect.left); + ClientToScreen(window->win32.handle, (POINT*)&clipRect.right); + ClipCursor(&clipRect); + } + else + ClipCursor(NULL); } // Update native window styles to match attributes // static void updateWindowStyles(const _GLFWwindow* window) { - RECT rect; - DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE); - style &= ~(WS_OVERLAPPEDWINDOW | WS_POPUP); - style |= getWindowStyle(window); + RECT rect; + DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE); + style &= ~(WS_OVERLAPPEDWINDOW | WS_POPUP); + style |= getWindowStyle(window); - GetClientRect(window->win32.handle, &rect); - AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window)); - ClientToScreen(window->win32.handle, (POINT*)&rect.left); - ClientToScreen(window->win32.handle, (POINT*)&rect.right); - SetWindowLongW(window->win32.handle, GWL_STYLE, style); - SetWindowPos(window->win32.handle, HWND_TOP, - rect.left, rect.top, - rect.right - rect.left, rect.bottom - rect.top, - SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOZORDER); + GetClientRect(window->win32.handle, &rect); + AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window)); + ClientToScreen(window->win32.handle, (POINT*)&rect.left); + ClientToScreen(window->win32.handle, (POINT*)&rect.right); + SetWindowLongW(window->win32.handle, GWL_STYLE, style); + SetWindowPos(window->win32.handle, HWND_TOP, + rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOZORDER); } // Update window framebuffer transparency // static void updateFramebufferTransparency(const _GLFWwindow* window) { - if (!IsWindowsVistaOrGreater()) - return; + if (!IsWindowsVistaOrGreater()) + return; - if (_glfwIsCompositionEnabledWin32()) - { - HRGN region = CreateRectRgn(0, 0, -1, -1); - DWM_BLURBEHIND bb = { 0 }; - bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; - bb.hRgnBlur = region; - bb.fEnable = TRUE; + if (_glfwIsCompositionEnabledWin32()) + { + HRGN region = CreateRectRgn(0, 0, -1, -1); + DWM_BLURBEHIND bb = { 0 }; + bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; + bb.hRgnBlur = region; + bb.fEnable = TRUE; - if (SUCCEEDED(DwmEnableBlurBehindWindow(window->win32.handle, &bb))) - { - // Decorated windows don't repaint the transparent background - // leaving a trail behind animations - // HACK: Making the window layered with a transparency color key - // seems to fix this. Normally, when specifying - // a transparency color key to be used when composing the - // layered window, all pixels painted by the window in this - // color will be transparent. That doesn't seem to be the - // case anymore, at least when used with blur behind window - // plus negative region. - LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE); - exStyle |= WS_EX_LAYERED; - SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle); + if (SUCCEEDED(DwmEnableBlurBehindWindow(window->win32.handle, &bb))) + { + // Decorated windows don't repaint the transparent background + // leaving a trail behind animations + // HACK: Making the window layered with a transparency color key + // seems to fix this. Normally, when specifying + // a transparency color key to be used when composing the + // layered window, all pixels painted by the window in this + // color will be transparent. That doesn't seem to be the + // case anymore, at least when used with blur behind window + // plus negative region. + LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE); + exStyle |= WS_EX_LAYERED; + SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle); - // Using a color key not equal to black to fix the trailing - // issue. When set to black, something is making the hit test - // not resize with the window frame. - SetLayeredWindowAttributes(window->win32.handle, - RGB(0, 193, 48), 255, LWA_COLORKEY); - } + // Using a color key not equal to black to fix the trailing + // issue. When set to black, something is making the hit test + // not resize with the window frame. + SetLayeredWindowAttributes(window->win32.handle, + RGB(0, 193, 48), 255, LWA_COLORKEY); + } - DeleteObject(region); - } - else - { - LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE); - exStyle &= ~WS_EX_LAYERED; - SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle); - RedrawWindow(window->win32.handle, NULL, NULL, - RDW_ERASE | RDW_INVALIDATE | RDW_FRAME); - } + DeleteObject(region); + } + else + { + LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE); + exStyle &= ~WS_EX_LAYERED; + SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle); + RedrawWindow(window->win32.handle, NULL, NULL, + RDW_ERASE | RDW_INVALIDATE | RDW_FRAME); + } } // Translates a GLFW standard cursor to a resource ID // static LPWSTR translateCursorShape(int shape) { - switch (shape) - { - case GLFW_ARROW_CURSOR: - return IDC_ARROW; - case GLFW_IBEAM_CURSOR: - return IDC_IBEAM; - case GLFW_CROSSHAIR_CURSOR: - return IDC_CROSS; - case GLFW_HAND_CURSOR: - return IDC_HAND; - case GLFW_HRESIZE_CURSOR: - return IDC_SIZEWE; - case GLFW_VRESIZE_CURSOR: - return IDC_SIZENS; - } + switch (shape) + { + case GLFW_ARROW_CURSOR: + return IDC_ARROW; + case GLFW_IBEAM_CURSOR: + return IDC_IBEAM; + case GLFW_CROSSHAIR_CURSOR: + return IDC_CROSS; + case GLFW_HAND_CURSOR: + return IDC_HAND; + case GLFW_HRESIZE_CURSOR: + return IDC_SIZEWE; + case GLFW_VRESIZE_CURSOR: + return IDC_SIZENS; + } - return NULL; + return NULL; } // Retrieves and translates modifier keys // static int getKeyMods(void) { - int mods = 0; + int mods = 0; - if (GetKeyState(VK_SHIFT) & (1 << 31)) - mods |= GLFW_MOD_SHIFT; - if (GetKeyState(VK_CONTROL) & (1 << 31)) - mods |= GLFW_MOD_CONTROL; - if (GetKeyState(VK_MENU) & (1 << 31)) - mods |= GLFW_MOD_ALT; - if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & (1 << 31)) - mods |= GLFW_MOD_SUPER; + if (GetKeyState(VK_SHIFT) & (1 << 31)) + mods |= GLFW_MOD_SHIFT; + if (GetKeyState(VK_CONTROL) & (1 << 31)) + mods |= GLFW_MOD_CONTROL; + if (GetKeyState(VK_MENU) & (1 << 31)) + mods |= GLFW_MOD_ALT; + if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & (1 << 31)) + mods |= GLFW_MOD_SUPER; - return mods; + return mods; } // Retrieves and translates modifier keys // static int getAsyncKeyMods(void) { - int mods = 0; + int mods = 0; - if (GetAsyncKeyState(VK_SHIFT) & (1 << 31)) - mods |= GLFW_MOD_SHIFT; - if (GetAsyncKeyState(VK_CONTROL) & (1 << 31)) - mods |= GLFW_MOD_CONTROL; - if (GetAsyncKeyState(VK_MENU) & (1 << 31)) - mods |= GLFW_MOD_ALT; - if ((GetAsyncKeyState(VK_LWIN) | GetAsyncKeyState(VK_RWIN)) & (1 << 31)) - mods |= GLFW_MOD_SUPER; + if (GetAsyncKeyState(VK_SHIFT) & (1 << 31)) + mods |= GLFW_MOD_SHIFT; + if (GetAsyncKeyState(VK_CONTROL) & (1 << 31)) + mods |= GLFW_MOD_CONTROL; + if (GetAsyncKeyState(VK_MENU) & (1 << 31)) + mods |= GLFW_MOD_ALT; + if ((GetAsyncKeyState(VK_LWIN) | GetAsyncKeyState(VK_RWIN)) & (1 << 31)) + mods |= GLFW_MOD_SUPER; - return mods; + return mods; } // Translates a Windows key to the corresponding GLFW key // static int translateKey(WPARAM wParam, LPARAM lParam) { - // The Ctrl keys require special handling - if (wParam == VK_CONTROL) - { - MSG next; - DWORD time; + // The Ctrl keys require special handling + if (wParam == VK_CONTROL) + { + MSG next; + DWORD time; - // Right side keys have the extended key bit set - if (lParam & 0x01000000) - return GLFW_KEY_RIGHT_CONTROL; + // Right side keys have the extended key bit set + if (lParam & 0x01000000) + return GLFW_KEY_RIGHT_CONTROL; - // HACK: Alt Gr sends Left Ctrl and then Right Alt in close sequence - // We only want the Right Alt message, so if the next message is - // Right Alt we ignore this (synthetic) Left Ctrl message - time = GetMessageTime(); + // HACK: Alt Gr sends Left Ctrl and then Right Alt in close sequence + // We only want the Right Alt message, so if the next message is + // Right Alt we ignore this (synthetic) Left Ctrl message + time = GetMessageTime(); - if (PeekMessageW(&next, NULL, 0, 0, PM_NOREMOVE)) - { - if (next.message == WM_KEYDOWN || - next.message == WM_SYSKEYDOWN || - next.message == WM_KEYUP || - next.message == WM_SYSKEYUP) - { - if (next.wParam == VK_MENU && - (next.lParam & 0x01000000) && - next.time == time) - { - // Next message is Right Alt down so discard this - return _GLFW_KEY_INVALID; - } - } - } + if (PeekMessageW(&next, NULL, 0, 0, PM_NOREMOVE)) + { + if (next.message == WM_KEYDOWN || + next.message == WM_SYSKEYDOWN || + next.message == WM_KEYUP || + next.message == WM_SYSKEYUP) + { + if (next.wParam == VK_MENU && + (next.lParam & 0x01000000) && + next.time == time) + { + // Next message is Right Alt down so discard this + return _GLFW_KEY_INVALID; + } + } + } - return GLFW_KEY_LEFT_CONTROL; - } + return GLFW_KEY_LEFT_CONTROL; + } - if (wParam == VK_PROCESSKEY) - { - // IME notifies that keys have been filtered by setting the virtual - // key-code to VK_PROCESSKEY - return _GLFW_KEY_INVALID; - } + if (wParam == VK_PROCESSKEY) + { + // IME notifies that keys have been filtered by setting the virtual + // key-code to VK_PROCESSKEY + return _GLFW_KEY_INVALID; + } - return _glfw.win32.keycodes[HIWORD(lParam) & 0x1FF]; + return _glfw.win32.keycodes[HIWORD(lParam) & 0x1FF]; } // Make the specified window and its video mode active on its monitor // static GLFWbool acquireMonitor(_GLFWwindow* window) { - GLFWvidmode mode; - GLFWbool status; - int xpos, ypos; + GLFWvidmode mode; + GLFWbool status; + int xpos, ypos; - if (!_glfw.win32.acquiredMonitorCount) - SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); - if (!window->monitor->window) - _glfw.win32.acquiredMonitorCount++; + if (!_glfw.win32.acquiredMonitorCount) + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); + if (!window->monitor->window) + _glfw.win32.acquiredMonitorCount++; - status = _glfwSetVideoModeWin32(window->monitor, &window->videoMode); + status = _glfwSetVideoModeWin32(window->monitor, &window->videoMode); - _glfwPlatformGetVideoMode(window->monitor, &mode); - _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); + _glfwPlatformGetVideoMode(window->monitor, &mode); + _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); - SetWindowPos(window->win32.handle, HWND_TOPMOST, - xpos, ypos, mode.width, mode.height, - SWP_NOACTIVATE | SWP_NOCOPYBITS); + SetWindowPos(window->win32.handle, HWND_TOPMOST, + xpos, ypos, mode.width, mode.height, + SWP_NOACTIVATE | SWP_NOCOPYBITS); - _glfwInputMonitorWindow(window->monitor, window); - return status; + _glfwInputMonitorWindow(window->monitor, window); + return status; } // Remove the window and restore the original video mode // static void releaseMonitor(_GLFWwindow* window) { - if (window->monitor->window != window) - return; + if (window->monitor->window != window) + return; - _glfw.win32.acquiredMonitorCount--; - if (!_glfw.win32.acquiredMonitorCount) - SetThreadExecutionState(ES_CONTINUOUS); + _glfw.win32.acquiredMonitorCount--; + if (!_glfw.win32.acquiredMonitorCount) + SetThreadExecutionState(ES_CONTINUOUS); - _glfwInputMonitorWindow(window->monitor, NULL); - _glfwRestoreVideoModeWin32(window->monitor); + _glfwInputMonitorWindow(window->monitor, NULL); + _glfwRestoreVideoModeWin32(window->monitor); } // Window callback function (handles window messages) // static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam) + WPARAM wParam, LPARAM lParam) { - _GLFWwindow* window = GetPropW(hWnd, L"GLFW"); - if (!window) - { - // This is the message handling for the hidden helper window - - switch (uMsg) - { - case WM_DISPLAYCHANGE: - _glfwPollMonitorsWin32(); - break; - - case WM_DEVICECHANGE: - { - if (wParam == DBT_DEVICEARRIVAL) - { - DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam; - if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) - _glfwDetectJoystickConnectionWin32(); - } - else if (wParam == DBT_DEVICEREMOVECOMPLETE) - { - DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam; - if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) - _glfwDetectJoystickDisconnectionWin32(); - } - - break; - } - } - - return DefWindowProcW(hWnd, uMsg, wParam, lParam); - } - - switch (uMsg) - { - case WM_MOUSEACTIVATE: - { - // HACK: Postpone cursor disabling when the window was activated by - // clicking a caption button - if (HIWORD(lParam) == WM_LBUTTONDOWN) - { - if (LOWORD(lParam) == HTCLOSE || - LOWORD(lParam) == HTMINBUTTON || - LOWORD(lParam) == HTMAXBUTTON) - { - window->win32.frameAction = GLFW_TRUE; - } - } - - break; - } - - case WM_POINTERDOWN: - case WM_POINTERUPDATE: - case WM_POINTERUP: - { - POINTER_PEN_INFO penInfo; - POINTER_INFO pointerInfo; - UINT32 pointerId = GET_POINTERID_WPARAM(wParam); - POINTER_INPUT_TYPE pointerType = PT_POINTER; - - // default to unhandled to enable call to DefWindowProc - BOOL fHandled = FALSE; - - // Retrieve common pointer information - if (!GetPointerType(pointerId, &pointerType)) - { - // failure, call - GetLastError(); - // set PT_POINTER to fall to default case below - pointerType = PT_POINTER; - } - - switch (pointerType) - { - case (PT_PEN): - //Retrieve pen information - if (!GetPointerPenInfo(pointerId, &penInfo)) - { - // failure, call - GetLastError(); - } - else - { - // success, process penInfo - // We change the pen pressure which is given normalized to a range between 0 and 1024 - // to a normalized value in [0..1] - double pressure = (double)penInfo.pressure /(double) 1024; - int xPos = GET_X_LPARAM(lParam); - int yPos = GET_Y_LPARAM(lParam); - if (IS_POINTER_INCONTACT_WPARAM(wParam)) - { - _glfwInputPenPressure(window, pressure, xPos, yPos); - } - // mark as handled to skip call to DefWindowProc - fHandled = TRUE; - } - break; - } - default: - if (!GetPointerInfo(pointerId, &pointerInfo)) - { - // failure. - GetLastError(); - } - else - { - // success, proceed with pointerInfo. -// fHandled = HandleGenericPointerMessage(&pointerInfo); - } - break; - } - - case WM_CAPTURECHANGED: - { - // HACK: Disable the cursor once the caption button action has been - // completed or cancelled - if (lParam == 0 && window->win32.frameAction) - { - if (window->cursorMode == GLFW_CURSOR_DISABLED) - _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); - - window->win32.frameAction = GLFW_FALSE; - } - - break; - } - - case WM_SETFOCUS: - { - _glfwInputWindowFocus(window, GLFW_TRUE); - - // HACK: Do not disable cursor while the user is interacting with - // a caption button - if (window->win32.frameAction) - break; - - if (window->cursorMode == GLFW_CURSOR_DISABLED) - _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); - - return 0; - } - - case WM_KILLFOCUS: - { - if (window->cursorMode == GLFW_CURSOR_DISABLED) - _glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL); - - if (window->monitor && window->autoIconify) - _glfwPlatformIconifyWindow(window); - - _glfwInputWindowFocus(window, GLFW_FALSE); - return 0; - } - - case WM_SYSCOMMAND: - { - switch (wParam & 0xfff0) - { - case SC_SCREENSAVE: - case SC_MONITORPOWER: - { - if (window->monitor) - { - // We are running in full screen mode, so disallow - // screen saver and screen blanking - return 0; - } - else - break; - } - - // User trying to access application menu using ALT? - case SC_KEYMENU: - return 0; - } - break; - } - - case WM_CLOSE: - { - _glfwInputWindowCloseRequest(window); - return 0; - } - - case WM_INPUTLANGCHANGE: - { - _glfwUpdateKeyNamesWin32(); - break; - } - - case WM_CHAR: - case WM_SYSCHAR: - case WM_UNICHAR: - { - const GLFWbool plain = (uMsg != WM_SYSCHAR); - - if (uMsg == WM_UNICHAR && wParam == UNICODE_NOCHAR) - { - // WM_UNICHAR is not sent by Windows, but is sent by some - // third-party input method engine - // Returning TRUE here announces support for this message - return TRUE; - } - - _glfwInputChar(window, (unsigned int)wParam, getKeyMods(), plain); - return 0; - } - - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - case WM_KEYUP: - case WM_SYSKEYUP: - { - const int key = translateKey(wParam, lParam); - const int scancode = (lParam >> 16) & 0x1ff; - const int action = ((lParam >> 31) & 1) ? GLFW_RELEASE : GLFW_PRESS; - const int mods = getKeyMods(); - - if (key == _GLFW_KEY_INVALID) - break; - - if (action == GLFW_RELEASE && wParam == VK_SHIFT) - { - // HACK: Release both Shift keys on Shift up event, as when both - // are pressed the first release does not emit any event - // NOTE: The other half of this is in _glfwPlatformPollEvents - _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, action, mods); - _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, action, mods); - } - else if (wParam == VK_SNAPSHOT) - { - // HACK: Key down is not reported for the Print Screen key - _glfwInputKey(window, key, scancode, GLFW_PRESS, mods); - _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods); - } - else - _glfwInputKey(window, key, scancode, action, mods); - - break; - } - - case WM_LBUTTONDOWN: - case WM_RBUTTONDOWN: - case WM_MBUTTONDOWN: - case WM_XBUTTONDOWN: - case WM_LBUTTONUP: - case WM_RBUTTONUP: - case WM_MBUTTONUP: - case WM_XBUTTONUP: - { - int i, button, action; - - if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) - button = GLFW_MOUSE_BUTTON_LEFT; - else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) - button = GLFW_MOUSE_BUTTON_RIGHT; - else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) - button = GLFW_MOUSE_BUTTON_MIDDLE; - else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) - button = GLFW_MOUSE_BUTTON_4; - else - button = GLFW_MOUSE_BUTTON_5; - - if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN || - uMsg == WM_MBUTTONDOWN || uMsg == WM_XBUTTONDOWN) - { - action = GLFW_PRESS; - } - else - action = GLFW_RELEASE; - - for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) - { - if (window->mouseButtons[i] == GLFW_PRESS) - break; - } - - if (i > GLFW_MOUSE_BUTTON_LAST) - SetCapture(hWnd); - - _glfwInputMouseClick(window, button, action, getKeyMods()); - - for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) - { - if (window->mouseButtons[i] == GLFW_PRESS) - break; - } - - if (i > GLFW_MOUSE_BUTTON_LAST) - ReleaseCapture(); - - if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) - return TRUE; - - return 0; - } - - case WM_MOUSEMOVE: - { - const int x = GET_X_LPARAM(lParam); - const int y = GET_Y_LPARAM(lParam); - - // Disabled cursor motion input is provided by WM_INPUT - if (window->cursorMode == GLFW_CURSOR_DISABLED) - break; - - _glfwInputCursorPos(window, x, y); - - window->win32.lastCursorPosX = x; - window->win32.lastCursorPosY = y; - - if (!window->win32.cursorTracked) - { - TRACKMOUSEEVENT tme; - ZeroMemory(&tme, sizeof(tme)); - tme.cbSize = sizeof(tme); - tme.dwFlags = TME_LEAVE; - tme.hwndTrack = window->win32.handle; - TrackMouseEvent(&tme); - - window->win32.cursorTracked = GLFW_TRUE; - _glfwInputCursorEnter(window, GLFW_TRUE); - } - - return 0; - } - - case WM_INPUT: - { - UINT size; - HRAWINPUT ri = (HRAWINPUT)lParam; - RAWINPUT* data; - int dx, dy; - - // Only process input when disabled cursor mode is applied - if (_glfw.win32.disabledCursorWindow != window) - break; - - GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); - if (size > (UINT)_glfw.win32.rawInputSize) - { - free(_glfw.win32.rawInput); - _glfw.win32.rawInput = calloc(size, 1); - _glfw.win32.rawInputSize = size; - } - - size = _glfw.win32.rawInputSize; - if (GetRawInputData(ri, RID_INPUT, - _glfw.win32.rawInput, &size, - sizeof(RAWINPUTHEADER)) == (UINT)-1) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Win32: Failed to retrieve raw input data"); - break; - } - - data = _glfw.win32.rawInput; - if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) - { - dx = data->data.mouse.lLastX - window->win32.lastCursorPosX; - dy = data->data.mouse.lLastY - window->win32.lastCursorPosY; - } - else - { - dx = data->data.mouse.lLastX; - dy = data->data.mouse.lLastY; - } - - _glfwInputCursorPos(window, - window->virtualCursorPosX + dx, - window->virtualCursorPosY + dy); - - window->win32.lastCursorPosX += dx; - window->win32.lastCursorPosY += dy; - break; - } - - case WM_MOUSELEAVE: - { - window->win32.cursorTracked = GLFW_FALSE; - _glfwInputCursorEnter(window, GLFW_FALSE); - return 0; - } - - case WM_MOUSEWHEEL: - { - _glfwInputScroll(window, 0.0, (SHORT)HIWORD(wParam) / (double)WHEEL_DELTA); - return 0; - } - - case WM_MOUSEHWHEEL: - { - // This message is only sent on Windows Vista and later - // NOTE: The X-axis is inverted for consistency with macOS and X11 - _glfwInputScroll(window, -((SHORT)HIWORD(wParam) / (double)WHEEL_DELTA), 0.0); - return 0; - } - - case WM_ENTERSIZEMOVE: - case WM_ENTERMENULOOP: - { - // HACK: Postpone cursor disabling while the user is moving or - // resizing the window or using the menu - if (window->cursorMode == GLFW_CURSOR_DISABLED) - _glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL); - - break; - } - - case WM_EXITSIZEMOVE: - case WM_EXITMENULOOP: - { - // HACK: Disable the cursor once the user is done moving or - // resizing the window or using the menu - if (window->cursorMode == GLFW_CURSOR_DISABLED) - _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); - - break; - } - - case WM_SIZE: - { - const GLFWbool iconified = wParam == SIZE_MINIMIZED; - const GLFWbool maximized = wParam == SIZE_MAXIMIZED || - (window->win32.maximized && - wParam != SIZE_RESTORED); - - if (_glfw.win32.disabledCursorWindow == window) - updateClipRect(window); - - if (window->win32.iconified != iconified) - _glfwInputWindowIconify(window, iconified); - - if (window->win32.maximized != maximized) - _glfwInputWindowMaximize(window, maximized); - - _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam)); - _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam)); - - if (window->monitor && window->win32.iconified != iconified) - { - if (iconified) - releaseMonitor(window); - else - acquireMonitor(window); - } - - window->win32.iconified = iconified; - window->win32.maximized = maximized; - return 0; - } - - case WM_MOVE: - { - if (_glfw.win32.disabledCursorWindow == window) - updateClipRect(window); - - // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as - // those macros do not handle negative window positions correctly - _glfwInputWindowPos(window, - GET_X_LPARAM(lParam), - GET_Y_LPARAM(lParam)); - return 0; - } - - case WM_SIZING: - { - if (window->numer == GLFW_DONT_CARE || - window->denom == GLFW_DONT_CARE) - { - break; - } - - applyAspectRatio(window, (int)wParam, (RECT*)lParam); - return TRUE; - } - - case WM_GETMINMAXINFO: - { - int xoff, yoff; - MINMAXINFO* mmi = (MINMAXINFO*)lParam; - - if (window->monitor) - break; - - getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), - 0, 0, &xoff, &yoff); - - if (window->minwidth != GLFW_DONT_CARE && - window->minheight != GLFW_DONT_CARE) - { - mmi->ptMinTrackSize.x = window->minwidth + xoff; - mmi->ptMinTrackSize.y = window->minheight + yoff; - } - - if (window->maxwidth != GLFW_DONT_CARE && - window->maxheight != GLFW_DONT_CARE) - { - mmi->ptMaxTrackSize.x = window->maxwidth + xoff; - mmi->ptMaxTrackSize.y = window->maxheight + yoff; - } + _GLFWwindow* window = GetPropW(hWnd, L"GLFW"); + if (!window) + { + // This is the message handling for the hidden helper window + + switch (uMsg) + { + case WM_DISPLAYCHANGE: + _glfwPollMonitorsWin32(); + break; + + case WM_DEVICECHANGE: + { + if (wParam == DBT_DEVICEARRIVAL) + { + DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam; + if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) + _glfwDetectJoystickConnectionWin32(); + } + else if (wParam == DBT_DEVICEREMOVECOMPLETE) + { + DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*)lParam; + if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) + _glfwDetectJoystickDisconnectionWin32(); + } + + break; + } + } + + return DefWindowProcW(hWnd, uMsg, wParam, lParam); + } + + switch (uMsg) + { + case WM_MOUSEACTIVATE: + { + // HACK: Postpone cursor disabling when the window was activated by + // clicking a caption button + if (HIWORD(lParam) == WM_LBUTTONDOWN) + { + if (LOWORD(lParam) == HTCLOSE || + LOWORD(lParam) == HTMINBUTTON || + LOWORD(lParam) == HTMAXBUTTON) + { + window->win32.frameAction = GLFW_TRUE; + } + } + + break; + } + + case WM_POINTERDOWN: + case WM_POINTERUPDATE: + case WM_POINTERUP: + { + POINTER_PEN_INFO penInfo; + POINTER_INFO pointerInfo; + UINT32 pointerId = GET_POINTERID_WPARAM(wParam); + POINTER_INPUT_TYPE pointerType = PT_POINTER; + + // default to unhandled to enable call to DefWindowProc + BOOL fHandled = FALSE; + + // Retrieve common pointer information + if (!GetPointerType(pointerId, &pointerType)) + { + // failure, call + GetLastError(); + // set PT_POINTER to fall to default case below + pointerType = PT_POINTER; + } + + switch (pointerType) + { + case (PT_PEN): + //Retrieve pen information + if (!GetPointerPenInfo(pointerId, &penInfo)) + { + // failure, call + GetLastError(); + } + else + { + // success, process penInfo + // We change the pen pressure which is given normalized to a range between 0 and 1024 + // to a normalized value in [0..1] + double pressure = (double)penInfo.pressure /(double) 1024; + int xPos = GET_X_LPARAM(lParam); + int yPos = GET_Y_LPARAM(lParam); + if (IS_POINTER_INCONTACT_WPARAM(wParam)) + { + _glfwInputPenPressure(window, pressure, xPos, yPos); + } + // mark as handled to skip call to DefWindowProc + fHandled = TRUE; + } + break; + } + default: + if (!GetPointerInfo(pointerId, &pointerInfo)) + { + // failure. + GetLastError(); + } + else + { + // success, proceed with pointerInfo. +// fHandled = HandleGenericPointerMessage(&pointerInfo); + } + break; + } + + case WM_CAPTURECHANGED: + { + // HACK: Disable the cursor once the caption button action has been + // completed or cancelled + if (lParam == 0 && window->win32.frameAction) + { + if (window->cursorMode == GLFW_CURSOR_DISABLED) + _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); + + window->win32.frameAction = GLFW_FALSE; + } + + break; + } + + case WM_SETFOCUS: + { + _glfwInputWindowFocus(window, GLFW_TRUE); + + // HACK: Do not disable cursor while the user is interacting with + // a caption button + if (window->win32.frameAction) + break; + + if (window->cursorMode == GLFW_CURSOR_DISABLED) + _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); + + return 0; + } + + case WM_KILLFOCUS: + { + if (window->cursorMode == GLFW_CURSOR_DISABLED) + _glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL); + + if (window->monitor && window->autoIconify) + _glfwPlatformIconifyWindow(window); + + _glfwInputWindowFocus(window, GLFW_FALSE); + return 0; + } + + case WM_SYSCOMMAND: + { + switch (wParam & 0xfff0) + { + case SC_SCREENSAVE: + case SC_MONITORPOWER: + { + if (window->monitor) + { + // We are running in full screen mode, so disallow + // screen saver and screen blanking + return 0; + } + else + break; + } + + // User trying to access application menu using ALT? + case SC_KEYMENU: + return 0; + } + break; + } + + case WM_CLOSE: + { + _glfwInputWindowCloseRequest(window); + return 0; + } + + case WM_INPUTLANGCHANGE: + { + _glfwUpdateKeyNamesWin32(); + break; + } + + case WM_CHAR: + case WM_SYSCHAR: + case WM_UNICHAR: + { + const GLFWbool plain = (uMsg != WM_SYSCHAR); + + if (uMsg == WM_UNICHAR && wParam == UNICODE_NOCHAR) + { + // WM_UNICHAR is not sent by Windows, but is sent by some + // third-party input method engine + // Returning TRUE here announces support for this message + return TRUE; + } + + _glfwInputChar(window, (unsigned int)wParam, getKeyMods(), plain); + return 0; + } + + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + case WM_KEYUP: + case WM_SYSKEYUP: + { + const int key = translateKey(wParam, lParam); + const int scancode = (lParam >> 16) & 0x1ff; + const int action = ((lParam >> 31) & 1) ? GLFW_RELEASE : GLFW_PRESS; + const int mods = getKeyMods(); + + if (key == _GLFW_KEY_INVALID) + break; + + if (action == GLFW_RELEASE && wParam == VK_SHIFT) + { + // HACK: Release both Shift keys on Shift up event, as when both + // are pressed the first release does not emit any event + // NOTE: The other half of this is in _glfwPlatformPollEvents + _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, action, mods); + _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, action, mods); + } + else if (wParam == VK_SNAPSHOT) + { + // HACK: Key down is not reported for the Print Screen key + _glfwInputKey(window, key, scancode, GLFW_PRESS, mods); + _glfwInputKey(window, key, scancode, GLFW_RELEASE, mods); + } + else + _glfwInputKey(window, key, scancode, action, mods); + + break; + } + + case WM_LBUTTONDOWN: + case WM_RBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_XBUTTONDOWN: + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + case WM_XBUTTONUP: + { + int i, button, action; + + if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) + button = GLFW_MOUSE_BUTTON_LEFT; + else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) + button = GLFW_MOUSE_BUTTON_RIGHT; + else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) + button = GLFW_MOUSE_BUTTON_MIDDLE; + else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1) + button = GLFW_MOUSE_BUTTON_4; + else + button = GLFW_MOUSE_BUTTON_5; + + if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN || + uMsg == WM_MBUTTONDOWN || uMsg == WM_XBUTTONDOWN) + { + action = GLFW_PRESS; + } + else + action = GLFW_RELEASE; + + for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) + { + if (window->mouseButtons[i] == GLFW_PRESS) + break; + } + + if (i > GLFW_MOUSE_BUTTON_LAST) + SetCapture(hWnd); + + _glfwInputMouseClick(window, button, action, getKeyMods()); + + for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) + { + if (window->mouseButtons[i] == GLFW_PRESS) + break; + } + + if (i > GLFW_MOUSE_BUTTON_LAST) + ReleaseCapture(); + + if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) + return TRUE; + + return 0; + } + + case WM_MOUSEMOVE: + { + const int x = GET_X_LPARAM(lParam); + const int y = GET_Y_LPARAM(lParam); + + // Disabled cursor motion input is provided by WM_INPUT + if (window->cursorMode == GLFW_CURSOR_DISABLED) + break; + + _glfwInputCursorPos(window, x, y); + + window->win32.lastCursorPosX = x; + window->win32.lastCursorPosY = y; + + if (!window->win32.cursorTracked) + { + TRACKMOUSEEVENT tme; + ZeroMemory(&tme, sizeof(tme)); + tme.cbSize = sizeof(tme); + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = window->win32.handle; + TrackMouseEvent(&tme); + + window->win32.cursorTracked = GLFW_TRUE; + _glfwInputCursorEnter(window, GLFW_TRUE); + } + + return 0; + } + + case WM_INPUT: + { + UINT size; + HRAWINPUT ri = (HRAWINPUT)lParam; + RAWINPUT* data; + int dx, dy; + + // Only process input when disabled cursor mode is applied + if (_glfw.win32.disabledCursorWindow != window) + break; + + GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); + if (size > (UINT)_glfw.win32.rawInputSize) + { + free(_glfw.win32.rawInput); + _glfw.win32.rawInput = calloc(size, 1); + _glfw.win32.rawInputSize = size; + } + + size = _glfw.win32.rawInputSize; + if (GetRawInputData(ri, RID_INPUT, + _glfw.win32.rawInput, &size, + sizeof(RAWINPUTHEADER)) == (UINT)-1) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Win32: Failed to retrieve raw input data"); + break; + } + + data = _glfw.win32.rawInput; + if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) + { + dx = data->data.mouse.lLastX - window->win32.lastCursorPosX; + dy = data->data.mouse.lLastY - window->win32.lastCursorPosY; + } + else + { + dx = data->data.mouse.lLastX; + dy = data->data.mouse.lLastY; + } + + _glfwInputCursorPos(window, + window->virtualCursorPosX + dx, + window->virtualCursorPosY + dy); + + window->win32.lastCursorPosX += dx; + window->win32.lastCursorPosY += dy; + break; + } + + case WM_MOUSELEAVE: + { + window->win32.cursorTracked = GLFW_FALSE; + _glfwInputCursorEnter(window, GLFW_FALSE); + return 0; + } + + case WM_MOUSEWHEEL: + { + _glfwInputScroll(window, 0.0, (SHORT)HIWORD(wParam) / (double)WHEEL_DELTA); + return 0; + } + + case WM_MOUSEHWHEEL: + { + // This message is only sent on Windows Vista and later + // NOTE: The X-axis is inverted for consistency with macOS and X11 + _glfwInputScroll(window, -((SHORT)HIWORD(wParam) / (double)WHEEL_DELTA), 0.0); + return 0; + } + + case WM_ENTERSIZEMOVE: + case WM_ENTERMENULOOP: + { + // HACK: Postpone cursor disabling while the user is moving or + // resizing the window or using the menu + if (window->cursorMode == GLFW_CURSOR_DISABLED) + _glfwPlatformSetCursorMode(window, GLFW_CURSOR_NORMAL); + + break; + } + + case WM_EXITSIZEMOVE: + case WM_EXITMENULOOP: + { + // HACK: Disable the cursor once the user is done moving or + // resizing the window or using the menu + if (window->cursorMode == GLFW_CURSOR_DISABLED) + _glfwPlatformSetCursorMode(window, GLFW_CURSOR_DISABLED); + + break; + } + + case WM_SIZE: + { + const GLFWbool iconified = wParam == SIZE_MINIMIZED; + const GLFWbool maximized = wParam == SIZE_MAXIMIZED || + (window->win32.maximized && + wParam != SIZE_RESTORED); + + if (_glfw.win32.disabledCursorWindow == window) + updateClipRect(window); + + if (window->win32.iconified != iconified) + _glfwInputWindowIconify(window, iconified); + + if (window->win32.maximized != maximized) + _glfwInputWindowMaximize(window, maximized); + + _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam)); + _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam)); + + if (window->monitor && window->win32.iconified != iconified) + { + if (iconified) + releaseMonitor(window); + else + acquireMonitor(window); + } + + window->win32.iconified = iconified; + window->win32.maximized = maximized; + return 0; + } + + case WM_MOVE: + { + if (_glfw.win32.disabledCursorWindow == window) + updateClipRect(window); + + // NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as + // those macros do not handle negative window positions correctly + _glfwInputWindowPos(window, + GET_X_LPARAM(lParam), + GET_Y_LPARAM(lParam)); + return 0; + } + + case WM_SIZING: + { + if (window->numer == GLFW_DONT_CARE || + window->denom == GLFW_DONT_CARE) + { + break; + } + + applyAspectRatio(window, (int)wParam, (RECT*)lParam); + return TRUE; + } + + case WM_GETMINMAXINFO: + { + int xoff, yoff; + MINMAXINFO* mmi = (MINMAXINFO*)lParam; + + if (window->monitor) + break; + + getFullWindowSize(getWindowStyle(window), getWindowExStyle(window), + 0, 0, &xoff, &yoff); + + if (window->minwidth != GLFW_DONT_CARE && + window->minheight != GLFW_DONT_CARE) + { + mmi->ptMinTrackSize.x = window->minwidth + xoff; + mmi->ptMinTrackSize.y = window->minheight + yoff; + } + + if (window->maxwidth != GLFW_DONT_CARE && + window->maxheight != GLFW_DONT_CARE) + { + mmi->ptMaxTrackSize.x = window->maxwidth + xoff; + mmi->ptMaxTrackSize.y = window->maxheight + yoff; + } if (!window->decorated) { @@ -1033,34 +1033,34 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, return 0; } - case WM_PAINT: - { - _glfwInputWindowDamage(window); - break; - } + case WM_PAINT: + { + _glfwInputWindowDamage(window); + break; + } - case WM_ERASEBKGND: - { - return TRUE; - } + case WM_ERASEBKGND: + { + return TRUE; + } - case WM_DWMCOMPOSITIONCHANGED: - { - if (window->win32.transparent) - updateFramebufferTransparency(window); - return 0; - } + case WM_DWMCOMPOSITIONCHANGED: + { + if (window->win32.transparent) + updateFramebufferTransparency(window); + return 0; + } - case WM_SETCURSOR: - { - if (LOWORD(lParam) == HTCLIENT) - { - updateCursorImage(window); - return TRUE; - } + case WM_SETCURSOR: + { + if (LOWORD(lParam) == HTCLIENT) + { + updateCursorImage(window); + return TRUE; + } - break; - } + break; + } case WM_DROPFILES: { @@ -1068,33 +1068,33 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, POINT pt; int i; - const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0); - char** paths = calloc(count, sizeof(char*)); + const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0); + char** paths = calloc(count, sizeof(char*)); - // Move the mouse to the position of the drop - DragQueryPoint(drop, &pt); - _glfwInputCursorPos(window, pt.x, pt.y); + // Move the mouse to the position of the drop + DragQueryPoint(drop, &pt); + _glfwInputCursorPos(window, pt.x, pt.y); - for (i = 0; i < count; i++) - { - const UINT length = DragQueryFileW(drop, i, NULL, 0); - WCHAR* buffer = calloc(length + 1, sizeof(WCHAR)); + for (i = 0; i < count; i++) + { + const UINT length = DragQueryFileW(drop, i, NULL, 0); + WCHAR* buffer = calloc(length + 1, sizeof(WCHAR)); - DragQueryFileW(drop, i, buffer, length + 1); - paths[i] = _glfwCreateUTF8FromWideStringWin32(buffer); + DragQueryFileW(drop, i, buffer, length + 1); + paths[i] = _glfwCreateUTF8FromWideStringWin32(buffer); - free(buffer); - } + free(buffer); + } - _glfwInputDrop(window, count, (const char**)paths); + _glfwInputDrop(window, count, (const char**)paths); - for (i = 0; i < count; i++) - free(paths[i]); - free(paths); + for (i = 0; i < count; i++) + free(paths[i]); + free(paths); - DragFinish(drop); - return 0; - } + DragFinish(drop); + return 0; + } } return DefWindowProcW(hWnd, uMsg, wParam, lParam); @@ -1103,84 +1103,84 @@ return DefWindowProcW(hWnd, uMsg, wParam, lParam); // Creates the GLFW window // static int createNativeWindow(_GLFWwindow* window, - const _GLFWwndconfig* wndconfig, - const _GLFWfbconfig* fbconfig) + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig) { - int xpos, ypos, fullWidth, fullHeight; - WCHAR* wideTitle; - DWORD style = getWindowStyle(window); - DWORD exStyle = getWindowExStyle(window); + int xpos, ypos, fullWidth, fullHeight; + WCHAR* wideTitle; + DWORD style = getWindowStyle(window); + DWORD exStyle = getWindowExStyle(window); - if (window->monitor) - { - GLFWvidmode mode; + if (window->monitor) + { + GLFWvidmode mode; - // NOTE: This window placement is temporary and approximate, as the - // correct position and size cannot be known until the monitor - // video mode has been picked in _glfwSetVideoModeWin32 - _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); - _glfwPlatformGetVideoMode(window->monitor, &mode); - fullWidth = mode.width; - fullHeight = mode.height; - } - else - { - xpos = CW_USEDEFAULT; - ypos = CW_USEDEFAULT; + // NOTE: This window placement is temporary and approximate, as the + // correct position and size cannot be known until the monitor + // video mode has been picked in _glfwSetVideoModeWin32 + _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); + _glfwPlatformGetVideoMode(window->monitor, &mode); + fullWidth = mode.width; + fullHeight = mode.height; + } + else + { + xpos = CW_USEDEFAULT; + ypos = CW_USEDEFAULT; - if (wndconfig->maximized) - style |= WS_MAXIMIZE; + if (wndconfig->maximized) + style |= WS_MAXIMIZE; - getFullWindowSize(style, exStyle, - wndconfig->width, wndconfig->height, - &fullWidth, &fullHeight); - } + getFullWindowSize(style, exStyle, + wndconfig->width, wndconfig->height, + &fullWidth, &fullHeight); + } - wideTitle = _glfwCreateWideStringFromUTF8Win32(wndconfig->title); - if (!wideTitle) - return GLFW_FALSE; + wideTitle = _glfwCreateWideStringFromUTF8Win32(wndconfig->title); + if (!wideTitle) + return GLFW_FALSE; - window->win32.handle = CreateWindowExW(exStyle, - _GLFW_WNDCLASSNAME, - wideTitle, - style, - xpos, ypos, - fullWidth, fullHeight, - NULL, // No parent window - NULL, // No window menu - GetModuleHandleW(NULL), - NULL); + window->win32.handle = CreateWindowExW(exStyle, + _GLFW_WNDCLASSNAME, + wideTitle, + style, + xpos, ypos, + fullWidth, fullHeight, + NULL, // No parent window + NULL, // No window menu + GetModuleHandleW(NULL), + NULL); - free(wideTitle); + free(wideTitle); - if (!window->win32.handle) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to create window"); - return GLFW_FALSE; - } + if (!window->win32.handle) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create window"); + return GLFW_FALSE; + } - SetPropW(window->win32.handle, L"GLFW", window); + SetPropW(window->win32.handle, L"GLFW", window); - if (IsWindows7OrGreater()) - { - ChangeWindowMessageFilterEx(window->win32.handle, - WM_DROPFILES, MSGFLT_ALLOW, NULL); - ChangeWindowMessageFilterEx(window->win32.handle, - WM_COPYDATA, MSGFLT_ALLOW, NULL); - ChangeWindowMessageFilterEx(window->win32.handle, - WM_COPYGLOBALDATA, MSGFLT_ALLOW, NULL); - } + if (IsWindows7OrGreater()) + { + ChangeWindowMessageFilterEx(window->win32.handle, + WM_DROPFILES, MSGFLT_ALLOW, NULL); + ChangeWindowMessageFilterEx(window->win32.handle, + WM_COPYDATA, MSGFLT_ALLOW, NULL); + ChangeWindowMessageFilterEx(window->win32.handle, + WM_COPYGLOBALDATA, MSGFLT_ALLOW, NULL); + } - DragAcceptFiles(window->win32.handle, TRUE); + DragAcceptFiles(window->win32.handle, TRUE); - if (fbconfig->transparent) - { - updateFramebufferTransparency(window); - window->win32.transparent = GLFW_TRUE; - } + if (fbconfig->transparent) + { + updateFramebufferTransparency(window); + window->win32.transparent = GLFW_TRUE; + } - return GLFW_TRUE; + return GLFW_TRUE; } @@ -1192,57 +1192,57 @@ static int createNativeWindow(_GLFWwindow* window, // GLFWbool _glfwRegisterWindowClassWin32(void) { - WNDCLASSEXW wc; + WNDCLASSEXW wc; - ZeroMemory(&wc, sizeof(wc)); - wc.cbSize = sizeof(wc); - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - wc.lpfnWndProc = (WNDPROC)windowProc; - wc.hInstance = GetModuleHandleW(NULL); - wc.hCursor = LoadCursorW(NULL, IDC_ARROW); - wc.lpszClassName = _GLFW_WNDCLASSNAME; + ZeroMemory(&wc, sizeof(wc)); + wc.cbSize = sizeof(wc); + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = (WNDPROC)windowProc; + wc.hInstance = GetModuleHandleW(NULL); + wc.hCursor = LoadCursorW(NULL, IDC_ARROW); + wc.lpszClassName = _GLFW_WNDCLASSNAME; - // Load user-provided icon if available - wc.hIcon = LoadImageW(GetModuleHandleW(NULL), - L"GLFW_ICON", IMAGE_ICON, - 0, 0, LR_DEFAULTSIZE | LR_SHARED); - if (!wc.hIcon) - { - // No user-provided icon found, load default icon - wc.hIcon = LoadImageW(NULL, - IDI_APPLICATION, IMAGE_ICON, - 0, 0, LR_DEFAULTSIZE | LR_SHARED); - } + // Load user-provided icon if available + wc.hIcon = LoadImageW(GetModuleHandleW(NULL), + L"GLFW_ICON", IMAGE_ICON, + 0, 0, LR_DEFAULTSIZE | LR_SHARED); + if (!wc.hIcon) + { + // No user-provided icon found, load default icon + wc.hIcon = LoadImageW(NULL, + IDI_APPLICATION, IMAGE_ICON, + 0, 0, LR_DEFAULTSIZE | LR_SHARED); + } - if (!RegisterClassExW(&wc)) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to register window class"); - return GLFW_FALSE; - } + if (!RegisterClassExW(&wc)) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to register window class"); + return GLFW_FALSE; + } - return GLFW_TRUE; + return GLFW_TRUE; } // Unregisters the GLFW window class // void _glfwUnregisterWindowClassWin32(void) { - UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL)); + UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL)); } // Returns whether desktop compositing is enabled // GLFWbool _glfwIsCompositionEnabledWin32(void) { - if (IsWindowsVistaOrGreater()) - { - BOOL enabled; - if (SUCCEEDED(DwmIsCompositionEnabled(&enabled))) - return enabled; - } + if (IsWindowsVistaOrGreater()) + { + BOOL enabled; + if (SUCCEEDED(DwmIsCompositionEnabled(&enabled))) + return enabled; + } - return FALSE; + return FALSE; } @@ -1251,234 +1251,234 @@ GLFWbool _glfwIsCompositionEnabledWin32(void) ////////////////////////////////////////////////////////////////////////// int _glfwPlatformCreateWindow(_GLFWwindow* window, - const _GLFWwndconfig* wndconfig, - const _GLFWctxconfig* ctxconfig, - const _GLFWfbconfig* fbconfig) + const _GLFWwndconfig* wndconfig, + const _GLFWctxconfig* ctxconfig, + const _GLFWfbconfig* fbconfig) { - if (!createNativeWindow(window, wndconfig, fbconfig)) - return GLFW_FALSE; + if (!createNativeWindow(window, wndconfig, fbconfig)) + return GLFW_FALSE; - if (ctxconfig->client != GLFW_NO_API) - { - if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API) - { - if (!_glfwInitWGL()) - return GLFW_FALSE; - if (!_glfwCreateContextWGL(window, ctxconfig, fbconfig)) - return GLFW_FALSE; - } - else if (ctxconfig->source == GLFW_EGL_CONTEXT_API) - { - if (!_glfwInitEGL()) - return GLFW_FALSE; - if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) - return GLFW_FALSE; - } - else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API) - { - if (!_glfwInitOSMesa()) - return GLFW_FALSE; - if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) - return GLFW_FALSE; - } - } + if (ctxconfig->client != GLFW_NO_API) + { + if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API) + { + if (!_glfwInitWGL()) + return GLFW_FALSE; + if (!_glfwCreateContextWGL(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } + else if (ctxconfig->source == GLFW_EGL_CONTEXT_API) + { + if (!_glfwInitEGL()) + return GLFW_FALSE; + if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } + else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API) + { + if (!_glfwInitOSMesa()) + return GLFW_FALSE; + if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig)) + return GLFW_FALSE; + } + } - if (window->monitor) - { - _glfwPlatformShowWindow(window); - _glfwPlatformFocusWindow(window); - if (!acquireMonitor(window)) - return GLFW_FALSE; + if (window->monitor) + { + _glfwPlatformShowWindow(window); + _glfwPlatformFocusWindow(window); + if (!acquireMonitor(window)) + return GLFW_FALSE; - if (wndconfig->centerCursor) - centerCursor(window); - } + if (wndconfig->centerCursor) + centerCursor(window); + } - return GLFW_TRUE; + return GLFW_TRUE; } void _glfwPlatformDestroyWindow(_GLFWwindow* window) { - if (window->monitor) - releaseMonitor(window); + if (window->monitor) + releaseMonitor(window); - if (window->context.destroy) - window->context.destroy(window); + if (window->context.destroy) + window->context.destroy(window); - if (_glfw.win32.disabledCursorWindow == window) - _glfw.win32.disabledCursorWindow = NULL; + if (_glfw.win32.disabledCursorWindow == window) + _glfw.win32.disabledCursorWindow = NULL; - if (window->win32.handle) - { - RemovePropW(window->win32.handle, L"GLFW"); - DestroyWindow(window->win32.handle); - window->win32.handle = NULL; - } + if (window->win32.handle) + { + RemovePropW(window->win32.handle, L"GLFW"); + DestroyWindow(window->win32.handle); + window->win32.handle = NULL; + } - if (window->win32.bigIcon) - DestroyIcon(window->win32.bigIcon); + if (window->win32.bigIcon) + DestroyIcon(window->win32.bigIcon); - if (window->win32.smallIcon) - DestroyIcon(window->win32.smallIcon); + if (window->win32.smallIcon) + DestroyIcon(window->win32.smallIcon); } void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { - WCHAR* wideTitle = _glfwCreateWideStringFromUTF8Win32(title); - if (!wideTitle) - return; + WCHAR* wideTitle = _glfwCreateWideStringFromUTF8Win32(title); + if (!wideTitle) + return; - SetWindowTextW(window->win32.handle, wideTitle); - free(wideTitle); + SetWindowTextW(window->win32.handle, wideTitle); + free(wideTitle); } void _glfwPlatformSetWindowIcon(_GLFWwindow* window, - int count, const GLFWimage* images) + int count, const GLFWimage* images) { - HICON bigIcon = NULL, smallIcon = NULL; + HICON bigIcon = NULL, smallIcon = NULL; - if (count) - { - const GLFWimage* bigImage = chooseImage(count, images, - GetSystemMetrics(SM_CXICON), - GetSystemMetrics(SM_CYICON)); - const GLFWimage* smallImage = chooseImage(count, images, - GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON)); + if (count) + { + const GLFWimage* bigImage = chooseImage(count, images, + GetSystemMetrics(SM_CXICON), + GetSystemMetrics(SM_CYICON)); + const GLFWimage* smallImage = chooseImage(count, images, + GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON)); - bigIcon = createIcon(bigImage, 0, 0, GLFW_TRUE); - smallIcon = createIcon(smallImage, 0, 0, GLFW_TRUE); - } - else - { - bigIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICON); - smallIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICONSM); - } + bigIcon = createIcon(bigImage, 0, 0, GLFW_TRUE); + smallIcon = createIcon(smallImage, 0, 0, GLFW_TRUE); + } + else + { + bigIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICON); + smallIcon = (HICON)GetClassLongPtrW(window->win32.handle, GCLP_HICONSM); + } - SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM)bigIcon); - SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon); + SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM)bigIcon); + SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM)smallIcon); - if (window->win32.bigIcon) - DestroyIcon(window->win32.bigIcon); + if (window->win32.bigIcon) + DestroyIcon(window->win32.bigIcon); - if (window->win32.smallIcon) - DestroyIcon(window->win32.smallIcon); + if (window->win32.smallIcon) + DestroyIcon(window->win32.smallIcon); - if (count) - { - window->win32.bigIcon = bigIcon; - window->win32.smallIcon = smallIcon; - } + if (count) + { + window->win32.bigIcon = bigIcon; + window->win32.smallIcon = smallIcon; + } } void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos) { - POINT pos = { 0, 0 }; - ClientToScreen(window->win32.handle, &pos); + POINT pos = { 0, 0 }; + ClientToScreen(window->win32.handle, &pos); - if (xpos) - *xpos = pos.x; - if (ypos) - *ypos = pos.y; + if (xpos) + *xpos = pos.x; + if (ypos) + *ypos = pos.y; } void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos) { - RECT rect = { xpos, ypos, xpos, ypos }; - AdjustWindowRectEx(&rect, getWindowStyle(window), - FALSE, getWindowExStyle(window)); - SetWindowPos(window->win32.handle, NULL, rect.left, rect.top, 0, 0, - SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE); + RECT rect = { xpos, ypos, xpos, ypos }; + AdjustWindowRectEx(&rect, getWindowStyle(window), + FALSE, getWindowExStyle(window)); + SetWindowPos(window->win32.handle, NULL, rect.left, rect.top, 0, 0, + SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE); } void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) { - RECT area; - GetClientRect(window->win32.handle, &area); + RECT area; + GetClientRect(window->win32.handle, &area); - if (width) - *width = area.right; - if (height) - *height = area.bottom; + if (width) + *width = area.right; + if (height) + *height = area.bottom; } void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - if (window->monitor) - { - if (window->monitor->window == window) - acquireMonitor(window); - } - else - { - RECT rect = { 0, 0, width, height }; - AdjustWindowRectEx(&rect, getWindowStyle(window), - FALSE, getWindowExStyle(window)); - SetWindowPos(window->win32.handle, HWND_TOP, - 0, 0, rect.right - rect.left, rect.bottom - rect.top, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER); - } + if (window->monitor) + { + if (window->monitor->window == window) + acquireMonitor(window); + } + else + { + RECT rect = { 0, 0, width, height }; + AdjustWindowRectEx(&rect, getWindowStyle(window), + FALSE, getWindowExStyle(window)); + SetWindowPos(window->win32.handle, HWND_TOP, + 0, 0, rect.right - rect.left, rect.bottom - rect.top, + SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER); + } } void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window, - int minwidth, int minheight, - int maxwidth, int maxheight) + int minwidth, int minheight, + int maxwidth, int maxheight) { - RECT area; + RECT area; - if ((minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE) && - (maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE)) - { - return; - } + if ((minwidth == GLFW_DONT_CARE || minheight == GLFW_DONT_CARE) && + (maxwidth == GLFW_DONT_CARE || maxheight == GLFW_DONT_CARE)) + { + return; + } - GetWindowRect(window->win32.handle, &area); - MoveWindow(window->win32.handle, - area.left, area.top, - area.right - area.left, - area.bottom - area.top, TRUE); + GetWindowRect(window->win32.handle, &area); + MoveWindow(window->win32.handle, + area.left, area.top, + area.right - area.left, + area.bottom - area.top, TRUE); } void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom) { - RECT area; + RECT area; - if (numer == GLFW_DONT_CARE || denom == GLFW_DONT_CARE) - return; + if (numer == GLFW_DONT_CARE || denom == GLFW_DONT_CARE) + return; - GetWindowRect(window->win32.handle, &area); - applyAspectRatio(window, WMSZ_BOTTOMRIGHT, &area); - MoveWindow(window->win32.handle, - area.left, area.top, - area.right - area.left, - area.bottom - area.top, TRUE); + GetWindowRect(window->win32.handle, &area); + applyAspectRatio(window, WMSZ_BOTTOMRIGHT, &area); + MoveWindow(window->win32.handle, + area.left, area.top, + area.right - area.left, + area.bottom - area.top, TRUE); } void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height) { - _glfwPlatformGetWindowSize(window, width, height); + _glfwPlatformGetWindowSize(window, width, height); } void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, - int* left, int* top, - int* right, int* bottom) + int* left, int* top, + int* right, int* bottom) { - RECT rect; - int width, height; + RECT rect; + int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - SetRect(&rect, 0, 0, width, height); - AdjustWindowRectEx(&rect, getWindowStyle(window), - FALSE, getWindowExStyle(window)); + _glfwPlatformGetWindowSize(window, &width, &height); + SetRect(&rect, 0, 0, width, height); + AdjustWindowRectEx(&rect, getWindowStyle(window), + FALSE, getWindowExStyle(window)); - if (left) - *left = -rect.left; - if (top) - *top = -rect.top; - if (right) - *right = rect.right - width; - if (bottom) - *bottom = rect.bottom - height; + if (left) + *left = -rect.left; + if (top) + *top = -rect.top; + if (right) + *right = rect.right - width; + if (bottom) + *bottom = rect.bottom - height; } void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, @@ -1491,70 +1491,70 @@ void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, void _glfwPlatformIconifyWindow(_GLFWwindow* window) { - ShowWindow(window->win32.handle, SW_MINIMIZE); + ShowWindow(window->win32.handle, SW_MINIMIZE); } void _glfwPlatformRestoreWindow(_GLFWwindow* window) { - ShowWindow(window->win32.handle, SW_RESTORE); + ShowWindow(window->win32.handle, SW_RESTORE); } void _glfwPlatformMaximizeWindow(_GLFWwindow* window) { - ShowWindow(window->win32.handle, SW_MAXIMIZE); + ShowWindow(window->win32.handle, SW_MAXIMIZE); } void _glfwPlatformShowWindow(_GLFWwindow* window) { - ShowWindow(window->win32.handle, SW_SHOW); + ShowWindow(window->win32.handle, SW_SHOW); } void _glfwPlatformHideWindow(_GLFWwindow* window) { - ShowWindow(window->win32.handle, SW_HIDE); + ShowWindow(window->win32.handle, SW_HIDE); } void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) { - FlashWindow(window->win32.handle, TRUE); + FlashWindow(window->win32.handle, TRUE); } void _glfwPlatformFocusWindow(_GLFWwindow* window) { - BringWindowToTop(window->win32.handle); - SetForegroundWindow(window->win32.handle); - SetFocus(window->win32.handle); + BringWindowToTop(window->win32.handle); + SetForegroundWindow(window->win32.handle); + SetFocus(window->win32.handle); } void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, - _GLFWmonitor* monitor, - int xpos, int ypos, - int width, int height, - int refreshRate) + _GLFWmonitor* monitor, + int xpos, int ypos, + int width, int height, + int refreshRate) { - if (window->monitor == monitor) - { - if (monitor) - { - if (monitor->window == window) - acquireMonitor(window); - } - else - { - RECT rect = { xpos, ypos, xpos + width, ypos + height }; - AdjustWindowRectEx(&rect, getWindowStyle(window), - FALSE, getWindowExStyle(window)); - SetWindowPos(window->win32.handle, HWND_TOP, - rect.left, rect.top, - rect.right - rect.left, rect.bottom - rect.top, - SWP_NOCOPYBITS | SWP_NOACTIVATE | SWP_NOZORDER); - } + if (window->monitor == monitor) + { + if (monitor) + { + if (monitor->window == window) + acquireMonitor(window); + } + else + { + RECT rect = { xpos, ypos, xpos + width, ypos + height }; + AdjustWindowRectEx(&rect, getWindowStyle(window), + FALSE, getWindowExStyle(window)); + SetWindowPos(window->win32.handle, HWND_TOP, + rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + SWP_NOCOPYBITS | SWP_NOACTIVATE | SWP_NOZORDER); + } - return; - } + return; + } - if (window->monitor) - releaseMonitor(window); + if (window->monitor) + releaseMonitor(window); _glfwInputWindowMonitor(window, monitor); @@ -1607,44 +1607,44 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, int _glfwPlatformWindowFocused(_GLFWwindow* window) { - return window->win32.handle == GetActiveWindow(); + return window->win32.handle == GetActiveWindow(); } int _glfwPlatformWindowIconified(_GLFWwindow* window) { - return IsIconic(window->win32.handle); + return IsIconic(window->win32.handle); } int _glfwPlatformWindowVisible(_GLFWwindow* window) { - return IsWindowVisible(window->win32.handle); + return IsWindowVisible(window->win32.handle); } int _glfwPlatformWindowMaximized(_GLFWwindow* window) { - return IsZoomed(window->win32.handle); + return IsZoomed(window->win32.handle); } int _glfwPlatformFramebufferTransparent(_GLFWwindow* window) { - return window->win32.transparent && _glfwIsCompositionEnabledWin32(); + return window->win32.transparent && _glfwIsCompositionEnabledWin32(); } void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled) { - updateWindowStyles(window); + updateWindowStyles(window); } void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled) { - updateWindowStyles(window); + updateWindowStyles(window); } void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled) { - const HWND after = enabled ? HWND_TOPMOST : HWND_NOTOPMOST; - SetWindowPos(window->win32.handle, after, 0, 0, 0, 0, - SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); + const HWND after = enabled ? HWND_TOPMOST : HWND_NOTOPMOST; + SetWindowPos(window->win32.handle, after, 0, 0, 0, 0, + SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); } float _glfwPlatformGetWindowOpacity(_GLFWwindow* window) @@ -1682,350 +1682,350 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity) void _glfwPlatformPollEvents(void) { - MSG msg; - HWND handle; - _GLFWwindow* window; + MSG msg; + HWND handle; + _GLFWwindow* window; - while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) - { - if (msg.message == WM_QUIT) - { - // NOTE: While GLFW does not itself post WM_QUIT, other processes - // may post it to this one, for example Task Manager - // HACK: Treat WM_QUIT as a close on all windows + while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_QUIT) + { + // NOTE: While GLFW does not itself post WM_QUIT, other processes + // may post it to this one, for example Task Manager + // HACK: Treat WM_QUIT as a close on all windows - window = _glfw.windowListHead; - while (window) - { - _glfwInputWindowCloseRequest(window); - window = window->next; - } - } - else - { - TranslateMessage(&msg); - DispatchMessageW(&msg); - } - } + window = _glfw.windowListHead; + while (window) + { + _glfwInputWindowCloseRequest(window); + window = window->next; + } + } + else + { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } - handle = GetActiveWindow(); - if (handle) - { - // NOTE: Shift keys on Windows tend to "stick" when both are pressed as - // no key up message is generated by the first key release - // The other half of this is in the handling of WM_KEYUP - // HACK: Query actual key state and synthesize release events as needed - window = GetPropW(handle, L"GLFW"); - if (window) - { - const GLFWbool lshift = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1; - const GLFWbool rshift = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1; + handle = GetActiveWindow(); + if (handle) + { + // NOTE: Shift keys on Windows tend to "stick" when both are pressed as + // no key up message is generated by the first key release + // The other half of this is in the handling of WM_KEYUP + // HACK: Query actual key state and synthesize release events as needed + window = GetPropW(handle, L"GLFW"); + if (window) + { + const GLFWbool lshift = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1; + const GLFWbool rshift = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1; - if (!lshift && window->keys[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS) - { - const int mods = getAsyncKeyMods(); - const int scancode = _glfw.win32.scancodes[GLFW_KEY_LEFT_SHIFT]; - _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods); - } - else if (!rshift && window->keys[GLFW_KEY_RIGHT_SHIFT] == GLFW_PRESS) - { - const int mods = getAsyncKeyMods(); - const int scancode = _glfw.win32.scancodes[GLFW_KEY_RIGHT_SHIFT]; - _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods); - } - } - } + if (!lshift && window->keys[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS) + { + const int mods = getAsyncKeyMods(); + const int scancode = _glfw.win32.scancodes[GLFW_KEY_LEFT_SHIFT]; + _glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods); + } + else if (!rshift && window->keys[GLFW_KEY_RIGHT_SHIFT] == GLFW_PRESS) + { + const int mods = getAsyncKeyMods(); + const int scancode = _glfw.win32.scancodes[GLFW_KEY_RIGHT_SHIFT]; + _glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods); + } + } + } - window = _glfw.win32.disabledCursorWindow; - if (window) - { - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); + window = _glfw.win32.disabledCursorWindow; + if (window) + { + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); - // NOTE: Re-center the cursor only if it has moved since the last call, - // to avoid breaking glfwWaitEvents with WM_MOUSEMOVE - if (window->win32.lastCursorPosX != width / 2 || - window->win32.lastCursorPosY != height / 2) - { - _glfwPlatformSetCursorPos(window, width / 2, height / 2); - } - } + // NOTE: Re-center the cursor only if it has moved since the last call, + // to avoid breaking glfwWaitEvents with WM_MOUSEMOVE + if (window->win32.lastCursorPosX != width / 2 || + window->win32.lastCursorPosY != height / 2) + { + _glfwPlatformSetCursorPos(window, width / 2, height / 2); + } + } } void _glfwPlatformWaitEvents(void) { - WaitMessage(); + WaitMessage(); - _glfwPlatformPollEvents(); + _glfwPlatformPollEvents(); } void _glfwPlatformWaitEventsTimeout(double timeout) { - MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD)(timeout * 1e3), QS_ALLEVENTS); + MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD)(timeout * 1e3), QS_ALLEVENTS); - _glfwPlatformPollEvents(); + _glfwPlatformPollEvents(); } void _glfwPlatformPostEmptyEvent(void) { - PostMessage(_glfw.win32.helperWindowHandle, WM_NULL, 0, 0); + PostMessage(_glfw.win32.helperWindowHandle, WM_NULL, 0, 0); } void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) { - POINT pos; + POINT pos; - if (GetCursorPos(&pos)) - { - ScreenToClient(window->win32.handle, &pos); + if (GetCursorPos(&pos)) + { + ScreenToClient(window->win32.handle, &pos); - if (xpos) - *xpos = pos.x; - if (ypos) - *ypos = pos.y; - } + if (xpos) + *xpos = pos.x; + if (ypos) + *ypos = pos.y; + } } void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos) { - POINT pos = { (int)xpos, (int)ypos }; + POINT pos = { (int)xpos, (int)ypos }; - // Store the new position so it can be recognized later - window->win32.lastCursorPosX = pos.x; - window->win32.lastCursorPosY = pos.y; + // Store the new position so it can be recognized later + window->win32.lastCursorPosX = pos.x; + window->win32.lastCursorPosY = pos.y; - ClientToScreen(window->win32.handle, &pos); - SetCursorPos(pos.x, pos.y); + ClientToScreen(window->win32.handle, &pos); + SetCursorPos(pos.x, pos.y); } void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) { - if (mode == GLFW_CURSOR_DISABLED) - { - const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle }; + if (mode == GLFW_CURSOR_DISABLED) + { + const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle }; - _glfw.win32.disabledCursorWindow = window; - _glfwPlatformGetCursorPos(window, - &_glfw.win32.restoreCursorPosX, - &_glfw.win32.restoreCursorPosY); - centerCursor(window); - updateClipRect(window); + _glfw.win32.disabledCursorWindow = window; + _glfwPlatformGetCursorPos(window, + &_glfw.win32.restoreCursorPosX, + &_glfw.win32.restoreCursorPosY); + centerCursor(window); + updateClipRect(window); - if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to register raw input device"); - } - } - else if (_glfw.win32.disabledCursorWindow == window) - { - const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE, NULL }; + if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to register raw input device"); + } + } + else if (_glfw.win32.disabledCursorWindow == window) + { + const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE, NULL }; - _glfw.win32.disabledCursorWindow = NULL; - updateClipRect(NULL); - _glfwPlatformSetCursorPos(window, - _glfw.win32.restoreCursorPosX, - _glfw.win32.restoreCursorPosY); + _glfw.win32.disabledCursorWindow = NULL; + updateClipRect(NULL); + _glfwPlatformSetCursorPos(window, + _glfw.win32.restoreCursorPosX, + _glfw.win32.restoreCursorPosY); - if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to remove raw input device"); - } - } + if (!RegisterRawInputDevices(&rid, 1, sizeof(rid))) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to remove raw input device"); + } + } - if (cursorInClientArea(window)) - updateCursorImage(window); + if (cursorInClientArea(window)) + updateCursorImage(window); } const char* _glfwPlatformGetScancodeName(int scancode) { - return _glfw.win32.keynames[_glfw.win32.keycodes[scancode]]; + return _glfw.win32.keynames[_glfw.win32.keycodes[scancode]]; } int _glfwPlatformGetKeyScancode(int key) { - return _glfw.win32.scancodes[key]; + return _glfw.win32.scancodes[key]; } int _glfwPlatformCreateCursor(_GLFWcursor* cursor, - const GLFWimage* image, - int xhot, int yhot) + const GLFWimage* image, + int xhot, int yhot) { - cursor->win32.handle = (HCURSOR)createIcon(image, xhot, yhot, GLFW_FALSE); - if (!cursor->win32.handle) - return GLFW_FALSE; + cursor->win32.handle = (HCURSOR)createIcon(image, xhot, yhot, GLFW_FALSE); + if (!cursor->win32.handle) + return GLFW_FALSE; - return GLFW_TRUE; + return GLFW_TRUE; } int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape) { - cursor->win32.handle = - CopyCursor(LoadCursorW(NULL, translateCursorShape(shape))); - if (!cursor->win32.handle) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to create standard cursor"); - return GLFW_FALSE; - } + cursor->win32.handle = + CopyCursor(LoadCursorW(NULL, translateCursorShape(shape))); + if (!cursor->win32.handle) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to create standard cursor"); + return GLFW_FALSE; + } - return GLFW_TRUE; + return GLFW_TRUE; } void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) { - if (cursor->win32.handle) - DestroyIcon((HICON)cursor->win32.handle); + if (cursor->win32.handle) + DestroyIcon((HICON)cursor->win32.handle); } void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) { - if (cursorInClientArea(window)) - updateCursorImage(window); + if (cursorInClientArea(window)) + updateCursorImage(window); } void _glfwPlatformSetClipboardString(const char* string) { - int characterCount; - HANDLE object; - WCHAR* buffer; + int characterCount; + HANDLE object; + WCHAR* buffer; - characterCount = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0); - if (!characterCount) - return; + characterCount = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0); + if (!characterCount) + return; - object = GlobalAlloc(GMEM_MOVEABLE, characterCount * sizeof(WCHAR)); - if (!object) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to allocate global handle for clipboard"); - return; - } + object = GlobalAlloc(GMEM_MOVEABLE, characterCount * sizeof(WCHAR)); + if (!object) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to allocate global handle for clipboard"); + return; + } - buffer = GlobalLock(object); - if (!buffer) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to lock global handle"); - GlobalFree(object); - return; - } + buffer = GlobalLock(object); + if (!buffer) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to lock global handle"); + GlobalFree(object); + return; + } - MultiByteToWideChar(CP_UTF8, 0, string, -1, buffer, characterCount); - GlobalUnlock(object); + MultiByteToWideChar(CP_UTF8, 0, string, -1, buffer, characterCount); + GlobalUnlock(object); - if (!OpenClipboard(_glfw.win32.helperWindowHandle)) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to open clipboard"); - GlobalFree(object); - return; - } + if (!OpenClipboard(_glfw.win32.helperWindowHandle)) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to open clipboard"); + GlobalFree(object); + return; + } - EmptyClipboard(); - SetClipboardData(CF_UNICODETEXT, object); - CloseClipboard(); + EmptyClipboard(); + SetClipboardData(CF_UNICODETEXT, object); + CloseClipboard(); } const char* _glfwPlatformGetClipboardString(void) { - HANDLE object; - WCHAR* buffer; + HANDLE object; + WCHAR* buffer; - if (!OpenClipboard(_glfw.win32.helperWindowHandle)) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to open clipboard"); - return NULL; - } + if (!OpenClipboard(_glfw.win32.helperWindowHandle)) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to open clipboard"); + return NULL; + } - object = GetClipboardData(CF_UNICODETEXT); - if (!object) - { - _glfwInputErrorWin32(GLFW_FORMAT_UNAVAILABLE, - "Win32: Failed to convert clipboard to string"); - CloseClipboard(); - return NULL; - } + object = GetClipboardData(CF_UNICODETEXT); + if (!object) + { + _glfwInputErrorWin32(GLFW_FORMAT_UNAVAILABLE, + "Win32: Failed to convert clipboard to string"); + CloseClipboard(); + return NULL; + } - buffer = GlobalLock(object); - if (!buffer) - { - _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, - "Win32: Failed to lock global handle"); - CloseClipboard(); - return NULL; - } + buffer = GlobalLock(object); + if (!buffer) + { + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "Win32: Failed to lock global handle"); + CloseClipboard(); + return NULL; + } - free(_glfw.win32.clipboardString); - _glfw.win32.clipboardString = _glfwCreateUTF8FromWideStringWin32(buffer); + free(_glfw.win32.clipboardString); + _glfw.win32.clipboardString = _glfwCreateUTF8FromWideStringWin32(buffer); - GlobalUnlock(object); - CloseClipboard(); + GlobalUnlock(object); + CloseClipboard(); - return _glfw.win32.clipboardString; + return _glfw.win32.clipboardString; } void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_win32_surface) - return; + if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_win32_surface) + return; - extensions[0] = "VK_KHR_surface"; - extensions[1] = "VK_KHR_win32_surface"; + extensions[0] = "VK_KHR_surface"; + extensions[1] = "VK_KHR_win32_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, - VkPhysicalDevice device, - uint32_t queuefamily) + VkPhysicalDevice device, + uint32_t queuefamily) { - PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR - vkGetPhysicalDeviceWin32PresentationSupportKHR = - (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) - vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); - if (!vkGetPhysicalDeviceWin32PresentationSupportKHR) - { - _glfwInputError(GLFW_API_UNAVAILABLE, - "Win32: Vulkan instance missing VK_KHR_win32_surface extension"); - return GLFW_FALSE; - } + PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR + vkGetPhysicalDeviceWin32PresentationSupportKHR = + (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) + vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); + if (!vkGetPhysicalDeviceWin32PresentationSupportKHR) + { + _glfwInputError(GLFW_API_UNAVAILABLE, + "Win32: Vulkan instance missing VK_KHR_win32_surface extension"); + return GLFW_FALSE; + } - return vkGetPhysicalDeviceWin32PresentationSupportKHR(device, queuefamily); + return vkGetPhysicalDeviceWin32PresentationSupportKHR(device, queuefamily); } VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, - _GLFWwindow* window, - const VkAllocationCallbacks* allocator, - VkSurfaceKHR* surface) + _GLFWwindow* window, + const VkAllocationCallbacks* allocator, + VkSurfaceKHR* surface) { - VkResult err; - VkWin32SurfaceCreateInfoKHR sci; - PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR; + VkResult err; + VkWin32SurfaceCreateInfoKHR sci; + PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR; - vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) - vkGetInstanceProcAddr(instance, "vkCreateWin32SurfaceKHR"); - if (!vkCreateWin32SurfaceKHR) - { - _glfwInputError(GLFW_API_UNAVAILABLE, - "Win32: Vulkan instance missing VK_KHR_win32_surface extension"); - return VK_ERROR_EXTENSION_NOT_PRESENT; - } + vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) + vkGetInstanceProcAddr(instance, "vkCreateWin32SurfaceKHR"); + if (!vkCreateWin32SurfaceKHR) + { + _glfwInputError(GLFW_API_UNAVAILABLE, + "Win32: Vulkan instance missing VK_KHR_win32_surface extension"); + return VK_ERROR_EXTENSION_NOT_PRESENT; + } - memset(&sci, 0, sizeof(sci)); - sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; - sci.hinstance = GetModuleHandle(NULL); - sci.hwnd = window->win32.handle; + memset(&sci, 0, sizeof(sci)); + sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; + sci.hinstance = GetModuleHandle(NULL); + sci.hwnd = window->win32.handle; - err = vkCreateWin32SurfaceKHR(instance, &sci, allocator, surface); - if (err) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Win32: Failed to create Vulkan surface: %s", - _glfwGetVulkanResultString(err)); - } + err = vkCreateWin32SurfaceKHR(instance, &sci, allocator, surface); + if (err) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Win32: Failed to create Vulkan surface: %s", + _glfwGetVulkanResultString(err)); + } - return err; + return err; } @@ -2035,8 +2035,8 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) { - _GLFWwindow* window = (_GLFWwindow*)handle; - _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return window->win32.handle; + _GLFWwindow* window = (_GLFWwindow*)handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + return window->win32.handle; }