From 446ead14577cf943459b5d29dee88a3b8c26abcc Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 4 Mar 2019 09:55:43 +0100 Subject: logind improvements --- fbcon.c | 18 +++++++++++++++--- logind.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- logind.h | 3 +++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/fbcon.c b/fbcon.c index 2f2f99f..d795b9f 100644 --- a/fbcon.c +++ b/fbcon.c @@ -521,7 +521,7 @@ int main(int argc, char *argv[]) const char *fb_node = NULL; const char *xdg_seat, *xdg_session_id; bool logind = false; - int input; + int input, dbus; pid_t child; setlocale(LC_ALL,""); @@ -531,9 +531,12 @@ int main(int argc, char *argv[]) xdg_session_id = getenv("XDG_SESSION_ID"); if (xdg_seat) seat_name = xdg_seat; - if (xdg_seat && xdg_session_id) - if (logind_init() == 0) + if (xdg_seat && xdg_session_id) { + if (logind_init() == 0) { + dbus = logind_dbus_fd(); logind = true; + } + } /* look for gfx devices */ udev = udev_new(); @@ -656,6 +659,11 @@ int main(int argc, char *argv[]) FD_SET(input, &set); if (max < input) max = input; + if (logind) { + FD_SET(dbus, &set); + if (max < dbus) + max = dbus; + } rc = select(max+ 1, &set, NULL, NULL, NULL); if (rc < 0) @@ -701,6 +709,10 @@ int main(int argc, char *argv[]) libinput_event_destroy(evt); } } + + if (logind && FD_ISSET(dbus, &set)) { + logind_dbus_input(); + } } cleanup_and_exit(0); diff --git a/logind.c b/logind.c index b426609..6388df1 100644 --- a/logind.c +++ b/logind.c @@ -46,6 +46,24 @@ int logind_init(void) return 0; } +int logind_dbus_fd(void) +{ + return sd_bus_get_fd(logind_dbus); +} + +void logind_dbus_input(void) +{ + sd_bus_message *m = NULL; + int ret; + + do { + ret = sd_bus_process(logind_dbus, &m); + fprintf(stderr, "%s: path %s\n", __func__, + sd_bus_message_get_path(m)); + sd_bus_message_unref(m); + } while (ret > 0); +} + int logind_take_control(void) { sd_bus_error error = SD_BUS_ERROR_NULL; @@ -70,6 +88,29 @@ int logind_take_control(void) return r; } +int logind_release_control(void) +{ + sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus_message *m = NULL; + int r; + + r = sd_bus_call_method(logind_dbus, + "org.freedesktop.login1", + "/org/freedesktop/login1/session/self", + "org.freedesktop.login1.Session", + "ReleaseControl", + &error, + &m, + ""); + if (r < 0) { + fprintf(stderr, "ReleaseControl failed: %s\n", error.message); + sd_bus_error_free(&error); + } + sd_bus_message_unref(m); + + return r; +} + int logind_open(const char *path, int flags, void *user_data) { sd_bus_error error = SD_BUS_ERROR_NULL; @@ -169,6 +210,15 @@ int logind_init(void) return -1; } +int logind_dbus_fd(void) +{ + return -1; +} + +void logind_dbus_input(void) +{ +} + int logind_take_control(void) { return -1; @@ -178,7 +228,6 @@ int logind_open(const char *path, int flags, void *user_data) { fprintf(stderr, "error: compiled without logind support.\n"); libinput_deverror++; - errno = ENOSYS; return -1; } diff --git a/logind.h b/logind.h index 6aca13c..e36a329 100644 --- a/logind.h +++ b/logind.h @@ -7,6 +7,9 @@ extern const struct libinput_interface libinput_if_logind; int logind_init(void); +int logind_dbus_fd(void); +void logind_dbus_input(void); int logind_take_control(void); +int logind_release_control(void); int logind_open(const char *path, int flags, void *user_data); void logind_close(int fd, void *user_data); -- cgit