Commit 84db95bd6be7604ea9dddb210b1ab3cf172e30c3 Parent: c1d52b45869bb6a30b15eebd2eb1bc095c8ab7a9 Author: mcol <mcol@posteo.net> Date: 2021-01-20 18:50:24 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-01-20 18:50:24 +0000 Set fullscreen windows size to that of specified or nearest output
src/shell.h Modified
@@ -6,7 +6,9 @@ void unmap_view(struct view *view); void map_view(struct view *view); void focus_view(struct view *view, struct wlr_surface *surface); -void fullscreen_xdg_surface(struct server *server, struct wlr_xdg_surface *xdg_surface); +void fullscreen_xdg_surface( + struct server *server, struct wlr_xdg_surface *xdg_surface, struct wlr_output *output +); void set_up_shell(struct server *server); #endif
src/shell.c Modified
@@ -43,27 +43,32 @@ } -void fullscreen_xdg_surface(struct server *server, struct wlr_xdg_surface *xdg_surface) { - struct wlr_box geo; +void fullscreen_xdg_surface( + struct server *server, struct wlr_xdg_surface *xdg_surface, struct wlr_output *output +) { struct wlr_xdg_surface *prev_surface = server->current_desk->fullscreened; - if (prev_surface) { wlr_xdg_toplevel_set_fullscreen(prev_surface, false); - geo = server->current_desk->fullscreened_saved_geo; - xdg_surface->toplevel->server_pending.width = geo.width; - xdg_surface->toplevel->server_pending.height = geo.height; - if (prev_surface == xdg_surface) { - server->current_desk->fullscreened = NULL; - return; - } + wlr_xdg_toplevel_set_size( + prev_surface, + server->current_desk->fullscreened_saved_geo.width, + server->current_desk->fullscreened_saved_geo.height + ); } - wlr_xdg_toplevel_set_fullscreen(xdg_surface, true); + if (prev_surface == xdg_surface) { + server->current_desk->fullscreened = NULL; + return; + } + + if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) + return; + server->current_desk->fullscreened = xdg_surface; server->current_desk->fullscreened_saved_geo.width = xdg_surface->geometry.width; server->current_desk->fullscreened_saved_geo.height = xdg_surface->geometry.height; - xdg_surface->toplevel->server_pending.width = 1000; - xdg_surface->toplevel->server_pending.height = 1000; + wlr_xdg_toplevel_set_fullscreen(xdg_surface, true); + wlr_xdg_toplevel_set_size(xdg_surface, output->width, output->height); } @@ -131,7 +136,7 @@ void on_request_fullscreen(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_set_fullscreen_event *event = data; struct view *view = wl_container_of(listener, view, request_fullscreen_listener); - fullscreen_xdg_surface(view->server, event->surface); + fullscreen_xdg_surface(view->server, event->surface, event->output); }
src/action.c Modified
@@ -194,6 +194,19 @@ void toggle_fullscreen(struct server *server, void *data) { struct wlr_surface *surface = server->seat->keyboard_state.focused_surface; - if (surface) - fullscreen_xdg_surface(server, wlr_xdg_surface_from_wlr_surface(surface)); + if (!surface) + return; + + struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_from_wlr_surface(surface); + double x = xdg_surface->geometry.width / 2; + double y = xdg_surface->geometry.height / 2; + + struct wlr_output *output = wlr_output_layout_output_at(server->output_layout, x, y); + if (output == NULL) { + double lx, ly; + wlr_output_layout_closest_point(server->output_layout, NULL, x, y, &lx, &ly); + output = wlr_output_layout_output_at(server->output_layout, lx, ly); + } + + fullscreen_xdg_surface(server, xdg_surface, output); }