view: expose view_set_maximized() instead of view_restore_to()

view_restore_to() (which is just set_maximized() + view_move_resize())
hasn't aged well and doesn't line up with typical usage anymore:

 - it's missing view_set_untiled(), which has to be called separately
 - it always forces view_move_resize() even when that's not needed
 - it doesn't allow un-maximizing only one axis (see next commit)
 - the fullscreen check is unnecessary (already checked in callers)

Eliminate it and just expose view_set_maximized() instead.

No functional change intended in this commit.
This commit is contained in:
John Lindgren 2025-09-01 11:49:24 -04:00 committed by Johan Malm
parent 72a5df16ea
commit 6d2140c4b7
4 changed files with 20 additions and 27 deletions

View file

@ -518,7 +518,7 @@ void view_place_by_policy(struct view *view, bool allow_cursor,
enum lab_placement_policy policy); enum lab_placement_policy policy);
void view_constrain_size_to_that_of_usable_area(struct view *view); void view_constrain_size_to_that_of_usable_area(struct view *view);
void view_restore_to(struct view *view, struct wlr_box geometry); void view_set_maximized(struct view *view, enum view_axis maximized);
void view_set_untiled(struct view *view); void view_set_untiled(struct view *view);
void view_maximize(struct view *view, enum view_axis axis, void view_maximize(struct view *view, enum view_axis axis,
bool store_natural_geometry); bool store_natural_geometry);

View file

@ -291,8 +291,9 @@ process_cursor_move(struct server *server, uint32_t time)
interactive_anchor_to_cursor(server, &new_geo); interactive_anchor_to_cursor(server, &new_geo);
/* Shaded clients will not process resize events until unshaded */ /* Shaded clients will not process resize events until unshaded */
view_set_shade(view, false); view_set_shade(view, false);
view_set_maximized(view, VIEW_AXIS_NONE);
view_set_untiled(view); view_set_untiled(view);
view_restore_to(view, new_geo); view_move_resize(view, new_geo);
x = new_geo.x; x = new_geo.x;
y = new_geo.y; y = new_geo.y;
} }

View file

@ -122,8 +122,8 @@ interactive_begin(struct view *view, enum input_mode mode, enum lab_edge edges)
* maximized/tiled state but keep the same geometry as * maximized/tiled state but keep the same geometry as
* the starting point for the resize. * the starting point for the resize.
*/ */
view_set_maximized(view, VIEW_AXIS_NONE);
view_set_untiled(view); view_set_untiled(view);
view_restore_to(view, view->pending);
cursor_shape = cursor_get_from_edge(edges); cursor_shape = cursor_get_from_edge(edges);
break; break;
default: default:
@ -153,8 +153,9 @@ interactive_begin(struct view *view, enum input_mode mode, enum lab_edge edges)
interactive_anchor_to_cursor(server, &natural_geo); interactive_anchor_to_cursor(server, &natural_geo);
/* Shaded clients will not process resize events until unshaded */ /* Shaded clients will not process resize events until unshaded */
view_set_shade(view, false); view_set_shade(view, false);
view_set_maximized(view, VIEW_AXIS_NONE);
view_set_untiled(view); view_set_untiled(view);
view_restore_to(view, natural_geo); view_move_resize(view, natural_geo);
} }
if (rc.resize_indicator) { if (rc.resize_indicator) {

View file

@ -660,7 +660,7 @@ view_move_relative(struct view *view, int x, int y)
view_maximize(view, VIEW_AXIS_NONE, /*store_natural_geometry*/ false); view_maximize(view, VIEW_AXIS_NONE, /*store_natural_geometry*/ false);
if (view_is_tiled(view)) { if (view_is_tiled(view)) {
view_set_untiled(view); view_set_untiled(view);
view_restore_to(view, view->natural_geometry); view_move_resize(view, view->natural_geometry);
} }
view_move(view, view->pending.x + x, view->pending.y + y); view_move(view, view->pending.x + x, view->pending.y + y);
} }
@ -678,7 +678,7 @@ view_move_to_cursor(struct view *view)
view_maximize(view, VIEW_AXIS_NONE, /*store_natural_geometry*/ false); view_maximize(view, VIEW_AXIS_NONE, /*store_natural_geometry*/ false);
if (view_is_tiled(view)) { if (view_is_tiled(view)) {
view_set_untiled(view); view_set_untiled(view);
view_restore_to(view, view->natural_geometry); view_move_resize(view, view->natural_geometry);
} }
struct border margin = ssd_thickness(view); struct border margin = ssd_thickness(view);
@ -1367,10 +1367,18 @@ view_apply_special_geometry(struct view *view)
} }
} }
/* For internal use only. Does not update geometry. */ /*
static void * Sets maximized state without updating geometry. Used in interactive
set_maximized(struct view *view, enum view_axis maximized) * move/resize. In most other cases, use view_maximize() instead.
*/
void
view_set_maximized(struct view *view, enum view_axis maximized)
{ {
assert(view);
if (view->maximized == maximized) {
return;
}
if (view->impl->maximize) { if (view->impl->maximize) {
view->impl->maximize(view, maximized); view->impl->maximize(view, maximized);
} }
@ -1386,23 +1394,6 @@ set_maximized(struct view *view, enum view_axis maximized)
ssd_update_margin(view->ssd); ssd_update_margin(view->ssd);
} }
/*
* Un-maximize view and move it to specific geometry. Does not reset
* tiled state (use view_set_untiled() if you want that).
*/
void
view_restore_to(struct view *view, struct wlr_box geometry)
{
assert(view);
if (view->fullscreen) {
return;
}
if (view->maximized != VIEW_AXIS_NONE) {
set_maximized(view, VIEW_AXIS_NONE);
}
view_move_resize(view, geometry);
}
bool bool
view_is_tiled(struct view *view) view_is_tiled(struct view *view)
{ {
@ -1505,7 +1496,7 @@ view_maximize(struct view *view, enum view_axis axis,
view->natural_geometry = view_get_fallback_natural_geometry(view); view->natural_geometry = view_get_fallback_natural_geometry(view);
} }
set_maximized(view, axis); view_set_maximized(view, axis);
if (view_is_floating(view)) { if (view_is_floating(view)) {
view_apply_natural_geometry(view); view_apply_natural_geometry(view);
} else { } else {