diff options
author | Simon Ser <contact@emersion.fr> | 2022-05-27 18:28:55 +0200 |
---|---|---|
committer | Isaac Freund <mail@isaacfreund.com> | 2022-05-31 11:40:47 +0000 |
commit | 459a642e83349cc96b722450c391a13758eeb1a6 (patch) | |
tree | ece6e2c6aab804ef05a5018088c0d54a72ecc962 | |
parent | e3e2a34cd82c7a45ee174df6e64c2261883ccc20 (diff) |
output: introduce wlr_output_cursor_set_buffer
This will supersede wlr_output_cursor_set_image, and then later
also supersede wlr_output_cursor_set_surface.
-rw-r--r-- | include/wlr/types/wlr_output.h | 2 | ||||
-rw-r--r-- | types/output/cursor.c | 44 |
2 files changed, 46 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 68f85ebb..a6523d3d 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -498,6 +498,8 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, int32_t hotspot_x, int32_t hotspot_y); void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y); +bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor, + struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y); bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y); void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); diff --git a/types/output/cursor.c b/types/output/cursor.c index c70b8e3d..0d82c354 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -411,6 +411,50 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, return true; } +bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor, + struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y) { + struct wlr_renderer *renderer = cursor->output->renderer; + if (!renderer) { + return false; + } + + output_cursor_reset(cursor); + + if (buffer != NULL) { + cursor->width = buffer->width; + cursor->height = buffer->height; + } else { + cursor->width = 0; + cursor->height = 0; + } + + cursor->hotspot_x = hotspot_x; + cursor->hotspot_y = hotspot_y; + + output_cursor_update_visible(cursor); + + wlr_texture_destroy(cursor->texture); + cursor->texture = NULL; + + cursor->enabled = false; + if (buffer != NULL) { + cursor->texture = wlr_texture_from_buffer(renderer, buffer); + if (cursor->texture == NULL) { + return false; + } + cursor->enabled = true; + } + + if (output_cursor_attempt_hardware(cursor)) { + return true; + } + + wlr_log(WLR_DEBUG, "Falling back to software cursor on output '%s'", + cursor->output->name); + output_cursor_damage_whole(cursor); + return true; +} + static void output_cursor_commit(struct wlr_output_cursor *cursor, bool update_hotspot) { if (cursor->output->hardware_cursor != cursor) { |