mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	cursor.c: Keep sending adjusted motion events while button is pressed
This allows to keep dragging a scrollbar or selecting text even when moving outside of the window. Fixes #241
This commit is contained in:
		
							parent
							
								
									afa3eb1572
								
							
						
					
					
						commit
						00b2925461
					
				
					 4 changed files with 35 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -79,6 +79,18 @@ struct seat {
 | 
			
		|||
	/* if set, views cannot receive focus */
 | 
			
		||||
	struct wlr_layer_surface_v1 *focused_layer;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * active_view will usually be NULL and is only set on button press
 | 
			
		||||
	 * while the mouse is over a view surface and reset to NULL on button
 | 
			
		||||
	 * release.
 | 
			
		||||
	 * It is used to send cursor motion events to a surface even though
 | 
			
		||||
	 * the cursor has left the surface in the meantime.
 | 
			
		||||
	 *
 | 
			
		||||
	 * This allows to keep dragging a scrollbar or selecting text even
 | 
			
		||||
	 * when moving outside of the window.
 | 
			
		||||
	 */
 | 
			
		||||
	struct view *active_view;
 | 
			
		||||
 | 
			
		||||
	struct wl_client *active_client_while_inhibited;
 | 
			
		||||
	struct wl_list inputs;
 | 
			
		||||
	struct wl_listener new_input;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								src/cursor.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								src/cursor.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -213,6 +213,15 @@ process_cursor_motion(struct server *server, uint32_t time)
 | 
			
		|||
			server->seat.cursor->x, server->seat.cursor->y);
 | 
			
		||||
		damage_all_outputs(server);
 | 
			
		||||
		return;
 | 
			
		||||
	} else if (server->seat.active_view && !server->seat.drag_icon) {
 | 
			
		||||
		/* Button has been pressed while over a view surface */
 | 
			
		||||
		struct view *view = server->seat.active_view;
 | 
			
		||||
		double sx = server->seat.cursor->x - view->x;
 | 
			
		||||
		double sy = server->seat.cursor->y - view->y;
 | 
			
		||||
		sx = sx < 0 ? 0 : (sx > view->w ? view->w : sx);
 | 
			
		||||
		sy = sy < 0 ? 0 : (sy > view->h ? view->h : sy);
 | 
			
		||||
		wlr_seat_pointer_notify_motion(server->seat.seat, time, sx, sy);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Otherwise, find view under the pointer and send the event along */
 | 
			
		||||
| 
						 | 
				
			
			@ -321,6 +330,7 @@ start_drag(struct wl_listener *listener, void *data)
 | 
			
		|||
{
 | 
			
		||||
	struct seat *seat = wl_container_of(listener, seat, start_drag);
 | 
			
		||||
	struct wlr_drag *wlr_drag = data;
 | 
			
		||||
	seat->active_view = NULL;
 | 
			
		||||
	seat->drag_icon = wlr_drag->icon;
 | 
			
		||||
	wl_signal_add(&seat->drag_icon->events.destroy, &seat->destroy_drag);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -627,6 +637,8 @@ cursor_button(struct wl_listener *listener, void *data)
 | 
			
		|||
 | 
			
		||||
	/* handle _release_ */
 | 
			
		||||
	if (event->state == WLR_BUTTON_RELEASED) {
 | 
			
		||||
		server->seat.active_view = NULL;
 | 
			
		||||
 | 
			
		||||
		if (server->input_mode == LAB_INPUT_STATE_MENU) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -658,6 +670,11 @@ cursor_button(struct wl_listener *listener, void *data)
 | 
			
		|||
		goto mousebindings;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Handle _press */
 | 
			
		||||
	if (view_area == LAB_SSD_CLIENT) {
 | 
			
		||||
		server->seat.active_view = view;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (server->input_mode == LAB_INPUT_STATE_MENU) {
 | 
			
		||||
		if (server->rootmenu->visible) {
 | 
			
		||||
			menu_action_selected(server, server->rootmenu);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -96,6 +96,9 @@ handle_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
		wlr_foreign_toplevel_handle_v1_destroy(view->toplevel_handle);
 | 
			
		||||
	}
 | 
			
		||||
	interactive_end(view);
 | 
			
		||||
	if (view->server->seat.active_view == view) {
 | 
			
		||||
		view->server->seat.active_view = NULL;
 | 
			
		||||
	}
 | 
			
		||||
	wl_list_remove(&view->link);
 | 
			
		||||
	wl_list_remove(&view->destroy.link);
 | 
			
		||||
	ssd_destroy(view);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,6 +82,9 @@ handle_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
		wlr_foreign_toplevel_handle_v1_destroy(view->toplevel_handle);
 | 
			
		||||
	}
 | 
			
		||||
	interactive_end(view);
 | 
			
		||||
	if (view->server->seat.active_view == view) {
 | 
			
		||||
		view->server->seat.active_view = NULL;
 | 
			
		||||
	}
 | 
			
		||||
	view->xwayland_surface = NULL;
 | 
			
		||||
	wl_list_remove(&view->link);
 | 
			
		||||
	wl_list_remove(&view->map.link);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue