mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	view: Unify view_move()/view_move_resize()
view->impl->move() is a specific case of view->impl->configure(). To reduce code duplication, we can use view->impl->configure() for pure moves (without resize) as well. xwayland's move() function also possibly contained a race condition when there was a pending resize, as it used the current surface width/height rather than the pending width/height. This is fixed.
This commit is contained in:
		
							parent
							
								
									859eba1c6b
								
							
						
					
					
						commit
						0ca6c4c763
					
				
					 4 changed files with 16 additions and 54 deletions
				
			
		| 
						 | 
				
			
			@ -26,7 +26,6 @@ struct view_impl {
 | 
			
		|||
	void (*close)(struct view *view);
 | 
			
		||||
	const char *(*get_string_prop)(struct view *view, const char *prop);
 | 
			
		||||
	void (*map)(struct view *view);
 | 
			
		||||
	void (*move)(struct view *view, int x, int y);
 | 
			
		||||
	void (*set_activated)(struct view *view, bool activated);
 | 
			
		||||
	void (*set_fullscreen)(struct view *view, bool fullscreen);
 | 
			
		||||
	void (*unmap)(struct view *view);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -143,9 +143,11 @@ void
 | 
			
		|||
view_move(struct view *view, int x, int y)
 | 
			
		||||
{
 | 
			
		||||
	assert(view);
 | 
			
		||||
	if (view->impl->move) {
 | 
			
		||||
		view->impl->move(view, x, y);
 | 
			
		||||
	}
 | 
			
		||||
	view_move_resize(view, (struct wlr_box){
 | 
			
		||||
		.x = x, .y = y,
 | 
			
		||||
		.width = view->pending.width,
 | 
			
		||||
		.height = view->pending.height
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										40
									
								
								src/xdg.c
									
										
									
									
									
								
							
							
						
						
									
										40
									
								
								src/xdg.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -200,46 +200,25 @@ handle_set_app_id(struct wl_listener *listener, void *data)
 | 
			
		|||
	view_update_app_id(view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
xdg_toplevel_view_move(struct view *view, int x, int y)
 | 
			
		||||
{
 | 
			
		||||
	/* override any previous pending move */
 | 
			
		||||
	view->pending.x = x;
 | 
			
		||||
	view->pending.y = y;
 | 
			
		||||
 | 
			
		||||
	/* Syncs moves with resizes  */
 | 
			
		||||
	if (view->pending_configure_serial > 0) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view->current.x = x;
 | 
			
		||||
	view->current.y = y;
 | 
			
		||||
	view_moved(view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
xdg_toplevel_view_configure(struct view *view, struct wlr_box geo)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t serial = 0;
 | 
			
		||||
	view_adjust_size(view, &geo.width, &geo.height);
 | 
			
		||||
 | 
			
		||||
	if (view->pending.width == geo.width && view->pending.height == geo.height) {
 | 
			
		||||
	/*
 | 
			
		||||
		 * As wayland has no notion of a global position
 | 
			
		||||
		 * we are only updating the size. If a wayland
 | 
			
		||||
		 * client receives the same size it already has
 | 
			
		||||
		 * it might not respond to the configure request
 | 
			
		||||
		 * and thus we will never actually set the new
 | 
			
		||||
		 * position. To handle this case just call move
 | 
			
		||||
		 * directly.
 | 
			
		||||
	 * We do not need to send a configure request unless the size
 | 
			
		||||
	 * changed (wayland has no notion of a global position). If the
 | 
			
		||||
	 * size is the same (and there is no pending configure request)
 | 
			
		||||
	 * then we can just move the view directly.
 | 
			
		||||
	 */
 | 
			
		||||
		xdg_toplevel_view_move(view, geo.x, geo.y);
 | 
			
		||||
		return;
 | 
			
		||||
	if (geo.width != view->pending.width
 | 
			
		||||
			|| geo.height != view->pending.height) {
 | 
			
		||||
		serial = wlr_xdg_toplevel_set_size(xdg_toplevel_from_view(view),
 | 
			
		||||
			geo.width, geo.height);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view->pending = geo;
 | 
			
		||||
	struct wlr_xdg_toplevel *xdg_toplevel = xdg_toplevel_from_view(view);
 | 
			
		||||
	uint32_t serial = wlr_xdg_toplevel_set_size(xdg_toplevel,
 | 
			
		||||
		(uint32_t)geo.width, (uint32_t)geo.height);
 | 
			
		||||
	if (serial > 0) {
 | 
			
		||||
		view->pending_configure_serial = serial;
 | 
			
		||||
	} else if (view->pending_configure_serial == 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -401,7 +380,6 @@ static const struct view_impl xdg_toplevel_view_impl = {
 | 
			
		|||
	.close = xdg_toplevel_view_close,
 | 
			
		||||
	.get_string_prop = xdg_toplevel_view_get_string_prop,
 | 
			
		||||
	.map = xdg_toplevel_view_map,
 | 
			
		||||
	.move = xdg_toplevel_view_move,
 | 
			
		||||
	.set_activated = xdg_toplevel_view_set_activated,
 | 
			
		||||
	.set_fullscreen = xdg_toplevel_view_set_fullscreen,
 | 
			
		||||
	.unmap = xdg_toplevel_view_unmap,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -386,22 +386,6 @@ handle_set_class(struct wl_listener *listener, void *data)
 | 
			
		|||
	view_update_app_id(view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
move(struct view *view, int x, int y)
 | 
			
		||||
{
 | 
			
		||||
	view->current.x = x;
 | 
			
		||||
	view->current.y = y;
 | 
			
		||||
 | 
			
		||||
	/* override any previous pending move */
 | 
			
		||||
	view->pending.x = x;
 | 
			
		||||
	view->pending.y = y;
 | 
			
		||||
 | 
			
		||||
	struct wlr_xwayland_surface *s = xwayland_surface_from_view(view);
 | 
			
		||||
	wlr_xwayland_surface_configure(s, (int16_t)x, (int16_t)y,
 | 
			
		||||
		(uint16_t)s->width, (uint16_t)s->height);
 | 
			
		||||
	view_moved(view);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
_close(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -615,7 +599,6 @@ static const struct view_impl xwl_view_impl = {
 | 
			
		|||
	.close = _close,
 | 
			
		||||
	.get_string_prop = get_string_prop,
 | 
			
		||||
	.map = map,
 | 
			
		||||
	.move = move,
 | 
			
		||||
	.set_activated = set_activated,
 | 
			
		||||
	.set_fullscreen = set_fullscreen,
 | 
			
		||||
	.unmap = unmap,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue