diff options
Diffstat (limited to 'sway/input')
| -rw-r--r-- | sway/input/cursor.c | 62 | ||||
| -rw-r--r-- | sway/input/input-manager.c | 22 | ||||
| -rw-r--r-- | sway/input/seat.c | 44 | 
3 files changed, 106 insertions, 22 deletions
| diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 85951c09..3ddc27a0 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -30,7 +30,7 @@  // when dragging to the edge of a layout container.  #define DROP_LAYOUT_BORDER 30 -static uint32_t get_current_time_msec() { +static uint32_t get_current_time_msec(void) {  	struct timespec now;  	clock_gettime(CLOCK_MONOTONIC, &now);  	return now.tv_nsec / 1000; @@ -897,7 +897,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,  	// Handle moving a tiling container  	if (config->tiling_drag && mod_pressed && state == WLR_BUTTON_PRESSED && -			!is_floating_or_child && !cont->is_fullscreen) { +			!is_floating_or_child && cont && !cont->is_fullscreen) {  		seat_pointer_notify_button(seat, time_msec, button, state);  		seat_begin_move_tiling(seat, cont, button);  		return; @@ -911,9 +911,10 @@ void dispatch_cursor_button(struct sway_cursor *cursor,  		return;  	} -	// Handle clicking a container surface +	// Handle clicking a container surface or decorations  	if (cont) { -		seat_set_focus_container(seat, cont); +		node = seat_get_focus_inactive(seat, &cont->node); +		seat_set_focus(seat, node);  		seat_pointer_notify_button(seat, time_msec, button, state);  		return;  	} @@ -930,12 +931,52 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {  	transaction_commit_dirty();  } +static void dispatch_cursor_axis(struct sway_cursor *cursor, +		struct wlr_event_pointer_axis *event) { +	struct sway_seat *seat = cursor->seat; + +	// Determine what's under the cursor +	struct wlr_surface *surface = NULL; +	double sx, sy; +	struct sway_node *node = node_at_coords(seat, +			cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); +	struct sway_container *cont = node && node->type == N_CONTAINER ? +		node->sway_container : NULL; +	enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE; +	bool on_border = edge != WLR_EDGE_NONE; +	bool on_titlebar = cont && !on_border && !surface; + +	// Scrolling on a tabbed or stacked title bar +	if (on_titlebar) { +		enum sway_container_layout layout = container_parent_layout(cont); +		if (layout == L_TABBED || layout == L_STACKED) { +			struct sway_node *active = +				seat_get_active_tiling_child(seat, node_get_parent(node)); +			list_t *siblings = container_get_siblings(cont); +			int desired = list_find(siblings, active->sway_container) + +				event->delta_discrete; +			if (desired < 0) { +				desired = 0; +			} else if (desired >= siblings->length) { +				desired = siblings->length - 1; +			} +			struct sway_container *new_focus = siblings->items[desired]; +			node = seat_get_focus_inactive(seat, &new_focus->node); +			seat_set_focus(seat, node); +			return; +		} +	} + +	wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, +		event->orientation, event->delta, event->delta_discrete, event->source); +} +  static void handle_cursor_axis(struct wl_listener *listener, void *data) {  	struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);  	wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);  	struct wlr_event_pointer_axis *event = data; -	wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, -		event->orientation, event->delta, event->delta_discrete, event->source); +	dispatch_cursor_axis(cursor, event); +	transaction_commit_dirty();  }  static void handle_touch_down(struct wl_listener *listener, void *data) { @@ -965,8 +1006,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {  	if (seat_is_input_allowed(seat, surface)) {  		wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,  				event->touch_id, sx, sy); -		cursor->image_client = NULL; -		wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); +		cursor_set_image(cursor, NULL, NULL);  	}  } @@ -1134,11 +1174,13 @@ static void handle_request_set_cursor(struct wl_listener *listener,  void cursor_set_image(struct sway_cursor *cursor, const char *image,  		struct wl_client *client) { -	if (!cursor->image || strcmp(cursor->image, image) != 0) { +	if (!image) { +		wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); +	} else if (!cursor->image || strcmp(cursor->image, image) != 0) {  		wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image,  				cursor->cursor); -		cursor->image = image;  	} +	cursor->image = image;  	cursor->image_client = client;  } diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index b4352c6a..32f0355e 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -120,6 +120,13 @@ static void input_manager_libinput_config_pointer(  		libinput_device_config_click_set_method(libinput_device,  			ic->click_method);  	} +	if (ic->drag != INT_MIN) { +		wlr_log(WLR_DEBUG, +			"libinput_config_pointer(%s) tap_set_drag_enabled(%d)", +			ic->identifier, ic->click_method); +		libinput_device_config_tap_set_drag_enabled(libinput_device, +			ic->drag); +	}  	if (ic->drag_lock != INT_MIN) {  		wlr_log(WLR_DEBUG,  			"libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)", @@ -233,7 +240,8 @@ static void handle_new_input(struct wl_listener *listener, void *data) {  	wlr_log(WLR_DEBUG, "adding device: '%s'",  		input_device->identifier); -	if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { +	if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || +			input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {  		input_manager_libinput_config_pointer(input_device);  	} @@ -389,9 +397,12 @@ void input_manager_set_focus(struct sway_input_manager *input,  void input_manager_apply_input_config(struct sway_input_manager *input,  		struct input_config *input_config) {  	struct sway_input_device *input_device = NULL; +	bool wildcard = strcmp(input_config->identifier, "*") == 0;  	wl_list_for_each(input_device, &input->devices, link) { -		if (strcmp(input_device->identifier, input_config->identifier) == 0) { -			if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) { +		if (strcmp(input_device->identifier, input_config->identifier) == 0 +				|| wildcard) { +			if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || +					input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {  				input_manager_libinput_config_pointer(input_device);  			} @@ -480,13 +491,16 @@ struct sway_seat *input_manager_get_default_seat(  }  struct input_config *input_device_get_config(struct sway_input_device *device) { +	struct input_config *wildcard_config = NULL;  	struct input_config *input_config = NULL;  	for (int i = 0; i < config->input_configs->length; ++i) {  		input_config = config->input_configs->items[i];  		if (strcmp(input_config->identifier, device->identifier) == 0) {  			return input_config; +		} else if (strcmp(input_config->identifier, "*") == 0) { +			wildcard_config = input_config;  		}  	} -	return NULL; +	return wildcard_config;  } diff --git a/sway/input/seat.c b/sway/input/seat.c index 49fe46ba..4817eae7 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -348,17 +348,42 @@ struct sway_seat *seat_create(struct sway_input_manager *input,  	seat->input = input;  	wl_list_init(&seat->devices); -	wlr_seat_set_capabilities(seat->wlr_seat, -		WL_SEAT_CAPABILITY_KEYBOARD | -		WL_SEAT_CAPABILITY_POINTER | -		WL_SEAT_CAPABILITY_TOUCH); - -  	wl_list_insert(&input->seats, &seat->link);  	return seat;  } +static void seat_update_capabilities(struct sway_seat *seat) { +	uint32_t caps = 0; +	struct sway_seat_device *seat_device; +	wl_list_for_each(seat_device, &seat->devices, link) { +		switch (seat_device->input_device->wlr_device->type) { +		case WLR_INPUT_DEVICE_KEYBOARD: +			caps |= WL_SEAT_CAPABILITY_KEYBOARD; +			break; +		case WLR_INPUT_DEVICE_POINTER: +			caps |= WL_SEAT_CAPABILITY_POINTER; +			break; +		case WLR_INPUT_DEVICE_TOUCH: +			caps |= WL_SEAT_CAPABILITY_TOUCH; +			break; +		case WLR_INPUT_DEVICE_TABLET_TOOL: +			caps |= WL_SEAT_CAPABILITY_POINTER; +			break; +		case WLR_INPUT_DEVICE_TABLET_PAD: +			break; +		} +	} +	wlr_seat_set_capabilities(seat->wlr_seat, caps); + +	// Hide cursor if seat doesn't have pointer capability +	if ((caps & WL_SEAT_CAPABILITY_POINTER) == 0) { +		cursor_set_image(seat->cursor, NULL, NULL); +	} else { +		cursor_set_image(seat->cursor, "left_ptr", NULL); +	} +} +  static void seat_apply_input_config(struct sway_seat *seat,  		struct sway_seat_device *sway_device) {  	const char *mapped_to_output = NULL; @@ -489,6 +514,8 @@ void seat_add_device(struct sway_seat *seat,  	wl_list_insert(&seat->devices, &seat_device->link);  	seat_configure_device(seat, input_device); + +	seat_update_capabilities(seat);  }  void seat_remove_device(struct sway_seat *seat, @@ -503,6 +530,8 @@ void seat_remove_device(struct sway_seat *seat,  		input_device->identifier, seat->wlr_seat->name);  	seat_device_destroy(seat_device); + +	seat_update_capabilities(seat);  }  void seat_configure_xcursor(struct sway_seat *seat) { @@ -532,8 +561,7 @@ void seat_configure_xcursor(struct sway_seat *seat) {  			output->name, (double)output->scale);  	} -	wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, -		"left_ptr", seat->cursor->cursor); +	cursor_set_image(seat->cursor, "left_ptr", NULL);  	wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,  		seat->cursor->cursor->y);  } | 
