mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-10-29 05:40:12 -04:00 
			
		
		
		
	pointer: release pressed buttons on destroy
This commit is contained in:
		
							parent
							
								
									c752270be7
								
							
						
					
					
						commit
						56d69320c7
					
				
					 8 changed files with 38 additions and 6 deletions
				
			
		|  | @ -69,7 +69,7 @@ void handle_pointer_button(struct libinput_event *event, | |||
| 		wlr_event.state = WL_POINTER_BUTTON_STATE_RELEASED; | ||||
| 		break; | ||||
| 	} | ||||
| 	wl_signal_emit_mutable(&pointer->events.button, &wlr_event); | ||||
| 	wlr_pointer_notify_button(pointer, &wlr_event); | ||||
| 	wl_signal_emit_mutable(&pointer->events.frame, pointer); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -112,7 +112,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, | |||
| 		.state = state, | ||||
| 		.time_msec = time, | ||||
| 	}; | ||||
| 	wl_signal_emit_mutable(&pointer->wlr_pointer.events.button, &event); | ||||
| 	wlr_pointer_notify_button(&pointer->wlr_pointer, &event); | ||||
| } | ||||
| 
 | ||||
| static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, | ||||
|  |  | |||
|  | @ -36,7 +36,7 @@ static void send_button_event(struct wlr_x11_output *output, uint32_t key, | |||
| 		.button = key, | ||||
| 		.state = st, | ||||
| 	}; | ||||
| 	wl_signal_emit_mutable(&output->pointer.events.button, &ev); | ||||
| 	wlr_pointer_notify_button(&output->pointer, &ev); | ||||
| 	wl_signal_emit_mutable(&output->pointer.events.frame, &output->pointer); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,4 +19,7 @@ void wlr_pointer_init(struct wlr_pointer *pointer, | |||
| 		const struct wlr_pointer_impl *impl, const char *name); | ||||
| void wlr_pointer_finish(struct wlr_pointer *pointer); | ||||
| 
 | ||||
| void wlr_pointer_notify_button(struct wlr_pointer *pointer, | ||||
| 		struct wlr_pointer_button_event *event); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -14,6 +14,8 @@ | |||
| #include <wayland-server-protocol.h> | ||||
| #include <wlr/types/wlr_input_device.h> | ||||
| 
 | ||||
| #define WLR_POINTER_BUTTONS_CAP 16 | ||||
| 
 | ||||
| struct wlr_pointer_impl; | ||||
| 
 | ||||
| struct wlr_pointer { | ||||
|  | @ -23,6 +25,9 @@ struct wlr_pointer { | |||
| 
 | ||||
| 	char *output_name; | ||||
| 
 | ||||
| 	uint32_t buttons[WLR_POINTER_BUTTONS_CAP]; | ||||
| 	size_t button_count; | ||||
| 
 | ||||
| 	struct { | ||||
| 		struct wl_signal motion; // struct wlr_pointer_motion_event
 | ||||
| 		struct wl_signal motion_absolute; // struct wlr_pointer_motion_absolute_event
 | ||||
|  |  | |||
|  | @ -170,8 +170,6 @@ struct wlr_seat_pointer_grab { | |||
| 	void *data; | ||||
| }; | ||||
| 
 | ||||
| #define WLR_POINTER_BUTTONS_CAP 16 | ||||
| 
 | ||||
| struct wlr_seat_pointer_button { | ||||
| 	uint32_t button; | ||||
| 	size_t n_pressed; | ||||
|  |  | |||
|  | @ -6,6 +6,8 @@ | |||
| #include <wlr/types/wlr_pointer.h> | ||||
| 
 | ||||
| #include "interfaces/wlr_input_device.h" | ||||
| #include "util/set.h" | ||||
| #include "util/time.h" | ||||
| 
 | ||||
| struct wlr_pointer *wlr_pointer_from_input_device( | ||||
| 		struct wlr_input_device *input_device) { | ||||
|  | @ -36,7 +38,31 @@ void wlr_pointer_init(struct wlr_pointer *pointer, | |||
| } | ||||
| 
 | ||||
| void wlr_pointer_finish(struct wlr_pointer *pointer) { | ||||
| 	int64_t time_msec = get_current_time_msec(); | ||||
| 	while (pointer->button_count > 0) { | ||||
| 		struct wlr_pointer_button_event event = { | ||||
| 			.pointer = pointer, | ||||
| 			.time_msec = time_msec, | ||||
| 			.button = pointer->buttons[pointer->button_count - 1], | ||||
| 			.state = WL_POINTER_BUTTON_STATE_RELEASED, | ||||
| 		}; | ||||
| 		wlr_pointer_notify_button(pointer, &event); | ||||
| 	} | ||||
| 
 | ||||
| 	wlr_input_device_finish(&pointer->base); | ||||
| 
 | ||||
| 	free(pointer->output_name); | ||||
| } | ||||
| 
 | ||||
| void wlr_pointer_notify_button(struct wlr_pointer *pointer, | ||||
| 		struct wlr_pointer_button_event *event) { | ||||
| 	if (event->state == WL_POINTER_BUTTON_STATE_PRESSED) { | ||||
| 		set_add(pointer->buttons, &pointer->button_count, | ||||
| 			WLR_POINTER_BUTTONS_CAP, event->button); | ||||
| 	} else { | ||||
| 		set_remove(pointer->buttons, &pointer->button_count, | ||||
| 			WLR_POINTER_BUTTONS_CAP, event->button); | ||||
| 	} | ||||
| 
 | ||||
| 	wl_signal_emit_mutable(&pointer->events.button, event); | ||||
| } | ||||
|  |  | |||
|  | @ -73,7 +73,7 @@ static void virtual_pointer_button(struct wl_client *client, | |||
| 		.button = button, | ||||
| 		.state = state ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED, | ||||
| 	}; | ||||
| 	wl_signal_emit_mutable(&pointer->pointer.events.button, &event); | ||||
| 	wlr_pointer_notify_button(&pointer->pointer, &event); | ||||
| } | ||||
| 
 | ||||
| static void virtual_pointer_axis(struct wl_client *client, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Kirill Primak
						Kirill Primak