summaryrefslogtreecommitdiff
path: root/desktop/lxpanel/patches/0001-Fix-battery-selection-it-appears-incompatible-with-0.patch
blob: 6210cf8d8bf63dd91dec3236eef6ee861951270d (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
From ad0022eb8b1524b18d2b512d7dd8d2920c0f8dab Mon Sep 17 00:00:00 2001
From: Andriy Grytsenko <andrej@rep.kiev.ua>
Date: Fri, 25 Nov 2016 01:18:47 +0200
Subject: [PATCH 1/2] Fix battery selection, it appears incompatible with 0.7.2
 behavior.

See https://bugs.debian.org/845555
---
 ChangeLog               |  2 ++
 TODO                    |  2 +-
 plugins/batt/batt_sys.c | 30 +++++++++++++++---------------
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a21a14e..0abe16b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+* Fixed battery selection, it appears incompatible with 0.7.2 behavior.
+
 0.9.1
 -------------------------------------------------------------------------
 * Fixed build failure without ALSA.
diff --git a/TODO b/TODO
index 965b17c..8d9f91f 100644
--- a/TODO
+++ b/TODO
@@ -17,7 +17,7 @@
 * decide 'netstat' vs 'netstatus'
 * optional libnotify support (useful for battery and volume plugins)
 * pull improvements from Raspbian
-* add Most Recent support into 'menu' plugin
+* add Most Recent support into 'menu' plugin (option: ones not by Run too)
 * check and use weather-* standard themed icons for weather plugin
 * "Remove this Launch Button" option in launchbar context menu
 * 'usb-unmount' plugin
diff --git a/plugins/batt/batt_sys.c b/plugins/batt/batt_sys.c
index 154bd3d..2482c6f 100644
--- a/plugins/batt/batt_sys.c
+++ b/plugins/batt/batt_sys.c
@@ -4,6 +4,7 @@
  *      Copyright 2009 Juergen Hötzel <juergen@archlinux.org>
  *                2015 Henry Gebhardt <hsggebhardt@googlemail.com>
  *                2015 Stanislav Kozina, Ersin <xersin@users.sf.net>
+ *                2016 Andriy Grytsenko <andrej@rep.kiev.ua>
  *
  * 	Parts shameless stolen and glibified from acpi package
  * 	Copyright (C) 2001  Grahame Bowland <grahame@angrygoats.net>
@@ -295,15 +296,8 @@ battery *battery_get(int battery_number) {
     const gchar *entry;
     gchar *batt_name = NULL;
     gchar *batt_path = NULL;
-    GDir * dir = g_dir_open( ACPI_PATH_SYS_POWER_SUPPLY, 0, &error );
+    GDir * dir;
     battery *b = NULL;
-    int i;
-
-    if ( dir == NULL )
-    {
-        g_warning( "NO ACPI/sysfs support in kernel: %s", error->message );
-        return NULL;
-    }
 
     /* Try the expected path in sysfs first */
     batt_name = g_strdup_printf(ACPI_BATTERY_DEVICE_NAME "%d", battery_number);
@@ -324,13 +318,20 @@ battery *battery_get(int battery_number) {
     g_free(batt_path);
 
     if (b != NULL)
-        goto done;
+        return b;
 
     /*
      * We didn't find the expected path in sysfs.
-     * Walk the dir and blindly return n-th entry.
+     * Walk the dir and return any battery.
      */
-    i = 0;
+    dir = g_dir_open( ACPI_PATH_SYS_POWER_SUPPLY, 0, &error );
+    if ( dir == NULL )
+    {
+        g_warning( "NO ACPI/sysfs support in kernel: %s", error->message );
+        g_error_free(error);
+        return NULL;
+    }
+
     while ( ( entry = g_dir_read_name (dir) ) != NULL )
     {
         b = battery_new();
@@ -339,9 +340,7 @@ battery *battery_get(int battery_number) {
 
         /* We're looking for a battery with the selected ID */
         if (b->type_battery == TRUE) {
-            if (i == battery_number)
-                break;
-            i++;
+            break;
         }
         battery_free(b);
         b = NULL;
@@ -349,9 +348,10 @@ battery *battery_get(int battery_number) {
     if (b != NULL)
         g_warning( "Battery entry " ACPI_BATTERY_DEVICE_NAME "%d not found, using %s",
             battery_number, b->path);
+        // FIXME: update config?
     else
         g_warning( "Battery %d not found", battery_number );
-done:
+
     g_dir_close( dir );
     return b;
 }
-- 
2.11.0