mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-27 13:50:33 +00:00
Fix remove when one item remains
This commit is contained in:
parent
eaf1bf4dc5
commit
07b6b5c454
1 changed files with 14 additions and 8 deletions
|
@ -107,15 +107,21 @@ void bar_manager_move_item(struct bar_manager* bar_manager, struct bar_item* ite
|
||||||
|
|
||||||
void bar_manager_remove_item(struct bar_manager* bar_manager, struct bar_item* bar_item) {
|
void bar_manager_remove_item(struct bar_manager* bar_manager, struct bar_item* bar_item) {
|
||||||
if (bar_manager->bar_item_count <= 0 || !bar_item) return;
|
if (bar_manager->bar_item_count <= 0 || !bar_item) return;
|
||||||
struct bar_item* tmp[bar_manager->bar_item_count - 1];
|
if (bar_manager->bar_item_count == 1) {
|
||||||
int count = 0;
|
free(bar_manager->bar_items);
|
||||||
for (int i = 0; i < bar_manager->bar_item_count; i++) {
|
bar_manager->bar_items = NULL;
|
||||||
if (bar_manager->bar_items[i] == bar_item) continue;
|
bar_manager->bar_item_count = 0;
|
||||||
tmp[count++] = bar_manager->bar_items[i];
|
} else {
|
||||||
|
struct bar_item* tmp[bar_manager->bar_item_count - 1];
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < bar_manager->bar_item_count; i++) {
|
||||||
|
if (bar_manager->bar_items[i] == bar_item) continue;
|
||||||
|
tmp[count++] = bar_manager->bar_items[i];
|
||||||
|
}
|
||||||
|
bar_manager->bar_item_count--;
|
||||||
|
bar_manager->bar_items = realloc(bar_manager->bar_items, sizeof(struct bar_item*)*bar_manager->bar_item_count);
|
||||||
|
memcpy(bar_manager->bar_items, tmp, sizeof(struct bar_item*)*bar_manager->bar_item_count);
|
||||||
}
|
}
|
||||||
bar_manager->bar_item_count--;
|
|
||||||
bar_manager->bar_items = realloc(bar_manager->bar_items, sizeof(struct bar_item*)*bar_manager->bar_item_count);
|
|
||||||
memcpy(bar_manager->bar_items, tmp, sizeof(struct bar_item*)*bar_manager->bar_item_count);
|
|
||||||
bar_item_destroy(bar_item);
|
bar_item_destroy(bar_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue