| @@ -1,98 +1,98 @@ | | | @@ -1,98 +1,98 @@ |
1 | $NetBSD: patch-aa,v 1.6 2008/01/05 05:42:02 hira Exp $ | | 1 | $NetBSD: patch-aa,v 1.7 2008/12/17 12:57:27 hira Exp $ |
2 | | | 2 | |
3 | --- panel-plugin/battery.c.orig 2007-01-18 02:56:51.000000000 +0900 | | 3 | --- panel-plugin/battery.c.orig 2008-09-05 05:53:40.000000000 +0900 |
4 | +++ panel-plugin/battery.c 2008-01-03 21:30:22.000000000 +0900 | | 4 | +++ panel-plugin/battery.c 2008-11-27 22:16:05.000000000 +0900 |
5 | @@ -25,7 +25,7 @@ | | 5 | @@ -25,7 +25,7 @@ |
6 | #include <config.h> | | 6 | #include <config.h> |
7 | #endif | | 7 | #endif |
8 | | | 8 | |
9 | -#ifdef __FreeBSD__ | | 9 | -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
10 | +#if defined(__FreeBSD__) || defined(__DragonFly__) | | 10 | +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
11 | #include <machine/apm_bios.h> | | 11 | #include <machine/apm_bios.h> |
12 | #elif __OpenBSD__ | | 12 | #elif __OpenBSD__ |
13 | #include <sys/param.h> | | 13 | #include <sys/param.h> |
14 | @@ -33,8 +33,15 @@ | | 14 | @@ -33,8 +33,15 @@ |
15 | #elif __NetBSD__ | | 15 | #elif __NetBSD__ |
16 | #include <sys/param.h> | | 16 | #include <sys/param.h> |
17 | #include <sys/ioctl.h> | | 17 | #include <sys/ioctl.h> |
18 | +#if defined(__sparc64__) | | 18 | +#if defined(__sparc64__) |
19 | +/* On NetBSD/sparc64, apmvar.h is not exist in /usr/include/machine. */ | | 19 | +/* On NetBSD/sparc64, apmvar.h is not exist in /usr/include/machine. */ |
20 | +/* Reported in PR port-sparc64/36735. */ | | 20 | +/* Reported in PR port-sparc64/36735. */ |
21 | +#include <sparc/apmvar.h> | | 21 | +#include <sparc/apmvar.h> |
22 | +#else | | 22 | +#else |
23 | #include <machine/apmvar.h> | | 23 | #include <machine/apmvar.h> |
24 | +#endif | | 24 | +#endif |
25 | #define APMDEVICE "/dev/apm" | | 25 | #define APMDEVICE "/dev/apm" |
26 | +#define _ACPI_APM_BATT_UNKNOWN 0xffff /* from sys/dev/acpi/acpi_apm.c */ | | 26 | +#define _ACPI_APM_BATT_UNKNOWN 0xffff /* from sys/dev/acpi/acpi_apm.c */ |
27 | #elif __linux__ | | 27 | #elif __linux__ |
28 | #include <libapm.h> | | 28 | #include <libapm.h> |
29 | #endif | | 29 | #endif |
30 | @@ -155,7 +162,7 @@ | | 30 | @@ -155,7 +162,7 @@ |
31 | gboolean | | 31 | gboolean |
32 | detect_battery_info(t_battmon *battmon) | | 32 | detect_battery_info(t_battmon *battmon) |
33 | { | | 33 | { |
34 | -#ifdef __FreeBSD__ | | 34 | -#ifdef __FreeBSD__ |
35 | +#if defined(__FreeBSD__) || defined(__DragonFly__) | | 35 | +#if defined(__FreeBSD__) || defined(__DragonFly__) |
36 | /* This is how I read the information from the APM subsystem under | | 36 | /* This is how I read the information from the APM subsystem under |
37 | FreeBSD. Each time this functions is called (once every second) | | 37 | FreeBSD. Each time this functions is called (once every second) |
38 | the APM device is opened, read from and then closed. | | 38 | the APM device is opened, read from and then closed. |
39 | @@ -209,7 +216,7 @@ | | 39 | @@ -209,7 +216,7 @@ |
40 | battmon->method = BM_BROKEN; | | 40 | battmon->method = BM_BROKEN; |
41 | fd = open(APMDEVICE, O_RDONLY); | | 41 | fd = open(APMDEVICE, O_RDONLY); |
42 | if (fd == -1) return FALSE; | | 42 | if (fd == -1) return FALSE; |
43 | - + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) { | | 43 | - + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) { |
44 | + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) { | | 44 | + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) { |
45 | close(fd); | | 45 | close(fd); |
46 | return FALSE; | | 46 | return FALSE; |
47 | } | | 47 | } |
48 | @@ -302,13 +309,16 @@ | | 48 | @@ -302,13 +309,16 @@ |
49 | battmon->method = BM_BROKEN; | | 49 | battmon->method = BM_BROKEN; |
50 | fd = open(APMDEVICE, O_RDONLY); | | 50 | fd = open(APMDEVICE, O_RDONLY); |
51 | if (fd == -1) return TRUE; | | 51 | if (fd == -1) return TRUE; |
52 | - if (ioctl(fd, APM_IOC_GETPOWER, &apminfo) == -1) | | 52 | - if (ioctl(fd, APM_IOC_GETPOWER, &apminfo) == -1) |
53 | + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) | | 53 | + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) |
54 | return TRUE; | | 54 | return TRUE; |
55 | close(fd); | | 55 | close(fd); |
56 | charge = apm.battery_life; | | 56 | charge = apm.battery_life; |
57 | time_remaining = apm.minutes_left; | | 57 | time_remaining = apm.minutes_left; |
58 | acline = apm.ac_state ? TRUE : FALSE; | | 58 | acline = apm.ac_state ? TRUE : FALSE; |
59 | | | 59 | |
60 | + if(battmon->timeoutid != 0) g_source_remove(battmon->timeoutid); | | 60 | + if(battmon->timeoutid != 0) g_source_remove(battmon->timeoutid); |
61 | + battmon->timeoutid = g_timeout_add(2 * 1024, | | 61 | + battmon->timeoutid = g_timeout_add(2 * 1024, |
62 | + (GSourceFunc) update_apm_status, battmon); | | 62 | + (GSourceFunc) update_apm_status, battmon); |
63 | #else | | 63 | #else |
64 | struct apm_info apm; | | 64 | struct apm_info apm; |
65 | DBG ("Updating battery status..."); | | 65 | DBG ("Updating battery status..."); |
66 | @@ -400,7 +410,7 @@ | | 66 | @@ -404,7 +414,7 @@ |
67 | acline = apm.ac_line_status ? TRUE : FALSE; | | 67 | acline = apm.ac_line_status ? TRUE : FALSE; |
68 | | | 68 | |
69 | } | | 69 | } |
70 | -#elif __FreeBSD__ | | 70 | -#elif __FreeBSD__ |
71 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) | | 71 | +#elif defined(__FreeBSD__) || defined(__DragonFly__) |
72 | else { | | 72 | else { |
73 | /* This is how I read the information from the APM subsystem under | | 73 | /* This is how I read the information from the APM subsystem under |
74 | FreeBSD. Each time this functions is called (once every second) | | 74 | FreeBSD. Each time this functions is called (once every second) |
75 | @@ -460,6 +470,11 @@ | | 75 | @@ -464,6 +474,11 @@ |
76 | | | 76 | |
77 | if(battmon->options.display_percentage && !(battmon->options.hide_when_full && acline && charge >= 99)){ | | 77 | if(battmon->options.display_percentage && !(battmon->options.hide_when_full && acline && charge >= 99)){ |
78 | gtk_widget_show((GtkWidget *)battmon->charge); | | 78 | gtk_widget_show((GtkWidget *)battmon->charge); |
79 | +#if defined(__NetBSD__) || defined(__OpenBSD__) | | 79 | +#if defined(__NetBSD__) || defined(__OpenBSD__) |
80 | + if (apm.battery_state == APM_BATT_ABSENT) | | 80 | + if (apm.battery_state == APM_BATT_ABSENT) |
81 | + g_snprintf(buffer, sizeof(buffer),"--%% "); | | 81 | + g_snprintf(buffer, sizeof(buffer),"--%% "); |
82 | + else | | 82 | + else |
83 | +#endif | | 83 | +#endif |
84 | g_snprintf(buffer, sizeof(buffer),"%d%% ", charge); | | 84 | g_snprintf(buffer, sizeof(buffer),"%d%% ", charge); |
85 | gtk_label_set_text(battmon->charge,buffer); | | 85 | gtk_label_set_text(battmon->charge,buffer); |
86 | } else { | | 86 | } else { |
87 | @@ -477,6 +492,11 @@ | | 87 | @@ -481,6 +496,11 @@ |
88 | } | | 88 | } |
89 | | | 89 | |
90 | gtk_widget_show((GtkWidget *)active_label); | | 90 | gtk_widget_show((GtkWidget *)active_label); |
91 | +#if defined(__NetBSD__) | | 91 | +#if defined(__NetBSD__) |
92 | + if (acline || time_remaining == _ACPI_APM_BATT_UNKNOWN) | | 92 | + if (acline || time_remaining == _ACPI_APM_BATT_UNKNOWN) |
93 | + g_snprintf(buffer, sizeof(buffer), "--:--"); | | 93 | + g_snprintf(buffer, sizeof(buffer), "--:--"); |
94 | + else | | 94 | + else |
95 | +#endif | | 95 | +#endif |
96 | g_snprintf(buffer, sizeof(buffer),"%02d:%02d ",time_remaining/60,time_remaining%60); | | 96 | g_snprintf(buffer, sizeof(buffer),"%02d:%02d ",time_remaining/60,time_remaining%60); |
97 | gtk_label_set_text(active_label,buffer); | | 97 | gtk_label_set_text(active_label,buffer); |
98 | | | 98 | |