Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/sysutils sysutils: Add wmbattery - based on work by sn...
details: https://anonhg.NetBSD.org/pkgsrc/rev/5bb56b176e41
branches: trunk
changeset: 438788:5bb56b176e41
user: nia <nia%pkgsrc.org@localhost>
date: Thu Sep 10 11:26:01 2020 +0000
description:
sysutils: Add wmbattery - based on work by snow flurry and myself in wip
wmbattery is a dockapp that displays the status of your laptop's
battery in a small icon. This includes if it is plugged in, if the
battery is charging, how many minutes of battery life remain, battery
life remaining (with both a percentage and a graph), and battery
status (high - green, low - yellow, or critical - red).
diffstat:
sysutils/Makefile | 3 +-
sysutils/wmbattery/DESCR | 5 +
sysutils/wmbattery/Makefile | 33 ++++
sysutils/wmbattery/PLIST | 17 ++
sysutils/wmbattery/distinfo | 9 +
sysutils/wmbattery/files/envsys.c | 198 ++++++++++++++++++++++++++
sysutils/wmbattery/files/envsys.h | 2 +
sysutils/wmbattery/options.mk | 26 +++
sysutils/wmbattery/patches/patch-Makefile.in | 29 +++
sysutils/wmbattery/patches/patch-configure.ac | 20 ++
sysutils/wmbattery/patches/patch-wmbattery.c | 67 ++++++++
11 files changed, 408 insertions(+), 1 deletions(-)
diffs (truncated from 463 to 300 lines):
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/Makefile
--- a/sysutils/Makefile Thu Sep 10 10:33:47 2020 +0000
+++ b/sysutils/Makefile Thu Sep 10 11:26:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.899 2020/09/04 13:25:32 wiz Exp $
+# $NetBSD: Makefile,v 1.900 2020/09/10 11:26:01 nia Exp $
#
COMMENT= System utilities
@@ -762,6 +762,7 @@
SUBDIR+= wipe
SUBDIR+= within
SUBDIR+= wmSMPmon
+SUBDIR+= wmbattery
SUBDIR+= wmcpuload
SUBDIR+= wmmemmon
SUBDIR+= wpi-firmware
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/wmbattery/DESCR
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/wmbattery/DESCR Thu Sep 10 11:26:01 2020 +0000
@@ -0,0 +1,5 @@
+wmbattery is a dockapp that displays the status of your laptop's
+battery in a small icon. This includes if it is plugged in, if the
+battery is charging, how many minutes of battery life remain, battery
+life remaining (with both a percentage and a graph), and battery
+status (high - green, low - yellow, or critical - red).
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/wmbattery/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/wmbattery/Makefile Thu Sep 10 11:26:01 2020 +0000
@@ -0,0 +1,33 @@
+# $NetBSD: Makefile,v 1.1 2020/09/10 11:26:01 nia Exp $
+
+DISTNAME= wmbattery-2.54
+CATEGORIES= sysutils
+MASTER_SITES= https://www.dockapps.net/download/
+
+MAINTAINER= pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE= https://www.dockapps.net/
+COMMENT= Dockapp that shows battery status
+LICENSE= gnu-gpl-v2
+
+GNU_CONFIGURE= yes
+USE_TOOLS+= autoreconf autoconf automake gmake pkg-config
+
+.include "../../mk/bsd.prefs.mk"
+
+.if ${OPSYS} == "NetBSD"
+CONFIGURE_ARGS+= --enable-envsys
+.endif
+
+pre-configure:
+ ${CP} \
+ ${FILESDIR}/envsys.c \
+ ${FILESDIR}/envsys.h \
+ ${WRKSRC}
+
+ cd ${WRKSRC} && autoreconf -fi
+
+.include "options.mk"
+.include "../../x11/libX11/buildlink3.mk"
+.include "../../x11/libXext/buildlink3.mk"
+.include "../../x11/libXpm/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/wmbattery/PLIST
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/wmbattery/PLIST Thu Sep 10 11:26:01 2020 +0000
@@ -0,0 +1,17 @@
+@comment $NetBSD: PLIST,v 1.1 2020/09/10 11:26:01 nia Exp $
+bin/wmbattery
+man/man1/wmbattery.1
+share/icons/wmbattery/battery_blink.xpm
+share/icons/wmbattery/battery_high.xpm
+share/icons/wmbattery/battery_low.xpm
+share/icons/wmbattery/battery_medium.xpm
+share/icons/wmbattery/battery_none.xpm
+share/icons/wmbattery/bigfont.xpm
+share/icons/wmbattery/charging.xpm
+share/icons/wmbattery/dial_bright.xpm
+share/icons/wmbattery/dial_dim.xpm
+share/icons/wmbattery/face.xpm
+share/icons/wmbattery/nocharging.xpm
+share/icons/wmbattery/plugged.xpm
+share/icons/wmbattery/smallfont.xpm
+share/icons/wmbattery/unplugged.xpm
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/wmbattery/distinfo
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/wmbattery/distinfo Thu Sep 10 11:26:01 2020 +0000
@@ -0,0 +1,9 @@
+$NetBSD: distinfo,v 1.1 2020/09/10 11:26:01 nia Exp $
+
+SHA1 (wmbattery-2.54.tar.gz) = 549b0eec16880f9b71b60faed6326d1a9a76af54
+RMD160 (wmbattery-2.54.tar.gz) = ef709353135de51a74599f9e86967b261df1caeb
+SHA512 (wmbattery-2.54.tar.gz) = 58c901ed85d3ea7e0c750bb968c3250706ed693162fe4684d75683a3897df7ff02ee4afbe12a5d26b1f1b632d4c6f9902713a632e6784173ea49bad312fd30aa
+Size (wmbattery-2.54.tar.gz) = 87925 bytes
+SHA1 (patch-Makefile.in) = 1445d031dd10b92e183337b4dc232e808f0e5e18
+SHA1 (patch-configure.ac) = e7f0d0d7c9a168423fb29ab853e58877e50b19aa
+SHA1 (patch-wmbattery.c) = 8a525090ec3cdc02090c50ead240dd839a1d08ea
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/wmbattery/files/envsys.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysutils/wmbattery/files/envsys.c Thu Sep 10 11:26:01 2020 +0000
@@ -0,0 +1,198 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <prop/proplib.h>
+#include <sys/envsys.h>
+
+#include "apm.h"
+#include "envsys.h"
+
+#define _DEV_SYSMON "/dev/sysmon"
+
+int
+envsys_supported (void)
+{
+ return 1; /* XXX */
+}
+
+prop_array_t
+get_device (const char * name)
+{
+ prop_dictionary_t sys_dict;
+ prop_array_t array;
+ int smfd;
+
+ if (name == NULL)
+ return NULL;
+
+ smfd = open (_DEV_SYSMON, O_RDONLY);
+ if (smfd == -1)
+ return NULL;
+
+ if (prop_dictionary_recv_ioctl (smfd,
+ ENVSYS_GETDICTIONARY,
+ &sys_dict) != 0)
+ {
+ return NULL;
+ }
+
+ close (smfd);
+
+ array = prop_dictionary_get (sys_dict, name);
+ if (array == NULL)
+ return NULL;
+
+ prop_object_retain (array);
+ prop_object_release (sys_dict);
+
+ return array;
+}
+
+bool
+stat_is_valid (prop_dictionary_t stat)
+{
+ prop_string_t strval;
+
+ if (stat == NULL)
+ return false;
+
+ strval = prop_dictionary_get (stat, "state");
+ if (strval == NULL)
+ return false;
+
+
+ return prop_string_equals_cstring (strval, "valid");
+}
+
+int64_t
+handle_stat (prop_dictionary_t stat,
+ const char * key)
+{
+ prop_number_t numval;
+
+ if (stat == NULL || key == NULL)
+ return -1;
+
+ numval = (prop_number_t) prop_dictionary_get (stat, key);
+ if (numval == NULL)
+ return -1;
+
+ return prop_number_integer_value (numval);
+}
+
+int
+envsys_read (int battery,
+ apm_info *info)
+{
+ prop_object_iterator_t iter;
+ prop_dictionary_t id;
+ prop_string_t desc;
+ prop_array_t bat_info, ac_info;
+ bool is_present = false;
+ int64_t charge_rate = 0,
+ max_charge = 0,
+ cur_charge = 0,
+ warn_charge = 0,
+ crit_charge = 0;
+ char dev_name[32];
+ int bat_id = battery - 1;
+
+ if (info == NULL || (battery - 1 < 0))
+ return -1;
+
+ info->battery_flags = 0;
+ info->using_minutes = 1;
+
+ snprintf (dev_name, sizeof (dev_name), "acpibat%d", bat_id);
+
+ bat_info = get_device (dev_name);
+ if (bat_info == NULL)
+ return -1;
+
+ ac_info = get_device ("acpiacad0");
+ if (ac_info != NULL) {
+ iter = prop_array_iterator (ac_info);
+ while ((id = (prop_dictionary_t) prop_object_iterator_next (iter)) != NULL)
+ {
+ desc = (prop_string_t) prop_dictionary_get (id, "description");
+ if (desc == NULL) continue;
+ if (!prop_string_equals_cstring (desc, "connected"))
+ continue;
+ if (handle_stat (id, "cur-value") != 0) {
+ info->ac_line_status = AC_LINE_STATUS_ON;
+ } else {
+ info->ac_line_status = AC_LINE_STATUS_OFF;
+ }
+ break;
+ }
+ prop_object_iterator_release (iter);
+ prop_object_release (ac_info);
+ } else {
+ info->ac_line_status = AC_LINE_STATUS_UNKNOWN;
+ }
+
+ iter = prop_array_iterator (bat_info);
+ while ((id = (prop_dictionary_t) prop_object_iterator_next (iter)) != NULL)
+ {
+ desc = (prop_string_t) prop_dictionary_get (id, "description");
+ if (desc == NULL) continue;
+ if (prop_string_equals_cstring (desc, "charge")) {
+ cur_charge = handle_stat (id, "cur-value");
+ max_charge = handle_stat (id, "max-value");
+ warn_charge = handle_stat (id, "warning-capacity");
+ crit_charge = handle_stat (id, "critical-capacity");
+ } else if (prop_string_equals_cstring (desc, "charge rate")) {
+ if (stat_is_valid (id)) charge_rate = handle_stat (id, "cur-value");
+ } else if (prop_string_equals_cstring (desc, "discharge rate")) {
+ if (stat_is_valid (id)) charge_rate = handle_stat (id, "cur-value");
+ } else if (prop_string_equals_cstring (desc, "present")) {
+ is_present = (handle_stat (id, "cur-value") == 1);
+ }
+ }
+ prop_object_iterator_release (iter);
+ prop_object_release (bat_info);
+
+ if (max_charge > 1) {
+ info->battery_percentage = ( cur_charge * 100 ) / max_charge;
+ if (info->battery_percentage > 100) info->battery_percentage = 100;
+ } else {
+ info->battery_percentage = BATTERY_PERCENTAGE_UNKNOWN;
+ }
+
+ if (info->ac_line_status) {
+ info->battery_status = BATTERY_STATUS_CHARGING;
+ /*
+ * If our charge rate is 0, then it was either marked invalid by envsys
+ * or we're "charging" at 0Wh-- either way, the battery isn't charging
+ */
+ if (charge_rate > 0) {
+ info->battery_flags = info->battery_flags | BATTERY_FLAGS_CHARGING;
+ }
+ } else {
+ if (cur_charge < crit_charge) {
+ info->battery_status = BATTERY_STATUS_CRITICAL;
+ } else if (cur_charge < warn_charge) {
+ info->battery_status = BATTERY_STATUS_LOW;
+ } else {
+ info->battery_status = BATTERY_STATUS_HIGH;
+ }
+ }
+
+ if (!is_present) {
+ info->battery_percentage = 0;
+ info->battery_time = 0;
+ info->battery_status = BATTERY_STATUS_ABSENT;
+ }
+
+ /* calculate time remaining */
+ if (charge_rate == 0) {
+ info->battery_time = BATTERY_TIME_UNKNOWN;
+ } else {
+ info->battery_time = ( (max_charge - cur_charge) * 60) / charge_rate;
+ }
+
+ return 0;
+}
diff -r 9360fd988a21 -r 5bb56b176e41 sysutils/wmbattery/files/envsys.h
Home |
Main Index |
Thread Index |
Old Index