tinywl: don't pass surface to focus_toplevel()

It's not required.
This commit is contained in:
Kirill Primak 2024-11-16 22:05:01 +03:00
parent 0b720ae5ea
commit f233d25e86

View file

@ -109,7 +109,7 @@ struct tinywl_keyboard {
struct wl_listener destroy; struct wl_listener destroy;
}; };
static void focus_toplevel(struct tinywl_toplevel *toplevel, struct wlr_surface *surface) { static void focus_toplevel(struct tinywl_toplevel *toplevel) {
/* Note: this function only deals with keyboard focus. */ /* Note: this function only deals with keyboard focus. */
if (toplevel == NULL) { if (toplevel == NULL) {
return; return;
@ -117,6 +117,7 @@ static void focus_toplevel(struct tinywl_toplevel *toplevel, struct wlr_surface
struct tinywl_server *server = toplevel->server; struct tinywl_server *server = toplevel->server;
struct wlr_seat *seat = server->seat; struct wlr_seat *seat = server->seat;
struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface; struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
struct wlr_surface *surface = toplevel->xdg_toplevel->base->surface;
if (prev_surface == surface) { if (prev_surface == surface) {
/* Don't re-focus an already focused surface. */ /* Don't re-focus an already focused surface. */
return; return;
@ -146,7 +147,7 @@ static void focus_toplevel(struct tinywl_toplevel *toplevel, struct wlr_surface
* clients without additional work on your part. * clients without additional work on your part.
*/ */
if (keyboard != NULL) { if (keyboard != NULL) {
wlr_seat_keyboard_notify_enter(seat, toplevel->xdg_toplevel->base->surface, wlr_seat_keyboard_notify_enter(seat, surface,
keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
} }
} }
@ -188,7 +189,7 @@ static bool handle_keybinding(struct tinywl_server *server, xkb_keysym_t sym) {
} }
struct tinywl_toplevel *next_toplevel = struct tinywl_toplevel *next_toplevel =
wl_container_of(server->toplevels.prev, next_toplevel, link); wl_container_of(server->toplevels.prev, next_toplevel, link);
focus_toplevel(next_toplevel, next_toplevel->xdg_toplevel->base->surface); focus_toplevel(next_toplevel);
break; break;
default: default:
return false; return false;
@ -520,16 +521,16 @@ static void server_cursor_button(struct wl_listener *listener, void *data) {
/* Notify the client with pointer focus that a button press has occurred */ /* Notify the client with pointer focus that a button press has occurred */
wlr_seat_pointer_notify_button(server->seat, wlr_seat_pointer_notify_button(server->seat,
event->time_msec, event->button, event->state); event->time_msec, event->button, event->state);
double sx, sy;
struct wlr_surface *surface = NULL;
struct tinywl_toplevel *toplevel = desktop_toplevel_at(server,
server->cursor->x, server->cursor->y, &surface, &sx, &sy);
if (event->state == WL_POINTER_BUTTON_STATE_RELEASED) { if (event->state == WL_POINTER_BUTTON_STATE_RELEASED) {
/* If you released any buttons, we exit interactive move/resize mode. */ /* If you released any buttons, we exit interactive move/resize mode. */
reset_cursor_mode(server); reset_cursor_mode(server);
} else { } else {
/* Focus that client if the button was _pressed_ */ /* Focus that client if the button was _pressed_ */
focus_toplevel(toplevel, surface); double sx, sy;
struct wlr_surface *surface = NULL;
struct tinywl_toplevel *toplevel = desktop_toplevel_at(server,
server->cursor->x, server->cursor->y, &surface, &sx, &sy);
focus_toplevel(toplevel);
} }
} }
@ -662,7 +663,7 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data) {
wl_list_insert(&toplevel->server->toplevels, &toplevel->link); wl_list_insert(&toplevel->server->toplevels, &toplevel->link);
focus_toplevel(toplevel, toplevel->xdg_toplevel->base->surface); focus_toplevel(toplevel);
} }
static void xdg_toplevel_unmap(struct wl_listener *listener, void *data) { static void xdg_toplevel_unmap(struct wl_listener *listener, void *data) {