From 8e3d294d6a84ca71b4dfac6b9041b01f228a6a15 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 11 Mar 2018 11:21:40 +0100 Subject: [PATCH] output: fix trailing cursor at (0, 0) on startup --- types/wlr_output.c | 52 ++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 15bb3577..7f19d1fe 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -669,6 +669,31 @@ static void output_cursor_reset(struct wlr_output_cursor *cursor) { } } +static void output_cursor_update_visible(struct wlr_output_cursor *cursor) { + struct wlr_box output_box; + output_box.x = output_box.y = 0; + wlr_output_transformed_resolution(cursor->output, &output_box.width, + &output_box.height); + + struct wlr_box cursor_box; + output_cursor_get_box(cursor, &cursor_box); + + struct wlr_box intersection; + bool visible = + wlr_box_intersection(&output_box, &cursor_box, &intersection); + + if (cursor->surface != NULL) { + if (cursor->visible && !visible) { + wlr_surface_send_leave(cursor->surface, cursor->output); + } + if (!cursor->visible && visible) { + wlr_surface_send_enter(cursor->surface, cursor->output); + } + } + + cursor->visible = visible; +} + bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { @@ -682,6 +707,7 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, cursor->height = height; cursor->hotspot_x = hotspot_x; cursor->hotspot_y = hotspot_y; + output_cursor_update_visible(cursor); struct wlr_output_cursor *hwcur = cursor->output->hardware_cursor; if (cursor->output->impl->set_cursor && (hwcur == NULL || hwcur == cursor)) { @@ -716,31 +742,6 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, stride, width, height, pixels); } -static void output_cursor_update_visible(struct wlr_output_cursor *cursor) { - struct wlr_box output_box; - output_box.x = output_box.y = 0; - wlr_output_transformed_resolution(cursor->output, &output_box.width, - &output_box.height); - - struct wlr_box cursor_box; - output_cursor_get_box(cursor, &cursor_box); - - struct wlr_box intersection; - bool visible = - wlr_box_intersection(&output_box, &cursor_box, &intersection); - - if (cursor->surface != NULL) { - if (cursor->visible && !visible) { - wlr_surface_send_leave(cursor->surface, cursor->output); - } - if (!cursor->visible && visible) { - wlr_surface_send_enter(cursor->surface, cursor->output); - } - } - - cursor->visible = visible; -} - static void output_cursor_commit(struct wlr_output_cursor *cursor) { if (cursor->output->hardware_cursor != cursor) { output_cursor_damage_whole(cursor); @@ -882,6 +883,7 @@ struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) { wl_list_init(&cursor->surface_destroy.link); cursor->surface_destroy.notify = output_cursor_handle_destroy; wl_list_insert(&output->cursors, &cursor->link); + cursor->visible = true; // default position is at (0, 0) return cursor; }