From d7f4d1001f1de296ac5c8f0baa28a3de5da0aca1 Mon Sep 17 00:00:00 2001 From: Keith Bowes Date: Sun, 8 Dec 2024 23:02:21 -0500 Subject: [PATCH] Remove the unneeded surface argument from focus_toplevel, like tinywl does --- include/waybox/xdg_shell.h | 2 +- waybox/cursor.c | 2 +- waybox/layer_shell.c | 2 +- waybox/seat.c | 4 ++-- waybox/xdg_shell.c | 13 +++++++------ 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/waybox/xdg_shell.h b/include/waybox/xdg_shell.h index 144b82e..ba9d427 100644 --- a/include/waybox/xdg_shell.h +++ b/include/waybox/xdg_shell.h @@ -43,7 +43,7 @@ struct wb_toplevel { }; void init_xdg_shell(struct wb_server *server); -void focus_toplevel(struct wb_toplevel *toplevel, struct wlr_surface *surface); +void focus_toplevel(struct wb_toplevel *toplevel); struct wlr_output *get_active_output(struct wb_toplevel *toplevel); struct wb_toplevel *get_toplevel_at( struct wb_server *server, double lx, double ly, diff --git a/waybox/cursor.c b/waybox/cursor.c index 2a9b175..4d5ac00 100644 --- a/waybox/cursor.c +++ b/waybox/cursor.c @@ -149,7 +149,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { reset_cursor_mode(cursor->server); } else { /* Focus that client if the button was _pressed_ */ - focus_toplevel(toplevel, surface); + focus_toplevel(toplevel); } wlr_idle_notifier_v1_notify_activity(cursor->server->idle_notifier, cursor->server->seat->seat); diff --git a/waybox/layer_shell.c b/waybox/layer_shell.c index 60444bc..40ed79b 100644 --- a/waybox/layer_shell.c +++ b/waybox/layer_shell.c @@ -175,7 +175,7 @@ static void handle_unmap(struct wl_listener *listener, void *data) { struct wb_toplevel *toplevel = wl_container_of(surface->server->toplevels.next, toplevel, link); if (toplevel && toplevel->scene_tree && toplevel->scene_tree->node.enabled) { - focus_toplevel(toplevel, toplevel->xdg_toplevel->base->surface); + focus_toplevel(toplevel); } } diff --git a/waybox/seat.c b/waybox/seat.c index 9a979e1..952f666 100644 --- a/waybox/seat.c +++ b/waybox/seat.c @@ -30,7 +30,7 @@ static void cycle_toplevels(struct wb_server *server) { struct wb_toplevel *current_toplevel = wl_container_of( server->toplevels.prev, current_toplevel, link); deiconify_toplevel(current_toplevel); - focus_toplevel(current_toplevel, current_toplevel->xdg_toplevel->base->surface); + focus_toplevel(current_toplevel); /* Move the current toplevel to the beginning of the list */ wl_list_remove(¤t_toplevel->link); @@ -48,7 +48,7 @@ static void cycle_toplevels_reverse(struct wb_server *server) { struct wb_toplevel *next_toplevel = wl_container_of( current_toplevel->link.next, next_toplevel, link); deiconify_toplevel(next_toplevel); - focus_toplevel(next_toplevel, next_toplevel->xdg_toplevel->base->surface); + focus_toplevel(next_toplevel); /* Move the current toplevel to after the previous toplevel in the list */ wl_list_remove(¤t_toplevel->link); diff --git a/waybox/xdg_shell.c b/waybox/xdg_shell.c index 3ea5a39..a5570dc 100644 --- a/waybox/xdg_shell.c +++ b/waybox/xdg_shell.c @@ -29,12 +29,13 @@ struct wb_toplevel *get_toplevel_at( return tree->node.data; } -void focus_toplevel(struct wb_toplevel *toplevel, struct wlr_surface *surface) { +void focus_toplevel(struct wb_toplevel *toplevel) { /* Note: this function only deals with keyboard focus. */ if (toplevel == NULL || toplevel->xdg_toplevel->base->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) { return; } + struct wlr_surface *surface = toplevel->xdg_toplevel->base->surface; struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_try_from_wlr_surface(surface); if (xdg_surface != NULL) wlr_log(WLR_INFO, "%s: %s", _("Keyboard focus is now on surface"), @@ -74,7 +75,7 @@ void focus_toplevel(struct wb_toplevel *toplevel, struct wlr_surface *surface) { * track of this and automatically send key events to the appropriate * clients without additional work on your part. */ - seat_focus_surface(server->seat, toplevel->xdg_toplevel->base->surface); + seat_focus_surface(server->seat, surface); } struct wlr_output *get_active_output(struct wb_toplevel *toplevel) { @@ -125,7 +126,7 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data) { wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, toplevel->geometry.width, toplevel->geometry.height); - focus_toplevel(toplevel, toplevel->xdg_toplevel->base->surface); + focus_toplevel(toplevel); wlr_scene_node_set_position(&toplevel->scene_tree->node, toplevel->geometry.x, toplevel->geometry.y); @@ -144,7 +145,7 @@ static void xdg_toplevel_unmap(struct wl_listener *listener, void *data) { if (next_toplevel && next_toplevel->xdg_toplevel && next_toplevel->scene_tree && next_toplevel->scene_tree->node.enabled) { wlr_log(WLR_INFO, "%s: %s", _("Focusing next toplevel"), next_toplevel->xdg_toplevel->app_id); - focus_toplevel(next_toplevel, next_toplevel->xdg_toplevel->base->surface); + focus_toplevel(next_toplevel); } } } @@ -292,9 +293,9 @@ static void xdg_toplevel_request_minimize(struct wl_listener *listener, void *da struct wb_toplevel *next_toplevel = wl_container_of(toplevel->link.next, next_toplevel, link); if (wl_list_length(&toplevel->link) > 1) - focus_toplevel(next_toplevel, next_toplevel->xdg_toplevel->base->surface); + focus_toplevel(next_toplevel); else - focus_toplevel(toplevel, toplevel->xdg_toplevel->base->surface); + focus_toplevel(toplevel); } else { toplevel->geometry = toplevel->previous_geometry; }