mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-05-02 04:31:09 +00:00
[client] evdev: read up to 256 events at a time
This commit is contained in:
parent
35e6a6e81a
commit
4278a10fe1
@ -149,6 +149,8 @@ err:
|
|||||||
static int evdev_thread(void * opaque)
|
static int evdev_thread(void * opaque)
|
||||||
{
|
{
|
||||||
struct epoll_event * events = alloca(sizeof(*events) * state.deviceCount);
|
struct epoll_event * events = alloca(sizeof(*events) * state.deviceCount);
|
||||||
|
struct input_event msgs[256];
|
||||||
|
|
||||||
DEBUG_INFO("evdev_thread Started");
|
DEBUG_INFO("evdev_thread Started");
|
||||||
while(app_isRunning())
|
while(app_isRunning())
|
||||||
{
|
{
|
||||||
@ -174,11 +176,9 @@ static int evdev_thread(void * opaque)
|
|||||||
int waiting = epoll_wait(state.epoll, events, state.deviceCount, 100);
|
int waiting = epoll_wait(state.epoll, events, state.deviceCount, 100);
|
||||||
for(int i = 0; i < waiting; ++i)
|
for(int i = 0; i < waiting; ++i)
|
||||||
{
|
{
|
||||||
struct input_event ev;
|
|
||||||
EvdevDevice * device = (EvdevDevice *)events[i].data.ptr;
|
EvdevDevice * device = (EvdevDevice *)events[i].data.ptr;
|
||||||
|
int n = read(device->fd, msgs, sizeof(msgs));
|
||||||
size_t n = read(device->fd, &ev, sizeof(ev));
|
if (n < 0)
|
||||||
if (n != sizeof(ev))
|
|
||||||
{
|
{
|
||||||
if (errno == ENODEV)
|
if (errno == ENODEV)
|
||||||
{
|
{
|
||||||
@ -196,20 +196,27 @@ static int evdev_thread(void * opaque)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.type != EV_KEY)
|
if (n % sizeof(*msgs) != 0)
|
||||||
|
DEBUG_WARN("Incomplete evdev read: %s", device->path);
|
||||||
|
|
||||||
|
int count = n / sizeof(*msgs);
|
||||||
|
struct input_event *ev = msgs;
|
||||||
|
for(int i = 0; i < count; ++i, ++ev)
|
||||||
|
{
|
||||||
|
if (ev->type != EV_KEY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool grabbed = state.grabbed;
|
bool grabbed = state.grabbed;
|
||||||
if (ev.value == 1)
|
if (ev->value == 1)
|
||||||
{
|
{
|
||||||
++state.keys[ev.code];
|
++state.keys[ev->code];
|
||||||
|
|
||||||
if (grabbed && state.keys[ev.code] == 1)
|
if (grabbed && state.keys[ev->code] == 1)
|
||||||
app_handleKeyPressInternal(ev.code);
|
app_handleKeyPressInternal(ev->code);
|
||||||
}
|
}
|
||||||
else if (ev.value == 0 && --state.keys[ev.code] <= 0)
|
else if (ev->value == 0 && --state.keys[ev->code] <= 0)
|
||||||
{
|
{
|
||||||
state.keys[ev.code] = 0;
|
state.keys[ev->code] = 0;
|
||||||
|
|
||||||
if (state.pending == PENDING_GRAB)
|
if (state.pending == PENDING_GRAB)
|
||||||
{
|
{
|
||||||
@ -223,7 +230,8 @@ static int evdev_thread(void * opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (grabbed)
|
if (grabbed)
|
||||||
app_handleKeyReleaseInternal(ev.code);
|
app_handleKeyReleaseInternal(ev->code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user