2009-05-15 20:48:55 +00:00
|
|
|
/**************************************************************************
|
2015-08-05 00:25:54 +00:00
|
|
|
* Copyright (C) 2009-2015 Sebastian Reichel <sre@ring0.de>
|
2009-05-15 20:48:55 +00:00
|
|
|
*
|
|
|
|
* Battery with functional data (percentage, time to life) and drawing data
|
|
|
|
* (area, font, ...). Each panel use his own drawing data.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef BATTERY_H
|
|
|
|
#define BATTERY_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "area.h"
|
|
|
|
|
2009-10-28 23:01:32 +00:00
|
|
|
// battery drawing parameter (per panel)
|
2009-05-15 20:48:55 +00:00
|
|
|
typedef struct Battery {
|
2009-09-20 20:48:00 +00:00
|
|
|
// always start with area
|
|
|
|
Area area;
|
2009-05-15 20:48:55 +00:00
|
|
|
|
2010-01-09 00:11:01 +00:00
|
|
|
Color font;
|
2009-09-20 20:48:00 +00:00
|
|
|
int bat1_posy;
|
|
|
|
int bat2_posy;
|
2009-05-15 20:48:55 +00:00
|
|
|
} Battery;
|
|
|
|
|
2015-11-23 15:12:42 +00:00
|
|
|
typedef enum ChargeState {
|
|
|
|
BATTERY_UNKNOWN = 0,
|
|
|
|
BATTERY_CHARGING,
|
|
|
|
BATTERY_DISCHARGING,
|
|
|
|
BATTERY_FULL,
|
|
|
|
} ChargeState;
|
|
|
|
|
|
|
|
typedef struct BatteryTime {
|
2009-05-15 20:48:55 +00:00
|
|
|
int16_t hours;
|
|
|
|
int8_t minutes;
|
|
|
|
int8_t seconds;
|
2015-11-23 15:12:42 +00:00
|
|
|
} BatteryTime;
|
2009-05-15 20:48:55 +00:00
|
|
|
|
2015-11-23 15:12:42 +00:00
|
|
|
typedef struct BatteryState {
|
2009-05-15 20:48:55 +00:00
|
|
|
int percentage;
|
2015-11-23 15:12:42 +00:00
|
|
|
BatteryTime time;
|
|
|
|
ChargeState state;
|
2015-08-07 03:20:24 +00:00
|
|
|
gboolean ac_connected;
|
2015-11-23 15:12:42 +00:00
|
|
|
} BatteryState;
|
2009-05-15 20:48:55 +00:00
|
|
|
|
2015-11-23 15:12:42 +00:00
|
|
|
extern struct BatteryState battery_state;
|
2009-05-15 20:48:55 +00:00
|
|
|
extern PangoFontDescription *bat1_font_desc;
|
|
|
|
extern PangoFontDescription *bat2_font_desc;
|
2015-11-20 22:28:37 +00:00
|
|
|
extern gboolean battery_enabled;
|
|
|
|
extern gboolean battery_tooltip_enabled;
|
2010-01-19 19:29:28 +00:00
|
|
|
extern int percentage_hide;
|
2009-05-15 20:48:55 +00:00
|
|
|
|
|
|
|
extern int8_t battery_low_status;
|
2009-05-31 12:40:40 +00:00
|
|
|
extern char *battery_low_cmd;
|
|
|
|
|
2015-08-07 03:20:24 +00:00
|
|
|
extern char *ac_connected_cmd;
|
|
|
|
extern char *ac_disconnected_cmd;
|
|
|
|
|
2015-07-13 03:16:02 +00:00
|
|
|
extern char *battery_lclick_command;
|
|
|
|
extern char *battery_mclick_command;
|
|
|
|
extern char *battery_rclick_command;
|
|
|
|
extern char *battery_uwheel_command;
|
|
|
|
extern char *battery_dwheel_command;
|
|
|
|
|
2015-11-23 15:12:42 +00:00
|
|
|
static inline gchar *chargestate2str(ChargeState state)
|
2015-11-20 22:28:37 +00:00
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case BATTERY_CHARGING:
|
|
|
|
return "Charging";
|
|
|
|
case BATTERY_DISCHARGING:
|
|
|
|
return "Discharging";
|
|
|
|
case BATTERY_FULL:
|
|
|
|
return "Full";
|
|
|
|
case BATTERY_UNKNOWN:
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
2015-08-05 00:15:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-11-23 15:12:42 +00:00
|
|
|
static inline void battery_state_set_time(BatteryState *state, int seconds)
|
2015-11-20 22:28:37 +00:00
|
|
|
{
|
2015-08-07 02:31:31 +00:00
|
|
|
state->time.hours = seconds / 3600;
|
|
|
|
seconds -= 3600 * state->time.hours;
|
|
|
|
state->time.minutes = seconds / 60;
|
|
|
|
seconds -= 60 * state->time.minutes;
|
|
|
|
state->time.seconds = seconds;
|
|
|
|
}
|
|
|
|
|
2010-04-18 14:28:45 +00:00
|
|
|
// default global data
|
2010-04-18 12:07:36 +00:00
|
|
|
void default_battery();
|
2010-04-18 14:28:45 +00:00
|
|
|
|
2010-04-18 12:07:36 +00:00
|
|
|
// freed memory
|
|
|
|
void cleanup_battery();
|
2009-05-15 20:48:55 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
void update_battery_tick(void *arg);
|
2015-03-28 18:08:44 +00:00
|
|
|
int update_battery();
|
2009-05-15 20:48:55 +00:00
|
|
|
|
|
|
|
void init_battery();
|
2009-10-18 17:54:09 +00:00
|
|
|
void init_battery_panel(void *panel);
|
2010-04-16 18:50:03 +00:00
|
|
|
|
2015-10-18 15:28:58 +00:00
|
|
|
void reinit_battery();
|
2010-01-09 00:11:01 +00:00
|
|
|
void draw_battery(void *obj, cairo_t *c);
|
2009-05-15 20:48:55 +00:00
|
|
|
|
2015-11-20 22:28:37 +00:00
|
|
|
gboolean resize_battery(void *obj);
|
2009-05-15 20:48:55 +00:00
|
|
|
|
2015-07-13 03:16:02 +00:00
|
|
|
void battery_action(int button);
|
|
|
|
|
2015-08-07 02:31:31 +00:00
|
|
|
/* operating system specific functions */
|
|
|
|
gboolean battery_os_init();
|
|
|
|
void battery_os_free();
|
2015-11-23 15:12:42 +00:00
|
|
|
int battery_os_update(BatteryState *state);
|
2015-11-20 22:28:37 +00:00
|
|
|
char *battery_os_tooltip();
|
2015-08-04 22:17:32 +00:00
|
|
|
|
2009-05-15 20:48:55 +00:00
|
|
|
#endif
|