]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-terminal: Only set keyboard mode when changing it
authorRay Strode <rstrode@redhat.com>
Tue, 2 Jan 2024 03:04:21 +0000 (22:04 -0500)
committerRay Strode <halfline@gmail.com>
Wed, 3 Jan 2024 00:56:10 +0000 (00:56 +0000)
Setting the console keyboard mode is not entirely idempotent.
The kernel may flush the input buffer leading to lost
key strokes. We currently set the mode explicitly on graphics
updates as part of our more general "fix things up in case
something during boot screws with the terminal settings" code.

That leads to keystrokes getting eaten.

This commit makes the terminal more careful about setting the
keyboard mode. It now only changes it when plymouth thinks its
necessary to do so.

In the future we could query the keyboard mode and reset it
when it's wrong, but I think we should hold off on doing that
until shown we need to.

src/libply-splash-core/ply-terminal.c

index 7afdb7542fa064b29b97f65d56b906d45216f414..84ec91eeb4dfe80af0f343ce0c18b1104018f6ee 100644 (file)
@@ -241,13 +241,14 @@ ply_terminal_set_unbuffered_input (ply_terminal_t *terminal)
 
         ply_terminal_unlock (terminal);
 
-        if (terminal->is_disabled)
+        if (terminal->is_disabled) {
                 ply_trace ("terminal input is getting enabled in unbuffered mode");
 
-        terminal->is_disabled = false;
+                if (ply_terminal_is_vt (terminal))
+                        ioctl (terminal->fd, KDSKBMODE, K_UNICODE);
 
-        if (ply_terminal_is_vt (terminal))
-                ioctl (terminal->fd, KDSKBMODE, K_UNICODE);
+                terminal->is_disabled = false;
+        }
 
         tcgetattr (terminal->fd, &term_attributes);
 
@@ -279,13 +280,14 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
 {
         struct termios term_attributes;
 
-        if (terminal->is_disabled)
+        if (terminal->is_disabled) {
                 ply_trace ("terminal input is getting enabled in buffered mode");
 
-        terminal->is_disabled = false;
+                if (ply_terminal_is_vt (terminal))
+                        ioctl (terminal->fd, KDSKBMODE, K_UNICODE);
 
-        if (ply_terminal_is_vt (terminal))
-                ioctl (terminal->fd, KDSKBMODE, K_UNICODE);
+                terminal->is_disabled = false;
+        }
 
         if (!terminal->is_unbuffered)
                 return true;
@@ -330,14 +332,15 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
 bool
 ply_terminal_set_disabled_input (ply_terminal_t *terminal)
 {
-        if (!terminal->is_disabled)
+        if (!terminal->is_disabled) {
                 ply_trace ("terminal input is getting disabled from %s mode",
                            terminal->is_unbuffered? "unbuffered" : "buffered");
 
-        terminal->is_disabled = true;
+                if (ply_terminal_is_vt (terminal))
+                        ioctl (terminal->fd, KDSKBMODE, K_OFF);
 
-        if (ply_terminal_is_vt (terminal))
-                ioctl (terminal->fd, KDSKBMODE, K_OFF);
+                terminal->is_disabled = true;
+        }
 
         return true;
 }