remove surface from focusclient function

Honestly not sure why a specific surface is focused rather than the
client figuring that out.  Seems to work in a quick test, but we can
remember this commit if something breaks for, I dunno, mouse people.
This commit is contained in:
Devin J. Pohly 2020-08-02 18:26:58 -05:00
parent 17e525cc6c
commit e7e01e06f6

46
dwl.c
View file

@ -174,7 +174,7 @@ static void cursorframe(struct wl_listener *listener, void *data);
static void destroynotify(struct wl_listener *listener, void *data); static void destroynotify(struct wl_listener *listener, void *data);
static void destroyxdeco(struct wl_listener *listener, void *data); static void destroyxdeco(struct wl_listener *listener, void *data);
static Monitor *dirtomon(int dir); static Monitor *dirtomon(int dir);
static void focusclient(Client *c, struct wlr_surface *surface, int lift); static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg); static void focusstack(const Arg *arg);
static Atom getatom(xcb_connection_t *xc, const char *name); static Atom getatom(xcb_connection_t *xc, const char *name);
@ -366,7 +366,6 @@ void
buttonpress(struct wl_listener *listener, void *data) buttonpress(struct wl_listener *listener, void *data)
{ {
struct wlr_event_pointer_button *event = data; struct wlr_event_pointer_button *event = data;
struct wlr_surface *surface;
struct wlr_keyboard *keyboard; struct wlr_keyboard *keyboard;
uint32_t mods; uint32_t mods;
Client *c; Client *c;
@ -375,17 +374,8 @@ buttonpress(struct wl_listener *listener, void *data)
switch (event->state) { switch (event->state) {
case WLR_BUTTON_PRESSED:; case WLR_BUTTON_PRESSED:;
/* Change focus if the button was _pressed_ over a client */ /* Change focus if the button was _pressed_ over a client */
if ((c = xytoclient(cursor->x, cursor->y))) { if ((c = xytoclient(cursor->x, cursor->y)))
if (c->type != XDGShell) focusclient(c, 1);
surface = wlr_surface_surface_at(c->surface.xwayland->surface,
cursor->x - c->geom.x - c->bw,
cursor->y - c->geom.y - c->bw, NULL, NULL);
else
surface = wlr_xdg_surface_surface_at(c->surface.xdg,
cursor->x - c->geom.x - c->bw,
cursor->y - c->geom.y - c->bw, NULL, NULL);
focusclient(c, surface, 1);
}
keyboard = wlr_seat_get_keyboard(seat); keyboard = wlr_seat_get_keyboard(seat);
mods = wlr_keyboard_get_modifiers(keyboard); mods = wlr_keyboard_get_modifiers(keyboard);
@ -679,15 +669,11 @@ dirtomon(int dir)
} }
void void
focusclient(Client *c, struct wlr_surface *surface, int lift) focusclient(Client *c, int lift)
{ {
Client *old = selclient(); Client *old = selclient();
struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat); struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat);
/* Use top-level wlr_surface if nothing more specific is given */
if (c && !surface)
surface = WLR_SURFACE(c);
/* Deactivate old client if focus is changing */ /* Deactivate old client if focus is changing */
if (c != old && old) { if (c != old && old) {
if (old->type != XDGShell) if (old->type != XDGShell)
@ -702,9 +688,9 @@ focusclient(Client *c, struct wlr_surface *surface, int lift)
wlr_seat_keyboard_notify_clear_focus(seat); wlr_seat_keyboard_notify_clear_focus(seat);
return; return;
} }
/* Otherwise, update the focus if it has changed */
if (surface != seat->keyboard_state.focused_surface) /* Have a client, so focus its top-level wlr_surface */
wlr_seat_keyboard_notify_enter(seat, surface, wlr_seat_keyboard_notify_enter(seat, WLR_SURFACE(c),
kb->keycodes, kb->num_keycodes, &kb->modifiers); kb->keycodes, kb->num_keycodes, &kb->modifiers);
/* Select client's monitor, move it to the top of the focus stack, and /* Select client's monitor, move it to the top of the focus stack, and
@ -732,7 +718,7 @@ focusmon(const Arg *arg)
if (m == selmon) if (m == selmon)
return; return;
selmon = m; selmon = m;
focusclient(lastfocused(), NULL, 1); focusclient(lastfocused(), 1);
} }
void void
@ -758,7 +744,7 @@ focusstack(const Arg *arg)
} }
} }
/* If only one client is visible on selmon, then c == sel */ /* If only one client is visible on selmon, then c == sel */
focusclient(c, NULL, 1); focusclient(c, 1);
} }
Atom Atom
@ -1070,7 +1056,7 @@ pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy,
* of its surfaces, and make keyboard focus follow if desired. */ * of its surfaces, and make keyboard focus follow if desired. */
wlr_seat_pointer_notify_enter(seat, surface, sx, sy); wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
if (sloppyfocus) if (sloppyfocus)
focusclient(c, surface, 0); focusclient(c, 0);
} }
void void
@ -1448,7 +1434,7 @@ setmon(Client *c, Monitor *m, unsigned int newtags)
} }
/* Focus can change if c is the top of selmon before or after */ /* Focus can change if c is the top of selmon before or after */
if (c == oldsel || c == selclient()) if (c == oldsel || c == selclient())
focusclient(lastfocused(), NULL, 1); focusclient(lastfocused(), 1);
} }
void void
@ -1611,7 +1597,7 @@ tag(const Arg *arg)
Client *sel = selclient(); Client *sel = selclient();
if (sel && arg->ui & TAGMASK) { if (sel && arg->ui & TAGMASK) {
sel->tags = arg->ui & TAGMASK; sel->tags = arg->ui & TAGMASK;
focusclient(lastfocused(), NULL, 1); focusclient(lastfocused(), 1);
arrange(selmon); arrange(selmon);
} }
} }
@ -1678,7 +1664,7 @@ toggletag(const Arg *arg)
newtags = sel->tags ^ (arg->ui & TAGMASK); newtags = sel->tags ^ (arg->ui & TAGMASK);
if (newtags) { if (newtags) {
sel->tags = newtags; sel->tags = newtags;
focusclient(lastfocused(), NULL, 1); focusclient(lastfocused(), 1);
arrange(selmon); arrange(selmon);
} }
} }
@ -1690,7 +1676,7 @@ toggleview(const Arg *arg)
if (newtagset) { if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
focusclient(lastfocused(), NULL, 1); focusclient(lastfocused(), 1);
arrange(selmon); arrange(selmon);
} }
} }
@ -1751,7 +1737,7 @@ view(const Arg *arg)
selmon->seltags ^= 1; /* toggle sel tagset */ selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK) if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focusclient(lastfocused(), NULL, 1); focusclient(lastfocused(), 1);
arrange(selmon); arrange(selmon);
} }
@ -1802,7 +1788,7 @@ zoom(const Arg *arg)
wl_list_remove(&sel->link); wl_list_remove(&sel->link);
wl_list_insert(&clients, &sel->link); wl_list_insert(&clients, &sel->link);
focusclient(sel, NULL, 1); focusclient(sel, 1);
arrange(selmon); arrange(selmon);
} }