diff options
Diffstat (limited to 'rootston/cursor.c')
-rw-r--r-- | rootston/cursor.c | 103 |
1 files changed, 96 insertions, 7 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 8bd514cc..d8753f44 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -30,19 +30,93 @@ void roots_cursor_destroy(struct roots_cursor *cursor) { // TODO } +static void seat_view_deco_motion(struct roots_seat_view *view, double deco_sx, double deco_sy) { + struct roots_cursor *cursor = view->seat->cursor; + + double sx = deco_sx; + double sy = deco_sy; + if (view->has_button_grab) { + sx = view->grab_sx; + sy = view->grab_sy; + } + + enum roots_deco_part parts = view_get_deco_part(view->view, sx, sy); + + bool is_titlebar = (parts & ROOTS_DECO_PART_TITLEBAR); + uint32_t edges = 0; + if (parts & ROOTS_DECO_PART_LEFT_BORDER) { + edges |= WLR_EDGE_LEFT; + } else if (parts & ROOTS_DECO_PART_RIGHT_BORDER) { + edges |= WLR_EDGE_RIGHT; + } else if (parts & ROOTS_DECO_PART_BOTTOM_BORDER) { + edges |= WLR_EDGE_BOTTOM; + } else if (parts & ROOTS_DECO_PART_TOP_BORDER) { + edges |= WLR_EDGE_TOP; + } + + if (view->has_button_grab) { + if (is_titlebar) { + roots_seat_begin_move(view->seat, view->view); + } else if (edges) { + roots_seat_begin_resize(view->seat, view->view, edges); + } + view->has_button_grab = false; + } else { + if (is_titlebar) { + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + } else if (edges) { + const char *resize_name = wlr_xcursor_get_resize_name(edges); + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + resize_name, cursor->cursor); + } + } +} + +static void seat_view_deco_leave(struct roots_seat_view *view) { + struct roots_cursor *cursor = view->seat->cursor; + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + view->has_button_grab = false; +} + +static void seat_view_deco_button(struct roots_seat_view *view, double sx, + double sy, uint32_t button, uint32_t state) { + if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED) { + view->has_button_grab = true; + view->grab_sx = sx; + view->grab_sy = sy; + } else { + view->has_button_grab = false; + } + + enum roots_deco_part parts = view_get_deco_part(view->view, sx, sy); + if (state == WLR_BUTTON_RELEASED && (parts & ROOTS_DECO_PART_TITLEBAR)) { + struct roots_cursor *cursor = view->seat->cursor; + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + } +} + static void roots_cursor_update_position(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; + 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); - bool set_compositor_cursor = !view && cursor->cursor_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)) { + 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; @@ -52,7 +126,13 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, cursor->default_xcursor, cursor->cursor); cursor->cursor_client = NULL; } - if (view) { + 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 { @@ -131,7 +211,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, struct roots_desktop *desktop = seat->input->server->desktop; bool is_touch = device->type == WLR_INPUT_DEVICE_TOUCH; - struct wlr_surface *surface; + struct wlr_surface *surface = NULL; double sx, sy; struct roots_view *view = desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); @@ -166,6 +246,13 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, } return; } + + if (view && !surface) { + if (cursor->pointer_view) { + seat_view_deco_button(cursor->pointer_view, sx, sy, button, state); + } + } + if (state == WLR_BUTTON_RELEASED && cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { cursor->mode = ROOTS_CURSOR_PASSTHROUGH; @@ -174,8 +261,10 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, } } - if (!is_touch) { - wlr_seat_pointer_notify_button(seat->seat, time, button, state); + if (view && surface) { + if (!is_touch) { + wlr_seat_pointer_notify_button(seat->seat, time, button, state); + } } switch (state) { |