mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-12 10:28:08 +00:00
[client] evdev: add new exclusive evdev while captured option
Some checks are pending
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Waiting to run
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Waiting to run
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Waiting to run
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Waiting to run
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Waiting to run
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Waiting to run
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Waiting to run
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Waiting to run
build / module (push) Waiting to run
build / host-linux (push) Waiting to run
build / host-windows-cross (push) Waiting to run
build / host-windows-native (push) Waiting to run
build / obs (clang) (push) Waiting to run
build / obs (gcc) (push) Waiting to run
build / docs (push) Waiting to run
Some checks are pending
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Waiting to run
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Waiting to run
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Waiting to run
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Waiting to run
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Waiting to run
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Waiting to run
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Waiting to run
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Waiting to run
build / module (push) Waiting to run
build / host-linux (push) Waiting to run
build / host-windows-cross (push) Waiting to run
build / host-windows-native (push) Waiting to run
build / obs (clang) (push) Waiting to run
build / obs (gcc) (push) Waiting to run
build / docs (push) Waiting to run
This commit is contained in:
@@ -27,7 +27,8 @@
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#include "app.h"
|
||||
#include "app_internal.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/option.h"
|
||||
@@ -47,9 +48,23 @@ struct EvdevState
|
||||
char * deviceList;
|
||||
EvdevDevice * devices;
|
||||
int deviceCount;
|
||||
bool exclusive;
|
||||
int keys[KEY_MAX];
|
||||
|
||||
void (*dsGrabKeyboard)(void);
|
||||
void (*dsUngrabKeyboard)(void);
|
||||
|
||||
int epoll;
|
||||
LGThread * thread;
|
||||
bool grabbed;
|
||||
|
||||
enum
|
||||
{
|
||||
PENDING_NONE,
|
||||
PENDING_GRAB,
|
||||
PENDING_UNGRAB
|
||||
}
|
||||
pending;
|
||||
};
|
||||
|
||||
static struct EvdevState state = {};
|
||||
@@ -64,6 +79,14 @@ static struct Option options[] =
|
||||
.type = OPTION_TYPE_STRING,
|
||||
.value.x_string = NULL,
|
||||
},
|
||||
{
|
||||
.module = "input",
|
||||
.name = "evdevExclusive",
|
||||
.description = "Only use evdev devices for keyboard input when in capture "
|
||||
"mode",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = true
|
||||
},
|
||||
{0}
|
||||
};
|
||||
|
||||
@@ -89,13 +112,35 @@ static int evdev_thread(void * opaque)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!state.grabbed || ev.type != EV_KEY)
|
||||
if (ev.type != EV_KEY)
|
||||
continue;
|
||||
|
||||
bool grabbed = state.grabbed;
|
||||
if (ev.value == 1)
|
||||
app_handleKeyPress(ev.code);
|
||||
else if (ev.value == 0)
|
||||
app_handleKeyRelease(ev.code);
|
||||
{
|
||||
++state.keys[ev.code];
|
||||
|
||||
if (grabbed && state.keys[ev.code] == 1)
|
||||
app_handleKeyPressInternal(ev.code);
|
||||
}
|
||||
else if (ev.value == 0 && --state.keys[ev.code] <= 0)
|
||||
{
|
||||
state.keys[ev.code] = 0;
|
||||
|
||||
if (state.pending == PENDING_GRAB)
|
||||
{
|
||||
state.pending = PENDING_NONE;
|
||||
evdev_grabKeyboard();
|
||||
}
|
||||
else if (state.pending == PENDING_UNGRAB)
|
||||
{
|
||||
state.pending = PENDING_NONE;
|
||||
evdev_ungrabKeyboard();
|
||||
}
|
||||
|
||||
if (grabbed)
|
||||
app_handleKeyReleaseInternal(ev.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUG_INFO("evdev_thread Stopped");
|
||||
@@ -128,6 +173,8 @@ bool evdev_start(void)
|
||||
if (state.deviceCount == 0)
|
||||
return false;
|
||||
|
||||
state.exclusive = option_get("input", "evdevExclusive");
|
||||
|
||||
state.epoll = epoll_create1(0);
|
||||
if (state.epoll < 0)
|
||||
{
|
||||
@@ -166,6 +213,12 @@ bool evdev_start(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
//hook the display server's grab methods
|
||||
state.dsGrabKeyboard = g_state.ds->grabKeyboard;
|
||||
state.dsUngrabKeyboard = g_state.ds->ungrabKeyboard;
|
||||
g_state.ds->grabKeyboard = &evdev_grabKeyboard;
|
||||
g_state.ds->ungrabKeyboard = &evdev_ungrabKeyboard;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -201,6 +254,19 @@ void evdev_stop(void)
|
||||
|
||||
void evdev_grabKeyboard(void)
|
||||
{
|
||||
if (state.grabbed)
|
||||
return;
|
||||
|
||||
// we must be in a neutral state
|
||||
for(int i = 0; i < KEY_MAX; ++i)
|
||||
if (state.keys[i] > 0)
|
||||
{
|
||||
state.pending = PENDING_GRAB;
|
||||
return;
|
||||
}
|
||||
|
||||
// state.dsGrabKeyboard();
|
||||
|
||||
for(EvdevDevice * device = state.devices; device->path; ++device)
|
||||
{
|
||||
if (device->fd <= 0 || device->grabbed)
|
||||
@@ -220,6 +286,17 @@ void evdev_grabKeyboard(void)
|
||||
|
||||
void evdev_ungrabKeyboard(void)
|
||||
{
|
||||
if (!state.grabbed)
|
||||
return;
|
||||
|
||||
// we must be in a neutral state
|
||||
for(int i = 0; i < KEY_MAX; ++i)
|
||||
if (state.keys[i] > 0)
|
||||
{
|
||||
state.pending = PENDING_UNGRAB;
|
||||
return;
|
||||
}
|
||||
|
||||
for(EvdevDevice * device = state.devices; device->path; ++device)
|
||||
{
|
||||
if (device->fd <= 0 || !device->grabbed)
|
||||
@@ -234,5 +311,13 @@ void evdev_ungrabKeyboard(void)
|
||||
DEBUG_INFO("Ungrabbed %s", device->path);
|
||||
device->grabbed = false;
|
||||
}
|
||||
|
||||
// state.dsUngrabKeyboard();
|
||||
|
||||
state.grabbed = false;
|
||||
}
|
||||
|
||||
bool evdev_isExclusive(void)
|
||||
{
|
||||
return state.exclusive && state.grabbed && !app_isOverlayMode();
|
||||
}
|
||||
|
Reference in New Issue
Block a user