fix: fix group cross monitor

This commit is contained in:
DreamMaoMao 2026-06-22 20:58:10 +08:00
parent 7a93414f36
commit a766994a8e
3 changed files with 59 additions and 32 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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') {