diff --git a/src/action/client.h b/src/action/client.h index 4a1f72c2..11ec5866 100644 --- a/src/action/client.h +++ b/src/action/client.h @@ -140,9 +140,6 @@ void client_focus_group_member(Client *c) { if (c->isgroupfocusing) return; - if (c->mon->isoverview) - return; - Client *head = c; while (head->group_prev) head = head->group_prev; @@ -156,12 +153,16 @@ void client_focus_group_member(Client *c) { head = head->group_next; } - if (cur_focusing) { - cur_focusing->isgroupfocusing = false; - c->mon = cur_focusing->mon; - client_replace(c, cur_focusing, true); - mango_group_bar_set_focus(cur_focusing->group_bar, false); - } + if (!cur_focusing || !cur_focusing->mon) + return; + + if (cur_focusing && cur_focusing->mon->isoverview) + return; + + cur_focusing->isgroupfocusing = false; + c->mon = cur_focusing->mon; + client_replace(c, cur_focusing, true); + mango_group_bar_set_focus(cur_focusing->group_bar, false); c->isgroupfocusing = true; mango_group_bar_set_focus(c->group_bar, true); @@ -255,4 +256,16 @@ void client_handle_decorate_click(MangoGroupBar *gb) { Client *c = gb->node_data; client_focus_group_member(c); } +} + +void client_set_group_mon(Client *c, Monitor *m) { + Client *head = c; + while (head->group_prev) + head = head->group_prev; + + Client *cur = head; + while (cur) { + cur->mon = m; + cur = cur->group_next; + } } \ No newline at end of file diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 607708a4..f2a73230 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -162,38 +162,50 @@ int32_t groupjoin(const Arg *arg) { if (!selmon) return 0; - Client *need_join_client = arg->tc ? arg->tc : selmon->sel; - if (!need_join_client) - return 0; + Monitor *oldmon = NULL; - if (need_join_client->group_next || need_join_client->group_prev) { + Client *need_join_client = arg->tc ? arg->tc : selmon->sel; + if (!need_join_client || !need_join_client->mon) return 0; - } Client *need_replace_client = NULL; need_replace_client = direction_select(arg); - if (!need_replace_client || - need_replace_client->mon != need_join_client->mon) + if (!need_replace_client || !need_replace_client->mon) return 0; - if (!need_join_client->group_next && !need_join_client->group_prev) { - - if (!need_replace_client->group_prev && - !need_replace_client->group_next) { - need_replace_client->isgroupfocusing = true; - } - - need_join_client->group_next = need_replace_client; - if (need_replace_client->group_prev) { - need_replace_client->group_prev->group_next = need_join_client; - } - need_join_client->group_prev = need_replace_client->group_prev; - need_replace_client->group_prev = need_join_client; - - client_focus_group_member(need_join_client); - arrange(need_join_client->mon, false, false); + if (need_join_client == need_replace_client) return 0; + + if (need_join_client->group_next || need_join_client->group_prev) { + groupleave(&(Arg){.tc = need_join_client}); + } + + if (need_join_client->mon != need_replace_client->mon) { + oldmon = need_join_client->mon; + need_join_client->mon = need_replace_client->mon; + } + + if (!need_replace_client->group_prev && !need_replace_client->group_next) { + need_replace_client->isgroupfocusing = true; + } + + need_join_client->group_next = need_replace_client; + + if (need_replace_client->group_prev) { + need_replace_client->group_prev->group_next = need_join_client; + } + + need_join_client->group_prev = need_replace_client->group_prev; + + need_replace_client->group_prev = need_join_client; + + client_focus_group_member(need_join_client); + arrange(need_join_client->mon, false, false); + + // oldmon可能已经死掉了 + if (oldmon) { + arrange(oldmon, false, false); } return 0; diff --git a/src/mango.c b/src/mango.c index 90e3ca66..01784257 100644 --- a/src/mango.c +++ b/src/mango.c @@ -2761,8 +2761,10 @@ void closemon(Monitor *m) { } c->mon = NULL; + client_set_group_mon(c, NULL); } else { client_change_mon(c, selmon); + client_set_group_mon(c, selmon); } // record the oldmonname which is used to restore if (c->oldmonname[0] == '\0') {