mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-11 01:31:31 +00:00
[client] input: add display server behaviour tests
Extract input policy from the Wayland and X11 protocol handlers. Exercise both implementations against literal Wayland event traces.
This commit is contained in:
@@ -19,6 +19,7 @@ add_library(displayserver_Wayland STATIC
|
||||
icon.c
|
||||
idle.c
|
||||
input.c
|
||||
input_event.c
|
||||
output.c
|
||||
poll.c
|
||||
presentation.c
|
||||
|
||||
@@ -240,7 +240,7 @@ void waylandSetPointer(LG_DSPointer pointer)
|
||||
wlWm.cursorHotY = wlWm.cursorHot[pointer].y;
|
||||
MTRACE("set id=%d surface=%p hot=%d,%d scale=%d entered=%d",
|
||||
pointer, (void *)wlWm.cursor, wlWm.cursorHotX, wlWm.cursorHotY,
|
||||
wlWm.cursorScale, wlWm.pointerInSurface);
|
||||
wlWm.cursorScale, wlWm.input.pointerInSurface);
|
||||
if (wlWm.pointer)
|
||||
wl_pointer_set_cursor(wlWm.pointer, wlWm.pointerEnterSerial, wlWm.cursor, wlWm.cursorHotX, wlWm.cursorHotY);
|
||||
}
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#include "app.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
const double WL_SCROLL_STEP = 15.0;
|
||||
const double WL_HALF_SCROLL_STEP = WL_SCROLL_STEP / 2.0;
|
||||
|
||||
#define MTRACE(fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
@@ -59,6 +56,93 @@ static uint32_t proxyId(void * proxy)
|
||||
return proxy ? wl_proxy_get_id(proxy) : 0;
|
||||
}
|
||||
|
||||
static void inputPosition(void * opaque, double x, double y)
|
||||
{
|
||||
(void)opaque;
|
||||
app_updateCursorPos(x, y);
|
||||
}
|
||||
|
||||
static void inputRelative(void * opaque, double x, double y,
|
||||
double rawX, double rawY)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleMouseRelative(x, y, rawX, rawY);
|
||||
}
|
||||
|
||||
static void inputButton(void * opaque, unsigned int button, bool pressed)
|
||||
{
|
||||
(void)opaque;
|
||||
if (pressed)
|
||||
app_handleButtonPress(button);
|
||||
else
|
||||
app_handleButtonRelease(button);
|
||||
}
|
||||
|
||||
static void inputWheel(void * opaque, double motion)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleWheelMotion(motion);
|
||||
}
|
||||
|
||||
static void inputKey(void * opaque, int scancode, bool pressed)
|
||||
{
|
||||
(void)opaque;
|
||||
if (pressed)
|
||||
app_handleKeyPress(scancode);
|
||||
else
|
||||
app_handleKeyRelease(scancode);
|
||||
}
|
||||
|
||||
static void inputText(void * opaque, const char * text)
|
||||
{
|
||||
(void)opaque;
|
||||
/* Test overlay state after the key callback, matching the native event
|
||||
* handler's ordering. */
|
||||
if (app_isOverlayMode())
|
||||
app_handleKeyboardTyped(text);
|
||||
}
|
||||
|
||||
static void inputModifiers(void * opaque, bool ctrl, bool shift, bool alt,
|
||||
bool super)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleKeyboardModifiers(ctrl, shift, alt, super);
|
||||
}
|
||||
|
||||
static void inputLEDs(void * opaque, bool numLock, bool capsLock,
|
||||
bool scrollLock)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleKeyboardLEDs(numLock, capsLock, scrollLock);
|
||||
}
|
||||
|
||||
static void inputEnter(void * opaque, bool entered)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleEnterEvent(entered);
|
||||
}
|
||||
|
||||
static void inputFocus(void * opaque, bool focused)
|
||||
{
|
||||
(void)opaque;
|
||||
if (!focused)
|
||||
waylandCBInvalidate();
|
||||
app_handleFocusEvent(focused);
|
||||
}
|
||||
|
||||
static const LG_DSInputSink inputSink = {
|
||||
.position = inputPosition,
|
||||
.relative = inputRelative,
|
||||
.button = inputButton,
|
||||
.wheel = inputWheel,
|
||||
.key = inputKey,
|
||||
.text = inputText,
|
||||
.modifiers = inputModifiers,
|
||||
.leds = inputLEDs,
|
||||
.enter = inputEnter,
|
||||
.focus = inputFocus,
|
||||
};
|
||||
|
||||
// Mouse-handling listeners.
|
||||
|
||||
static void pointerMotionHandler(void * data, struct wl_pointer * pointer,
|
||||
@@ -68,7 +152,7 @@ static void pointerMotionHandler(void * data, struct wl_pointer * pointer,
|
||||
wl_fixed_to_double(syW));
|
||||
MTRACE("abs time=%u pos=%.3f,%.3f", time, wlWm.motion.x,
|
||||
wlWm.motion.y);
|
||||
app_updateCursorPos(wlWm.motion.x, wlWm.motion.y);
|
||||
wlInputPointerMotion(&wlWm.input, wlWm.motion.x, wlWm.motion.y);
|
||||
}
|
||||
|
||||
static void pointerEnterHandler(void * data, struct wl_pointer * pointer,
|
||||
@@ -79,18 +163,15 @@ static void pointerEnterHandler(void * data, struct wl_pointer * pointer,
|
||||
surface == wlWm.surface, (void *)surface, serial,
|
||||
wl_fixed_to_double(sxW), wl_fixed_to_double(syW));
|
||||
|
||||
if (surface != wlWm.surface)
|
||||
if (!wlInputPointerEnter(&wlWm.input, surface == wlWm.surface))
|
||||
return;
|
||||
|
||||
wlWm.pointerInSurface = true;
|
||||
app_handleEnterEvent(true);
|
||||
|
||||
wl_pointer_set_cursor(pointer, serial, wlWm.cursor, wlWm.cursorHotX, wlWm.cursorHotY);
|
||||
wlWm.pointerEnterSerial = serial;
|
||||
|
||||
wlMotionAbs(&wlWm.motion, wl_fixed_to_double(sxW),
|
||||
wl_fixed_to_double(syW));
|
||||
app_updateCursorPos(wlWm.motion.x, wlWm.motion.y);
|
||||
wlInputPointerMotion(&wlWm.input, wlWm.motion.x, wlWm.motion.y);
|
||||
}
|
||||
|
||||
static void pointerLeaveHandler(void * data, struct wl_pointer * pointer,
|
||||
@@ -99,76 +180,21 @@ static void pointerLeaveHandler(void * data, struct wl_pointer * pointer,
|
||||
MTRACE("leave main=%d surface=%p serial=%u",
|
||||
surface == wlWm.surface, (void *)surface, serial);
|
||||
|
||||
if (surface != wlWm.surface)
|
||||
return;
|
||||
|
||||
wlWm.pointerInSurface = false;
|
||||
app_handleEnterEvent(false);
|
||||
wlInputPointerLeave(&wlWm.input, surface == wlWm.surface);
|
||||
}
|
||||
|
||||
static void pointerAxisHandler(void * data, struct wl_pointer * pointer,
|
||||
uint32_t serial, uint32_t axis, wl_fixed_t value)
|
||||
{
|
||||
if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)
|
||||
return;
|
||||
|
||||
double delta = wl_fixed_to_double(value);
|
||||
|
||||
wlWm.scrollState += delta;
|
||||
|
||||
while (wlWm.scrollState > WL_HALF_SCROLL_STEP)
|
||||
{
|
||||
app_handleButtonPress(5 /* SPICE_MOUSE_BUTTON_DOWN */);
|
||||
app_handleButtonRelease(5 /* SPICE_MOUSE_BUTTON_DOWN */);
|
||||
wlWm.scrollState -= WL_SCROLL_STEP;
|
||||
}
|
||||
|
||||
while (wlWm.scrollState < -WL_HALF_SCROLL_STEP)
|
||||
{
|
||||
app_handleButtonPress(4 /* SPICE_MOUSE_BUTTON_UP */);
|
||||
app_handleButtonRelease(4 /* SPICE_MOUSE_BUTTON_UP */);
|
||||
wlWm.scrollState += WL_SCROLL_STEP;
|
||||
}
|
||||
|
||||
app_handleWheelMotion(delta / WL_SCROLL_STEP);
|
||||
}
|
||||
|
||||
static int mapWaylandButton(uint32_t button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case BTN_LEFT:
|
||||
return 1;
|
||||
case BTN_MIDDLE:
|
||||
return 2;
|
||||
case BTN_RIGHT:
|
||||
return 3;
|
||||
case BTN_SIDE:
|
||||
return 6;
|
||||
case BTN_EXTRA:
|
||||
return 7;
|
||||
case BTN_FORWARD:
|
||||
return 8;
|
||||
case BTN_BACK:
|
||||
return 9;
|
||||
case BTN_TASK:
|
||||
return 10;
|
||||
}
|
||||
|
||||
return 0;
|
||||
wlInputPointerAxis(&wlWm.input,
|
||||
axis == WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_to_double(value));
|
||||
}
|
||||
|
||||
static void pointerButtonHandler(void *data, struct wl_pointer *pointer,
|
||||
uint32_t serial, uint32_t time, uint32_t button, uint32_t stateW)
|
||||
{
|
||||
button = mapWaylandButton(button);
|
||||
if (!button)
|
||||
return;
|
||||
|
||||
if (stateW == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
app_handleButtonPress(button);
|
||||
else
|
||||
app_handleButtonRelease(button);
|
||||
wlInputPointerButton(&wlWm.input, button,
|
||||
stateW == WL_POINTER_BUTTON_STATE_PRESSED);
|
||||
}
|
||||
|
||||
static const struct wl_pointer_listener pointerListener = {
|
||||
@@ -223,21 +249,18 @@ static void relativePointerMotionHandler(void * data,
|
||||
wl_fixed_t dxW, wl_fixed_t dyW, wl_fixed_t dxUnaccelW,
|
||||
wl_fixed_t dyUnaccelW)
|
||||
{
|
||||
if (!atomic_load_explicit(&wlWm.lockActive, memory_order_acquire))
|
||||
return;
|
||||
|
||||
const bool active =
|
||||
atomic_load_explicit(&wlWm.lockActive, memory_order_acquire);
|
||||
const double dx = wl_fixed_to_double(dxW);
|
||||
const double dy = wl_fixed_to_double(dyW);
|
||||
MTRACE("rel time=%u:%u delta=%.3f,%.3f raw=%.3f,%.3f "
|
||||
"pos=%.3f,%.3f", timeHi, timeLo, dx, dy,
|
||||
wl_fixed_to_double(dxUnaccelW), wl_fixed_to_double(dyUnaccelW),
|
||||
wlWm.motion.x, wlWm.motion.y);
|
||||
const double rawX = wl_fixed_to_double(dxUnaccelW);
|
||||
const double rawY = wl_fixed_to_double(dyUnaccelW);
|
||||
if (active)
|
||||
MTRACE("rel time=%u:%u delta=%.3f,%.3f raw=%.3f,%.3f "
|
||||
"pos=%.3f,%.3f", timeHi, timeLo, dx, dy, rawX, rawY,
|
||||
wlWm.motion.x, wlWm.motion.y);
|
||||
|
||||
app_handleMouseRelative(
|
||||
dx,
|
||||
dy,
|
||||
wl_fixed_to_double(dxUnaccelW),
|
||||
wl_fixed_to_double(dyUnaccelW));
|
||||
wlInputRelativeMotion(&wlWm.input, active, dx, dy, rawX, rawY);
|
||||
}
|
||||
|
||||
static const struct zwp_relative_pointer_v1_listener relativePointerListener = {
|
||||
@@ -314,51 +337,46 @@ static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard,
|
||||
uint32_t serial, struct wl_surface * surface, struct wl_array * keys)
|
||||
{
|
||||
if (surface != wlWm.surface)
|
||||
{
|
||||
wlInputKeyboardEnter(&wlWm.input, false, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wlWm.focusedOnSurface = true;
|
||||
app_handleFocusEvent(true);
|
||||
wlWm.keyboardEnterSerial = serial;
|
||||
|
||||
uint32_t * key;
|
||||
wl_array_for_each(key, keys)
|
||||
app_handleKeyPress(*key);
|
||||
wlInputKeyboardEnter(&wlWm.input, true, keys->data,
|
||||
keys->size / sizeof(uint32_t));
|
||||
}
|
||||
|
||||
static void keyboardLeaveHandler(void * data, struct wl_keyboard * keyboard,
|
||||
uint32_t serial, struct wl_surface * surface)
|
||||
{
|
||||
if (surface != wlWm.surface)
|
||||
return;
|
||||
|
||||
wlWm.focusedOnSurface = false;
|
||||
waylandCBInvalidate();
|
||||
app_handleFocusEvent(false);
|
||||
wlInputKeyboardLeave(&wlWm.input, surface == wlWm.surface);
|
||||
}
|
||||
|
||||
static void keyboardKeyHandler(void * data, struct wl_keyboard * keyboard,
|
||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
||||
{
|
||||
if (!wlWm.focusedOnSurface)
|
||||
if (!wlWm.input.focused)
|
||||
return;
|
||||
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||
app_handleKeyPress(key);
|
||||
else
|
||||
app_handleKeyRelease(key);
|
||||
|
||||
if (!wlWm.xkbState || !app_isOverlayMode() || state != WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||
const bool pressed = state == WL_KEYBOARD_KEY_STATE_PRESSED;
|
||||
if (!wlWm.xkbState || !pressed)
|
||||
{
|
||||
wlInputKeyboardKey(&wlWm.input, key, pressed, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
key += 8; // xkb scancode is evdev scancode + 8
|
||||
int size = xkb_state_key_get_utf8(wlWm.xkbState, key, NULL, 0);
|
||||
|
||||
const xkb_keycode_t xkbKey = key + 8;
|
||||
const int size = xkb_state_key_get_utf8(wlWm.xkbState, xkbKey, NULL, 0);
|
||||
if (size <= 0)
|
||||
{
|
||||
wlInputKeyboardKey(&wlWm.input, key, true, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[size + 1];
|
||||
xkb_state_key_get_utf8(wlWm.xkbState, key, buffer, size + 1);
|
||||
app_handleKeyboardTyped(buffer);
|
||||
xkb_state_key_get_utf8(wlWm.xkbState, xkbKey, buffer, size + 1);
|
||||
wlInputKeyboardKey(&wlWm.input, key, true, buffer);
|
||||
}
|
||||
|
||||
static void keyboardModifiersHandler(void * data,
|
||||
@@ -369,18 +387,24 @@ static void keyboardModifiersHandler(void * data,
|
||||
return;
|
||||
|
||||
xkb_state_update_mask(wlWm.xkbState, modsDepressed, modsLatched, modsLocked, 0, 0, group);
|
||||
app_handleKeyboardModifiers(
|
||||
xkb_state_mod_name_is_active(wlWm.xkbState, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0,
|
||||
xkb_state_mod_name_is_active(wlWm.xkbState, XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_EFFECTIVE) > 0,
|
||||
xkb_state_mod_name_is_active(wlWm.xkbState, XKB_MOD_NAME_ALT, XKB_STATE_MODS_EFFECTIVE) > 0,
|
||||
xkb_state_mod_name_is_active(wlWm.xkbState, XKB_MOD_NAME_LOGO, XKB_STATE_MODS_EFFECTIVE) > 0
|
||||
);
|
||||
const bool ctrl = xkb_state_mod_name_is_active(wlWm.xkbState,
|
||||
XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0;
|
||||
const bool shift = xkb_state_mod_name_is_active(wlWm.xkbState,
|
||||
XKB_MOD_NAME_SHIFT, XKB_STATE_MODS_EFFECTIVE) > 0;
|
||||
const bool alt = xkb_state_mod_name_is_active(wlWm.xkbState,
|
||||
XKB_MOD_NAME_ALT, XKB_STATE_MODS_EFFECTIVE) > 0;
|
||||
const bool super = xkb_state_mod_name_is_active(wlWm.xkbState,
|
||||
XKB_MOD_NAME_LOGO, XKB_STATE_MODS_EFFECTIVE) > 0;
|
||||
|
||||
app_handleKeyboardLEDs(
|
||||
xkb_state_led_name_is_active(wlWm.xkbState, XKB_LED_NAME_NUM) > 0,
|
||||
xkb_state_led_name_is_active(wlWm.xkbState, XKB_LED_NAME_CAPS) > 0,
|
||||
xkb_state_led_name_is_active(wlWm.xkbState, XKB_LED_NAME_SCROLL) > 0
|
||||
);
|
||||
const bool numLock = xkb_state_led_name_is_active(wlWm.xkbState,
|
||||
XKB_LED_NAME_NUM) > 0;
|
||||
const bool capsLock = xkb_state_led_name_is_active(wlWm.xkbState,
|
||||
XKB_LED_NAME_CAPS) > 0;
|
||||
const bool scrollLock = xkb_state_led_name_is_active(wlWm.xkbState,
|
||||
XKB_LED_NAME_SCROLL) > 0;
|
||||
|
||||
wlInputKeyboardState(&wlWm.input, ctrl, shift, alt, super,
|
||||
numLock, capsLock, scrollLock);
|
||||
}
|
||||
|
||||
static const struct wl_keyboard_listener keyboardListener = {
|
||||
@@ -468,13 +492,10 @@ static void waylandCleanUpPointer(bool notify)
|
||||
|
||||
wl_pointer_destroy(wlWm.pointer);
|
||||
wlWm.pointer = NULL;
|
||||
wlWm.pointerInSurface = false;
|
||||
});
|
||||
|
||||
MLOG(lockSeq, "lock destroy id=%u why=pointer", lockId);
|
||||
|
||||
if (notify)
|
||||
app_handleEnterEvent(false);
|
||||
wlInputPointerDisconnect(&wlWm.input, notify);
|
||||
}
|
||||
|
||||
// Seat-handling listeners.
|
||||
@@ -531,6 +552,8 @@ static const struct wl_seat_listener seatListener = {
|
||||
|
||||
bool waylandInputInit(bool allowNoInput)
|
||||
{
|
||||
wlInputInit(&wlWm.input, &inputSink, NULL);
|
||||
|
||||
if (!wlWm.seat)
|
||||
{
|
||||
MTRACE("input seat=0 allowNone=%d", allowNoInput);
|
||||
@@ -672,7 +695,7 @@ void waylandWarpPointer(int x, int y, bool exiting)
|
||||
{
|
||||
const int reqX = x;
|
||||
const int reqY = y;
|
||||
if (!wlWm.pointerInSurface)
|
||||
if (!wlWm.input.pointerInSurface)
|
||||
{
|
||||
MTRACE("warp drop=surface target=%d,%d exit=%d", x, y, exiting);
|
||||
return;
|
||||
@@ -737,8 +760,7 @@ void waylandWarpPointer(int x, int y, bool exiting)
|
||||
|
||||
void waylandRealignPointer(void)
|
||||
{
|
||||
if (wlWm.pointerInSurface)
|
||||
app_updateCursorPos(wlWm.motion.x, wlWm.motion.y);
|
||||
wlInputRealignPointer(&wlWm.input, wlWm.motion.x, wlWm.motion.y);
|
||||
}
|
||||
|
||||
void waylandGuestPointerUpdated(double x, double y, double localX,
|
||||
|
||||
179
client/displayservers/Wayland/input_event.c
Normal file
179
client/displayservers/Wayland/input_event.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "input_event.h"
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <string.h>
|
||||
|
||||
static const double WL_SCROLL_STEP = 15.0;
|
||||
static const double WL_HALF_SCROLL_STEP = 7.5;
|
||||
|
||||
void wlInputInit(WaylandInput * input, const LG_DSInputSink * sink,
|
||||
void * opaque)
|
||||
{
|
||||
memset(input, 0, sizeof(*input));
|
||||
input->sink = sink;
|
||||
input->opaque = opaque;
|
||||
}
|
||||
|
||||
bool wlInputPointerEnter(WaylandInput * input, bool mainSurface)
|
||||
{
|
||||
if (!mainSurface)
|
||||
return false;
|
||||
|
||||
input->pointerInSurface = true;
|
||||
input->sink->enter(input->opaque, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wlInputPointerLeave(WaylandInput * input, bool mainSurface)
|
||||
{
|
||||
if (!mainSurface)
|
||||
return false;
|
||||
|
||||
input->pointerInSurface = false;
|
||||
input->sink->enter(input->opaque, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void wlInputPointerDisconnect(WaylandInput * input, bool notify)
|
||||
{
|
||||
input->pointerInSurface = false;
|
||||
if (notify)
|
||||
input->sink->enter(input->opaque, false);
|
||||
}
|
||||
|
||||
void wlInputPointerMotion(WaylandInput * input, double x, double y)
|
||||
{
|
||||
input->sink->position(input->opaque, x, y);
|
||||
}
|
||||
|
||||
static unsigned int mapButton(uint32_t button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case BTN_LEFT:
|
||||
return 1;
|
||||
case BTN_MIDDLE:
|
||||
return 2;
|
||||
case BTN_RIGHT:
|
||||
return 3;
|
||||
case BTN_SIDE:
|
||||
return 6;
|
||||
case BTN_EXTRA:
|
||||
return 7;
|
||||
case BTN_FORWARD:
|
||||
return 8;
|
||||
case BTN_BACK:
|
||||
return 9;
|
||||
case BTN_TASK:
|
||||
return 10;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wlInputPointerButton(WaylandInput * input, uint32_t button,
|
||||
bool pressed)
|
||||
{
|
||||
const unsigned int mapped = mapButton(button);
|
||||
if (mapped)
|
||||
input->sink->button(input->opaque, mapped, pressed);
|
||||
}
|
||||
|
||||
void wlInputPointerAxis(WaylandInput * input, bool vertical, double delta)
|
||||
{
|
||||
if (!vertical)
|
||||
return;
|
||||
|
||||
input->scrollState += delta;
|
||||
|
||||
while (input->scrollState > WL_HALF_SCROLL_STEP)
|
||||
{
|
||||
input->sink->button(input->opaque, 5, true);
|
||||
input->sink->button(input->opaque, 5, false);
|
||||
input->scrollState -= WL_SCROLL_STEP;
|
||||
}
|
||||
|
||||
while (input->scrollState < -WL_HALF_SCROLL_STEP)
|
||||
{
|
||||
input->sink->button(input->opaque, 4, true);
|
||||
input->sink->button(input->opaque, 4, false);
|
||||
input->scrollState += WL_SCROLL_STEP;
|
||||
}
|
||||
|
||||
input->sink->wheel(input->opaque, delta / WL_SCROLL_STEP);
|
||||
}
|
||||
|
||||
void wlInputRelativeMotion(WaylandInput * input, bool active,
|
||||
double x, double y, double rawX, double rawY)
|
||||
{
|
||||
if (active)
|
||||
input->sink->relative(input->opaque, x, y, rawX, rawY);
|
||||
}
|
||||
|
||||
void wlInputRealignPointer(WaylandInput * input, double x, double y)
|
||||
{
|
||||
if (input->pointerInSurface)
|
||||
input->sink->position(input->opaque, x, y);
|
||||
}
|
||||
|
||||
bool wlInputKeyboardEnter(WaylandInput * input, bool mainSurface,
|
||||
const uint32_t * keys, size_t count)
|
||||
{
|
||||
if (!mainSurface)
|
||||
return false;
|
||||
|
||||
input->focused = true;
|
||||
input->sink->focus(input->opaque, true);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
input->sink->key(input->opaque, keys[i], true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wlInputKeyboardLeave(WaylandInput * input, bool mainSurface)
|
||||
{
|
||||
if (!mainSurface)
|
||||
return false;
|
||||
|
||||
input->focused = false;
|
||||
input->sink->focus(input->opaque, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void wlInputKeyboardKey(WaylandInput * input, uint32_t key, bool pressed,
|
||||
const char * text)
|
||||
{
|
||||
if (!input->focused)
|
||||
return;
|
||||
|
||||
input->sink->key(input->opaque, key, pressed);
|
||||
if (pressed && text && *text)
|
||||
input->sink->text(input->opaque, text);
|
||||
}
|
||||
|
||||
void wlInputKeyboardState(WaylandInput * input,
|
||||
bool ctrl, bool shift, bool alt, bool super,
|
||||
bool numLock, bool capsLock, bool scrollLock)
|
||||
{
|
||||
input->sink->modifiers(input->opaque, ctrl, shift, alt, super);
|
||||
input->sink->leds(input->opaque, numLock, capsLock, scrollLock);
|
||||
}
|
||||
63
client/displayservers/Wayland/input_event.h
Normal file
63
client/displayservers/Wayland/input_event.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _H_LG_WAYLAND_INPUT_EVENT_
|
||||
#define _H_LG_WAYLAND_INPUT_EVENT_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../input.h"
|
||||
|
||||
typedef struct WaylandInput
|
||||
{
|
||||
const LG_DSInputSink * sink;
|
||||
void * opaque;
|
||||
double scrollState;
|
||||
bool pointerInSurface;
|
||||
bool focused;
|
||||
}
|
||||
WaylandInput;
|
||||
|
||||
void wlInputInit(WaylandInput * input, const LG_DSInputSink * sink,
|
||||
void * opaque);
|
||||
|
||||
bool wlInputPointerEnter(WaylandInput * input, bool mainSurface);
|
||||
bool wlInputPointerLeave(WaylandInput * input, bool mainSurface);
|
||||
void wlInputPointerDisconnect(WaylandInput * input, bool notify);
|
||||
void wlInputPointerMotion(WaylandInput * input, double x, double y);
|
||||
void wlInputPointerButton(WaylandInput * input, uint32_t button,
|
||||
bool pressed);
|
||||
void wlInputPointerAxis(WaylandInput * input, bool vertical, double delta);
|
||||
void wlInputRelativeMotion(WaylandInput * input, bool active,
|
||||
double x, double y, double rawX, double rawY);
|
||||
void wlInputRealignPointer(WaylandInput * input, double x, double y);
|
||||
|
||||
bool wlInputKeyboardEnter(WaylandInput * input, bool mainSurface,
|
||||
const uint32_t * keys, size_t count);
|
||||
bool wlInputKeyboardLeave(WaylandInput * input, bool mainSurface);
|
||||
void wlInputKeyboardKey(WaylandInput * input, uint32_t key, bool pressed,
|
||||
const char * text);
|
||||
void wlInputKeyboardState(WaylandInput * input,
|
||||
bool ctrl, bool shift, bool alt, bool super,
|
||||
bool numLock, bool capsLock, bool scrollLock);
|
||||
|
||||
#endif
|
||||
@@ -57,6 +57,7 @@
|
||||
|
||||
#include "scale.h"
|
||||
#include "motion.h"
|
||||
#include "input_event.h"
|
||||
|
||||
typedef void (*WaylandPollCallback)(uint32_t events, void * opaque);
|
||||
typedef void (*WaylandPollCleanup)(void * opaque);
|
||||
@@ -128,8 +129,7 @@ struct WaylandDSState
|
||||
{
|
||||
_Atomic(bool) lockActive;
|
||||
bool keyboardGrabbed;
|
||||
bool pointerInSurface;
|
||||
bool focusedOnSurface;
|
||||
WaylandInput input;
|
||||
|
||||
WL_DesktopOps * desktop;
|
||||
|
||||
@@ -147,7 +147,6 @@ struct WaylandDSState
|
||||
bool configured;
|
||||
bool warpSupport;
|
||||
struct WlMotion motion;
|
||||
double scrollState;
|
||||
|
||||
#if defined(ENABLE_EGL) || defined(ENABLE_OPENGL)
|
||||
struct wl_egl_window * eglWindow;
|
||||
|
||||
@@ -16,6 +16,7 @@ pkg_check_modules(DISPLAYSERVER_X11 REQUIRED IMPORTED_TARGET
|
||||
|
||||
add_library(displayserver_X11 STATIC
|
||||
x11.c
|
||||
input_event.c
|
||||
atoms.c
|
||||
clipboard.c
|
||||
cursor.c
|
||||
|
||||
183
client/displayservers/X11/input_event.c
Normal file
183
client/displayservers/X11/input_event.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "input_event.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static unsigned int mapButton(unsigned int button)
|
||||
{
|
||||
if (button >= 1 && button <= 5)
|
||||
return button;
|
||||
|
||||
/* X11 reserves buttons 6 and 7 for horizontal scrolling. */
|
||||
if (button >= 8 && button < 34)
|
||||
return button - 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void x11InputInit(X11Input * input, const LG_DSInputSink * sink,
|
||||
void * opaque)
|
||||
{
|
||||
memset(input, 0, sizeof(*input));
|
||||
input->sink = sink;
|
||||
input->opaque = opaque;
|
||||
}
|
||||
|
||||
bool x11InputFocus(X11Input * input, bool focused, double x, double y,
|
||||
const uint32_t * keys, size_t count)
|
||||
{
|
||||
(void)keys;
|
||||
(void)count;
|
||||
|
||||
if (input->focused == focused)
|
||||
return false;
|
||||
|
||||
input->focused = focused;
|
||||
input->sink->position(input->opaque, x, y);
|
||||
input->sink->focus(input->opaque, focused);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool x11InputPointerEnter(X11Input * input, bool mainWindow,
|
||||
bool normal, double x, double y)
|
||||
{
|
||||
if (input->entered || !mainWindow || !normal)
|
||||
return false;
|
||||
|
||||
input->sink->position(input->opaque, x, y);
|
||||
input->sink->enter(input->opaque, true);
|
||||
input->entered = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool x11InputPointerLeave(X11Input * input, bool mainWindow,
|
||||
bool normal, bool captureMode, double x, double y)
|
||||
{
|
||||
if (!input->entered || !mainWindow || input->buttons || captureMode ||
|
||||
!normal)
|
||||
return false;
|
||||
|
||||
input->sink->position(input->opaque, x, y);
|
||||
input->sink->enter(input->opaque, false);
|
||||
input->entered = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void x11InputPointerMotion(X11Input * input, double x, double y,
|
||||
bool pointerGrabbed)
|
||||
{
|
||||
input->sink->position(input->opaque, x, y);
|
||||
|
||||
if (!pointerGrabbed)
|
||||
input->sink->relative(input->opaque, 0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
void x11InputPointerButton(X11Input * input, unsigned int detail,
|
||||
bool pressed, bool raw, uint32_t time, bool inputActive)
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
if (!inputActive)
|
||||
return;
|
||||
}
|
||||
else if (!input->focused || !input->entered)
|
||||
return;
|
||||
|
||||
const unsigned int button = mapButton(detail);
|
||||
if (!button)
|
||||
return;
|
||||
|
||||
if (!raw)
|
||||
{
|
||||
if (pressed && button == 4)
|
||||
input->sink->wheel(input->opaque, -0.5);
|
||||
else if (pressed && button == 5)
|
||||
input->sink->wheel(input->opaque, 0.5);
|
||||
else if (button != 4 && button != 5)
|
||||
input->sink->button(input->opaque, button, pressed);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t * previousTime = pressed ?
|
||||
&input->previousPressTime : &input->previousReleaseTime;
|
||||
uint32_t * previousButton = pressed ?
|
||||
&input->previousPressButton : &input->previousReleaseButton;
|
||||
|
||||
if (time == *previousTime && detail == *previousButton)
|
||||
return;
|
||||
|
||||
*previousTime = time;
|
||||
*previousButton = detail;
|
||||
|
||||
const uint32_t mask = UINT32_C(1) << button;
|
||||
if (pressed)
|
||||
input->buttons |= mask;
|
||||
else
|
||||
input->buttons &= ~mask;
|
||||
|
||||
input->sink->button(input->opaque, button, pressed);
|
||||
}
|
||||
|
||||
void x11InputRelativeMotion(X11Input * input, uint32_t time,
|
||||
double x, double y, double rawX, double rawY, bool inputActive)
|
||||
{
|
||||
if (!inputActive)
|
||||
return;
|
||||
|
||||
if (time == input->previousMotionTime &&
|
||||
x == input->previousMotionX && y == input->previousMotionY)
|
||||
return;
|
||||
|
||||
input->previousMotionTime = time;
|
||||
input->previousMotionX = x;
|
||||
input->previousMotionY = y;
|
||||
|
||||
input->sink->relative(input->opaque, x, y, rawX, rawY);
|
||||
}
|
||||
|
||||
void x11InputKeyboardKey(X11Input * input, unsigned int keycode,
|
||||
int minKeycode, bool pressed, bool raw, bool inputActive,
|
||||
const char * text)
|
||||
{
|
||||
if (raw)
|
||||
{
|
||||
if (!inputActive)
|
||||
return;
|
||||
}
|
||||
else if (!input->focused)
|
||||
return;
|
||||
|
||||
input->sink->key(input->opaque, (int)keycode - minKeycode, pressed);
|
||||
|
||||
if (!raw && pressed && text)
|
||||
input->sink->text(input->opaque, text);
|
||||
}
|
||||
|
||||
void x11InputKeyboardState(X11Input * input,
|
||||
bool ctrl, bool shift, bool alt, bool super,
|
||||
bool numLock, bool capsLock, bool scrollLock)
|
||||
{
|
||||
(void)numLock;
|
||||
(void)capsLock;
|
||||
(void)scrollLock;
|
||||
input->sink->modifiers(input->opaque, ctrl, shift, alt, super);
|
||||
}
|
||||
69
client/displayservers/X11/input_event.h
Normal file
69
client/displayservers/X11/input_event.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _H_LG_X11_INPUT_EVENT_
|
||||
#define _H_LG_X11_INPUT_EVENT_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../input.h"
|
||||
|
||||
typedef struct X11Input
|
||||
{
|
||||
const LG_DSInputSink * sink;
|
||||
void * opaque;
|
||||
uint32_t buttons;
|
||||
uint32_t previousPressTime;
|
||||
uint32_t previousReleaseTime;
|
||||
uint32_t previousPressButton;
|
||||
uint32_t previousReleaseButton;
|
||||
uint32_t previousMotionTime;
|
||||
double previousMotionX;
|
||||
double previousMotionY;
|
||||
bool entered;
|
||||
bool focused;
|
||||
}
|
||||
X11Input;
|
||||
|
||||
void x11InputInit(X11Input * input, const LG_DSInputSink * sink,
|
||||
void * opaque);
|
||||
|
||||
bool x11InputFocus(X11Input * input, bool focused, double x, double y,
|
||||
const uint32_t * keys, size_t count);
|
||||
bool x11InputPointerEnter(X11Input * input, bool mainWindow,
|
||||
bool normal, double x, double y);
|
||||
bool x11InputPointerLeave(X11Input * input, bool mainWindow,
|
||||
bool normal, bool captureMode, double x, double y);
|
||||
void x11InputPointerMotion(X11Input * input, double x, double y,
|
||||
bool pointerGrabbed);
|
||||
void x11InputPointerButton(X11Input * input, unsigned int button,
|
||||
bool pressed, bool raw, uint32_t time, bool inputActive);
|
||||
void x11InputRelativeMotion(X11Input * input, uint32_t time,
|
||||
double x, double y, double rawX, double rawY, bool inputActive);
|
||||
void x11InputKeyboardKey(X11Input * input, unsigned int keycode,
|
||||
int minKeycode, bool pressed, bool raw, bool inputActive,
|
||||
const char * text);
|
||||
void x11InputKeyboardState(X11Input * input,
|
||||
bool ctrl, bool shift, bool alt, bool super,
|
||||
bool numLock, bool capsLock, bool scrollLock);
|
||||
|
||||
#endif
|
||||
@@ -95,6 +95,88 @@ static void x11XPresentEvent(XGenericEventCookie *cookie);
|
||||
static void x11UpdateKeyboardGroup(void);
|
||||
static void x11GrabPointer(void);
|
||||
|
||||
static void inputPosition(void * opaque, double x, double y)
|
||||
{
|
||||
(void)opaque;
|
||||
app_updateCursorPos(x, y);
|
||||
}
|
||||
|
||||
static void inputRelative(void * opaque, double x, double y,
|
||||
double rawX, double rawY)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleMouseRelative(x, y, rawX, rawY);
|
||||
}
|
||||
|
||||
static void inputButton(void * opaque, unsigned int button, bool pressed)
|
||||
{
|
||||
(void)opaque;
|
||||
if (pressed)
|
||||
app_handleButtonPress(button);
|
||||
else
|
||||
app_handleButtonRelease(button);
|
||||
}
|
||||
|
||||
static void inputWheel(void * opaque, double motion)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleWheelMotion(motion);
|
||||
}
|
||||
|
||||
static void inputKey(void * opaque, int scancode, bool pressed)
|
||||
{
|
||||
(void)opaque;
|
||||
if (pressed)
|
||||
app_handleKeyPress(scancode);
|
||||
else
|
||||
app_handleKeyRelease(scancode);
|
||||
}
|
||||
|
||||
static void inputText(void * opaque, const char * text)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleKeyboardTyped(text);
|
||||
}
|
||||
|
||||
static void inputModifiers(void * opaque, bool ctrl, bool shift,
|
||||
bool alt, bool super)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleKeyboardModifiers(ctrl, shift, alt, super);
|
||||
}
|
||||
|
||||
static void inputLEDs(void * opaque, bool numLock, bool capsLock,
|
||||
bool scrollLock)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleKeyboardLEDs(numLock, capsLock, scrollLock);
|
||||
}
|
||||
|
||||
static void inputEnter(void * opaque, bool entered)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleEnterEvent(entered);
|
||||
}
|
||||
|
||||
static void inputFocus(void * opaque, bool focused)
|
||||
{
|
||||
(void)opaque;
|
||||
app_handleFocusEvent(focused);
|
||||
}
|
||||
|
||||
static const LG_DSInputSink inputSink = {
|
||||
.position = inputPosition,
|
||||
.relative = inputRelative,
|
||||
.button = inputButton,
|
||||
.wheel = inputWheel,
|
||||
.key = inputKey,
|
||||
.text = inputText,
|
||||
.modifiers = inputModifiers,
|
||||
.leds = inputLEDs,
|
||||
.enter = inputEnter,
|
||||
.focus = inputFocus,
|
||||
};
|
||||
|
||||
static void x11SignalFrame(LG_DSWaitFrameResult result)
|
||||
{
|
||||
atomic_fetch_or_explicit(
|
||||
@@ -354,6 +436,7 @@ static bool x11Init(const LG_DSInitParams params)
|
||||
XSetIOErrorHandler(x11IOErrorHandler);
|
||||
|
||||
memset(&x11, 0, sizeof(x11));
|
||||
x11InputInit(&x11.input, &inputSink, NULL);
|
||||
LG_LOCK_INIT(x11.pointerLock);
|
||||
atomic_init(&x11.captureActive, false);
|
||||
atomic_init(&x11.pointerGrabbed, false);
|
||||
@@ -1117,10 +1200,10 @@ static int x11EventThread(void * unused)
|
||||
focused = true;
|
||||
}
|
||||
|
||||
if (x11.ewmhHasFocusEvent && x11.focused != focused)
|
||||
if (x11.ewmhHasFocusEvent && x11.input.focused != focused)
|
||||
{
|
||||
x11.focused = focused;
|
||||
app_handleFocusEvent(focused);
|
||||
x11.input.focused = focused;
|
||||
inputFocus(x11.input.opaque, focused);
|
||||
}
|
||||
|
||||
x11.fullscreen = fullscreen;
|
||||
@@ -1181,12 +1264,12 @@ static enum Modifiers keySymToModifier(KeySym sym)
|
||||
|
||||
static void updateModifiers(void)
|
||||
{
|
||||
app_handleKeyboardModifiers(
|
||||
x11InputKeyboardState(&x11.input,
|
||||
x11.modifiers[MOD_CTRL_LEFT] || x11.modifiers[MOD_CTRL_RIGHT],
|
||||
x11.modifiers[MOD_SHIFT_LEFT] || x11.modifiers[MOD_SHIFT_RIGHT],
|
||||
x11.modifiers[MOD_ALT_LEFT] || x11.modifiers[MOD_ALT_RIGHT],
|
||||
x11.modifiers[MOD_SUPER_LEFT] || x11.modifiers[MOD_SUPER_RIGHT]
|
||||
);
|
||||
x11.modifiers[MOD_SUPER_LEFT] || x11.modifiers[MOD_SUPER_RIGHT],
|
||||
false, false, false);
|
||||
}
|
||||
|
||||
static void x11UpdateKeyboardGroup(void)
|
||||
@@ -1196,29 +1279,15 @@ static void x11UpdateKeyboardGroup(void)
|
||||
atomic_store(&x11.keyboardGroup, state.group);
|
||||
}
|
||||
|
||||
static int x11MapButton(unsigned int button)
|
||||
{
|
||||
if (button >= 1 && button <= 5)
|
||||
return button;
|
||||
|
||||
/* X11 reserves buttons 6 and 7 for horizontal scrolling. */
|
||||
if (button >= 8 && button < 34)
|
||||
return button - 2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setFocus(bool focused, double x, double y)
|
||||
{
|
||||
if (x11.focused == focused)
|
||||
if (x11.input.focused == focused)
|
||||
return;
|
||||
|
||||
if (focused)
|
||||
x11UpdateKeyboardGroup();
|
||||
|
||||
x11.focused = focused;
|
||||
app_updateCursorPos(x, y);
|
||||
app_handleFocusEvent(focused);
|
||||
x11InputFocus(&x11.input, focused, x, y, NULL, 0);
|
||||
}
|
||||
|
||||
static bool x11GetKeyLabel(int sc, char * label, size_t size)
|
||||
@@ -1238,8 +1307,6 @@ static bool x11GetKeyLabel(int sc, char * label, size_t size)
|
||||
|
||||
static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
{
|
||||
static uint32_t button_state = 0;
|
||||
|
||||
switch(cookie->evtype)
|
||||
{
|
||||
case XI_FocusIn:
|
||||
@@ -1254,7 +1321,7 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
}
|
||||
|
||||
atomic_store(&x11.lastWMEvent, microtime());
|
||||
if (x11.focused)
|
||||
if (x11.input.focused)
|
||||
return;
|
||||
|
||||
if (xie->mode != XINotifyNormal &&
|
||||
@@ -1279,7 +1346,7 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
}
|
||||
|
||||
atomic_store(&x11.lastWMEvent, microtime());
|
||||
if (!x11.focused)
|
||||
if (!x11.input.focused)
|
||||
return;
|
||||
|
||||
if (xie->mode != XINotifyNormal &&
|
||||
@@ -1295,13 +1362,8 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
{
|
||||
atomic_store(&x11.lastWMEvent, microtime());
|
||||
XIEnterEvent *xie = cookie->data;
|
||||
if (x11.entered || xie->event != x11.window ||
|
||||
xie->mode != XINotifyNormal)
|
||||
return;
|
||||
|
||||
app_updateCursorPos(xie->event_x, xie->event_y);
|
||||
app_handleEnterEvent(true);
|
||||
x11.entered = true;
|
||||
x11InputPointerEnter(&x11.input, xie->event == x11.window,
|
||||
xie->mode == XINotifyNormal, xie->event_x, xie->event_y);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1310,15 +1372,11 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
atomic_store(&x11.lastWMEvent, microtime());
|
||||
XILeaveEvent *xie = cookie->data;
|
||||
|
||||
if (!x11.entered || xie->event != x11.window ||
|
||||
button_state != 0 || app_isCaptureMode() ||
|
||||
xie->mode == NotifyGrab)
|
||||
if (!x11InputPointerLeave(&x11.input, xie->event == x11.window,
|
||||
xie->mode != NotifyGrab, app_isCaptureMode(),
|
||||
xie->event_x, xie->event_y))
|
||||
return;
|
||||
|
||||
app_updateCursorPos(xie->event_x, xie->event_y);
|
||||
app_handleEnterEvent(false);
|
||||
x11.entered = false;
|
||||
|
||||
/**
|
||||
* Because there is a race with the pointer ungrab the enter event for the
|
||||
* next window is sometimes sent with the mode NotifyUngrab, unfortunatly
|
||||
@@ -1363,12 +1421,13 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
|
||||
case XI_KeyPress:
|
||||
{
|
||||
if (!x11.focused || x11.keyboardGrabbed)
|
||||
if (!x11.input.focused || x11.keyboardGrabbed)
|
||||
return;
|
||||
|
||||
XIDeviceEvent *device = cookie->data;
|
||||
atomic_store(&x11.keyboardGroup, device->group.effective);
|
||||
app_handleKeyPress(device->detail - x11.minKeycode);
|
||||
x11InputKeyboardKey(&x11.input, device->detail, x11.minKeycode,
|
||||
true, false, true, NULL);
|
||||
|
||||
if (!x11.xic || !app_isOverlayMode())
|
||||
return;
|
||||
@@ -1397,7 +1456,7 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
if (status == XLookupChars || status == XLookupBoth)
|
||||
{
|
||||
buffer[count] = '\0';
|
||||
app_handleKeyboardTyped(buffer);
|
||||
inputText(x11.input.opaque, buffer);
|
||||
}
|
||||
|
||||
if (status == XLookupKeySym || status == XLookupBoth)
|
||||
@@ -1414,11 +1473,12 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
|
||||
case XI_KeyRelease:
|
||||
{
|
||||
if (!x11.focused || x11.keyboardGrabbed)
|
||||
if (!x11.input.focused || x11.keyboardGrabbed)
|
||||
return;
|
||||
|
||||
XIDeviceEvent *device = cookie->data;
|
||||
app_handleKeyRelease(device->detail - x11.minKeycode);
|
||||
x11InputKeyboardKey(&x11.input, device->detail, x11.minKeycode,
|
||||
false, false, true, NULL);
|
||||
|
||||
if (!x11.xic || !app_isOverlayMode())
|
||||
return;
|
||||
@@ -1443,116 +1503,63 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
|
||||
case XI_RawKeyPress:
|
||||
{
|
||||
if (!x11.focused)
|
||||
return;
|
||||
|
||||
XIRawEvent *raw = cookie->data;
|
||||
app_handleKeyPress(raw->detail - x11.minKeycode);
|
||||
x11InputKeyboardKey(&x11.input, raw->detail, x11.minKeycode,
|
||||
true, true, x11.input.focused, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_RawKeyRelease:
|
||||
{
|
||||
if (!x11.focused)
|
||||
return;
|
||||
|
||||
XIRawEvent *raw = cookie->data;
|
||||
app_handleKeyRelease(raw->detail - x11.minKeycode);
|
||||
x11InputKeyboardKey(&x11.input, raw->detail, x11.minKeycode,
|
||||
false, true, x11.input.focused, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_ButtonPress:
|
||||
{
|
||||
if (!x11.focused || !x11.entered)
|
||||
return;
|
||||
|
||||
XIDeviceEvent *device = cookie->data;
|
||||
const int button = x11MapButton(device->detail);
|
||||
if (button == 4)
|
||||
app_handleWheelMotion(-0.5);
|
||||
else if (button == 5)
|
||||
app_handleWheelMotion(0.5);
|
||||
else if (button)
|
||||
app_handleButtonPress(button);
|
||||
|
||||
x11InputPointerButton(&x11.input, device->detail, true, false,
|
||||
device->time, true);
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_ButtonRelease:
|
||||
{
|
||||
if (!x11.focused || !x11.entered)
|
||||
return;
|
||||
|
||||
XIDeviceEvent *device = cookie->data;
|
||||
const int button = x11MapButton(device->detail);
|
||||
if (button && button != 4 && button != 5)
|
||||
app_handleButtonRelease(button);
|
||||
x11InputPointerButton(&x11.input, device->detail, false, false,
|
||||
device->time, true);
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_RawButtonPress:
|
||||
{
|
||||
if (!x11.focused || !x11.entered)
|
||||
return;
|
||||
|
||||
XIRawEvent *raw = cookie->data;
|
||||
const int button = x11MapButton(raw->detail);
|
||||
if (!button)
|
||||
return;
|
||||
|
||||
/* filter out duplicate events */
|
||||
static Time prev_time = 0;
|
||||
static unsigned int prev_detail = 0;
|
||||
if (raw->time == prev_time && raw->detail == prev_detail)
|
||||
return;
|
||||
|
||||
prev_time = raw->time;
|
||||
prev_detail = raw->detail;
|
||||
button_state |= UINT32_C(1) << button;
|
||||
|
||||
app_handleButtonPress(button);
|
||||
x11InputPointerButton(&x11.input, raw->detail, true, true,
|
||||
raw->time, x11.input.focused && x11.input.entered);
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_RawButtonRelease:
|
||||
{
|
||||
if (!x11.focused || !x11.entered)
|
||||
return;
|
||||
|
||||
XIRawEvent *raw = cookie->data;
|
||||
const int button = x11MapButton(raw->detail);
|
||||
if (!button)
|
||||
return;
|
||||
|
||||
/* filter out duplicate events */
|
||||
static Time prev_time = 0;
|
||||
static unsigned int prev_detail = 0;
|
||||
if (raw->time == prev_time && raw->detail == prev_detail)
|
||||
return;
|
||||
|
||||
prev_time = raw->time;
|
||||
prev_detail = raw->detail;
|
||||
button_state &= ~(UINT32_C(1) << button);
|
||||
|
||||
app_handleButtonRelease(button);
|
||||
x11InputPointerButton(&x11.input, raw->detail, false, true,
|
||||
raw->time, x11.input.focused && x11.input.entered);
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_Motion:
|
||||
{
|
||||
XIDeviceEvent *device = cookie->data;
|
||||
app_updateCursorPos(device->event_x, device->event_y);
|
||||
|
||||
if (!atomic_load_explicit(&x11.pointerGrabbed, memory_order_acquire))
|
||||
app_handleMouseRelative(0.0, 0.0, 0.0, 0.0);
|
||||
x11InputPointerMotion(&x11.input, device->event_x, device->event_y,
|
||||
atomic_load_explicit(&x11.pointerGrabbed,
|
||||
memory_order_acquire));
|
||||
return;
|
||||
}
|
||||
|
||||
case XI_RawMotion:
|
||||
{
|
||||
if (!x11.focused || !x11.entered)
|
||||
return;
|
||||
|
||||
XIRawEvent *raw = cookie->data;
|
||||
double raw_axis[2] = { 0 };
|
||||
double axis[2] = { 0 };
|
||||
@@ -1587,19 +1594,9 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
|
||||
if (!has_axes)
|
||||
return;
|
||||
|
||||
/* filter out duplicate events */
|
||||
static Time prev_time = 0;
|
||||
static double prev_axis[2] = {0};
|
||||
if (raw->time == prev_time &&
|
||||
axis[0] == prev_axis[0] &&
|
||||
axis[1] == prev_axis[1])
|
||||
return;
|
||||
|
||||
prev_time = raw->time;
|
||||
prev_axis[0] = axis[0];
|
||||
prev_axis[1] = axis[1];
|
||||
|
||||
app_handleMouseRelative(axis[0], axis[1], raw_axis[0], raw_axis[1]);
|
||||
x11InputRelativeMotion(&x11.input, raw->time, axis[0], axis[1],
|
||||
raw_axis[0], raw_axis[1],
|
||||
x11.input.focused && x11.input.entered);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1903,7 +1900,7 @@ static void x11StopWaitFrame(void)
|
||||
|
||||
static void x11GuestPointerUpdated(double x, double y, double localX, double localY)
|
||||
{
|
||||
if (app_isCaptureMode() || !x11.entered)
|
||||
if (app_isCaptureMode() || !x11.input.entered)
|
||||
return;
|
||||
|
||||
// avoid running too often
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "common/locking.h"
|
||||
#include "common/thread.h"
|
||||
#include "common/types.h"
|
||||
#include "input_event.h"
|
||||
#include "wm.h"
|
||||
|
||||
enum Modifiers
|
||||
@@ -96,12 +97,11 @@ struct X11DSState
|
||||
int xValuator;
|
||||
int yValuator;
|
||||
|
||||
X11Input input;
|
||||
LG_Lock pointerLock;
|
||||
_Atomic(bool) captureActive;
|
||||
_Atomic(bool) pointerGrabbed;
|
||||
bool keyboardGrabbed;
|
||||
bool entered;
|
||||
bool focused;
|
||||
bool fullscreen;
|
||||
|
||||
struct Rect rect;
|
||||
|
||||
44
client/displayservers/input.h
Normal file
44
client/displayservers/input.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _H_LG_DS_INPUT_
|
||||
#define _H_LG_DS_INPUT_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct LG_DSInputSink
|
||||
{
|
||||
void (*position)(void * opaque, double x, double y);
|
||||
void (*relative)(void * opaque, double x, double y,
|
||||
double rawX, double rawY);
|
||||
void (*button)(void * opaque, unsigned int button, bool pressed);
|
||||
void (*wheel)(void * opaque, double motion);
|
||||
void (*key)(void * opaque, int scancode, bool pressed);
|
||||
void (*text)(void * opaque, const char * text);
|
||||
void (*modifiers)(void * opaque, bool ctrl, bool shift, bool alt,
|
||||
bool super);
|
||||
void (*leds)(void * opaque, bool numLock, bool capsLock,
|
||||
bool scrollLock);
|
||||
void (*enter)(void * opaque, bool entered);
|
||||
void (*focus)(void * opaque, bool focused);
|
||||
}
|
||||
LG_DSInputSink;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user