src/battery/openbsd.c (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
/************************************************************************** * * Tint2 : OpenBSD & NetBSD battery * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * or any later version as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **************************************************************************/ #if defined(__OpenBSD__) || defined(__NetBSD__) //#include <machine/apmvar.h> #include <err.h> #include <sys/ioctl.h> #include <unistd.h> #include <string.h> #include "common.h" #include "battery.h" int apm_fd = -1; gboolean battery_os_init() { if (apm_fd > 0) close(apm_fd); apm_fd = open("/dev/apm", O_RDONLY); if (apm_fd < 0) { warn("ERROR: battery applet cannot open /dev/apm."); return FALSE; } else { return TRUE; } } void battery_os_free() { if ((apm_fd != -1) && (close(apm_fd) == -1)) warn("cannot close /dev/apm"); apm_fd = -1; } int battery_os_update(struct batstate *state) { struct apm_power_info info; if (apm_fd > 0 && ioctl(apm_fd, APM_IOC_GETPOWER, &(info)) == 0) { // best attempt at mapping to Linux battery states switch (info.battery_state) { case APM_BATT_CHARGING: state->state = BATTERY_CHARGING; break; default: state->state = BATTERY_DISCHARGING; break; } if (info.battery_life == 100) state->state = BATTERY_FULL; if (info.minutes_left != -1) batstate_set_time(state, info.minutes_left * 60); state->percentage = info.battery_life; } else { warn("power update: APM_IOC_GETPOWER"); return -1; } return 0; } char* battery_os_tooltip() { return strdup("Operating System not supported"); } #endif |