'batt': make sure 'Size' is at least 1.
[lxde/lxpanel.git] / plugins / batt / batt.c
1 /*
2 * ACPI battery monitor plugin for LXPanel
3 *
4 * Copyright (C) 2007 by Greg McNew <gmcnew@gmail.com>
5 * Copyright (C) 2008 by Hong Jen Yee <pcman.tw@gmail.com>
6 * Copyright (C) 2009 by Juergen Hoetzel <juergen@archlinux.org>
7 * Copyright (C) 2014 by Andriy Grytsenko <andrej@rep.kiev.ua>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 *
24 * This plugin monitors battery usage on ACPI-enabled systems by reading the
25 * battery information found in /sys/class/power_supply. The update interval is
26 * user-configurable and defaults to 3 second.
27 *
28 * The battery's remaining life is estimated from its current charge and current
29 * rate of discharge. The user may configure an alarm command to be run when
30 * their estimated remaining battery life reaches a certain level.
31 */
32
33 /* FIXME:
34 * Here are somethings need to be improvec:
35 * 1. Replace pthread stuff with gthread counterparts for portability.
36 * 3. Add an option to hide the plugin when AC power is used or there is no battery.
37 * 4. Handle failure gracefully under systems other than Linux.
38 */
39
40 #include <glib.h>
41 #include <glib/gi18n.h>
42 #include <pthread.h> /* used by pthread_create() and alarmThread */
43 #include <semaphore.h> /* used by update() and alarmProcess() for alarms */
44 #include <stdlib.h>
45 #include <string.h>
46 #include <stdarg.h>
47
48 #include "dbg.h" /* for ENTER and RET macros */
49 #include "batt_sys.h"
50 #include "plugin.h" /* all other APIs including panel configuration */
51
52 /* The last MAX_SAMPLES samples are averaged when charge rates are evaluated.
53 This helps prevent spikes in the "time left" values the user sees. */
54 #define MAX_SAMPLES 10
55
56 typedef struct {
57 char *alarmCommand,
58 *backgroundColor,
59 *chargingColor1,
60 *chargingColor2,
61 *dischargingColor1,
62 *dischargingColor2;
63 GdkColor background,
64 charging1,
65 charging2,
66 discharging1,
67 discharging2;
68 cairo_surface_t *pixmap;
69 GtkContainer *box;
70 GtkWidget *drawingArea;
71 GtkOrientation orientation;
72 unsigned int alarmTime,
73 border,
74 height,
75 length,
76 numSamples,
77 requestedBorder,
78 *rateSamples,
79 rateSamplesSum,
80 thickness,
81 timer,
82 state_elapsed_time,
83 info_elapsed_time,
84 wasCharging,
85 width,
86 hide_if_no_battery;
87 sem_t alarmProcessLock;
88 battery* b;
89 gboolean has_ac_adapter;
90 gboolean show_extended_information;
91 LXPanel *panel;
92 config_setting_t *settings;
93 } lx_battery;
94
95
96 typedef struct {
97 char *command;
98 sem_t *lock;
99 } Alarm;
100
101 static void destructor(gpointer data);
102 static void update_display(lx_battery *lx_b, gboolean repaint);
103
104 /* alarmProcess takes the address of a dynamically allocated alarm struct (which
105 it must free). It ensures that alarm commands do not run concurrently. */
106 static void * alarmProcess(void *arg) {
107 Alarm *a = (Alarm *) arg;
108
109 sem_wait(a->lock);
110 if (system(a->command) != 0)
111 g_warning("plugin batt: failed to execute alarm command \"%s\"", a->command);
112 sem_post(a->lock);
113
114 g_free(a);
115 return NULL;
116 }
117
118
119 static void append(gchar **tooltip, gchar *fmt, ...)
120 {
121 gchar *old = *tooltip;
122 gchar *new;
123 va_list va;
124
125 va_start(va, fmt);
126 new = g_strdup_vprintf(fmt, va);
127 va_end(va);
128
129 *tooltip = g_strconcat(old, new, NULL);
130
131 g_free(old);
132 g_free(new);
133 }
134
135
136 /* Make a tooltip string, and display remaining charge time if the battery
137 is charging or remaining life if it's discharging */
138 static gchar* make_tooltip(lx_battery* lx_b, gboolean isCharging)
139 {
140 gchar * tooltip;
141 gchar * indent = " ";
142 battery *b = lx_b->b;
143
144 if (b == NULL)
145 return NULL;
146
147 if (isCharging) {
148 int hours = lx_b->b->seconds / 3600;
149 int left_seconds = lx_b->b->seconds - 3600 * hours;
150 int minutes = left_seconds / 60;
151 tooltip = g_strdup_printf(
152 _("Battery: %d%% charged, %d:%02d until full"),
153 lx_b->b->percentage,
154 hours,
155 minutes );
156 } else {
157 /* if we have enough rate information for battery */
158 if (lx_b->b->percentage != 100) {
159 int hours = lx_b->b->seconds / 3600;
160 int left_seconds = lx_b->b->seconds - 3600 * hours;
161 int minutes = left_seconds / 60;
162 tooltip = g_strdup_printf(
163 _("Battery: %d%% charged, %d:%02d left"),
164 lx_b->b->percentage,
165 hours,
166 minutes );
167 } else {
168 tooltip = g_strdup_printf(
169 _("Battery: %d%% charged"),
170 100 );
171 }
172 }
173
174 if (!lx_b->show_extended_information) {
175 return tooltip;
176 }
177
178 if (b->energy_full_design != -1)
179 append(&tooltip, _("\n%sEnergy full design:\t\t%5d mWh"), indent, b->energy_full_design);
180 if (b->energy_full != -1)
181 append(&tooltip, _("\n%sEnergy full:\t\t\t%5d mWh"), indent, b->energy_full);
182 if (b->energy_now != -1)
183 append(&tooltip, _("\n%sEnergy now:\t\t\t%5d mWh"), indent, b->energy_now);
184 if (b->power_now != -1)
185 append(&tooltip, _("\n%sPower now:\t\t\t%5d mW"), indent, b->power_now);
186
187 if (b->charge_full_design != -1)
188 append(&tooltip, _("\n%sCharge full design:\t%5d mAh"), indent, b->charge_full_design);
189 if (b->charge_full != -1)
190 append(&tooltip, _("\n%sCharge full:\t\t\t%5d mAh"), indent, b->charge_full);
191 if (b->charge_now != -1)
192 append(&tooltip, _("\n%sCharge now:\t\t\t%5d mAh"), indent, b->charge_now);
193 if (b->current_now != -1)
194 append(&tooltip, _("\n%sCurrent now:\t\t\t%5d mA"), indent, b->current_now);
195
196 if (b->voltage_now != -1)
197 append(&tooltip, _("\n%sCurrent Voltage:\t\t%.3lf V"), indent, b->voltage_now / 1000.0);
198
199 return tooltip;
200 }
201
202 static void set_tooltip_text(lx_battery* lx_b)
203 {
204 if (lx_b->b == NULL)
205 return;
206 gboolean isCharging = battery_is_charging(lx_b->b);
207 gchar *tooltip = make_tooltip(lx_b, isCharging);
208 gtk_widget_set_tooltip_text(lx_b->drawingArea, tooltip);
209 g_free(tooltip);
210 }
211
212 /* FIXME:
213 Don't repaint if percentage of remaining charge and remaining time aren't changed. */
214 void update_display(lx_battery *lx_b, gboolean repaint) {
215 cairo_t *cr;
216 battery *b = lx_b->b;
217 /* unit: mW */
218 int rate;
219 gboolean isCharging;
220
221 if (! lx_b->pixmap )
222 return;
223
224 cr = cairo_create(lx_b->pixmap);
225 cairo_set_line_width (cr, 1.0);
226
227 /* draw background */
228 gdk_cairo_set_source_color(cr, &lx_b->background);
229 cairo_rectangle(cr, 0, 0, lx_b->width, lx_b->height);
230 cairo_fill(cr);
231
232 /* no battery is found */
233 if( b == NULL )
234 {
235 gtk_widget_set_tooltip_text( lx_b->drawingArea, _("No batteries found") );
236 if (lx_b->hide_if_no_battery)
237 {
238 gtk_widget_hide(gtk_widget_get_parent(lx_b->drawingArea));
239 repaint = FALSE;
240 }
241 goto update_done;
242 }
243
244 /* fixme: only one battery supported */
245
246 rate = lx_b->b->current_now;
247 isCharging = battery_is_charging ( b );
248
249 /* Consider running the alarm command */
250 if ( !isCharging && rate > 0 &&
251 ( ( battery_get_remaining( b ) / 60 ) < (int)lx_b->alarmTime ) )
252 {
253 /* Shrug this should be done using glibs process functions */
254 /* Alarms should not run concurrently; determine whether an alarm is
255 already running */
256 int alarmCanRun;
257 sem_getvalue(&(lx_b->alarmProcessLock), &alarmCanRun);
258
259 /* Run the alarm command if it isn't already running */
260 if (alarmCanRun) {
261
262 Alarm *a = (Alarm *) malloc(sizeof(Alarm));
263 a->command = lx_b->alarmCommand;
264 a->lock = &(lx_b->alarmProcessLock);
265
266 /* Manage the alarm process in a new thread, which which will be
267 responsible for freeing the alarm struct it's given */
268 pthread_t alarmThread;
269 pthread_create(&alarmThread, NULL, alarmProcess, a);
270 }
271 }
272
273 set_tooltip_text(lx_b);
274
275 int chargeLevel = lx_b->b->percentage * lx_b->length / 100;
276
277 if (lx_b->orientation == GTK_ORIENTATION_HORIZONTAL) {
278
279 /* Draw the battery bar vertically, using color 1 for the left half and
280 color 2 for the right half */
281 gdk_cairo_set_source_color(cr,
282 isCharging ? &lx_b->charging1 : &lx_b->discharging1);
283 cairo_rectangle(cr, 0, lx_b->height - chargeLevel,
284 lx_b->width / 2, chargeLevel);
285 cairo_fill(cr);
286 gdk_cairo_set_source_color(cr,
287 isCharging ? &lx_b->charging2 : &lx_b->discharging2);
288 cairo_rectangle(cr, lx_b->width / 2, lx_b->height - chargeLevel,
289 (lx_b->width + 1) / 2, chargeLevel);
290 cairo_fill(cr);
291
292 }
293 else {
294
295 /* Draw the battery bar horizontally, using color 1 for the top half and
296 color 2 for the bottom half */
297 gdk_cairo_set_source_color(cr,
298 isCharging ? &lx_b->charging1 : &lx_b->discharging1);
299 cairo_rectangle(cr, 0, 0, chargeLevel, lx_b->height / 2);
300 cairo_fill(cr);
301 gdk_cairo_set_source_color(cr,
302 isCharging ? &lx_b->charging2 : &lx_b->discharging2);
303 cairo_rectangle(cr, 0, (lx_b->height + 1) / 2,
304 chargeLevel, lx_b->height / 2);
305 cairo_fill(cr);
306
307 }
308 gtk_widget_show(gtk_widget_get_parent(lx_b->drawingArea));
309
310 update_done:
311 if( repaint )
312 gtk_widget_queue_draw( lx_b->drawingArea );
313
314 check_cairo_status(cr);
315 cairo_destroy(cr);
316 }
317
318 /* This callback is called every 3 seconds */
319 static int update_timout(lx_battery *lx_b) {
320 battery *bat;
321 if (g_source_is_destroyed(g_main_current_source()))
322 return FALSE;
323 GDK_THREADS_ENTER();
324 lx_b->state_elapsed_time++;
325 lx_b->info_elapsed_time++;
326
327 bat = battery_update( lx_b->b );
328 if (bat == NULL)
329 {
330 battery_free(lx_b->b);
331
332 /* maybe in the mean time a battery has been inserted. */
333 lx_b->b = battery_get();
334 }
335
336 update_display( lx_b, TRUE );
337
338 GDK_THREADS_LEAVE();
339 return TRUE;
340 }
341
342 /* An update will be performed whenever the user clicks on the charge bar */
343 static gboolean buttonPressEvent(GtkWidget *p, GdkEventButton *event,
344 LXPanel *panel)
345 {
346 lx_battery *lx_b = lxpanel_plugin_get_data(p);
347
348 update_display(lx_b, TRUE);
349 /* FIXME: open some application for lid/power management may be? */
350
351 return FALSE;
352 }
353
354 static gint configureEvent(GtkWidget *widget, GdkEventConfigure *event,
355 lx_battery *lx_b)
356 {
357 GtkAllocation allocation;
358
359 ENTER;
360
361 gtk_widget_get_allocation(widget, &allocation);
362 if (allocation.width <= 1 && allocation.height <= 1)
363 {
364 /* If plugin is hidden currently then we get 1x1 here */
365 RET(TRUE);
366 }
367
368 if (lx_b->pixmap)
369 cairo_surface_destroy(lx_b->pixmap);
370
371 /* Update the plugin's dimensions */
372 lx_b->width = allocation.width;
373 lx_b->height = allocation.height;
374 if (lx_b->orientation == GTK_ORIENTATION_HORIZONTAL) {
375 lx_b->length = lx_b->height;
376 }
377 else {
378 lx_b->length = lx_b->width;
379 }
380
381 lx_b->pixmap = cairo_image_surface_create (CAIRO_FORMAT_RGB24, allocation.width,
382 allocation.height);
383 check_cairo_surface_status(&lx_b->pixmap);
384
385 /* Perform an update so the bar will look right in its new orientation */
386 update_display(lx_b, FALSE);
387
388 /* we enforce border width here as it seems GtkEventBox doesn't apply it initially */
389 gtk_container_set_border_width(lx_b->box, lx_b->border);
390
391 RET(TRUE);
392 }
393
394
395 static gint exposeEvent(GtkWidget *widget, GdkEventExpose *event, lx_battery *lx_b) {
396
397 ENTER;
398 cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
399 GtkStyle *style = gtk_widget_get_style(lx_b->drawingArea);
400
401 gdk_cairo_region(cr, event->region);
402 cairo_clip(cr);
403
404 gdk_cairo_set_source_color(cr, &style->black);
405 cairo_set_source_surface(cr, lx_b->pixmap, 0, 0);
406 cairo_paint(cr);
407
408 check_cairo_status(cr);
409 cairo_destroy(cr);
410
411 RET(FALSE);
412 }
413
414 /* updates length, border, and height/width appropriate to orientation */
415 static void updateSizes(lx_battery *b)
416 {
417 b->length = panel_get_height(b->panel);
418 b->border = MIN(b->requestedBorder, (MAX(1, b->length) - 1) / 2);
419 b->length -= 2 * b->border;
420 if (b->orientation == GTK_ORIENTATION_HORIZONTAL)
421 b->height = b->length;
422 else
423 b->width = b->length;
424 }
425
426
427 static GtkWidget * constructor(LXPanel *panel, config_setting_t *settings)
428 {
429 ENTER;
430
431 lx_battery *lx_b;
432 GtkWidget *p;
433 const char *str;
434 int tmp_int;
435
436 lx_b = g_new0(lx_battery, 1);
437
438 /* get available battery */
439 lx_b->b = battery_get ();
440
441 p = gtk_event_box_new();
442 lxpanel_plugin_set_data(p, lx_b, destructor);
443 gtk_widget_set_has_window(p, FALSE);
444
445 lx_b->box = GTK_CONTAINER(p);
446 lx_b->drawingArea = gtk_drawing_area_new();
447 gtk_widget_add_events( lx_b->drawingArea, GDK_BUTTON_PRESS_MASK );
448
449 gtk_container_add(lx_b->box, lx_b->drawingArea);
450
451 lx_b->orientation = panel_get_orientation(panel);
452
453 gtk_widget_show(lx_b->drawingArea);
454
455 sem_init(&(lx_b->alarmProcessLock), 0, 1);
456
457 lx_b->alarmCommand = lx_b->backgroundColor = lx_b->chargingColor1 = lx_b->chargingColor2
458 = lx_b->dischargingColor1 = lx_b->dischargingColor2 = NULL;
459
460 /* Set default values for integers */
461 lx_b->alarmTime = 5;
462 lx_b->requestedBorder = 1;
463 lx_b->thickness = 8;
464
465 /* remember instance data */
466 lx_b->panel = panel;
467 lx_b->settings = settings;
468
469 lx_b->show_extended_information = FALSE;
470
471 if (config_setting_lookup_int(settings, "HideIfNoBattery", &tmp_int))
472 lx_b->hide_if_no_battery = (tmp_int != 0);
473 if (config_setting_lookup_string(settings, "AlarmCommand", &str))
474 lx_b->alarmCommand = g_strdup(str);
475 if (config_setting_lookup_string(settings, "BackgroundColor", &str))
476 lx_b->backgroundColor = g_strdup(str);
477 if (config_setting_lookup_string(settings, "ChargingColor1", &str))
478 lx_b->chargingColor1 = g_strdup(str);
479 if (config_setting_lookup_string(settings, "ChargingColor2", &str))
480 lx_b->chargingColor2 = g_strdup(str);
481 if (config_setting_lookup_string(settings, "DischargingColor1", &str))
482 lx_b->dischargingColor1 = g_strdup(str);
483 if (config_setting_lookup_string(settings, "DischargingColor2", &str))
484 lx_b->dischargingColor2 = g_strdup(str);
485 if (config_setting_lookup_int(settings, "AlarmTime", &tmp_int))
486 lx_b->alarmTime = MAX(0, tmp_int);
487 if (config_setting_lookup_int(settings, "BorderWidth", &tmp_int))
488 lx_b->requestedBorder = CLAMP(tmp_int, 0, 6);
489 if (config_setting_lookup_int(settings, "Size", &tmp_int))
490 lx_b->thickness = MAX(1, tmp_int);
491 if (config_setting_lookup_int(settings, "ShowExtendedInformation", &tmp_int))
492 lx_b->show_extended_information = (tmp_int != 0);
493
494 /* Make sure the border value is acceptable */
495 updateSizes(lx_b);
496 if (lx_b->orientation == GTK_ORIENTATION_HORIZONTAL)
497 {
498 lx_b->width = lx_b->thickness;
499 gtk_widget_set_size_request(lx_b->drawingArea, lx_b->width, -1);
500 }
501 else
502 {
503 lx_b->height = lx_b->thickness;
504 gtk_widget_set_size_request(lx_b->drawingArea, -1, lx_b->height);
505 }
506 gtk_container_set_border_width(lx_b->box, lx_b->border);
507
508 g_signal_connect (G_OBJECT (lx_b->drawingArea),"configure-event",
509 G_CALLBACK (configureEvent), (gpointer) lx_b);
510 g_signal_connect (G_OBJECT (lx_b->drawingArea), "expose-event",
511 G_CALLBACK (exposeEvent), (gpointer) lx_b);
512
513 /* Apply more default options */
514 if (! lx_b->alarmCommand)
515 lx_b->alarmCommand = g_strconcat("xmessage ", _("Battery low"), NULL);
516 if (! lx_b->backgroundColor)
517 lx_b->backgroundColor = g_strdup("black");
518 if (! lx_b->chargingColor1)
519 lx_b->chargingColor1 = g_strdup("#28f200");
520 if (! lx_b->chargingColor2)
521 lx_b->chargingColor2 = g_strdup("#22cc00");
522 if (! lx_b->dischargingColor1)
523 lx_b->dischargingColor1 = g_strdup("#ffee00");
524 if (! lx_b->dischargingColor2)
525 lx_b->dischargingColor2 = g_strdup("#d9ca00");
526
527 gdk_color_parse(lx_b->backgroundColor, &lx_b->background);
528 gdk_color_parse(lx_b->chargingColor1, &lx_b->charging1);
529 gdk_color_parse(lx_b->chargingColor2, &lx_b->charging2);
530 gdk_color_parse(lx_b->dischargingColor1, &lx_b->discharging1);
531 gdk_color_parse(lx_b->dischargingColor2, &lx_b->discharging2);
532
533 /* Start the update loop */
534 lx_b->timer = g_timeout_add_seconds( 9, (GSourceFunc) update_timout, (gpointer) lx_b);
535
536 RET(p);
537 }
538
539
540 static void
541 destructor(gpointer data)
542 {
543 ENTER;
544
545 lx_battery *b = (lx_battery *)data;
546
547 if (b->b != NULL)
548 battery_free(b->b);
549
550 if (b->pixmap)
551 cairo_surface_destroy(b->pixmap);
552
553 g_free(b->alarmCommand);
554 g_free(b->backgroundColor);
555 g_free(b->chargingColor1);
556 g_free(b->chargingColor2);
557 g_free(b->dischargingColor1);
558 g_free(b->dischargingColor2);
559
560 g_free(b->rateSamples);
561 sem_destroy(&(b->alarmProcessLock));
562 if (b->timer)
563 g_source_remove(b->timer);
564 g_free(b);
565
566 RET();
567
568 }
569
570
571 static void orientation(LXPanel *panel, GtkWidget *p) {
572
573 ENTER;
574
575 lx_battery *b = lxpanel_plugin_get_data(p);
576
577 if (b->orientation != panel_get_orientation(panel)) {
578 b->orientation = panel_get_orientation(panel);
579 updateSizes(b);
580 if (b->orientation == GTK_ORIENTATION_HORIZONTAL)
581 {
582 b->width = b->thickness;
583 gtk_widget_set_size_request(b->drawingArea, b->width, -1);
584 }
585 else
586 {
587 b->height = b->thickness;
588 gtk_widget_set_size_request(b->drawingArea, -1, b->height);
589 }
590 }
591
592 RET();
593 }
594
595
596 static gboolean applyConfig(gpointer user_data)
597 {
598 ENTER;
599
600 lx_battery *b = lxpanel_plugin_get_data(user_data);
601
602 /* Update colors */
603 if (b->backgroundColor &&
604 gdk_color_parse(b->backgroundColor, &b->background))
605 config_group_set_string(b->settings, "BackgroundColor", b->backgroundColor);
606 if (b->chargingColor1 && gdk_color_parse(b->chargingColor1, &b->charging1))
607 config_group_set_string(b->settings, "ChargingColor1", b->chargingColor1);
608 if (b->chargingColor2 && gdk_color_parse(b->chargingColor2, &b->charging2))
609 config_group_set_string(b->settings, "ChargingColor2", b->chargingColor2);
610 if (b->dischargingColor1 &&
611 gdk_color_parse(b->dischargingColor1, &b->discharging1))
612 config_group_set_string(b->settings, "DischargingColor1", b->dischargingColor1);
613 if (b->dischargingColor2 &&
614 gdk_color_parse(b->dischargingColor2, &b->discharging2))
615 config_group_set_string(b->settings, "DischargingColor2", b->dischargingColor2);
616
617 /* Make sure it is at least 1 px */
618 if (b->thickness < 1)
619 b->thickness = 1;
620
621 /* Make sure the border value is acceptable */
622 b->requestedBorder = MIN(b->requestedBorder, 6);
623 updateSizes(b);
624
625 /* Resize the widget */
626 gtk_container_set_border_width(b->box, b->border);
627 if (b->orientation == GTK_ORIENTATION_HORIZONTAL)
628 {
629 b->width = b->thickness;
630 gtk_widget_set_size_request(b->drawingArea, b->width, -1);
631 }
632 else
633 {
634 b->height = b->thickness;
635 gtk_widget_set_size_request(b->drawingArea, -1, b->height);
636 }
637 /* ensure visibility if requested */
638 if (!b->hide_if_no_battery)
639 gtk_widget_show(user_data);
640 else if (b->b == NULL)
641 gtk_widget_hide(user_data);
642
643 if (b->alarmCommand == NULL)
644 b->alarmCommand = g_strconcat("xmessage ", _("Battery low"), NULL);
645
646 /* update tooltip */
647 set_tooltip_text(b);
648
649 /* update settings */
650 config_group_set_int(b->settings, "HideIfNoBattery", b->hide_if_no_battery);
651 config_group_set_string(b->settings, "AlarmCommand", b->alarmCommand);
652 config_group_set_int(b->settings, "AlarmTime", b->alarmTime);
653 config_group_set_int(b->settings, "BorderWidth", b->requestedBorder);
654 config_group_set_int(b->settings, "Size", b->thickness);
655 config_group_set_int(b->settings, "ShowExtendedInformation",
656 b->show_extended_information);
657
658 RET(FALSE);
659 }
660
661
662 static GtkWidget *config(LXPanel *panel, GtkWidget *p) {
663 lx_battery *b = lxpanel_plugin_get_data(p);
664 return lxpanel_generic_config_dlg(_("Battery Monitor"),
665 panel, applyConfig, p,
666 _("Hide if there is no battery"), &b->hide_if_no_battery, CONF_TYPE_BOOL,
667 _("Alarm command"), &b->alarmCommand, CONF_TYPE_STR,
668 _("Alarm time (minutes left)"), &b->alarmTime, CONF_TYPE_INT,
669 _("Background color"), &b->backgroundColor, CONF_TYPE_STR,
670 _("Charging color 1"), &b->chargingColor1, CONF_TYPE_STR,
671 _("Charging color 2"), &b->chargingColor2, CONF_TYPE_STR,
672 _("Discharging color 1"), &b->dischargingColor1, CONF_TYPE_STR,
673 _("Discharging color 2"), &b->dischargingColor2, CONF_TYPE_STR,
674 _("Border width"), &b->requestedBorder, CONF_TYPE_INT,
675 _("Size"), &b->thickness, CONF_TYPE_INT,
676 _("Show Extended Information"), &b->show_extended_information, CONF_TYPE_BOOL,
677 NULL);
678 }
679
680
681 FM_DEFINE_MODULE(lxpanel_gtk, batt)
682
683 /* Plugin descriptor. */
684 LXPanelPluginInit fm_module_init_lxpanel_gtk = {
685 .name = N_("Battery Monitor"),
686 .description = N_("Display battery status using ACPI"),
687
688 .new_instance = constructor,
689 .config = config,
690 .reconfigure = orientation,
691 .button_press_event = buttonPressEvent
692 };
693
694
695 /* vim: set sw=4 sts=4 : */