2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2019-04-16 12:43:29 +00:00
|
|
|
// GLFW 3.4 Win32 - www.glfw.org
|
2010-09-07 15:34:51 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
2019-04-15 18:50:00 +00:00
|
|
|
// Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
|
2010-09-07 15:34:51 +00:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
2019-05-20 13:24:14 +00:00
|
|
|
// Please use C89 style variable declarations in this file because VS 2010
|
|
|
|
//========================================================================
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2016-03-07 13:55:30 +00:00
|
|
|
#include <limits.h>
|
2010-09-13 23:05:03 +00:00
|
|
|
#include <stdlib.h>
|
2012-08-14 11:51:39 +00:00
|
|
|
#include <malloc.h>
|
2014-09-09 14:26:57 +00:00
|
|
|
#include <string.h>
|
2012-09-12 19:37:36 +00:00
|
|
|
#include <windowsx.h>
|
2013-12-22 15:47:03 +00:00
|
|
|
#include <shellapi.h>
|
2010-09-13 21:50:04 +00:00
|
|
|
|
2013-05-30 15:19:12 +00:00
|
|
|
#define _GLFW_KEY_INVALID -2
|
|
|
|
|
2015-06-02 19:12:37 +00:00
|
|
|
// Returns the window style for the specified window
|
|
|
|
//
|
2015-07-04 23:13:52 +00:00
|
|
|
static DWORD getWindowStyle(const _GLFWwindow* window)
|
2015-06-02 19:12:37 +00:00
|
|
|
{
|
|
|
|
DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->monitor)
|
|
|
|
style |= WS_POPUP;
|
|
|
|
else
|
2015-06-02 19:12:37 +00:00
|
|
|
{
|
2016-09-14 11:05:13 +00:00
|
|
|
style |= WS_SYSMENU | WS_MINIMIZEBOX;
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->decorated)
|
|
|
|
{
|
2016-09-14 11:05:13 +00:00
|
|
|
style |= WS_CAPTION;
|
2015-06-02 19:12:37 +00:00
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->resizable)
|
|
|
|
style |= WS_MAXIMIZEBOX | WS_THICKFRAME;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
style |= WS_POPUP;
|
2015-06-02 19:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the extended window style for the specified window
|
|
|
|
//
|
2015-07-04 23:13:52 +00:00
|
|
|
static DWORD getWindowExStyle(const _GLFWwindow* window)
|
2015-06-02 19:12:37 +00:00
|
|
|
{
|
|
|
|
DWORD style = WS_EX_APPWINDOW;
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->monitor || window->floating)
|
|
|
|
style |= WS_EX_TOPMOST;
|
2015-06-02 19:12:37 +00:00
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2016-03-07 13:55:30 +00:00
|
|
|
// 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 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates an RGBA icon or cursor
|
|
|
|
//
|
|
|
|
static HICON createIcon(const GLFWimage* image,
|
|
|
|
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;
|
|
|
|
|
|
|
|
ZeroMemory(&bi, sizeof(bi));
|
2017-08-27 21:09:08 +00:00
|
|
|
bi.bV5Size = sizeof(bi);
|
2016-03-07 13:55:30 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (!color)
|
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create RGBA bitmap");
|
2016-03-07 13:55:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = CreateBitmap(image->width, image->height, 1, 1, NULL);
|
|
|
|
if (!mask)
|
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create mask bitmap");
|
2016-03-07 13:55:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(&ii, sizeof(ii));
|
|
|
|
ii.fIcon = icon;
|
|
|
|
ii.xHotspot = xhot;
|
|
|
|
ii.yHotspot = yhot;
|
|
|
|
ii.hbmMask = mask;
|
|
|
|
ii.hbmColor = color;
|
|
|
|
|
|
|
|
handle = CreateIconIndirect(&ii);
|
|
|
|
|
|
|
|
DeleteObject(color);
|
|
|
|
DeleteObject(mask);
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
if (icon)
|
2017-01-19 19:29:27 +00:00
|
|
|
{
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create icon");
|
|
|
|
}
|
2016-03-07 13:55:30 +00:00
|
|
|
else
|
2017-01-19 19:29:27 +00:00
|
|
|
{
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create cursor");
|
|
|
|
}
|
2016-03-07 13:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:54:16 +00:00
|
|
|
// Translate content area size to full window size according to styles and DPI
|
2014-02-13 01:57:59 +00:00
|
|
|
//
|
2015-10-18 15:01:14 +00:00
|
|
|
static void getFullWindowSize(DWORD style, DWORD exStyle,
|
2019-01-22 19:54:16 +00:00
|
|
|
int contentWidth, int contentHeight,
|
2018-06-07 17:01:07 +00:00
|
|
|
int* fullWidth, int* fullHeight,
|
|
|
|
UINT dpi)
|
2014-02-13 01:57:59 +00:00
|
|
|
{
|
2019-01-22 19:54:16 +00:00
|
|
|
RECT rect = { 0, 0, contentWidth, contentHeight };
|
2018-06-07 17:01:07 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle, dpi);
|
|
|
|
else
|
|
|
|
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
|
|
|
|
|
2014-02-13 01:57:59 +00:00
|
|
|
*fullWidth = rect.right - rect.left;
|
|
|
|
*fullHeight = rect.bottom - rect.top;
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:54:16 +00:00
|
|
|
// Enforce the content area aspect ratio based on which edge is being dragged
|
2014-02-13 01:57:59 +00:00
|
|
|
//
|
|
|
|
static void applyAspectRatio(_GLFWwindow* window, int edge, RECT* area)
|
|
|
|
{
|
|
|
|
int xoff, yoff;
|
2018-10-21 12:35:48 +00:00
|
|
|
UINT dpi = USER_DEFAULT_SCREEN_DPI;
|
2016-02-23 11:26:42 +00:00
|
|
|
const float ratio = (float) window->numer / (float) window->denom;
|
2014-02-13 01:57:59 +00:00
|
|
|
|
2018-10-21 12:35:48 +00:00
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
dpi = GetDpiForWindow(window->win32.handle);
|
|
|
|
|
2015-10-18 15:01:14 +00:00
|
|
|
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
|
2018-10-21 12:35:48 +00:00
|
|
|
0, 0, &xoff, &yoff, dpi);
|
2014-02-13 01:57:59 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 19:21:09 +00:00
|
|
|
// Updates the cursor image according to its cursor mode
|
2016-05-25 12:06:02 +00:00
|
|
|
//
|
2016-05-30 19:21:09 +00:00
|
|
|
static void updateCursorImage(_GLFWwindow* window)
|
2016-05-25 12:06:02 +00:00
|
|
|
{
|
2016-05-30 19:21:09 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_NORMAL)
|
2016-05-25 12:06:02 +00:00
|
|
|
{
|
|
|
|
if (window->cursor)
|
|
|
|
SetCursor(window->cursor->win32.handle);
|
|
|
|
else
|
|
|
|
SetCursor(LoadCursorW(NULL, IDC_ARROW));
|
|
|
|
}
|
|
|
|
else
|
2016-05-30 19:21:09 +00:00
|
|
|
SetCursor(NULL);
|
2016-05-25 12:06:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-20 16:29:06 +00:00
|
|
|
// Updates the cursor clip rect
|
|
|
|
//
|
|
|
|
static void updateClipRect(_GLFWwindow* window)
|
|
|
|
{
|
2016-05-25 12:06:02 +00:00
|
|
|
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);
|
2013-02-20 16:29:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 18:10:20 +00:00
|
|
|
// Enables WM_INPUT messages for the mouse for the specified window
|
2018-04-17 17:54:36 +00:00
|
|
|
//
|
2019-02-11 18:10:20 +00:00
|
|
|
static void enableRawMouseMotion(_GLFWwindow* window)
|
2018-04-17 17:54:36 +00:00
|
|
|
{
|
|
|
|
const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle };
|
|
|
|
|
2019-02-11 18:10:20 +00:00
|
|
|
if (!RegisterRawInputDevices(&rid, 1, sizeof(rid)))
|
|
|
|
{
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to register raw input device");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disables WM_INPUT messages for the mouse
|
|
|
|
//
|
|
|
|
static void disableRawMouseMotion(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE, NULL };
|
|
|
|
|
|
|
|
if (!RegisterRawInputDevices(&rid, 1, sizeof(rid)))
|
|
|
|
{
|
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to remove raw input device");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply disabled cursor mode to a focused window
|
|
|
|
//
|
|
|
|
static void disableCursor(_GLFWwindow* window)
|
|
|
|
{
|
2018-04-17 17:54:36 +00:00
|
|
|
_glfw.win32.disabledCursorWindow = window;
|
|
|
|
_glfwPlatformGetCursorPos(window,
|
|
|
|
&_glfw.win32.restoreCursorPosX,
|
|
|
|
&_glfw.win32.restoreCursorPosY);
|
|
|
|
updateCursorImage(window);
|
2019-01-22 19:54:16 +00:00
|
|
|
_glfwCenterCursorInContentArea(window);
|
2018-04-17 17:54:36 +00:00
|
|
|
updateClipRect(window);
|
|
|
|
|
2019-02-11 18:10:20 +00:00
|
|
|
if (window->rawMouseMotion)
|
|
|
|
enableRawMouseMotion(window);
|
2018-04-17 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exit disabled cursor mode for the specified window
|
|
|
|
//
|
|
|
|
static void enableCursor(_GLFWwindow* window)
|
|
|
|
{
|
2019-02-11 18:10:20 +00:00
|
|
|
if (window->rawMouseMotion)
|
|
|
|
disableRawMouseMotion(window);
|
2018-04-17 17:54:36 +00:00
|
|
|
|
|
|
|
_glfw.win32.disabledCursorWindow = NULL;
|
|
|
|
updateClipRect(NULL);
|
|
|
|
_glfwPlatformSetCursorPos(window,
|
|
|
|
_glfw.win32.restoreCursorPosX,
|
|
|
|
_glfw.win32.restoreCursorPosY);
|
|
|
|
updateCursorImage(window);
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:54:16 +00:00
|
|
|
// Returns whether the cursor is in the content area of the specified window
|
2018-04-17 17:54:36 +00:00
|
|
|
//
|
2019-01-22 19:54:16 +00:00
|
|
|
static GLFWbool cursorInContentArea(_GLFWwindow* window)
|
2018-04-17 17:54:36 +00:00
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
if (!GetCursorPos(&pos))
|
|
|
|
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);
|
|
|
|
|
|
|
|
return PtInRect(&area, pos);
|
|
|
|
}
|
|
|
|
|
2016-09-29 23:52:22 +00:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
GetClientRect(window->win32.handle, &rect);
|
2018-06-07 17:01:07 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, style, FALSE,
|
|
|
|
getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
AdjustWindowRectEx(&rect, style, FALSE, getWindowExStyle(window));
|
|
|
|
|
2016-09-29 23:52:22 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-18 16:10:57 +00:00
|
|
|
// Update window framebuffer transparency
|
|
|
|
//
|
|
|
|
static void updateFramebufferTransparency(const _GLFWwindow* window)
|
|
|
|
{
|
2018-08-12 11:58:30 +00:00
|
|
|
BOOL enabled;
|
|
|
|
|
2017-09-18 16:10:57 +00:00
|
|
|
if (!IsWindowsVistaOrGreater())
|
|
|
|
return;
|
|
|
|
|
2018-08-12 11:58:30 +00:00
|
|
|
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
2017-09-18 16:10:57 +00:00
|
|
|
{
|
|
|
|
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.
|
2017-09-28 15:32:15 +00:00
|
|
|
LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
|
|
|
|
exStyle |= WS_EX_LAYERED;
|
|
|
|
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle);
|
2017-09-18 16:10:57 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
2017-09-28 15:32:15 +00:00
|
|
|
LONG exStyle = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
|
|
|
|
exStyle &= ~WS_EX_LAYERED;
|
|
|
|
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, exStyle);
|
2017-09-18 16:10:57 +00:00
|
|
|
RedrawWindow(window->win32.handle, NULL, NULL,
|
|
|
|
RDW_ERASE | RDW_INVALIDATE | RDW_FRAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-09 18:19:00 +00:00
|
|
|
// Retrieves and translates modifier keys
|
|
|
|
//
|
|
|
|
static int getKeyMods(void)
|
|
|
|
{
|
|
|
|
int mods = 0;
|
|
|
|
|
2017-11-28 18:59:59 +00:00
|
|
|
if (GetKeyState(VK_SHIFT) & 0x8000)
|
2012-12-09 18:19:00 +00:00
|
|
|
mods |= GLFW_MOD_SHIFT;
|
2017-11-28 18:59:59 +00:00
|
|
|
if (GetKeyState(VK_CONTROL) & 0x8000)
|
2013-05-23 12:11:05 +00:00
|
|
|
mods |= GLFW_MOD_CONTROL;
|
2017-11-28 18:59:59 +00:00
|
|
|
if (GetKeyState(VK_MENU) & 0x8000)
|
2012-12-09 18:19:00 +00:00
|
|
|
mods |= GLFW_MOD_ALT;
|
2017-11-28 18:59:59 +00:00
|
|
|
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x8000)
|
2013-05-23 11:22:27 +00:00
|
|
|
mods |= GLFW_MOD_SUPER;
|
2017-11-29 19:42:37 +00:00
|
|
|
if (GetKeyState(VK_CAPITAL) & 1)
|
|
|
|
mods |= GLFW_MOD_CAPS_LOCK;
|
|
|
|
if (GetKeyState(VK_NUMLOCK) & 1)
|
|
|
|
mods |= GLFW_MOD_NUM_LOCK;
|
2012-12-09 18:19:00 +00:00
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieves and translates modifier keys
|
|
|
|
//
|
|
|
|
static int getAsyncKeyMods(void)
|
|
|
|
{
|
|
|
|
int mods = 0;
|
|
|
|
|
2017-11-28 18:59:59 +00:00
|
|
|
if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
|
2012-12-09 18:19:00 +00:00
|
|
|
mods |= GLFW_MOD_SHIFT;
|
2017-11-28 18:59:59 +00:00
|
|
|
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
|
2013-05-23 12:11:05 +00:00
|
|
|
mods |= GLFW_MOD_CONTROL;
|
2017-11-28 18:59:59 +00:00
|
|
|
if (GetAsyncKeyState(VK_MENU) & 0x8000)
|
2012-12-09 18:19:00 +00:00
|
|
|
mods |= GLFW_MOD_ALT;
|
2017-11-28 18:59:59 +00:00
|
|
|
if ((GetAsyncKeyState(VK_LWIN) | GetAsyncKeyState(VK_RWIN)) & 0x8000)
|
2013-05-23 11:22:27 +00:00
|
|
|
mods |= GLFW_MOD_SUPER;
|
2017-11-29 19:42:37 +00:00
|
|
|
if (GetAsyncKeyState(VK_CAPITAL) & 1)
|
|
|
|
mods |= GLFW_MOD_CAPS_LOCK;
|
|
|
|
if (GetAsyncKeyState(VK_NUMLOCK) & 1)
|
|
|
|
mods |= GLFW_MOD_NUM_LOCK;
|
2012-12-09 18:19:00 +00:00
|
|
|
|
|
|
|
return mods;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
// Translates a Windows key to the corresponding GLFW key
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2010-09-10 20:03:36 +00:00
|
|
|
static int translateKey(WPARAM wParam, LPARAM lParam)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2017-02-09 19:55:29 +00:00
|
|
|
// The Ctrl keys require special handling
|
2014-03-30 14:23:22 +00:00
|
|
|
if (wParam == VK_CONTROL)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-30 14:23:22 +00:00
|
|
|
MSG next;
|
|
|
|
DWORD time;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2017-02-09 19:55:29 +00:00
|
|
|
// Right side keys have the extended key bit set
|
2014-03-30 14:23:22 +00:00
|
|
|
if (lParam & 0x01000000)
|
|
|
|
return GLFW_KEY_RIGHT_CONTROL;
|
2013-04-17 13:29:17 +00:00
|
|
|
|
2017-02-09 19:55:29 +00:00
|
|
|
// 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
|
2014-03-30 14:23:22 +00:00
|
|
|
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)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2014-03-30 14:23:22 +00:00
|
|
|
if (next.wParam == VK_MENU &&
|
|
|
|
(next.lParam & 0x01000000) &&
|
|
|
|
next.time == time)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2017-02-09 19:55:29 +00:00
|
|
|
// Next message is Right Alt down so discard this
|
2014-03-30 14:23:22 +00:00
|
|
|
return _GLFW_KEY_INVALID;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 14:23:22 +00:00
|
|
|
return GLFW_KEY_LEFT_CONTROL;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2011-01-10 20:19:27 +00:00
|
|
|
|
2015-11-29 16:55:08 +00:00
|
|
|
if (wParam == VK_PROCESSKEY)
|
|
|
|
{
|
|
|
|
// IME notifies that keys have been filtered by setting the virtual
|
|
|
|
// key-code to VK_PROCESSKEY
|
|
|
|
return _GLFW_KEY_INVALID;
|
|
|
|
}
|
|
|
|
|
2016-09-07 13:43:39 +00:00
|
|
|
return _glfw.win32.keycodes[HIWORD(lParam) & 0x1FF];
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 12:04:59 +00:00
|
|
|
static void fitToMonitor(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
MONITORINFO mi = { sizeof(mi) };
|
|
|
|
GetMonitorInfo(window->monitor->win32.handle, &mi);
|
|
|
|
SetWindowPos(window->win32.handle, HWND_TOPMOST,
|
|
|
|
mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.top,
|
|
|
|
mi.rcMonitor.right - mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.bottom - mi.rcMonitor.top,
|
|
|
|
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS);
|
|
|
|
}
|
|
|
|
|
2016-02-23 11:34:35 +00:00
|
|
|
// Make the specified window and its video mode active on its monitor
|
2014-09-10 11:40:40 +00:00
|
|
|
//
|
2018-02-05 16:11:04 +00:00
|
|
|
static void acquireMonitor(_GLFWwindow* window)
|
2014-09-10 11:40:40 +00:00
|
|
|
{
|
2017-02-09 20:21:58 +00:00
|
|
|
if (!_glfw.win32.acquiredMonitorCount)
|
2018-08-01 22:01:26 +00:00
|
|
|
{
|
2017-02-09 20:21:58 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
|
2018-08-01 22:01:26 +00:00
|
|
|
|
|
|
|
// HACK: When mouse trails are enabled the cursor becomes invisible when
|
|
|
|
// the OpenGL ICD switches to page flipping
|
|
|
|
if (IsWindowsXPOrGreater())
|
|
|
|
{
|
|
|
|
SystemParametersInfo(SPI_GETMOUSETRAILS, 0, &_glfw.win32.mouseTrailSize, 0);
|
|
|
|
SystemParametersInfo(SPI_SETMOUSETRAILS, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-09 20:21:58 +00:00
|
|
|
if (!window->monitor->window)
|
|
|
|
_glfw.win32.acquiredMonitorCount++;
|
|
|
|
|
2018-02-05 16:11:04 +00:00
|
|
|
_glfwSetVideoModeWin32(window->monitor, &window->videoMode);
|
2017-01-10 14:46:00 +00:00
|
|
|
_glfwInputMonitorWindow(window->monitor, window);
|
2014-09-10 11:40:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 11:34:35 +00:00
|
|
|
// Remove the window and restore the original video mode
|
2014-09-10 11:40:40 +00:00
|
|
|
//
|
2016-02-23 11:34:35 +00:00
|
|
|
static void releaseMonitor(_GLFWwindow* window)
|
2014-09-10 11:40:40 +00:00
|
|
|
{
|
2016-02-23 11:34:35 +00:00
|
|
|
if (window->monitor->window != window)
|
|
|
|
return;
|
|
|
|
|
2017-02-09 20:21:58 +00:00
|
|
|
_glfw.win32.acquiredMonitorCount--;
|
|
|
|
if (!_glfw.win32.acquiredMonitorCount)
|
2018-08-01 22:01:26 +00:00
|
|
|
{
|
2017-02-09 20:21:58 +00:00
|
|
|
SetThreadExecutionState(ES_CONTINUOUS);
|
|
|
|
|
2018-08-01 22:01:26 +00:00
|
|
|
// HACK: Restore mouse trail length saved in acquireMonitor
|
|
|
|
if (IsWindowsXPOrGreater())
|
|
|
|
SystemParametersInfo(SPI_SETMOUSETRAILS, _glfw.win32.mouseTrailSize, 0, 0);
|
|
|
|
}
|
|
|
|
|
2017-01-10 14:46:00 +00:00
|
|
|
_glfwInputMonitorWindow(window->monitor, NULL);
|
2015-12-03 17:16:46 +00:00
|
|
|
_glfwRestoreVideoModeWin32(window->monitor);
|
2014-09-10 11:40:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 01:55:18 +00:00
|
|
|
// Window callback function (handles window messages)
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2010-09-10 20:03:36 +00:00
|
|
|
static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2016-05-30 19:21:09 +00:00
|
|
|
_GLFWwindow* window = GetPropW(hWnd, L"GLFW");
|
2015-11-03 14:16:00 +00:00
|
|
|
if (!window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2016-02-23 10:30:17 +00:00
|
|
|
// This is the message handling for the hidden helper window
|
2018-06-07 17:01:07 +00:00
|
|
|
// and for a regular window during its initial creation
|
2016-02-23 10:30:17 +00:00
|
|
|
|
2015-11-03 14:28:56 +00:00
|
|
|
switch (uMsg)
|
2010-09-13 23:05:03 +00:00
|
|
|
{
|
2018-06-07 17:01:07 +00:00
|
|
|
case WM_NCCREATE:
|
|
|
|
{
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
EnableNonClientDpiScaling(hWnd);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-14 18:21:52 +00:00
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
_glfwPollMonitorsWin32();
|
|
|
|
break;
|
|
|
|
|
2014-08-15 13:08:09 +00:00
|
|
|
case WM_DEVICECHANGE:
|
2015-11-03 14:28:56 +00:00
|
|
|
{
|
2017-03-14 18:21:52 +00:00
|
|
|
if (wParam == DBT_DEVICEARRIVAL)
|
2014-08-15 13:08:09 +00:00
|
|
|
{
|
|
|
|
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
|
2017-03-14 19:39:18 +00:00
|
|
|
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
|
|
|
|
_glfwDetectJoystickConnectionWin32();
|
2014-08-15 13:08:09 +00:00
|
|
|
}
|
|
|
|
else if (wParam == DBT_DEVICEREMOVECOMPLETE)
|
|
|
|
{
|
|
|
|
DEV_BROADCAST_HDR* dbh = (DEV_BROADCAST_HDR*) lParam;
|
2017-03-14 19:39:18 +00:00
|
|
|
if (dbh && dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
|
|
|
|
_glfwDetectJoystickDisconnectionWin32();
|
2014-08-15 13:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2015-11-03 14:28:56 +00:00
|
|
|
}
|
2010-09-13 23:05:03 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 14:16:00 +00:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
2017-09-08 14:15:57 +00:00
|
|
|
case WM_MOUSEACTIVATE:
|
|
|
|
{
|
|
|
|
// HACK: Postpone cursor disabling when the window was activated by
|
|
|
|
// clicking a caption button
|
|
|
|
if (HIWORD(lParam) == WM_LBUTTONDOWN)
|
|
|
|
{
|
2019-05-02 19:15:35 +00:00
|
|
|
if (LOWORD(lParam) != HTCLIENT)
|
2017-09-08 14:15:57 +00:00
|
|
|
window->win32.frameAction = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2018-04-17 17:54:36 +00:00
|
|
|
disableCursor(window);
|
2017-09-08 14:15:57 +00:00
|
|
|
|
|
|
|
window->win32.frameAction = GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-26 11:25:48 +00:00
|
|
|
case WM_SETFOCUS:
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2016-05-25 12:06:02 +00:00
|
|
|
_glfwInputWindowFocus(window, GLFW_TRUE);
|
|
|
|
|
2017-09-08 14:15:57 +00:00
|
|
|
// HACK: Do not disable cursor while the user is interacting with
|
|
|
|
// a caption button
|
|
|
|
if (window->win32.frameAction)
|
|
|
|
break;
|
|
|
|
|
2015-07-02 11:04:56 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2018-04-17 17:54:36 +00:00
|
|
|
disableCursor(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-26 11:25:48 +00:00
|
|
|
case WM_KILLFOCUS:
|
2013-12-05 01:15:14 +00:00
|
|
|
{
|
2015-07-02 11:04:56 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2018-04-17 17:54:36 +00:00
|
|
|
enableCursor(window);
|
2014-12-26 11:25:48 +00:00
|
|
|
|
|
|
|
if (window->monitor && window->autoIconify)
|
|
|
|
_glfwPlatformIconifyWindow(window);
|
2013-12-05 01:15:14 +00:00
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfwInputWindowFocus(window, GLFW_FALSE);
|
2013-12-05 01:15:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
{
|
2010-09-10 20:03:36 +00:00
|
|
|
switch (wParam & 0xfff0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
case SC_SCREENSAVE:
|
|
|
|
case SC_MONITORPOWER:
|
|
|
|
{
|
2012-09-27 19:37:36 +00:00
|
|
|
if (window->monitor)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2015-01-05 20:55:15 +00:00
|
|
|
// We are running in full screen mode, so disallow
|
2010-09-10 20:03:36 +00:00
|
|
|
// screen saver and screen blanking
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// User trying to access application menu using ALT?
|
|
|
|
case SC_KEYMENU:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
{
|
2012-08-10 11:31:15 +00:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-07 02:29:57 +00:00
|
|
|
case WM_INPUTLANGCHANGE:
|
|
|
|
{
|
|
|
|
_glfwUpdateKeyNamesWin32();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-19 11:17:53 +00:00
|
|
|
case WM_CHAR:
|
2013-08-19 11:08:35 +00:00
|
|
|
case WM_SYSCHAR:
|
2013-04-10 22:59:21 +00:00
|
|
|
case WM_UNICHAR:
|
|
|
|
{
|
2015-10-29 13:05:57 +00:00
|
|
|
const GLFWbool plain = (uMsg != WM_SYSCHAR);
|
2013-04-10 22:59:21 +00:00
|
|
|
|
2015-10-29 13:05:57 +00:00
|
|
|
if (uMsg == WM_UNICHAR && wParam == UNICODE_NOCHAR)
|
2013-04-10 22:59:21 +00:00
|
|
|
{
|
2015-10-29 13:05:57 +00:00
|
|
|
// WM_UNICHAR is not sent by Windows, but is sent by some
|
|
|
|
// third-party input method engine
|
2013-04-10 22:59:21 +00:00
|
|
|
// Returning TRUE here announces support for this message
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:05:57 +00:00
|
|
|
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), plain);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_SYSKEYDOWN:
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
{
|
2013-05-30 15:19:12 +00:00
|
|
|
const int key = translateKey(wParam, lParam);
|
2015-10-29 14:39:54 +00:00
|
|
|
const int scancode = (lParam >> 16) & 0x1ff;
|
|
|
|
const int action = ((lParam >> 31) & 1) ? GLFW_RELEASE : GLFW_PRESS;
|
|
|
|
const int mods = getKeyMods();
|
|
|
|
|
2013-05-30 15:19:12 +00:00
|
|
|
if (key == _GLFW_KEY_INVALID)
|
|
|
|
break;
|
2012-12-09 18:19:00 +00:00
|
|
|
|
2015-10-29 14:39:54 +00:00
|
|
|
if (action == GLFW_RELEASE && wParam == VK_SHIFT)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2017-02-09 19:55:29 +00:00
|
|
|
// 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
|
2015-10-29 14:39:54 +00:00
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, action, mods);
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, action, mods);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2013-02-21 17:39:22 +00:00
|
|
|
else if (wParam == VK_SNAPSHOT)
|
|
|
|
{
|
2017-02-09 19:55:29 +00:00
|
|
|
// HACK: Key down is not reported for the Print Screen key
|
2013-05-30 15:19:12 +00:00
|
|
|
_glfwInputKey(window, key, scancode, GLFW_PRESS, mods);
|
|
|
|
_glfwInputKey(window, key, scancode, GLFW_RELEASE, mods);
|
2013-02-21 17:39:22 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
2015-10-29 14:39:54 +00:00
|
|
|
_glfwInputKey(window, key, scancode, action, mods);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-02-07 15:44:22 +00:00
|
|
|
break;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN:
|
2013-04-16 18:57:51 +00:00
|
|
|
case WM_XBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONUP:
|
2013-04-16 18:57:51 +00:00
|
|
|
case WM_XBUTTONUP:
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2017-02-26 16:23:56 +00:00
|
|
|
int i, button, action;
|
2015-10-29 14:39:54 +00:00
|
|
|
|
|
|
|
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;
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2015-10-29 14:39:54 +00:00
|
|
|
if (uMsg == WM_LBUTTONDOWN || uMsg == WM_RBUTTONDOWN ||
|
|
|
|
uMsg == WM_MBUTTONDOWN || uMsg == WM_XBUTTONDOWN)
|
|
|
|
{
|
|
|
|
action = GLFW_PRESS;
|
|
|
|
}
|
2013-04-16 18:57:51 +00:00
|
|
|
else
|
2015-10-29 14:39:54 +00:00
|
|
|
action = GLFW_RELEASE;
|
2017-02-26 16:23:56 +00:00
|
|
|
|
2017-07-09 16:37:24 +00:00
|
|
|
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
2017-02-26 16:23:56 +00:00
|
|
|
{
|
|
|
|
if (window->mouseButtons[i] == GLFW_PRESS)
|
|
|
|
break;
|
2015-10-29 14:39:54 +00:00
|
|
|
}
|
2013-04-16 18:57:51 +00:00
|
|
|
|
2017-07-09 16:37:24 +00:00
|
|
|
if (i > GLFW_MOUSE_BUTTON_LAST)
|
2017-02-26 16:23:56 +00:00
|
|
|
SetCapture(hWnd);
|
|
|
|
|
2015-10-29 14:39:54 +00:00
|
|
|
_glfwInputMouseClick(window, button, action, getKeyMods());
|
|
|
|
|
2017-07-09 16:37:24 +00:00
|
|
|
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
2017-02-26 16:23:56 +00:00
|
|
|
{
|
|
|
|
if (window->mouseButtons[i] == GLFW_PRESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-07-09 16:37:24 +00:00
|
|
|
if (i > GLFW_MOUSE_BUTTON_LAST)
|
2017-02-26 16:23:56 +00:00
|
|
|
ReleaseCapture();
|
|
|
|
|
2015-10-29 14:39:54 +00:00
|
|
|
if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP)
|
2013-04-16 18:57:51 +00:00
|
|
|
return TRUE;
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2013-04-16 18:57:51 +00:00
|
|
|
return 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
2014-02-11 17:24:01 +00:00
|
|
|
const int x = GET_X_LPARAM(lParam);
|
|
|
|
const int y = GET_Y_LPARAM(lParam);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2019-05-27 20:42:12 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-02-11 17:24:01 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2018-12-14 02:08:25 +00:00
|
|
|
{
|
|
|
|
const int dx = x - window->win32.lastCursorPosX;
|
|
|
|
const int dy = y - window->win32.lastCursorPosY;
|
2019-02-11 18:10:20 +00:00
|
|
|
|
|
|
|
if (_glfw.win32.disabledCursorWindow != window)
|
|
|
|
break;
|
|
|
|
if (window->rawMouseMotion)
|
|
|
|
break;
|
|
|
|
|
2018-12-14 02:08:25 +00:00
|
|
|
_glfwInputCursorPos(window,
|
|
|
|
window->virtualCursorPosX + dx,
|
|
|
|
window->virtualCursorPosY + dy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_glfwInputCursorPos(window, x, y);
|
2014-02-11 17:24:01 +00:00
|
|
|
|
2016-05-24 10:23:58 +00:00
|
|
|
window->win32.lastCursorPosX = x;
|
|
|
|
window->win32.lastCursorPosY = y;
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2012-03-22 12:17:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:16:15 +00:00
|
|
|
case WM_INPUT:
|
|
|
|
{
|
2019-04-15 13:35:38 +00:00
|
|
|
UINT size = 0;
|
2017-01-10 17:16:15 +00:00
|
|
|
HRAWINPUT ri = (HRAWINPUT) lParam;
|
2019-04-15 13:35:38 +00:00
|
|
|
RAWINPUT* data = NULL;
|
2017-01-10 17:16:15 +00:00
|
|
|
int dx, dy;
|
|
|
|
|
2019-02-11 18:10:20 +00:00
|
|
|
if (_glfw.win32.disabledCursorWindow != window)
|
|
|
|
break;
|
|
|
|
if (!window->rawMouseMotion)
|
2017-01-10 17:16:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
2017-02-27 23:07:37 +00:00
|
|
|
if (size > (UINT) _glfw.win32.rawInputSize)
|
2017-01-10 17:16:15 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-03-22 12:17:44 +00:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
{
|
2015-08-23 17:30:04 +00:00
|
|
|
window->win32.cursorTracked = GLFW_FALSE;
|
|
|
|
_glfwInputCursorEnter(window, GLFW_FALSE);
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2012-03-28 19:54:09 +00:00
|
|
|
_glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
|
2010-09-27 00:32:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2010-09-27 00:32:41 +00:00
|
|
|
case WM_MOUSEHWHEEL:
|
|
|
|
{
|
|
|
|
// This message is only sent on Windows Vista and later
|
2016-10-19 22:50:54 +00:00
|
|
|
// NOTE: The X-axis is inverted for consistency with macOS and X11
|
2014-10-26 12:53:45 +00:00
|
|
|
_glfwInputScroll(window, -((SHORT) HIWORD(wParam) / (double) WHEEL_DELTA), 0.0);
|
2010-09-12 14:26:00 +00:00
|
|
|
return 0;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 10:57:55 +00:00
|
|
|
case WM_ENTERSIZEMOVE:
|
|
|
|
case WM_ENTERMENULOOP:
|
|
|
|
{
|
2019-05-02 19:15:35 +00:00
|
|
|
if (window->win32.frameAction)
|
|
|
|
break;
|
|
|
|
|
2018-04-17 17:54:36 +00:00
|
|
|
// HACK: Enable the cursor while the user is moving or
|
|
|
|
// resizing the window or using the window menu
|
2016-05-31 10:57:55 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2018-04-17 17:54:36 +00:00
|
|
|
enableCursor(window);
|
2016-05-31 10:57:55 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_EXITSIZEMOVE:
|
|
|
|
case WM_EXITMENULOOP:
|
|
|
|
{
|
2019-05-02 19:15:35 +00:00
|
|
|
if (window->win32.frameAction)
|
|
|
|
break;
|
|
|
|
|
2017-09-08 14:15:57 +00:00
|
|
|
// HACK: Disable the cursor once the user is done moving or
|
|
|
|
// resizing the window or using the menu
|
2016-05-31 10:57:55 +00:00
|
|
|
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
2018-04-17 17:54:36 +00:00
|
|
|
disableCursor(window);
|
2016-05-31 10:57:55 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2016-06-16 11:09:28 +00:00
|
|
|
const GLFWbool iconified = wParam == SIZE_MINIMIZED;
|
|
|
|
const GLFWbool maximized = wParam == SIZE_MAXIMIZED ||
|
|
|
|
(window->win32.maximized &&
|
|
|
|
wParam != SIZE_RESTORED);
|
2016-05-04 14:04:26 +00:00
|
|
|
|
2016-05-30 19:21:09 +00:00
|
|
|
if (_glfw.win32.disabledCursorWindow == window)
|
|
|
|
updateClipRect(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2016-06-16 11:09:28 +00:00
|
|
|
if (window->win32.iconified != iconified)
|
|
|
|
_glfwInputWindowIconify(window, iconified);
|
|
|
|
|
|
|
|
if (window->win32.maximized != maximized)
|
|
|
|
_glfwInputWindowMaximize(window, maximized);
|
2016-05-04 14:04:26 +00:00
|
|
|
|
|
|
|
_glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
|
|
|
|
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
|
|
|
|
2016-06-16 11:09:28 +00:00
|
|
|
if (window->monitor && window->win32.iconified != iconified)
|
2015-01-06 14:35:49 +00:00
|
|
|
{
|
2016-06-16 11:09:28 +00:00
|
|
|
if (iconified)
|
2016-02-23 11:34:35 +00:00
|
|
|
releaseMonitor(window);
|
2016-06-16 11:09:28 +00:00
|
|
|
else
|
2018-02-06 12:04:59 +00:00
|
|
|
{
|
2016-02-23 11:34:35 +00:00
|
|
|
acquireMonitor(window);
|
2018-02-06 12:04:59 +00:00
|
|
|
fitToMonitor(window);
|
|
|
|
}
|
2015-01-06 14:35:49 +00:00
|
|
|
}
|
2014-12-31 19:25:54 +00:00
|
|
|
|
2016-06-16 11:09:28 +00:00
|
|
|
window->win32.iconified = iconified;
|
|
|
|
window->win32.maximized = maximized;
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOVE:
|
|
|
|
{
|
2016-05-30 19:21:09 +00:00
|
|
|
if (_glfw.win32.disabledCursorWindow == window)
|
|
|
|
updateClipRect(window);
|
2011-10-09 15:10:40 +00:00
|
|
|
|
2013-11-13 11:47:44 +00:00
|
|
|
// NOTE: This cannot use LOWORD/HIWORD recommended by MSDN, as
|
|
|
|
// those macros do not handle negative window positions correctly
|
2013-11-13 11:34:43 +00:00
|
|
|
_glfwInputWindowPos(window,
|
|
|
|
GET_X_LPARAM(lParam),
|
|
|
|
GET_Y_LPARAM(lParam));
|
2010-09-07 15:34:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-13 01:57:59 +00:00
|
|
|
case WM_SIZING:
|
|
|
|
{
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->numer == GLFW_DONT_CARE ||
|
|
|
|
window->denom == GLFW_DONT_CARE)
|
2014-02-13 01:57:59 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyAspectRatio(window, (int) wParam, (RECT*) lParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
{
|
|
|
|
int xoff, yoff;
|
2018-10-21 12:35:48 +00:00
|
|
|
UINT dpi = USER_DEFAULT_SCREEN_DPI;
|
2014-02-13 01:57:59 +00:00
|
|
|
MINMAXINFO* mmi = (MINMAXINFO*) lParam;
|
2015-10-18 16:50:38 +00:00
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->monitor)
|
|
|
|
break;
|
|
|
|
|
2018-10-21 12:35:48 +00:00
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
dpi = GetDpiForWindow(window->win32.handle);
|
|
|
|
|
2015-10-18 15:01:14 +00:00
|
|
|
getFullWindowSize(getWindowStyle(window), getWindowExStyle(window),
|
2018-10-21 12:35:48 +00:00
|
|
|
0, 0, &xoff, &yoff, dpi);
|
2014-02-13 01:57:59 +00:00
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->minwidth != GLFW_DONT_CARE &&
|
|
|
|
window->minheight != GLFW_DONT_CARE)
|
2014-02-13 01:57:59 +00:00
|
|
|
{
|
2016-02-23 11:26:42 +00:00
|
|
|
mmi->ptMinTrackSize.x = window->minwidth + xoff;
|
|
|
|
mmi->ptMinTrackSize.y = window->minheight + yoff;
|
2014-02-13 01:57:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->maxwidth != GLFW_DONT_CARE &&
|
|
|
|
window->maxheight != GLFW_DONT_CARE)
|
2014-02-13 01:57:59 +00:00
|
|
|
{
|
2016-02-23 11:26:42 +00:00
|
|
|
mmi->ptMaxTrackSize.x = window->maxwidth + xoff;
|
|
|
|
mmi->ptMaxTrackSize.y = window->maxheight + yoff;
|
2014-02-13 01:57:59 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 14:47:01 +00:00
|
|
|
if (!window->decorated)
|
|
|
|
{
|
|
|
|
MONITORINFO mi;
|
|
|
|
const HMONITOR mh = MonitorFromWindow(window->win32.handle,
|
|
|
|
MONITOR_DEFAULTTONEAREST);
|
|
|
|
|
|
|
|
ZeroMemory(&mi, sizeof(mi));
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
GetMonitorInfo(mh, &mi);
|
|
|
|
|
|
|
|
mmi->ptMaxPosition.x = mi.rcWork.left - mi.rcMonitor.left;
|
|
|
|
mmi->ptMaxPosition.y = mi.rcWork.top - mi.rcMonitor.top;
|
|
|
|
mmi->ptMaxSize.x = mi.rcWork.right - mi.rcWork.left;
|
|
|
|
mmi->ptMaxSize.y = mi.rcWork.bottom - mi.rcWork.top;
|
|
|
|
}
|
|
|
|
|
2014-02-13 01:57:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
case WM_PAINT:
|
|
|
|
{
|
2011-10-09 19:12:13 +00:00
|
|
|
_glfwInputWindowDamage(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-08 19:16:48 +00:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-12-26 14:18:36 +00:00
|
|
|
case WM_NCACTIVATE:
|
|
|
|
case WM_NCPAINT:
|
|
|
|
{
|
|
|
|
// Prevent title bar from being drawn after restoring a minimized
|
|
|
|
// undecorated window
|
|
|
|
if (!window->decorated)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-18 16:10:57 +00:00
|
|
|
case WM_DWMCOMPOSITIONCHANGED:
|
|
|
|
{
|
|
|
|
if (window->win32.transparent)
|
|
|
|
updateFramebufferTransparency(window);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-07 17:01:07 +00:00
|
|
|
case WM_GETDPISCALEDSIZE:
|
|
|
|
{
|
2018-08-31 11:33:48 +00:00
|
|
|
if (window->win32.scaleToMonitor)
|
|
|
|
break;
|
|
|
|
|
2019-01-22 19:54:16 +00:00
|
|
|
// Adjust the window size to keep the content area size constant
|
2018-06-07 17:01:07 +00:00
|
|
|
if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
RECT source = {0}, target = {0};
|
|
|
|
SIZE* size = (SIZE*) lParam;
|
|
|
|
|
|
|
|
AdjustWindowRectExForDpi(&source, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
AdjustWindowRectExForDpi(&target, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
LOWORD(wParam));
|
|
|
|
|
|
|
|
size->cx += (target.right - target.left) -
|
|
|
|
(source.right - source.left);
|
|
|
|
size->cy += (target.bottom - target.top) -
|
|
|
|
(source.bottom - source.top);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-11 20:26:40 +00:00
|
|
|
case WM_DPICHANGED:
|
|
|
|
{
|
2018-06-07 17:01:07 +00:00
|
|
|
const float xscale = HIWORD(wParam) / (float) USER_DEFAULT_SCREEN_DPI;
|
|
|
|
const float yscale = LOWORD(wParam) / (float) USER_DEFAULT_SCREEN_DPI;
|
|
|
|
|
|
|
|
// Only apply the suggested size if the OS is new enough to have
|
|
|
|
// sent a WM_GETDPISCALEDSIZE before this
|
|
|
|
if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
RECT* suggested = (RECT*) lParam;
|
|
|
|
SetWindowPos(window->win32.handle, HWND_TOP,
|
|
|
|
suggested->left,
|
|
|
|
suggested->top,
|
|
|
|
suggested->right - suggested->left,
|
|
|
|
suggested->bottom - suggested->top,
|
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER);
|
|
|
|
}
|
|
|
|
|
2017-12-11 20:26:40 +00:00
|
|
|
_glfwInputWindowContentScale(window, xscale, yscale);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-11 21:57:39 +00:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
{
|
2016-05-25 12:06:02 +00:00
|
|
|
if (LOWORD(lParam) == HTCLIENT)
|
2013-03-11 21:57:39 +00:00
|
|
|
{
|
2016-05-30 19:21:09 +00:00
|
|
|
updateCursorImage(window);
|
2016-05-25 12:06:02 +00:00
|
|
|
return TRUE;
|
2013-03-11 21:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:42:14 +00:00
|
|
|
case WM_DROPFILES:
|
|
|
|
{
|
2015-08-09 11:58:50 +00:00
|
|
|
HDROP drop = (HDROP) wParam;
|
2013-12-22 15:38:56 +00:00
|
|
|
POINT pt;
|
2013-12-22 18:28:46 +00:00
|
|
|
int i;
|
|
|
|
|
2015-08-09 11:58:50 +00:00
|
|
|
const int count = DragQueryFileW(drop, 0xffffffff, NULL, 0);
|
2015-01-27 22:04:22 +00:00
|
|
|
char** paths = calloc(count, sizeof(char*));
|
2013-12-22 15:38:56 +00:00
|
|
|
|
|
|
|
// Move the mouse to the position of the drop
|
2015-08-09 11:58:50 +00:00
|
|
|
DragQueryPoint(drop, &pt);
|
2016-05-25 12:06:02 +00:00
|
|
|
_glfwInputCursorPos(window, pt.x, pt.y);
|
2013-12-22 15:38:56 +00:00
|
|
|
|
2013-12-22 18:28:46 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2013-12-22 15:38:56 +00:00
|
|
|
{
|
2015-08-09 11:58:50 +00:00
|
|
|
const UINT length = DragQueryFileW(drop, i, NULL, 0);
|
2019-04-15 13:35:38 +00:00
|
|
|
WCHAR* buffer = calloc((size_t) length + 1, sizeof(WCHAR));
|
2013-12-22 15:38:56 +00:00
|
|
|
|
2015-08-09 11:58:50 +00:00
|
|
|
DragQueryFileW(drop, i, buffer, length + 1);
|
2015-12-03 17:16:46 +00:00
|
|
|
paths[i] = _glfwCreateUTF8FromWideStringWin32(buffer);
|
2013-12-22 15:38:56 +00:00
|
|
|
|
2013-12-22 18:28:46 +00:00
|
|
|
free(buffer);
|
2013-12-22 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 22:04:22 +00:00
|
|
|
_glfwInputDrop(window, count, (const char**) paths);
|
2013-12-22 18:28:46 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2015-01-27 22:04:22 +00:00
|
|
|
free(paths[i]);
|
|
|
|
free(paths);
|
2013-12-22 18:28:46 +00:00
|
|
|
|
2015-08-09 11:58:50 +00:00
|
|
|
DragFinish(drop);
|
2014-02-10 23:56:52 +00:00
|
|
|
return 0;
|
2013-07-10 09:42:14 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 13:03:22 +00:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 10:15:08 +00:00
|
|
|
// Creates the GLFW window
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2016-07-25 17:36:25 +00:00
|
|
|
static int createNativeWindow(_GLFWwindow* window,
|
2017-09-18 16:10:57 +00:00
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2013-02-20 15:00:53 +00:00
|
|
|
int xpos, ypos, fullWidth, fullHeight;
|
2012-02-03 19:34:24 +00:00
|
|
|
WCHAR* wideTitle;
|
2015-10-13 10:50:59 +00:00
|
|
|
DWORD style = getWindowStyle(window);
|
|
|
|
DWORD exStyle = getWindowExStyle(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2016-03-14 14:17:28 +00:00
|
|
|
if (window->monitor)
|
2013-01-24 18:30:31 +00:00
|
|
|
{
|
2015-06-08 14:12:47 +00:00
|
|
|
GLFWvidmode mode;
|
|
|
|
|
2014-09-10 11:40:40 +00:00
|
|
|
// NOTE: This window placement is temporary and approximate, as the
|
|
|
|
// correct position and size cannot be known until the monitor
|
2017-02-09 19:55:29 +00:00
|
|
|
// video mode has been picked in _glfwSetVideoModeWin32
|
2016-03-14 14:17:28 +00:00
|
|
|
_glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos);
|
|
|
|
_glfwPlatformGetVideoMode(window->monitor, &mode);
|
2015-06-08 14:12:47 +00:00
|
|
|
fullWidth = mode.width;
|
|
|
|
fullHeight = mode.height;
|
2013-01-24 18:30:31 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
2013-02-20 15:00:53 +00:00
|
|
|
xpos = CW_USEDEFAULT;
|
|
|
|
ypos = CW_USEDEFAULT;
|
2010-09-10 20:03:36 +00:00
|
|
|
|
2019-08-14 17:18:29 +00:00
|
|
|
window->win32.maximized = wndconfig->maximized;
|
2015-10-13 10:50:59 +00:00
|
|
|
if (wndconfig->maximized)
|
|
|
|
style |= WS_MAXIMIZE;
|
|
|
|
|
|
|
|
getFullWindowSize(style, exStyle,
|
2015-01-05 19:24:48 +00:00
|
|
|
wndconfig->width, wndconfig->height,
|
2018-06-07 17:01:07 +00:00
|
|
|
&fullWidth, &fullHeight,
|
|
|
|
USER_DEFAULT_SCREEN_DPI);
|
2012-10-05 02:10:42 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 17:16:46 +00:00
|
|
|
wideTitle = _glfwCreateWideStringFromUTF8Win32(wndconfig->title);
|
2012-02-03 19:34:24 +00:00
|
|
|
if (!wideTitle)
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-02-03 19:34:24 +00:00
|
|
|
|
2015-10-13 10:50:59 +00:00
|
|
|
window->win32.handle = CreateWindowExW(exStyle,
|
2014-03-06 17:30:14 +00:00
|
|
|
_GLFW_WNDCLASSNAME,
|
|
|
|
wideTitle,
|
2015-10-13 10:50:59 +00:00
|
|
|
style,
|
2014-03-06 17:30:14 +00:00
|
|
|
xpos, ypos,
|
|
|
|
fullWidth, fullHeight,
|
|
|
|
NULL, // No parent window
|
|
|
|
NULL, // No window menu
|
|
|
|
GetModuleHandleW(NULL),
|
2016-03-27 19:20:31 +00:00
|
|
|
NULL);
|
2010-09-12 14:26:00 +00:00
|
|
|
|
2013-01-22 22:28:41 +00:00
|
|
|
free(wideTitle);
|
2013-12-22 15:38:56 +00:00
|
|
|
|
2014-05-23 11:24:36 +00:00
|
|
|
if (!window->win32.handle)
|
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create window");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2014-05-23 11:24:36 +00:00
|
|
|
}
|
|
|
|
|
2016-03-27 19:20:31 +00:00
|
|
|
SetPropW(window->win32.handle, L"GLFW", window);
|
|
|
|
|
2017-08-29 18:05:44 +00:00
|
|
|
if (IsWindows7OrGreater())
|
2014-02-10 14:03:23 +00:00
|
|
|
{
|
2017-08-29 18:05:44 +00:00
|
|
|
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);
|
2014-02-10 14:03:23 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 11:33:48 +00:00
|
|
|
window->win32.scaleToMonitor = wndconfig->scaleToMonitor;
|
|
|
|
|
2019-08-15 15:25:36 +00:00
|
|
|
// Adjust window rect to account for DPI scaling of the window frame and
|
|
|
|
// (if enabled) DPI scaling of the content area
|
|
|
|
// This cannot be done until we know what monitor the window was placed on
|
2018-08-31 11:33:48 +00:00
|
|
|
if (!window->monitor)
|
2018-06-07 17:01:07 +00:00
|
|
|
{
|
|
|
|
RECT rect = { 0, 0, wndconfig->width, wndconfig->height };
|
2019-08-13 13:18:02 +00:00
|
|
|
WINDOWPLACEMENT wp = { sizeof(wp) };
|
2018-08-31 11:33:48 +00:00
|
|
|
|
|
|
|
if (wndconfig->scaleToMonitor)
|
|
|
|
{
|
|
|
|
float xscale, yscale;
|
|
|
|
_glfwPlatformGetWindowContentScale(window, &xscale, &yscale);
|
|
|
|
rect.right = (int) (rect.right * xscale);
|
|
|
|
rect.bottom = (int) (rect.bottom * yscale);
|
|
|
|
}
|
|
|
|
|
2018-06-07 17:01:07 +00:00
|
|
|
ClientToScreen(window->win32.handle, (POINT*) &rect.left);
|
|
|
|
ClientToScreen(window->win32.handle, (POINT*) &rect.right);
|
2018-08-31 11:33:48 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle,
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
|
|
|
|
|
2019-08-13 13:18:02 +00:00
|
|
|
// Only update the restored window rect as the window may be maximized
|
|
|
|
GetWindowPlacement(window->win32.handle, &wp);
|
|
|
|
wp.rcNormalPosition = rect;
|
|
|
|
wp.showCmd = SW_HIDE;
|
|
|
|
SetWindowPlacement(window->win32.handle, &wp);
|
2018-06-07 17:01:07 +00:00
|
|
|
}
|
|
|
|
|
2013-12-22 15:38:56 +00:00
|
|
|
DragAcceptFiles(window->win32.handle, TRUE);
|
2013-01-22 22:28:41 +00:00
|
|
|
|
2017-09-18 16:10:57 +00:00
|
|
|
if (fbconfig->transparent)
|
|
|
|
{
|
|
|
|
updateFramebufferTransparency(window);
|
|
|
|
window->win32.transparent = GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-31 12:17:31 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Registers the GLFW window class
|
|
|
|
//
|
2015-12-03 17:16:46 +00:00
|
|
|
GLFWbool _glfwRegisterWindowClassWin32(void)
|
2014-08-31 12:17:31 +00:00
|
|
|
{
|
2015-11-03 15:06:17 +00:00
|
|
|
WNDCLASSEXW wc;
|
2014-08-31 12:17:31 +00:00
|
|
|
|
2015-11-03 15:06:17 +00:00
|
|
|
ZeroMemory(&wc, sizeof(wc));
|
|
|
|
wc.cbSize = sizeof(wc);
|
2014-08-31 12:17:31 +00:00
|
|
|
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
|
2015-10-15 15:03:36 +00:00
|
|
|
wc.hIcon = LoadImageW(GetModuleHandleW(NULL),
|
|
|
|
L"GLFW_ICON", IMAGE_ICON,
|
|
|
|
0, 0, LR_DEFAULTSIZE | LR_SHARED);
|
2014-08-31 12:17:31 +00:00
|
|
|
if (!wc.hIcon)
|
|
|
|
{
|
|
|
|
// No user-provided icon found, load default icon
|
2015-10-15 15:03:36 +00:00
|
|
|
wc.hIcon = LoadImageW(NULL,
|
|
|
|
IDI_APPLICATION, IMAGE_ICON,
|
|
|
|
0, 0, LR_DEFAULTSIZE | LR_SHARED);
|
2014-08-31 12:17:31 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 15:06:17 +00:00
|
|
|
if (!RegisterClassExW(&wc))
|
2014-08-31 12:17:31 +00:00
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to register window class");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2014-08-31 12:17:31 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2014-08-31 12:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unregisters the GLFW window class
|
|
|
|
//
|
2015-12-03 17:16:46 +00:00
|
|
|
void _glfwUnregisterWindowClassWin32(void)
|
2014-08-31 12:17:31 +00:00
|
|
|
{
|
|
|
|
UnregisterClassW(_GLFW_WNDCLASSNAME, GetModuleHandleW(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-08-06 15:56:41 +00:00
|
|
|
int _glfwPlatformCreateWindow(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
2014-03-06 19:05:32 +00:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2012-08-06 15:56:41 +00:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2017-09-18 16:10:57 +00:00
|
|
|
if (!createNativeWindow(window, wndconfig, fbconfig))
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2016-03-28 11:19:31 +00:00
|
|
|
if (ctxconfig->client != GLFW_NO_API)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2016-03-28 11:19:31 +00:00
|
|
|
if (ctxconfig->source == GLFW_NATIVE_CONTEXT_API)
|
|
|
|
{
|
2016-07-20 10:52:06 +00:00
|
|
|
if (!_glfwInitWGL())
|
|
|
|
return GLFW_FALSE;
|
2016-03-28 11:19:31 +00:00
|
|
|
if (!_glfwCreateContextWGL(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2017-02-28 18:23:25 +00:00
|
|
|
else if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
|
2015-06-18 12:03:02 +00:00
|
|
|
{
|
2016-07-20 10:52:06 +00:00
|
|
|
if (!_glfwInitEGL())
|
|
|
|
return GLFW_FALSE;
|
2016-03-28 11:19:31 +00:00
|
|
|
if (!_glfwCreateContextEGL(window, ctxconfig, fbconfig))
|
2015-06-18 12:03:02 +00:00
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2017-02-28 18:23:25 +00:00
|
|
|
else if (ctxconfig->source == GLFW_OSMESA_CONTEXT_API)
|
|
|
|
{
|
|
|
|
if (!_glfwInitOSMesa())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
if (!_glfwCreateContextOSMesa(window, ctxconfig, fbconfig))
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 19:37:36 +00:00
|
|
|
if (window->monitor)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-09-23 13:08:43 +00:00
|
|
|
_glfwPlatformShowWindow(window);
|
2016-02-23 11:26:42 +00:00
|
|
|
_glfwPlatformFocusWindow(window);
|
2018-02-05 16:11:04 +00:00
|
|
|
acquireMonitor(window);
|
2018-02-06 12:04:59 +00:00
|
|
|
fitToMonitor(window);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 15:56:41 +00:00
|
|
|
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-09-27 19:37:36 +00:00
|
|
|
if (window->monitor)
|
2016-02-23 11:34:35 +00:00
|
|
|
releaseMonitor(window);
|
2014-09-10 11:40:40 +00:00
|
|
|
|
2016-08-05 09:22:55 +00:00
|
|
|
if (window->context.destroy)
|
2016-05-25 12:43:51 +00:00
|
|
|
window->context.destroy(window);
|
2015-06-18 12:03:02 +00:00
|
|
|
|
2016-06-22 18:09:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-03-07 13:55:30 +00:00
|
|
|
|
|
|
|
if (window->win32.bigIcon)
|
|
|
|
DestroyIcon(window->win32.bigIcon);
|
|
|
|
|
|
|
|
if (window->win32.smallIcon)
|
|
|
|
DestroyIcon(window->win32.smallIcon);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2015-12-03 17:16:46 +00:00
|
|
|
WCHAR* wideTitle = _glfwCreateWideStringFromUTF8Win32(title);
|
2012-02-03 19:34:24 +00:00
|
|
|
if (!wideTitle)
|
|
|
|
return;
|
|
|
|
|
2014-03-06 17:30:14 +00:00
|
|
|
SetWindowTextW(window->win32.handle, wideTitle);
|
2012-02-07 13:58:58 +00:00
|
|
|
free(wideTitle);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 13:55:30 +00:00
|
|
|
void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
|
|
|
|
int count, const GLFWimage* images)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
bigIcon = createIcon(bigImage, 0, 0, GLFW_TRUE);
|
|
|
|
smallIcon = createIcon(smallImage, 0, 0, GLFW_TRUE);
|
|
|
|
}
|
2016-03-11 13:41:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
bigIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICON);
|
|
|
|
smallIcon = (HICON) GetClassLongPtrW(window->win32.handle, GCLP_HICONSM);
|
|
|
|
}
|
2016-03-07 13:55:30 +00:00
|
|
|
|
|
|
|
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.smallIcon)
|
|
|
|
DestroyIcon(window->win32.smallIcon);
|
|
|
|
|
2016-03-11 13:41:18 +00:00
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
window->win32.bigIcon = bigIcon;
|
|
|
|
window->win32.smallIcon = smallIcon;
|
|
|
|
}
|
2016-03-07 13:55:30 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 18:30:31 +00:00
|
|
|
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
|
|
|
{
|
|
|
|
POINT pos = { 0, 0 };
|
|
|
|
ClientToScreen(window->win32.handle, &pos);
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = pos.x;
|
|
|
|
if (ypos)
|
|
|
|
*ypos = pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos)
|
|
|
|
{
|
|
|
|
RECT rect = { xpos, ypos, xpos, ypos };
|
2018-06-07 17:01:07 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
|
|
|
}
|
|
|
|
|
2013-01-24 18:30:31 +00:00
|
|
|
SetWindowPos(window->win32.handle, NULL, rect.left, rect.top, 0, 0,
|
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
|
|
|
|
}
|
|
|
|
|
2012-11-25 13:53:33 +00:00
|
|
|
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
GetClientRect(window->win32.handle, &area);
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = area.right;
|
|
|
|
if (height)
|
|
|
|
*height = area.bottom;
|
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-09-27 19:37:36 +00:00
|
|
|
if (window->monitor)
|
2016-02-23 11:26:42 +00:00
|
|
|
{
|
|
|
|
if (window->monitor->window == window)
|
2018-02-06 12:04:59 +00:00
|
|
|
{
|
2016-02-23 11:26:42 +00:00
|
|
|
acquireMonitor(window);
|
2018-02-06 12:04:59 +00:00
|
|
|
fitToMonitor(window);
|
|
|
|
}
|
2016-02-23 11:26:42 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
2016-02-23 11:26:42 +00:00
|
|
|
RECT rect = { 0, 0, width, height };
|
2018-06-07 17:01:07 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
|
|
|
}
|
|
|
|
|
2013-03-12 16:25:33 +00:00
|
|
|
SetWindowPos(window->win32.handle, HWND_TOP,
|
2016-02-23 11:26:42 +00:00
|
|
|
0, 0, rect.right - rect.left, rect.bottom - rect.top,
|
2013-12-28 19:56:57 +00:00
|
|
|
SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOZORDER);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 01:57:59 +00:00
|
|
|
void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
|
|
|
int minwidth, int minheight,
|
|
|
|
int maxwidth, int maxheight)
|
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom)
|
|
|
|
{
|
|
|
|
RECT area;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-06-03 10:51:57 +00:00
|
|
|
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
|
|
|
|
{
|
|
|
|
_glfwPlatformGetWindowSize(window, width, height);
|
|
|
|
}
|
|
|
|
|
2014-03-25 20:30:13 +00:00
|
|
|
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|
|
|
int* left, int* top,
|
|
|
|
int* right, int* bottom)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
|
|
|
SetRect(&rect, 0, 0, width, height);
|
2018-06-07 17:01:07 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
|
|
|
}
|
2014-03-25 20:30:13 +00:00
|
|
|
|
|
|
|
if (left)
|
|
|
|
*left = -rect.left;
|
|
|
|
if (top)
|
|
|
|
*top = -rect.top;
|
|
|
|
if (right)
|
|
|
|
*right = rect.right - width;
|
|
|
|
if (bottom)
|
|
|
|
*bottom = rect.bottom - height;
|
|
|
|
}
|
|
|
|
|
2017-08-29 17:19:00 +00:00
|
|
|
void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
|
|
|
|
float* xscale, float* yscale)
|
|
|
|
{
|
|
|
|
const HANDLE handle = MonitorFromWindow(window->win32.handle,
|
|
|
|
MONITOR_DEFAULTTONEAREST);
|
|
|
|
_glfwGetMonitorContentScaleWin32(handle, xscale, yscale);
|
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
ShowWindow(window->win32.handle, SW_MINIMIZE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 14:26:00 +00:00
|
|
|
void _glfwPlatformRestoreWindow(_GLFWwindow* window)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
ShowWindow(window->win32.handle, SW_RESTORE);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 10:50:59 +00:00
|
|
|
void _glfwPlatformMaximizeWindow(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
ShowWindow(window->win32.handle, SW_MAXIMIZE);
|
|
|
|
}
|
|
|
|
|
2012-08-21 18:01:57 +00:00
|
|
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
|
|
|
{
|
2018-01-09 10:11:58 +00:00
|
|
|
ShowWindow(window->win32.handle, SW_SHOWNA);
|
2012-08-21 18:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-21 14:42:49 +00:00
|
|
|
void _glfwPlatformHideWindow(_GLFWwindow* window)
|
2014-06-20 11:39:06 +00:00
|
|
|
{
|
2016-02-21 14:42:49 +00:00
|
|
|
ShowWindow(window->win32.handle, SW_HIDE);
|
2014-06-20 11:39:06 +00:00
|
|
|
}
|
|
|
|
|
2017-03-21 13:02:57 +00:00
|
|
|
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
FlashWindow(window->win32.handle, TRUE);
|
|
|
|
}
|
|
|
|
|
2016-02-21 14:42:49 +00:00
|
|
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
2012-08-21 18:01:57 +00:00
|
|
|
{
|
2016-02-21 14:42:49 +00:00
|
|
|
BringWindowToTop(window->win32.handle);
|
|
|
|
SetForegroundWindow(window->win32.handle);
|
|
|
|
SetFocus(window->win32.handle);
|
2012-08-21 18:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
|
|
|
|
_GLFWmonitor* monitor,
|
|
|
|
int xpos, int ypos,
|
|
|
|
int width, int height,
|
|
|
|
int refreshRate)
|
|
|
|
{
|
|
|
|
if (window->monitor == monitor)
|
|
|
|
{
|
|
|
|
if (monitor)
|
|
|
|
{
|
|
|
|
if (monitor->window == window)
|
2018-02-06 12:04:59 +00:00
|
|
|
{
|
2016-02-23 11:26:42 +00:00
|
|
|
acquireMonitor(window);
|
2018-02-06 12:04:59 +00:00
|
|
|
fitToMonitor(window);
|
|
|
|
}
|
2016-02-23 11:26:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT rect = { xpos, ypos, xpos + width, ypos + height };
|
2018-06-07 17:01:07 +00:00
|
|
|
|
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
|
|
|
}
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->monitor)
|
|
|
|
releaseMonitor(window);
|
|
|
|
|
2017-10-26 16:05:56 +00:00
|
|
|
_glfwInputWindowMonitor(window, monitor);
|
2016-02-23 11:26:42 +00:00
|
|
|
|
2019-05-28 00:24:18 +00:00
|
|
|
if (window->monitor)
|
2016-02-23 11:26:42 +00:00
|
|
|
{
|
2018-02-06 12:04:59 +00:00
|
|
|
MONITORINFO mi = { sizeof(mi) };
|
|
|
|
UINT flags = SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOCOPYBITS;
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
if (window->decorated)
|
|
|
|
{
|
2017-11-16 10:03:05 +00:00
|
|
|
DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE);
|
2016-02-23 11:26:42 +00:00
|
|
|
style &= ~WS_OVERLAPPEDWINDOW;
|
|
|
|
style |= getWindowStyle(window);
|
2016-03-29 09:05:42 +00:00
|
|
|
SetWindowLongW(window->win32.handle, GWL_STYLE, style);
|
2018-02-06 12:04:59 +00:00
|
|
|
flags |= SWP_FRAMECHANGED;
|
2016-02-23 11:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
acquireMonitor(window);
|
2018-02-06 12:04:59 +00:00
|
|
|
|
|
|
|
GetMonitorInfo(window->monitor->win32.handle, &mi);
|
|
|
|
SetWindowPos(window->win32.handle, HWND_TOPMOST,
|
|
|
|
mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.top,
|
|
|
|
mi.rcMonitor.right - mi.rcMonitor.left,
|
|
|
|
mi.rcMonitor.bottom - mi.rcMonitor.top,
|
|
|
|
flags);
|
2016-02-23 11:26:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HWND after;
|
|
|
|
RECT rect = { xpos, ypos, xpos + width, ypos + height };
|
2016-03-29 09:05:42 +00:00
|
|
|
DWORD style = GetWindowLongW(window->win32.handle, GWL_STYLE);
|
2016-02-23 11:26:42 +00:00
|
|
|
UINT flags = SWP_NOACTIVATE | SWP_NOCOPYBITS;
|
|
|
|
|
|
|
|
if (window->decorated)
|
|
|
|
{
|
|
|
|
style &= ~WS_POPUP;
|
|
|
|
style |= getWindowStyle(window);
|
2016-03-29 09:05:42 +00:00
|
|
|
SetWindowLongW(window->win32.handle, GWL_STYLE, style);
|
2016-02-23 11:26:42 +00:00
|
|
|
|
|
|
|
flags |= SWP_FRAMECHANGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->floating)
|
|
|
|
after = HWND_TOPMOST;
|
|
|
|
else
|
|
|
|
after = HWND_NOTOPMOST;
|
|
|
|
|
2018-06-07 17:01:07 +00:00
|
|
|
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
|
|
|
{
|
|
|
|
AdjustWindowRectExForDpi(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window),
|
|
|
|
GetDpiForWindow(window->win32.handle));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AdjustWindowRectEx(&rect, getWindowStyle(window),
|
|
|
|
FALSE, getWindowExStyle(window));
|
|
|
|
}
|
|
|
|
|
2016-02-23 11:26:42 +00:00
|
|
|
SetWindowPos(window->win32.handle, after,
|
|
|
|
rect.left, rect.top,
|
|
|
|
rect.right - rect.left, rect.bottom - rect.top,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 11:25:48 +00:00
|
|
|
int _glfwPlatformWindowFocused(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return window->win32.handle == GetActiveWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowIconified(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return IsIconic(window->win32.handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return IsWindowVisible(window->win32.handle);
|
|
|
|
}
|
|
|
|
|
2015-10-13 10:50:59 +00:00
|
|
|
int _glfwPlatformWindowMaximized(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
return IsZoomed(window->win32.handle);
|
|
|
|
}
|
|
|
|
|
2018-01-04 12:50:58 +00:00
|
|
|
int _glfwPlatformWindowHovered(_GLFWwindow* window)
|
|
|
|
{
|
2019-01-22 19:54:16 +00:00
|
|
|
return cursorInContentArea(window);
|
2018-01-04 12:50:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-18 16:10:57 +00:00
|
|
|
int _glfwPlatformFramebufferTransparent(_GLFWwindow* window)
|
|
|
|
{
|
2018-08-12 11:58:30 +00:00
|
|
|
BOOL enabled;
|
|
|
|
|
|
|
|
if (!window->win32.transparent)
|
|
|
|
return GLFW_FALSE;
|
|
|
|
|
|
|
|
if (!IsWindowsVistaOrGreater())
|
|
|
|
return GLFW_FALSE;
|
|
|
|
|
|
|
|
return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled;
|
2017-09-18 16:10:57 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 23:52:22 +00:00
|
|
|
void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
|
|
|
updateWindowStyles(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-25 21:14:45 +00:00
|
|
|
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
BYTE alpha;
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
if ((GetWindowLongW(window->win32.handle, GWL_EXSTYLE) & WS_EX_LAYERED) &&
|
|
|
|
GetLayeredWindowAttributes(window->win32.handle, NULL, &alpha, &flags))
|
|
|
|
{
|
|
|
|
if (flags & LWA_ALPHA)
|
|
|
|
return alpha / 255.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
|
|
|
{
|
|
|
|
if (opacity < 1.f)
|
|
|
|
{
|
|
|
|
const BYTE alpha = (BYTE) (255 * opacity);
|
|
|
|
DWORD style = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
|
|
|
|
style |= WS_EX_LAYERED;
|
|
|
|
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, style);
|
|
|
|
SetLayeredWindowAttributes(window->win32.handle, 0, alpha, LWA_ALPHA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD style = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
|
|
|
|
style &= ~WS_EX_LAYERED;
|
|
|
|
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-11 18:10:20 +00:00
|
|
|
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
2018-12-14 02:08:25 +00:00
|
|
|
{
|
2019-02-11 18:10:20 +00:00
|
|
|
if (_glfw.win32.disabledCursorWindow != window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
enableRawMouseMotion(window);
|
|
|
|
else
|
|
|
|
disableRawMouseMotion(window);
|
2018-12-14 02:08:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 18:10:20 +00:00
|
|
|
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
2018-12-14 02:08:25 +00:00
|
|
|
{
|
|
|
|
return GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
void _glfwPlatformPollEvents(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
2016-05-30 19:21:09 +00:00
|
|
|
HWND handle;
|
|
|
|
_GLFWwindow* window;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2014-03-06 17:30:14 +00:00
|
|
|
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-09-19 11:17:53 +00:00
|
|
|
if (msg.message == WM_QUIT)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2017-02-09 19:55:29 +00:00
|
|
|
// 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
|
2010-09-13 21:50:04 +00:00
|
|
|
|
2016-05-30 19:21:09 +00:00
|
|
|
window = _glfw.windowListHead;
|
2012-09-19 11:17:53 +00:00
|
|
|
while (window)
|
2010-09-10 20:03:36 +00:00
|
|
|
{
|
2012-09-19 11:17:53 +00:00
|
|
|
_glfwInputWindowCloseRequest(window);
|
|
|
|
window = window->next;
|
2010-09-10 20:03:36 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
2012-09-19 11:17:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
2014-03-06 17:30:14 +00:00
|
|
|
DispatchMessageW(&msg);
|
2012-09-19 11:17:53 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 19:21:09 +00:00
|
|
|
handle = GetActiveWindow();
|
|
|
|
if (handle)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2017-01-29 17:47:59 +00:00
|
|
|
// NOTE: Shift keys on Windows tend to "stick" when both are pressed as
|
|
|
|
// no key up message is generated by the first key release
|
2017-02-09 19:55:29 +00:00
|
|
|
// The other half of this is in the handling of WM_KEYUP
|
2017-01-29 17:47:59 +00:00
|
|
|
// HACK: Query actual key state and synthesize release events as needed
|
2016-05-30 19:21:09 +00:00
|
|
|
window = GetPropW(handle, L"GLFW");
|
|
|
|
if (window)
|
2013-02-20 16:44:16 +00:00
|
|
|
{
|
2017-01-29 17:47:59 +00:00
|
|
|
const GLFWbool lshift = (GetAsyncKeyState(VK_LSHIFT) >> 15) & 1;
|
|
|
|
const GLFWbool rshift = (GetAsyncKeyState(VK_RSHIFT) >> 15) & 1;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2017-01-29 17:47:59 +00:00
|
|
|
if (!lshift && window->keys[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS)
|
2017-01-29 15:18:58 +00:00
|
|
|
{
|
2017-01-29 17:47:59 +00:00
|
|
|
const int mods = getAsyncKeyMods();
|
2017-01-29 15:18:58 +00:00
|
|
|
const int scancode = _glfw.win32.scancodes[GLFW_KEY_LEFT_SHIFT];
|
|
|
|
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT, scancode, GLFW_RELEASE, mods);
|
|
|
|
}
|
2017-01-29 17:47:59 +00:00
|
|
|
else if (!rshift && window->keys[GLFW_KEY_RIGHT_SHIFT] == GLFW_PRESS)
|
2017-01-29 15:18:58 +00:00
|
|
|
{
|
2017-01-29 17:47:59 +00:00
|
|
|
const int mods = getAsyncKeyMods();
|
2017-01-29 15:18:58 +00:00
|
|
|
const int scancode = _glfw.win32.scancodes[GLFW_KEY_RIGHT_SHIFT];
|
|
|
|
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT, scancode, GLFW_RELEASE, mods);
|
|
|
|
}
|
2013-02-20 16:44:16 +00:00
|
|
|
}
|
2016-05-30 19:21:09 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2016-05-30 19:21:09 +00:00
|
|
|
window = _glfw.win32.disabledCursorWindow;
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
_glfwPlatformGetWindowSize(window, &width, &height);
|
2015-08-16 11:55:44 +00:00
|
|
|
|
2016-05-30 19:21:09 +00:00
|
|
|
// 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);
|
2011-09-06 11:55:29 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 20:03:36 +00:00
|
|
|
void _glfwPlatformWaitEvents(void)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
WaitMessage();
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
2016-02-02 20:11:16 +00:00
|
|
|
void _glfwPlatformWaitEventsTimeout(double timeout)
|
|
|
|
{
|
|
|
|
MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS);
|
|
|
|
|
|
|
|
_glfwPlatformPollEvents();
|
|
|
|
}
|
|
|
|
|
2014-02-10 17:16:58 +00:00
|
|
|
void _glfwPlatformPostEmptyEvent(void)
|
|
|
|
{
|
2016-09-05 12:34:03 +00:00
|
|
|
PostMessage(_glfw.win32.helperWindowHandle, WM_NULL, 0, 0);
|
2014-02-10 17:16:58 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 17:24:01 +00:00
|
|
|
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
|
|
|
{
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
if (GetCursorPos(&pos))
|
|
|
|
{
|
|
|
|
ScreenToClient(window->win32.handle, &pos);
|
|
|
|
|
|
|
|
if (xpos)
|
|
|
|
*xpos = pos.x;
|
|
|
|
if (ypos)
|
|
|
|
*ypos = pos.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 14:16:21 +00:00
|
|
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2013-04-04 14:16:21 +00:00
|
|
|
POINT pos = { (int) xpos, (int) ypos };
|
2014-02-11 17:24:01 +00:00
|
|
|
|
|
|
|
// Store the new position so it can be recognized later
|
2016-05-24 10:23:58 +00:00
|
|
|
window->win32.lastCursorPosX = pos.x;
|
|
|
|
window->win32.lastCursorPosY = pos.y;
|
2014-02-11 17:24:01 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
ClientToScreen(window->win32.handle, &pos);
|
2010-09-10 20:03:36 +00:00
|
|
|
SetCursorPos(pos.x, pos.y);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 11:04:56 +00:00
|
|
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
2011-10-01 05:40:36 +00:00
|
|
|
{
|
2015-07-02 11:04:56 +00:00
|
|
|
if (mode == GLFW_CURSOR_DISABLED)
|
2016-05-25 12:06:02 +00:00
|
|
|
{
|
2018-04-17 17:54:36 +00:00
|
|
|
if (_glfwPlatformWindowFocused(window))
|
|
|
|
disableCursor(window);
|
2016-05-25 12:06:02 +00:00
|
|
|
}
|
2016-05-30 19:21:09 +00:00
|
|
|
else if (_glfw.win32.disabledCursorWindow == window)
|
2018-04-17 17:54:36 +00:00
|
|
|
enableCursor(window);
|
2019-01-22 19:54:16 +00:00
|
|
|
else if (cursorInContentArea(window))
|
2016-05-30 19:21:09 +00:00
|
|
|
updateCursorImage(window);
|
2011-10-01 05:40:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 21:00:17 +00:00
|
|
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
2015-07-02 12:24:50 +00:00
|
|
|
{
|
2017-02-07 02:29:57 +00:00
|
|
|
return _glfw.win32.keynames[_glfw.win32.keycodes[scancode]];
|
2015-07-02 12:24:50 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 13:40:31 +00:00
|
|
|
int _glfwPlatformGetKeyScancode(int key)
|
2016-08-11 17:11:40 +00:00
|
|
|
{
|
2016-09-07 13:43:39 +00:00
|
|
|
return _glfw.win32.scancodes[key];
|
2016-08-11 17:11:40 +00:00
|
|
|
}
|
|
|
|
|
2014-02-23 15:43:17 +00:00
|
|
|
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
|
|
|
const GLFWimage* image,
|
|
|
|
int xhot, int yhot)
|
2013-12-04 13:19:22 +00:00
|
|
|
{
|
2016-03-07 13:55:30 +00:00
|
|
|
cursor->win32.handle = (HCURSOR) createIcon(image, xhot, yhot, GLFW_FALSE);
|
2014-01-23 14:24:57 +00:00
|
|
|
if (!cursor->win32.handle)
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2013-12-04 13:19:22 +00:00
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2013-12-04 13:19:22 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 14:52:16 +00:00
|
|
|
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|
|
|
{
|
2019-02-11 17:14:03 +00:00
|
|
|
int id = 0;
|
2018-08-15 10:52:00 +00:00
|
|
|
|
|
|
|
if (shape == GLFW_ARROW_CURSOR)
|
2019-02-11 17:14:03 +00:00
|
|
|
id = OCR_NORMAL;
|
2018-08-15 10:52:00 +00:00
|
|
|
else if (shape == GLFW_IBEAM_CURSOR)
|
2019-02-11 17:14:03 +00:00
|
|
|
id = OCR_IBEAM;
|
2018-08-15 10:52:00 +00:00
|
|
|
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
2019-02-11 17:14:03 +00:00
|
|
|
id = OCR_CROSS;
|
2018-08-15 10:52:00 +00:00
|
|
|
else if (shape == GLFW_HAND_CURSOR)
|
2019-02-11 17:14:03 +00:00
|
|
|
id = OCR_HAND;
|
2018-08-15 10:52:00 +00:00
|
|
|
else if (shape == GLFW_HRESIZE_CURSOR)
|
2019-02-11 17:14:03 +00:00
|
|
|
id = OCR_SIZEWE;
|
2018-08-15 10:52:00 +00:00
|
|
|
else if (shape == GLFW_VRESIZE_CURSOR)
|
2019-02-11 17:14:03 +00:00
|
|
|
id = OCR_SIZENS;
|
2018-08-15 10:52:00 +00:00
|
|
|
else
|
|
|
|
return GLFW_FALSE;
|
|
|
|
|
2019-02-13 22:21:05 +00:00
|
|
|
cursor->win32.handle = LoadImageW(NULL,
|
|
|
|
MAKEINTRESOURCEW(id), IMAGE_CURSOR, 0, 0,
|
|
|
|
LR_DEFAULTSIZE | LR_SHARED);
|
2014-09-02 14:52:16 +00:00
|
|
|
if (!cursor->win32.handle)
|
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to create standard cursor");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2014-09-02 14:52:16 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2014-09-02 14:52:16 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 13:19:22 +00:00
|
|
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
|
|
|
|
{
|
2014-01-23 14:24:57 +00:00
|
|
|
if (cursor->win32.handle)
|
|
|
|
DestroyIcon((HICON) cursor->win32.handle);
|
2013-12-04 13:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
|
|
|
{
|
2019-01-22 19:54:16 +00:00
|
|
|
if (cursorInContentArea(window))
|
2016-05-30 19:21:09 +00:00
|
|
|
updateCursorImage(window);
|
2013-12-04 13:19:22 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 20:11:58 +00:00
|
|
|
void _glfwPlatformSetClipboardString(const char* string)
|
2014-09-09 14:26:57 +00:00
|
|
|
{
|
2016-06-23 15:06:03 +00:00
|
|
|
int characterCount;
|
2016-06-23 15:40:30 +00:00
|
|
|
HANDLE object;
|
|
|
|
WCHAR* buffer;
|
2014-09-09 14:26:57 +00:00
|
|
|
|
2016-06-23 15:06:03 +00:00
|
|
|
characterCount = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0);
|
|
|
|
if (!characterCount)
|
2014-09-09 14:26:57 +00:00
|
|
|
return;
|
|
|
|
|
2016-06-23 15:40:30 +00:00
|
|
|
object = GlobalAlloc(GMEM_MOVEABLE, characterCount * sizeof(WCHAR));
|
|
|
|
if (!object)
|
2014-09-09 14:26:57 +00:00
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to allocate global handle for clipboard");
|
2014-09-09 14:26:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-23 15:40:30 +00:00
|
|
|
buffer = GlobalLock(object);
|
|
|
|
if (!buffer)
|
2016-06-23 15:06:03 +00:00
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to lock global handle");
|
2016-06-23 15:40:30 +00:00
|
|
|
GlobalFree(object);
|
2016-06-23 15:06:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-23 15:40:30 +00:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, string, -1, buffer, characterCount);
|
|
|
|
GlobalUnlock(object);
|
2014-09-09 14:26:57 +00:00
|
|
|
|
2016-05-30 19:19:00 +00:00
|
|
|
if (!OpenClipboard(_glfw.win32.helperWindowHandle))
|
2014-09-09 14:26:57 +00:00
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to open clipboard");
|
2016-06-23 15:40:30 +00:00
|
|
|
GlobalFree(object);
|
2014-09-09 14:26:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmptyClipboard();
|
2016-06-23 15:40:30 +00:00
|
|
|
SetClipboardData(CF_UNICODETEXT, object);
|
2014-09-09 14:26:57 +00:00
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
2017-11-04 20:11:58 +00:00
|
|
|
const char* _glfwPlatformGetClipboardString(void)
|
2014-09-09 14:26:57 +00:00
|
|
|
{
|
2016-06-23 15:40:30 +00:00
|
|
|
HANDLE object;
|
|
|
|
WCHAR* buffer;
|
2014-09-09 14:26:57 +00:00
|
|
|
|
2016-05-30 19:19:00 +00:00
|
|
|
if (!OpenClipboard(_glfw.win32.helperWindowHandle))
|
2014-09-09 14:26:57 +00:00
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to open clipboard");
|
2014-09-09 14:26:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-23 15:40:30 +00:00
|
|
|
object = GetClipboardData(CF_UNICODETEXT);
|
|
|
|
if (!object)
|
2014-09-09 14:26:57 +00:00
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"Win32: Failed to convert clipboard to string");
|
2014-09-09 14:26:57 +00:00
|
|
|
CloseClipboard();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-23 15:40:30 +00:00
|
|
|
buffer = GlobalLock(object);
|
|
|
|
if (!buffer)
|
|
|
|
{
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
|
|
|
"Win32: Failed to lock global handle");
|
2016-06-23 15:40:30 +00:00
|
|
|
CloseClipboard();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-09 14:26:57 +00:00
|
|
|
free(_glfw.win32.clipboardString);
|
2017-01-19 19:29:27 +00:00
|
|
|
_glfw.win32.clipboardString = _glfwCreateUTF8FromWideStringWin32(buffer);
|
2014-09-09 14:26:57 +00:00
|
|
|
|
2016-06-23 15:40:30 +00:00
|
|
|
GlobalUnlock(object);
|
2014-09-09 14:26:57 +00:00
|
|
|
CloseClipboard();
|
|
|
|
|
|
|
|
return _glfw.win32.clipboardString;
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:25:52 +00:00
|
|
|
void _glfwPlatformGetRequiredInstanceExtensions(char** extensions)
|
2015-08-10 18:19:04 +00:00
|
|
|
{
|
2016-08-22 18:25:52 +00:00
|
|
|
if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_win32_surface)
|
|
|
|
return;
|
2015-08-10 18:19:04 +00:00
|
|
|
|
2016-08-22 18:25:52 +00:00
|
|
|
extensions[0] = "VK_KHR_surface";
|
|
|
|
extensions[1] = "VK_KHR_win32_surface";
|
2015-08-10 18:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
|
|
|
|
VkPhysicalDevice device,
|
2016-03-23 09:24:01 +00:00
|
|
|
uint32_t queuefamily)
|
2015-08-10 18:19:04 +00:00
|
|
|
{
|
2017-09-17 12:39:17 +00:00
|
|
|
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
|
|
|
|
vkGetPhysicalDeviceWin32PresentationSupportKHR =
|
2015-08-10 18:19:04 +00:00
|
|
|
(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);
|
|
|
|
}
|
|
|
|
|
|
|
|
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
|
|
|
|
_GLFWwindow* window,
|
|
|
|
const VkAllocationCallbacks* allocator,
|
|
|
|
VkSurfaceKHR* surface)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-04-17 13:29:17 +00:00
|
|
|
|
2013-01-15 21:38:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-19 23:28:08 +00:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2013-01-15 21:38:14 +00:00
|
|
|
return window->win32.handle;
|
|
|
|
}
|
2011-10-01 05:40:36 +00:00
|
|
|
|