Listen to cursor surface commit & destroy events
This commit is contained in:
parent
17354b630a
commit
8a77d1b6a2
|
@ -49,6 +49,11 @@ struct wlr_output {
|
|||
int32_t hotspot_x, hotspot_y;
|
||||
struct wlr_renderer *renderer;
|
||||
struct wlr_texture *texture;
|
||||
|
||||
// only when using a cursor surface
|
||||
struct wlr_surface *surface;
|
||||
struct wl_listener surface_commit;
|
||||
struct wl_listener surface_destroy;
|
||||
} cursor;
|
||||
|
||||
void *data;
|
||||
|
@ -64,7 +69,7 @@ void wlr_output_transform(struct wlr_output *output,
|
|||
bool wlr_output_set_cursor(struct wlr_output *output,
|
||||
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height,
|
||||
int32_t hotspot_x, int32_t hotspot_y);
|
||||
bool wlr_output_set_cursor_surface(struct wlr_output *output,
|
||||
void wlr_output_set_cursor_surface(struct wlr_output *output,
|
||||
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y);
|
||||
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y);
|
||||
void wlr_output_destroy(struct wlr_output *output);
|
||||
|
|
|
@ -288,11 +288,8 @@ static void handle_request_set_cursor(struct wl_listener *listener,
|
|||
|
||||
struct roots_output *output;
|
||||
wl_list_for_each(output, &input->server->desktop->outputs, link) {
|
||||
if (!wlr_output_set_cursor_surface(output->wlr_output,
|
||||
event->surface, event->hotspot_x, event->hotspot_y)) {
|
||||
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
||||
return;
|
||||
}
|
||||
wlr_output_set_cursor_surface(output->wlr_output, event->surface,
|
||||
event->hotspot_x, event->hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,18 +99,6 @@ void wlr_output_update_matrix(struct wlr_output *output) {
|
|||
wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform);
|
||||
}
|
||||
|
||||
void wlr_output_init(struct wlr_output *output,
|
||||
const struct wlr_output_impl *impl) {
|
||||
output->impl = impl;
|
||||
output->modes = list_create();
|
||||
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
output->scale = 1;
|
||||
wl_signal_init(&output->events.frame);
|
||||
wl_signal_init(&output->events.swap_buffers);
|
||||
wl_signal_init(&output->events.resolution);
|
||||
wl_signal_init(&output->events.destroy);
|
||||
}
|
||||
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable) {
|
||||
output->impl->enable(output, enable);
|
||||
}
|
||||
|
@ -167,29 +155,67 @@ bool wlr_output_set_cursor(struct wlr_output *output,
|
|||
}
|
||||
|
||||
return wlr_texture_upload_pixels(output->cursor.texture,
|
||||
WL_SHM_FORMAT_ARGB8888, stride, width, height, buf);
|
||||
WL_SHM_FORMAT_ARGB8888, stride, width, height, buf);
|
||||
}
|
||||
|
||||
bool wlr_output_set_cursor_surface(struct wlr_output *output,
|
||||
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
static void handle_cursor_surface_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output *output = wl_container_of(listener, output,
|
||||
cursor.surface_commit);
|
||||
struct wlr_surface *surface = data;
|
||||
|
||||
struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer);
|
||||
if (buffer == NULL) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t format = wl_shm_buffer_get_format(buffer);
|
||||
if (format != WL_SHM_FORMAT_ARGB8888) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
void *data = wl_shm_buffer_get_data(buffer);
|
||||
void *buffer_data = wl_shm_buffer_get_data(buffer);
|
||||
int32_t width = wl_shm_buffer_get_width(buffer);
|
||||
int32_t height = wl_shm_buffer_get_height(buffer);
|
||||
wl_shm_buffer_begin_access(buffer);
|
||||
bool ok = wlr_output_set_cursor(output, data, width, width, height,
|
||||
hotspot_x, hotspot_y);
|
||||
wlr_output_set_cursor(output, buffer_data, width, width, height,
|
||||
output->cursor.hotspot_x, output->cursor.hotspot_y);
|
||||
wl_shm_buffer_end_access(buffer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void handle_cursor_surface_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output *output = wl_container_of(listener, output,
|
||||
cursor.surface_destroy);
|
||||
struct wlr_surface *surface = data;
|
||||
|
||||
if (output->cursor.surface == surface) {
|
||||
wl_list_remove(&output->cursor.surface_commit.link);
|
||||
wl_list_remove(&output->cursor.surface_destroy.link);
|
||||
output->cursor.surface = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_output_set_cursor_surface(struct wlr_output *output,
|
||||
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
|
||||
if (output->cursor.surface == surface) {
|
||||
return;
|
||||
}
|
||||
output->cursor.surface = surface;
|
||||
|
||||
if (output->cursor.surface) {
|
||||
wl_list_remove(&output->cursor.surface_commit.link);
|
||||
wl_list_remove(&output->cursor.surface_destroy.link);
|
||||
output->cursor.surface = NULL;
|
||||
}
|
||||
|
||||
if (surface != NULL) {
|
||||
wl_signal_add(&surface->events.commit, &output->cursor.surface_commit);
|
||||
wl_signal_add(&surface->events.destroy, &output->cursor.surface_destroy);
|
||||
}
|
||||
}
|
||||
|
||||
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
|
||||
|
@ -207,6 +233,23 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
|
|||
return output->impl->move_cursor(output, x, y);
|
||||
}
|
||||
|
||||
void wlr_output_init(struct wlr_output *output,
|
||||
const struct wlr_output_impl *impl) {
|
||||
output->impl = impl;
|
||||
output->modes = list_create();
|
||||
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
output->scale = 1;
|
||||
wl_signal_init(&output->events.frame);
|
||||
wl_signal_init(&output->events.swap_buffers);
|
||||
wl_signal_init(&output->events.resolution);
|
||||
wl_signal_init(&output->events.destroy);
|
||||
|
||||
wl_list_init(&output->cursor.surface_commit.link);
|
||||
output->cursor.surface_commit.notify = handle_cursor_surface_commit;
|
||||
wl_list_init(&output->cursor.surface_destroy.link);
|
||||
output->cursor.surface_destroy.notify = handle_cursor_surface_destroy;
|
||||
}
|
||||
|
||||
void wlr_output_destroy(struct wlr_output *output) {
|
||||
if (!output) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue