Commit 441c054ff901a87601202c74e06bfce15b6f17a6 Parent: 35fb5518f44b97e24c96c75da753efbe14e20559 Author: mcol <mcol@posteo.net> Date: 2021-02-12 10:30:49 +0000 Committer: mcol <mcol@posteo.net> Committed: 2021-02-12 10:30:49 +0000 add view_apply_geometry function to clean up some repeated code use
src/shell.h Modified
@@ -3,6 +3,7 @@ #include "types.h" +void view_apply_geometry(struct view *view, struct wlr_box *geo); void unmap_view(struct view *view); void map_view(struct view *view); void focus(void *aview, struct wlr_surface *surface, bool is_layer);
src/shell.c Modified
@@ -9,6 +9,22 @@ #include "types.h" +void view_apply_geometry(struct view *view, struct wlr_box *new) { + struct wlr_box old = { + .x = view->x, + .y = view->y, + .width = view->surface->geometry.width, + .height = view->surface->geometry.height, + }; + + view->x = new->x; + view->y = new->y, + wlr_xdg_toplevel_set_size(view->surface, new->width, new->height); + damage_box(&old, true); + damage_box(new, true); +} + + void unmap_view(struct view *view) { wl_signal_emit(&view->surface->events.unmap, view); } @@ -158,6 +174,7 @@ struct wlr_xdg_surface *prev_surface = wimp.current_desk->fullscreened; if (prev_surface) { wlr_xdg_toplevel_set_fullscreen(prev_surface, false); + wlr_xdg_toplevel_set_tiled(view->surface, true); wlr_xdg_toplevel_set_size(prev_surface, saved_geo->width, saved_geo->height); view->x = saved_geo->x; view->y = saved_geo->y; @@ -186,6 +203,7 @@ saved_geo->width = xdg_surface->geometry.width; saved_geo->height = xdg_surface->geometry.height; wlr_xdg_toplevel_set_fullscreen(xdg_surface, true); + wlr_xdg_toplevel_set_tiled(view->surface, false); double zoom = wimp.current_desk->zoom; wlr_xdg_toplevel_set_size(xdg_surface, wlr_output->width / zoom, wlr_output->height / zoom); struct output *output = wlr_output->data; @@ -239,6 +257,7 @@ scratchpad->is_mapped = true; } + wlr_xdg_toplevel_set_tiled(view->surface, true); focus_view(view, NULL); }
src/action.c Modified
@@ -324,9 +324,10 @@ void halfimize(void *data) { - if (wl_list_empty(&wimp.current_desk->views)) + struct wlr_surface *surface = wimp.seat->keyboard_state.focused_surface; + if (!surface || !wlr_surface_is_xdg_surface(surface) || wl_list_empty(&wimp.current_desk->views)) { return; - + } struct view *view = wl_container_of(wimp.current_desk->views.next, view, link); enum direction dir = *(enum direction*)data; double vx = view->x + view->surface->geometry.width / 2; @@ -367,19 +368,21 @@ double zoom = wimp.current_desk->zoom; int border_width = wimp.current_desk->border_width; - view->x = x / zoom + border_width; - view->y = y / zoom + border_width; - width -= border_width * 2; - height -= border_width * 2; - wlr_xdg_toplevel_set_size(view->surface, width / zoom, height / zoom); - wlr_xdg_toplevel_set_tiled(view->surface, true); - damage_all_outputs(); + struct wlr_box new = { + .x = x / zoom + border_width, + .y = y / zoom + border_width, + .width = (width - border_width * 2) / zoom, + .height = (height - border_width * 2) / zoom, + }; + view_apply_geometry(view, &new); } void maximize(void *data) { - if (wl_list_empty(&wimp.current_desk->views)) + struct wlr_surface *surface = wimp.seat->keyboard_state.focused_surface; + if (!surface || !wlr_surface_is_xdg_surface(surface) || wl_list_empty(&wimp.current_desk->views)) { return; + } struct view *view = wl_container_of(wimp.current_desk->views.next, view, link); double vx = view->x + view->surface->geometry.width / 2;