[PATCH weston] compositor: don't have the backend libraries switch vt

Giulio Camuffo giuliocamuffo at gmail.com
Tue Mar 3 11:21:32 PST 2015


A compositor may want to handle the vt switches itself, for example
to ensure to have a lock screen before switching. To enable that move
the key bindings for the vt switch in the common weston code and add
a generic API in libweston to switch vt.
---
 Makefile.am            |  2 +-
 src/compositor-drm.c   | 14 --------------
 src/compositor-fbdev.c | 14 --------------
 src/compositor.c       |  1 +
 src/compositor.h       | 27 +++++++++++++++++++++++++++
 src/launcher-util.c    | 13 ++++++++++++-
 src/launcher-util.h    |  3 ---
 src/weston.c           | 15 +++++++++++++++
 8 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 5cf8a30..e4acd89 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,7 +50,7 @@ lib_LTLIBRARIES = libweston.la
 libweston_la_CPPFLAGS = $(AM_CPPFLAGS) -DIN_WESTON
 libweston_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS) $(LIBUNWIND_CFLAGS)
 libweston_la_LIBADD = $(COMPOSITOR_LIBS) $(LIBUNWIND_LIBS) \
-	$(DLOPEN_LIBS) -lm libshared.la
+	$(DLOPEN_LIBS) -lm libshared.la libsession-helper.la
 libweston_la_LDFLAGS = -release $(abi_version)
 
 libweston_la_SOURCES =           			\
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index d41c9cf..6bcf85b 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -2402,14 +2402,6 @@ session_notify(struct wl_listener *listener, void *data)
 	};
 }
 
-static void
-switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
-{
-	struct weston_compositor *compositor = data;
-
-	weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
-}
-
 /*
  * Find primary GPU
  * Some systems may have multiple DRM devices attached to a single seat. This
@@ -2648,7 +2640,6 @@ drm_backend_create(struct weston_compositor *compositor,
 	struct udev_device *drm_device;
 	struct wl_event_loop *loop;
 	const char *path;
-	uint32_t key;
 
 	weston_log("initializing drm backend\n");
 
@@ -2711,11 +2702,6 @@ drm_backend_create(struct weston_compositor *compositor,
 
 	b->prev_state = WESTON_COMPOSITOR_ACTIVE;
 
-	for (key = KEY_F1; key < KEY_F9; key++)
-		weston_compositor_add_key_binding(compositor, key,
-						  MODIFIER_CTRL | MODIFIER_ALT,
-						  switch_vt_binding, compositor);
-
 	wl_list_init(&b->sprite_list);
 	create_sprites(b);
 
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
index 8d3185e..88585c5 100644
--- a/src/compositor-fbdev.c
+++ b/src/compositor-fbdev.c
@@ -857,21 +857,12 @@ fbdev_restore(struct weston_compositor *compositor)
 	weston_launcher_restore(compositor->launcher);
 }
 
-static void
-switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
-{
-	struct weston_compositor *compositor = data;
-
-	weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
-}
-
 static struct fbdev_backend *
 fbdev_backend_create(struct weston_compositor *compositor,
                      struct fbdev_parameters *param)
 {
 	struct fbdev_backend *backend;
 	const char *seat_id = default_seat;
-	uint32_t key;
 
 	weston_log("initializing fbdev backend\n");
 
@@ -908,11 +899,6 @@ fbdev_backend_create(struct weston_compositor *compositor,
 	backend->prev_state = WESTON_COMPOSITOR_ACTIVE;
 	backend->use_pixman = !param->use_gl;
 
-	for (key = KEY_F1; key < KEY_F9; key++)
-		weston_compositor_add_key_binding(compositor, key,
-		                                  MODIFIER_CTRL | MODIFIER_ALT,
-		                                  switch_vt_binding,
-		                                  compositor);
 	if (backend->use_pixman) {
 		if (pixman_renderer_init(compositor) < 0)
 			goto out_launcher;
diff --git a/src/compositor.c b/src/compositor.c
index 6d11144..b27f0e0 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -51,6 +51,7 @@
 #include "timeline.h"
 
 #include "compositor.h"
+#include "launcher-util.h"
 #include "scaler-server-protocol.h"
 #include "presentation_timing-server-protocol.h"
 #include "../shared/os-compatibility.h"
diff --git a/src/compositor.h b/src/compositor.h
index af34290..24a4567 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1221,6 +1221,33 @@ void
 weston_compositor_set_default_pointer_grab(struct weston_compositor *compositor,
 			const struct weston_pointer_grab_interface *interface);
 
+/**
+ * Request a vt switch for the compositor.
+ *
+ * \param launcher The launcher helper used by the compositor
+ * \param vt The vt to switch to
+ *
+ * Returns 0 on success, -1 otherwise.
+ *
+ * \sa weston_launcher_get_vt
+ * \sa weston_compositor.launcher
+ */
+int
+weston_launcher_activate_vt(struct weston_launcher *launcher, int vt);
+
+/**
+ * Get the vt the compositor is running on.
+ *
+ * \param launcher The launcher helper used by the compositor
+ *
+ * Returns the number of the vt on success, -1 otherwise.
+ *
+ * \sa weston_launcher_activate_vt
+ * \sa weston_compositor.launcher
+ */
+int
+weston_launcher_get_vt(struct weston_launcher *launcher);
+
 int
 weston_environment_get_fd(const char *env);
 
