mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	view: Set view->output prior to calling view_center()
This commit is contained in:
		
							parent
							
								
									bdbbbb2e62
								
							
						
					
					
						commit
						a9cbbe1e41
					
				
					 4 changed files with 16 additions and 19 deletions
				
			
		| 
						 | 
					@ -131,9 +131,7 @@ 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);
 | 
					struct output *view_output(struct view *view);
 | 
				
			||||||
void view_store_natural_geometry(struct view *view);
 | 
					void view_store_natural_geometry(struct view *view);
 | 
				
			||||||
/* output is optional, defaults to current nearest output */
 | 
					void view_center(struct view *view, const struct wlr_box *ref);
 | 
				
			||||||
void view_center(struct view *view, struct output *output,
 | 
					 | 
				
			||||||
	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);
 | 
				
			||||||
void view_set_untiled(struct view *view);
 | 
					void view_set_untiled(struct view *view);
 | 
				
			||||||
void view_maximize(struct view *view, bool maximize,
 | 
					void view_maximize(struct view *view, bool maximize,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										22
									
								
								src/view.c
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								src/view.c
									
										
									
									
									
								
							| 
						 | 
					@ -254,19 +254,17 @@ view_minimize(struct view *view, bool minimized)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool
 | 
					static bool
 | 
				
			||||||
view_compute_centered_position(struct view *view, struct output *output,
 | 
					view_compute_centered_position(struct view *view, const struct wlr_box *ref,
 | 
				
			||||||
		const struct wlr_box *ref, int w, int h, int *x, int *y)
 | 
							int w, int h, int *x, int *y)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (w <= 0 || h <= 0) {
 | 
						if (w <= 0 || h <= 0) {
 | 
				
			||||||
		wlr_log(WLR_ERROR, "view has empty geometry, not centering");
 | 
							wlr_log(WLR_ERROR, "view has empty geometry, not centering");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!output_is_usable(output)) {
 | 
						struct output *output = view_output(view);
 | 
				
			||||||
		output = view_output(view);
 | 
					 | 
				
			||||||
	if (!output_is_usable(output)) {
 | 
						if (!output_is_usable(output)) {
 | 
				
			||||||
		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(output);
 | 
				
			||||||
| 
						 | 
					@ -299,7 +297,7 @@ set_fallback_geometry(struct view *view)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	view->natural_geometry.width = LAB_FALLBACK_WIDTH;
 | 
						view->natural_geometry.width = LAB_FALLBACK_WIDTH;
 | 
				
			||||||
	view->natural_geometry.height = LAB_FALLBACK_HEIGHT;
 | 
						view->natural_geometry.height = LAB_FALLBACK_HEIGHT;
 | 
				
			||||||
	view_compute_centered_position(view, NULL, NULL,
 | 
						view_compute_centered_position(view, NULL,
 | 
				
			||||||
		view->natural_geometry.width,
 | 
							view->natural_geometry.width,
 | 
				
			||||||
		view->natural_geometry.height,
 | 
							view->natural_geometry.height,
 | 
				
			||||||
		&view->natural_geometry.x,
 | 
							&view->natural_geometry.x,
 | 
				
			||||||
| 
						 | 
					@ -331,12 +329,12 @@ view_store_natural_geometry(struct view *view)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
view_center(struct view *view, struct output *output, const struct wlr_box *ref)
 | 
					view_center(struct view *view, const struct wlr_box *ref)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	assert(view);
 | 
						assert(view);
 | 
				
			||||||
	int x, y;
 | 
						int x, y;
 | 
				
			||||||
	if (view_compute_centered_position(view, output, ref,
 | 
						if (view_compute_centered_position(view, ref, view->pending.width,
 | 
				
			||||||
			view->pending.width, view->pending.height, &x, &y)) {
 | 
								view->pending.height, &x, &y)) {
 | 
				
			||||||
		view_move(view, x, y);
 | 
							view_move(view, x, y);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -352,8 +350,8 @@ view_apply_natural_geometry(struct view *view)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		/* reposition if original geometry is offscreen */
 | 
							/* reposition if original geometry is offscreen */
 | 
				
			||||||
		struct wlr_box box = view->natural_geometry;
 | 
							struct wlr_box box = view->natural_geometry;
 | 
				
			||||||
		if (view_compute_centered_position(view, NULL, NULL,
 | 
							if (view_compute_centered_position(view, NULL, box.width,
 | 
				
			||||||
				box.width, box.height, &box.x, &box.y)) {
 | 
									box.height, &box.x, &box.y)) {
 | 
				
			||||||
			view_move_resize(view, box);
 | 
								view_move_resize(view, box);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -777,7 +775,7 @@ view_adjust_for_layout_change(struct view *view)
 | 
				
			||||||
			if (!wlr_output_layout_intersects(
 | 
								if (!wlr_output_layout_intersects(
 | 
				
			||||||
					view->server->output_layout,
 | 
										view->server->output_layout,
 | 
				
			||||||
					NULL, &view->pending)) {
 | 
										NULL, &view->pending)) {
 | 
				
			||||||
				view_center(view, NULL, NULL);
 | 
									view_center(view, NULL);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -306,7 +306,7 @@ position_xdg_toplevel_view(struct view *view)
 | 
				
			||||||
		xdg_toplevel_from_view(view)->parent;
 | 
							xdg_toplevel_from_view(view)->parent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!parent_xdg_toplevel) {
 | 
						if (!parent_xdg_toplevel) {
 | 
				
			||||||
		view_center(view, output_nearest_to_cursor(view->server), NULL);
 | 
							view_center(view, NULL);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * If child-toplevel-views, we center-align relative to their
 | 
							 * If child-toplevel-views, we center-align relative to their
 | 
				
			||||||
| 
						 | 
					@ -315,7 +315,8 @@ 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_center(view, view_output(parent), &parent->pending);
 | 
							view->output = view_output(parent);
 | 
				
			||||||
 | 
							view_center(view, &parent->pending);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -400,7 +400,7 @@ set_initial_position(struct view *view,
 | 
				
			||||||
		/* Just make sure the view is on-screen */
 | 
							/* Just make sure the view is on-screen */
 | 
				
			||||||
		view_adjust_for_layout_change(view);
 | 
							view_adjust_for_layout_change(view);
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		view_center(view, output_nearest_to_cursor(view->server), NULL);
 | 
							view_center(view, NULL);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue