aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/drm/drm.c35
-rw-r--r--backend/wayland/output.c110
-rw-r--r--backend/wayland/wl_seat.c4
-rw-r--r--backend/x11/backend.c5
4 files changed, 85 insertions, 69 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 27a8490c..6cbb0535 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -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);
diff --git a/backend/wayland/output.c b/backend/wayland/output.c
index 0dde343c..494e0522 100644
--- a/backend/wayland/output.c
+++ b/backend/wayland/output.c
@@ -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);
-
- 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);
+ 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);
+
+ 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,
diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c
index 903ca3ee..0d8e5b1f 100644
--- a/backend/wayland/wl_seat.c
+++ b/backend/wayland/wl_seat.c
@@ -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,
diff --git a/backend/x11/backend.c b/backend/x11/backend.c
index 37bbdaec..97b0dd8c 100644
--- a/backend/x11/backend.c
+++ b/backend/x11/backend.c
@@ -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) {