chiark / gitweb /
terminal: add sysview_seat_switch_to()
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 29 Sep 2014 12:59:01 +0000 (14:59 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 29 Sep 2014 13:37:31 +0000 (15:37 +0200)
Add helper to perform session switches on a specific seat whenever we
retrieve a VT-switch keyboard event.

src/libsystemd-terminal/sysview-internal.h
src/libsystemd-terminal/sysview.c
src/libsystemd-terminal/sysview.h

index d9f7fe3..39ff933 100644 (file)
@@ -88,6 +88,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_session*, sysview_session_free);
 struct sysview_seat {
         sysview_context *context;
         char *name;
+        char *path;
 
         Hashmap *session_map;
         Hashmap *device_map;
index cd776f6..919fadf 100644 (file)
@@ -391,6 +391,10 @@ int sysview_seat_new(sysview_seat **out, sysview_context *c, const char *name) {
         if (!seat->name)
                 return -ENOMEM;
 
+        r = sd_bus_path_encode("/org/freedesktop/login1/seat", seat->name, &seat->path);
+        if (r < 0)
+                return r;
+
         seat->session_map = hashmap_new(&string_hash_ops);
         if (!seat->session_map)
                 return -ENOMEM;
@@ -422,6 +426,7 @@ sysview_seat *sysview_seat_free(sysview_seat *seat) {
 
         hashmap_free(seat->device_map);
         hashmap_free(seat->session_map);
+        free(seat->path);
         free(seat->name);
         free(seat);
 
@@ -434,6 +439,29 @@ const char *sysview_seat_get_name(sysview_seat *seat) {
         return seat->name;
 }
 
+int sysview_seat_switch_to(sysview_seat *seat, uint32_t nr) {
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+        int r;
+
+        assert_return(seat, -EINVAL);
+        assert_return(seat->context->sysbus, -EINVAL);
+
+        r = sd_bus_message_new_method_call(seat->context->sysbus,
+                                           &m,
+                                           "org.freedesktop.login1",
+                                           seat->path,
+                                           "org.freedesktop.login1.Seat",
+                                           "SwitchTo");
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_append(m, "u", nr);
+        if (r < 0)
+                return r;
+
+        return sd_bus_send(seat->context->sysbus, m, NULL);
+}
+
 /*
  * Contexts
  */
index f691e49..31b800f 100644 (file)
@@ -137,6 +137,7 @@ void sysview_session_release_control(sysview_session *session);
  */
 
 const char *sysview_seat_get_name(sysview_seat *seat);
+int sysview_seat_switch_to(sysview_seat *seat, uint32_t nr);
 
 /*
  * Contexts