[PATCH weston v3 1/2] launcher: don't try to switch to weston's vt

Giulio Camuffo giuliocamuffo at gmail.com
Mon Dec 5 13:50:36 UTC 2016


Signed-off-by: Giulio Camuffo <giuliocamuffo at gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---

v3: changed the summary to say "weston's vt" instead of "current vt"

 libweston/launcher-direct.c        | 12 ++++++++++++
 libweston/launcher-impl.h          |  2 ++
 libweston/launcher-logind.c        |  8 ++++++++
 libweston/launcher-util.c          |  7 ++++++-
 libweston/launcher-weston-launch.c | 12 ++++++++++++
 5 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/libweston/launcher-direct.c b/libweston/launcher-direct.c
index 29d9c28..0ff99a4 100644
--- a/libweston/launcher-direct.c
+++ b/libweston/launcher-direct.c
@@ -305,6 +305,17 @@ launcher_direct_destroy(struct weston_launcher *launcher_base)
 	free(launcher);
 }
 
+static int
+launcher_direct_get_vt(struct weston_launcher *base)
+{
+	struct launcher_direct *launcher = wl_container_of(base, launcher, base);
+	struct stat s;
+	if (fstat(launcher->tty, &s) < 0)
+		return -1;
+
+	return minor(s.st_rdev);
+}
+
 struct launcher_interface launcher_direct_iface = {
 	launcher_direct_connect,
 	launcher_direct_destroy,
@@ -312,4 +323,5 @@ struct launcher_interface launcher_direct_iface = {
 	launcher_direct_close,
 	launcher_direct_activate_vt,
 	launcher_direct_restore,
+	launcher_direct_get_vt,
 };
diff --git a/libweston/launcher-impl.h b/libweston/launcher-impl.h
index 742721b..8d09025 100644
--- a/libweston/launcher-impl.h
+++ b/libweston/launcher-impl.h
@@ -34,6 +34,8 @@ struct launcher_interface {
 	void (* close) (struct weston_launcher *launcher, int fd);
 	int (* activate_vt) (struct weston_launcher *launcher, int vt);
 	void (* restore) (struct weston_launcher *launcher);
+	/* Get the number of the VT weston is running in */
+	int (* get_vt) (struct weston_launcher *launcher);
 };
 
 struct weston_launcher {
diff --git a/libweston/launcher-logind.c b/libweston/launcher-logind.c
index 8d5e8f9..8b984a6 100644
--- a/libweston/launcher-logind.c
+++ b/libweston/launcher-logind.c
@@ -830,6 +830,13 @@ launcher_logind_destroy(struct weston_launcher *launcher)
 	free(wl);
 }
 
+static int
+launcher_logind_get_vt(struct weston_launcher *launcher)
+{
+	struct launcher_logind *wl = wl_container_of(launcher, wl, base);
+	return wl->vtnr;
+}
+
 struct launcher_interface launcher_logind_iface = {
 	launcher_logind_connect,
 	launcher_logind_destroy,
@@ -837,4 +844,5 @@ struct launcher_interface launcher_logind_iface = {
 	launcher_logind_close,
 	launcher_logind_activate_vt,
 	launcher_logind_restore,
+	launcher_logind_get_vt,
 };
diff --git a/libweston/launcher-util.c b/libweston/launcher-util.c
index 4abd1e2..2b828be 100644
--- a/libweston/launcher-util.c
+++ b/libweston/launcher-util.c
@@ -98,8 +98,13 @@ switch_vt_binding(struct weston_keyboard *keyboard,
 		  uint32_t time, uint32_t key, void *data)
 {
 	struct weston_compositor *compositor = data;
+	struct weston_launcher *launcher = compositor->launcher;
+	int vt = key - KEY_F1 + 1;
 
-	weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1);
+	if (vt == launcher->iface->get_vt(launcher))
+		return;
+
+	weston_launcher_activate_vt(launcher, vt);
 }
 
 WL_EXPORT void
diff --git a/libweston/launcher-weston-launch.c b/libweston/launcher-weston-launch.c
index f3e3a24..2c9128c 100644
--- a/libweston/launcher-weston-launch.c
+++ b/libweston/launcher-weston-launch.c
@@ -276,6 +276,17 @@ launcher_weston_launch_destroy(struct weston_launcher *launcher_base)
 	free(launcher);
 }
 
+static int
+launcher_weston_launch_get_vt(struct weston_launcher *base)
+{
+	struct launcher_weston_launch *launcher = wl_container_of(base, launcher, base);
+	struct stat s;
+	if (fstat(launcher->tty, &s) < 0)
+		return -1;
+
+	return minor(s.st_rdev);
+}
+
 struct launcher_interface launcher_weston_launch_iface = {
 	launcher_weston_launch_connect,
 	launcher_weston_launch_destroy,
@@ -283,4 +294,5 @@ struct launcher_interface launcher_weston_launch_iface = {
 	launcher_weston_launch_close,
 	launcher_weston_launch_activate_vt,
 	launcher_weston_launch_restore,
+	launcher_weston_launch_get_vt,
 };
-- 
2.10.2



More information about the wayland-devel mailing list