output: fix trailing cursor at (0, 0) on startup

This commit is contained in:
emersion 2018-03-11 11:21:40 +01:00
parent a951fbb264
commit 8e3d294d6a
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 27 additions and 25 deletions

View File

@ -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, bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor,
const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height, const uint8_t *pixels, int32_t stride, uint32_t width, uint32_t height,
int32_t hotspot_x, int32_t hotspot_y) { 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->height = height;
cursor->hotspot_x = hotspot_x; cursor->hotspot_x = hotspot_x;
cursor->hotspot_y = hotspot_y; cursor->hotspot_y = hotspot_y;
output_cursor_update_visible(cursor);
struct wlr_output_cursor *hwcur = cursor->output->hardware_cursor; struct wlr_output_cursor *hwcur = cursor->output->hardware_cursor;
if (cursor->output->impl->set_cursor && (hwcur == NULL || hwcur == 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); 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) { static void output_cursor_commit(struct wlr_output_cursor *cursor) {
if (cursor->output->hardware_cursor != cursor) { if (cursor->output->hardware_cursor != cursor) {
output_cursor_damage_whole(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); wl_list_init(&cursor->surface_destroy.link);
cursor->surface_destroy.notify = output_cursor_handle_destroy; cursor->surface_destroy.notify = output_cursor_handle_destroy;
wl_list_insert(&output->cursors, &cursor->link); wl_list_insert(&output->cursors, &cursor->link);
cursor->visible = true; // default position is at (0, 0)
return cursor; return cursor;
} }