pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
wmbattery: Import wmbattery-2.54 as wip/wmbattery
Module Name: pkgsrc-wip
Committed By: flurry <snow%datagirl.xyz@localhost>
Pushed By: flurry
Date: Tue Sep 1 20:14:56 2020 -0700
Changeset: e2d9d117999dea512bf8ead9f63a5e8b6e2ed47f
Modified Files:
Makefile
Added Files:
wmbattery/DESCR
wmbattery/Makefile
wmbattery/PLIST
wmbattery/TODO
wmbattery/distinfo
wmbattery/files/envsys.c
wmbattery/files/envsys.h
wmbattery/options.mk
wmbattery/patches/patch-Makefile.in
wmbattery/patches/patch-configure.ac
wmbattery/patches/patch-wmbattery.c
Log Message:
wmbattery: Import wmbattery-2.54 as wip/wmbattery
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).
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=e2d9d117999dea512bf8ead9f63a5e8b6e2ed47f
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
Makefile | 1 +
wmbattery/DESCR | 5 +
wmbattery/Makefile | 29 ++++++
wmbattery/PLIST | 17 ++++
wmbattery/TODO | 3 +
wmbattery/distinfo | 9 ++
wmbattery/files/envsys.c | 181 +++++++++++++++++++++++++++++++++++
wmbattery/files/envsys.h | 2 +
wmbattery/options.mk | 32 +++++++
wmbattery/patches/patch-Makefile.in | 29 ++++++
wmbattery/patches/patch-configure.ac | 20 ++++
wmbattery/patches/patch-wmbattery.c | 67 +++++++++++++
12 files changed, 395 insertions(+)
diffs:
diff --git a/Makefile b/Makefile
index 67696285f0..4bf169e3cf 100644
--- a/Makefile
+++ b/Makefile
@@ -4991,6 +4991,7 @@ SUBDIR+= wl-git
SUBDIR+= wla-dx
SUBDIR+= wla-dx-git
SUBDIR+= wlroots
+SUBDIR+= wmbattery
SUBDIR+= wmc2d
SUBDIR+= wmii-devel
SUBDIR+= wmname
diff --git a/wmbattery/DESCR b/wmbattery/DESCR
new file mode 100644
index 0000000000..8a04a5211a
--- /dev/null
+++ b/wmbattery/DESCR
@@ -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 --git a/wmbattery/Makefile b/wmbattery/Makefile
new file mode 100644
index 0000000000..6c66dd7387
--- /dev/null
+++ b/wmbattery/Makefile
@@ -0,0 +1,29 @@
+# $NetBSD$
+
+DISTNAME= wmbattery-2.54
+CATEGORIES= x11
+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
+
+PATCHDIR= ${.CURDIR}/../../wip/wmbattery/patches
+FILESDIR= ${.CURDIR}/../../wip/wmbattery/files
+
+.include "options.mk"
+
+GNU_CONFIGURE= yes
+USE_TOOLS+= autoreconf autoconf automake gmake pkg-config
+
+pre-configure:
+ ${CP} \
+ ${FILESDIR}/envsys.c \
+ ${FILESDIR}/envsys.h \
+ ${WRKSRC}
+
+ cd ${WRKSRC} && autoreconf -fi
+
+.include "../../x11/libX11/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/wmbattery/PLIST b/wmbattery/PLIST
new file mode 100644
index 0000000000..0091fe7973
--- /dev/null
+++ b/wmbattery/PLIST
@@ -0,0 +1,17 @@
+@comment $NetBSD$
+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 --git a/wmbattery/TODO b/wmbattery/TODO
new file mode 100644
index 0000000000..5f8c9ee807
--- /dev/null
+++ b/wmbattery/TODO
@@ -0,0 +1,3 @@
+- Find out if there are other battery types than acpibat* and add
+ support for those if so
+- Check acpiacad* for whether the AC adapter is plugged in
diff --git a/wmbattery/distinfo b/wmbattery/distinfo
new file mode 100644
index 0000000000..801303f9a8
--- /dev/null
+++ b/wmbattery/distinfo
@@ -0,0 +1,9 @@
+$NetBSD$
+
+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 --git a/wmbattery/files/envsys.c b/wmbattery/files/envsys.c
new file mode 100644
index 0000000000..63e1a6da36
--- /dev/null
+++ b/wmbattery/files/envsys.c
@@ -0,0 +1,181 @@
+#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"
+#define ACPIBAT_FMT "acpibat%d"
+
+int
+envsys_supported (void)
+{
+ return 1; /* XXX */
+}
+
+prop_array_t
+get_battery (char * battery_name)
+{
+ prop_dictionary_t sys_dict;
+ prop_array_t bat_arr;
+ int smfd;
+
+ if (battery_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);
+
+ bat_arr = prop_dictionary_get (sys_dict, battery_name);
+ if (bat_arr == NULL)
+ return NULL;
+
+ prop_object_retain (bat_arr);
+ prop_object_release (sys_dict);
+
+ return bat_arr;
+}
+
+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,
+ 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;
+ bool is_present = false;
+ int64_t charge_rate = 0,
+ max_charge = 0,
+ cur_charge = 0,
+ warn_charge = 0,
+ crit_charge = 0;
+ char bat_name[] = ACPIBAT_FMT;
+ int bat_id = battery - 1;
+
+ if (info == NULL || (battery - 1 < 0))
+ return -1;
+
+ info->battery_flags = 0;
+ info->using_minutes = 1;
+
+ snprintf (bat_name, strlen (ACPIBAT_FMT), ACPIBAT_FMT, bat_id);
+
+ bat_info = get_battery (bat_name);
+ if (bat_info == NULL)
+ return -1;
+
+ 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, "charging"))
+ {
+ /* 1 is AC_LINE_STATUS_ON, 0 is AC_LINE_STATUS_OFF */
+ info->ac_line_status = handle_stat (id, "cur-value");
+ } else 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 --git a/wmbattery/files/envsys.h b/wmbattery/files/envsys.h
new file mode 100644
index 0000000000..b0c43da15a
--- /dev/null
+++ b/wmbattery/files/envsys.h
@@ -0,0 +1,2 @@
+int envsys_supported(void);
+int envsys_read(int battery, apm_info *info);
diff --git a/wmbattery/options.mk b/wmbattery/options.mk
new file mode 100644
index 0000000000..c7abee993c
--- /dev/null
+++ b/wmbattery/options.mk
@@ -0,0 +1,32 @@
+# $NetBSD$
+
+PKG_OPTIONS_VAR= PKG_OPTIONS.wmbattery
+PKG_SUPPORTED_OPTIONS= hal upower
+
+.include "../../mk/bsd.prefs.mk"
+
+.if ${OPSYS} == "NetBSD"
+CONFIGURE_ARGS+= --enable-envsys
+.endif
+
+.include "../../mk/bsd.options.mk"
+
+#
+# hal support
+#
+.if !empty(PKG_OPTIONS:Mhal)
+CONFIGURE_ARGS+= --enable-hal
+.include "../../sysutils/hal/buildlink3.mk"
+.else
+CONFIGURE_ARGS+= --disable-hal
+.endif
+
+#
+# upower support
+#
+.if !empty(PKG_OPTIONS:Mupower)
+CONFIGURE_ARGS+= --enable-upower
+.include "../../sysutils/hal/buildlink3.mk"
+.else
+CONFIGURE_ARGS+= --disable-upower
+.endif
diff --git a/wmbattery/patches/patch-Makefile.in b/wmbattery/patches/patch-Makefile.in
new file mode 100644
index 0000000000..52546d29ae
--- /dev/null
+++ b/wmbattery/patches/patch-Makefile.in
@@ -0,0 +1,29 @@
+$NetBSD$
+
+Adds checks for USE_ENVSYS provided by configure.ac.
+
+--- Makefile.in.orig 2020-09-01 05:47:00.995267854 +0000
++++ Makefile.in
+@@ -21,6 +21,7 @@ LDFLAGS = @LDFLAGS@
+ LIBS = @LIBS@ @Xlib_LIBS@ @Xext_LIBS@ @libXpm_LIBS@
+ USE_HAL = @USE_HAL@
+ USE_UPOWER = @USE_UPOWER@
++USE_ENVSYS = @USE_ENVSYS@
+
+ all: wmbattery
+
+@@ -80,6 +81,14 @@ upower.o: upower.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c upower.c -o upower.o
+ endif
+
++ifdef USE_ENVSYS
++CPPFLAGS += -DENVSYS
++LIBS += -lprop
++OBJS += envsys.o
++envsys.o: envsys.c
++ $(CC) $(CPPFLAGS) $(CFLAGS) -c envsys.c -o envsys.o
++endif
++
+ wmbattery: $(OBJS)
+ $(CC) -o wmbattery $(LDFLAGS) $(OBJS) $(LIBS)
+
diff --git a/wmbattery/patches/patch-configure.ac b/wmbattery/patches/patch-configure.ac
new file mode 100644
index 0000000000..3334322dc0
--- /dev/null
+++ b/wmbattery/patches/patch-configure.ac
@@ -0,0 +1,20 @@
+$NetBSD$
+
+Allows enabling envsys support.
+
+--- configure.ac.orig 2020-09-01 05:47:18.004496746 +0000
++++ configure.ac
+@@ -39,6 +39,13 @@ AS_IF([test x$enable_upower != xno], [
+ PKG_CHECK_MODULES([upower], [upower-glib])
+ AC_SUBST(USE_UPOWER, 1)
+ ])
++AC_ARG_ENABLE(envsys, AS_HELP_STRING([--enable-envsys], [enable envsys]),
++ [], [enable_envsys=no])
++AS_IF([test x$enable_envsys != xno], [
++ AC_CHECK_HEADERS(sys/envsys.h)
++ AC_CHECK_HEADERS(prop/proplib.h)
++ AC_SUBST(USE_ENVSYS, 1)
++])
+
+ dnl Checks for header files.
+ AC_HEADER_STDC
diff --git a/wmbattery/patches/patch-wmbattery.c b/wmbattery/patches/patch-wmbattery.c
new file mode 100644
index 0000000000..fc72565290
--- /dev/null
+++ b/wmbattery/patches/patch-wmbattery.c
@@ -0,0 +1,67 @@
+$NetBSD$
+
+Adds support for envsys (see ../files/envsys.c).
+
+--- wmbattery.c.orig 2020-09-01 05:47:33.306716070 +0000
++++ wmbattery.c
+@@ -49,6 +49,9 @@
+ #ifdef UPOWER
+ #include "upower.h"
+ #endif
++#ifdef ENVSYS
++#include "envsys.h"
++#endif
+
+ Pixmap images[NUM_IMAGES];
+ Window root, iconwin, win;
+@@ -78,6 +81,9 @@ int use_simplehal = 0;
+ #ifdef UPOWER
+ int use_upower = 0;
+ #endif
++#ifdef ENVSYS
++int use_envsys = 0;
++#endif
+ int use_sonypi = 0;
+ int use_acpi = 0;
+ int delay = 0;
+@@ -719,6 +725,12 @@ void alarmhandler(int sig)
+ if (acpi_read(battnum, &cur_info) != 0)
+ error("Cannot read ACPI information.");
+ }
++#ifdef ENVSYS
++ else if (use_envsys) {
++ if (envsys_read(battnum, &cur_info) != 0)
++ error("Cannot read envsys information.");
++ }
++#endif
+ #ifdef HAL
+ else if (use_simplehal) {
+ if (simplehal_read(battnum, &cur_info) != 0)
+@@ -784,8 +796,18 @@ int main(int argc, char *argv[])
+ {
+ make_window(parse_commandline(argc, argv), argc, argv);
+
++#ifdef ENVSYS
++ /* Check for envsys support. */
++ if (envsys_supported()) {
++ use_envsys = 1;
++ if (!delay)
++ delay = 2;
++ }
+ /* Check for APM support (returns 0 on success). */
++ else if (apm_exists() == 0) {
++#else
+ if (apm_exists() == 0) {
++#endif
+ if (!delay)
+ delay = 1;
+ }
+@@ -816,7 +838,7 @@ int main(int argc, char *argv[])
+ if (!delay)
+ delay = 1;
+ } else {
+- error("No APM, ACPI, UPOWER, HAL or SPIC support detected.");
++ error("No envsys, APM, ACPI, UPOWER, HAL or SPIC support detected.");
+ }
+
+ load_images();
Home |
Main Index |
Thread Index |
Old Index