for openbsd, talk to /dev/apm to hook up ac state changes instead of

/proc/apm
This commit is contained in:
jcs 2007-06-01 01:54:53 +00:00
parent 8c576bbcab
commit 72dff0e80b
2 changed files with 58 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.7 2007/05/13 11:42:39 jasper Exp $
# $OpenBSD: Makefile,v 1.8 2007/06/01 01:54:53 jcs Exp $
# requires nvram(4) device
ONLY_FOR_ARCHS= i386
@ -6,7 +6,7 @@ ONLY_FOR_ARCHS= i386
COMMENT= "utility to use ibm thinkpad(tm) special keys"
DISTNAME= tpb-0.6.4
PKGNAME= ${DISTNAME}p0
PKGNAME= ${DISTNAME}p1
CATEGORIES= sysutils
HOMEPAGE= http://www.nongnu.org/tpb/

View File

@ -1,7 +1,7 @@
$OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
--- src/tpb.c.orig Sun Aug 22 08:45:11 2004
+++ src/tpb.c Thu Dec 2 12:18:26 2004
@@ -25,7 +25,11 @@
$OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
--- src/tpb.c.orig Mon Jul 18 08:15:59 2005
+++ src/tpb.c Thu May 31 19:51:17 2007
@@ -25,13 +25,21 @@
#include <sys/wait.h>
#include <locale.h>
#include <signal.h>
@ -13,7 +13,17 @@ $OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -86,6 +90,8 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#ifdef __OpenBSD__
+#include <sys/ioctl.h>
+#include <machine/apmvar.h>
+#endif
#include "config.h"
#if ENABLE_NLS
@@ -86,6 +94,8 @@ int *xerrorhandler(Display *display, XErrorEvent *even
void sig_chld_handler(int signo);
/* }}} */
@ -22,7 +32,7 @@ $OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
int main(int argc, char **argv) /* {{{ */
{
t_thinkpad_state thinkpad_state, last_thinkpad_state;
@@ -103,6 +109,17 @@
@@ -103,6 +113,17 @@ int main(int argc, char **argv) /* {{{ */
Display *display = NULL;
#endif /* HAVE_LIBX11 */
@ -40,7 +50,7 @@ $OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
/* zero thinkpad_state */
memset(&thinkpad_state, 0, sizeof(thinkpad_state));
@@ -143,7 +160,7 @@
@@ -143,7 +164,7 @@ int main(int argc, char **argv) /* {{{ */
/* become a daemon if requested */
if(cfg.daemon == STATE_ON) {
@ -49,7 +59,7 @@ $OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
}
/* initialize osd */
@@ -972,7 +989,6 @@
@@ -980,7 +1001,6 @@ Display *init_xgrabkey(void) /* {{{ */
/* get the current state from the nvram */
int get_nvram_state(t_thinkpad_state *thinkpad_state) /* {{{ */
{
@ -57,7 +67,7 @@ $OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
unsigned char buffer[114];
struct {
int pos;
@@ -986,26 +1002,20 @@
@@ -994,26 +1014,20 @@ int get_nvram_state(t_thinkpad_state *thinkpad_state)
};
int pos_len_idx = 0;
@ -90,7 +100,43 @@ $OpenBSD: patch-src_tpb_c,v 1.2 2004/12/14 23:23:18 jcs Exp $
perror(NULL);
return -1;
}
@@ -1273,6 +1283,11 @@
@@ -1045,11 +1059,26 @@ int get_nvram_state(t_thinkpad_state *thinkpad_state)
/* get the current state from the apm subsystem */
int get_apm_state(t_thinkpad_state *thinkpad_state) /* {{{ */
{
- unsigned int i;
static int fdsc = -1; /* -1 -> file not opened */
+#ifdef __OpenBSD__
+ struct apm_power_info info;
+#else
+ unsigned int i;
char buffer[38];
char *tokens[9];
+#endif
+#ifdef __OpenBSD__
+ memset(&info, 0, sizeof(info));
+
+ if (fdsc == -1)
+ fdsc = open("/dev/apm", O_RDONLY);
+
+ if (fdsc) {
+ if (ioctl(fdsc, APM_IOC_GETPOWER, &info) == 0)
+ thinkpad_state->ac_state = (info.ac_state ? STATE_ON : STATE_OFF);
+ }
+#else
/* Read the state of the ac line from proc filesystem.
* Documentation of /proc/apm from linux kernel (/usr/src/linux/arch/i386/kernel/apm.c)
*
@@ -1122,6 +1151,7 @@ int get_apm_state(t_thinkpad_state *thinkpad_state) /*
thinkpad_state->ac_state = STATE_ON;
break;
}
+#endif
return 0;
} /* }}} */
@@ -1282,6 +1312,11 @@ void set_nvram_volume_level(t_thinkpad_state *thinkpad
{
int fdsc;
char buffer;