when the laptop volume is muted, it's kind of hard to notice the
little flashing battery icon when the battery is about to die so as long as we're talking to /dev/apm, store the battery level and show when it changes ("Battery level changed to low")
This commit is contained in:
parent
2bb3d706c0
commit
cb9da7a10f
@ -1,4 +1,4 @@
|
|||||||
# $OpenBSD: Makefile,v 1.8 2007/06/01 01:54:53 jcs Exp $
|
# $OpenBSD: Makefile,v 1.9 2007/06/01 16:44:10 jcs Exp $
|
||||||
|
|
||||||
# requires nvram(4) device
|
# requires nvram(4) device
|
||||||
ONLY_FOR_ARCHS= i386
|
ONLY_FOR_ARCHS= i386
|
||||||
@ -6,12 +6,14 @@ ONLY_FOR_ARCHS= i386
|
|||||||
COMMENT= "utility to use ibm thinkpad(tm) special keys"
|
COMMENT= "utility to use ibm thinkpad(tm) special keys"
|
||||||
|
|
||||||
DISTNAME= tpb-0.6.4
|
DISTNAME= tpb-0.6.4
|
||||||
PKGNAME= ${DISTNAME}p1
|
PKGNAME= ${DISTNAME}p2
|
||||||
CATEGORIES= sysutils
|
CATEGORIES= sysutils
|
||||||
|
|
||||||
HOMEPAGE= http://www.nongnu.org/tpb/
|
HOMEPAGE= http://www.nongnu.org/tpb/
|
||||||
MASTER_SITES= http://savannah.nongnu.org/download/tpb/
|
MASTER_SITES= http://savannah.nongnu.org/download/tpb/
|
||||||
|
|
||||||
|
MAINTAINER= joshua stein <jcs@openbsd.org>
|
||||||
|
|
||||||
# gpl
|
# gpl
|
||||||
PERMIT_PACKAGE_CDROM= yes
|
PERMIT_PACKAGE_CDROM= yes
|
||||||
PERMIT_PACKAGE_FTP= yes
|
PERMIT_PACKAGE_FTP= yes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
$OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
$OpenBSD: patch-src_tpb_c,v 1.4 2007/06/01 16:44:11 jcs Exp $
|
||||||
--- src/tpb.c.orig Mon Jul 18 08:15:59 2005
|
--- src/tpb.c.orig Mon Jul 18 08:15:59 2005
|
||||||
+++ src/tpb.c Thu May 31 19:51:17 2007
|
+++ src/tpb.c Fri Jun 1 10:34:14 2007
|
||||||
@@ -25,13 +25,21 @@
|
@@ -25,13 +25,21 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
@ -23,8 +23,13 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if ENABLE_NLS
|
#if ENABLE_NLS
|
||||||
@@ -86,6 +94,8 @@ int *xerrorhandler(Display *display, XErrorEvent *even
|
@@ -84,8 +92,13 @@ int apmiser_running(void);
|
||||||
|
int *xerrorhandler(Display *display, XErrorEvent *event);
|
||||||
|
#endif /* HAVE_LIBX11 */
|
||||||
void sig_chld_handler(int signo);
|
void sig_chld_handler(int signo);
|
||||||
|
+#ifdef __OpenBSD__
|
||||||
|
+const char *apm_battery_level(int state);
|
||||||
|
+#endif
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
+int nfd = -1;
|
+int nfd = -1;
|
||||||
@ -32,7 +37,7 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
int main(int argc, char **argv) /* {{{ */
|
int main(int argc, char **argv) /* {{{ */
|
||||||
{
|
{
|
||||||
t_thinkpad_state thinkpad_state, last_thinkpad_state;
|
t_thinkpad_state thinkpad_state, last_thinkpad_state;
|
||||||
@@ -103,6 +113,17 @@ int main(int argc, char **argv) /* {{{ */
|
@@ -103,6 +116,17 @@ int main(int argc, char **argv) /* {{{ */
|
||||||
Display *display = NULL;
|
Display *display = NULL;
|
||||||
#endif /* HAVE_LIBX11 */
|
#endif /* HAVE_LIBX11 */
|
||||||
|
|
||||||
@ -50,7 +55,7 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
/* zero thinkpad_state */
|
/* zero thinkpad_state */
|
||||||
memset(&thinkpad_state, 0, sizeof(thinkpad_state));
|
memset(&thinkpad_state, 0, sizeof(thinkpad_state));
|
||||||
|
|
||||||
@@ -143,7 +164,7 @@ int main(int argc, char **argv) /* {{{ */
|
@@ -143,7 +167,7 @@ int main(int argc, char **argv) /* {{{ */
|
||||||
|
|
||||||
/* become a daemon if requested */
|
/* become a daemon if requested */
|
||||||
if(cfg.daemon == STATE_ON) {
|
if(cfg.daemon == STATE_ON) {
|
||||||
@ -59,7 +64,36 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* initialize osd */
|
/* initialize osd */
|
||||||
@@ -980,7 +1001,6 @@ Display *init_xgrabkey(void) /* {{{ */
|
@@ -638,6 +662,28 @@ int main(int argc, char **argv) /* {{{ */
|
||||||
|
#endif /* HAVE_LIBXOSD */
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
+#ifdef __OpenBSD__
|
||||||
|
+ /* determine the level of battery {{{ */
|
||||||
|
+ if(thinkpad_state.battery_level != last_thinkpad_state.battery_level) {
|
||||||
|
+ if(cfg.verbose == STATE_ON) {
|
||||||
|
+ printf(_("Battery level changed: %s\n"), _(apm_battery_level(thinkpad_state.battery_level)));
|
||||||
|
+ }
|
||||||
|
+ if(cfg.callback != NULL) {
|
||||||
|
+ snprintf(callback_cmd, sizeof(callback_cmd), "%s battery_level %s", cfg.callback, _(apm_battery_level(thinkpad_state.battery_level)));
|
||||||
|
+ if(fork_app(callback_cmd) != 0) {
|
||||||
|
+ _exit(0);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+#ifdef HAVE_LIBXOSD
|
||||||
|
+ if(osd_ptr != NULL &&
|
||||||
|
+ ((cfg.osd == STATE_OFF && cfg.osdpowermgt == STATE_ON) || (cfg.osd == STATE_ON && cfg.osdpowermgt != STATE_OFF))) {
|
||||||
|
+ xosd_display(osd_ptr, 0, XOSD_printf, "Battery level changed to %s", apm_battery_level(thinkpad_state.battery_level));
|
||||||
|
+ xosd_display(osd_ptr, 1, XOSD_string, "");
|
||||||
|
+ }
|
||||||
|
+#endif /* HAVE_LIBXOSD */
|
||||||
|
+ } /* }}} */
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
/* determine power management mode AC {{{ */
|
||||||
|
if(thinkpad_state.powermgt_ac != last_thinkpad_state.powermgt_ac) {
|
||||||
|
switch(thinkpad_state.powermgt_ac) {
|
||||||
|
@@ -980,7 +1026,6 @@ Display *init_xgrabkey(void) /* {{{ */
|
||||||
/* get the current state from the nvram */
|
/* get the current state from the nvram */
|
||||||
int get_nvram_state(t_thinkpad_state *thinkpad_state) /* {{{ */
|
int get_nvram_state(t_thinkpad_state *thinkpad_state) /* {{{ */
|
||||||
{
|
{
|
||||||
@ -67,7 +101,7 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
unsigned char buffer[114];
|
unsigned char buffer[114];
|
||||||
struct {
|
struct {
|
||||||
int pos;
|
int pos;
|
||||||
@@ -994,26 +1014,20 @@ int get_nvram_state(t_thinkpad_state *thinkpad_state)
|
@@ -994,26 +1039,20 @@ int get_nvram_state(t_thinkpad_state *thinkpad_state)
|
||||||
};
|
};
|
||||||
int pos_len_idx = 0;
|
int pos_len_idx = 0;
|
||||||
|
|
||||||
@ -100,7 +134,7 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
perror(NULL);
|
perror(NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1045,11 +1059,26 @@ int get_nvram_state(t_thinkpad_state *thinkpad_state)
|
@@ -1045,11 +1084,28 @@ int get_nvram_state(t_thinkpad_state *thinkpad_state)
|
||||||
/* get the current state from the apm subsystem */
|
/* get the current state from the apm subsystem */
|
||||||
int get_apm_state(t_thinkpad_state *thinkpad_state) /* {{{ */
|
int get_apm_state(t_thinkpad_state *thinkpad_state) /* {{{ */
|
||||||
{
|
{
|
||||||
@ -121,14 +155,16 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
+ fdsc = open("/dev/apm", O_RDONLY);
|
+ fdsc = open("/dev/apm", O_RDONLY);
|
||||||
+
|
+
|
||||||
+ if (fdsc) {
|
+ if (fdsc) {
|
||||||
+ if (ioctl(fdsc, APM_IOC_GETPOWER, &info) == 0)
|
+ if (ioctl(fdsc, APM_IOC_GETPOWER, &info) == 0) {
|
||||||
+ thinkpad_state->ac_state = (info.ac_state ? STATE_ON : STATE_OFF);
|
+ thinkpad_state->ac_state = (info.ac_state ? STATE_ON : STATE_OFF);
|
||||||
|
+ thinkpad_state->battery_level = info.battery_state;
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+#else
|
+#else
|
||||||
/* Read the state of the ac line from proc filesystem.
|
/* 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)
|
* 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) /*
|
@@ -1122,6 +1178,7 @@ int get_apm_state(t_thinkpad_state *thinkpad_state) /*
|
||||||
thinkpad_state->ac_state = STATE_ON;
|
thinkpad_state->ac_state = STATE_ON;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -136,15 +172,44 @@ $OpenBSD: patch-src_tpb_c,v 1.3 2007/06/01 01:54:53 jcs Exp $
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
@@ -1282,6 +1312,11 @@ void set_nvram_volume_level(t_thinkpad_state *thinkpad
|
@@ -1283,6 +1340,11 @@ void set_nvram_volume_level(t_thinkpad_state *thinkpad
|
||||||
{
|
|
||||||
int fdsc;
|
int fdsc;
|
||||||
char buffer;
|
char buffer;
|
||||||
+
|
|
||||||
+#ifdef __OpenBSD__
|
+#ifdef __OpenBSD__
|
||||||
+ /* nvram writing not supported in OpenBSD */
|
+ /* nvram writing not supported in OpenBSD */
|
||||||
+ return;
|
+ return;
|
||||||
+#endif
|
+#endif
|
||||||
|
+
|
||||||
/* only use writeback to nvram when cfg.mixersteps is different from DEFAULT_MIXERSTEPS */
|
/* only use writeback to nvram when cfg.mixersteps is different from DEFAULT_MIXERSTEPS */
|
||||||
if(cfg.mixersteps != DEFAULT_MIXERSTEPS) {
|
if(cfg.mixersteps != DEFAULT_MIXERSTEPS) {
|
||||||
|
/* open nvram */
|
||||||
|
@@ -1466,5 +1528,28 @@ void sig_chld_handler(int signo) /* {{{ */
|
||||||
|
waitpid(-1, &status, WNOHANG);
|
||||||
|
return;
|
||||||
|
} /* }}} */
|
||||||
|
+
|
||||||
|
+#ifdef __OpenBSD__
|
||||||
|
+const char *
|
||||||
|
+apm_battery_level(int state)
|
||||||
|
+{
|
||||||
|
+ switch (state) {
|
||||||
|
+ case APM_BATT_HIGH:
|
||||||
|
+ return "high";
|
||||||
|
+ case APM_BATT_LOW:
|
||||||
|
+ return "low";
|
||||||
|
+ case APM_BATT_CRITICAL:
|
||||||
|
+ return "CRITICAL";
|
||||||
|
+ case APM_BATT_CHARGING:
|
||||||
|
+ return "charging";
|
||||||
|
+ case APM_BATTERY_ABSENT:
|
||||||
|
+ return "absent";
|
||||||
|
+ case APM_BATT_UNKNOWN:
|
||||||
|
+ return "unknown";
|
||||||
|
+ default:
|
||||||
|
+ return "invalid battery state";
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
/* vim600:set fen:set fdm=marker:set fdl=0: */
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
$OpenBSD: patch-src_tpb_h,v 1.1 2004/12/14 23:23:18 jcs Exp $
|
$OpenBSD: patch-src_tpb_h,v 1.2 2007/06/01 16:44:11 jcs Exp $
|
||||||
--- src/tpb.h.orig Thu Dec 2 11:30:36 2004
|
--- src/tpb.h.orig Mon Jul 18 08:15:59 2005
|
||||||
+++ src/tpb.h Thu Dec 2 11:30:58 2004
|
+++ src/tpb.h Thu May 31 20:04:13 2007
|
||||||
@@ -28,6 +28,8 @@
|
@@ -28,6 +28,8 @@
|
||||||
#define _(String) (String)
|
#define _(String) (String)
|
||||||
#endif /* ENABLE_NLS */
|
#endif /* ENABLE_NLS */
|
||||||
@ -10,3 +10,11 @@ $OpenBSD: patch-src_tpb_h,v 1.1 2004/12/14 23:23:18 jcs Exp $
|
|||||||
#define MAX_VOLUME 100
|
#define MAX_VOLUME 100
|
||||||
#define CALLBACK_CMD_LENGTH 256
|
#define CALLBACK_CMD_LENGTH 256
|
||||||
#define CALLBACK_CMD_ARGS 30
|
#define CALLBACK_CMD_ARGS 30
|
||||||
|
@@ -68,6 +70,7 @@ typedef struct {
|
||||||
|
unsigned int volume_toggle; /* volume toggle */
|
||||||
|
unsigned int mute_toggle; /* mute toggle */
|
||||||
|
unsigned int ac_state; /* ac connected */
|
||||||
|
+ unsigned int battery_level; /* battery level */
|
||||||
|
unsigned int powermgt_ac; /* power management mode ac */
|
||||||
|
unsigned int powermgt_battery; /* power management mode battery */
|
||||||
|
} t_thinkpad_state;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user