mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-25 02:17:03 +00:00
Rename raw input to raw mouse motion, cleanup
From upstream: 1155c83013.
This commit is contained in:
parent
48fb051253
commit
55ad228166
9 changed files with 105 additions and 84 deletions
|
|
@ -1863,12 +1863,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
|||
[window->ns.object setAlphaValue:opacity];
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, bool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window UNUSED, bool enabled UNUSED)
|
||||
{
|
||||
window->useRawInput = enabled;
|
||||
}
|
||||
|
||||
bool _glfwPlatformRawInputSupported(void)
|
||||
bool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
54
glfw/glfw3.h
vendored
54
glfw/glfw3.h
vendored
|
|
@ -1076,7 +1076,7 @@ extern "C" {
|
|||
#define GLFW_STICKY_KEYS 0x00033002
|
||||
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
|
||||
#define GLFW_LOCK_KEY_MODS 0x00033004
|
||||
#define GLFW_RAW_INPUT 0x00033005
|
||||
#define GLFW_RAW_MOUSE_MOTION 0x00033005
|
||||
|
||||
#define GLFW_CURSOR_NORMAL 0x00034001
|
||||
#define GLFW_CURSOR_HIDDEN 0x00034002
|
||||
|
|
@ -4078,11 +4078,12 @@ GLFWAPI void glfwPostEmptyEvent(void);
|
|||
* This function returns the value of an input option for the specified window.
|
||||
* The mode must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS,
|
||||
* @ref GLFW_STICKY_MOUSE_BUTTONS, @ref GLFW_LOCK_KEY_MODS or
|
||||
* @ref GLFW_RAW_INPUT.
|
||||
* @ref GLFW_RAW_MOUSE_MOTION.
|
||||
*
|
||||
* @param[in] window The window to query.
|
||||
* @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS`,
|
||||
* `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or `GLFW_RAW_INPUT`.
|
||||
* `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or
|
||||
* `GLFW_RAW_MOUSE_MOTION`.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
|
||||
* GLFW_INVALID_ENUM.
|
||||
|
|
@ -4102,7 +4103,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
|||
* This function sets an input mode option for the specified window. The mode
|
||||
* must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS,
|
||||
* @ref GLFW_STICKY_MOUSE_BUTTONS, @ref GLFW_LOCK_KEY_MODS or
|
||||
* @ref GLFW_RAW_INPUT.
|
||||
* @ref GLFW_RAW_MOUSE_MOTION.
|
||||
*
|
||||
* If the mode is `GLFW_CURSOR`, the value must be one of the following cursor
|
||||
* modes:
|
||||
|
|
@ -4134,14 +4135,16 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
|||
* GLFW_MOD_CAPS_LOCK bit set when the event was generated with Caps Lock on,
|
||||
* and the @ref GLFW_MOD_NUM_LOCK bit when Num Lock was on.
|
||||
*
|
||||
* If the mode is `GLFW_RAW_INPUT`, the value must be either `true` to
|
||||
* enable the use of raw input, or `false` to disable it. If enabled and
|
||||
* supported by the machine, the program will retrieve high-definition mouse
|
||||
* movement when cursor is grabbed.
|
||||
* If the mode is `GLFW_RAW_MOUSE_MOTION`, the value must be either `GLFW_TRUE`
|
||||
* to enable raw (unscaled and unaccelerated) mouse motion when the cursor is
|
||||
* disabled, or `false` to disable it. If raw motion is not supported,
|
||||
* attempting to set this will emit @ref GLFW_PLATFORM_ERROR. Call @ref
|
||||
* glfwRawMouseMotionSupported to check for support.
|
||||
*
|
||||
* @param[in] window The window whose input mode to set.
|
||||
* @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS`,
|
||||
* `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or `GLFW_RAW_INPUT`.
|
||||
* `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or
|
||||
* `GLFW_RAW_MOUSE_MOTION`.
|
||||
* @param[in] value The new value of the specified input mode.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
|
||||
|
|
@ -4157,37 +4160,34 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode);
|
|||
*/
|
||||
GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value);
|
||||
|
||||
/*! @brief Returns whether the raw input is supported.
|
||||
/*! @brief Returns whether raw mouse motion is supported.
|
||||
*
|
||||
* This function returns whether the raw input is supported by the current
|
||||
* machine.
|
||||
* This function returns whether raw mouse motion is supported on the current
|
||||
* system. This status does not change after GLFW has been initialized so you
|
||||
* only need to check this once. If you attempt to enable raw motion on
|
||||
* a system that does not support it, @ref GLFW_PLATFORM_ERROR will be emitted.
|
||||
*
|
||||
* Raw input allow to retrieve high-definition movement from mouse.
|
||||
* Input from a high-definition mouse is much more precise than that from a
|
||||
* standard mouse. But often, they cannot be obtained through standard
|
||||
* platforms API which transform mouse movement using their own improvements
|
||||
* (like pointer acceleration). Platform's improvements are ideal for pointer
|
||||
* control but it is not so good for moving a first-person camera. For this
|
||||
* reason when the cursor of a window is grabbed by setting @ref GLFW_CURSOR
|
||||
* to @ref GLFW_CURSOR_DISABLED, raw input is used.
|
||||
* Raw mouse motion is closer to the actual motion of the mouse across
|
||||
* a surface. It is not affected by the scaling and acceleration applied to
|
||||
* the motion of the desktop cursor. That processing is suitable for a cursor
|
||||
* while raw motion is better for controlling for example a 3D camera. Because
|
||||
* of this, raw mouse motion is only provided when the cursor is disabled.
|
||||
*
|
||||
* The use of raw input can be disabled using @ref glfwSetInputMode with
|
||||
* @ref GLFW_RAW_INPUT mode.
|
||||
*
|
||||
* @return `true` if high-definition mouse movement is supported, or
|
||||
* `false` otherwise.
|
||||
* @return `true` if raw mouse motion is supported on the current machine,
|
||||
* or `false` otherwise.
|
||||
*
|
||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread.
|
||||
* @thread_safety This function must only be called from the main thread.
|
||||
*
|
||||
* @sa @ref raw_mouse_motion
|
||||
* @sa @ref glfwSetInputMode
|
||||
*
|
||||
* @since Added in version 3.3.
|
||||
*
|
||||
* @ingroup input
|
||||
*/
|
||||
GLFWAPI int glfwRawInputSupported(void);
|
||||
GLFWAPI int glfwRawMouseMotionSupported(void);
|
||||
|
||||
/*! @brief Returns the layout-specific name of the specified printable key.
|
||||
*
|
||||
|
|
|
|||
28
glfw/input.c
vendored
28
glfw/input.c
vendored
|
|
@ -675,8 +675,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);
|
||||
|
|
@ -756,16 +756,30 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
|
|||
{
|
||||
window->lockKeyMods = value ? true : false;
|
||||
}
|
||||
else if (mode == GLFW_RAW_INPUT)
|
||||
_glfwPlatformSetRawInput(window, value ? true : 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 ? true : 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(false);
|
||||
return _glfwPlatformRawMouseMotionSupported();
|
||||
}
|
||||
|
||||
GLFWAPI const char* glfwGetKeyName(int key, int native_key)
|
||||
|
|
|
|||
6
glfw/internal.h
vendored
6
glfw/internal.h
vendored
|
|
@ -429,7 +429,7 @@ struct _GLFWwindow
|
|||
char keys[GLFW_KEY_LAST + 1];
|
||||
// Virtual cursor position when cursor is disabled
|
||||
double virtualCursorPosX, virtualCursorPosY;
|
||||
bool useRawInput;
|
||||
bool rawMouseMotion;
|
||||
|
||||
_GLFWcontext context;
|
||||
|
||||
|
|
@ -632,8 +632,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, bool enabled);
|
||||
bool _glfwPlatformRawInputSupported(void);
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, bool enabled);
|
||||
bool _glfwPlatformRawMouseMotionSupported(void);
|
||||
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
||||
const GLFWimage* image, int xhot, int yhot, int count);
|
||||
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, GLFWCursorShape shape);
|
||||
|
|
|
|||
5
glfw/null_window.c
vendored
5
glfw/null_window.c
vendored
|
|
@ -208,12 +208,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window UNUSED, float opacity UNU
|
|||
{
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, bool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window UNUSED, bool enabled UNUSED)
|
||||
{
|
||||
window->useRawInput = enabled;
|
||||
}
|
||||
|
||||
bool _glfwPlatformRawInputSupported(void)
|
||||
bool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
1
glfw/window.c
vendored
1
glfw/window.c
vendored
|
|
@ -247,7 +247,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
|||
window->floating = wndconfig.floating;
|
||||
window->focusOnShow = wndconfig.focusOnShow;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
window->useRawInput = true;
|
||||
|
||||
window->minwidth = GLFW_DONT_CARE;
|
||||
window->minheight = GLFW_DONT_CARE;
|
||||
|
|
|
|||
5
glfw/wl_window.c
vendored
5
glfw/wl_window.c
vendored
|
|
@ -1237,12 +1237,11 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window UNUSED, float opacity UNU
|
|||
{
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, bool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window UNUSED, bool enabled UNUSED)
|
||||
{
|
||||
window->useRawInput = enabled;
|
||||
}
|
||||
|
||||
bool _glfwPlatformRawInputSupported(void)
|
||||
bool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
83
glfw/x11_window.c
vendored
83
glfw/x11_window.c
vendored
|
|
@ -455,22 +455,41 @@ static void updateCursorImage(_GLFWwindow* window)
|
|||
}
|
||||
}
|
||||
|
||||
// Enable XI2 raw mouse motion events
|
||||
//
|
||||
static void enableRawMouseMotion(_GLFWwindow* window UNUSED)
|
||||
{
|
||||
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 UNUSED)
|
||||
{
|
||||
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,
|
||||
|
|
@ -490,17 +509,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);
|
||||
|
|
@ -1122,7 +1132,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)
|
||||
|
|
@ -1364,7 +1374,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;
|
||||
|
|
@ -2630,20 +2640,21 @@ _glfwDispatchX11Events(void) {
|
|||
return dispatched;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetRawInput(_GLFWwindow *window, bool enabled)
|
||||
void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, bool 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);
|
||||
}
|
||||
|
||||
bool _glfwPlatformRawInputSupported(void)
|
||||
bool _glfwPlatformRawMouseMotionSupported(void)
|
||||
{
|
||||
return _glfw.x11.xi.available;
|
||||
}
|
||||
|
|
|
|||
2
kitty/glfw-wrapper.h
generated
2
kitty/glfw-wrapper.h
generated
|
|
@ -839,7 +839,7 @@
|
|||
#define GLFW_STICKY_KEYS 0x00033002
|
||||
#define GLFW_STICKY_MOUSE_BUTTONS 0x00033003
|
||||
#define GLFW_LOCK_KEY_MODS 0x00033004
|
||||
#define GLFW_RAW_INPUT 0x00033005
|
||||
#define GLFW_RAW_MOUSE_MOTION 0x00033005
|
||||
|
||||
#define GLFW_CURSOR_NORMAL 0x00034001
|
||||
#define GLFW_CURSOR_HIDDEN 0x00034002
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue