diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-03-27 13:33:49 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-03-27 13:33:49 +0100 |
commit | 59ca05ee1a59c5298767cf9563ef7f92ec895936 (patch) | |
tree | 6b0e8eecb498f7c01f4ae7bff540ee5e175c2451 | |
parent | e772b065d85445049854d806cd06943dbd58d619 (diff) | |
download | fbida-59ca05ee1a59c5298767cf9563ef7f92ec895936.tar.gz |
[wip still] more logind console switching
-rw-r--r-- | fbcon.c | 18 | ||||
-rw-r--r-- | logind.c | 98 | ||||
-rw-r--r-- | logind.h | 4 | ||||
-rw-r--r-- | vttest.c | 2 |
4 files changed, 96 insertions, 26 deletions
@@ -446,18 +446,13 @@ static void fbcon_handle_keydown(struct xkb_state *state, return; } -#if 0 /* WIP & broken */ - if (logind && ctrlalt) { - if (sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - int vt = sym - XKB_KEY_F1 + 1; - fprintf(stderr, "console switch to vt %d\n", vt); - console_switch_suspend(); - logind_switch_vt(vt); - return; - } + if (logind && sym >= XKB_KEY_XF86Switch_VT_1 && sym <= XKB_KEY_XF86Switch_VT_12) { + int vt = sym - XKB_KEY_XF86Switch_VT_1 + 1; + console_switch_suspend(); + logind_switch_vt(vt); + return; } -#endif /* scrollback */ if (shift && sym == XKB_KEY_Up) { @@ -600,7 +595,8 @@ int main(int argc, char *argv[]) if (xdg_seat) seat_name = xdg_seat; if (xdg_seat && xdg_session_id) { - if (logind_init(true) == 0) { + if (logind_init(true, NULL, + console_switch_resume) == 0) { dbus = logind_dbus_fd(); logind = true; } @@ -26,6 +26,39 @@ static sd_bus *logind_dbus = NULL; static sd_bus_slot *logind_signals; +static void (*session_suspend)(void); +static void (*session_resume)(void); + +/* ---------------------------------------------------------------------- */ + +static void logind_pause_device_complete(unsigned int maj, + unsigned int min) +{ + sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus_message *m = NULL; + int r; + + fprintf(stderr, "call : PauseDeviceComplete(%d,%d)\n", maj, min); + r = sd_bus_call_method(logind_dbus, + "org.freedesktop.login1", + "/org/freedesktop/login1/session/self", + "org.freedesktop.login1.Session", + "PauseDeviceComplete", + &error, + &m, + "uu", + maj, + min); + if (r < 0) { + fprintf(stderr, "error : PauseDeviceComplete failed: %s\n", + error.message); + sd_bus_error_free(&error); + return; + } + + sd_bus_message_unref(m); +} + static int logind_prop_cb(sd_bus_message *m, void *data, sd_bus_error *ret_err) { const char *intf, *prop, *unused; @@ -56,12 +89,22 @@ static int logind_prop_cb(sd_bus_message *m, void *data, sd_bus_error *ret_err) err = sd_bus_message_read(m, "b", &active); if (err < 0) return err; - printf(" Property: %s=%d\n", prop, active); + if (!active) { + fprintf(stderr, "Active off (callback %s)\n", + session_suspend ? "yes" : "no"); + if (session_suspend) + session_suspend(); + } + if (active) { + fprintf(stderr, "Active on (callback %s)\n", + session_resume ? "yes" : "no"); + if (session_resume) + session_resume(); + } } else { err = sd_bus_message_skip(m, unused); if (err < 0) return err; - printf(" Property: %s\n", prop); } /* variant */ err = sd_bus_message_exit_container(m); @@ -81,14 +124,30 @@ static int logind_prop_cb(sd_bus_message *m, void *data, sd_bus_error *ret_err) static int logind_session_cb(sd_bus_message *m, void *data, sd_bus_error *ret_err) { - fprintf(stderr, "%s: %s %s\n", __func__, - sd_bus_message_get_path(m), - sd_bus_message_get_member(m)); + const char *member = sd_bus_message_get_member(m); + const char *type; + unsigned int maj, min; + int r; + + + if (strcmp(member, "PauseDevice") == 0) { + r = sd_bus_message_read(m, "uus", &maj, &min, &type); + if (r < 0) { + fprintf(stderr, "error : parsing PauseDevice msg failed\n"); + return r; + } + fprintf(stderr, "signal : %s(%d,%d,%s)\n", member, maj, min, type); + logind_pause_device_complete(maj, min); + } else { + fprintf(stderr, "signal : %s(...)\n", member); + } return 0; } -int logind_init(bool take_control) +int logind_init(bool take_control, + void (*suspend)(void), + void (*resume)(void)) { int r; @@ -155,6 +214,7 @@ int logind_switch_vt(int vt) if (!logind_dbus) return -1; + fprintf(stderr, "call : SwitchTo(%d)\n", vt); r = sd_bus_call_method(logind_dbus, "org.freedesktop.login1", "/org/freedesktop/login1/seat/self", @@ -165,7 +225,8 @@ int logind_switch_vt(int vt) "u", vt); if (r < 0) { - fprintf(stderr, "SwitchTo failed: %s\n", error.message); + fprintf(stderr, "error : SwitchTo failed: %s\n", + error.message); sd_bus_error_free(&error); } sd_bus_message_unref(m); @@ -182,6 +243,7 @@ int logind_take_control(void) if (!logind_dbus) return -1; + fprintf(stderr, "call : TakeControl()\n"); r = sd_bus_call_method(logind_dbus, "org.freedesktop.login1", "/org/freedesktop/login1/session/self", @@ -192,7 +254,8 @@ int logind_take_control(void) "b", false); if (r < 0) { - fprintf(stderr, "TakeControl failed: %s\n", error.message); + fprintf(stderr, "error : TakeControl failed: %s\n", + error.message); sd_bus_error_free(&error); } sd_bus_message_unref(m); @@ -209,6 +272,7 @@ int logind_release_control(void) if (!logind_dbus) return -1; + fprintf(stderr, "call : ReleaseControl()\n"); r = sd_bus_call_method(logind_dbus, "org.freedesktop.login1", "/org/freedesktop/login1/session/self", @@ -218,7 +282,8 @@ int logind_release_control(void) &m, ""); if (r < 0) { - fprintf(stderr, "ReleaseControl failed: %s\n", error.message); + fprintf(stderr, "error : ReleaseControl failed: %s\n", + error.message); sd_bus_error_free(&error); } sd_bus_message_unref(m); @@ -244,6 +309,7 @@ int logind_open(const char *path, int flags, void *user_data) maj = major(st.st_rdev); min = minor(st.st_rdev); + fprintf(stderr, "call : TakeDevice(%d,%d)\n", maj, min); r = sd_bus_call_method(logind_dbus, "org.freedesktop.login1", "/org/freedesktop/login1/session/self", @@ -255,7 +321,8 @@ int logind_open(const char *path, int flags, void *user_data) maj, min); if (r < 0) { - fprintf(stderr, "TakeDevice failed: %s\n", error.message); + fprintf(stderr, "error : TakeDevice failed: %s\n", + error.message); sd_bus_error_free(&error); libinput_deverror++; return -1; @@ -266,7 +333,8 @@ int logind_open(const char *path, int flags, void *user_data) r = sd_bus_message_read(m, "hb", &handle, &inactive); if (r < 0) { fd = -1; - fprintf(stderr, "Parsing TakeDevice reply failed: %s\n", strerror(-r)); + fprintf(stderr, "error : Parsing TakeDevice reply failed: %s\n", + strerror(-r)); libinput_deverror++; } else { fd = fcntl(handle, F_DUPFD_CLOEXEC, 0); @@ -296,6 +364,7 @@ void logind_close(int fd, void *user_data) maj = major(st.st_rdev); min = minor(st.st_rdev); + fprintf(stderr, "call : ReleaseDevice(%d,%d)\n", maj, min); r = sd_bus_call_method(logind_dbus, "org.freedesktop.login1", "/org/freedesktop/login1/session/self", @@ -307,7 +376,8 @@ void logind_close(int fd, void *user_data) maj, min); if (r < 0) { - fprintf(stderr, "ReleaseDevice failed: %s\n", error.message); + fprintf(stderr, "error : ReleaseDevice failed: %s\n", + error.message); sd_bus_error_free(&error); } sd_bus_message_unref(m); @@ -319,7 +389,9 @@ void logind_close(int fd, void *user_data) /* ---------------------------------------------------------------------- */ -int logind_init(bool take_control) +int logind_init(bool take_control, + void (*suspend)(void), + void (*resume)(void)) { fprintf(stderr, "warning: compiled without logind support.\n"); return -1; @@ -6,7 +6,9 @@ extern const struct libinput_interface libinput_if_logind; -int logind_init(bool take_control); +int logind_init(bool take_control, + void (*suspend)(void), + void (*resume)(void)); int logind_dbus_fd(void); void logind_dbus_input(void); int logind_switch_vt(int vt); @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "session %s at %s\n", xdg_session_id, xdg_seat); - if (logind_init(false) != 0) { + if (logind_init(false, NULL, NULL) != 0) { fprintf(stderr, "logind init failed\n"); exit(1); } |