mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Enable windows to register to get notified when the mouse wheel is scrolled
This commit is contained in:
		
							parent
							
								
									250ddc66c6
								
							
						
					
					
						commit
						c0b7610c26
					
				
					 2 changed files with 29 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -27,11 +27,20 @@ struct cursor {
 | 
			
		|||
	struct wl_poitner *pointer;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum scroll_direction {
 | 
			
		||||
	SCROLL_UP,
 | 
			
		||||
	SCROLL_DOWN,
 | 
			
		||||
	SCROLL_LEFT,
 | 
			
		||||
	SCROLL_RIGHT,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct pointer_input {
 | 
			
		||||
	int last_x;
 | 
			
		||||
	int last_y;
 | 
			
		||||
 | 
			
		||||
	void (*notify_button)(struct window *window, int x, int y, uint32_t button);
 | 
			
		||||
 | 
			
		||||
	void (*notify_scroll)(struct window *window, enum scroll_direction direction);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct window {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,6 +48,25 @@ static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32
 | 
			
		|||
 | 
			
		||||
static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
 | 
			
		||||
				uint32_t time, uint32_t axis, wl_fixed_t value) {
 | 
			
		||||
	struct window *window = data;
 | 
			
		||||
	enum scroll_direction direction;
 | 
			
		||||
 | 
			
		||||
	switch (axis) {
 | 
			
		||||
	case 0:
 | 
			
		||||
		direction = wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
 | 
			
		||||
		break;
 | 
			
		||||
	case 1:
 | 
			
		||||
		direction = wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		if (!sway_assert(false, "Unexpected axis value")) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (window->pointer_input.notify_scroll) {
 | 
			
		||||
		window->pointer_input.notify_scroll(window, direction);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct wl_pointer_listener pointer_listener = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue