wayland: Prepare cursor implementation for reconnect support Co-authored-by: David Edmundson <kde@davidedmundson.co.uk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index a5a45e7..32499fd 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -459,24 +459,34 @@ Wayland_CreateDefaultCursor()
}
static void
-Wayland_FreeCursor(SDL_Cursor *cursor)
+Wayland_FreeCursorData(Wayland_CursorData *d)
{
- Wayland_CursorData *d;
+ if (d->buffer) {
+ if (d->shm_data) {
+ wl_buffer_destroy(d->buffer);
+ }
+ d->buffer = NULL;
+ }
- if (!cursor)
- return;
+ if (d->surface) {
+ wl_surface_destroy(d->surface);
+ d->surface = NULL;
+ }
+}
- d = cursor->driverdata;
+static void
+Wayland_FreeCursor(SDL_Cursor *cursor)
+{
+ if (!cursor) {
+ return;
+ }
/* Probably not a cursor we own */
- if (!d)
+ if (!cursor->driverdata) {
return;
+ }
- if (d->buffer && d->shm_data)
- wl_buffer_destroy(d->buffer);
-
- if (d->surface)
- wl_surface_destroy(d->surface);
+ Wayland_FreeCursorData((Wayland_CursorData *) cursor->driverdata);
/* Not sure what's meant to happen to shm_data */
SDL_free(cursor->driverdata);
@@ -589,6 +599,65 @@ Wayland_EmulateMouseWarpChanged(void *userdata, const char *name, const char *ol
input->warp_emulation_prohibited = !SDL_GetStringBoolean(hint, !input->warp_emulation_prohibited);
}
+#if 0 /* TODO RECONNECT: See waylandvideo.c for more information! */
+static void
+Wayland_RecreateCursor(SDL_Cursor *cursor, SDL_VideoData *vdata)
+{
+ Wayland_CursorData *cdata = (Wayland_CursorData *) cursor->driverdata;
+
+ /* Probably not a cursor we own */
+ if (cdata == NULL) {
+ return;
+ }
+
+ Wayland_FreeCursorData(cdata);
+
+ /* We're not currently freeing this, so... yolo? */
+ if (cdata->shm_data != NULL) {
+ void *old_data_pointer = cdata->shm_data;
+ int stride = cdata->w * 4;
+
+ create_buffer_from_shm(cdata, cdata->w, cdata->h, WL_SHM_FORMAT_ARGB8888);
+
+ SDL_memcpy(cdata->shm_data, old_data_pointer, stride * cdata->h);
+
+ cdata->surface = wl_compositor_create_surface(vdata->compositor);
+ wl_surface_set_user_data(cdata->surface, NULL);
+ }
+}
+
+void
+Wayland_RecreateCursors(void)
+{
+ SDL_Cursor *cursor;
+ SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_VideoData *vdata = SDL_GetVideoDevice()->driverdata;
+
+ if (vdata && vdata->cursor_themes) {
+ SDL_free(vdata->cursor_themes);
+ vdata->cursor_themes = NULL;
+ vdata->num_cursor_themes = 0;
+ }
+
+ if (mouse == NULL) {
+ return;
+ }
+
+ for (cursor = mouse->cursors; cursor != NULL; cursor = cursor->next) {
+ Wayland_RecreateCursor(cursor, vdata);
+ }
+ if (mouse->def_cursor) {
+ Wayland_RecreateCursor(mouse->def_cursor, vdata);
+ }
+ if (mouse->cur_cursor) {
+ Wayland_RecreateCursor(mouse->cur_cursor, vdata);
+ if (mouse->cursor_shown) {
+ Wayland_ShowCursor(mouse->cur_cursor);
+ }
+ }
+}
+#endif /* 0 */
+
void
Wayland_InitMouse(void)
{
diff --git a/src/video/wayland/SDL_waylandmouse.h b/src/video/wayland/SDL_waylandmouse.h
index 76b58b5..00a56af 100644
--- a/src/video/wayland/SDL_waylandmouse.h
+++ b/src/video/wayland/SDL_waylandmouse.h
@@ -27,5 +27,8 @@
extern void Wayland_InitMouse(void);
extern void Wayland_FiniMouse(SDL_VideoData *data);
+#if 0 /* TODO RECONNECT: See waylandvideo.c for more information! */
+extern void Wayland_RecreateCursors(void);
+#endif /* 0 */
#endif
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index 318d96e..eccdd0b 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -1027,7 +1027,7 @@ Wayland_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float * ddpi, float
return driverdata->ddpi != 0.0f ? 0 : SDL_SetError("Couldn't get DPI");
}
-void
+static void
Wayland_VideoCleanup(_THIS)
{
SDL_VideoData *data = _this->driverdata;
@@ -1160,8 +1160,6 @@ Wayland_VideoReconnect(_THIS)
SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
SDL_Window *current_window = SDL_GL_GetCurrentWindow();
- Wayland_FiniMouse(data);
-
SDL_GL_MakeCurrent(NULL, NULL);
Wayland_VideoCleanup(_this);
@@ -1188,6 +1186,8 @@ Wayland_VideoReconnect(_THIS)
window = window->next;
}
+ Wayland_RecreateCursors();
+
if (current_window && current_ctx) {
SDL_GL_MakeCurrent (current_window, current_ctx);
}