mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-22 03:13:02 +00:00
fix issues if an item is added to a popup multiple times
This commit is contained in:
parent
b5c2c65447
commit
533d4914f9
1 changed files with 8 additions and 7 deletions
15
src/popup.c
15
src/popup.c
|
@ -258,7 +258,15 @@ static void popup_close_window(struct popup* popup) {
|
|||
window_close(&popup->window);
|
||||
}
|
||||
|
||||
static bool popup_contains_item(struct popup* popup, struct bar_item* bar_item) {
|
||||
for (int i = 0; i < popup->num_items; i++) {
|
||||
if (popup->items[i] == bar_item) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void popup_add_item(struct popup* popup, struct bar_item* bar_item) {
|
||||
if (popup_contains_item(popup, bar_item)) return;
|
||||
popup->num_items++;
|
||||
popup->items = realloc(popup->items,
|
||||
sizeof(struct bar_item*)*popup->num_items);
|
||||
|
@ -267,13 +275,6 @@ void popup_add_item(struct popup* popup, struct bar_item* bar_item) {
|
|||
popup->needs_ordering = true;
|
||||
}
|
||||
|
||||
static bool popup_contains_item(struct popup* popup, struct bar_item* bar_item) {
|
||||
for (int i = 0; i < popup->num_items; i++) {
|
||||
if (popup->items[i] == bar_item) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void popup_remove_item(struct popup* popup, struct bar_item* bar_item) {
|
||||
if (popup->num_items == 0 || !popup_contains_item(popup, bar_item))
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue