aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fbcon.c2
-rw-r--r--logind.c101
-rw-r--r--logind.h2
-rw-r--r--meson.build5
-rw-r--r--vttest.c67
5 files changed, 163 insertions, 14 deletions
diff --git a/fbcon.c b/fbcon.c
index ef5743c..d9b208e 100644
--- a/fbcon.c
+++ b/fbcon.c
@@ -600,7 +600,7 @@ int main(int argc, char *argv[])
if (xdg_seat)
seat_name = xdg_seat;
if (xdg_seat && xdg_session_id) {
- if (logind_init() == 0) {
+ if (logind_init(true) == 0) {
dbus = logind_dbus_fd();
logind = true;
}
diff --git a/logind.c b/logind.c
index 9e64013..fa24398 100644
--- a/logind.c
+++ b/logind.c
@@ -24,8 +24,71 @@
/* ---------------------------------------------------------------------- */
static sd_bus *logind_dbus = NULL;
+static sd_bus_slot *logind_signals;
-int logind_init(void)
+static int logind_prop_cb(sd_bus_message *m, void *data, sd_bus_error *ret_err)
+{
+ const char *intf, *prop, *unused;
+ bool active;
+ char type;
+ int err;
+
+ fprintf(stderr, "%s: %s\n", __func__,
+ sd_bus_message_get_path(m));
+
+ err = sd_bus_message_read(m, "s", &intf);
+ if (err < 0)
+ return err;
+
+ err = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
+ while ((err = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
+ err = sd_bus_message_read(m, "s", &prop);
+ if (err < 0)
+ return err;
+ err = sd_bus_message_peek_type(m, &type, &unused);
+ if (err < 0)
+ return err;
+ /* Need to enter the variant, regarless we want it or not */
+ err = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, unused);
+ if (err < 0)
+ return err;
+ if (strcmp(prop, "Active") == 0) {
+ err = sd_bus_message_read(m, "b", &active);
+ if (err < 0)
+ return err;
+ printf(" Property: %s=%d\n", prop, active);
+ } 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);
+ if (err < 0)
+ return err;
+ /* dict entry */
+ err = sd_bus_message_exit_container(m);
+ if (err < 0)
+ return err;
+ }
+ /* array */
+ err = sd_bus_message_exit_container(m);
+ if (err < 0)
+ return err;
+ return 0;
+}
+
+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));
+
+ return 0;
+}
+
+int logind_init(bool take_control)
{
int r;
@@ -35,13 +98,31 @@ int logind_init(void)
return -1;
}
- r = logind_take_control();
- if (r < 0) {
- sd_bus_unref(logind_dbus);
- logind_dbus = NULL;
- return -1;
+ if (take_control) {
+ r = logind_take_control();
+ if (r < 0) {
+ sd_bus_unref(logind_dbus);
+ logind_dbus = NULL;
+ return -1;
+ }
}
+ sd_bus_match_signal(logind_dbus, &logind_signals,
+ "org.freedesktop.login1",
+ NULL,
+ NULL,
+ "PropertiesChanged",
+ logind_prop_cb,
+ NULL);
+
+ sd_bus_match_signal(logind_dbus, &logind_signals,
+ "org.freedesktop.login1",
+ NULL,
+ "org.freedesktop.login1.Session",
+ NULL,
+ logind_session_cb,
+ NULL);
+
fprintf(stderr, "Opening input devices via logind.\n");
return 0;
}
@@ -55,17 +136,13 @@ int logind_dbus_fd(void)
void logind_dbus_input(void)
{
- sd_bus_message *m = NULL;
int ret;
if (!logind_dbus)
return;
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);
+ ret = sd_bus_process(logind_dbus, NULL);
} while (ret > 0);
}
@@ -242,7 +319,7 @@ void logind_close(int fd, void *user_data)
/* ---------------------------------------------------------------------- */
-int logind_init(void)
+int logind_init(bool take_control)
{
fprintf(stderr, "warning: compiled without logind support.\n");
return -1;
diff --git a/logind.h b/logind.h
index 89c4c0c..e95b361 100644
--- a/logind.h
+++ b/logind.h
@@ -6,7 +6,7 @@
extern const struct libinput_interface libinput_if_logind;
-int logind_init(void);
+int logind_init(bool take_control);
int logind_dbus_fd(void);
void logind_dbus_input(void);
int logind_switch_vt(int vt);
diff --git a/meson.build b/meson.build
index 7da73ba..e8239de 100644
--- a/meson.build
+++ b/meson.build
@@ -151,6 +151,11 @@ executable('kbdtest',
sources : [ 'kbdtest.c', 'kbd.c' ],
dependencies : [ udev_dep, input_dep, systemd_dep ] )
+# build vttest
+executable('vttest',
+ sources : [ 'vttest.c', 'kbd.c', 'logind.c' ],
+ dependencies : [ udev_dep, input_dep, systemd_dep ] )
+
# build ida
mkfallback = find_program('scripts/fallback.pl')
hexify = find_program('scripts/hexify.sh')
diff --git a/vttest.c b/vttest.c
new file mode 100644
index 0000000..2de51c8
--- /dev/null
+++ b/vttest.c
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <inttypes.h>
+#include <time.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <errno.h>
+#include <termios.h>
+
+#include "logind.h"
+
+/* ---------------------------------------------------------------------- */
+
+int main(int argc, char *argv[])
+{
+ const char *xdg_seat, *xdg_session_id;
+ int dbus;
+
+ xdg_seat = getenv("XDG_SEAT");
+ xdg_session_id = getenv("XDG_SESSION_ID");
+ if (!xdg_seat || !xdg_session_id) {
+ fprintf(stderr, "session id or seat not found\n");
+ exit(1);
+ }
+
+ fprintf(stderr, "session %s at %s\n",
+ xdg_session_id, xdg_seat);
+ if (logind_init(false) != 0) {
+ fprintf(stderr, "logind init failed\n");
+ exit(1);
+ }
+ dbus = logind_dbus_fd();
+
+#if 0
+ logind_open("/dev/dri/card0", 0, NULL);
+
+ const char *xdg_vtnr = getenv("XDG_VTNR");
+ if (xdg_vtnr) {
+ int vt = atoi(xdg_vtnr);
+ vt++;
+ fprintf(stderr, "switch to vt %d\n", vt);
+ logind_switch_vt(vt);
+ }
+#endif
+
+ for (;;) {
+ fd_set set;
+ int rc, max;
+
+ max = 0;
+ FD_ZERO(&set);
+ FD_SET(dbus, &set);
+ if (max < dbus)
+ max = dbus;
+
+ rc = select(max+ 1, &set, NULL, NULL, NULL);
+ if (rc < 0)
+ break;
+
+ if (FD_ISSET(dbus, &set)) {
+ logind_dbus_input();
+ }
+ }
+ return 0;
+}