wayland: move keyboard repeat handling into wayland

This commit is contained in:
Daniel Eklöf 2019-10-27 19:16:12 +01:00
parent 1e75b89552
commit 251cf98388
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 39 additions and 31 deletions

31
main.c
View file

@ -123,33 +123,6 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
return !(events & EPOLLHUP);
}
#include "input.h"
static bool
fdm_repeat(struct fdm *fdm, int fd, int events, void *data)
{
if (events & EPOLLHUP)
return false;
struct wayland *wayl = data;
uint64_t expiration_count;
ssize_t ret = read(
wayl->kbd.repeat.fd, &expiration_count, sizeof(expiration_count));
if (ret < 0) {
if (errno == EAGAIN)
return true;
LOG_ERRNO("failed to read repeat key from repeat timer fd");
return false;
}
wayl->kbd.repeat.dont_re_repeat = true;
for (size_t i = 0; i < expiration_count; i++)
input_repeat(wayl, wayl->kbd.repeat.key);
wayl->kbd.repeat.dont_re_repeat = false;
return true;
}
static bool
fdm_flash(struct fdm *fdm, int fd, int events, void *data)
{
@ -637,7 +610,6 @@ main(int argc, char *const *argv)
}
fdm_add(fdm, term.ptmx, EPOLLIN, &fdm_ptmx, &term);
fdm_add(fdm, term.wl->kbd.repeat.fd, EPOLLIN, &fdm_repeat, term.wl);
fdm_add(fdm, term.flash.fd, EPOLLIN, &fdm_flash, &term);
fdm_add(fdm, term.blink.fd, EPOLLIN, &fdm_blink, &term);
fdm_add(fdm, term.delayed_render_timer.lower_fd, EPOLLIN, &fdm_delayed_render, &term);
@ -655,7 +627,6 @@ main(int argc, char *const *argv)
out:
if (fdm != NULL) {
fdm_del(fdm, term.ptmx);
fdm_del(fdm, term.wl->kbd.repeat.fd);
fdm_del(fdm, term.flash.fd);
fdm_del(fdm, term.blink.fd);
fdm_del(fdm, term.delayed_render_timer.lower_fd);
@ -701,8 +672,6 @@ out:
close(term.flash.fd);
if (term.blink.fd != -1)
close(term.blink.fd);
if (term.wl->kbd.repeat.fd != -1)
close(term.wl->kbd.repeat.fd);
if (term.ptmx != -1)
close(term.ptmx);

View file

@ -1,6 +1,9 @@
#include "wayland.h"
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/timerfd.h>
#include <sys/epoll.h>
@ -393,6 +396,32 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data)
return event_count != -1 && !wayl->term->quit;
}
static bool
fdm_repeat(struct fdm *fdm, int fd, int events, void *data)
{
if (events & EPOLLHUP)
return false;
struct wayland *wayl = data;
uint64_t expiration_count;
ssize_t ret = read(
wayl->kbd.repeat.fd, &expiration_count, sizeof(expiration_count));
if (ret < 0) {
if (errno == EAGAIN)
return true;
LOG_ERRNO("failed to read repeat key from repeat timer fd");
return false;
}
wayl->kbd.repeat.dont_re_repeat = true;
for (size_t i = 0; i < expiration_count; i++)
input_repeat(wayl, wayl->kbd.repeat.key);
wayl->kbd.repeat.dont_re_repeat = false;
return true;
}
struct wayland *
wayl_init(struct fdm *fdm)
{
@ -496,6 +525,11 @@ wayl_init(struct fdm *fdm)
goto out;
}
if (!fdm_add(fdm, wayl->kbd.repeat.fd, EPOLLIN, &fdm_repeat, wayl)) {
LOG_ERR("failed to register keyboard repeat timer with the FDM");
goto out;
}
return wayl;
out:
@ -507,6 +541,11 @@ out:
void
wayl_destroy(struct wayland *wayl)
{
if (wayl->kbd.repeat.fd != 0) {
fdm_del(wayl->fdm, wayl->kbd.repeat.fd);
close(wayl->kbd.repeat.fd);
}
tll_foreach(wayl->monitors, it) {
free(it->item.name);
if (it->item.xdg != NULL)