all repos — tint2 @ df241dfd895a0b4332672557c90aa6f5b97b9527

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

src/battery/battery.h (raw)

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
116
117
/**************************************************************************
* Copyright (C) 2009-2015 Sebastian Reichel <sre@ring0.de>
*
* 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"

typedef struct Battery {
	Area area;
	Color font_color;
	int bat1_posy;
	int bat2_posy;
} Battery;

typedef enum ChargeState {
	BATTERY_UNKNOWN = 0,
	BATTERY_CHARGING,
	BATTERY_DISCHARGING,
	BATTERY_FULL,
} ChargeState;

typedef struct BatteryTime {
	int16_t hours;
	int8_t minutes;
	int8_t seconds;
} BatteryTime;

typedef struct BatteryState {
	int percentage;
	BatteryTime time;
	ChargeState state;
	gboolean ac_connected;
} BatteryState;

extern struct BatteryState battery_state;
extern gboolean bat1_has_font;
extern PangoFontDescription *bat1_font_desc;
extern gboolean bat2_has_font;
extern PangoFontDescription *bat2_font_desc;
extern gboolean battery_enabled;
extern gboolean battery_tooltip_enabled;
extern int percentage_hide;

extern int8_t battery_low_status;
extern char *battery_low_cmd;

extern char *ac_connected_cmd;
extern char *ac_disconnected_cmd;

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;

static inline gchar *chargestate2str(ChargeState state)
{
	switch (state) {
	case BATTERY_CHARGING:
		return "Charging";
	case BATTERY_DISCHARGING:
		return "Discharging";
	case BATTERY_FULL:
		return "Full";
	case BATTERY_UNKNOWN:
	default:
		return "Unknown";
	};
}

static inline void battery_state_set_time(BatteryState *state, int seconds)
{
	state->time.hours = seconds / 3600;
	seconds -= 3600 * state->time.hours;
	state->time.minutes = seconds / 60;
	seconds -= 60 * state->time.minutes;
	state->time.seconds = seconds;
}

// default global data
void default_battery();

// freed memory
void cleanup_battery();

void update_battery_tick(void *arg);
int update_battery();

void init_battery();
void init_battery_panel(void *panel);

void reinit_battery();
void draw_battery(void *obj, cairo_t *c);
void battery_default_font_changed();

gboolean resize_battery(void *obj);

void battery_action(int button);

/* operating system specific functions */
gboolean battery_os_init();
void battery_os_free();
int battery_os_update(BatteryState *state);
char *battery_os_tooltip();

#endif