mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Simplify popup_unconstrain
Just use the parent output.
This commit is contained in:
		
							parent
							
								
									671a202c94
								
							
						
					
					
						commit
						efda33b285
					
				
					 2 changed files with 10 additions and 68 deletions
				
			
		| 
						 | 
					@ -46,47 +46,18 @@ static void popup_handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void popup_unconstrain(struct sway_xdg_popup *popup) {
 | 
					static void popup_unconstrain(struct sway_xdg_popup *popup) {
 | 
				
			||||||
	// get the output of the popup's positioner anchor point and convert it to
 | 
					 | 
				
			||||||
	// the toplevel parent's coordinate system and then pass it to
 | 
					 | 
				
			||||||
	// wlr_xdg_popup_unconstrain_from_box
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct sway_view *view = popup->child.view;
 | 
						struct sway_view *view = popup->child.view;
 | 
				
			||||||
	struct wlr_output_layout *output_layout =
 | 
					 | 
				
			||||||
		root_container.sway_root->output_layout;
 | 
					 | 
				
			||||||
	struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_surface->popup;
 | 
						struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_surface->popup;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int anchor_lx, anchor_ly;
 | 
						struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
 | 
				
			||||||
	wlr_xdg_popup_get_anchor_point(wlr_popup, &anchor_lx, &anchor_ly);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	int popup_lx, popup_ly;
 | 
					 | 
				
			||||||
	wlr_xdg_popup_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x,
 | 
					 | 
				
			||||||
		wlr_popup->geometry.y, &popup_lx, &popup_ly);
 | 
					 | 
				
			||||||
	popup_lx += view->x;
 | 
					 | 
				
			||||||
	popup_ly += view->y;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	anchor_lx += popup_lx;
 | 
					 | 
				
			||||||
	anchor_ly += popup_ly;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	double dest_x = 0, dest_y = 0;
 | 
					 | 
				
			||||||
	wlr_output_layout_closest_point(output_layout, NULL, anchor_lx, anchor_ly,
 | 
					 | 
				
			||||||
		&dest_x, &dest_y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct wlr_output *output =
 | 
					 | 
				
			||||||
		wlr_output_layout_output_at(output_layout, dest_x, dest_y);
 | 
					 | 
				
			||||||
	if (output == NULL) {
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	int width = 0, height = 0;
 | 
					 | 
				
			||||||
	wlr_output_effective_resolution(output, &width, &height);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// the output box expressed in the coordinate system of the toplevel parent
 | 
						// the output box expressed in the coordinate system of the toplevel parent
 | 
				
			||||||
	// of the popup
 | 
						// of the popup
 | 
				
			||||||
	struct wlr_box output_toplevel_sx_box = {
 | 
						struct wlr_box output_toplevel_sx_box = {
 | 
				
			||||||
		.x = output->lx - view->x,
 | 
							.x = output->x - view->x,
 | 
				
			||||||
		.y = output->ly - view->y,
 | 
							.y = output->y - view->y,
 | 
				
			||||||
		.width = width,
 | 
							.width = output->width,
 | 
				
			||||||
		.height = height
 | 
							.height = output->height,
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
 | 
						wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,47 +45,18 @@ static void popup_handle_destroy(struct wl_listener *listener, void *data) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void popup_unconstrain(struct sway_xdg_popup_v6 *popup) {
 | 
					static void popup_unconstrain(struct sway_xdg_popup_v6 *popup) {
 | 
				
			||||||
	// get the output of the popup's positioner anchor point and convert it to
 | 
					 | 
				
			||||||
	// the toplevel parent's coordinate system and then pass it to
 | 
					 | 
				
			||||||
	// wlr_xdg_popup_unconstrain_from_box
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct sway_view *view = popup->child.view;
 | 
						struct sway_view *view = popup->child.view;
 | 
				
			||||||
	struct wlr_output_layout *output_layout =
 | 
					 | 
				
			||||||
		root_container.sway_root->output_layout;
 | 
					 | 
				
			||||||
	struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_xdg_surface_v6->popup;
 | 
						struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_xdg_surface_v6->popup;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int anchor_lx, anchor_ly;
 | 
						struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
 | 
				
			||||||
	wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_lx, &anchor_ly);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	int popup_lx, popup_ly;
 | 
					 | 
				
			||||||
	wlr_xdg_popup_v6_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x,
 | 
					 | 
				
			||||||
		wlr_popup->geometry.y, &popup_lx, &popup_ly);
 | 
					 | 
				
			||||||
	popup_lx += view->x;
 | 
					 | 
				
			||||||
	popup_ly += view->y;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	anchor_lx += popup_lx;
 | 
					 | 
				
			||||||
	anchor_ly += popup_ly;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	double dest_x = 0, dest_y = 0;
 | 
					 | 
				
			||||||
	wlr_output_layout_closest_point(output_layout, NULL, anchor_lx, anchor_ly,
 | 
					 | 
				
			||||||
		&dest_x, &dest_y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct wlr_output *output =
 | 
					 | 
				
			||||||
		wlr_output_layout_output_at(output_layout, dest_x, dest_y);
 | 
					 | 
				
			||||||
	if (output == NULL) {
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	int width = 0, height = 0;
 | 
					 | 
				
			||||||
	wlr_output_effective_resolution(output, &width, &height);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// the output box expressed in the coordinate system of the toplevel parent
 | 
						// the output box expressed in the coordinate system of the toplevel parent
 | 
				
			||||||
	// of the popup
 | 
						// of the popup
 | 
				
			||||||
	struct wlr_box output_toplevel_sx_box = {
 | 
						struct wlr_box output_toplevel_sx_box = {
 | 
				
			||||||
		.x = output->lx - view->x,
 | 
							.x = output->x - view->x,
 | 
				
			||||||
		.y = output->ly - view->y,
 | 
							.y = output->y - view->y,
 | 
				
			||||||
		.width = width,
 | 
							.width = output->width,
 | 
				
			||||||
		.height = height
 | 
							.height = output->height,
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_xdg_popup_v6_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
 | 
						wlr_xdg_popup_v6_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue