mirror of
https://github.com/glfw/glfw.git
synced 2026-11-18 12:54:54 +00:00
Rename raw input to raw mouse motion, cleanup
This renames 'raw input' to 'raw mouse motion' as there are other kinds of raw input. The update path is restructured to avoid reinitializing all of disabled cursor mode. Modification of shared state is moved out into shared code. Raw mouse motion is disabled by default for compatibility. Related to #1401.
This commit is contained in:
+2
-3
@@ -1297,12 +1297,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
[window->ns.object setAlphaValue:opacity];
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
||||
{
|
||||
window->useRawInput = enabled;
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformRawInputSupported(void)
|
||||
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
+24
-7
@@ -463,6 +463,7 @@ void _glfwCenterCursorInContentArea(_GLFWwindow* window)
|
||||
_glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -484,8 +485,8 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode)
|
||||
return window->stickyMouseButtons;
|
||||
case GLFW_LOCK_KEY_MODS:
|
||||
return window->lockKeyMods;
|
||||
case GLFW_RAW_INPUT:
|
||||
return window->useRawInput;
|
||||
case GLFW_RAW_MOUSE_MOTION:
|
||||
return window->rawMouseMotion;
|
||||
}
|
||||
|
||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
|
||||
@@ -562,17 +563,33 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
|
||||
window->stickyMouseButtons = value;
|
||||
}
|
||||
else if (mode == GLFW_LOCK_KEY_MODS)
|
||||
{
|
||||
window->lockKeyMods = value ? GLFW_TRUE : GLFW_FALSE;
|
||||
else if (mode == GLFW_RAW_INPUT)
|
||||
_glfwPlatformSetRawInput(window, value ? GLFW_TRUE : GLFW_FALSE);
|
||||
}
|
||||
else if (mode == GLFW_RAW_MOUSE_MOTION)
|
||||
{
|
||||
if (!_glfwPlatformRawMouseMotionSupported())
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Raw mouse motion is not supported on this system");
|
||||
return;
|
||||
}
|
||||
|
||||
value = value ? GLFW_TRUE : GLFW_FALSE;
|
||||
if (window->rawMouseMotion == value)
|
||||
return;
|
||||
|
||||
window->rawMouseMotion = value;
|
||||
_glfwPlatformSetRawMouseMotion(window, value);
|
||||
}
|
||||
else
|
||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode);
|
||||
}
|
||||
|
||||
GLFWAPI int glfwRawInputSupported(void)
|
||||
GLFWAPI int glfwRawMouseMotionSupported(void)
|
||||
{
|
||||
_GLFW_REQUIRE_INIT_OR_RETURN(0);
|
||||
return _glfwPlatformRawInputSupported();
|
||||
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
|
||||
return _glfwPlatformRawMouseMotionSupported();
|
||||
}
|
||||
|
||||
GLFWAPI const char* glfwGetKeyName(int key, int scancode)
|
||||
|
||||
+3
-3
@@ -390,7 +390,7 @@ struct _GLFWwindow
|
||||
char keys[GLFW_KEY_LAST + 1];
|
||||
// Virtual cursor position when cursor is disabled
|
||||
double virtualCursorPosX, virtualCursorPosY;
|
||||
GLFWbool useRawInput;
|
||||
GLFWbool rawMouseMotion;
|
||||
|
||||
_GLFWcontext context;
|
||||
|
||||
@@ -597,8 +597,8 @@ const char* _glfwPlatformGetVersionString(void);
|
||||
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
|
||||
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
|
||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled);
|
||||
GLFWbool _glfwPlatformRawInputSupported(void);
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled);
|
||||
GLFWbool _glfwPlatformRawMouseMotionSupported(void);
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
||||
const GLFWimage* image, int xhot, int yhot);
|
||||
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
|
||||
|
||||
+2
-3
@@ -196,12 +196,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
{
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
||||
{
|
||||
window->useRawInput = enabled;
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformRawInputSupported(void)
|
||||
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
+48
-30
@@ -267,12 +267,36 @@ static void updateClipRect(_GLFWwindow* window)
|
||||
ClipCursor(NULL);
|
||||
}
|
||||
|
||||
// Enables WM_INPUT messages for the mouse for the specified window
|
||||
//
|
||||
static void enableRawMouseMotion(_GLFWwindow* window)
|
||||
{
|
||||
const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle };
|
||||
|
||||
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)
|
||||
{
|
||||
const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle };
|
||||
|
||||
_glfw.win32.disabledCursorWindow = window;
|
||||
_glfwPlatformGetCursorPos(window,
|
||||
&_glfw.win32.restoreCursorPosX,
|
||||
@@ -281,18 +305,16 @@ static void disableCursor(_GLFWwindow* window)
|
||||
_glfwCenterCursorInContentArea(window);
|
||||
updateClipRect(window);
|
||||
|
||||
if (window->useRawInput && !RegisterRawInputDevices(&rid, 1, sizeof(rid)))
|
||||
{
|
||||
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
||||
"Win32: Failed to register raw input device");
|
||||
}
|
||||
if (window->rawMouseMotion)
|
||||
enableRawMouseMotion(window);
|
||||
}
|
||||
|
||||
// Exit disabled cursor mode for the specified window
|
||||
//
|
||||
static void enableCursor(_GLFWwindow* window)
|
||||
{
|
||||
const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_REMOVE, NULL };
|
||||
if (window->rawMouseMotion)
|
||||
disableRawMouseMotion(window);
|
||||
|
||||
_glfw.win32.disabledCursorWindow = NULL;
|
||||
updateClipRect(NULL);
|
||||
@@ -300,12 +322,6 @@ static void enableCursor(_GLFWwindow* window)
|
||||
_glfw.win32.restoreCursorPosX,
|
||||
_glfw.win32.restoreCursorPosY);
|
||||
updateCursorImage(window);
|
||||
|
||||
if (window->useRawInput && !RegisterRawInputDevices(&rid, 1, sizeof(rid)))
|
||||
{
|
||||
_glfwInputErrorWin32(GLFW_PLATFORM_ERROR,
|
||||
"Win32: Failed to remove raw input device");
|
||||
}
|
||||
}
|
||||
|
||||
// Returns whether the cursor is in the content area of the specified window
|
||||
@@ -817,11 +833,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
// Disabled cursor motion input is provided by WM_INPUT
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
if (_glfw.win32.disabledCursorWindow != window || window->useRawInput)
|
||||
break;
|
||||
|
||||
const int dx = x - window->win32.lastCursorPosX;
|
||||
const int dy = y - window->win32.lastCursorPosY;
|
||||
|
||||
if (_glfw.win32.disabledCursorWindow != window)
|
||||
break;
|
||||
if (window->rawMouseMotion)
|
||||
break;
|
||||
|
||||
_glfwInputCursorPos(window,
|
||||
window->virtualCursorPosX + dx,
|
||||
window->virtualCursorPosY + dy);
|
||||
@@ -855,8 +874,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
RAWINPUT* data;
|
||||
int dx, dy;
|
||||
|
||||
// Only process input when disabled cursor mode is applied
|
||||
if (_glfw.win32.disabledCursorWindow != window || !window->useRawInput)
|
||||
if (_glfw.win32.disabledCursorWindow != window)
|
||||
break;
|
||||
if (!window->rawMouseMotion)
|
||||
break;
|
||||
|
||||
GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
||||
@@ -1854,20 +1874,18 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
||||
{
|
||||
if (window->useRawInput != enabled)
|
||||
{
|
||||
int update = (_glfw.win32.disabledCursorWindow == window);
|
||||
if (update)
|
||||
enableCursor(window);
|
||||
window->useRawInput = enabled;
|
||||
if (update)
|
||||
disableCursor(window);
|
||||
}
|
||||
if (_glfw.win32.disabledCursorWindow != window)
|
||||
return;
|
||||
|
||||
if (enabled)
|
||||
enableRawMouseMotion(window);
|
||||
else
|
||||
disableRawMouseMotion(window);
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformRawInputSupported(void)
|
||||
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
||||
window->floating = wndconfig.floating;
|
||||
window->focusOnShow = wndconfig.focusOnShow;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
window->useRawInput = GLFW_TRUE;
|
||||
|
||||
window->minwidth = GLFW_DONT_CARE;
|
||||
window->minheight = GLFW_DONT_CARE;
|
||||
|
||||
+2
-3
@@ -1318,12 +1318,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
{
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
||||
{
|
||||
window->useRawInput = enabled;
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformRawInputSupported(void)
|
||||
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
+47
-36
@@ -522,22 +522,41 @@ static void updateCursorImage(_GLFWwindow* window)
|
||||
}
|
||||
}
|
||||
|
||||
// Enable XI2 raw mouse motion events
|
||||
//
|
||||
static void enableRawMouseMotion(_GLFWwindow* window)
|
||||
{
|
||||
XIEventMask em;
|
||||
unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 };
|
||||
|
||||
em.deviceid = XIAllMasterDevices;
|
||||
em.mask_len = sizeof(mask);
|
||||
em.mask = mask;
|
||||
XISetMask(mask, XI_RawMotion);
|
||||
|
||||
XISelectEvents(_glfw.x11.display, _glfw.x11.root, &em, 1);
|
||||
}
|
||||
|
||||
// Disable XI2 raw mouse motion events
|
||||
//
|
||||
static void disableRawMouseMotion(_GLFWwindow* window)
|
||||
{
|
||||
XIEventMask em;
|
||||
unsigned char mask[] = { 0 };
|
||||
|
||||
em.deviceid = XIAllMasterDevices;
|
||||
em.mask_len = sizeof(mask);
|
||||
em.mask = mask;
|
||||
|
||||
XISelectEvents(_glfw.x11.display, _glfw.x11.root, &em, 1);
|
||||
}
|
||||
|
||||
// Apply disabled cursor mode to a focused window
|
||||
//
|
||||
static void disableCursor(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfw.x11.xi.available && window->useRawInput)
|
||||
{
|
||||
XIEventMask em;
|
||||
unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 };
|
||||
|
||||
em.deviceid = XIAllMasterDevices;
|
||||
em.mask_len = sizeof(mask);
|
||||
em.mask = mask;
|
||||
XISetMask(mask, XI_RawMotion);
|
||||
|
||||
XISelectEvents(_glfw.x11.display, _glfw.x11.root, &em, 1);
|
||||
}
|
||||
if (window->rawMouseMotion)
|
||||
enableRawMouseMotion(window);
|
||||
|
||||
_glfw.x11.disabledCursorWindow = window;
|
||||
_glfwPlatformGetCursorPos(window,
|
||||
@@ -557,17 +576,8 @@ static void disableCursor(_GLFWwindow* window)
|
||||
//
|
||||
static void enableCursor(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfw.x11.xi.available && window->useRawInput)
|
||||
{
|
||||
XIEventMask em;
|
||||
unsigned char mask[] = { 0 };
|
||||
|
||||
em.deviceid = XIAllMasterDevices;
|
||||
em.mask_len = sizeof(mask);
|
||||
em.mask = mask;
|
||||
|
||||
XISelectEvents(_glfw.x11.display, _glfw.x11.root, &em, 1);
|
||||
}
|
||||
if (window->rawMouseMotion)
|
||||
disableRawMouseMotion(window);
|
||||
|
||||
_glfw.x11.disabledCursorWindow = NULL;
|
||||
XUngrabPointer(_glfw.x11.display, CurrentTime);
|
||||
@@ -1183,7 +1193,7 @@ static void processEvent(XEvent *event)
|
||||
_GLFWwindow* window = _glfw.x11.disabledCursorWindow;
|
||||
|
||||
if (window &&
|
||||
window->useRawInput &&
|
||||
window->rawMouseMotion &&
|
||||
event->xcookie.extension == _glfw.x11.xi.majorOpcode &&
|
||||
XGetEventData(_glfw.x11.display, &event->xcookie) &&
|
||||
event->xcookie.evtype == XI_RawMotion)
|
||||
@@ -1484,7 +1494,7 @@ static void processEvent(XEvent *event)
|
||||
{
|
||||
if (_glfw.x11.disabledCursorWindow != window)
|
||||
return;
|
||||
if (_glfw.x11.xi.available && window->useRawInput)
|
||||
if (window->rawMouseMotion)
|
||||
return;
|
||||
|
||||
const int dx = x - window->x11.lastCursorPosX;
|
||||
@@ -2653,20 +2663,21 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
PropModeReplace, (unsigned char*) &value, 1);
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, GLFWbool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, GLFWbool enabled)
|
||||
{
|
||||
if (window->useRawInput != enabled)
|
||||
{
|
||||
int update = (_glfw.x11.disabledCursorWindow == window && _glfw.x11.xi.available);
|
||||
if (update)
|
||||
enableCursor(window);
|
||||
window->useRawInput = enabled;
|
||||
if (update)
|
||||
disableCursor(window);
|
||||
}
|
||||
if (!_glfw.x11.xi.available)
|
||||
return;
|
||||
|
||||
if (_glfw.x11.disabledCursorWindow != window)
|
||||
return;
|
||||
|
||||
if (enabled)
|
||||
enableRawMouseMotion(window);
|
||||
else
|
||||
disableRawMouseMotion(window);
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformRawInputSupported(void)
|
||||
GLFWbool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return _glfw.x11.xi.available;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user