lkml.org 
[lkml]   [2021]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v7] tty: Fix the keyboard led light display problem
On Tue, Oct 26, 2021 at 11:41:17PM +0800, 常廉志 wrote:
> On Tue, Oct 26, 2021 at 05:23:35PM +0300, Andy Shevchenko wrote:
> > On Tue, Oct 26, 2021 at 10:40:32AM +0800, lianzhi chang wrote:
> > > Switching from the desktop environment to the tty environment,
> > > the state of the keyboard led lights and the state of the keyboard
> > > lock are inconsistent. This is because the attribute kb->kbdmode
> > > of the tty bound in the desktop environment (xorg) is set to
> >
> > Xorg
> >
> > I think I already pointed that out.
> >
> > > VC_OFF, which causes the ledstate and kb->ledflagstate
> > > values of the bound tty to always be 0, which causes the switch
> > > from the desktop When to the tty environment, the LED light
> > > status is inconsistent with the keyboard lock status.
> >
> > ...
> >
> > > +static void kbd_update_ledstate(struct input_dev *dev)
> > > +{
> > > + if (!!test_bit(LED_NUML, dev->led) !=
> > > + !!(ledstate & BIT(VC_NUMLOCK)))
> > > + ledstate ^= BIT(VC_NUMLOCK);
> > > + if (!!test_bit(LED_CAPSL, dev->led) !=
> > > + !!(ledstate & BIT(VC_CAPSLOCK)))
> > > + ledstate ^= BIT(VC_CAPSLOCK);
> > > + if (!!test_bit(LED_SCROLLL, dev->led) !=
> > > + !!(ledstate & BIT(VC_SCROLLOCK)))
> > > + ledstate ^= BIT(VC_SCROLLOCK);
> >
> > This looks ugly.
>
> I think it can be done like this:
> static void kbd_update_ledstate(struct input_dev *dev)
> {
> ledstate = (test_bit(LED_SCROLL,dev->led) ?1 :0)
> | (test_bit(LED_NUML,dev->led) ?2 :0)
> | (test_bit(LED_CAPSL,dev->led) ?3 :0)
> }

Please write code for developers to read first, and compilers second.
That ? : stuff is a mess, do not do that.

thanks,

greg k-h

\
 
 \ /
  Last update: 2021-10-26 17:58    [W:0.356 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site