diff --git a/src/launcher-util.c b/src/launcher-util.c
index e89710b..fdec610 100644
--- a/src/launcher-util.c
+++ b/src/launcher-util.c
@@ -375,7 +375,7 @@ setup_tty(struct weston_launcher *launcher, int tty)
 	return -1;
 }
 
-int
+WL_EXPORT int
 weston_launcher_activate_vt(struct weston_launcher *launcher, int vt)
 {
 	if (launcher->logind)
@@ -454,3 +454,14 @@ weston_launcher_destroy(struct weston_launcher *launcher)
 
 	free(launcher);
 }
+
+WL_EXPORT int
+weston_launcher_get_vt(struct weston_launcher *launcher)
+{
+	struct stat s;
+	if (fstat(launcher->tty, &s) < 0)
+		return -1;
+
+	return minor(s.st_rdev);
+}
+
diff --git a/src/launcher-util.h b/src/launcher-util.h
index a60f8a1..497d801 100644
--- a/src/launcher-util.h
+++ b/src/launcher-util.h
@@ -43,9 +43,6 @@ weston_launcher_open(struct weston_launcher *launcher,
 void
 weston_launcher_close(struct weston_launcher *launcher, int fd);
 
-int
-weston_launcher_activate_vt(struct weston_launcher *launcher, int vt);
-
 void
 weston_launcher_restore(struct weston_launcher *launcher);
 
diff --git a/src/weston.c b/src/weston.c
index f1a4351..be98a23 100644
--- a/src/weston.c
+++ b/src/weston.c
@@ -948,6 +948,14 @@ weston_transform_to_string(uint32_t output_transform)
 }
 
 static void
+switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *data)
+{
+	struct weston_compositor *compositor = data;
+
+	weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
+}
+
+static void
 handle_terminate(struct weston_compositor *c)
 {
 	wl_display_terminate(c->wl_display);
@@ -976,6 +984,7 @@ int main(int argc, char *argv[])
 	int32_t version = 0;
 	int32_t noconfig = 0;
 	int32_t numlock_on;
+	uint32_t key;
 	struct weston_config *config = NULL;
 	struct weston_config_section *section;
 	struct wl_client *primary_client;
@@ -1079,6 +1088,12 @@ int main(int argc, char *argv[])
 		goto out_signals;
 	}
 
+	if (ec->launcher) {
+		for (key = KEY_F1; key < KEY_F9; key++)
+			weston_compositor_add_key_binding(ec, key,
+							MODIFIER_CTRL | MODIFIER_ALT,
+							switch_vt_binding, ec);
+	}
 	catch_signals();
 	segv_compositor = ec;
 
-- 
2.3.1



More information about the wayland-devel mailing list