fix: crash when set text_input focus after grab window to other window

This commit is contained in:
DreamMaoMao 2025-04-18 12:43:29 +08:00
parent 2ff859bb29
commit ed7d768b3e

View file

@ -2335,6 +2335,8 @@ buttonpress(struct wl_listener *listener, void *data) {
selmon = xytomon(cursor->x, cursor->y); selmon = xytomon(cursor->x, cursor->y);
setmon(grabc, selmon, 0,true); setmon(grabc, selmon, 0,true);
reset_foreign_tolevel(grabc); reset_foreign_tolevel(grabc);
selmon->prevsel = selmon->sel;
selmon->sel = grabc;
grabc = NULL; grabc = NULL;
return; return;
} else { } else {
@ -3457,13 +3459,13 @@ void focusclient(Client *c, int lift) {
false); false);
} }
if(c && !c->iskilling && c->mon) { if (c && !c->iskilling && !client_is_unmanaged(c) && c->mon) {
selmon = c->mon;
}
if (selmon) { selmon = c->mon;
selmon->prevsel = selmon->sel; selmon->prevsel = selmon->sel;
selmon->sel = c; selmon->sel = c;
// decide whether need to re-arrange
if (c && selmon->prevsel && !selmon->prevsel->isfloating && if (c && selmon->prevsel && !selmon->prevsel->isfloating &&
selmon->prevsel->tags == c->tags && !c->isfloating && selmon->prevsel->tags == c->tags && !c->isfloating &&
!c->isfullscreen && !c->isfullscreen &&
@ -3473,22 +3475,19 @@ void focusclient(Client *c, int lift) {
} else if (selmon->prevsel) { } else if (selmon->prevsel) {
selmon->prevsel = NULL; selmon->prevsel = NULL;
} }
}
if (c && c->foreign_toplevel)
wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, true);
/* Put the new client atop the focus stack and select its monitor */ // change focus link position
if (c && !client_is_unmanaged(c)) {
wl_list_remove(&c->flink); wl_list_remove(&c->flink);
wl_list_insert(&fstack, &c->flink); wl_list_insert(&fstack, &c->flink);
selmon = c->mon;
c->isurgent = 0;
// change border color
c->isurgent = 0;
setborder_color(c); setborder_color(c);
/* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */
} }
if (c && !c->iskilling && c->foreign_toplevel)
wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, true);
/* Deactivate old client if focus is changing */ /* Deactivate old client if focus is changing */
if (old_keyboard_focus_surface && if (old_keyboard_focus_surface &&
(!c || client_surface(c) != old_keyboard_focus_surface)) { (!c || client_surface(c) != old_keyboard_focus_surface)) {
@ -6601,18 +6600,18 @@ void unmapnotify(struct wl_listener *listener, void *data) {
grabc = NULL; grabc = NULL;
} }
if (c == selmon->prevsel) if (c->mon && c == c->mon->prevsel)
selmon->prevsel = NULL; c->mon->prevsel = NULL;
if (c == selmon->sel) { if (c->mon && c == c->mon->sel) {
selmon->sel = NULL; c->mon->sel = NULL;
Client *nextfocus = focustop(selmon); Client *nextfocus = focustop(c->mon);
if (nextfocus) { if (nextfocus && c->mon && c->mon == selmon) {
focusclient(nextfocus, 0); focusclient(nextfocus, 0);
} }
if (!nextfocus && selmon->isoverview) { if (!nextfocus && selmon->isoverview && c->mon && c->mon == selmon) {
Arg arg = {0}; Arg arg = {0};
toggleoverview(&arg); toggleoverview(&arg);
} }