Commit 4a693782 authored by o9000's avatar o9000

Cleanup indentation with clang-format and changed a few variable names

parent c0e62e2e
# works with clang-format-3.7
#
# Most controversial fields are UseTab, IndentWidth, ContinuationIndentWidth, ColumnLimit, BreakBeforeBraces
#BasedOnStyle: Google
AccessModifierOffset: 0
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: false
#AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DerivePointerBinding: false
DisableFormat: false
ForEachMacros: ['foreach']
IndentCaseLabels: false
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
IndentWrappedFunctionNames: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 1000
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 100
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 2000
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: ForIndentation
build
*.user
......@@ -170,7 +170,7 @@ endif( RT_LIBRARY )
target_link_libraries( tint2 m )
add_dependencies( tint2 version )
set_target_properties( tint2 PROPERTIES COMPILE_FLAGS "-Wall -fno-strict-aliasing -pthread ${ASAN_C_FLAGS}" )
set_target_properties( tint2 PROPERTIES COMPILE_FLAGS "-Wall -Wshadow -Wpointer-arith -fno-strict-aliasing -pthread ${ASAN_C_FLAGS}" )
set_target_properties( tint2 PROPERTIES LINK_FLAGS "-pthread -fno-strict-aliasing ${ASAN_L_FLAGS}" )
install( TARGETS tint2 DESTINATION bin )
......
......@@ -34,10 +34,10 @@
PangoFontDescription *bat1_font_desc;
PangoFontDescription *bat2_font_desc;
struct batstate battery_state;
int battery_enabled;
int battery_tooltip_enabled;
gboolean battery_enabled;
gboolean battery_tooltip_enabled;
int percentage_hide;
static timeout* battery_timeout;
static timeout *battery_timeout;
static char buf_bat_percentage[10];
static char buf_bat_time[20];
......@@ -54,7 +54,7 @@ char *battery_uwheel_command;
char *battery_dwheel_command;
int battery_found;
void update_battery_tick(void* arg)
void update_battery_tick(void *arg)
{
if (!battery_enabled)
return;
......@@ -64,7 +64,7 @@ void update_battery_tick(void* arg)
gboolean old_ac_connected = battery_state.ac_connected;
int16_t old_hours = battery_state.time.hours;
int8_t old_minutes = battery_state.time.minutes;
if (!battery_found) {
init_battery();
old_ac_connected = battery_state.ac_connected;
......@@ -81,48 +81,44 @@ void update_battery_tick(void* arg)
tint_exec(ac_disconnected_cmd);
}
if (old_found == battery_found &&
old_percentage == battery_state.percentage &&
old_hours == battery_state.time.hours &&
old_minutes == battery_state.time.minutes) {
if (old_found == battery_found && old_percentage == battery_state.percentage &&
old_hours == battery_state.time.hours && old_minutes == battery_state.time.minutes) {
return;
}
if (battery_state.percentage < battery_low_status &&
battery_state.state == BATTERY_DISCHARGING &&
if (battery_state.percentage < battery_low_status && battery_state.state == BATTERY_DISCHARGING &&
!battery_low_cmd_sent) {
tint_exec(battery_low_cmd);
battery_low_cmd_sent = 1;
}
if (battery_state.percentage > battery_low_status &&
battery_state.state == BATTERY_CHARGING &&
if (battery_state.percentage > battery_low_status && battery_state.state == BATTERY_CHARGING &&
battery_low_cmd_sent) {
battery_low_cmd_sent = 0;
}
int i;
for (i = 0; i < nb_panel; i++) {
for (i = 0; i < num_panels; i++) {
if (!battery_found) {
if (panel1[i].battery.area.on_screen == 1) {
hide(&panel1[i].battery.area);
panel_refresh = 1;
if (panels[i].battery.area.on_screen) {
hide(&panels[i].battery.area);
panel_refresh = TRUE;
}
} else {
if (battery_state.percentage >= percentage_hide) {
if (panel1[i].battery.area.on_screen == 1) {
hide(&panel1[i].battery.area);
panel_refresh = 1;
if (panels[i].battery.area.on_screen) {
hide(&panels[i].battery.area);
panel_refresh = TRUE;
}
} else {
if (panel1[i].battery.area.on_screen == 0) {
show(&panel1[i].battery.area);
panel_refresh = 1;
if (panels[i].battery.area.on_screen == 0) {
show(&panels[i].battery.area);
panel_refresh = TRUE;
}
}
}
if (panel1[i].battery.area.on_screen == 1) {
panel1[i].battery.area.resize_needed = 1;
panel_refresh = 1;
if (panels[i].battery.area.on_screen) {
panels[i].battery.area.resize_needed = 1;
panel_refresh = TRUE;
}
}
}
......@@ -200,13 +196,14 @@ void init_battery()
update_battery();
}
char* battery_get_tooltip(void* obj) {
char *battery_get_tooltip(void *obj)
{
return battery_os_tooltip();
}
void init_battery_panel(void *p)
{
Panel *panel = (Panel*)p;
Panel *panel = (Panel *)p;
Battery *battery = &panel->battery;
if (!battery_enabled)
......@@ -217,28 +214,25 @@ void init_battery_panel(void *p)
if (!bat2_font_desc)
bat2_font_desc = pango_font_description_from_string(DEFAULT_FONT);
if (battery->area.bg == 0)
if (!battery->area.bg)
battery->area.bg = &g_array_index(backgrounds, Background, 0);
battery->area.parent = p;
battery->area.panel = p;
battery->area._draw_foreground = draw_battery;
battery->area.size_mode = LAYOUT_FIXED;
battery->area._resize = resize_battery;
battery->area.on_screen = 1;
battery->area.resize_needed = 1;
battery->area.has_mouse_over_effect = battery_lclick_command ||
battery_mclick_command ||
battery_rclick_command ||
battery_uwheel_command ||
battery_dwheel_command;
battery->area.has_mouse_press_effect = battery->area.has_mouse_over_effect;
battery->area.size_mode = LAYOUT_FIXED;
battery->area._resize = resize_battery;
battery->area.on_screen = TRUE;
battery->area.resize_needed = 1;
battery->area.has_mouse_over_effect = battery_lclick_command || battery_mclick_command || battery_rclick_command ||
battery_uwheel_command || battery_dwheel_command;
battery->area.has_mouse_press_effect = battery->area.has_mouse_over_effect;
if (battery_tooltip_enabled)
battery->area._get_tooltip_text = battery_get_tooltip;
}
int update_battery() {
int update_battery()
{
int err;
/* reset */
......@@ -257,13 +251,12 @@ int update_battery() {
return err;
}
void draw_battery (void *obj, cairo_t *c)
void draw_battery(void *obj, cairo_t *c)
{
Battery *battery = obj;
PangoLayout *layout;
layout = pango_cairo_create_layout (c);
layout = pango_cairo_create_layout(c);
// draw layout
pango_layout_set_font_description(layout, bat1_font_desc);
......@@ -273,10 +266,10 @@ void draw_battery (void *obj, cairo_t *c)
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
pango_layout_set_text(layout, buf_bat_percentage, strlen(buf_bat_percentage));
cairo_set_source_rgba(c, battery->font.rgb[0], battery->font.rgb[1], battery->font.rgb[2], battery->font.alpha);
cairo_set_source_rgba(c, battery->font.rgb[0], battery->font.rgb[1], battery->font.rgb[2], battery->font.alpha);
pango_cairo_update_layout(c, layout);
draw_text(layout, c, 0, battery->bat1_posy, &battery->font, ((Panel*)battery->area.panel)->font_shadow);
draw_text(layout, c, 0, battery->bat1_posy, &battery->font, ((Panel *)battery->area.panel)->font_shadow);
pango_layout_set_font_description(layout, bat2_font_desc);
pango_layout_set_indent(layout, 0);
......@@ -286,14 +279,13 @@ void draw_battery (void *obj, cairo_t *c)
pango_layout_set_width(layout, battery->area.width * PANGO_SCALE);
pango_cairo_update_layout(c, layout);
draw_text(layout, c, 0, battery->bat2_posy, &battery->font, ((Panel*)battery->area.panel)->font_shadow);
draw_text(layout, c, 0, battery->bat2_posy, &battery->font, ((Panel *)battery->area.panel)->font_shadow);
pango_cairo_show_layout(c, layout);
g_object_unref(layout);
}
int resize_battery(void *obj)
gboolean resize_battery(void *obj)
{
Battery *battery = obj;
Panel *panel = battery->area.panel;
......@@ -301,28 +293,39 @@ int resize_battery(void *obj)
int bat_time_height, bat_time_width, bat_time_height_ink;
int ret = 0;
battery->area.redraw_needed = 1;
battery->area.redraw_needed = TRUE;
snprintf(buf_bat_percentage, sizeof(buf_bat_percentage), "%d%%", battery_state.percentage);
if (battery_state.state == BATTERY_FULL) {
strcpy(buf_bat_time, "Full");
} else {
snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes);
}
get_text_size2(bat1_font_desc, &bat_percentage_height_ink, &bat_percentage_height, &bat_percentage_width,
panel->area.height, panel->area.width, buf_bat_percentage, strlen(buf_bat_percentage),
get_text_size2(bat1_font_desc,
&bat_percentage_height_ink,
&bat_percentage_height,
&bat_percentage_width,
panel->area.height,
panel->area.width,
buf_bat_percentage,
strlen(buf_bat_percentage),
PANGO_WRAP_WORD_CHAR,
PANGO_ELLIPSIZE_NONE);
get_text_size2(bat2_font_desc, &bat_time_height_ink, &bat_time_height, &bat_time_width,
panel->area.height, panel->area.width, buf_bat_time, strlen(buf_bat_time),
get_text_size2(bat2_font_desc,
&bat_time_height_ink,
&bat_time_height,
&bat_time_width,
panel->area.height,
panel->area.width,
buf_bat_time,
strlen(buf_bat_time),
PANGO_WRAP_WORD_CHAR,
PANGO_ELLIPSIZE_NONE);
if (panel_horizontal) {
int new_size = (bat_percentage_width > bat_time_width) ? bat_percentage_width : bat_time_width;
new_size += 2 * battery->area.paddingxlr + 2 * battery->area.bg->border.width;
if (new_size > battery->area.width ||
new_size < battery->area.width - 2) {
if (new_size > battery->area.width || new_size < battery->area.width - 2) {
// we try to limit the number of resize
battery->area.width = new_size;
battery->bat1_posy = (battery->area.height - bat_percentage_height - bat_time_height) / 2;
......@@ -330,11 +333,10 @@ int resize_battery(void *obj)
ret = 1;
}
} else {
int new_size = bat_percentage_height + bat_time_height +
(2 * (battery->area.paddingxlr + battery->area.bg->border.width));
if (new_size > battery->area.height ||
new_size < battery->area.height - 2) {
battery->area.height = new_size;
int new_size =
bat_percentage_height + bat_time_height + (2 * (battery->area.paddingxlr + battery->area.bg->border.width));
if (new_size > battery->area.height || new_size < battery->area.height - 2) {
battery->area.height = new_size;
battery->bat1_posy = (battery->area.height - bat_percentage_height - bat_time_height - 2) / 2;
battery->bat2_posy = battery->bat1_posy + bat_percentage_height + 2;
ret = 1;
......@@ -347,19 +349,19 @@ void battery_action(int button)
{
char *command = 0;
switch (button) {
case 1:
case 1:
command = battery_lclick_command;
break;
case 2:
case 2:
command = battery_mclick_command;
break;
case 3:
case 3:
command = battery_rclick_command;
break;
case 4:
case 4:
command = battery_uwheel_command;
break;
case 5:
case 5:
command = battery_dwheel_command;
break;
}
......
......@@ -16,7 +16,6 @@
#include "common.h"
#include "area.h"
// battery drawing parameter (per panel)
typedef struct Battery {
// always start with area
......@@ -27,12 +26,7 @@ typedef struct Battery {
int bat2_posy;
} Battery;
enum chargestate {
BATTERY_UNKNOWN,
BATTERY_CHARGING,
BATTERY_DISCHARGING,
BATTERY_FULL
};
enum chargestate { BATTERY_UNKNOWN, BATTERY_CHARGING, BATTERY_DISCHARGING, BATTERY_FULL };
typedef struct battime {
int16_t hours;
......@@ -50,8 +44,8 @@ typedef struct batstate {
extern struct batstate battery_state;
extern PangoFontDescription *bat1_font_desc;
extern PangoFontDescription *bat2_font_desc;
extern int battery_enabled;
extern int battery_tooltip_enabled;
extern gboolean battery_enabled;
extern gboolean battery_tooltip_enabled;
extern int percentage_hide;
extern int8_t battery_low_status;
......@@ -66,21 +60,23 @@ extern char *battery_rclick_command;
extern char *battery_uwheel_command;
extern char *battery_dwheel_command;
static inline gchar* chargestate2str(enum 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 gchar *chargestate2str(enum 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 batstate_set_time(struct batstate *state, int seconds) {
static inline void batstate_set_time(struct batstate *state, int seconds)
{
state->time.hours = seconds / 3600;
seconds -= 3600 * state->time.hours;
state->time.minutes = seconds / 60;
......@@ -94,7 +90,7 @@ void default_battery();
// freed memory
void cleanup_battery();
void update_battery_tick(void* arg);
void update_battery_tick(void *arg);
int update_battery();
void init_battery();
......@@ -103,7 +99,7 @@ void init_battery_panel(void *panel);
void reinit_battery();
void draw_battery(void *obj, cairo_t *c);
int resize_battery(void *obj);
gboolean resize_battery(void *obj);
void battery_action(int button);
......@@ -111,6 +107,6 @@ void battery_action(int button);
gboolean battery_os_init();
void battery_os_free();
int battery_os_update(struct batstate *state);
char* battery_os_tooltip();
char *battery_os_tooltip();
#endif
......@@ -23,18 +23,22 @@
#warning tint2 has no battery support for this operating system!
gboolean battery_os_init() {
gboolean battery_os_init()
{
return FALSE;
}
void battery_os_free() {
void battery_os_free()
{
return;
}
int battery_os_update(struct batstate *state) {
int battery_os_update(struct batstate *state)
{
return -1;
}
char* battery_os_tooltip() {
char *battery_os_tooltip()
{
return strdup("Operating System not supported");
}
......@@ -24,26 +24,29 @@
#include "common.h"
#include "battery.h"
gboolean battery_os_init() {
gboolean battery_os_init()
{
int sysctl_out = 0;
size_t len = sizeof(sysctl_out);
return (sysctlbyname("hw.acpi.battery.state", &sysctl_out, &len, NULL, 0) == 0) ||
(sysctlbyname("hw.acpi.battery.time", &sysctl_out, &len, NULL, 0) == 0) ||
(sysctlbyname("hw.acpi.battery.life", &sysctl_out, &len, NULL, 0) == 0);
(sysctlbyname("hw.acpi.battery.time", &sysctl_out, &len, NULL, 0) == 0) ||
(sysctlbyname("hw.acpi.battery.life", &sysctl_out, &len, NULL, 0) == 0);
}
void battery_os_free() {
void battery_os_free()
{
return;
}
int battery_os_update(struct batstate *state) {
int battery_os_update(struct batstate *state)
{
int sysctl_out = 0;
size_t len = sizeof(sysctl_out);
gboolean err = 0;
if (sysctlbyname("hw.acpi.battery.state", &sysctl_out, &len, NULL, 0) == 0) {
switch(sysctl_out) {
switch (sysctl_out) {
case 1:
state->state = BATTERY_DISCHARGING;
break;
......@@ -71,11 +74,12 @@ int battery_os_update(struct batstate *state) {
if (sysctlbyname("hw.acpi.acline", &sysctl_out, &len, NULL, 0) == 0)
state->ac_connected = sysctl_out;
return err;
}
char* battery_os_tooltip() {
char *battery_os_tooltip()
{
GString *tooltip = g_string_new("");
gchar *result;
......
......@@ -33,65 +33,63 @@ enum psy_type {
struct psy_battery {
/* generic properties */
gchar* name;
gint64 timestamp;
gchar *name;
gint64 timestamp;
/* sysfs files */
gchar* path_present;
gchar* path_energy_now;
gchar* path_energy_full;
gchar* path_power_now;
gchar* path_status;
gchar *path_present;
gchar *path_energy_now;
gchar *path_energy_full;
gchar *path_power_now;
gchar *path_status;
/* sysfs hints */
gboolean energy_in_uamp;
gboolean power_in_uamp;
gboolean energy_in_uamp;
gboolean power_in_uamp;
/* values */
gboolean present;
gint energy_now;
gint energy_full;
gint power_now;
enum chargestate status;
gboolean present;
gint energy_now;
gint energy_full;
gint power_now;
enum chargestate status;
};
struct psy_mains {
/* generic properties */
gchar* name;
gchar *name;
/* sysfs files */
gchar* path_online;
gchar *path_online;
/* values */
gboolean online;
gboolean online;
};
static void uevent_battery_update() {
static void uevent_battery_update()
{
update_battery_tick(NULL);
}
static struct uevent_notify psy_change = {
UEVENT_CHANGE,
"power_supply",
NULL,
uevent_battery_update
};
static struct uevent_notify psy_change = {UEVENT_CHANGE, "power_supply", NULL, uevent_battery_update};
static void uevent_battery_plug() {
static void uevent_battery_plug()
{
printf("reinitialize batteries after HW change\n");
reinit_battery();
}
static struct uevent_notify psy_plug = {
UEVENT_ADD | UEVENT_REMOVE,
"power_supply",
NULL,
uevent_battery_plug
};
static struct uevent_notify psy_plug = {UEVENT_ADD | UEVENT_REMOVE, "power_supply", NULL, uevent_battery_plug};
#define RETURN_ON_ERROR(err) if (error) { g_error_free(err); return FALSE; }
#define RETURN_ON_ERROR(err) \
if (error) { \
g_error_free(err); \
return FALSE; \
}
static GList *batteries = NULL;
static GList *mains = NULL;
static guint8 energy_to_percent(gint energy_now, gint energy_full) {
static guint8 energy_to_percent(gint energy_now, gint energy_full)
{
return 0.5 + ((energy_now <= energy_full ? energy_now : energy_full) * 100.0) / energy_full;
}
static enum psy_type power_supply_get_type(const gchar *entryname) {
static enum psy_type power_supply_get_type(const gchar *entryname)
{
gchar *path_type = g_build_filename("/sys/class/power_supply", entryname, "type", NULL);
GError *error = NULL;
gchar *type;
......@@ -119,7 +117,8 @@ static enum psy_type power_supply_get_type(const gchar *entryname) {
return PSY_UNKNOWN;
}
static gboolean init_linux_battery(struct psy_battery *bat) {
static gboolean init_linux_battery(struct psy_battery *bat)
{
const gchar *entryname = bat->name;
bat->energy_in_uamp = FALSE;
......@@ -181,7 +180,8 @@ err0:
return FALSE;
}
static gboolean init_linux_mains(struct psy_mains *ac) {
static gboolean init_linux_mains(struct psy_mains *ac)
{
const gchar *entryname = ac->name;
ac->path_online = g_build_filename("/sys/class/power_supply", entryname, "online", NULL);
......@@ -193,7 +193,8 @@ static gboolean init_linux_mains(struct psy_mains *ac) {
return TRUE;
}
static void psy_battery_free(gpointer data) {
static void psy_battery_free(gpointer data)
{
struct psy_battery *bat = data;
g_free(bat->name);
g_free(bat->path_status);
......@@ -204,14 +205,16 @@ static void psy_battery_free(gpointer data) {
g_free(bat);
}
static void psy_mains_free(gpointer data) {
static void psy_mains_free(gpointer data)
{
struct psy_mains *ac = data;
g_free(ac->name);
g_free(ac->path_online);
g_free(ac);
}
void battery_os_free() {
void battery_os_free()
{
uevent_unregister_notifier(&psy_change);
uevent_unregister_notifier(&psy_plug);
......@@ -221,7 +224,8 @@ void battery_os_free() {
mains = NULL;
}
static void add_battery(const char *entryname) {
static void add_battery(const char *entryname)
{
struct psy_battery *bat = g_malloc0(sizeof(*bat));
bat->name = g_strdup(entryname);
......@@ -234,7 +238,8 @@ static void add_battery(const char *entryname) {
}
}
static void add_mains(const char *entryname) {
static void add_mains(const char *entryname)
{
struct psy_mains *ac = g_malloc0(sizeof(*ac));
ac->name = g_strdup(entryname);
......@@ -247,7 +252,8 @@ static void add_mains(const char *entryname) {
}
}
gboolean battery_os_init() {
gboolean battery_os_init()
{
GDir *directory = 0;
GError *error = NULL;
const char *entryname;
......@@ -260,15 +266,15 @@ gboolean battery_os_init() {
while ((entryname = g_dir_read_name(directory))) {
enum psy_type type = power_supply_get_type(entryname);
switch(type) {
case PSY_BATTERY:
add_battery(entryname);
break;
case PSY_MAINS:
add_mains(entryname);
break;
default:
break;
switch (type) {
case PSY_BATTERY:
add_battery(entryname);