mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	view: add view_output() and view_wlr_output()
This commit is contained in:
		
							parent
							
								
									2e4f931469
								
							
						
					
					
						commit
						10264110f1
					
				
					 1 changed files with 18 additions and 15 deletions
				
			
		
							
								
								
									
										33
									
								
								src/view.c
									
										
									
									
									
								
							
							
						
						
									
										33
									
								
								src/view.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -35,10 +35,10 @@ view_unminimize(struct view *view)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * view_output - return the output that a view is mostly on
 | 
			
		||||
 * view_wlr_output - return the output that a view is mostly on
 | 
			
		||||
 */
 | 
			
		||||
static struct wlr_output *
 | 
			
		||||
view_output(struct view *view)
 | 
			
		||||
view_wlr_output(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
	struct wlr_output_layout *layout = view->server->output_layout;
 | 
			
		||||
	struct wlr_output *output;
 | 
			
		||||
| 
						 | 
				
			
			@ -49,19 +49,26 @@ view_output(struct view *view)
 | 
			
		|||
	return output;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct output *
 | 
			
		||||
view_output(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
	struct wlr_output *wlr_output = view_wlr_output(view);
 | 
			
		||||
	return output_from_wlr_output(view->server, wlr_output);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
view_center(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
	struct wlr_output *output = view_output(view);
 | 
			
		||||
	if (!output) {
 | 
			
		||||
	struct wlr_output *wlr_output = view_wlr_output(view);
 | 
			
		||||
	if (!wlr_output) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct wlr_output_layout *layout = view->server->output_layout;
 | 
			
		||||
	struct wlr_output_layout_output* ol_output =
 | 
			
		||||
		wlr_output_layout_get(layout, output);
 | 
			
		||||
	int center_x = ol_output->x + output->width / 2;
 | 
			
		||||
	int center_y = ol_output->y + output->height / 2;
 | 
			
		||||
		wlr_output_layout_get(layout, wlr_output);
 | 
			
		||||
	int center_x = ol_output->x + wlr_output->width / 2;
 | 
			
		||||
	int center_y = ol_output->y + wlr_output->height / 2;
 | 
			
		||||
	view_move(view, center_x - view->w / 2, center_y - view->h / 2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -78,16 +85,13 @@ view_maximize(struct view *view, bool maximize)
 | 
			
		|||
		view->unmaximized_geometry.width = view->w;
 | 
			
		||||
		view->unmaximized_geometry.height = view->h;
 | 
			
		||||
 | 
			
		||||
		struct wlr_output *wlr_output = view_output(view);
 | 
			
		||||
		struct output *output =
 | 
			
		||||
			output_from_wlr_output(view->server, wlr_output);
 | 
			
		||||
 | 
			
		||||
		struct output *output = view_output(view);
 | 
			
		||||
		struct wlr_box box;
 | 
			
		||||
		memcpy(&box, &output->usable_area, sizeof(struct wlr_box));
 | 
			
		||||
 | 
			
		||||
		double ox = 0, oy = 0;
 | 
			
		||||
		wlr_output_layout_output_coords(view->server->output_layout,
 | 
			
		||||
			wlr_output, &ox, &oy);
 | 
			
		||||
			output->wlr_output, &ox, &oy);
 | 
			
		||||
		box.x -= ox;
 | 
			
		||||
		box.y -= oy;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -98,10 +102,9 @@ view_maximize(struct view *view, bool maximize)
 | 
			
		|||
			box.width -= border.right + border.left;
 | 
			
		||||
			box.height -= border.top + border.bottom;
 | 
			
		||||
		}
 | 
			
		||||
		box.width /= wlr_output->scale;
 | 
			
		||||
		box.height /= wlr_output->scale;
 | 
			
		||||
		box.width /= output->wlr_output->scale;
 | 
			
		||||
		box.height /= output->wlr_output->scale;
 | 
			
		||||
		view_move_resize(view, box);
 | 
			
		||||
		view_move(view, box.x, box.y);
 | 
			
		||||
		view->maximized = true;
 | 
			
		||||
	} else {
 | 
			
		||||
		/* unmaximize */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue