Merge pull request #352 from emersion/output-cursor
Add wlr_output_cursor
This commit is contained in:
commit
c7c0d34e92
|
@ -560,33 +560,36 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
|
|||
|
||||
switch (output->transform) {
|
||||
case WL_OUTPUT_TRANSFORM_90:
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = -plane->surf.height + hotspot_y;
|
||||
plane->cursor_hotspot_x = hotspot_x;
|
||||
plane->cursor_hotspot_y = -plane->surf.height + hotspot_y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_180:
|
||||
output->cursor.hotspot_x = plane->surf.width - hotspot_x;
|
||||
output->cursor.hotspot_y = plane->surf.height - hotspot_y;
|
||||
plane->cursor_hotspot_x = plane->surf.width - hotspot_x;
|
||||
plane->cursor_hotspot_y = plane->surf.height - hotspot_y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_270:
|
||||
output->cursor.hotspot_x = -plane->surf.height + hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
plane->cursor_hotspot_x = -plane->surf.height + hotspot_x;
|
||||
plane->cursor_hotspot_y = hotspot_y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
||||
output->cursor.hotspot_x = plane->surf.width - hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
plane->cursor_hotspot_x = plane->surf.width - hotspot_x;
|
||||
plane->cursor_hotspot_y = hotspot_y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = -hotspot_y;
|
||||
plane->cursor_hotspot_x = hotspot_x;
|
||||
plane->cursor_hotspot_y = -hotspot_y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = plane->surf.height - hotspot_y;
|
||||
plane->cursor_hotspot_x = hotspot_x;
|
||||
plane->cursor_hotspot_y = plane->surf.height - hotspot_y;
|
||||
break;
|
||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
||||
output->cursor.hotspot_x = -plane->surf.height + hotspot_x;
|
||||
output->cursor.hotspot_y = plane->surf.width - hotspot_y;
|
||||
plane->cursor_hotspot_x = -plane->surf.height + hotspot_x;
|
||||
plane->cursor_hotspot_y = plane->surf.width - hotspot_y;
|
||||
break;
|
||||
default: // WL_OUTPUT_TRANSFORM_NORMAL
|
||||
plane->cursor_hotspot_x = hotspot_x;
|
||||
plane->cursor_hotspot_y = hotspot_y;
|
||||
}
|
||||
|
||||
if (!update_pixels) {
|
||||
|
@ -636,6 +639,10 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output,
|
|||
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output;
|
||||
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend;
|
||||
|
||||
struct wlr_drm_plane *plane = conn->crtc->cursor;
|
||||
x -= plane->cursor_hotspot_x;
|
||||
y -= plane->cursor_hotspot_y;
|
||||
|
||||
int width, height, tmp;
|
||||
wlr_output_effective_resolution(output, &width, &height);
|
||||
|
||||
|
|
|
@ -55,25 +55,27 @@ static void wlr_wl_output_transform(struct wlr_output *_output,
|
|||
static bool wlr_wl_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 update_pixels) {
|
||||
struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output;
|
||||
struct wlr_wl_backend_output *output =
|
||||
(struct wlr_wl_backend_output *)_output;
|
||||
struct wlr_wl_backend *backend = output->backend;
|
||||
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
|
||||
if (!update_pixels) {
|
||||
// Update hotspot without changing cursor image
|
||||
wlr_wl_output_update_cursor(output, output->enter_serial, hotspot_x,
|
||||
hotspot_y);
|
||||
wlr_wl_output_update_cursor(output);
|
||||
return true;
|
||||
}
|
||||
if (!buf) {
|
||||
// Hide cursor
|
||||
if (output->cursor_surface) {
|
||||
wl_surface_destroy(output->cursor_surface);
|
||||
munmap(output->cursor_data, output->cursor_buf_size);
|
||||
output->cursor_surface = NULL;
|
||||
output->cursor_buf_size = 0;
|
||||
if (output->cursor.surface) {
|
||||
wl_surface_destroy(output->cursor.surface);
|
||||
munmap(output->cursor.data, output->cursor.buf_size);
|
||||
output->cursor.surface = NULL;
|
||||
output->cursor.buf_size = 0;
|
||||
}
|
||||
wlr_wl_output_update_cursor(output, output->enter_serial, hotspot_x,
|
||||
hotspot_y);
|
||||
wlr_wl_output_update_cursor(output);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -84,73 +86,77 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!output->cursor_surface) {
|
||||
output->cursor_surface = wl_compositor_create_surface(output->backend->compositor);
|
||||
if (!output->cursor.surface) {
|
||||
output->cursor.surface =
|
||||
wl_compositor_create_surface(output->backend->compositor);
|
||||
}
|
||||
|
||||
uint32_t size = stride * height;
|
||||
if (output->cursor_buf_size != size) {
|
||||
if (output->cursor_buffer) {
|
||||
wl_buffer_destroy(output->cursor_buffer);
|
||||
if (output->cursor.buf_size != size) {
|
||||
if (output->cursor.buffer) {
|
||||
wl_buffer_destroy(output->cursor.buffer);
|
||||
}
|
||||
|
||||
if (size > output->cursor_buf_size) {
|
||||
if (output->cursor_pool) {
|
||||
wl_shm_pool_destroy(output->cursor_pool);
|
||||
output->cursor_pool = NULL;
|
||||
munmap(output->cursor_data, output->cursor_buf_size);
|
||||
if (size > output->cursor.buf_size) {
|
||||
if (output->cursor.pool) {
|
||||
wl_shm_pool_destroy(output->cursor.pool);
|
||||
output->cursor.pool = NULL;
|
||||
munmap(output->cursor.data, output->cursor.buf_size);
|
||||
}
|
||||
}
|
||||
|
||||
if (!output->cursor_pool) {
|
||||
if (!output->cursor.pool) {
|
||||
int fd = os_create_anonymous_file(size);
|
||||
if (fd < 0) {
|
||||
wlr_log_errno(L_INFO, "creating anonymous file for cursor buffer failed");
|
||||
wlr_log_errno(L_INFO,
|
||||
"creating anonymous file for cursor buffer failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
output->cursor_data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (output->cursor_data == MAP_FAILED) {
|
||||
output->cursor.data = mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, fd, 0);
|
||||
if (output->cursor.data == MAP_FAILED) {
|
||||
close(fd);
|
||||
wlr_log_errno(L_INFO, "mmap failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
output->cursor_pool = wl_shm_create_pool(backend->shm, fd, size);
|
||||
output->cursor.pool = wl_shm_create_pool(backend->shm, fd, size);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
output->cursor_buffer = wl_shm_pool_create_buffer(output->cursor_pool,
|
||||
output->cursor.buffer = wl_shm_pool_create_buffer(output->cursor.pool,
|
||||
0, width, height, stride, WL_SHM_FORMAT_ARGB8888);
|
||||
output->cursor_buf_size = size;
|
||||
output->cursor.buf_size = size;
|
||||
}
|
||||
|
||||
memcpy(output->cursor_data, buf, size);
|
||||
wl_surface_attach(output->cursor_surface, output->cursor_buffer, 0, 0);
|
||||
wl_surface_damage(output->cursor_surface, 0, 0, width, height);
|
||||
wl_surface_commit(output->cursor_surface);
|
||||
memcpy(output->cursor.data, buf, size);
|
||||
wl_surface_attach(output->cursor.surface, output->cursor.buffer, 0, 0);
|
||||
wl_surface_damage(output->cursor.surface, 0, 0, width, height);
|
||||
wl_surface_commit(output->cursor.surface);
|
||||
|
||||
wlr_wl_output_update_cursor(output, output->enter_serial,
|
||||
hotspot_x, hotspot_y);
|
||||
wlr_wl_output_update_cursor(output);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wlr_wl_output_destroy(struct wlr_output *_output) {
|
||||
struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output;
|
||||
wl_signal_emit(&output->backend->backend.events.output_remove, &output->wlr_output);
|
||||
struct wlr_wl_backend_output *output =
|
||||
(struct wlr_wl_backend_output *)_output;
|
||||
wl_signal_emit(&output->backend->backend.events.output_remove,
|
||||
&output->wlr_output);
|
||||
|
||||
if (output->cursor_buf_size != 0) {
|
||||
assert(output->cursor_data);
|
||||
assert(output->cursor_buffer);
|
||||
assert(output->cursor_pool);
|
||||
if (output->cursor.buf_size != 0) {
|
||||
assert(output->cursor.data);
|
||||
assert(output->cursor.buffer);
|
||||
assert(output->cursor.pool);
|
||||
|
||||
wl_buffer_destroy(output->cursor_buffer);
|
||||
munmap(output->cursor_data, output->cursor_buf_size);
|
||||
wl_shm_pool_destroy(output->cursor_pool);
|
||||
wl_buffer_destroy(output->cursor.buffer);
|
||||
munmap(output->cursor.data, output->cursor.buf_size);
|
||||
wl_shm_pool_destroy(output->cursor.pool);
|
||||
}
|
||||
|
||||
if (output->cursor_surface) {
|
||||
wl_surface_destroy(output->cursor_surface);
|
||||
if (output->cursor.surface) {
|
||||
wl_surface_destroy(output->cursor.surface);
|
||||
}
|
||||
|
||||
if (output->frame_callback) {
|
||||
|
@ -164,11 +170,11 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) {
|
|||
free(output);
|
||||
}
|
||||
|
||||
void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output,
|
||||
uint32_t serial, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
if (output->backend->pointer && serial) {
|
||||
wl_pointer_set_cursor(output->backend->pointer, serial,
|
||||
output->cursor_surface, hotspot_x, hotspot_y);
|
||||
void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output) {
|
||||
if (output->backend->pointer && output->enter_serial) {
|
||||
wl_pointer_set_cursor(output->backend->pointer, output->enter_serial,
|
||||
output->cursor.surface, output->cursor.hotspot_x,
|
||||
output->cursor.hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,7 +189,7 @@ static struct wlr_output_impl output_impl = {
|
|||
.make_current = wlr_wl_output_make_current,
|
||||
.swap_buffers = wlr_wl_output_swap_buffers,
|
||||
.set_cursor = wlr_wl_output_set_cursor,
|
||||
.move_cursor = wlr_wl_output_move_cursor
|
||||
.move_cursor = wlr_wl_output_move_cursor,
|
||||
};
|
||||
|
||||
static void xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *xdg_surface,
|
||||
|
|
|
@ -23,8 +23,8 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
|
|||
wlr_wl_output_for_surface(wlr_wl_dev->backend, surface);
|
||||
assert(output);
|
||||
wlr_wl_pointer->current_output = output;
|
||||
wlr_wl_pointer->current_output->enter_serial = serial;
|
||||
wlr_wl_output_update_cursor(wlr_wl_pointer->current_output, serial, 0, 0);
|
||||
output->enter_serial = serial;
|
||||
wlr_wl_output_update_cursor(output);
|
||||
}
|
||||
|
||||
static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
|
||||
|
|
|
@ -298,6 +298,9 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) {
|
|||
|
||||
struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend;
|
||||
|
||||
struct wlr_x11_output *output = &x11->output;
|
||||
wlr_output_destroy(&output->wlr_output);
|
||||
|
||||
wl_event_source_remove(x11->frame_timer);
|
||||
wlr_egl_free(&x11->egl);
|
||||
|
||||
|
@ -331,7 +334,7 @@ static void output_destroy(struct wlr_output *wlr_output) {
|
|||
|
||||
eglDestroySurface(x11->egl.display, output->surf);
|
||||
xcb_destroy_window(x11->xcb_conn, output->win);
|
||||
free(wlr_output);
|
||||
// output has been allocated on the stack, do not free it
|
||||
}
|
||||
|
||||
static void output_make_current(struct wlr_output *wlr_output) {
|
||||
|
|
|
@ -8,6 +8,8 @@ executable('simple', 'simple.c', dependencies: wlroots, link_with: lib_shared)
|
|||
executable('pointer', 'pointer.c', dependencies: wlroots, link_with: lib_shared)
|
||||
executable('touch', 'touch.c', dependencies: wlroots, link_with: lib_shared)
|
||||
executable('tablet', 'tablet.c', dependencies: wlroots, link_with: lib_shared)
|
||||
executable('multi-pointer', 'multi-pointer.c', dependencies: wlroots,
|
||||
link_with: lib_shared)
|
||||
|
||||
executable(
|
||||
'rotation',
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
#define _POSIX_C_SOURCE 199309L
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <GLES2/gl2.h>
|
||||
#include <wlr/render/matrix.h>
|
||||
#include <wlr/render/gles2.h>
|
||||
#include <wlr/render.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/backend/session.h>
|
||||
#include <wlr/types/wlr_keyboard.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/xcursor.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/types/wlr_list.h>
|
||||
#include "shared.h"
|
||||
#include "config.h"
|
||||
#include "cat.h"
|
||||
|
||||
struct sample_state;
|
||||
|
||||
struct sample_cursor {
|
||||
struct sample_state *state;
|
||||
struct wlr_input_device *device;
|
||||
struct wlr_cursor *cursor;
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_listener cursor_motion;
|
||||
struct wl_listener cursor_motion_absolute;
|
||||
struct wl_listener cursor_button;
|
||||
struct wl_listener cursor_axis;
|
||||
};
|
||||
|
||||
struct sample_state {
|
||||
struct compositor_state *compositor;
|
||||
struct example_config *config;
|
||||
struct wlr_xcursor *xcursor;
|
||||
float default_color[4];
|
||||
float clear_color[4];
|
||||
struct wlr_output_layout *layout;
|
||||
struct wl_list cursors; // sample_cursor::link
|
||||
};
|
||||
|
||||
static void handle_output_frame(struct output_state *output,
|
||||
struct timespec *ts) {
|
||||
struct compositor_state *state = output->compositor;
|
||||
struct sample_state *sample = state->data;
|
||||
struct wlr_output *wlr_output = output->output;
|
||||
|
||||
wlr_output_make_current(wlr_output);
|
||||
|
||||
glClearColor(sample->clear_color[0], sample->clear_color[1],
|
||||
sample->clear_color[2], sample->clear_color[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
wlr_output_swap_buffers(wlr_output);
|
||||
}
|
||||
|
||||
static void handle_output_add(struct output_state *ostate) {
|
||||
struct sample_state *sample = ostate->compositor->data;
|
||||
|
||||
struct output_config *o_config =
|
||||
example_config_get_output(sample->config, ostate->output);
|
||||
|
||||
if (o_config) {
|
||||
wlr_output_transform(ostate->output, o_config->transform);
|
||||
wlr_output_layout_add(sample->layout, ostate->output, o_config->x,
|
||||
o_config->y);
|
||||
} else {
|
||||
wlr_output_layout_add_auto(sample->layout, ostate->output);
|
||||
}
|
||||
|
||||
struct sample_cursor *cursor;
|
||||
wl_list_for_each(cursor, &sample->cursors, link) {
|
||||
example_config_configure_cursor(sample->config, cursor->cursor,
|
||||
sample->compositor);
|
||||
|
||||
struct wlr_xcursor_image *image = sample->xcursor->images[0];
|
||||
wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
|
||||
wlr_cursor_warp(cursor->cursor, NULL, cursor->cursor->x,
|
||||
cursor->cursor->y);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_output_remove(struct output_state *ostate) {
|
||||
struct sample_state *sample = ostate->compositor->data;
|
||||
|
||||
wlr_output_layout_remove(sample->layout, ostate->output);
|
||||
|
||||
struct sample_cursor *cursor;
|
||||
wl_list_for_each(cursor, &sample->cursors, link) {
|
||||
example_config_configure_cursor(sample->config, cursor->cursor,
|
||||
sample->compositor);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
struct sample_cursor *cursor =
|
||||
wl_container_of(listener, cursor, cursor_motion);
|
||||
struct wlr_event_pointer_motion *event = data;
|
||||
wlr_cursor_move(cursor->cursor, event->device, event->delta_x,
|
||||
event->delta_y);
|
||||
}
|
||||
|
||||
static void handle_cursor_motion_absolute(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct sample_cursor *cursor =
|
||||
wl_container_of(listener, cursor, cursor_motion_absolute);
|
||||
struct wlr_event_pointer_motion_absolute *event = data;
|
||||
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
||||
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
|
||||
}
|
||||
|
||||
static void handle_input_add(struct compositor_state *state,
|
||||
struct wlr_input_device *device) {
|
||||
struct sample_state *sample = state->data;
|
||||
|
||||
if (device->type != WLR_INPUT_DEVICE_POINTER) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct sample_cursor *cursor = calloc(1, sizeof(struct sample_cursor));
|
||||
cursor->state = sample;
|
||||
cursor->device = device;
|
||||
|
||||
cursor->cursor = wlr_cursor_create();
|
||||
wlr_cursor_attach_output_layout(cursor->cursor, sample->layout);
|
||||
wlr_cursor_map_to_region(cursor->cursor, sample->config->cursor.mapped_box);
|
||||
|
||||
wl_signal_add(&cursor->cursor->events.motion, &cursor->cursor_motion);
|
||||
cursor->cursor_motion.notify = handle_cursor_motion;
|
||||
wl_signal_add(&cursor->cursor->events.motion_absolute,
|
||||
&cursor->cursor_motion_absolute);
|
||||
cursor->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
|
||||
|
||||
wlr_cursor_attach_input_device(cursor->cursor, device);
|
||||
example_config_configure_cursor(sample->config, cursor->cursor,
|
||||
sample->compositor);
|
||||
|
||||
struct wlr_xcursor_image *image = sample->xcursor->images[0];
|
||||
wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
|
||||
wl_list_insert(&sample->cursors, &cursor->link);
|
||||
}
|
||||
|
||||
static void cursor_destroy(struct sample_cursor *cursor) {
|
||||
wl_list_remove(&cursor->link);
|
||||
wl_list_remove(&cursor->cursor_motion.link);
|
||||
wl_list_remove(&cursor->cursor_motion_absolute.link);
|
||||
wlr_cursor_destroy(cursor->cursor);
|
||||
free(cursor);
|
||||
}
|
||||
|
||||
static void handle_input_remove(struct compositor_state *state,
|
||||
struct wlr_input_device *device) {
|
||||
struct sample_state *sample = state->data;
|
||||
struct sample_cursor *cursor;
|
||||
wl_list_for_each(cursor, &sample->cursors, link) {
|
||||
if (cursor->device == device) {
|
||||
cursor_destroy(cursor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct sample_state state = {
|
||||
.default_color = { 0.25f, 0.25f, 0.25f, 1 },
|
||||
.clear_color = { 0.25f, 0.25f, 0.25f, 1 },
|
||||
};
|
||||
|
||||
wl_list_init(&state.cursors);
|
||||
|
||||
state.config = parse_args(argc, argv);
|
||||
state.layout = wlr_output_layout_create();
|
||||
|
||||
struct compositor_state compositor = { 0 };
|
||||
compositor.data = &state;
|
||||
compositor.output_add_cb = handle_output_add;
|
||||
compositor.output_remove_cb = handle_output_remove;
|
||||
compositor.output_frame_cb = handle_output_frame;
|
||||
compositor.input_add_cb = handle_input_add;
|
||||
compositor.input_remove_cb = handle_input_remove;
|
||||
|
||||
state.compositor = &compositor;
|
||||
|
||||
struct wlr_xcursor_theme *theme = wlr_xcursor_theme_load("default", 16);
|
||||
if (!theme) {
|
||||
wlr_log(L_ERROR, "Failed to load cursor theme");
|
||||
return 1;
|
||||
}
|
||||
state.xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr");
|
||||
if (!state.xcursor) {
|
||||
wlr_log(L_ERROR, "Failed to load left_ptr cursor");
|
||||
return 1;
|
||||
}
|
||||
|
||||
compositor_init(&compositor);
|
||||
if (!wlr_backend_start(compositor.backend)) {
|
||||
wlr_log(L_ERROR, "Failed to start backend");
|
||||
wlr_backend_destroy(compositor.backend);
|
||||
exit(1);
|
||||
}
|
||||
wl_display_run(compositor.display);
|
||||
compositor_fini(&compositor);
|
||||
|
||||
struct sample_cursor *cursor, *tmp_cursor;
|
||||
wl_list_for_each_safe(cursor, tmp_cursor, &state.cursors, link) {
|
||||
cursor_destroy(cursor);
|
||||
}
|
||||
|
||||
wlr_xcursor_theme_destroy(theme);
|
||||
example_config_destroy(state.config);
|
||||
wlr_output_layout_destroy(state.layout);
|
||||
}
|
|
@ -93,8 +93,6 @@ static void handle_output_frame(struct output_state *output,
|
|||
|
||||
static void handle_output_add(struct output_state *ostate) {
|
||||
struct sample_state *sample = ostate->compositor->data;
|
||||
struct wlr_output *wlr_output = ostate->output;
|
||||
struct wlr_xcursor_image *image = sample->xcursor->images[0];
|
||||
|
||||
struct output_config *o_config =
|
||||
example_config_get_output(sample->config, ostate->output);
|
||||
|
@ -110,14 +108,9 @@ static void handle_output_add(struct output_state *ostate) {
|
|||
example_config_configure_cursor(sample->config, sample->cursor,
|
||||
sample->compositor);
|
||||
|
||||
// TODO the cursor must be set depending on which surface it is displayed
|
||||
// over which should happen in the compositor.
|
||||
if (!wlr_output_set_cursor(wlr_output, image->buffer,
|
||||
image->width, image->width, image->height,
|
||||
image->hotspot_x, image->hotspot_y)) {
|
||||
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
||||
return;
|
||||
}
|
||||
struct wlr_xcursor_image *image = sample->xcursor->images[0];
|
||||
wlr_cursor_set_image(sample->cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
|
||||
wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y);
|
||||
}
|
||||
|
@ -161,14 +154,8 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
|
|||
sample->cur_x = event->x_mm;
|
||||
sample->cur_y = event->y_mm;
|
||||
|
||||
struct wlr_xcursor_image *image = sample->xcursor->images[0];
|
||||
|
||||
struct output_state *output;
|
||||
wl_list_for_each(output, &sample->compositor->outputs, link) {
|
||||
wlr_output_move_cursor(output->output,
|
||||
sample->cur_x - image->hotspot_x,
|
||||
sample->cur_y - image->hotspot_y);
|
||||
}
|
||||
wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x,
|
||||
sample->cur_y);
|
||||
}
|
||||
|
||||
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||
|
@ -332,7 +319,9 @@ int main(int argc, char *argv[]) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
wlr_cursor_set_xcursor(state.cursor, state.xcursor);
|
||||
struct wlr_xcursor_image *image = state.xcursor->images[0];
|
||||
wlr_cursor_set_image(state.cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
|
||||
compositor_init(&compositor);
|
||||
if (!wlr_backend_start(compositor.backend)) {
|
||||
|
|
|
@ -34,6 +34,7 @@ struct wlr_drm_plane {
|
|||
struct wlr_texture *wlr_tex;
|
||||
struct gbm_bo *cursor_bo;
|
||||
bool cursor_enabled;
|
||||
int32_t cursor_hotspot_x, cursor_hotspot_y;
|
||||
|
||||
union wlr_drm_plane_props props;
|
||||
};
|
||||
|
|
|
@ -43,11 +43,15 @@ struct wlr_wl_backend_output {
|
|||
struct wl_egl_window *egl_window;
|
||||
struct wl_callback *frame_callback;
|
||||
|
||||
struct wl_shm_pool *cursor_pool;
|
||||
void *cursor_buffer; // actually a (client-side) struct wl_buffer*
|
||||
uint8_t *cursor_data;
|
||||
struct wl_surface *cursor_surface;
|
||||
uint32_t cursor_buf_size;
|
||||
struct {
|
||||
struct wl_shm_pool *pool;
|
||||
void *buffer; // actually a (client-side) struct wl_buffer*
|
||||
uint32_t buf_size;
|
||||
uint8_t *data;
|
||||
struct wl_surface *surface;
|
||||
int32_t hotspot_x, hotspot_y;
|
||||
} cursor;
|
||||
|
||||
uint32_t enter_serial;
|
||||
|
||||
void *egl_surface;
|
||||
|
@ -68,8 +72,7 @@ struct wlr_wl_pointer {
|
|||
};
|
||||
|
||||
void wlr_wl_registry_poll(struct wlr_wl_backend *backend);
|
||||
void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output,
|
||||
uint32_t serial, int32_t hotspot_x, int32_t hotspot_y);
|
||||
void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output);
|
||||
struct wlr_wl_backend_output *wlr_wl_output_for_surface(
|
||||
struct wlr_wl_backend *backend, struct wl_surface *surface);
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ struct wlr_cursor *wlr_cursor_create();
|
|||
|
||||
void wlr_cursor_destroy(struct wlr_cursor *cur);
|
||||
|
||||
void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur);
|
||||
|
||||
/**
|
||||
* Warp the cursor to the given x and y in layout coordinates. If x and y are
|
||||
* out of the layout boundaries or constraints, no warp will happen.
|
||||
|
@ -62,6 +60,12 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
|
|||
void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
||||
double delta_x, double delta_y);
|
||||
|
||||
void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels,
|
||||
int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x,
|
||||
int32_t hotspot_y);
|
||||
void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface,
|
||||
int32_t hotspot_x, int32_t hotspot_y);
|
||||
|
||||
/**
|
||||
* Attaches this input device to this cursor. The input device must be one of:
|
||||
*
|
||||
|
|
|
@ -12,6 +12,22 @@ struct wlr_output_mode {
|
|||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct wlr_output_cursor {
|
||||
struct wlr_output *output;
|
||||
int32_t x, y;
|
||||
uint32_t width, height;
|
||||
int32_t hotspot_x, hotspot_y;
|
||||
struct wl_list link;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
struct wlr_output_impl;
|
||||
|
||||
struct wlr_output {
|
||||
|
@ -44,19 +60,8 @@ struct wlr_output {
|
|||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
struct {
|
||||
bool is_sw;
|
||||
int32_t x, y;
|
||||
uint32_t width, height;
|
||||
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;
|
||||
struct wl_list cursors; // wlr_output_cursor::link
|
||||
struct wlr_output_cursor *hardware_cursor;
|
||||
|
||||
// the output position in layout space reported to clients
|
||||
int32_t lx, ly;
|
||||
|
@ -72,12 +77,6 @@ bool wlr_output_set_mode(struct wlr_output *output,
|
|||
void wlr_output_transform(struct wlr_output *output,
|
||||
enum wl_output_transform transform);
|
||||
void wlr_output_set_position(struct wlr_output *output, int32_t lx, int32_t ly);
|
||||
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);
|
||||
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);
|
||||
void wlr_output_effective_resolution(struct wlr_output *output,
|
||||
int *width, int *height);
|
||||
|
@ -87,4 +86,13 @@ void wlr_output_set_gamma(struct wlr_output *output,
|
|||
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b);
|
||||
uint32_t wlr_output_get_gamma_size(struct wlr_output *output);
|
||||
|
||||
struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output);
|
||||
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);
|
||||
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_move(struct wlr_output_cursor *cursor, int x, int y);
|
||||
void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,6 +12,7 @@ struct wlr_output_layout {
|
|||
struct wlr_output_layout_state *state;
|
||||
|
||||
struct {
|
||||
struct wl_signal add;
|
||||
struct wl_signal change;
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
@ -24,6 +25,10 @@ struct wlr_output_layout_output {
|
|||
int x, y;
|
||||
struct wl_list link;
|
||||
struct wlr_output_layout_output_state *state;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
};
|
||||
|
||||
struct wlr_output_layout *wlr_output_layout_create();
|
||||
|
|
|
@ -33,24 +33,8 @@ const struct roots_input_event *get_input_event(struct roots_input *input,
|
|||
|
||||
static void cursor_set_xcursor_image(struct roots_input *input,
|
||||
struct wlr_xcursor_image *image) {
|
||||
struct roots_output *output;
|
||||
wl_list_for_each(output, &input->server->desktop->outputs, link) {
|
||||
if (!wlr_output_set_cursor(output->wlr_output, image->buffer,
|
||||
image->width, image->width, image->height,
|
||||
image->hotspot_x, image->hotspot_y)) {
|
||||
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cursor_set_surface(struct roots_input *input,
|
||||
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
struct roots_output *output;
|
||||
wl_list_for_each(output, &input->server->desktop->outputs, link) {
|
||||
wlr_output_set_cursor_surface(output->wlr_output, surface,
|
||||
hotspot_x, hotspot_y);
|
||||
}
|
||||
wlr_cursor_set_image(input->cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
}
|
||||
|
||||
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
|
||||
|
@ -487,7 +471,8 @@ static void handle_request_set_cursor(struct wl_listener *listener,
|
|||
}
|
||||
|
||||
wlr_log(L_DEBUG, "Setting client cursor");
|
||||
cursor_set_surface(input, event->surface, event->hotspot_x, event->hotspot_y);
|
||||
wlr_cursor_set_surface(input->cursor, event->surface, event->hotspot_x,
|
||||
event->hotspot_y);
|
||||
input->cursor_client = event->seat_client->client;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,7 +118,10 @@ struct roots_input *input_create(struct roots_server *server,
|
|||
|
||||
input->cursor = wlr_cursor_create();
|
||||
cursor_initialize(input);
|
||||
wlr_cursor_set_xcursor(input->cursor, xcursor);
|
||||
|
||||
struct wlr_xcursor_image *image = xcursor->images[0];
|
||||
wlr_cursor_set_image(input->cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
|
||||
wlr_cursor_attach_output_layout(input->cursor, server->desktop->layout);
|
||||
wlr_cursor_map_to_region(input->cursor, config->cursor.mapped_box);
|
||||
|
|
|
@ -186,15 +186,15 @@ static void set_mode(struct wlr_output *output, struct output_config *oc) {
|
|||
}
|
||||
|
||||
void output_add_notify(struct wl_listener *listener, void *data) {
|
||||
struct roots_desktop *desktop = wl_container_of(listener, desktop,
|
||||
output_add);
|
||||
struct wlr_output *wlr_output = data;
|
||||
struct roots_desktop *desktop = wl_container_of(listener, desktop, output_add);
|
||||
struct roots_input *input = desktop->server->input;
|
||||
struct roots_config *config = desktop->config;
|
||||
|
||||
wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name);
|
||||
wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm",
|
||||
wlr_output->make, wlr_output->model,
|
||||
wlr_output->phys_width, wlr_output->phys_height);
|
||||
wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make,
|
||||
wlr_output->model, wlr_output->phys_width, wlr_output->phys_height);
|
||||
if (wl_list_length(&wlr_output->modes) > 0) {
|
||||
struct wlr_output_mode *mode = NULL;
|
||||
mode = wl_container_of((&wlr_output->modes)->prev, mode, link);
|
||||
|
@ -225,14 +225,8 @@ void output_add_notify(struct wl_listener *listener, void *data) {
|
|||
|
||||
struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
|
||||
struct wlr_xcursor_image *image = xcursor->images[0];
|
||||
// TODO the cursor must be set depending on which surface it is displayed
|
||||
// over which should happen in the compositor.
|
||||
if (!wlr_output_set_cursor(wlr_output, image->buffer,
|
||||
image->width, image->width, image->height,
|
||||
image->hotspot_x, image->hotspot_y)) {
|
||||
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
||||
return;
|
||||
}
|
||||
wlr_cursor_set_image(input->cursor, image->buffer, image->width,
|
||||
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
||||
|
||||
wlr_cursor_warp(input->cursor, NULL, input->cursor->x, input->cursor->y);
|
||||
}
|
||||
|
|
|
@ -33,14 +33,23 @@ struct wlr_cursor_device {
|
|||
struct wl_listener destroy;
|
||||
};
|
||||
|
||||
struct wlr_cursor_output_cursor {
|
||||
struct wlr_cursor *cursor;
|
||||
struct wlr_output_cursor *output_cursor;
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_listener layout_output_destroy;
|
||||
};
|
||||
|
||||
struct wlr_cursor_state {
|
||||
struct wlr_cursor *cursor;
|
||||
struct wl_list devices;
|
||||
struct wl_list devices; // wlr_cursor_device::link
|
||||
struct wl_list output_cursors; // wlr_cursor_output_cursor::link
|
||||
struct wlr_output_layout *layout;
|
||||
struct wlr_xcursor *xcursor;
|
||||
struct wlr_output *mapped_output;
|
||||
struct wlr_box *mapped_box;
|
||||
|
||||
struct wl_listener layout_add;
|
||||
struct wl_listener layout_change;
|
||||
struct wl_listener layout_destroy;
|
||||
};
|
||||
|
@ -63,6 +72,7 @@ struct wlr_cursor *wlr_cursor_create() {
|
|||
cur->state->mapped_output = NULL;
|
||||
|
||||
wl_list_init(&cur->state->devices);
|
||||
wl_list_init(&cur->state->output_cursors);
|
||||
|
||||
// pointer signals
|
||||
wl_signal_init(&cur->events.motion);
|
||||
|
@ -88,33 +98,68 @@ struct wlr_cursor *wlr_cursor_create() {
|
|||
return cur;
|
||||
}
|
||||
|
||||
static void output_cursor_destroy(
|
||||
struct wlr_cursor_output_cursor *output_cursor) {
|
||||
wl_list_remove(&output_cursor->layout_output_destroy.link);
|
||||
wl_list_remove(&output_cursor->link);
|
||||
wlr_output_cursor_destroy(output_cursor->output_cursor);
|
||||
free(output_cursor);
|
||||
}
|
||||
|
||||
static void wlr_cursor_detach_output_layout(struct wlr_cursor *cur) {
|
||||
if (!cur->state->layout) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_cursor_output_cursor *output_cursor, *tmp;
|
||||
wl_list_for_each_safe(output_cursor, tmp, &cur->state->output_cursors,
|
||||
link) {
|
||||
output_cursor_destroy(output_cursor);
|
||||
}
|
||||
|
||||
wl_list_remove(&cur->state->layout_destroy.link);
|
||||
wl_list_remove(&cur->state->layout_change.link);
|
||||
wl_list_remove(&cur->state->layout_add.link);
|
||||
|
||||
cur->state->layout = NULL;
|
||||
}
|
||||
|
||||
static void wlr_cursor_device_destroy(struct wlr_cursor_device *c_device) {
|
||||
struct wlr_input_device *dev = c_device->device;
|
||||
if (dev->type == WLR_INPUT_DEVICE_POINTER) {
|
||||
wl_list_remove(&c_device->motion.link);
|
||||
wl_list_remove(&c_device->motion_absolute.link);
|
||||
wl_list_remove(&c_device->button.link);
|
||||
wl_list_remove(&c_device->axis.link);
|
||||
} else if (dev->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
wl_list_remove(&c_device->touch_down.link);
|
||||
wl_list_remove(&c_device->touch_up.link);
|
||||
wl_list_remove(&c_device->touch_motion.link);
|
||||
wl_list_remove(&c_device->touch_cancel.link);
|
||||
} else if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
wl_list_remove(&c_device->tablet_tool_axis.link);
|
||||
wl_list_remove(&c_device->tablet_tool_proximity.link);
|
||||
wl_list_remove(&c_device->tablet_tool_tip.link);
|
||||
wl_list_remove(&c_device->tablet_tool_button.link);
|
||||
}
|
||||
|
||||
wl_list_remove(&c_device->link);
|
||||
wl_list_remove(&c_device->destroy.link);
|
||||
free(c_device);
|
||||
}
|
||||
|
||||
void wlr_cursor_destroy(struct wlr_cursor *cur) {
|
||||
wlr_cursor_detach_output_layout(cur);
|
||||
|
||||
struct wlr_cursor_device *device, *device_tmp = NULL;
|
||||
wl_list_for_each_safe(device, device_tmp, &cur->state->devices, link) {
|
||||
wl_list_remove(&device->link);
|
||||
free(device);
|
||||
wlr_cursor_device_destroy(device);
|
||||
}
|
||||
|
||||
free(cur->state);
|
||||
free(cur);
|
||||
}
|
||||
|
||||
void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur) {
|
||||
cur->state->xcursor = xcur;
|
||||
}
|
||||
|
||||
static struct wlr_cursor_device *get_cursor_device(struct wlr_cursor *cur,
|
||||
struct wlr_input_device *device) {
|
||||
struct wlr_cursor_device *c_device, *ret = NULL;
|
||||
|
@ -132,16 +177,14 @@ static void wlr_cursor_warp_unchecked(struct wlr_cursor *cur,
|
|||
double x, double y) {
|
||||
assert(cur->state->layout);
|
||||
|
||||
struct wlr_output_layout_output *l_output;
|
||||
wl_list_for_each(l_output, &cur->state->layout->outputs, link) {
|
||||
struct wlr_cursor_output_cursor *output_cursor;
|
||||
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
|
||||
double output_x = x;
|
||||
double output_y = y;
|
||||
|
||||
wlr_output_layout_output_coords(cur->state->layout,
|
||||
l_output->output, &output_x, &output_y);
|
||||
wlr_output_move_cursor(l_output->output,
|
||||
output_x - l_output->output->cursor.hotspot_x,
|
||||
output_y - l_output->output->cursor.hotspot_y);
|
||||
output_cursor->output_cursor->output, &output_x, &output_y);
|
||||
wlr_output_cursor_move(output_cursor->output_cursor, output_x,
|
||||
output_y);
|
||||
}
|
||||
|
||||
cur->x = x;
|
||||
|
@ -254,6 +297,25 @@ void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
|||
wlr_cursor_warp_unchecked(cur, x, y);
|
||||
}
|
||||
|
||||
void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels,
|
||||
int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x,
|
||||
int32_t hotspot_y) {
|
||||
struct wlr_cursor_output_cursor *output_cursor;
|
||||
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
|
||||
wlr_output_cursor_set_image(output_cursor->output_cursor, pixels,
|
||||
stride, width, height, hotspot_x, hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface,
|
||||
int32_t hotspot_x, int32_t hotspot_y) {
|
||||
struct wlr_cursor_output_cursor *output_cursor;
|
||||
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
|
||||
wlr_output_cursor_set_surface(output_cursor->output_cursor, surface,
|
||||
hotspot_x, hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_pointer_motion(struct wl_listener *listener, void *data) {
|
||||
struct wlr_event_pointer_motion *event = data;
|
||||
struct wlr_cursor_device *device =
|
||||
|
@ -431,31 +493,6 @@ void wlr_cursor_attach_input_device(struct wlr_cursor *cur,
|
|||
wlr_cursor_device_create(cur, dev);
|
||||
}
|
||||
|
||||
static void wlr_cursor_device_destroy(struct wlr_cursor_device *c_device) {
|
||||
struct wlr_input_device *dev = c_device->device;
|
||||
if (dev->type == WLR_INPUT_DEVICE_POINTER) {
|
||||
wl_list_remove(&c_device->motion.link);
|
||||
wl_list_remove(&c_device->motion_absolute.link);
|
||||
wl_list_remove(&c_device->button.link);
|
||||
wl_list_remove(&c_device->axis.link);
|
||||
} else if (dev->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
wl_list_remove(&c_device->touch_down.link);
|
||||
wl_list_remove(&c_device->touch_up.link);
|
||||
wl_list_remove(&c_device->touch_motion.link);
|
||||
wl_list_remove(&c_device->touch_cancel.link);
|
||||
} else if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
wl_list_remove(&c_device->tablet_tool_axis.link);
|
||||
wl_list_remove(&c_device->tablet_tool_proximity.link);
|
||||
wl_list_remove(&c_device->tablet_tool_tip.link);
|
||||
wl_list_remove(&c_device->tablet_tool_button.link);
|
||||
}
|
||||
|
||||
wl_list_remove(&c_device->link);
|
||||
wl_list_remove(&c_device->destroy.link);
|
||||
free(c_device);
|
||||
|
||||
}
|
||||
|
||||
void wlr_cursor_detach_input_device(struct wlr_cursor *cur,
|
||||
struct wlr_input_device *dev) {
|
||||
struct wlr_cursor_device *c_device, *tmp = NULL;
|
||||
|
@ -472,10 +509,50 @@ static void handle_layout_destroy(struct wl_listener *listener, void *data) {
|
|||
wlr_cursor_detach_output_layout(state->cursor);
|
||||
}
|
||||
|
||||
static void handle_layout_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_cursor_output_cursor *output_cursor =
|
||||
wl_container_of(listener, output_cursor, layout_output_destroy);
|
||||
//struct wlr_output_layout_output *l_output = data;
|
||||
output_cursor_destroy(output_cursor);
|
||||
}
|
||||
|
||||
static void layout_add(struct wlr_cursor_state *state,
|
||||
struct wlr_output_layout_output *l_output) {
|
||||
struct wlr_cursor_output_cursor *output_cursor =
|
||||
calloc(1, sizeof(struct wlr_cursor_output_cursor));
|
||||
if (output_cursor == NULL) {
|
||||
wlr_log(L_ERROR, "Failed to allocate wlr_cursor_output_cursor");
|
||||
return;
|
||||
}
|
||||
output_cursor->cursor = state->cursor;
|
||||
|
||||
output_cursor->output_cursor = wlr_output_cursor_create(l_output->output);
|
||||
if (output_cursor->output_cursor == NULL) {
|
||||
wlr_log(L_ERROR, "Failed to create wlr_output_cursor");
|
||||
free(output_cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
output_cursor->layout_output_destroy.notify = handle_layout_output_destroy;
|
||||
wl_signal_add(&l_output->events.destroy,
|
||||
&output_cursor->layout_output_destroy);
|
||||
|
||||
wl_list_insert(&state->output_cursors, &output_cursor->link);
|
||||
}
|
||||
|
||||
static void handle_layout_add(struct wl_listener *listener, void *data) {
|
||||
struct wlr_cursor_state *state =
|
||||
wl_container_of(listener, state, layout_add);
|
||||
struct wlr_output_layout_output *l_output = data;
|
||||
layout_add(state, l_output);
|
||||
}
|
||||
|
||||
static void handle_layout_change(struct wl_listener *listener, void *data) {
|
||||
struct wlr_cursor_state *state =
|
||||
wl_container_of(listener, state, layout_change);
|
||||
struct wlr_output_layout *layout = data;
|
||||
|
||||
if (!wlr_output_layout_contains_point(layout, NULL, state->cursor->x,
|
||||
state->cursor->y)) {
|
||||
// the output we were on has gone away so go to the closest boundary
|
||||
|
@ -496,13 +573,19 @@ void wlr_cursor_attach_output_layout(struct wlr_cursor *cur,
|
|||
return;
|
||||
}
|
||||
|
||||
wl_signal_add(&l->events.add, &cur->state->layout_add);
|
||||
cur->state->layout_add.notify = handle_layout_add;
|
||||
wl_signal_add(&l->events.change, &cur->state->layout_change);
|
||||
cur->state->layout_change.notify = handle_layout_change;
|
||||
|
||||
wl_signal_add(&l->events.destroy, &cur->state->layout_destroy);
|
||||
cur->state->layout_destroy.notify = handle_layout_destroy;
|
||||
|
||||
cur->state->layout = l;
|
||||
|
||||
struct wlr_output_layout_output *l_output;
|
||||
wl_list_for_each(l_output, &l->outputs, link) {
|
||||
layout_add(cur->state, l_output);
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_cursor_map_to_output(struct wlr_cursor *cur,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <tgmath.h>
|
||||
#include <time.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/interfaces/wlr_output.h>
|
||||
|
@ -135,7 +136,9 @@ static void wlr_output_update_matrix(struct wlr_output *output) {
|
|||
}
|
||||
|
||||
void wlr_output_enable(struct wlr_output *output, bool enable) {
|
||||
if (output->impl->enable) {
|
||||
output->impl->enable(output, enable);
|
||||
}
|
||||
}
|
||||
|
||||
bool wlr_output_set_mode(struct wlr_output *output,
|
||||
|
@ -188,192 +191,19 @@ void wlr_output_set_position(struct wlr_output *output, int32_t lx,
|
|||
}
|
||||
}
|
||||
|
||||
static bool 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) {
|
||||
if (output->impl->set_cursor
|
||||
&& output->impl->set_cursor(output, buf, stride, width, height,
|
||||
hotspot_x, hotspot_y, true)) {
|
||||
output->cursor.is_sw = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
wlr_log(L_INFO, "Falling back to software cursor");
|
||||
|
||||
output->cursor.is_sw = true;
|
||||
output->cursor.width = width;
|
||||
output->cursor.height = height;
|
||||
|
||||
if (!output->cursor.renderer) {
|
||||
output->cursor.renderer = wlr_gles2_renderer_create(output->backend);
|
||||
if (!output->cursor.renderer) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!output->cursor.texture) {
|
||||
output->cursor.texture =
|
||||
wlr_render_texture_create(output->cursor.renderer);
|
||||
if (!output->cursor.texture) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return wlr_texture_upload_pixels(output->cursor.texture,
|
||||
WL_SHM_FORMAT_ARGB8888, stride, width, height, buf);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (output->cursor.surface) {
|
||||
wl_list_remove(&output->cursor.surface_commit.link);
|
||||
wl_list_remove(&output->cursor.surface_destroy.link);
|
||||
output->cursor.surface = NULL;
|
||||
}
|
||||
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
|
||||
return set_cursor(output, buf, stride, width, height, hotspot_x, hotspot_y);
|
||||
}
|
||||
|
||||
static inline int64_t timespec_to_msec(const struct timespec *a) {
|
||||
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
static void commit_cursor_surface(struct wlr_output *output,
|
||||
struct wlr_surface *surface) {
|
||||
if (output->cursor.is_sw) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer);
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t format = wl_shm_buffer_get_format(buffer);
|
||||
if (format != WL_SHM_FORMAT_ARGB8888) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
int32_t stride = wl_shm_buffer_get_stride(buffer);
|
||||
wl_shm_buffer_begin_access(buffer);
|
||||
wlr_output_set_cursor(output, buffer_data, stride/4, width, height,
|
||||
output->cursor.hotspot_x - surface->current->sx,
|
||||
output->cursor.hotspot_y - surface->current->sy);
|
||||
wl_shm_buffer_end_access(buffer);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
commit_cursor_surface(output, surface);
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
struct wlr_frame_callback *cb, *cnext;
|
||||
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list,
|
||||
link) {
|
||||
wl_callback_send_done(cb->resource, timespec_to_msec(&now));
|
||||
wl_resource_destroy(cb->resource);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_cursor_surface_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output *output = wl_container_of(listener, output,
|
||||
cursor.surface_destroy);
|
||||
|
||||
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) {
|
||||
if (surface && strcmp(surface->role, "wl_pointer-cursor") != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
output->cursor.hotspot_x = hotspot_x;
|
||||
output->cursor.hotspot_y = hotspot_y;
|
||||
|
||||
if (surface && surface == output->cursor.surface) {
|
||||
if (output->impl->set_cursor && !output->cursor.is_sw) {
|
||||
// Only update the hotspot
|
||||
output->impl->set_cursor(output, NULL, 0, 0, 0, hotspot_x,
|
||||
hotspot_y, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (output->cursor.surface) {
|
||||
wl_list_remove(&output->cursor.surface_commit.link);
|
||||
wl_list_remove(&output->cursor.surface_destroy.link);
|
||||
output->cursor.surface = NULL;
|
||||
}
|
||||
|
||||
// Disable hardware cursor
|
||||
// TODO: support hardware cursors
|
||||
output->cursor.is_sw = true;
|
||||
if (output->impl->set_cursor) {
|
||||
output->impl->set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y,
|
||||
true);
|
||||
}
|
||||
|
||||
//output->cursor.is_sw = output->impl->set_cursor == NULL;
|
||||
output->cursor.surface = surface;
|
||||
|
||||
if (surface != NULL) {
|
||||
wl_signal_add(&surface->events.commit, &output->cursor.surface_commit);
|
||||
wl_signal_add(&surface->events.destroy,
|
||||
&output->cursor.surface_destroy);
|
||||
commit_cursor_surface(output, surface);
|
||||
} else {
|
||||
set_cursor(output, NULL, 0, 0, 0, hotspot_x, hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
|
||||
output->cursor.x = x;
|
||||
output->cursor.y = y;
|
||||
|
||||
if (output->cursor.is_sw) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!output->impl->move_cursor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return output->impl->move_cursor(output, x, y);
|
||||
}
|
||||
|
||||
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
||||
const struct wlr_output_impl *impl) {
|
||||
assert(impl->make_current && impl->swap_buffers && impl->transform);
|
||||
output->backend = backend;
|
||||
output->impl = impl;
|
||||
wl_list_init(&output->modes);
|
||||
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
output->scale = 1;
|
||||
wl_list_init(&output->cursors);
|
||||
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) {
|
||||
|
@ -383,9 +213,6 @@ void wlr_output_destroy(struct wlr_output *output) {
|
|||
|
||||
wl_signal_emit(&output->events.destroy, output);
|
||||
|
||||
wlr_texture_destroy(output->cursor.texture);
|
||||
wlr_renderer_destroy(output->cursor.renderer);
|
||||
|
||||
struct wlr_output_mode *mode, *tmp_mode;
|
||||
wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) {
|
||||
free(mode);
|
||||
|
@ -414,27 +241,62 @@ void wlr_output_make_current(struct wlr_output *output) {
|
|||
output->impl->make_current(output);
|
||||
}
|
||||
|
||||
void wlr_output_swap_buffers(struct wlr_output *output) {
|
||||
if (output->cursor.is_sw) {
|
||||
glViewport(0, 0, output->width, output->height);
|
||||
static void output_cursor_get_box(struct wlr_output_cursor *cursor,
|
||||
struct wlr_box *box) {
|
||||
box->x = cursor->x - cursor->hotspot_x;
|
||||
box->y = cursor->y - cursor->hotspot_y;
|
||||
box->width = cursor->width;
|
||||
box->height = cursor->height;
|
||||
}
|
||||
|
||||
static void output_cursor_render(struct wlr_output_cursor *cursor) {
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
struct wlr_renderer *renderer = cursor->renderer;
|
||||
if (cursor->surface != NULL) {
|
||||
// Some clients commit a cursor surface with a NULL buffer to hide it.
|
||||
if (!wlr_surface_has_buffer(cursor->surface)) {
|
||||
return;
|
||||
}
|
||||
texture = cursor->surface->texture;
|
||||
renderer = cursor->surface->renderer;
|
||||
}
|
||||
|
||||
if (texture == NULL || renderer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_box output_box;
|
||||
output_box.x = output_box.y = 0;
|
||||
output_box.width = cursor->output->width;
|
||||
output_box.height = cursor->output->height;
|
||||
|
||||
struct wlr_box cursor_box;
|
||||
output_cursor_get_box(cursor, &cursor_box);
|
||||
|
||||
struct wlr_box intersection;
|
||||
struct wlr_box *intersection_ptr = &intersection;
|
||||
if (!wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
glViewport(0, 0, cursor->output->width, cursor->output->height);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
struct wlr_texture *texture = output->cursor.texture;
|
||||
struct wlr_renderer *renderer = output->cursor.renderer;
|
||||
if (output->cursor.surface) {
|
||||
texture = output->cursor.surface->texture;
|
||||
renderer = output->cursor.surface->renderer;
|
||||
}
|
||||
|
||||
// We check texture->valid because some clients set a cursor surface
|
||||
// with a NULL buffer to hide it
|
||||
if (renderer && texture && texture->valid) {
|
||||
float matrix[16];
|
||||
wlr_texture_get_matrix(texture, &matrix, &output->transform_matrix,
|
||||
output->cursor.x, output->cursor.y);
|
||||
wlr_texture_get_matrix(texture, &matrix,
|
||||
&cursor->output->transform_matrix, cursor->x - cursor->hotspot_x,
|
||||
cursor->y - cursor->hotspot_y);
|
||||
wlr_render_with_matrix(renderer, texture, &matrix);
|
||||
}
|
||||
|
||||
void wlr_output_swap_buffers(struct wlr_output *output) {
|
||||
struct wlr_output_cursor *cursor;
|
||||
wl_list_for_each(cursor, &output->cursors, link) {
|
||||
if (output->hardware_cursor == cursor) {
|
||||
continue;
|
||||
}
|
||||
output_cursor_render(cursor);
|
||||
}
|
||||
|
||||
wl_signal_emit(&output->events.swap_buffers, &output);
|
||||
|
@ -455,3 +317,186 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) {
|
|||
}
|
||||
return output->impl->get_gamma_size(output);
|
||||
}
|
||||
|
||||
static void output_cursor_reset(struct wlr_output_cursor *cursor) {
|
||||
if (cursor->surface != NULL) {
|
||||
wl_list_remove(&cursor->surface_commit.link);
|
||||
wl_list_remove(&cursor->surface_destroy.link);
|
||||
cursor->surface = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
output_cursor_reset(cursor);
|
||||
|
||||
cursor->width = width;
|
||||
cursor->height = height;
|
||||
cursor->hotspot_x = hotspot_x;
|
||||
cursor->hotspot_y = hotspot_y;
|
||||
|
||||
if (cursor->output->hardware_cursor == NULL &&
|
||||
cursor->output->impl->set_cursor) {
|
||||
int ok = cursor->output->impl->set_cursor(cursor->output, pixels,
|
||||
stride, width, height, hotspot_x, hotspot_y, true);
|
||||
if (ok) {
|
||||
cursor->output->hardware_cursor = cursor;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_log(L_INFO, "Falling back to software cursor");
|
||||
|
||||
if (cursor->renderer == NULL) {
|
||||
cursor->renderer = wlr_gles2_renderer_create(cursor->output->backend);
|
||||
if (cursor->renderer == NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor->texture == NULL) {
|
||||
cursor->texture = wlr_render_texture_create(cursor->renderer);
|
||||
if (cursor->texture == NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return wlr_texture_upload_pixels(cursor->texture, WL_SHM_FORMAT_ARGB8888,
|
||||
stride, width, height, pixels);
|
||||
}
|
||||
|
||||
static void output_cursor_commit(struct wlr_output_cursor *cursor) {
|
||||
cursor->width = cursor->surface->current->width;
|
||||
cursor->height = cursor->surface->current->height;
|
||||
|
||||
// TODO: if hardware cursor, upload pixels
|
||||
}
|
||||
|
||||
static inline int64_t timespec_to_msec(const struct timespec *a) {
|
||||
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
static void output_cursor_handle_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_cursor *cursor = wl_container_of(listener, cursor,
|
||||
surface_commit);
|
||||
struct wlr_surface *surface = data;
|
||||
|
||||
output_cursor_commit(cursor);
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
struct wlr_frame_callback *cb, *cnext;
|
||||
wl_list_for_each_safe(cb, cnext, &surface->current->frame_callback_list,
|
||||
link) {
|
||||
wl_callback_send_done(cb->resource, timespec_to_msec(&now));
|
||||
wl_resource_destroy(cb->resource);
|
||||
}
|
||||
}
|
||||
|
||||
static void output_cursor_handle_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_cursor *cursor = wl_container_of(listener, cursor,
|
||||
surface_destroy);
|
||||
output_cursor_reset(cursor);
|
||||
}
|
||||
|
||||
void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor,
|
||||
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) {
|
||||
if (surface && strcmp(surface->role, "wl_pointer-cursor") != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
cursor->width = surface->current->width;
|
||||
cursor->height = surface->current->height;
|
||||
}
|
||||
cursor->hotspot_x = hotspot_x;
|
||||
cursor->hotspot_y = hotspot_y;
|
||||
|
||||
if (surface && surface == cursor->surface) {
|
||||
if (cursor->output->hardware_cursor == cursor &&
|
||||
cursor->output->impl->set_cursor) {
|
||||
// If the surface hasn't changed and it's an hardware cursor, only
|
||||
// update the hotspot
|
||||
cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0,
|
||||
hotspot_x, hotspot_y, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
output_cursor_reset(cursor);
|
||||
|
||||
// Disable hardware cursor for surfaces
|
||||
// TODO: support hardware cursors
|
||||
if (cursor->output->hardware_cursor == cursor &&
|
||||
cursor->output->impl->set_cursor) {
|
||||
cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0, 0,
|
||||
true);
|
||||
cursor->output->hardware_cursor = NULL;
|
||||
}
|
||||
|
||||
cursor->surface = surface;
|
||||
|
||||
if (surface != NULL) {
|
||||
wl_signal_add(&surface->events.commit, &cursor->surface_commit);
|
||||
wl_signal_add(&surface->events.destroy, &cursor->surface_destroy);
|
||||
output_cursor_commit(cursor);
|
||||
} else {
|
||||
// TODO: if hardware cursor, disable cursor
|
||||
}
|
||||
}
|
||||
|
||||
bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) {
|
||||
cursor->x = x;
|
||||
cursor->y = y;
|
||||
|
||||
if (cursor->output->hardware_cursor != cursor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!cursor->output->impl->move_cursor) {
|
||||
return false;
|
||||
}
|
||||
return cursor->output->impl->move_cursor(cursor->output, x, y);
|
||||
}
|
||||
|
||||
struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) {
|
||||
struct wlr_output_cursor *cursor =
|
||||
calloc(1, sizeof(struct wlr_output_cursor));
|
||||
if (cursor == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
cursor->output = output;
|
||||
wl_list_init(&cursor->surface_commit.link);
|
||||
cursor->surface_commit.notify = output_cursor_handle_commit;
|
||||
wl_list_init(&cursor->surface_destroy.link);
|
||||
cursor->surface_destroy.notify = output_cursor_handle_destroy;
|
||||
wl_list_insert(&output->cursors, &cursor->link);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) {
|
||||
if (cursor == NULL) {
|
||||
return;
|
||||
}
|
||||
output_cursor_reset(cursor);
|
||||
if (cursor->output->hardware_cursor == cursor) {
|
||||
// If this cursor was the hardware cursor, disable it
|
||||
if (cursor->output->impl->set_cursor) {
|
||||
cursor->output->impl->set_cursor(cursor->output, NULL, 0, 0, 0, 0,
|
||||
0, true);
|
||||
}
|
||||
cursor->output->hardware_cursor = NULL;
|
||||
}
|
||||
if (cursor->texture != NULL) {
|
||||
wlr_texture_destroy(cursor->texture);
|
||||
}
|
||||
if (cursor->renderer != NULL) {
|
||||
wlr_renderer_destroy(cursor->renderer);
|
||||
}
|
||||
wl_list_remove(&cursor->link);
|
||||
free(cursor);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ struct wlr_output_layout *wlr_output_layout_create() {
|
|||
}
|
||||
wl_list_init(&layout->outputs);
|
||||
|
||||
wl_signal_init(&layout->events.add);
|
||||
wl_signal_init(&layout->events.change);
|
||||
wl_signal_init(&layout->events.destroy);
|
||||
|
||||
|
@ -43,6 +44,7 @@ struct wlr_output_layout *wlr_output_layout_create() {
|
|||
|
||||
static void wlr_output_layout_output_destroy(
|
||||
struct wlr_output_layout_output *l_output) {
|
||||
wl_signal_emit(&l_output->events.destroy, l_output);
|
||||
wl_list_remove(&l_output->state->resolution.link);
|
||||
wl_list_remove(&l_output->state->output_destroy.link);
|
||||
wl_list_remove(&l_output->link);
|
||||
|
@ -155,7 +157,7 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create(
|
|||
l_output->state->l_output = l_output;
|
||||
l_output->state->layout = layout;
|
||||
l_output->output = output;
|
||||
|
||||
wl_signal_init(&l_output->events.destroy);
|
||||
wl_list_insert(&layout->outputs, &l_output->link);
|
||||
|
||||
wl_signal_add(&output->events.resolution, &l_output->state->resolution);
|
||||
|
@ -181,6 +183,7 @@ void wlr_output_layout_add(struct wlr_output_layout *layout,
|
|||
l_output->y = y;
|
||||
l_output->state->auto_configured = false;
|
||||
wlr_output_layout_reconfigure(layout);
|
||||
wl_signal_emit(&layout->events.add, l_output);
|
||||
}
|
||||
|
||||
struct wlr_output_layout_output *wlr_output_layout_get(
|
||||
|
@ -363,6 +366,7 @@ void wlr_output_layout_add_auto(struct wlr_output_layout *layout,
|
|||
|
||||
l_output->state->auto_configured = true;
|
||||
wlr_output_layout_reconfigure(layout);
|
||||
wl_signal_emit(&layout->events.add, l_output);
|
||||
}
|
||||
|
||||
struct wlr_output *wlr_output_layout_get_center_output(
|
||||
|
|
Loading…
Reference in New Issue