remove selclient()

selclient() does not work well when dealing newly mapped
clients (specifically those mapped on invisible tags).

This fixes various bugs related to things not working because selclient() would
return NULL.

References: 94c8bd6048
This commit is contained in:
Leonardo Hernández Hernández 2022-12-18 11:39:50 -06:00
parent 686958a4cc
commit dd9d8d543c
No known key found for this signature in database
GPG key ID: E538897EE11B9624

34
dwl.c
View file

@ -280,7 +280,6 @@ static void rendermon(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data); static void requeststartdrag(struct wl_listener *listener, void *data);
static void resize(Client *c, struct wlr_box geo, int interact); static void resize(Client *c, struct wlr_box geo, int interact);
static void run(char *startup_cmd); static void run(char *startup_cmd);
static Client *selclient(void);
static void setcursor(struct wl_listener *listener, void *data); static void setcursor(struct wl_listener *listener, void *data);
static void setfloating(Client *c, int floating); static void setfloating(Client *c, int floating);
static void setfullscreen(Client *c, int fullscreen); static void setfullscreen(Client *c, int fullscreen);
@ -1055,7 +1054,7 @@ destroydragicon(struct wl_listener *listener, void *data)
struct wlr_drag_icon *icon = data; struct wlr_drag_icon *icon = data;
wlr_scene_node_destroy(icon->data); wlr_scene_node_destroy(icon->data);
/* Focus enter isn't sent during drag, so refocus the focused node. */ /* Focus enter isn't sent during drag, so refocus the focused node. */
focusclient(selclient(), 1); focusclient(focustop(selmon), 1);
motionnotify(0); motionnotify(0);
} }
@ -1417,7 +1416,7 @@ keypressmod(struct wl_listener *listener, void *data)
void void
killclient(const Arg *arg) killclient(const Arg *arg)
{ {
Client *sel = selclient(); Client *sel = focustop(selmon);
if (sel) if (sel)
client_send_close(sel); client_send_close(sel);
} }
@ -1940,15 +1939,6 @@ run(char *startup_cmd)
wl_display_run(dpy); wl_display_run(dpy);
} }
Client *
selclient(void)
{
Client *c = wl_container_of(fstack.next, c, flink);
if (wl_list_empty(&fstack) || !VISIBLEON(c, selmon))
return NULL;
return c;
}
void void
setcursor(struct wl_listener *listener, void *data) setcursor(struct wl_listener *listener, void *data)
{ {
@ -2292,7 +2282,7 @@ startdrag(struct wl_listener *listener, void *data)
void void
tag(const Arg *arg) tag(const Arg *arg)
{ {
Client *sel = selclient(); Client *sel = focustop(selmon);
if (sel && arg->ui & TAGMASK) { if (sel && arg->ui & TAGMASK) {
sel->tags = arg->ui & TAGMASK; sel->tags = arg->ui & TAGMASK;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
@ -2304,7 +2294,7 @@ tag(const Arg *arg)
void void
tagmon(const Arg *arg) tagmon(const Arg *arg)
{ {
Client *sel = selclient(); Client *sel = focustop(selmon);
if (sel) if (sel)
setmon(sel, dirtomon(arg->i), 0); setmon(sel, dirtomon(arg->i), 0);
} }
@ -2345,7 +2335,7 @@ tile(Monitor *m)
void void
togglefloating(const Arg *arg) togglefloating(const Arg *arg)
{ {
Client *sel = selclient(); Client *sel = focustop(selmon);
/* return if fullscreen */ /* return if fullscreen */
if (sel && !sel->isfullscreen) if (sel && !sel->isfullscreen)
setfloating(sel, !sel->isfloating); setfloating(sel, !sel->isfloating);
@ -2354,7 +2344,7 @@ togglefloating(const Arg *arg)
void void
togglefullscreen(const Arg *arg) togglefullscreen(const Arg *arg)
{ {
Client *sel = selclient(); Client *sel = focustop(selmon);
if (sel) if (sel)
setfullscreen(sel, !sel->isfullscreen); setfullscreen(sel, !sel->isfullscreen);
} }
@ -2363,7 +2353,7 @@ void
toggletag(const Arg *arg) toggletag(const Arg *arg)
{ {
unsigned int newtags; unsigned int newtags;
Client *sel = selclient(); Client *sel = focustop(selmon);
if (!sel) if (!sel)
return; return;
newtags = sel->tags ^ (arg->ui & TAGMASK); newtags = sel->tags ^ (arg->ui & TAGMASK);
@ -2409,7 +2399,7 @@ unmaplayersurfacenotify(struct wl_listener *listener, void *data)
arrangelayers(layersurface->mon); arrangelayers(layersurface->mon);
if (layersurface->layer_surface->surface == if (layersurface->layer_surface->surface ==
seat->keyboard_state.focused_surface) seat->keyboard_state.focused_surface)
focusclient(selclient(), 1); focusclient(focustop(selmon), 1);
motionnotify(0); motionnotify(0);
} }
@ -2430,7 +2420,7 @@ unmapnotify(struct wl_listener *listener, void *data)
if (c == exclusive_focus) if (c == exclusive_focus)
exclusive_focus = NULL; exclusive_focus = NULL;
if (client_surface(c) == seat->keyboard_state.focused_surface) if (client_surface(c) == seat->keyboard_state.focused_surface)
focusclient(selclient(), 1); focusclient(focustop(selmon), 1);
} else { } else {
wl_list_remove(&c->link); wl_list_remove(&c->link);
setmon(c, NULL, 0); setmon(c, NULL, 0);
@ -2535,7 +2525,7 @@ urgent(struct wl_listener *listener, void *data)
struct wlr_xdg_activation_v1_request_activate_event *event = data; struct wlr_xdg_activation_v1_request_activate_event *event = data;
Client *c = NULL; Client *c = NULL;
int type = toplevel_from_wlr_surface(event->surface, &c, NULL); int type = toplevel_from_wlr_surface(event->surface, &c, NULL);
if (type >= 0 && type != LayerShell && c != selclient()) { if (type >= 0 && type != LayerShell && c != focustop(selmon)) {
c->isurgent = 1; c->isurgent = 1;
printstatus(); printstatus();
} }
@ -2605,7 +2595,7 @@ xytonode(double x, double y, struct wlr_surface **psurface,
void void
zoom(const Arg *arg) zoom(const Arg *arg)
{ {
Client *c, *sel = selclient(); Client *c, *sel = focustop(selmon);
if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange || sel->isfloating) if (!sel || !selmon || !selmon->lt[selmon->sellt]->arrange || sel->isfloating)
return; return;
@ -2699,7 +2689,7 @@ void
sethints(struct wl_listener *listener, void *data) sethints(struct wl_listener *listener, void *data)
{ {
Client *c = wl_container_of(listener, c, set_hints); Client *c = wl_container_of(listener, c, set_hints);
if (c != selclient()) { if (c != focustop(selmon)) {
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus(); printstatus();
} }