Module Name:    src
Committed By:   macallan
Date:           Wed Nov 16 06:56:50 UTC 2011

Modified Files:
        src/sys/dev/adb: adb_kbd.c

Log Message:
only require the power button to be pressed twice on keyboards where it's easy
to hit by accident, send an event to sysmon immediately otherwise


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/adb/adb_kbd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/adb/adb_kbd.c
diff -u src/sys/dev/adb/adb_kbd.c:1.15 src/sys/dev/adb/adb_kbd.c:1.16
--- src/sys/dev/adb/adb_kbd.c:1.15	Thu Aug 18 02:18:40 2011
+++ src/sys/dev/adb/adb_kbd.c	Wed Nov 16 06:56:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: adb_kbd.c,v 1.15 2011/08/18 02:18:40 christos Exp $	*/
+/*	$NetBSD: adb_kbd.c,v 1.16 2011/11/16 06:56:49 macallan Exp $	*/
 
 /*
  * Copyright (C) 1998	Colin Wood
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adb_kbd.c,v 1.15 2011/08/18 02:18:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adb_kbd.c,v 1.16 2011/11/16 06:56:49 macallan Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -75,6 +75,7 @@ struct adbkbd_softc {
 	struct sysmon_pswitch sc_sm_pbutton;
 	int sc_leds;
 	int sc_have_led_control;
+	int sc_power_button_delay;
 	int sc_msg_len;
 	int sc_event;
 	int sc_poll;
@@ -194,6 +195,19 @@ adbkbd_attach(device_t parent, device_t 
 
 	sc->sc_leds = 0;	/* initially off */
 	sc->sc_have_led_control = 0;
+
+	/*
+	 * If this is != 0 then pushing the power button will not immadiately
+	 * send a shutdown event to sysmon but instead require another key
+	 * press within 5 seconds with a gap of at least two seconds. The 
+	 * reason to do this is the fact that some PowerBook keyboards,
+	 * like the 2400, 3400 and original G3 have their power buttons
+	 * right next to the backspace key and it's extremely easy to hit
+	 * it by accident.
+	 * On most other keyboards the power button is sufficiently far out
+	 * of the way so we don't need this.
+	 */
+	sc->sc_power_button_delay = 0;
 	sc->sc_msg_len = 0;
 	sc->sc_poll = 0;
 	sc->sc_capslock = 0;
@@ -244,10 +258,12 @@ adbkbd_attach(device_t parent, device_t 
 	case ADB_PBKBD:
 		printf("PowerBook keyboard\n");
 		sc->sc_power = 0x7e;
+		sc->sc_power_button_delay = 1;
 		break;
 	case ADB_PBISOKBD:
 		printf("PowerBook keyboard (ISO layout)\n");
 		sc->sc_power = 0x7e;
+		sc->sc_power_button_delay = 1;
 		break;
 	case ADB_ADJKPD:
 		printf("adjustable keypad\n");
@@ -263,10 +279,12 @@ adbkbd_attach(device_t parent, device_t 
 		break;
 	case ADB_PBEXTISOKBD:
 		printf("PowerBook extended keyboard (ISO layout)\n");
+		sc->sc_power_button_delay = 1;
 		sc->sc_power = 0x7e;
 		break;
 	case ADB_PBEXTJAPKBD:
 		printf("PowerBook extended keyboard (Japanese layout)\n");
+		sc->sc_power_button_delay = 1;
 		sc->sc_power = 0x7e;
 		break;
 	case ADB_JPKBDII:
@@ -274,6 +292,7 @@ adbkbd_attach(device_t parent, device_t 
 		break;
 	case ADB_PBEXTKBD:
 		printf("PowerBook extended keyboard\n");
+		sc->sc_power_button_delay = 1;
 		sc->sc_power = 0x7e;
 		break;
 	case ADB_DESIGNKBD:
@@ -282,6 +301,7 @@ adbkbd_attach(device_t parent, device_t 
 		break;
 	case ADB_PBJPKBD:
 		printf("PowerBook keyboard (Japanese layout)\n");
+		sc->sc_power_button_delay = 1;
 		sc->sc_power = 0x7e;
 		break;
 	case ADB_PBG3KBD:
@@ -392,7 +412,8 @@ adbkbd_keys(struct adbkbd_softc *sc, uin
 		uint32_t diff = now - sc->sc_timestamp;
 
 		sc->sc_timestamp = now;
-		if ((diff > 1) && (diff < 5)) {
+		if (((diff > 1) && (diff < 5)) ||
+		     (sc->sc_power_button_delay == 0)) {
 
 			/* power button, report to sysmon */
 			sc->sc_pe = k1;

Reply via email to