Blob Blame History Raw
From cabcd21c17ca98e517a3eea7c9d5ce269445e3e0 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 31 Aug 2018 15:46:55 -0400
Subject: [PATCH 25/51] session-worker: clear VT before jumping to it

If we're going to jump to a new VT we should make sure it's free
of residual console text.  That way if there's flicker the user
will be less likely to notice it.

This commit sends a clear screen escape sequence to the tty
before jumping to it.
---
 daemon/gdm-session-worker.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index 391969d96..7ed2789da 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -943,60 +943,67 @@ fix_terminal_vt_mode (GdmSessionWorker  *worker,
         }
 
         /* VT is in the anti-social state of VT_AUTO + KD_GRAPHICS,
          * fix it.
          */
         succeeded = handle_terminal_vt_switches (worker, tty_fd);
         mode_fixed = TRUE;
 out:
         if (!succeeded) {
                 g_error ("GdmSessionWorker: couldn't set up terminal, aborting...");
                 return;
         }
 
         g_debug ("GdmSessionWorker: VT mode did %sneed to be fixed",
                  mode_fixed? "" : "not ");
 }
 
 static void
 jump_to_vt (GdmSessionWorker  *worker,
             int                vt_number)
 {
         int fd;
         int active_vt_tty_fd;
         int active_vt = -1;
         struct vt_stat vt_state = { 0 };
 
         g_debug ("GdmSessionWorker: jumping to VT %d", vt_number);
         active_vt_tty_fd = open ("/dev/tty0", O_RDWR | O_NOCTTY);
 
         if (worker->priv->session_tty_fd != -1) {
+                static const char *clear_screen_escape_sequence = "\33[H\33[2J";
+
+                /* let's make sure the new VT is clear */
+                write (worker->priv->session_tty_fd,
+                       clear_screen_escape_sequence,
+                       sizeof (clear_screen_escape_sequence));
+
                 fd = worker->priv->session_tty_fd;
 
                 g_debug ("GdmSessionWorker: first setting graphics mode to prevent flicker");
                 if (ioctl (fd, KDSETMODE, KD_GRAPHICS) < 0) {
                         g_debug ("GdmSessionWorker: couldn't set graphics mode: %m");
                 }
 
                 /* It's possible that the current VT was left in a broken
                  * combination of states (KD_GRAPHICS with VT_AUTO), that
                  * can't be switched away from.  This call makes sure things
                  * are set in a way that VT_ACTIVATE should work and
                  * VT_WAITACTIVE shouldn't hang.
                  */
                 fix_terminal_vt_mode (worker, active_vt_tty_fd);
         } else {
                 fd = active_vt_tty_fd;
         }
 
         handle_terminal_vt_switches (worker, fd);
 
         if (ioctl (fd, VT_GETSTATE, &vt_state) < 0) {
                 g_debug ("GdmSessionWorker: couldn't get current VT: %m");
         } else {
                 active_vt = vt_state.v_active;
         }
 
         if (active_vt != vt_number) {
                 if (ioctl (fd, VT_ACTIVATE, vt_number) < 0) {
                         g_debug ("GdmSessionWorker: couldn't initiate jump to VT %d: %m",
                                  vt_number);
-- 
2.27.0