Add a function to disable the use of raw input per window (support X11)

This commit is contained in:
Nathan Poirier 2018-12-14 03:08:25 +01:00
parent f9923e9095
commit a905b080c9
No known key found for this signature in database
GPG Key ID: 94C1CE923BD6A70C
7 changed files with 55 additions and 4 deletions

View File

@ -1552,6 +1552,10 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
[window->ns.object setAlphaValue:opacity]; [window->ns.object setAlphaValue:opacity];
} }
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled)
{
}
void _glfwPlatformPollEvents(void) void _glfwPlatformPollEvents(void)
{ {
if (!initializeAppKit()) if (!initializeAppKit())

View File

@ -390,6 +390,7 @@ struct _GLFWwindow
char keys[GLFW_KEY_LAST + 1]; char keys[GLFW_KEY_LAST + 1];
// Virtual cursor position when cursor is disabled // Virtual cursor position when cursor is disabled
double virtualCursorPosX, virtualCursorPosY; double virtualCursorPosX, virtualCursorPosY;
GLFWbool useRawInput;
_GLFWcontext context; _GLFWcontext context;
@ -666,6 +667,7 @@ void _glfwPlatformSetWindowResizable(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled); void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled); void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity); void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity);
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled);
void _glfwPlatformPollEvents(void); void _glfwPlatformPollEvents(void);
void _glfwPlatformWaitEvents(void); void _glfwPlatformWaitEvents(void);

View File

@ -196,6 +196,10 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
{ {
} }
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled)
{
}
void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
} }

View File

@ -1843,6 +1843,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
} }
} }
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled)
{
// TODO
}
void _glfwPlatformPollEvents(void) void _glfwPlatformPollEvents(void)
{ {
MSG msg; MSG msg;

View File

@ -203,6 +203,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
window->floating = wndconfig.floating; window->floating = wndconfig.floating;
window->focusOnShow = wndconfig.focusOnShow; window->focusOnShow = wndconfig.focusOnShow;
window->cursorMode = GLFW_CURSOR_NORMAL; window->cursorMode = GLFW_CURSOR_NORMAL;
window->useRawInput = GLFW_TRUE;
window->minwidth = GLFW_DONT_CARE; window->minwidth = GLFW_DONT_CARE;
window->minheight = GLFW_DONT_CARE; window->minheight = GLFW_DONT_CARE;
@ -970,6 +971,23 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
return window->userPointer; return window->userPointer;
} }
GLFWAPI int glfwGetWindowUseRawInput(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
return window->useRawInput;
}
GLFWAPI void glfwSetWindowUseRawInput(GLFWwindow* handle,
int value)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_glfwPlatformSetWindowUseRawInput(window, value ? GLFW_TRUE : GLFW_FALSE);
}
GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle, GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle,
GLFWwindowposfun cbfun) GLFWwindowposfun cbfun)
{ {
@ -1110,4 +1128,3 @@ GLFWAPI void glfwPostEmptyEvent(void)
_glfwPlatformPostEmptyEvent(); _glfwPlatformPostEmptyEvent();
} }

View File

@ -1304,6 +1304,10 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
{ {
} }
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled)
{
}
void _glfwPlatformPollEvents(void) void _glfwPlatformPollEvents(void)
{ {
handleEvents(0); handleEvents(0);

View File

@ -26,6 +26,7 @@
//======================================================================== //========================================================================
#include "internal.h" #include "internal.h"
#include "x11_platform.h"
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
@ -535,7 +536,7 @@ static void updateCursorImage(_GLFWwindow* window)
// //
static void disableCursor(_GLFWwindow* window) static void disableCursor(_GLFWwindow* window)
{ {
if (_glfw.x11.xi.available) if (_glfw.x11.xi.available && window->useRawInput)
{ {
XIEventMask em; XIEventMask em;
unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 }; unsigned char mask[XIMaskLen(XI_RawMotion)] = { 0 };
@ -566,7 +567,7 @@ static void disableCursor(_GLFWwindow* window)
// //
static void enableCursor(_GLFWwindow* window) static void enableCursor(_GLFWwindow* window)
{ {
if (_glfw.x11.xi.available) if (_glfw.x11.xi.available && window->useRawInput)
{ {
XIEventMask em; XIEventMask em;
unsigned char mask[] = { 0 }; unsigned char mask[] = { 0 };
@ -1192,6 +1193,7 @@ static void processEvent(XEvent *event)
_GLFWwindow* window = _glfw.x11.disabledCursorWindow; _GLFWwindow* window = _glfw.x11.disabledCursorWindow;
if (window && if (window &&
window->useRawInput &&
event->xcookie.extension == _glfw.x11.xi.majorOpcode && event->xcookie.extension == _glfw.x11.xi.majorOpcode &&
XGetEventData(_glfw.x11.display, &event->xcookie) && XGetEventData(_glfw.x11.display, &event->xcookie) &&
event->xcookie.evtype == XI_RawMotion) event->xcookie.evtype == XI_RawMotion)
@ -1492,7 +1494,7 @@ static void processEvent(XEvent *event)
{ {
if (_glfw.x11.disabledCursorWindow != window) if (_glfw.x11.disabledCursorWindow != window)
return; return;
if (_glfw.x11.xi.available) if (_glfw.x11.xi.available && window->useRawInput)
return; return;
const int dx = x - window->x11.lastCursorPosX; const int dx = x - window->x11.lastCursorPosX;
@ -2652,6 +2654,19 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
PropModeReplace, (unsigned char*) &value, 1); PropModeReplace, (unsigned char*) &value, 1);
} }
void _glfwPlatformSetWindowUseRawInput(_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);
}
}
void _glfwPlatformPollEvents(void) void _glfwPlatformPollEvents(void)
{ {
_GLFWwindow* window; _GLFWwindow* window;