- /* move windows on desktops that will no longer exist! */
- for (it = client_list; it; it = g_list_next(it)) {
- ObClient *c = it->data;
- if (c->desktop >= num && c->desktop != DESKTOP_ALL)
- client_set_desktop(c, num - 1, FALSE, TRUE);
+ /* move windows on desktops that will no longer exist!
+ make a copy of the list cuz we're changing it */
+ stacking_copy = g_list_copy(stacking_list);
+ for (it = g_list_last(stacking_copy); it; it = g_list_previous(it)) {
+ if (WINDOW_IS_CLIENT(it->data)) {
+ ObClient *c = it->data;
+ if (c->desktop != DESKTOP_ALL && c->desktop >= num)
+ client_set_desktop(c, num - 1, FALSE, TRUE);
+ /* raise all the windows that are on the current desktop which
+ is being merged */
+ else if (screen_desktop == num - 1 &&
+ (c->desktop == DESKTOP_ALL ||
+ c->desktop == screen_desktop))
+ stacking_raise(WINDOW_AS_CLIENT(c));
+ }