mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-25 21:00:18 +00:00
recreate bars when displays changed
This commit is contained in:
parent
fd7b7b1f32
commit
80b9fe76c9
4 changed files with 12 additions and 31 deletions
|
@ -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++)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
10
src/event.c
10
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue