Skip to content

Commit

Permalink
recreate bars when displays changed
Browse files Browse the repository at this point in the history
  • Loading branch information
somdoron committed Mar 29, 2020
1 parent fd7b7b1 commit 80b9fe7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
28 changes: 5 additions & 23 deletions src/bar_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++)
{
Expand Down
3 changes: 1 addition & 2 deletions src/bar_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -163,31 +163,31 @@ 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;
}

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;
}

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;
}

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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/spacebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 80b9fe7

Please sign in to comment.