Skip to content

Commit fb09d0a

Browse files
lianzhi changgregkh
authored andcommitted
tty: Fix the keyboard led light display problem
Use the "ctrl+alt+Fn" key combination to switch the system from tty to desktop or switch the system from desktop to tty. After the switch is completed, it is found that the state of the keyboard lock is inconsistent with the state of the keyboard Led light.The reasons are as follows: * The desktop environment (Xorg and other services) is bound to a tty (assuming it is tty1), and the kb->kbdmode attribute value of tty1 will be set to VC_OFF. According to the current code logic, in the desktop environment, the values of ledstate and kb->ledflagstate of tty1 will not be modified anymore, so they are always 0. * When switching between each tty, the final value of ledstate set by the previous tty is compared with the kb->ledflagstate value of the current tty to determine whether to set the state of the keyboard light. The process of switching between desktop and tty is also the process of switching between tty1 and other ttys. There are two situations: - (1) In the desktop environment, tty1 will not set the ledstate, which will cause when switching from the desktop to other ttys, if the desktop lights up the keyboard's led, after the switch is completed, the keyboard's led light will always be on; - (2) When switching from another tty to the desktop, this mechanism will trigger tty1 to set the led state. If other tty lights up the led of the keyboard before switching to the desktop, the led will be forcibly turned off. This situation should be avoided. * The current patch is to solve these problems: When VT is switched, the keyboard led needs to be set once.Ensure that after the switch is completed, the state of the keyboard LED is consistent with the state of the keyboard lock. Suggested-by: Dmitry Torokhov <[email protected]> Reviewed-by: Dmitry Torokhov <[email protected]> Signed-off-by: lianzhi chang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 34de666 commit fb09d0a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/tty/vt/keyboard.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static int shift_state = 0;
153153

154154
static unsigned int ledstate = -1U; /* undefined */
155155
static unsigned char ledioctl;
156+
static bool vt_switch;
156157

157158
/*
158159
* Notifier list for console keyboard events
@@ -414,6 +415,12 @@ void vt_set_leds_compute_shiftstate(void)
414415
{
415416
unsigned long flags;
416417

418+
/*
419+
* When VT is switched, the keyboard led needs to be set once.
420+
* Ensure that after the switch is completed, the state of the
421+
* keyboard LED is consistent with the state of the keyboard lock.
422+
*/
423+
vt_switch = true;
417424
set_leds();
418425

419426
spin_lock_irqsave(&kbd_event_lock, flags);
@@ -1255,6 +1262,11 @@ static void kbd_bh(struct tasklet_struct *unused)
12551262
leds |= (unsigned int)kbd->lockstate << 8;
12561263
spin_unlock_irqrestore(&led_lock, flags);
12571264

1265+
if (vt_switch) {
1266+
ledstate = ~leds;
1267+
vt_switch = false;
1268+
}
1269+
12581270
if (leds != ledstate) {
12591271
kbd_propagate_led_state(ledstate, leds);
12601272
ledstate = leds;

0 commit comments

Comments
 (0)