input/pointer: don't trigger pointer bindings for emulated input
Prior to this commit, a tablet device could trigger mouse button down bindings if the pen was pressed on a surface that didn't bind tablet handlers -- but it wouldn't if the surface did bind tablet handlers. We should expose consistent behavior to users so that they don't have to care about emulated vs. non-emulated input, so stop triggering bindings for any non-pointer devices.
This commit is contained in:
		
							parent
							
								
									20deb8ec16
								
							
						
					
					
						commit
						8fa74add82
					
				
					 1 changed files with 42 additions and 23 deletions
				
			
		|  | @ -275,10 +275,47 @@ static void handle_tablet_tool_tip(struct sway_seat *seat, | ||||||
|  * Functions used by handle_button  / |  * Functions used by handle_button  / | ||||||
|  *--------------------------------*/ |  *--------------------------------*/ | ||||||
| 
 | 
 | ||||||
|  | static bool trigger_pointer_button_binding(struct sway_seat *seat, | ||||||
|  | 		struct wlr_input_device *device, uint32_t button, | ||||||
|  | 		enum wlr_button_state state, uint32_t modifiers, | ||||||
|  | 		bool on_titlebar, bool on_border, bool on_contents, bool on_workspace) { | ||||||
|  | 	// We can reach this for non-pointer devices if we're currently emulating
 | ||||||
|  | 	// pointer input for one. Emulated input should not trigger bindings.
 | ||||||
|  | 	if (device->type != WLR_INPUT_DEVICE_POINTER) { | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	struct seatop_default_event *e = seat->seatop_data; | ||||||
|  | 
 | ||||||
|  | 	char *device_identifier = device ? input_device_get_identifier(device) | ||||||
|  | 		: strdup("*"); | ||||||
|  | 	struct sway_binding *binding = NULL; | ||||||
|  | 	if (state == WLR_BUTTON_PRESSED) { | ||||||
|  | 		state_add_button(e, button); | ||||||
|  | 		binding = get_active_mouse_binding(e, | ||||||
|  | 			config->current_mode->mouse_bindings, modifiers, false, | ||||||
|  | 			on_titlebar, on_border, on_contents, on_workspace, | ||||||
|  | 			device_identifier); | ||||||
|  | 	} else { | ||||||
|  | 		binding = get_active_mouse_binding(e, | ||||||
|  | 			config->current_mode->mouse_bindings, modifiers, true, | ||||||
|  | 			on_titlebar, on_border, on_contents, on_workspace, | ||||||
|  | 			device_identifier); | ||||||
|  | 		state_erase_button(e, button); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	free(device_identifier); | ||||||
|  | 	if (binding) { | ||||||
|  | 		seat_execute_command(seat, binding); | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void handle_button(struct sway_seat *seat, uint32_t time_msec, | static void handle_button(struct sway_seat *seat, uint32_t time_msec, | ||||||
| 		struct wlr_input_device *device, uint32_t button, | 		struct wlr_input_device *device, uint32_t button, | ||||||
| 		enum wlr_button_state state) { | 		enum wlr_button_state state) { | ||||||
| 	struct seatop_default_event *e = seat->seatop_data; |  | ||||||
| 	struct sway_cursor *cursor = seat->cursor; | 	struct sway_cursor *cursor = seat->cursor; | ||||||
| 
 | 
 | ||||||
| 	// Determine what's under the cursor
 | 	// Determine what's under the cursor
 | ||||||
|  | @ -300,29 +337,12 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, | ||||||
| 	bool on_workspace = node && node->type == N_WORKSPACE; | 	bool on_workspace = node && node->type == N_WORKSPACE; | ||||||
| 	bool on_titlebar = cont && !on_border && !surface; | 	bool on_titlebar = cont && !on_border && !surface; | ||||||
| 
 | 
 | ||||||
| 	// Handle mouse bindings
 |  | ||||||
| 	struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); | 	struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); | ||||||
| 	uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; | 	uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; | ||||||
| 
 | 
 | ||||||
| 	char *device_identifier = device ? input_device_get_identifier(device) | 	// Handle mouse bindings
 | ||||||
| 		: strdup("*"); | 	if (trigger_pointer_button_binding(seat, device, button, state, modifiers, | ||||||
| 	struct sway_binding *binding = NULL; | 			on_titlebar, on_border, on_contents, on_workspace)) { | ||||||
| 	if (state == WLR_BUTTON_PRESSED) { |  | ||||||
| 		state_add_button(e, button); |  | ||||||
| 		binding = get_active_mouse_binding(e, |  | ||||||
| 			config->current_mode->mouse_bindings, modifiers, false, |  | ||||||
| 			on_titlebar, on_border, on_contents, on_workspace, |  | ||||||
| 			device_identifier); |  | ||||||
| 	} else { |  | ||||||
| 		binding = get_active_mouse_binding(e, |  | ||||||
| 			config->current_mode->mouse_bindings, modifiers, true, |  | ||||||
| 			on_titlebar, on_border, on_contents, on_workspace, |  | ||||||
| 			device_identifier); |  | ||||||
| 		state_erase_button(e, button); |  | ||||||
| 	} |  | ||||||
| 	free(device_identifier); |  | ||||||
| 	if (binding) { |  | ||||||
| 		seat_execute_command(seat, binding); |  | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -364,8 +384,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Handle tiling resize via mod
 | 	// Handle tiling resize via mod
 | ||||||
| 	bool mod_pressed = keyboard && | 	bool mod_pressed = modifiers & config->floating_mod; | ||||||
| 		(wlr_keyboard_get_modifiers(keyboard) & config->floating_mod); |  | ||||||
| 	if (cont && !is_floating_or_child && mod_pressed && | 	if (cont && !is_floating_or_child && mod_pressed && | ||||||
| 			state == WLR_BUTTON_PRESSED) { | 			state == WLR_BUTTON_PRESSED) { | ||||||
| 		uint32_t btn_resize = config->floating_mod_inverse ? | 		uint32_t btn_resize = config->floating_mod_inverse ? | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue