Skip to content

Commit 5b7c407

Browse files
rvldtor
authored andcommitted
Input: adbhid - capslock and power button fix
If the adbhid module parameter restore_capslock_events is used, pressing the power button may confuse the capslock state. This is because the power button release scancode (0xff) is sometimes the same as the capslock press/release scancode. This fix adds yet another flag to track the state of the power button so that it works independently of capslock. Signed-off-by: Rodney Lorrimar <rodney@rodney.id.au> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent 2e75f04 commit 5b7c407

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎drivers/macintosh/adbhid.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ struct adbhid {
225225
#define FLAG_CAPSLOCK_TRANSLATE 0x00000008
226226
#define FLAG_CAPSLOCK_DOWN 0x00000010
227227
#define FLAG_CAPSLOCK_IGNORE_NEXT 0x00000020
228+
#define FLAG_POWER_KEY_PRESSED 0x00000040
228229

229230
static struct adbhid *adbhid[16];
230231

@@ -301,9 +302,11 @@ adbhid_input_keycode(int id, int scancode, int repeat)
301302
ahid->flags |= FLAG_CAPSLOCK_TRANSLATE
302303
| FLAG_CAPSLOCK_DOWN;
303304
}
304-
} else if (scancode == 0xff) {
305+
} else if (scancode == 0xff &&
306+
!(ahid->flags & FLAG_POWER_KEY_PRESSED)) {
305307
/* Scancode 0xff usually signifies that the capslock
306-
* key was either pressed or released. */
308+
* key was either pressed or released, or that the
309+
* power button was released. */
307310
if (ahid->flags & FLAG_CAPSLOCK_TRANSLATE) {
308311
keycode = ADB_KEY_CAPSLOCK;
309312
if (ahid->flags & FLAG_CAPSLOCK_DOWN) {
@@ -317,7 +320,7 @@ adbhid_input_keycode(int id, int scancode, int repeat)
317320
}
318321
} else {
319322
printk(KERN_INFO "Spurious caps lock event "
320-
"(scancode 0xff).");
323+
"(scancode 0xff).\n");
321324
}
322325
}
323326
}
@@ -344,6 +347,12 @@ adbhid_input_keycode(int id, int scancode, int repeat)
344347
}
345348
break;
346349
case ADB_KEY_POWER:
350+
/* Keep track of the power key state */
351+
if (up_flag)
352+
ahid->flags &= ~FLAG_POWER_KEY_PRESSED;
353+
else
354+
ahid->flags |= FLAG_POWER_KEY_PRESSED;
355+
347356
/* Fn + Command will produce a bogus "power" keycode */
348357
if (ahid->flags & FLAG_FN_KEY_PRESSED) {
349358
keycode = ADB_KEY_CMD;

0 commit comments

Comments
 (0)