aboutsummaryrefslogtreecommitdiffstats
path: root/kbd.c
diff options
context:
space:
mode:
Diffstat (limited to 'kbd.c')
-rw-r--r--kbd.c175
1 files changed, 2 insertions, 173 deletions
diff --git a/kbd.c b/kbd.c
index ed39220..d9ce8b3 100644
--- a/kbd.c
+++ b/kbd.c
@@ -11,11 +11,6 @@
#include <sys/stat.h>
-#include "config.h"
-#ifdef HAVE_SYSTEMD
-# include <systemd/sd-bus.h>
-#endif
-
#include "kbd.h"
/* ---------------------------------------------------------------------- */
@@ -199,157 +194,6 @@ static int file_wait(int fd, int timeout)
/* ---------------------------------------------------------------------- */
-#ifdef HAVE_SYSTEMD
-
-static sd_bus *logind_dbus = NULL;
-
-void logind_init(void)
-{
- sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus_message *m = NULL;
- int r;
-
- r = sd_bus_open_system(&logind_dbus);
- if (r < 0) {
- fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));
- return;
- }
-
- r = sd_bus_call_method(logind_dbus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1/session/self",
- "org.freedesktop.login1.Session",
- "TakeControl",
- &error,
- &m,
- "b",
- false);
- if (r < 0) {
- fprintf(stderr, "TakeControl failed: %s\n", error.message);
- sd_bus_error_free(&error);
- sd_bus_unref(logind_dbus);
- logind_dbus = NULL;
- return;
- }
-
- fprintf(stderr, "Opening input devices via logind.\n");
-}
-
-bool use_logind(void)
-{
- return logind_dbus != NULL;
-}
-
-int logind_open(const char *path)
-{
- sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus_message *m = NULL;
- struct stat st;
- unsigned int maj, min;
- int inactive;
- int handle, fd, r;
-
- r = stat(path, &st);
- if (r < 0) {
- fprintf(stderr, "stat %s failed: %s\n", path, strerror(errno));
- return -1;
- }
-
- maj = major(st.st_rdev);
- min = minor(st.st_rdev);
- r = sd_bus_call_method(logind_dbus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1/session/self",
- "org.freedesktop.login1.Session",
- "TakeDevice",
- &error,
- &m,
- "uu",
- maj,
- min);
- if (r < 0) {
- fprintf(stderr, "TakeDevice failed: %s\n", error.message);
- sd_bus_error_free(&error);
- return -1;
- }
-
- handle = -1;
- inactive = -1;
- r = sd_bus_message_read(m, "hb", &handle, &inactive);
- if (r < 0) {
- fd = -1;
- fprintf(stderr, "Parsing TakeDevice reply failed: %s\n", strerror(-r));
- } else {
- fd = fcntl(handle, F_DUPFD_CLOEXEC, 0);
- fprintf(stderr, "open %s: got fd %d via logind.\n",
- path, fd);
- }
- sd_bus_message_unref(m);
-
- return fd;
-}
-
-void logind_close(int fd)
-{
- sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus_message *m = NULL;
- struct stat st;
- unsigned int maj, min;
- int r;
-
- r = fstat(fd, &st);
- if (r < 0) {
- fprintf(stderr, "fstat failed: %s\n", strerror(errno));
- return;
- }
- close(fd);
-
- maj = major(st.st_rdev);
- min = minor(st.st_rdev);
- r = sd_bus_call_method(logind_dbus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1/session/self",
- "org.freedesktop.login1.Session",
- "ReleaseDevice",
- &error,
- &m,
- "uu",
- maj,
- min);
- if (r < 0) {
- fprintf(stderr, "ReleaseDevice failed: %s\n", error.message);
- sd_bus_error_free(&error);
- return;
- }
- sd_bus_message_unref(m);
-}
-
-#else
-
-void logind_init(void)
-{
- fprintf(stderr, "warning: compiled without logind support.\n");
-}
-
-bool use_logind(void)
-{
- return false;
-}
-
-int logind_open(const char *path)
-{
- errno = ENOSYS;
- return -1;
-}
-
-void logind_close(int fd)
-{
-}
-
-#endif
-
-/* ---------------------------------------------------------------------- */
-
int libinput_devcount;
int libinput_deverror;
@@ -357,15 +201,6 @@ static int open_restricted(const char *path, int flags, void *user_data)
{
int fd;
- if (use_logind()) {
- fd = logind_open(path);
- if (fd < 0)
- libinput_deverror++;
- else
- libinput_devcount++;
- return fd;
- }
-
fd = open(path, flags | O_CLOEXEC);
if (fd < 0) {
fprintf(stderr, "kbd: open %s: %s\n", path, strerror(errno));
@@ -381,18 +216,12 @@ static int open_restricted(const char *path, int flags, void *user_data)
static void close_restricted(int fd, void *user_data)
{
- if (use_logind()) {
- logind_close(fd);
- libinput_devcount--;
- return;
- }
-
ioctl(fd, EVIOCGRAB, 0);
close(fd);
libinput_devcount--;
}
-const struct libinput_interface libinput_interface = {
+const struct libinput_interface libinput_if_default = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
@@ -412,7 +241,7 @@ void kbd_init(int use_libinput, dev_t gfx)
seat = udev_device_get_property_value(ugfx, "ID_SEAT");
if (!seat)
seat = "seat0";
- ctx = libinput_udev_create_context(&libinput_interface, NULL, udev);
+ ctx = libinput_udev_create_context(&libinput_if_default, NULL, udev);
libinput_udev_assign_seat(ctx, seat);
fprintf(stderr, "kbd: using libinput (%d devices, %s)\n",
libinput_devcount, seat);