diff options
-rw-r--r-- | src/daemon/daemon.c | 70 | ||||
-rw-r--r-- | src/daemon/stack.c | 5 | ||||
-rw-r--r-- | src/daemon/stack.h | 1 |
3 files changed, 48 insertions, 28 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 59b4ec6..a513efd 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -323,54 +323,68 @@ static void on_screen_monitors_changed(GdkScreen* screen, NotifyDaemon* daemon) GdkDisplay *display; NotifyScreen* nscreen; int n_monitors; - int i; nscreen = daemon->screen; display = gdk_screen_get_display (screen); n_monitors = gdk_display_get_n_monitors(display); - if (n_monitors > (int) nscreen->n_stacks) + if (n_monitors != (int) nscreen->n_stacks) { - /* grow */ - nscreen->stacks = g_renew(NotifyStack *, nscreen->stacks, (gsize) n_monitors); + NotifyStack **new_stacks = g_malloc (sizeof *new_stacks * n_monitors); - /* add more stacks */ - for (i = (int) nscreen->n_stacks; i < n_monitors; i++) + /* create the new list, either moving over from the existing stacks, + * or creating new ones as needed */ + for (int i = 0; i < n_monitors; i++) { - create_stack_for_monitor(daemon, screen, gdk_display_get_monitor (display, i)); - } - - nscreen->n_stacks = (gsize) n_monitors; - } - else if (n_monitors < (int) nscreen->n_stacks) - { - NotifyStack* last_stack; + GdkMonitor *monitor = gdk_display_get_monitor (display, i); + gsize j; - last_stack = nscreen->stacks[n_monitors - 1]; - - /* transfer items before removing stacks */ - for (i = n_monitors; i < (int) nscreen->n_stacks; i++) + for (j = 0; j < nscreen->n_stacks; j++) + { + if (nscreen->stacks[j] != NULL && + notify_stack_get_monitor (nscreen->stacks[j]) == monitor) + { + new_stacks[i] = nscreen->stacks[j]; + nscreen->stacks[j] = NULL; + break; + } + } + /* not found, create it */ + if (j >= nscreen->n_stacks) + new_stacks[i] = notify_stack_new (daemon, screen, monitor, daemon->stack_location); + } + /* transfer items and remove old stacks */ + for (gsize i = 0; i < nscreen->n_stacks; i++) { NotifyStack* stack = nscreen->stacks[i]; - GList* windows = g_list_copy(notify_stack_get_windows(stack)); - GList* l; - for (l = windows; l != NULL; l = l->next) + /* if it has been moved over to the new ones, ignore it */ + if (stack == NULL) + continue; + + if (n_monitors > 0) /* always true, but just to be safe */ { - /* skip removing the window from the old stack since it will try - * to unrealize the window. - * And the stack is going away anyhow. */ - notify_stack_add_window(last_stack, l->data, TRUE); + int target_idx = n_monitors - 1; + GList* windows = g_list_copy (notify_stack_get_windows (stack)); + + for (GList *l = windows; l != NULL; l = l->next) + { + /* skip removing the window from the old stack since it will try + * to unrealize the window. + * And the stack is going away anyhow. */ + notify_stack_add_window (new_stacks[target_idx], l->data, TRUE); + } + + g_list_free(windows); } - g_list_free(windows); notify_stack_destroy(stack); nscreen->stacks[i] = NULL; } - /* remove the extra stacks */ - nscreen->stacks = g_renew(NotifyStack*, nscreen->stacks, (gsize) n_monitors); + g_free (nscreen->stacks); + nscreen->stacks = new_stacks; nscreen->n_stacks = (gsize) n_monitors; } } diff --git a/src/daemon/stack.c b/src/daemon/stack.c index 608436e..0e8ec87 100644 --- a/src/daemon/stack.c +++ b/src/daemon/stack.c @@ -50,6 +50,11 @@ GList* notify_stack_get_windows(NotifyStack *stack) return stack->windows; } +GdkMonitor* notify_stack_get_monitor(NotifyStack *stack) +{ + return stack->monitor; +} + #ifdef HAVE_X11 static gboolean get_work_area (NotifyStack *stack, diff --git a/src/daemon/stack.h b/src/daemon/stack.h index 2795beb..0e24b70 100644 --- a/src/daemon/stack.h +++ b/src/daemon/stack.h @@ -46,6 +46,7 @@ void notify_stack_set_location(NotifyStack* stack, NotifyStackLocation location) void notify_stack_add_window(NotifyStack* stack, GtkWindow* nw, gboolean new_notification); void notify_stack_remove_window(NotifyStack* stack, GtkWindow* nw); GList* notify_stack_get_windows(NotifyStack* stack); +GdkMonitor* notify_stack_get_monitor(NotifyStack* stack); void notify_stack_queue_update_position(NotifyStack* stack); #endif /* _NOTIFY_STACK_H_ */ |