view: Eliminate view_output() and use view->output directly

This commit is contained in:
John Lindgren 2023-02-20 16:35:23 -05:00 committed by Johan Malm
parent 799f81ae05
commit 60fbb44f6a
3 changed files with 41 additions and 55 deletions

View file

@ -129,7 +129,6 @@ void view_move_resize(struct view *view, struct wlr_box geo);
void view_move(struct view *view, int x, int y); void view_move(struct view *view, int x, int y);
void view_moved(struct view *view); void view_moved(struct view *view);
void view_minimize(struct view *view, bool minimized); void view_minimize(struct view *view, bool minimized);
struct output *view_output(struct view *view);
void view_store_natural_geometry(struct view *view); void view_store_natural_geometry(struct view *view);
void view_center(struct view *view, const struct wlr_box *ref); void view_center(struct view *view, const struct wlr_box *ref);
void view_restore_to(struct view *view, struct wlr_box geometry); void view_restore_to(struct view *view, struct wlr_box geometry);

View file

@ -116,17 +116,6 @@ view_discover_output(struct view *view)
view->current.y + view->current.height / 2); view->current.y + view->current.height / 2);
} }
/* deprecated */
struct output *
view_output(struct view *view)
{
assert(view);
if (!output_is_usable(view->output)) {
view_discover_output(view);
}
return view->output;
}
static void static void
_view_set_activated(struct view *view, bool activated) _view_set_activated(struct view *view, bool activated)
{ {
@ -261,13 +250,13 @@ view_compute_centered_position(struct view *view, const struct wlr_box *ref,
wlr_log(WLR_ERROR, "view has empty geometry, not centering"); wlr_log(WLR_ERROR, "view has empty geometry, not centering");
return false; return false;
} }
struct output *output = view_output(view); if (!output_is_usable(view->output)) {
if (!output_is_usable(output)) { wlr_log(WLR_ERROR, "view has no output, not centering");
return false; return false;
} }
struct border margin = ssd_get_margin(view->ssd); struct border margin = ssd_get_margin(view->ssd);
struct wlr_box usable = output_usable_area_in_layout_coords(output); struct wlr_box usable = output_usable_area_in_layout_coords(view->output);
int width = w + margin.left + margin.right; int width = w + margin.left + margin.right;
int height = h + margin.top + margin.bottom; int height = h + margin.top + margin.bottom;
@ -311,7 +300,7 @@ void
view_store_natural_geometry(struct view *view) view_store_natural_geometry(struct view *view)
{ {
assert(view); assert(view);
if (view->maximized || view_is_tiled(view)) { if (!view_is_floating(view)) {
/* Do not overwrite the stored geometry with special cases */ /* Do not overwrite the stored geometry with special cases */
return; return;
} }
@ -342,6 +331,9 @@ view_center(struct view *view, const struct wlr_box *ref)
static void static void
view_apply_natural_geometry(struct view *view) view_apply_natural_geometry(struct view *view)
{ {
assert(view);
assert(view_is_floating(view));
struct wlr_output_layout *layout = view->server->output_layout; struct wlr_output_layout *layout = view->server->output_layout;
if (wlr_output_layout_intersects(layout, NULL, &view->natural_geometry) if (wlr_output_layout_intersects(layout, NULL, &view->natural_geometry)
|| wl_list_empty(&layout->outputs)) { || wl_list_empty(&layout->outputs)) {
@ -362,15 +354,11 @@ view_apply_region_geometry(struct view *view)
{ {
assert(view); assert(view);
assert(view->tiled_region || view->tiled_region_evacuate); assert(view->tiled_region || view->tiled_region_evacuate);
struct output *output = view->output;
assert(output_is_usable(output));
if (view->tiled_region_evacuate) { if (view->tiled_region_evacuate) {
/* View was evacuated from a destroying output */ /* View was evacuated from a destroying output */
struct output *output = view_output(view);
if (!output) {
wlr_log(WLR_INFO, "apply region geometry failed: no more ouputs");
return;
}
/* Get new output local region, may be NULL */ /* Get new output local region, may be NULL */
view->tiled_region = regions_from_name( view->tiled_region = regions_from_name(
view->tiled_region_evacuate, output); view->tiled_region_evacuate, output);
@ -390,8 +378,7 @@ view_apply_region_geometry(struct view *view)
struct wlr_box geo = view->tiled_region->geo; struct wlr_box geo = view->tiled_region->geo;
/* Adjust for rc.gap */ /* Adjust for rc.gap */
struct output *output = view_output(view); if (rc.gap) {
if (rc.gap && output) {
double half_gap = rc.gap / 2.0; double half_gap = rc.gap / 2.0;
struct wlr_fbox offset = { struct wlr_fbox offset = {
.x = half_gap, .x = half_gap,
@ -434,20 +421,18 @@ view_apply_region_geometry(struct view *view)
static void static void
view_apply_tiled_geometry(struct view *view) view_apply_tiled_geometry(struct view *view)
{ {
assert(view);
assert(view->tiled); assert(view->tiled);
struct output *output = view_output(view); assert(output_is_usable(view->output));
if (!output_is_usable(output)) {
wlr_log(WLR_ERROR, "Can't tile: no output");
return;
}
struct wlr_box dst = view_get_edge_snap_box(view, output, view->tiled); view_move_resize(view, view_get_edge_snap_box(view,
view_move_resize(view, dst); view->output, view->tiled));
} }
static void static void
view_apply_fullscreen_geometry(struct view *view) view_apply_fullscreen_geometry(struct view *view)
{ {
assert(view);
assert(view->fullscreen); assert(view->fullscreen);
assert(output_is_usable(view->output)); assert(output_is_usable(view->output));
@ -465,17 +450,11 @@ view_apply_fullscreen_geometry(struct view *view)
static void static void
view_apply_maximized_geometry(struct view *view) view_apply_maximized_geometry(struct view *view)
{ {
/* assert(view);
* The same code handles both initial maximize and re-maximize assert(view->maximized);
* to account for layout changes. In either case, view_output() struct output *output = view->output;
* gives the output closest to the current geometry (which may assert(output_is_usable(output));
* be different from the output originally maximized onto).
* view_output() can return NULL if all outputs are disabled.
*/
struct output *output = view_output(view);
if (!output) {
return;
}
struct wlr_box box = output_usable_area_in_layout_coords(output); struct wlr_box box = output_usable_area_in_layout_coords(output);
if (box.height == output->wlr_output->height if (box.height == output->wlr_output->height
&& output->wlr_output->scale != 1) { && output->wlr_output->scale != 1) {
@ -501,6 +480,10 @@ view_apply_special_geometry(struct view *view)
{ {
assert(view); assert(view);
assert(!view_is_floating(view)); assert(!view_is_floating(view));
if (!output_is_usable(view->output)) {
wlr_log(WLR_ERROR, "view has no output, not updating geometry");
return;
}
if (view->fullscreen) { if (view->fullscreen) {
view_apply_fullscreen_geometry(view); view_apply_fullscreen_geometry(view);
@ -731,8 +714,7 @@ view_set_fullscreen(struct view *view, bool fullscreen)
return; return;
} }
if (fullscreen) { if (fullscreen) {
struct output *output = view_output(view); if (!output_is_usable(view->output)) {
if (!output_is_usable(output)) {
/* Prevent fullscreen with no available outputs */ /* Prevent fullscreen with no available outputs */
return; return;
} }
@ -743,7 +725,6 @@ view_set_fullscreen(struct view *view, bool fullscreen)
*/ */
interactive_cancel(view); interactive_cancel(view);
view_store_natural_geometry(view); view_store_natural_geometry(view);
view->output = output;
} }
set_fullscreen(view, fullscreen); set_fullscreen(view, fullscreen);
@ -812,13 +793,13 @@ void
view_move_to_edge(struct view *view, const char *direction) view_move_to_edge(struct view *view, const char *direction)
{ {
assert(view); assert(view);
struct output *output = view_output(view); struct output *output = view->output;
if (!output) { if (!output_is_usable(output)) {
wlr_log(WLR_ERROR, "no output"); wlr_log(WLR_ERROR, "view has no output, not moving to edge");
return; return;
} }
if (!direction) { if (!direction) {
wlr_log(WLR_ERROR, "invalid edge"); wlr_log(WLR_ERROR, "invalid edge, not moving view");
return; return;
} }
@ -849,7 +830,7 @@ view_move_to_edge(struct view *view, const char *direction)
y = usable.y + usable.height - view->pending.height y = usable.y + usable.height - view->pending.height
- margin.bottom - rc.gap; - margin.bottom - rc.gap;
} else { } else {
wlr_log(WLR_ERROR, "invalid edge"); wlr_log(WLR_ERROR, "invalid edge, not moving view");
return; return;
} }
view_move(view, x, y); view_move(view, x, y);
@ -884,14 +865,14 @@ view_snap_to_edge(struct view *view, const char *direction,
if (view->fullscreen) { if (view->fullscreen) {
return; return;
} }
struct output *output = view_output(view); struct output *output = view->output;
if (output_is_usable(output)) { if (!output_is_usable(output)) {
wlr_log(WLR_ERROR, "no output"); wlr_log(WLR_ERROR, "view has no output, not snapping to edge");
return; return;
} }
enum view_edge edge = view_edge_parse(direction); enum view_edge edge = view_edge_parse(direction);
if (edge == VIEW_EDGE_INVALID) { if (edge == VIEW_EDGE_INVALID) {
wlr_log(WLR_ERROR, "invalid edge"); wlr_log(WLR_ERROR, "invalid edge, not snapping view");
return; return;
} }
@ -971,6 +952,12 @@ view_snap_to_region(struct view *view, struct region *region,
if (view->fullscreen) { if (view->fullscreen) {
return; return;
} }
/* view_apply_region_geometry() needs a usable output */
if (!output_is_usable(view->output)) {
wlr_log(WLR_ERROR, "view has no output, not snapping to region");
return;
}
if (view->maximized) { if (view->maximized) {
/* Unmaximize + keep using existing natural_geometry */ /* Unmaximize + keep using existing natural_geometry */
view_maximize(view, false, /*store_natural_geometry*/ false); view_maximize(view, false, /*store_natural_geometry*/ false);

View file

@ -315,7 +315,7 @@ position_xdg_toplevel_view(struct view *view)
struct view *parent = lookup_view_by_xdg_toplevel( struct view *parent = lookup_view_by_xdg_toplevel(
view->server, parent_xdg_toplevel); view->server, parent_xdg_toplevel);
assert(parent); assert(parent);
view->output = view_output(parent); view->output = parent->output;
view_center(view, &parent->pending); view_center(view, &parent->pending);
} }
} }