[PATCH v2 keyboard 3/3] Rewrote code to set initial state LEDS
Peter Hutterer
peter.hutterer at who-t.net
Mon Mar 7 19:03:37 PST 2011
On Sun, Feb 20, 2011 at 08:44:06PM +0500, Alexandr Shadchin wrote:
> Saved only initial state CapsLock and NumLock
Please write a more elaborate commit message. this code hasn't been touched
for ages, if you went through the effort of understanding it and writing a
patch, then a few sentences in the commit message (or comments in the code)
could easily be added to make it easier on the next person hacking on this.
> Signed-off-by: Alexandr Shadchin <Alexandr.Shadchin at gmail.com>
> ---
> src/kbd.c | 105 ++++++++++++++++---------------------------------------------
> 1 files changed, 27 insertions(+), 78 deletions(-)
>
> diff --git a/src/kbd.c b/src/kbd.c
> index e0d55e5..2a2a8a8 100644
> --- a/src/kbd.c
> +++ b/src/kbd.c
> @@ -41,13 +41,8 @@
> #include "xkbstr.h"
> #include "xkbsrv.h"
>
> -#define CAPSFLAG 1
> -#define NUMFLAG 2
> -#define SCROLLFLAG 4
> -#define MODEFLAG 8
> -#define COMPOSEFLAG 16
> -/* Used to know when the first DEVICE_ON after a DEVICE_INIT is called */
> -#define INITFLAG (1U << 31)
> +/* Support only 4 LEDS */
> +#define INITFLAG (~(XLED1 | XLED2 | XLED3 | XLED4))
this is a rather unusual definition of a flag, what was wrong with the
original value?
I think XLED1 etc can be moved from the server to this driver, it seems
that's just a leftover from the monolith.
> #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
> static InputInfoPtr KbdPreInit(InputDriverPtr drv, IDevPtr dev, int flags);
> @@ -59,9 +54,6 @@ static void KbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl);
> static void KbdBell(int percent, DeviceIntPtr dev, pointer ctrl, int unused);
> static void PostKbdEvent(InputInfoPtr pInfo, unsigned int key, Bool down);
>
> -static void InitKBD(InputInfoPtr pInfo, Bool init);
> -static void UpdateLeds(InputInfoPtr pInfo);
> -
> _X_EXPORT InputDriverRec KBD = {
> 1,
> "kbd",
> @@ -209,76 +201,19 @@ KbdBell(int percent, DeviceIntPtr dev, pointer ctrl, int unused)
> }
>
> static void
> -UpdateLeds(InputInfoPtr pInfo)
> +KbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl)
> {
> + InputInfoPtr pInfo = (InputInfoPtr) device->public.devicePrivate;
> KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
> - unsigned long leds = 0;
> -
> - if (pKbd->keyLeds & CAPSFLAG) leds |= XLED1;
> - if (pKbd->keyLeds & NUMFLAG) leds |= XLED2;
> - if (pKbd->keyLeds & SCROLLFLAG ||
> - pKbd->keyLeds & MODEFLAG) leds |= XLED3;
> - if (pKbd->keyLeds & COMPOSEFLAG) leds |= XLED4;
> -
> - pKbd->SetLeds(pInfo, leds);
> -}
> -
> -static void
> -KbdCtrl( DeviceIntPtr device, KeybdCtrl *ctrl)
> -{
> - InputInfoPtr pInfo = (InputInfoPtr) device->public.devicePrivate;
> - KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
> -
> - if ( ctrl->leds & XLED1) {
> - pKbd->keyLeds |= CAPSFLAG;
> - } else {
> - pKbd->keyLeds &= ~CAPSFLAG;
> - }
> - if ( ctrl->leds & XLED2) {
> - pKbd->keyLeds |= NUMFLAG;
> - } else {
> - pKbd->keyLeds &= ~NUMFLAG;
> - }
> - if ( ctrl->leds & XLED3) {
> - pKbd->keyLeds |= SCROLLFLAG;
> - } else {
> - pKbd->keyLeds &= ~SCROLLFLAG;
> - }
> - if ( ctrl->leds & (XCOMP|XLED4) ) {
> - pKbd->keyLeds |= COMPOSEFLAG;
> - } else {
> - pKbd->keyLeds &= ~COMPOSEFLAG;
> - }
> - pKbd->SetLeds(pInfo, ctrl->leds);
> -}
>
> -static void
> -InitKBD(InputInfoPtr pInfo, Bool init)
> -{
> - KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
> -
> - pKbd->scanPrefix = 0;
> + if (pKbd->keyLeds & INITFLAG) {
> + pKbd->keyLeds &= (INITFLAG | XLED1 |XLED2);
> + pKbd->keyLeds |= ctrl->leds;
> + } else {
> + pKbd->keyLeds = ctrl->leds;
> + }
>
> - if (init) {
> - pKbd->keyLeds = pKbd->GetLeds(pInfo);
> - UpdateLeds(pInfo);
> - pKbd->keyLeds |= INITFLAG;
> - } else {
> - unsigned long leds = pKbd->keyLeds;
> -
> - pKbd->keyLeds = pKbd->GetLeds(pInfo);
> - UpdateLeds(pInfo);
> - if ((pKbd->keyLeds & CAPSFLAG) !=
> - ((leds & INITFLAG) ? 0 : (leds & CAPSFLAG))) {
> - pKbd->PostEvent(pInfo, KEY_CapsLock, TRUE);
> - pKbd->PostEvent(pInfo, KEY_CapsLock, FALSE);
> - }
> - if ((pKbd->keyLeds & NUMFLAG) !=
> - (leds & INITFLAG ? 0 : leds & NUMFLAG)) {
> - pKbd->PostEvent(pInfo, KEY_NumLock, TRUE);
> - pKbd->PostEvent(pInfo, KEY_NumLock, FALSE);
> - }
> - }
> + pKbd->SetLeds(pInfo, pKbd->keyLeds);
> }
>
> static int
> @@ -299,6 +234,9 @@ KbdProc(DeviceIntPtr device, int what)
>
> pKbd->KbdGetMapping(pInfo, &keySyms, modMap);
>
> + pKbd->keyLeds = pKbd->GetLeds(pInfo);
> + pKbd->keyLeds |= INITFLAG;
> +
> device->public.on = FALSE;
> #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 5
> {
> @@ -329,7 +267,6 @@ KbdProc(DeviceIntPtr device, int what)
> (KbdCtrlProcPtr)KbdCtrl);
> }
> #endif /* XINPUT ABI 5*/
> - InitKBD(pInfo, TRUE);
> break;
> case DEVICE_ON:
> if (device->public.on)
> @@ -350,7 +287,7 @@ KbdProc(DeviceIntPtr device, int what)
> }
>
> device->public.on = TRUE;
> - InitKBD(pInfo, FALSE);
> + pKbd->scanPrefix = 0;
> break;
>
> case DEVICE_CLOSE:
> @@ -412,6 +349,18 @@ PostKbdEvent(InputInfoPtr pInfo, unsigned int scanCode, Bool down)
> scanCode = KEY_Pause;
> }
>
> + if (pKbd->keyLeds & INITFLAG) {
> + if (pKbd->keyLeds & XLED1) {
> + xf86PostKeyboardEvent(device, KEY_CapsLock + MIN_KEYCODE, TRUE);
> + xf86PostKeyboardEvent(device, KEY_CapsLock + MIN_KEYCODE, FALSE);
> + }
> + if (pKbd->keyLeds & XLED2) {
> + xf86PostKeyboardEvent(device, KEY_NumLock + MIN_KEYCODE, TRUE);
> + xf86PostKeyboardEvent(device, KEY_NumLock + MIN_KEYCODE, FALSE);
> + }
> + pKbd->keyLeds &= ~INITFLAG;
> + }
> +
this hunk uses different indentation than the rest of this function.
Cheers,
Peter
> xf86PostKeyboardEvent(device, scanCode + MIN_KEYCODE, down);
> }
>
> --
> 1.7.3.5
More information about the xorg-devel
mailing list