mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 21:56:36 +00:00
Add a function to disable the use of raw input per window (support X11)
This commit is contained in:
parent
f9923e9095
commit
a905b080c9
@ -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())
|
||||||
|
@ -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);
|
||||||
|
@ -196,6 +196,10 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _glfwPlatformSetWindowUseRawInput(_GLFWwindow* window, GLFWbool enabled)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
void _glfwPlatformShowWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
19
src/window.c
19
src/window.c
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user