diff options
Diffstat (limited to 'rootston/cursor.c')
| -rw-r--r-- | rootston/cursor.c | 145 | 
1 files changed, 69 insertions, 76 deletions
| diff --git a/rootston/cursor.c b/rootston/cursor.c index ac597590..1ee195c2 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -10,6 +10,7 @@  #include <dev/evdev/input-event-codes.h>  #endif  #include "rootston/cursor.h" +#include "rootston/desktop.h"  #include "rootston/xcursor.h"  struct roots_cursor *roots_cursor_create(struct roots_seat *seat) { @@ -98,52 +99,59 @@ static void seat_view_deco_button(struct roots_seat_view *view, double sx,  	}  } -static void roots_cursor_update_position(struct roots_cursor *cursor, +static void roots_passthrough_cursor(struct roots_cursor *cursor,  		uint32_t time) { -	struct roots_desktop *desktop = cursor->seat->input->server->desktop; -	struct roots_seat *seat = cursor->seat; -	struct roots_view *view; -	struct wlr_surface *surface = NULL;  	double sx, sy; -	switch (cursor->mode) { -	case ROOTS_CURSOR_PASSTHROUGH: -		view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y, -			&surface, &sx, &sy); +	struct roots_view *view = NULL; +	struct roots_seat *seat = cursor->seat; +	struct roots_desktop *desktop = seat->input->server->desktop; +	struct wlr_surface *surface = desktop_surface_at(desktop, +			cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); +	struct wl_client *client = NULL; +	if (surface) { +		client = wl_resource_get_client(surface->resource); +	} + +	if (cursor->cursor_client != client) { +		wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, +			cursor->default_xcursor, cursor->cursor); +		cursor->cursor_client = client; +	} + +	if (view) {  		struct roots_seat_view *seat_view =  			roots_seat_view_from_view(seat, view); -		if (cursor->pointer_view && (surface || seat_view != cursor->pointer_view)) { +		if (cursor->pointer_view && (surface || +					seat_view != cursor->pointer_view)) {  			seat_view_deco_leave(cursor->pointer_view);  			cursor->pointer_view = NULL;  		} -		bool set_compositor_cursor = !view && !surface && cursor->cursor_client; -		if (view && surface) { -			struct wl_client *view_client = -				wl_resource_get_client(view->wlr_surface->resource); -			set_compositor_cursor = view_client != cursor->cursor_client; -		} -		if (set_compositor_cursor) { -			wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, -				cursor->default_xcursor, cursor->cursor); -			cursor->cursor_client = NULL; -		} -		if (view && !surface) { -			if (seat_view) { -				cursor->pointer_view = seat_view; -				seat_view_deco_motion(seat_view, sx, sy); -			} -		} -		if (view && surface) { -			// motion over a view surface -			wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy); -			wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy); -		} else { -			wlr_seat_pointer_clear_focus(seat->seat); +		if (!surface) { +			cursor->pointer_view = seat_view; +			seat_view_deco_motion(seat_view, sx, sy);  		} +	} -		struct roots_drag_icon *drag_icon; -		wl_list_for_each(drag_icon, &seat->drag_icons, link) { -			roots_drag_icon_update_position(drag_icon); -		} +	if (surface) { +		wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy); +		wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy); +	} else { +		wlr_seat_pointer_clear_focus(seat->seat); +	} + +	struct roots_drag_icon *drag_icon; +	wl_list_for_each(drag_icon, &seat->drag_icons, link) { +		roots_drag_icon_update_position(drag_icon); +	} +} + +static void roots_cursor_update_position( +		struct roots_cursor *cursor, uint32_t time) { +	struct roots_seat *seat = cursor->seat; +	struct roots_view *view; +	switch (cursor->mode) { +	case ROOTS_CURSOR_PASSTHROUGH: +		roots_passthrough_cursor(cursor, time);  		break;  	case ROOTS_CURSOR_MOVE:  		view = roots_seat_get_focus(seat); @@ -181,15 +189,9 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,  			} else if (cursor->resize_edges & WLR_EDGE_RIGHT) {  				width += dx;  			} - -			if (width < 1) { -				width = 1; -			} -			if (height < 1) { -				height = 1; -			} - -			view_move_resize(view, x, y, width, height); +			view_move_resize(view, x, y, +					width < 1 ? 1 : width, +					height < 1 ? 1 : height);  		}  		break;  	case ROOTS_CURSOR_ROTATE: @@ -215,15 +217,15 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,  		uint32_t state, double lx, double ly) {  	struct roots_seat *seat = cursor->seat;  	struct roots_desktop *desktop = seat->input->server->desktop; +  	bool is_touch = device->type == WLR_INPUT_DEVICE_TOUCH; -	struct wlr_surface *surface = NULL;  	double sx, sy; -	struct roots_view *view = -		desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); +	struct roots_view *view; +	struct wlr_surface *surface = desktop_surface_at(desktop, +			lx, ly, &sx, &sy, &view); -	if (state == WLR_BUTTON_PRESSED && -			view && +	if (state == WLR_BUTTON_PRESSED && view &&  			roots_seat_has_meta_pressed(seat)) {  		roots_seat_set_focus(seat, view); @@ -251,11 +253,9 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,  			break;  		}  	} else { - -		if (view && !surface) { -			if (cursor->pointer_view) { -				seat_view_deco_button(cursor->pointer_view, sx, sy, button, state); -			} +		if (view && !surface && cursor->pointer_view) { +			seat_view_deco_button(cursor->pointer_view, +					sx, sy, button, state);  		}  		if (state == WLR_BUTTON_RELEASED && @@ -289,8 +289,8 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor,  void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,  		struct wlr_event_pointer_motion_absolute *event) { -	wlr_cursor_warp_absolute(cursor->cursor, event->device, -		event->x_mm / event->width_mm, event->y_mm / event->height_mm); +	wlr_cursor_warp_absolute(cursor->cursor, +			event->device, event->x, event->y);  	roots_cursor_update_position(cursor, event->time_msec);  } @@ -309,17 +309,15 @@ void roots_cursor_handle_axis(struct roots_cursor *cursor,  void roots_cursor_handle_touch_down(struct roots_cursor *cursor,  		struct wlr_event_touch_down *event) {  	struct roots_desktop *desktop = cursor->seat->input->server->desktop; -	struct wlr_surface *surface = NULL;  	double lx, ly; -	bool result = -		wlr_cursor_absolute_to_layout_coords(cursor->cursor, -			event->device, event->x_mm, event->y_mm, event->width_mm, -			event->height_mm, &lx, &ly); +	bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, +			event->device, event->x, event->y, &lx, &ly);  	if (!result) {  		return;  	}  	double sx, sy; -	desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); +	struct wlr_surface *surface = desktop_surface_at( +			desktop, lx, ly, &sx, &sy, NULL);  	uint32_t serial = 0;  	if (surface) { @@ -362,18 +360,16 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,  		return;  	} -	struct wlr_surface *surface = NULL;  	double lx, ly; -	bool result = -		wlr_cursor_absolute_to_layout_coords(cursor->cursor, -			event->device, event->x_mm, event->y_mm, event->width_mm, -			event->height_mm, &lx, &ly); +	bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, +			event->device, event->x, event->y, &lx, &ly);  	if (!result) {  		return;  	}  	double sx, sy; -	desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); +	struct wlr_surface *surface = desktop_surface_at( +			desktop, lx, ly, &sx, &sy, NULL);  	if (surface) {  		wlr_seat_touch_point_focus(cursor->seat->seat, surface, @@ -396,15 +392,13 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,  	if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&  			(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {  		wlr_cursor_warp_absolute(cursor->cursor, event->device, -			event->x_mm / event->width_mm, event->y_mm / event->height_mm); +			event->x, event->y);  		roots_cursor_update_position(cursor, event->time_msec);  	} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { -		wlr_cursor_warp_absolute(cursor->cursor, event->device, -			event->x_mm / event->width_mm, -1); +		wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);  		roots_cursor_update_position(cursor, event->time_msec);  	} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { -		wlr_cursor_warp_absolute(cursor->cursor, event->device, -			-1, event->y_mm / event->height_mm); +		wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);  		roots_cursor_update_position(cursor, event->time_msec);  	}  } @@ -432,7 +426,6 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,  		return;  	} -	wlr_log(L_DEBUG, "Setting client cursor");  	wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x,  		event->hotspot_y);  	cursor->cursor_client = event->seat_client->client; | 
