aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drmtest.c3
-rw-r--r--egltest.c3
-rw-r--r--fbtest.c6
-rw-r--r--logind.c47
-rw-r--r--logind.h4
-rw-r--r--meson.build14
-rw-r--r--ttytools.c66
-rw-r--r--ttytools.h1
-rw-r--r--virtiotest.c3
9 files changed, 106 insertions, 41 deletions
diff --git a/drmtest.c b/drmtest.c
index 6eb7e2b..8dc961c 100644
--- a/drmtest.c
+++ b/drmtest.c
@@ -355,7 +355,6 @@ int main(int argc, char **argv)
char *output = NULL;
char *format = NULL;
char *modename = NULL;
- char buf[32];
bool dmabuf = false;
bool autotest = false;
bool pixman = false;
@@ -512,7 +511,7 @@ int main(int argc, char **argv)
fprintf(stdout, "---ok---\n");
tty_raw();
kbd_wait(secs);
- read(0, buf, sizeof(buf));
+ kbd_read();
tty_restore();
drm_fini_dev();
diff --git a/egltest.c b/egltest.c
index 3231f66..cea29da 100644
--- a/egltest.c
+++ b/egltest.c
@@ -94,7 +94,6 @@ int main(int argc, char **argv)
bool printinfo = false;
bool printext = false;
bool autotest = false;
- char buf[32];
int c;
for (;;) {
@@ -148,7 +147,7 @@ int main(int argc, char **argv)
tty_raw();
kbd_wait(secs);
- read(0, buf, sizeof(buf));
+ kbd_read();
tty_restore();
done:
diff --git a/fbtest.c b/fbtest.c
index 5c17fef..e946c3b 100644
--- a/fbtest.c
+++ b/fbtest.c
@@ -77,7 +77,6 @@ int main(int argc, char **argv)
int framebuffer = 0;
int secs = 60;
bool autotest = false;
- char buf[32];
int c;
for (;;) {
@@ -106,7 +105,10 @@ int main(int argc, char **argv)
}
}
+#if 0
+ /* logind doesn't support framebuffers it seems ... */
logind_init();
+#endif
fb_init(framebuffer);
cs = cairo_image_surface_create_for_data(fb_mem + fb_mem_offset,
fb_format,
@@ -119,7 +121,7 @@ int main(int argc, char **argv)
fprintf(stdout, "---ok---\n");
tty_raw();
kbd_wait(secs);
- read(0, buf, sizeof(buf));
+ kbd_read();
tty_restore();
fb_fini();
diff --git a/logind.c b/logind.c
index de568c7..a2bc9a8 100644
--- a/logind.c
+++ b/logind.c
@@ -95,12 +95,6 @@ void logind_init(void)
const char *session_id, *seat;
int r;
-#if 1
- /* Disable for now. TakeControl kills input via tty, only evdev works. */
- if (1)
- return;
-#endif
-
if (logind_dbus)
return;
@@ -136,7 +130,7 @@ void logind_fini(void)
logind_dbus = NULL;
}
-int logind_open(const char *path)
+int logind_open(const char *path, int flags, void *user_data)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *m = NULL;
@@ -184,14 +178,26 @@ int logind_open(const char *path)
strerror(-r));
} else {
fd = fcntl(handle, F_DUPFD_CLOEXEC, 0);
+#if 0
fprintf(stderr, "open %s: got fd %d via logind.\n",
path, fd);
+#endif
}
sd_bus_message_unref(m);
return fd;
}
+void logind_close(int fd, void *user_data)
+{
+ /* FIXME */
+}
+
+bool have_logind(void)
+{
+ return logind_dbus != NULL;
+}
+
#else
/* ---------------------------------------------------------------------- */
@@ -204,7 +210,7 @@ void logind_fini(void)
{
}
-int logind_open(const char *path)
+int logind_open(const char *path, int flags, void *user_data)
{
const char *session_id, *seat;
@@ -218,20 +224,33 @@ int logind_open(const char *path)
return -1;
}
+void logind_close(int fd, void *user_data)
+{
+}
+
+bool have_logind(void)
+{
+ return false;
+}
+
#endif
/* ---------------------------------------------------------------------- */
int device_open(const char *device)
{
- int saved_errno, fd;
+ int fd;
- fd = open(device, O_RDWR | O_CLOEXEC);
- if (fd < 0) {
- saved_errno = errno;
- fd = logind_open(device);
+ if (have_logind()) {
+ fd = logind_open(device, O_RDWR, NULL);
+ if (fd < 0) {
+ fprintf(stderr,"logind: can't get handle for %s\n", device);
+ exit(1);
+ }
+ } else {
+ fd = open(device, O_RDWR | O_CLOEXEC);
if (fd < 0) {
- fprintf(stderr,"open %s: %s\n", device, strerror(saved_errno));
+ fprintf(stderr,"open %s: %s\n", device, strerror(errno));
exit(1);
}
}
diff --git a/logind.h b/logind.h
index 0e81b0b..5dee999 100644
--- a/logind.h
+++ b/logind.h
@@ -3,6 +3,8 @@
void logind_init(void);
void logind_fini(void);
-int logind_open(const char *path);
+bool have_logind(void);
+int logind_open(const char *path, int flags, void *user_data);
+void logind_close(int fd, void *user_data);
int device_open(const char *device);
diff --git a/meson.build b/meson.build
index 29e6e6a..fa89bcc 100644
--- a/meson.build
+++ b/meson.build
@@ -11,6 +11,8 @@ epoxy_dep = dependency('epoxy')
cairo_dep = dependency('cairo')
pixman_dep = dependency('pixman-1')
gtk3_dep = dependency('gtk+-3.0')
+udev_dep = dependency('libudev')
+input_dep = dependency('libinput')
xcb_dep = dependency('xcb', required : false)
randr_dep = dependency('xcb-randr', required : false, version : '>=1.13')
systemd_dep = dependency('libsystemd', required : false, version : '>=221')
@@ -46,15 +48,19 @@ drminfo_deps = [ libdrm_dep, cairo_dep, pixman_dep, systemd_dep,
xcb_dep, randr_dep ]
drmtest_deps = [ libdrm_dep, gbm_dep, epoxy_dep,
xcb_dep, randr_dep,
- cairo_dep, pixman_dep, jpeg_dep, systemd_dep ]
+ cairo_dep, pixman_dep, jpeg_dep,
+ udev_dep, input_dep, systemd_dep ]
fbinfo_deps = [ cairo_dep, systemd_dep ]
-fbtest_deps = [ cairo_dep, pixman_dep, jpeg_dep, systemd_dep ]
+fbtest_deps = [ cairo_dep, pixman_dep, jpeg_dep,
+ udev_dep, input_dep, systemd_dep ]
prime_deps = [ libdrm_dep, gbm_dep, systemd_dep ]
viotest_deps = [ libdrm_dep, gbm_dep, epoxy_dep,
- cairo_dep, pixman_dep, jpeg_dep, systemd_dep ]
+ cairo_dep, pixman_dep, jpeg_dep,
+ udev_dep, input_dep, systemd_dep ]
egltest_deps = [ libdrm_dep, gbm_dep, epoxy_dep,
xcb_dep, randr_dep,
- cairo_dep, pixman_dep, systemd_dep ]
+ cairo_dep, pixman_dep,
+ udev_dep, input_dep, systemd_dep ]
gtktest_deps = [ gtk3_dep,
cairo_dep, pixman_dep, jpeg_dep ]
diff --git a/ttytools.c b/ttytools.c
index 95289a2..1c38249 100644
--- a/ttytools.c
+++ b/ttytools.c
@@ -11,43 +11,81 @@
#include <sys/time.h>
+#include <libudev.h>
+#include <libinput.h>
+
#include "ttytools.h"
+#include "logind.h"
static struct termios saved_attributes;
static int saved_fl;
+static struct libinput *ctx;
+
+const struct libinput_interface libinput_if = {
+ .open_restricted = logind_open,
+ .close_restricted = logind_close,
+};
+
void tty_raw(void)
{
struct termios tattr;
+ struct udev *udev;
- fcntl(STDIN_FILENO, F_GETFL, &saved_fl);
- tcgetattr (0, &saved_attributes);
-
- fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
- memcpy(&tattr,&saved_attributes,sizeof(struct termios));
- tattr.c_lflag &= ~(ICANON|ECHO);
- tattr.c_cc[VMIN] = 1;
- tattr.c_cc[VTIME] = 0;
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr);
+ if (have_logind()) {
+ udev = udev_new();
+ ctx = libinput_udev_create_context(&libinput_if, NULL, udev);
+ libinput_udev_assign_seat(ctx, getenv("XDG_SEAT"));
+ } else {
+ fcntl(STDIN_FILENO, F_GETFL, &saved_fl);
+ tcgetattr (0, &saved_attributes);
+ fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
+ memcpy(&tattr,&saved_attributes,sizeof(struct termios));
+ tattr.c_lflag &= ~(ICANON|ECHO);
+ tattr.c_cc[VMIN] = 1;
+ tattr.c_cc[VTIME] = 0;
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr);
+ }
}
void tty_restore(void)
{
- fcntl(STDIN_FILENO, F_SETFL, saved_fl);
- tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes);
+ if (have_logind()) {
+ libinput_unref(ctx);
+ } else {
+ fcntl(STDIN_FILENO, F_SETFL, saved_fl);
+ tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes);
+ }
}
int kbd_wait(int timeout)
{
struct timeval limit;
fd_set set;
- int rc;
+ int fd, rc;
+
+ if (have_logind()) {
+ fd = libinput_get_fd(ctx);
+ } else {
+ fd = STDIN_FILENO;
+ }
FD_ZERO(&set);
- FD_SET(STDIN_FILENO, &set);
+ FD_SET(fd, &set);
limit.tv_sec = timeout;
limit.tv_usec = 0;
- rc = select(STDIN_FILENO + 1, &set, NULL, NULL,
+ rc = select(fd + 1, &set, NULL, NULL,
timeout ? &limit : NULL);
return rc;
}
+
+void kbd_read(void)
+{
+ char buf[32];
+
+ if (have_logind()) {
+ /* nothing */
+ } else {
+ read(0, buf, sizeof(buf));
+ }
+}
diff --git a/ttytools.h b/ttytools.h
index 391fa08..3f369d2 100644
--- a/ttytools.h
+++ b/ttytools.h
@@ -1,3 +1,4 @@
void tty_raw(void);
void tty_restore(void);
int kbd_wait(int timeout);
+void kbd_read(void);
diff --git a/virtiotest.c b/virtiotest.c
index 8acce4c..d718e7f 100644
--- a/virtiotest.c
+++ b/virtiotest.c
@@ -249,7 +249,6 @@ int main(int argc, char **argv)
bool printinfo = false;
bool listformat = false;
bool autotest = false;
- char buf[32];
int c, i;
for (;;) {
@@ -310,7 +309,7 @@ int main(int argc, char **argv)
fprintf(stdout, "---ok---\n");
tty_raw();
kbd_wait(secs);
- read(0, buf, sizeof(buf));
+ kbd_read();
tty_restore();
done: