diff --git a/src/bar_manager.c b/src/bar_manager.c index 8825aad..d72aeda 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -165,30 +165,12 @@ void bar_manager_set_space_icon(struct bar_manager *bar_manager, char *icon) bar_manager_refresh(bar_manager); } -void bar_manager_add_display(struct bar_manager *bar_manager, uint32_t did) -{ - for (int i = 0; i < bar_manager->bar_count; ++i) { - if (bar_manager->bars[i]->did == did) - return; - } - - bar_manager->bar_count++; - bar_manager->bars = realloc(bar_manager->bars, sizeof(struct bar *) * bar_manager->bar_count); - bar_manager->bars[bar_manager->bar_count - 1] = bar_create(did); -} - -void bar_manager_remove_display(struct bar_manager *bar_manager, uint32_t did) +void bar_manager_display_changed(struct bar_manager *bar_manager) { for (int i = 0; i < bar_manager->bar_count; ++i) - { - if (bar_manager->bars[i]->did == did) { - free (bar_manager->bars[i]); - bar_manager->bars[i] = bar_manager->bars[bar_manager->bar_count - 1]; - bar_manager->bar_count--; - bar_manager->bars = realloc(bar_manager->bars, sizeof(struct bar *) * bar_manager->bar_count); - return; - } - } + bar_destroy(bar_manager->bars[i]); + + bar_manager_begin(bar_manager); } void bar_manager_refresh(struct bar_manager *bar_manager) @@ -219,7 +201,7 @@ void bar_manager_init(struct bar_manager *bar_manager) void bar_manager_begin(struct bar_manager *bar_manager) { bar_manager->bar_count = display_manager_active_display_count(); - bar_manager->bars = (struct bar **) malloc(sizeof(struct bar *) * bar_manager->bar_count); + bar_manager->bars = (struct bar **) realloc(bar_manager->bars, sizeof(struct bar *) * bar_manager->bar_count); for (uint32_t index=1; index <= bar_manager->bar_count; index++) { diff --git a/src/bar_manager.h b/src/bar_manager.h index e846e1e..9e7a523 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -35,8 +35,7 @@ void bar_manager_set_power_strip(struct bar_manager *bar_manager, char **icon_st void bar_manager_set_clock_icon(struct bar_manager *bar_manager, char *icon); void bar_manager_set_space_icon(struct bar_manager *bar_manager, char *icon); -void bar_manager_add_display(struct bar_manager *bar_manager, uint32_t did); -void bar_manager_remove_display(struct bar_manager *bar_manager, uint32_t did); +void bar_manager_display_changed(struct bar_manager *bar_manager); void bar_manager_refresh(struct bar_manager *bar_manager); void bar_manager_resize(struct bar_manager *bar_manager); void bar_manager_begin(struct bar_manager *bar_manager); diff --git a/src/event.c b/src/event.c index 0e2edd8..95c5210 100644 --- a/src/event.c +++ b/src/event.c @@ -154,7 +154,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_CHANGED) debug("%s: %d\n", __FUNCTION__, g_display_manager.current_display_id); - bar_manager_refresh(&g_bar_manager); + bar_manager_display_changed(&g_bar_manager); return EVENT_SUCCESS; } @@ -163,7 +163,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_ADDED) { uint32_t did = (uint32_t)(intptr_t) context; debug("%s: %d\n", __FUNCTION__, did); - bar_manager_add_display(&g_bar_manager, did); + bar_manager_display_changed(&g_bar_manager); return EVENT_SUCCESS; } @@ -171,7 +171,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_REMOVED) { uint32_t did = (uint32_t)(intptr_t) context; debug("%s: %d\n", __FUNCTION__, did); - bar_manager_remove_display(&g_bar_manager, did); + bar_manager_display_changed(&g_bar_manager); return EVENT_SUCCESS; } @@ -179,7 +179,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_MOVED) { uint32_t did = (uint32_t)(intptr_t) context; debug("%s: %d\n", __FUNCTION__, did); - bar_manager_resize(&g_bar_manager); + bar_manager_display_changed(&g_bar_manager); return EVENT_SUCCESS; } @@ -187,7 +187,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_RESIZED) { uint32_t did = (uint32_t)(intptr_t) context; debug("%s: %d\n", __FUNCTION__, did); - bar_manager_resize(&g_bar_manager); + bar_manager_display_changed(&g_bar_manager); return EVENT_SUCCESS; } diff --git a/src/spacebar.c b/src/spacebar.c index 6ac130c..7c49137 100644 --- a/src/spacebar.c +++ b/src/spacebar.c @@ -12,7 +12,7 @@ #define CONFIG_OPT_SHRT "-c" #define MAJOR 0 -#define MINOR 2 +#define MINOR 3 #define PATCH 0 extern int SLSMainConnectionID(void);