diff options
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 122 | ||||
-rw-r--r-- | rootston/desktop.c | 82 |
2 files changed, 141 insertions, 63 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index c794cbce..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,51 +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); @@ -180,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: @@ -214,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); @@ -250,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 && @@ -308,7 +309,6 @@ 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, event->y, &lx, &ly); @@ -316,7 +316,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, 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) { @@ -359,17 +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, + 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, diff --git a/rootston/desktop.c b/rootston/desktop.c index 15e0e336..7ee2c69a 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -20,10 +20,12 @@ #include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell.h> #include <wlr/util/log.h> +#include "rootston/layers.h" #include "rootston/seat.h" #include "rootston/server.h" #include "rootston/view.h" #include "rootston/xcursor.h" +#include "wlr-layer-shell-unstable-v1-protocol.h" struct roots_view *view_create(struct roots_desktop *desktop) { struct roots_view *view = calloc(1, sizeof(struct roots_view)); @@ -632,8 +634,9 @@ static bool view_at(struct roots_view *view, double lx, double ly, return false; } -struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, - double ly, struct wlr_surface **surface, double *sx, double *sy) { +static struct roots_view *desktop_view_at(struct roots_desktop *desktop, + double lx, double ly, struct wlr_surface **surface, + double *sx, double *sy) { struct wlr_output *wlr_output = wlr_output_layout_output_at(desktop->layout, lx, ly); if (wlr_output != NULL) { @@ -657,6 +660,81 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, return NULL; } +static struct wlr_surface *layer_surface_at(struct roots_output *output, + struct wl_list *layer, double ox, double oy, double *sx, double *sy) { + struct roots_layer_surface *roots_surface; + wl_list_for_each_reverse(roots_surface, layer, link) { + struct wlr_surface *wlr_surface = + roots_surface->layer_surface->surface; + double _sx = ox - roots_surface->geo.x; + double _sy = oy - roots_surface->geo.y; + struct wlr_box box = { + .x = roots_surface->geo.x, + .y = roots_surface->geo.y, + .width = wlr_surface->current->width, + .height = wlr_surface->current->height, + }; + // TODO: Test popups/subsurfaces + if (wlr_box_contains_point(&box, ox, oy) && + pixman_region32_contains_point(&wlr_surface->current->input, + _sx, _sy, NULL)) { + *sx = _sx; + *sy = _sy; + return wlr_surface; + } + } + return NULL; +} + +struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, + double lx, double ly, double *sx, double *sy, + struct roots_view **view) { + struct wlr_surface *surface = NULL; + struct wlr_output *wlr_output = + wlr_output_layout_output_at(desktop->layout, lx, ly); + struct roots_output *roots_output; + double ox = lx, oy = ly; + *view = NULL; + + if (wlr_output) { + roots_output = wlr_output->data; + wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); + + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + ox, oy, sx, sy))) { + return surface; + } + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], + ox, oy, sx, sy))) { + return surface; + } + } + + struct roots_view *_view; + if ((_view = desktop_view_at(desktop, lx, ly, &surface, sx, sy))) { + if (view) { + *view = _view; + } + return surface; + } + + if (wlr_output) { + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], + ox, oy, sx, sy))) { + return surface; + } + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], + ox, oy, sx, sy))) { + return surface; + } + } + return NULL; +} + static void handle_layout_change(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, layout_change); |