From f5acde9a6936f6b0234359cb214b05efff4d434e Mon Sep 17 00:00:00 2001 From: Toby Rea Date: Mon, 31 Aug 2020 22:40:49 +0100 Subject: [PATCH] Move cursor functions to 'cursor.c'. Implement cursor show method properly --- include/input/cursor.h | 2 ++ kiwmi/desktop/output.c | 1 - kiwmi/input/cursor.c | 54 +++++++++++++++++++++++++++++++++++++++ kiwmi/luak/kiwmi_cursor.c | 6 ++--- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/include/input/cursor.h b/include/input/cursor.h index aaec7e0..4d5b88c 100644 --- a/include/input/cursor.h +++ b/include/input/cursor.h @@ -64,6 +64,8 @@ struct kiwmi_cursor_motion_event { struct kiwmi_cursor *cursor_create( struct kiwmi_server *server, struct wlr_output_layout *output_layout); +void cursor_hide(struct kiwmi_cursor *cursor); +void cursor_show(struct kiwmi_cursor *cursor); void cursor_destroy(struct kiwmi_cursor *cursor); #endif /* KIWMI_INPUT_CURSOR_H */ diff --git a/kiwmi/desktop/output.c b/kiwmi/desktop/output.c index c947020..034a518 100644 --- a/kiwmi/desktop/output.c +++ b/kiwmi/desktop/output.c @@ -115,7 +115,6 @@ output_frame_notify(struct wl_listener *listener, void *data) struct wlr_output_layout *output_layout = desktop->output_layout; struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); - struct kiwmi_cursor *cursor = server->input.cursor; struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); diff --git a/kiwmi/input/cursor.c b/kiwmi/input/cursor.c index c03499f..742b187 100644 --- a/kiwmi/input/cursor.c +++ b/kiwmi/input/cursor.c @@ -230,6 +230,60 @@ cursor_frame_notify(struct wl_listener *listener, void *UNUSED(data)) wlr_seat_pointer_notify_frame(input->seat->seat); } +void +cursor_hide(struct kiwmi_cursor *cursor) +{ + wlr_cursor_set_surface(cursor->cursor, NULL, 0, 0); + cursor->visible = false; + wlr_seat_pointer_notify_clear_focus(cursor->server->input.seat->seat); +} + +void +cursor_show(struct kiwmi_cursor *cursor) +{ + struct kiwmi_server *server = cursor->server; + struct kiwmi_desktop *desktop = &server->desktop; + struct wlr_seat *seat = server->input.seat->seat; + + double ox = 0; + double oy = 0; + struct wlr_output *wlr_output = wlr_output_layout_output_at( + desktop->output_layout, cursor->cursor->x, cursor->cursor->y); + + wlr_output_layout_output_coords( + desktop->output_layout, wlr_output, &ox, &oy); + + struct kiwmi_output *output = wlr_output->data; + + struct wlr_surface *surface = NULL; + double sx; + double sy; + + struct kiwmi_layer *layer = layer_at( + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + &surface, + cursor->cursor->x, + cursor->cursor->y, + &sx, + &sy); + + cursor->visible = true; + + if (!layer) { + struct kiwmi_view *view = view_at( + desktop, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + + if (!view) { + wlr_xcursor_manager_set_cursor_image( + cursor->xcursor_manager, "left_ptr", cursor->cursor); + } + } + + if (surface) { + wlr_seat_pointer_notify_enter(seat, surface, sx, sy); + } +} + struct kiwmi_cursor * cursor_create( struct kiwmi_server *server, diff --git a/kiwmi/luak/kiwmi_cursor.c b/kiwmi/luak/kiwmi_cursor.c index 7cfae6b..ce0101d 100644 --- a/kiwmi/luak/kiwmi_cursor.c +++ b/kiwmi/luak/kiwmi_cursor.c @@ -29,9 +29,7 @@ l_kiwmi_cursor_hide(lua_State *L) *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_cursor"); struct kiwmi_cursor *cursor = obj->object; - wlr_cursor_set_surface(cursor->cursor, NULL, 0, 0); - cursor->visible = false; - wlr_seat_pointer_notify_clear_focus(cursor->server->input.seat->seat); + cursor_hide(cursor); } static int @@ -55,7 +53,7 @@ l_kiwmi_cursor_show(lua_State *L) *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_cursor"); struct kiwmi_cursor *cursor = obj->object; - cursor->visible = true; + cursor_show(cursor); } static int