From 737150d7e97df32b03eec062a3eb955145950663 Mon Sep 17 00:00:00 2001 From: o9000 Date: Sun, 27 Dec 2015 15:39:39 +0100 Subject: [PATCH] Work better with empty config files --- src/clock/clock.h | 2 +- src/config.c | 46 ++++++++++++++++++++++++++----------------- src/panel.c | 18 +++++++++++++++++ src/taskbar/taskbar.c | 6 +++++- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/clock/clock.h b/src/clock/clock.h index 40b6f50..511c982 100644 --- a/src/clock/clock.h +++ b/src/clock/clock.h @@ -37,7 +37,7 @@ extern char *clock_mclick_command; extern char *clock_rclick_command; extern char *clock_uwheel_command; extern char *clock_dwheel_command; -extern int clock_enabled; +extern gboolean clock_enabled; // default global data void default_clock(); diff --git a/src/config.c b/src/config.c index 45d1c09..7f14280 100644 --- a/src/config.c +++ b/src/config.c @@ -69,18 +69,20 @@ char *snapshot_path; // -------------------------------------------------- // backward compatibility // detect if it's an old config file (==1) -static int new_config_file; +static gboolean new_config_file; -static int read_bg_color_hover; -static int read_border_color_hover; -static int read_bg_color_press; -static int read_border_color_press; +static gboolean read_bg_color_hover; +static gboolean read_border_color_hover; +static gboolean read_bg_color_press; +static gboolean read_border_color_press; +static gboolean read_panel_position; void default_config() { config_path = NULL; snapshot_path = NULL; - new_config_file = 0; + new_config_file = FALSE; + read_panel_position = FALSE; } void cleanup_config() @@ -318,7 +320,7 @@ void add_entry(char *key, char *value) panel_config.area.height = atoi(value2); } } else if (strcmp(key, "panel_items") == 0) { - new_config_file = 1; + new_config_file = TRUE; panel_items_order = strdup(value); systray_enabled = 0; launcher_enabled = 0; @@ -360,6 +362,7 @@ void add_entry(char *key, char *value) if (value3) panel_config.area.paddingx = atoi(value3); } else if (strcmp(key, "panel_position") == 0) { + read_panel_position = TRUE; extract_values(value, &value1, &value2, &value3); if (strcmp(value1, "top") == 0) panel_position = TOP; @@ -620,19 +623,20 @@ void add_entry(char *key, char *value) /* Clock */ else if (strcmp(key, "time1_format") == 0) { - if (new_config_file == 0) { - clock_enabled = 1; + if (!new_config_file) { + clock_enabled = TRUE; if (panel_items_order) { gchar *tmp = g_strconcat(panel_items_order, "C", NULL); free(panel_items_order); panel_items_order = strdup(tmp); g_free(tmp); - } else + } else { panel_items_order = strdup("C"); + } } if (strlen(value) > 0) { time1_format = strdup(value); - clock_enabled = 1; + clock_enabled = TRUE; } } else if (strcmp(key, "time2_format") == 0) { if (strlen(value) > 0) @@ -846,8 +850,8 @@ void add_entry(char *key, char *value) /* Systray */ else if (strcmp(key, "systray_padding") == 0) { - if (new_config_file == 0 && systray_enabled == 0) { - systray_enabled = 1; + if (!new_config_file && systray_enabled == 0) { + systray_enabled = TRUE; if (panel_items_order) { gchar *tmp = g_strconcat(panel_items_order, "S", NULL); free(panel_items_order); @@ -1006,7 +1010,7 @@ void add_entry(char *key, char *value) // old config option else if (strcmp(key, "systray") == 0) { - if (new_config_file == 0) { + if (!new_config_file) { systray_enabled = atoi(value); if (systray_enabled) { if (panel_items_order) { @@ -1021,7 +1025,7 @@ void add_entry(char *key, char *value) } #ifdef ENABLE_BATTERY else if (strcmp(key, "battery") == 0) { - if (new_config_file == 0) { + if (!new_config_file) { battery_enabled = atoi(value); if (battery_enabled) { if (panel_items_order) { @@ -1064,16 +1068,22 @@ gboolean config_read_file(const char *path) } fclose(fp); + if (!read_panel_position) { + panel_horizontal = TRUE; + panel_position = BOTTOM; + } + // append Taskbar item - if (new_config_file == 0) { - taskbar_enabled = 1; + if (!new_config_file) { + taskbar_enabled = TRUE; if (panel_items_order) { gchar *tmp = g_strconcat("T", panel_items_order, NULL); free(panel_items_order); panel_items_order = strdup(tmp); g_free(tmp); - } else + } else { panel_items_order = strdup("T"); + } } if (backgrounds->len > 0) { diff --git a/src/panel.c b/src/panel.c index b975918..e5a0cff 100644 --- a/src/panel.c +++ b/src/panel.c @@ -156,6 +156,8 @@ void init_panel() panel_config.monitor = 0; } + fprintf(stderr, "panel items: %s\n", panel_items_order); + init_tooltip(); init_systray(); init_launcher(); @@ -269,6 +271,14 @@ void init_panel_size_and_position(Panel *panel) { // detect panel size if (panel_horizontal) { + if (panel->area.width == 0) { + panel->fractional_width = TRUE; + panel->area.width = 100; + } + if (panel->area.height == 0) { + panel->fractional_height = FALSE; + panel->area.height = 32; + } if (panel->fractional_width) panel->area.width = (float)server.monitors[panel->monitor].width * panel->area.width / 100; if (panel->fractional_height) @@ -282,6 +292,14 @@ void init_panel_size_and_position(Panel *panel) panel->area.bg->border.radius = panel->area.height / 2; } } else { + if (panel->area.height == 0) { + panel->fractional_height = TRUE; + panel->area.height = 100; + } + if (panel->area.width == 0) { + panel->fractional_width = FALSE; + panel->area.width = 140; + } int old_panel_height = panel->area.height; if (panel->fractional_width) panel->area.height = (float)server.monitors[panel->monitor].height * panel->area.width / 100; diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 07754b7..ac0a7c6 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -122,6 +122,10 @@ void cleanup_taskbar() void init_taskbar() { + if (!panel_config.g_task.text && !panel_config.g_task.icon) { + panel_config.g_task.text = panel_config.g_task.icon = 1; + } + if (!win_to_task) win_to_task = g_hash_table_new_full(win_hash, win_compare, free, free_ptr_array); @@ -204,7 +208,7 @@ void init_taskbar_panel(void *p) panel->g_task.brightness[TASK_URGENT] = panel->g_task.brightness[TASK_ACTIVE]; } if ((panel->g_task.config_font_mask & (1 << TASK_NORMAL)) == 0) - panel->g_task.font[TASK_NORMAL] = (Color){{0, 0, 0}, 0}; + panel->g_task.font[TASK_NORMAL] = (Color){{1, 1, 1}, 1}; if ((panel->g_task.config_font_mask & (1 << TASK_ACTIVE)) == 0) panel->g_task.font[TASK_ACTIVE] = panel->g_task.font[TASK_NORMAL]; if ((panel->g_task.config_font_mask & (1 << TASK_ICONIFIED)) == 0)