Subject: Hotkey support via powerd
To: None <tech-kern@NetBSD.org>
From: Jared D. McNeill <jmcneill@invisible.ca>
List: tech-kern
Date: 12/22/2007 10:18:17
Heyas folks --

The following is a patch I'm using to allow hotkeys to be passed from a 
device driver through to powerd. I'm using it for eg. automatically 
locking my screen when I press Fn+F2, and invoking xrandr to change my 
outputs when I press Fn+F7 on this Thinkpad.

Comments?

Cheers,
Jared

Index: sys/power.h
===================================================================
RCS file: /cvsroot/src/sys/sys/power.h,v
retrieving revision 1.10
diff -u -r1.10 power.h
--- sys/power.h	11 Oct 2007 17:31:06 -0000	1.10
+++ sys/power.h	22 Dec 2007 15:16:55 -0000
@@ -86,6 +86,13 @@
  #define	PSWITCH_TYPE_LID	2	/* lid switch */
  #define	PSWITCH_TYPE_RESET	3	/* reset button */
  #define	PSWITCH_TYPE_ACADAPTER	4	/* AC adapter presence */
+#define	PSWITCH_TYPE_HOTKEY	5	/* hotkey button */
+#define		PSWITCH_HK_DISPLAY_CYCLE	"display-cycle"
+#define		PSWITCH_HK_LOCK_SCREEN		"lock-screen"
+#define		PSWITCH_HK_BATTERY_INFO		"battery-info"
+#define		PSWITCH_HK_EJECT_BUTTON		"eject-button"
+#define		PSWITCH_HK_ZOOM_BUTTON		"zoom-button"
+#define		PSWITCH_HK_VENDOR_BUTTON	"vendor-button"

  #define	PSWITCH_EVENT_PRESSED	0	/* button pressed, lid closed, AC off */
  #define	PSWITCH_EVENT_RELEASED	1	/* button released, lid open, AC on */
Index: dev/sysmon/sysmon_power.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sysmon/sysmon_power.c,v
retrieving revision 1.34
diff -u -r1.34 sysmon_power.c
--- dev/sysmon/sysmon_power.c	9 Dec 2007 20:57:19 -0000	1.34
+++ dev/sysmon/sysmon_power.c	22 Dec 2007 15:16:55 -0000
@@ -119,6 +119,7 @@
  	{ PSWITCH_TYPE_LID, 		"lid_switch" },
  	{ PSWITCH_TYPE_RESET, 		"reset_button" },
  	{ PSWITCH_TYPE_ACADAPTER,	"acadapter" },
+	{ PSWITCH_TYPE_HOTKEY,		"hotkey_button" },
  	{ -1, NULL }
  };

@@ -972,6 +973,12 @@
  		printf("%s: sleep button pressed.\n", smpsw->smpsw_name);
  		break;

+	case PSWITCH_TYPE_HOTKEY:
+		/*
+		 * Eat up the event, there's nothing we can do
+		 */
+		break;
+
  	case PSWITCH_TYPE_LID:
  		switch (event) {
  		case PSWITCH_EVENT_PRESSED: