diff options
Diffstat (limited to 'rootston/cursor.c')
-rw-r--r-- | rootston/cursor.c | 94 |
1 files changed, 66 insertions, 28 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 9193f9b7..2cf90539 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -31,6 +31,28 @@ const struct roots_input_event *get_input_event(struct roots_input *input, return NULL; } +static void cursor_set_xcursor_image(struct roots_input *input, + struct wlr_xcursor_image *image) { + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + if (!wlr_output_set_cursor(output->wlr_output, image->buffer, + image->width, image->width, image->height, + image->hotspot_x, image->hotspot_y)) { + wlr_log(L_DEBUG, "Failed to set hardware cursor"); + return; + } + } +} + +static void cursor_set_surface(struct roots_input *input, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + wlr_output_set_cursor_surface(output->wlr_output, surface, + hotspot_x, hotspot_y); + } +} + void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { input->mode = ROOTS_CURSOR_MOVE; @@ -39,6 +61,11 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, input->view_x = view->x; input->view_y = view->y; wlr_seat_pointer_clear_focus(input->wl_seat); + + struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); + } } void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, @@ -54,6 +81,11 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, input->view_height = size.height; input->resize_edges = edges; wlr_seat_pointer_clear_focus(input->wl_seat); + + struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); + } } void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, @@ -63,18 +95,10 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, input->offs_y = cursor->y; input->view_rotation = view->rotation; wlr_seat_pointer_clear_focus(input->wl_seat); -} -static void cursor_set_xcursor_image(struct roots_input *input, - struct wlr_xcursor_image *image) { - struct roots_output *output; - wl_list_for_each(output, &input->server->desktop->outputs, link) { - if (!wlr_output_set_cursor(output->wlr_output, image->buffer, - image->width, image->width, image->height, - image->hotspot_x, image->hotspot_y)) { - wlr_log(L_DEBUG, "Failed to set hardware cursor"); - return; - } + struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); } } @@ -94,8 +118,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { set_compositor_cursor = view_client != input->cursor_client; } if (set_compositor_cursor) { - wlr_log(L_DEBUG, "Switching to compositor cursor"); - cursor_set_xcursor_image(input, input->xcursor->images[0]); + struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); + cursor_set_xcursor_image(input, xcursor->images[0]); input->cursor_client = NULL; } if (view) { @@ -172,11 +196,11 @@ void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, if (!view) { return; } + if (view->type == ROOTS_XWAYLAND_VIEW && view->xwayland_surface->override_redirect) { return; } - input->last_active_view = view; size_t index = 0; for (size_t i = 0; i < desktop->views->length; ++i) { @@ -220,8 +244,16 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { event->orientation, event->delta); } -static bool is_meta_pressed(struct roots_input *input) { - uint32_t meta_key = input->server->config->keyboard.meta_key; +static bool is_meta_pressed(struct roots_input *input, + struct wlr_input_device *device) { + uint32_t meta_key = 0; + struct keyboard_config *config; + if ((config = config_get_keyboard(input->server->config, device))) { + meta_key = config->meta_key; + } else if (!meta_key && (config = config_get_keyboard(input->server->config, + NULL))) { + meta_key = config->meta_key; + } if (meta_key == 0) { return false; } @@ -246,20 +278,31 @@ static void do_cursor_button_press(struct roots_input *input, struct roots_view *view = view_at(desktop, input->cursor->x, input->cursor->y, &surface, &sx, &sy); - if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input)) { + if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input, device)) { set_view_focus(input, desktop, view); + uint32_t edges; switch (button) { case BTN_LEFT: view_begin_move(input, cursor, view); break; case BTN_RIGHT: - view_begin_resize(input, cursor, view, - ROOTS_CURSOR_RESIZE_EDGE_RIGHT | - ROOTS_CURSOR_RESIZE_EDGE_BOTTOM); + edges = 0; + if (sx < view->wlr_surface->current->width/2) { + edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT; + } else { + edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT; + } + if (sy < view->wlr_surface->current->height/2) { + edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP; + } else { + edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM; + } + view_begin_resize(input, cursor, view, edges); break; case BTN_MIDDLE: view_begin_rotate(input, cursor, view); + break; } return; } @@ -271,6 +314,7 @@ static void do_cursor_button_press(struct roots_input *input, switch (state) { case WLR_BUTTON_RELEASED: set_view_focus(input, desktop, NULL); + cursor_update_position(input, time); break; case WLR_BUTTON_PRESSED: i = input->input_events_idx; @@ -431,19 +475,13 @@ static void handle_request_set_cursor(struct wl_listener *listener, wl_resource_get_client(focused_surface->resource); ok = event->client == focused_client; } - if (!ok) { + if (!ok || input->mode != ROOTS_CURSOR_PASSTHROUGH) { wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client"); return; } wlr_log(L_DEBUG, "Setting client cursor"); - - struct roots_output *output; - wl_list_for_each(output, &input->server->desktop->outputs, link) { - wlr_output_set_cursor_surface(output->wlr_output, event->surface, - event->hotspot_x, event->hotspot_y); - } - + cursor_set_surface(input, event->surface, event->hotspot_x, event->hotspot_y); input->cursor_client = event->client; } |