X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fstacking.c;h=696ce354f09d6fec6ba348ee4fc21273d90c13fb;hb=069e9607fa433190307bb8242294a109e88165de;hp=782a57ddeb27cd33c5b816be6fc96b4af4f4aab8;hpb=58cfbb7f8419e084af6b6b8b00c88ed270c29e88;p=chaz%2Fopenbox diff --git a/openbox/stacking.c b/openbox/stacking.c index 782a57dd..696ce354 100644 --- a/openbox/stacking.c +++ b/openbox/stacking.c @@ -26,14 +26,16 @@ void stacking_set_list() windows = g_new(Window, size); win_it = windows; for (it = g_list_last(stacking_list); it != NULL; - it = it->prev, ++win_it) - if (WINDOW_IS_CLIENT(it->data)) - *win_it = window_top(it->data); + it = it->prev) + if (WINDOW_IS_CLIENT(it->data)) { + *win_it = WINDOW_AS_CLIENT(it->data)->window; + ++win_it; + } } else - windows = NULL; + windows = win_it = NULL; PROP_SETA32(ob_root, net_client_list_stacking, window, - (guint32*)windows, size); + (guint32*)windows, win_it - windows); if (windows) g_free(windows); @@ -110,28 +112,28 @@ void stacking_raise(ObWindow *window) if (WINDOW_IS_CLIENT(window)) { Client *client = WINDOW_AS_CLIENT(window); + /* move up the transient chain as far as possible first */ - while (client->transient_for) { + if (client->transient_for) { if (client->transient_for != TRAN_GROUP) { - client = client->transient_for; + stacking_raise(CLIENT_AS_WINDOW(client->transient_for)); + return; } else { GSList *it; + gboolean raised = FALSE; - /* the check for TRAN_GROUP is to prevent an infinate loop with - 2 transients of the same group at the head of the group's - members list */ for (it = client->group->members; it; it = it->next) { Client *c = it->data; - if (c != client && c->transient_for != TRAN_GROUP) { - client = it->data; - break; + /* checking transient_for prevents infinate loops! */ + if (c != client && !c->transient_for) { + stacking_raise(it->data); + raised = TRUE; } } - if (it == NULL) break; + if (raised) return; } } - window = CLIENT_AS_WINDOW(client); } raise_recursive(window); @@ -178,22 +180,19 @@ void stacking_lower(ObWindow *window) /* move up the transient chain as far as possible first */ while (client->transient_for) { if (client->transient_for != TRAN_GROUP) { - client = client->transient_for; + stacking_lower(CLIENT_AS_WINDOW(client->transient_for)); + return; } else { GSList *it; - /* the check for TRAN_GROUP is to prevent an infinate loop with - 2 transients of the same group at the head of the group's - members list */ for (it = client->group->members; it; it = it->next) { Client *c = it->data; - if (c != client && c->transient_for != TRAN_GROUP) { - client = it->data; - break; - } + /* checking transient_for prevents infinate loops! */ + if (c != client && !c->transient_for) + stacking_lower(it->data); } - if (it == NULL) break; + if (it == NULL) return; } } window = CLIENT_AS_WINDOW(client); @@ -203,3 +202,66 @@ void stacking_lower(ObWindow *window) stacking_set_list(); } + +void stacking_add(ObWindow *win) +{ + stacking_list = g_list_append(stacking_list, win); + stacking_raise(win); +} + +void stacking_add_nonintrusive(ObWindow *win) +{ + Window wins[2]; /* only ever restack 2 windows. */ + + if (!WINDOW_IS_CLIENT(win)) + stacking_add(win); /* no special rules for others */ + else { + Client *client = WINDOW_AS_CLIENT(win); + Client *parent = NULL; + GList *it_before = NULL; + + /* insert above its highest parent */ + if (client->transient_for) { + if (client->transient_for != TRAN_GROUP) { + parent = client->transient_for; + } else { + GSList *sit; + GList *it; + + for (it = stacking_list; !parent && it; it = it->next) { + for (sit = client->group->members; !parent && sit; + sit = sit->next) { + Client *c = sit->data; + /* checking transient_for prevents infinate loops! */ + if (sit->data == it->data && !c->transient_for) + parent = it->data; + } + } + } + } + + if (!(it_before = g_list_find(stacking_list, parent))) { + /* no parent to put above, try find the focused client to go + under */ + if (focus_client && focus_client->layer == client->layer) { + if ((it_before = g_list_find(stacking_list, focus_client))) + it_before = it_before->next; + } + } + if (!it_before) { + /* out of ideas, just add it normally... */ + stacking_add(win); + } else { + stacking_list = g_list_insert_before(stacking_list, it_before,win); + + it_before = g_list_find(stacking_list, win)->prev; + if (!it_before) + wins[0] = focus_backup; + else + wins[0] = window_top(it_before->data); + wins[1] = window_top(win); + + XRestackWindows(ob_display, wins, 2); + } + } +}