Skip to contentSkip to conversation

panel: added sysfs support

PATCH In review Dixit Parmar 1 participant 2 messages Sep 10, 2025 – Oct 24, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 panel: added sysfs support

battery applet supports reading battery and supply information from sysfs entries, /sys/class/power_supply/.

[YOCTO #12904]
https://bugzilla.yoctoproject.org/show_bug.cgi?id=12904

---
V6: https://lists.yoctoproject.org/g/yocto-patches/message/2145

---
 applets/battery/Makefile.am     |   4 +
 applets/battery/battery-acpi.c  |   2 +
 applets/battery/battery-apm.c   |   2 +
 applets/battery/battery-sysfs.c | 143 ++++++++++++++++++++++++++++++++
 applets/battery/battery.c       |   2 +
 applets/battery/battery.h       |   3 +-
 configure.ac                    |   4 +
 7 files changed, 158 insertions(+), 2 deletions(-)
 create mode 100644 applets/battery/battery-sysfs.c
applets/battery/Makefile.am +4 -0
index 9b02240..1b93a0b 100644
@@ -5,6 +5,10 @@ applet_LTLIBRARIES = libbattery.la
 libbattery_la_SOURCES = battery.c battery.h
 libbattery_la_CPPFLAGS = $(AM_CPPFLAGS) -DDATADIR=\"$(pkgdatadir)/battery/\"
 
+if HAVE_SYSFS
+libbattery_la_SOURCES += battery-sysfs.c
+endif
+
 if HAVE_LIBAPM
 libbattery_la_LIBADD = -lapm
 libbattery_la_SOURCES += battery-apm.c
applets/battery/battery-acpi.c +2 -0
index d1d3de9..42ef9c8 100644
@@ -14,6 +14,8 @@ global_t global;
 adapter_t *ac;
 int batt_state, ac_state;
 
+void pm_cleanup(void) { }
+
 int pm_support(void)
 {
 	if(check_acpi_support() == NOT_SUPPORTED){
applets/battery/battery-apm.c +2 -0
index edaba43..f1501a0 100644
@@ -9,6 +9,8 @@
 #include "battery.h"
 #include <apm.h>
 
+void pm_cleanup(void) { }
+
 int pm_support(void)
 {
 	if (1 == apm_exists ()) {
applets/battery/battery-sysfs.c new file +143 -0

143 lines not on this page · raw message

applets/battery/battery.c +2 -0
index b11517d..755042b 100644
@@ -24,6 +24,8 @@ battery_applet_free (BatteryApplet *applet)
         g_source_remove (applet->timeout_id);
 
         g_slice_free (BatteryApplet, applet);
+
+        pm_cleanup ();
 }
 
 static gboolean
applets/battery/battery.h +1 -2
index 534988f..7c54a3a 100644
@@ -9,8 +9,7 @@
 #ifndef MB_APPLET_BATTERY_H
 #define MB_APPLET_BATTERY_H
 
-#include <string.h>
-
+void pm_cleanup(void);
 int pm_support(void);
 const char* pm_battery_icon(void);
 
configure.ac +4 -0
index be4d591..0f607f8 100644
@@ -61,6 +61,9 @@ AC_ARG_WITH(
 )
 
 case "$with_battery" in
+     "sysfs") enable_linux_sysfs=yes
+     enable_battery=yes
+     ;;
      "acpi") AC_CHECK_HEADERS(libacpi.h, enable_linux_acpi=yes, AC_MSG_FAILURE([You need to install libacpi]))
      enable_battery=yes
      ;;
@@ -75,6 +78,7 @@ esac
 AM_CONDITIONAL(HAVE_BATTERY, test x$enable_battery = xyes)
 AM_CONDITIONAL(HAVE_LIBAPM, test x$enable_linux_apm = xyes)
 AM_CONDITIONAL(HAVE_LIBACPI, test x$enable_linux_acpi = xyes)
+AM_CONDITIONAL(HAVE_SYSFS, test x$enable_linux_sysfs = xyes)
 
 # glib-genmarshal
 GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`  
Signature · 1 line
2.43.0
#1 lore raw

Hi Ross and all,

It might have slipped at the bottom of your review list. Kindly review this patch.

Thanks,
Dixit