diff options
author | chai <chaifix@163.com> | 2019-05-11 22:54:56 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-05-11 22:54:56 +0800 |
commit | 9645be0af1b1d5cb0ad5892d5464e1b23c51b550 (patch) | |
tree | 129c716bed8e93312421c3adb2f8e7c4f811602d /source/3rd-party/SDL2/src/video/wayland |
Diffstat (limited to 'source/3rd-party/SDL2/src/video/wayland')
21 files changed, 5105 insertions, 0 deletions
diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandclipboard.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandclipboard.c new file mode 100644 index 0000000..5fd826b --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandclipboard.c @@ -0,0 +1,123 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +#include "SDL_waylanddatamanager.h" +#include "SDL_waylandevents_c.h" + +int +Wayland_SetClipboardText(_THIS, const char *text) +{ + SDL_VideoData *video_data = NULL; + SDL_WaylandDataDevice *data_device = NULL; + + int status = 0; + + if (_this == NULL || _this->driverdata == NULL) { + status = SDL_SetError("Video driver uninitialized"); + } else { + video_data = _this->driverdata; + /* TODO: Support more than one seat */ + data_device = Wayland_get_data_device(video_data->input); + if (text[0] != '\0') { + SDL_WaylandDataSource* source = Wayland_data_source_create(_this); + Wayland_data_source_add_data(source, TEXT_MIME, text, + strlen(text) + 1); + + status = Wayland_data_device_set_selection(data_device, source); + if (status != 0) { + Wayland_data_source_destroy(source); + } + } else { + status = Wayland_data_device_clear_selection(data_device); + } + } + + return status; +} + +char * +Wayland_GetClipboardText(_THIS) +{ + SDL_VideoData *video_data = NULL; + SDL_WaylandDataDevice *data_device = NULL; + + char *text = NULL; + + void *buffer = NULL; + size_t length = 0; + + if (_this == NULL || _this->driverdata == NULL) { + SDL_SetError("Video driver uninitialized"); + } else { + video_data = _this->driverdata; + /* TODO: Support more than one seat */ + data_device = Wayland_get_data_device(video_data->input); + if (data_device->selection_offer != NULL) { + buffer = Wayland_data_offer_receive(data_device->selection_offer, + &length, TEXT_MIME, SDL_TRUE); + if (length > 0) { + text = (char*) buffer; + } + } else if (data_device->selection_source != NULL) { + buffer = Wayland_data_source_get_data(data_device->selection_source, + &length, TEXT_MIME, SDL_TRUE); + if (length > 0) { + text = (char*) buffer; + } + } + } + + if (text == NULL) { + text = SDL_strdup(""); + } + + return text; +} + +SDL_bool +Wayland_HasClipboardText(_THIS) +{ + SDL_VideoData *video_data = NULL; + SDL_WaylandDataDevice *data_device = NULL; + + SDL_bool result = SDL_FALSE; + if (_this == NULL || _this->driverdata == NULL) { + SDL_SetError("Video driver uninitialized"); + } else { + video_data = _this->driverdata; + data_device = Wayland_get_data_device(video_data->input); + if (data_device != NULL && Wayland_data_offer_has_mime( + data_device->selection_offer, TEXT_MIME)) { + result = SDL_TRUE; + } else if(data_device != NULL && Wayland_data_source_has_mime( + data_device->selection_source, TEXT_MIME)) { + result = SDL_TRUE; + } + } + return result; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandclipboard.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandclipboard.h new file mode 100644 index 0000000..467e1c7 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandclipboard.h @@ -0,0 +1,32 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#ifndef SDL_waylandclipboard_h_ +#define SDL_waylandclipboard_h_ + +extern int Wayland_SetClipboardText(_THIS, const char *text); +extern char *Wayland_GetClipboardText(_THIS); +extern SDL_bool Wayland_HasClipboardText(_THIS); + +#endif /* SDL_waylandclipboard_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddatamanager.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddatamanager.c new file mode 100644 index 0000000..f1b9742 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddatamanager.c @@ -0,0 +1,468 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +#include <fcntl.h> +#include <unistd.h> +#include <limits.h> +#include <signal.h> + +#include "SDL_stdinc.h" +#include "SDL_assert.h" +#include "../../core/unix/SDL_poll.h" + +#include "SDL_waylandvideo.h" +#include "SDL_waylanddatamanager.h" + +#include "SDL_waylanddyn.h" + +static ssize_t +write_pipe(int fd, const void* buffer, size_t total_length, size_t *pos) +{ + int ready = 0; + ssize_t bytes_written = 0; + ssize_t length = total_length - *pos; + + sigset_t sig_set; + sigset_t old_sig_set; + struct timespec zerotime = {0}; + + ready = SDL_IOReady(fd, SDL_TRUE, 1 * 1000); + + sigemptyset(&sig_set); + sigaddset(&sig_set, SIGPIPE); + + pthread_sigmask(SIG_BLOCK, &sig_set, &old_sig_set); + + if (ready == 0) { + bytes_written = SDL_SetError("Pipe timeout"); + } else if (ready < 0) { + bytes_written = SDL_SetError("Pipe select error"); + } else { + if (length > 0) { + bytes_written = write(fd, (Uint8*)buffer + *pos, SDL_min(length, PIPE_BUF)); + } + + if (bytes_written > 0) { + *pos += bytes_written; + } + } + + sigtimedwait(&sig_set, 0, &zerotime); + pthread_sigmask(SIG_SETMASK, &old_sig_set, NULL); + + return bytes_written; +} + +static ssize_t +read_pipe(int fd, void** buffer, size_t* total_length, SDL_bool null_terminate) +{ + int ready = 0; + void* output_buffer = NULL; + char temp[PIPE_BUF]; + size_t new_buffer_length = 0; + ssize_t bytes_read = 0; + size_t pos = 0; + + ready = SDL_IOReady(fd, SDL_FALSE, 1 * 1000); + + if (ready == 0) { + bytes_read = SDL_SetError("Pipe timeout"); + } else if (ready < 0) { + bytes_read = SDL_SetError("Pipe select error"); + } else { + bytes_read = read(fd, temp, sizeof(temp)); + } + + if (bytes_read > 0) { + pos = *total_length; + *total_length += bytes_read; + + if (null_terminate == SDL_TRUE) { + new_buffer_length = *total_length + 1; + } else { + new_buffer_length = *total_length; + } + + if (*buffer == NULL) { + output_buffer = SDL_malloc(new_buffer_length); + } else { + output_buffer = SDL_realloc(*buffer, new_buffer_length); + } + + if (output_buffer == NULL) { + bytes_read = SDL_OutOfMemory(); + } else { + SDL_memcpy((Uint8*)output_buffer + pos, temp, bytes_read); + + if (null_terminate == SDL_TRUE) { + SDL_memset((Uint8*)output_buffer + (new_buffer_length - 1), 0, 1); + } + + *buffer = output_buffer; + } + } + + return bytes_read; +} + +#define MIME_LIST_SIZE 4 + +static const char* mime_conversion_list[MIME_LIST_SIZE][2] = { + {"text/plain", TEXT_MIME}, + {"TEXT", TEXT_MIME}, + {"UTF8_STRING", TEXT_MIME}, + {"STRING", TEXT_MIME} +}; + +const char* +Wayland_convert_mime_type(const char *mime_type) +{ + const char *found = mime_type; + + size_t index = 0; + + for (index = 0; index < MIME_LIST_SIZE; ++index) { + if (strcmp(mime_conversion_list[index][0], mime_type) == 0) { + found = mime_conversion_list[index][1]; + break; + } + } + + return found; +} + +static SDL_MimeDataList* +mime_data_list_find(struct wl_list* list, + const char* mime_type) +{ + SDL_MimeDataList *found = NULL; + + SDL_MimeDataList *mime_list = NULL; + wl_list_for_each(mime_list, list, link) { + if (strcmp(mime_list->mime_type, mime_type) == 0) { + found = mime_list; + break; + } + } + return found; +} + +static int +mime_data_list_add(struct wl_list* list, + const char* mime_type, + void* buffer, size_t length) +{ + int status = 0; + size_t mime_type_length = 0; + + SDL_MimeDataList *mime_data = NULL; + + mime_data = mime_data_list_find(list, mime_type); + + if (mime_data == NULL) { + mime_data = SDL_calloc(1, sizeof(*mime_data)); + if (mime_data == NULL) { + status = SDL_OutOfMemory(); + } else { + WAYLAND_wl_list_insert(list, &(mime_data->link)); + + mime_type_length = strlen(mime_type) + 1; + mime_data->mime_type = SDL_malloc(mime_type_length); + if (mime_data->mime_type == NULL) { + status = SDL_OutOfMemory(); + } else { + SDL_memcpy(mime_data->mime_type, mime_type, mime_type_length); + } + } + } + + if (mime_data != NULL && buffer != NULL && length > 0) { + if (mime_data->data != NULL) { + SDL_free(mime_data->data); + } + mime_data->data = buffer; + mime_data->length = length; + } + + return status; +} + +static void +mime_data_list_free(struct wl_list *list) +{ + SDL_MimeDataList *mime_data = NULL; + SDL_MimeDataList *next = NULL; + + wl_list_for_each_safe(mime_data, next, list, link) { + if (mime_data->data != NULL) { + SDL_free(mime_data->data); + } + if (mime_data->mime_type != NULL) { + SDL_free(mime_data->mime_type); + } + SDL_free(mime_data); + } +} + +ssize_t +Wayland_data_source_send(SDL_WaylandDataSource *source, + const char *mime_type, int fd) +{ + size_t written_bytes = 0; + ssize_t status = 0; + SDL_MimeDataList *mime_data = NULL; + + mime_type = Wayland_convert_mime_type(mime_type); + mime_data = mime_data_list_find(&source->mimes, + mime_type); + + if (mime_data == NULL || mime_data->data == NULL) { + status = SDL_SetError("Invalid mime type"); + close(fd); + } else { + while (write_pipe(fd, mime_data->data, mime_data->length, + &written_bytes) > 0); + close(fd); + status = written_bytes; + } + return status; +} + +int Wayland_data_source_add_data(SDL_WaylandDataSource *source, + const char *mime_type, + const void *buffer, + size_t length) +{ + int status = 0; + if (length > 0) { + void *internal_buffer = SDL_malloc(length); + if (internal_buffer == NULL) { + status = SDL_OutOfMemory(); + } else { + SDL_memcpy(internal_buffer, buffer, length); + status = mime_data_list_add(&source->mimes, mime_type, + internal_buffer, length); + } + } + return status; +} + +SDL_bool +Wayland_data_source_has_mime(SDL_WaylandDataSource *source, + const char *mime_type) +{ + SDL_bool found = SDL_FALSE; + + if (source != NULL) { + found = mime_data_list_find(&source->mimes, mime_type) != NULL; + } + return found; +} + +void* +Wayland_data_source_get_data(SDL_WaylandDataSource *source, + size_t *length, const char* mime_type, + SDL_bool null_terminate) +{ + SDL_MimeDataList *mime_data = NULL; + void *buffer = NULL; + *length = 0; + + if (source == NULL) { + SDL_SetError("Invalid data source"); + } else { + mime_data = mime_data_list_find(&source->mimes, mime_type); + if (mime_data != NULL && mime_data->length > 0) { + buffer = SDL_malloc(mime_data->length); + if (buffer == NULL) { + *length = SDL_OutOfMemory(); + } else { + *length = mime_data->length; + SDL_memcpy(buffer, mime_data->data, mime_data->length); + } + } + } + + return buffer; +} + +void +Wayland_data_source_destroy(SDL_WaylandDataSource *source) +{ + if (source != NULL) { + wl_data_source_destroy(source->source); + mime_data_list_free(&source->mimes); + SDL_free(source); + } +} + +void* +Wayland_data_offer_receive(SDL_WaylandDataOffer *offer, + size_t *length, const char* mime_type, + SDL_bool null_terminate) +{ + SDL_WaylandDataDevice *data_device = NULL; + + int pipefd[2]; + void *buffer = NULL; + *length = 0; + + if (offer == NULL) { + SDL_SetError("Invalid data offer"); + } else if ((data_device = offer->data_device) == NULL) { + SDL_SetError("Data device not initialized"); + } else if (pipe2(pipefd, O_CLOEXEC|O_NONBLOCK) == -1) { + SDL_SetError("Could not read pipe"); + } else { + wl_data_offer_receive(offer->offer, mime_type, pipefd[1]); + + /* TODO: Needs pump and flush? */ + WAYLAND_wl_display_flush(data_device->video_data->display); + + close(pipefd[1]); + + while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0); + close(pipefd[0]); + } + return buffer; +} + +int +Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, + const char* mime_type) +{ + return mime_data_list_add(&offer->mimes, mime_type, NULL, 0); +} + + +SDL_bool +Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, + const char *mime_type) +{ + SDL_bool found = SDL_FALSE; + + if (offer != NULL) { + found = mime_data_list_find(&offer->mimes, mime_type) != NULL; + } + return found; +} + +void +Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer) +{ + if (offer != NULL) { + wl_data_offer_destroy(offer->offer); + mime_data_list_free(&offer->mimes); + SDL_free(offer); + } +} + +int +Wayland_data_device_clear_selection(SDL_WaylandDataDevice *data_device) +{ + int status = 0; + + if (data_device == NULL || data_device->data_device == NULL) { + status = SDL_SetError("Invalid Data Device"); + } else if (data_device->selection_source != 0) { + wl_data_device_set_selection(data_device->data_device, NULL, 0); + data_device->selection_source = NULL; + } + return status; +} + +int +Wayland_data_device_set_selection(SDL_WaylandDataDevice *data_device, + SDL_WaylandDataSource *source) +{ + int status = 0; + size_t num_offers = 0; + size_t index = 0; + + if (data_device == NULL) { + status = SDL_SetError("Invalid Data Device"); + } else if (source == NULL) { + status = SDL_SetError("Invalid source"); + } else { + SDL_MimeDataList *mime_data = NULL; + + wl_list_for_each(mime_data, &(source->mimes), link) { + wl_data_source_offer(source->source, + mime_data->mime_type); + + /* TODO - Improve system for multiple mime types to same data */ + for (index = 0; index < MIME_LIST_SIZE; ++index) { + if (strcmp(mime_conversion_list[index][1], mime_data->mime_type) == 0) { + wl_data_source_offer(source->source, + mime_conversion_list[index][0]); + } + } + /* */ + + ++num_offers; + } + + if (num_offers == 0) { + Wayland_data_device_clear_selection(data_device); + status = SDL_SetError("No mime data"); + } else { + /* Only set if there is a valid serial if not set it later */ + if (data_device->selection_serial != 0) { + wl_data_device_set_selection(data_device->data_device, + source->source, + data_device->selection_serial); + } + data_device->selection_source = source; + } + } + + return status; +} + +int +Wayland_data_device_set_serial(SDL_WaylandDataDevice *data_device, + uint32_t serial) +{ + int status = -1; + if (data_device != NULL) { + status = 0; + + /* If there was no serial and there is a pending selection set it now. */ + if (data_device->selection_serial == 0 + && data_device->selection_source != NULL) { + wl_data_device_set_selection(data_device->data_device, + data_device->selection_source->source, + serial); + } + + data_device->selection_serial = serial; + } + + return status; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddatamanager.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddatamanager.h new file mode 100644 index 0000000..9b13e64 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddatamanager.h @@ -0,0 +1,103 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#ifndef SDL_waylanddatamanager_h_ +#define SDL_waylanddatamanager_h_ + +#include "SDL_waylandvideo.h" +#include "SDL_waylandwindow.h" + +#define TEXT_MIME "text/plain;charset=utf-8" +#define FILE_MIME "text/uri-list" + +typedef struct { + char *mime_type; + void *data; + size_t length; + struct wl_list link; +} SDL_MimeDataList; + +typedef struct { + struct wl_data_source *source; + struct wl_list mimes; +} SDL_WaylandDataSource; + +typedef struct { + struct wl_data_offer *offer; + struct wl_list mimes; + void *data_device; +} SDL_WaylandDataOffer; + +typedef struct { + struct wl_data_device *data_device; + SDL_VideoData *video_data; + + /* Drag and Drop */ + uint32_t drag_serial; + SDL_WaylandDataOffer *drag_offer; + SDL_WaylandDataOffer *selection_offer; + + /* Clipboard */ + uint32_t selection_serial; + SDL_WaylandDataSource *selection_source; +} SDL_WaylandDataDevice; + +extern const char* Wayland_convert_mime_type(const char *mime_type); + +/* Wayland Data Source - (Sending) */ +extern SDL_WaylandDataSource* Wayland_data_source_create(_THIS); +extern ssize_t Wayland_data_source_send(SDL_WaylandDataSource *source, + const char *mime_type, int fd); +extern int Wayland_data_source_add_data(SDL_WaylandDataSource *source, + const char *mime_type, + const void *buffer, + size_t length); +extern SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source, + const char *mime_type); +extern void* Wayland_data_source_get_data(SDL_WaylandDataSource *source, + size_t *length, + const char *mime_type, + SDL_bool null_terminate); +extern void Wayland_data_source_destroy(SDL_WaylandDataSource *source); + +/* Wayland Data Offer - (Receiving) */ +extern void* Wayland_data_offer_receive(SDL_WaylandDataOffer *offer, + size_t *length, + const char *mime_type, + SDL_bool null_terminate); +extern SDL_bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, + const char *mime_type); +extern int Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, + const char *mime_type); +extern void Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer); + +/* Clipboard */ +extern int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device); +extern int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, + SDL_WaylandDataSource *source); +extern int Wayland_data_device_set_serial(SDL_WaylandDataDevice *device, + uint32_t serial); +#endif /* SDL_waylanddatamanager_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ + diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddyn.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddyn.c new file mode 100644 index 0000000..98cc518 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddyn.c @@ -0,0 +1,178 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +#define DEBUG_DYNAMIC_WAYLAND 0 + +#include "SDL_waylanddyn.h" + +#if DEBUG_DYNAMIC_WAYLAND +#include "SDL_log.h" +#endif + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + +#include "SDL_name.h" +#include "SDL_loadso.h" + +typedef struct +{ + void *lib; + const char *libname; +} waylanddynlib; + +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC NULL +#endif +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL NULL +#endif +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR NULL +#endif +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON +#define SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON NULL +#endif + +static waylanddynlib waylandlibs[] = { + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC}, + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL}, + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR}, + {NULL, SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON} +}; + +static void * +WAYLAND_GetSym(const char *fnname, int *pHasModule) +{ + int i; + void *fn = NULL; + for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { + if (waylandlibs[i].lib != NULL) { + fn = SDL_LoadFunction(waylandlibs[i].lib, fnname); + if (fn != NULL) + break; + } + } + +#if DEBUG_DYNAMIC_WAYLAND + if (fn != NULL) + SDL_Log("WAYLAND: Found '%s' in %s (%p)\n", fnname, waylandlibs[i].libname, fn); + else + SDL_Log("WAYLAND: Symbol '%s' NOT FOUND!\n", fnname); +#endif + + if (fn == NULL) + *pHasModule = 0; /* kill this module. */ + + return fn; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */ + +/* Define all the function pointers and wrappers... */ +#define SDL_WAYLAND_MODULE(modname) int SDL_WAYLAND_HAVE_##modname = 0; +#define SDL_WAYLAND_SYM(rc,fn,params) SDL_DYNWAYLANDFN_##fn WAYLAND_##fn = NULL; +#define SDL_WAYLAND_INTERFACE(iface) const struct wl_interface *WAYLAND_##iface = NULL; +#include "SDL_waylandsym.h" + +static int wayland_load_refcount = 0; + +void +SDL_WAYLAND_UnloadSymbols(void) +{ + /* Don't actually unload if more than one module is using the libs... */ + if (wayland_load_refcount > 0) { + if (--wayland_load_refcount == 0) { +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + int i; +#endif + + /* set all the function pointers to NULL. */ +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 0; +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = NULL; +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = NULL; +#include "SDL_waylandsym.h" + + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { + if (waylandlibs[i].lib != NULL) { + SDL_UnloadObject(waylandlibs[i].lib); + waylandlibs[i].lib = NULL; + } + } +#endif + } + } +} + +/* returns non-zero if all needed symbols were loaded. */ +int +SDL_WAYLAND_LoadSymbols(void) +{ + int rc = 1; /* always succeed if not using Dynamic WAYLAND stuff. */ + + /* deal with multiple modules (dga, wayland, etc) needing these symbols... */ + if (wayland_load_refcount++ == 0) { +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + int i; + int *thismod = NULL; + for (i = 0; i < SDL_TABLESIZE(waylandlibs); i++) { + if (waylandlibs[i].libname != NULL) { + waylandlibs[i].lib = SDL_LoadObject(waylandlibs[i].libname); + } + } + +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */ +#include "SDL_waylandsym.h" + +#define SDL_WAYLAND_MODULE(modname) thismod = &SDL_WAYLAND_HAVE_##modname; +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = (SDL_DYNWAYLANDFN_##fn) WAYLAND_GetSym(#fn,thismod); +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = (struct wl_interface *) WAYLAND_GetSym(#iface,thismod); +#include "SDL_waylandsym.h" + + if (SDL_WAYLAND_HAVE_WAYLAND_CLIENT) { + /* all required symbols loaded. */ + SDL_ClearError(); + } else { + /* in case something got loaded... */ + SDL_WAYLAND_UnloadSymbols(); + rc = 0; + } + +#else /* no dynamic WAYLAND */ + +#define SDL_WAYLAND_MODULE(modname) SDL_WAYLAND_HAVE_##modname = 1; /* default yes */ +#define SDL_WAYLAND_SYM(rc,fn,params) WAYLAND_##fn = fn; +#define SDL_WAYLAND_INTERFACE(iface) WAYLAND_##iface = &iface; +#include "SDL_waylandsym.h" + +#endif + } + + return rc; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddyn.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddyn.h new file mode 100644 index 0000000..720427e --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylanddyn.h @@ -0,0 +1,107 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_waylanddyn_h_ +#define SDL_waylanddyn_h_ + +#include "../../SDL_internal.h" + +/* We can't include wayland-client.h here + * but we need some structs from it + */ +struct wl_interface; +struct wl_proxy; +struct wl_event_queue; +struct wl_display; +struct wl_surface; +struct wl_shm; + +#include <stdint.h> +#include "wayland-cursor.h" +#include "wayland-util.h" +#include "xkbcommon/xkbcommon.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +int SDL_WAYLAND_LoadSymbols(void); +void SDL_WAYLAND_UnloadSymbols(void); + +#define SDL_WAYLAND_MODULE(modname) extern int SDL_WAYLAND_HAVE_##modname; +#define SDL_WAYLAND_SYM(rc,fn,params) \ + typedef rc (*SDL_DYNWAYLANDFN_##fn) params; \ + extern SDL_DYNWAYLANDFN_##fn WAYLAND_##fn; +#define SDL_WAYLAND_INTERFACE(iface) extern const struct wl_interface *WAYLAND_##iface; +#include "SDL_waylandsym.h" + + +#ifdef __cplusplus +} +#endif + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + +#ifdef _WAYLAND_CLIENT_H +#error Do not include wayland-client ahead of SDL_waylanddyn.h in dynamic loading mode +#endif + +/* wayland-client-protocol.h included from wayland-client.h + * has inline functions that require these to be defined in dynamic loading mode + */ + +#define wl_proxy_create (*WAYLAND_wl_proxy_create) +#define wl_proxy_destroy (*WAYLAND_wl_proxy_destroy) +#define wl_proxy_marshal (*WAYLAND_wl_proxy_marshal) +#define wl_proxy_set_user_data (*WAYLAND_wl_proxy_set_user_data) +#define wl_proxy_get_user_data (*WAYLAND_wl_proxy_get_user_data) +#define wl_proxy_add_listener (*WAYLAND_wl_proxy_add_listener) +#define wl_proxy_marshal_constructor (*WAYLAND_wl_proxy_marshal_constructor) +#define wl_proxy_marshal_constructor_versioned (*WAYLAND_wl_proxy_marshal_constructor_versioned) + +#define wl_seat_interface (*WAYLAND_wl_seat_interface) +#define wl_surface_interface (*WAYLAND_wl_surface_interface) +#define wl_shm_pool_interface (*WAYLAND_wl_shm_pool_interface) +#define wl_buffer_interface (*WAYLAND_wl_buffer_interface) +#define wl_registry_interface (*WAYLAND_wl_registry_interface) +#define wl_shell_surface_interface (*WAYLAND_wl_shell_surface_interface) +#define wl_region_interface (*WAYLAND_wl_region_interface) +#define wl_pointer_interface (*WAYLAND_wl_pointer_interface) +#define wl_keyboard_interface (*WAYLAND_wl_keyboard_interface) +#define wl_compositor_interface (*WAYLAND_wl_compositor_interface) +#define wl_output_interface (*WAYLAND_wl_output_interface) +#define wl_shell_interface (*WAYLAND_wl_shell_interface) +#define wl_shm_interface (*WAYLAND_wl_shm_interface) +#define wl_data_device_interface (*WAYLAND_wl_data_device_interface) +#define wl_data_offer_interface (*WAYLAND_wl_data_offer_interface) +#define wl_data_source_interface (*WAYLAND_wl_data_source_interface) +#define wl_data_device_manager_interface (*WAYLAND_wl_data_device_manager_interface) + +#endif /* SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC */ + +#include "wayland-client-core.h" +#include "wayland-client-protocol.h" +#include "wayland-egl.h" + +#endif /* SDL_waylanddyn_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandevents.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandevents.c new file mode 100644 index 0000000..0c953a5 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandevents.c @@ -0,0 +1,1136 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +#include "SDL_stdinc.h" +#include "SDL_assert.h" +#include "SDL_log.h" + +#include "../../core/unix/SDL_poll.h" +#include "../../events/SDL_sysevents.h" +#include "../../events/SDL_events_c.h" +#include "../../events/scancodes_xfree86.h" + +#include "SDL_waylandvideo.h" +#include "SDL_waylandevents_c.h" +#include "SDL_waylandwindow.h" + +#include "SDL_waylanddyn.h" + +#include "pointer-constraints-unstable-v1-client-protocol.h" +#include "relative-pointer-unstable-v1-client-protocol.h" +#include "xdg-shell-client-protocol.h" +#include "xdg-shell-unstable-v6-client-protocol.h" + +#include <linux/input.h> +#include <sys/select.h> +#include <sys/mman.h> +#include <poll.h> +#include <unistd.h> +#include <xkbcommon/xkbcommon.h> + +struct SDL_WaylandInput { + SDL_VideoData *display; + struct wl_seat *seat; + struct wl_pointer *pointer; + struct wl_touch *touch; + struct wl_keyboard *keyboard; + SDL_WaylandDataDevice *data_device; + struct zwp_relative_pointer_v1 *relative_pointer; + SDL_WindowData *pointer_focus; + SDL_WindowData *keyboard_focus; + + /* Last motion location */ + wl_fixed_t sx_w; + wl_fixed_t sy_w; + + double dx_frac; + double dy_frac; + + struct { + struct xkb_keymap *keymap; + struct xkb_state *state; + } xkb; +}; + +struct SDL_WaylandTouchPoint { + SDL_TouchID id; + float x; + float y; + struct wl_surface* surface; + + struct SDL_WaylandTouchPoint* prev; + struct SDL_WaylandTouchPoint* next; +}; + +struct SDL_WaylandTouchPointList { + struct SDL_WaylandTouchPoint* head; + struct SDL_WaylandTouchPoint* tail; +}; + +static struct SDL_WaylandTouchPointList touch_points = {NULL, NULL}; + +static void +touch_add(SDL_TouchID id, float x, float y, struct wl_surface *surface) +{ + struct SDL_WaylandTouchPoint* tp = SDL_malloc(sizeof(struct SDL_WaylandTouchPoint)); + + tp->id = id; + tp->x = x; + tp->y = y; + tp->surface = surface; + + if (touch_points.tail) { + touch_points.tail->next = tp; + tp->prev = touch_points.tail; + } else { + touch_points.head = tp; + tp->prev = NULL; + } + + touch_points.tail = tp; + tp->next = NULL; +} + +static void +touch_update(SDL_TouchID id, float x, float y) +{ + struct SDL_WaylandTouchPoint* tp = touch_points.head; + + while (tp) { + if (tp->id == id) { + tp->x = x; + tp->y = y; + } + + tp = tp->next; + } +} + +static void +touch_del(SDL_TouchID id, float* x, float* y) +{ + struct SDL_WaylandTouchPoint* tp = touch_points.head; + + while (tp) { + if (tp->id == id) { + *x = tp->x; + *y = tp->y; + + if (tp->prev) { + tp->prev->next = tp->next; + } else { + touch_points.head = tp->next; + } + + if (tp->next) { + tp->next->prev = tp->prev; + } else { + touch_points.tail = tp->prev; + } + + SDL_free(tp); + } + + tp = tp->next; + } +} + +static struct wl_surface* +touch_surface(SDL_TouchID id) +{ + struct SDL_WaylandTouchPoint* tp = touch_points.head; + + while (tp) { + if (tp->id == id) { + return tp->surface; + } + + tp = tp->next; + } + + return NULL; +} + +void +Wayland_PumpEvents(_THIS) +{ + SDL_VideoData *d = _this->driverdata; + + WAYLAND_wl_display_flush(d->display); + + if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, 0)) { + WAYLAND_wl_display_dispatch(d->display); + } + else + { + WAYLAND_wl_display_dispatch_pending(d->display); + } +} + +static void +pointer_handle_enter(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface, + wl_fixed_t sx_w, wl_fixed_t sy_w) +{ + struct SDL_WaylandInput *input = data; + SDL_WindowData *window; + + if (!surface) { + /* enter event for a window we've just destroyed */ + return; + } + + /* This handler will be called twice in Wayland 1.4 + * Once for the window surface which has valid user data + * and again for the mouse cursor surface which does not have valid user data + * We ignore the later + */ + + window = (SDL_WindowData *)wl_surface_get_user_data(surface); + + if (window) { + input->pointer_focus = window; + SDL_SetMouseFocus(window->sdlwindow); + } +} + +static void +pointer_handle_leave(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface) +{ + struct SDL_WaylandInput *input = data; + + if (input->pointer_focus) { + SDL_SetMouseFocus(NULL); + input->pointer_focus = NULL; + } +} + +static void +pointer_handle_motion(void *data, struct wl_pointer *pointer, + uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) +{ + struct SDL_WaylandInput *input = data; + SDL_WindowData *window = input->pointer_focus; + input->sx_w = sx_w; + input->sy_w = sy_w; + if (input->pointer_focus) { + const int sx = wl_fixed_to_int(sx_w); + const int sy = wl_fixed_to_int(sy_w); + SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy); + } +} + +static SDL_bool +ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial) +{ + SDL_WindowData *window_data = input->pointer_focus; + SDL_Window *window = window_data->sdlwindow; + + if (window->hit_test) { + const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) }; + const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data); + + static const uint32_t directions_wl[] = { + WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP, + WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT, + WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM, + WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT + }; + + /* the names are different (ZXDG_TOPLEVEL_V6_RESIZE_EDGE_* vs + WL_SHELL_SURFACE_RESIZE_*), but the values are the same. */ + const uint32_t *directions_zxdg = directions_wl; + + switch (rc) { + case SDL_HITTEST_DRAGGABLE: + if (input->display->shell.xdg) { + xdg_toplevel_move(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial); + } else if (input->display->shell.zxdg) { + zxdg_toplevel_v6_move(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial); + } else { + wl_shell_surface_move(window_data->shell_surface.wl, input->seat, serial); + } + return SDL_TRUE; + + case SDL_HITTEST_RESIZE_TOPLEFT: + case SDL_HITTEST_RESIZE_TOP: + case SDL_HITTEST_RESIZE_TOPRIGHT: + case SDL_HITTEST_RESIZE_RIGHT: + case SDL_HITTEST_RESIZE_BOTTOMRIGHT: + case SDL_HITTEST_RESIZE_BOTTOM: + case SDL_HITTEST_RESIZE_BOTTOMLEFT: + case SDL_HITTEST_RESIZE_LEFT: + if (input->display->shell.xdg) { + xdg_toplevel_resize(window_data->shell_surface.xdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]); + } else if (input->display->shell.zxdg) { + zxdg_toplevel_v6_resize(window_data->shell_surface.zxdg.roleobj.toplevel, input->seat, serial, directions_zxdg[rc - SDL_HITTEST_RESIZE_TOPLEFT]); + } else { + wl_shell_surface_resize(window_data->shell_surface.wl, input->seat, serial, directions_wl[rc - SDL_HITTEST_RESIZE_TOPLEFT]); + } + return SDL_TRUE; + + default: return SDL_FALSE; + } + } + + return SDL_FALSE; +} + +static void +pointer_handle_button_common(struct SDL_WaylandInput *input, uint32_t serial, + uint32_t time, uint32_t button, uint32_t state_w) +{ + SDL_WindowData *window = input->pointer_focus; + enum wl_pointer_button_state state = state_w; + uint32_t sdl_button; + + if (input->pointer_focus) { + switch (button) { + case BTN_LEFT: + sdl_button = SDL_BUTTON_LEFT; + if (ProcessHitTest(input, serial)) { + return; /* don't pass this event on to app. */ + } + break; + case BTN_MIDDLE: + sdl_button = SDL_BUTTON_MIDDLE; + break; + case BTN_RIGHT: + sdl_button = SDL_BUTTON_RIGHT; + break; + case BTN_SIDE: + sdl_button = SDL_BUTTON_X1; + break; + case BTN_EXTRA: + sdl_button = SDL_BUTTON_X2; + break; + default: + return; + } + + Wayland_data_device_set_serial(input->data_device, serial); + + SDL_SendMouseButton(window->sdlwindow, 0, + state ? SDL_PRESSED : SDL_RELEASED, sdl_button); + } +} + +static void +pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, + uint32_t time, uint32_t button, uint32_t state_w) +{ + struct SDL_WaylandInput *input = data; + + pointer_handle_button_common(input, serial, time, button, state_w); +} + +static void +pointer_handle_axis_common(struct SDL_WaylandInput *input, + uint32_t time, uint32_t axis, wl_fixed_t value) +{ + SDL_WindowData *window = input->pointer_focus; + enum wl_pointer_axis a = axis; + float x, y; + + if (input->pointer_focus) { + switch (a) { + case WL_POINTER_AXIS_VERTICAL_SCROLL: + x = 0; + y = 0 - (float)wl_fixed_to_double(value); + break; + case WL_POINTER_AXIS_HORIZONTAL_SCROLL: + x = 0 - (float)wl_fixed_to_double(value); + y = 0; + break; + default: + return; + } + + SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL); + } +} + +static void +pointer_handle_axis(void *data, struct wl_pointer *pointer, + uint32_t time, uint32_t axis, wl_fixed_t value) +{ + struct SDL_WaylandInput *input = data; + + pointer_handle_axis_common(input, time, axis, value); +} + +static const struct wl_pointer_listener pointer_listener = { + pointer_handle_enter, + pointer_handle_leave, + pointer_handle_motion, + pointer_handle_button, + pointer_handle_axis, + NULL, /* frame */ + NULL, /* axis_source */ + NULL, /* axis_stop */ + NULL, /* axis_discrete */ +}; + +static void +touch_handler_down(void *data, struct wl_touch *touch, unsigned int serial, + unsigned int timestamp, struct wl_surface *surface, + int id, wl_fixed_t fx, wl_fixed_t fy) +{ + float x, y; + SDL_WindowData* window; + + window = (SDL_WindowData *)wl_surface_get_user_data(surface); + + x = wl_fixed_to_double(fx) / window->sdlwindow->w; + y = wl_fixed_to_double(fy) / window->sdlwindow->h; + + touch_add(id, x, y, surface); + SDL_SendTouch(1, (SDL_FingerID)id, SDL_TRUE, x, y, 1.0f); +} + +static void +touch_handler_up(void *data, struct wl_touch *touch, unsigned int serial, + unsigned int timestamp, int id) +{ + float x = 0, y = 0; + + touch_del(id, &x, &y); + SDL_SendTouch(1, (SDL_FingerID)id, SDL_FALSE, x, y, 0.0f); +} + +static void +touch_handler_motion(void *data, struct wl_touch *touch, unsigned int timestamp, + int id, wl_fixed_t fx, wl_fixed_t fy) +{ + float x, y; + SDL_WindowData* window; + + window = (SDL_WindowData *)wl_surface_get_user_data(touch_surface(id)); + + x = wl_fixed_to_double(fx) / window->sdlwindow->w; + y = wl_fixed_to_double(fy) / window->sdlwindow->h; + + touch_update(id, x, y); + SDL_SendTouchMotion(1, (SDL_FingerID)id, x, y, 1.0f); +} + +static void +touch_handler_frame(void *data, struct wl_touch *touch) +{ + +} + +static void +touch_handler_cancel(void *data, struct wl_touch *touch) +{ + +} + +static const struct wl_touch_listener touch_listener = { + touch_handler_down, + touch_handler_up, + touch_handler_motion, + touch_handler_frame, + touch_handler_cancel, + NULL, /* shape */ + NULL, /* orientation */ +}; + +static void +keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, + uint32_t format, int fd, uint32_t size) +{ + struct SDL_WaylandInput *input = data; + char *map_str; + + if (!data) { + close(fd); + return; + } + + if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { + close(fd); + return; + } + + map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); + if (map_str == MAP_FAILED) { + close(fd); + return; + } + + input->xkb.keymap = WAYLAND_xkb_keymap_new_from_string(input->display->xkb_context, + map_str, + XKB_KEYMAP_FORMAT_TEXT_V1, + 0); + munmap(map_str, size); + close(fd); + + if (!input->xkb.keymap) { + fprintf(stderr, "failed to compile keymap\n"); + return; + } + + input->xkb.state = WAYLAND_xkb_state_new(input->xkb.keymap); + if (!input->xkb.state) { + fprintf(stderr, "failed to create XKB state\n"); + WAYLAND_xkb_keymap_unref(input->xkb.keymap); + input->xkb.keymap = NULL; + return; + } +} + +static void +keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, + uint32_t serial, struct wl_surface *surface, + struct wl_array *keys) +{ + struct SDL_WaylandInput *input = data; + SDL_WindowData *window; + + if (!surface) { + /* enter event for a window we've just destroyed */ + return; + } + + window = wl_surface_get_user_data(surface); + + if (window) { + input->keyboard_focus = window; + window->keyboard_device = input; + SDL_SetKeyboardFocus(window->sdlwindow); + } +} + +static void +keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, + uint32_t serial, struct wl_surface *surface) +{ + SDL_SetKeyboardFocus(NULL); +} + +static void +keyboard_handle_key(void *data, struct wl_keyboard *keyboard, + uint32_t serial, uint32_t time, uint32_t key, + uint32_t state_w) +{ + struct SDL_WaylandInput *input = data; + SDL_WindowData *window = input->keyboard_focus; + enum wl_keyboard_key_state state = state_w; + const xkb_keysym_t *syms; + uint32_t scancode; + char text[8]; + int size; + + if (key < SDL_arraysize(xfree86_scancode_table2)) { + scancode = xfree86_scancode_table2[key]; + + // TODO when do we get WL_KEYBOARD_KEY_STATE_REPEAT? + if (scancode != SDL_SCANCODE_UNKNOWN) + SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ? + SDL_PRESSED : SDL_RELEASED, scancode); + } + + if (!window || window->keyboard_device != input || !input->xkb.state) + return; + + // TODO can this happen? + if (WAYLAND_xkb_state_key_get_syms(input->xkb.state, key + 8, &syms) != 1) + return; + + if (state) { + size = WAYLAND_xkb_keysym_to_utf8(syms[0], text, sizeof text); + + if (size > 0) { + text[size] = 0; + + Wayland_data_device_set_serial(input->data_device, serial); + + SDL_SendKeyboardText(text); + } + } +} + +static void +keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, + uint32_t serial, uint32_t mods_depressed, + uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) +{ + struct SDL_WaylandInput *input = data; + + WAYLAND_xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched, + mods_locked, 0, 0, group); +} + +static const struct wl_keyboard_listener keyboard_listener = { + keyboard_handle_keymap, + keyboard_handle_enter, + keyboard_handle_leave, + keyboard_handle_key, + keyboard_handle_modifiers, + NULL, /* repeat_info */ +}; + +static void +seat_handle_capabilities(void *data, struct wl_seat *seat, + enum wl_seat_capability caps) +{ + struct SDL_WaylandInput *input = data; + + if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) { + input->pointer = wl_seat_get_pointer(seat); + input->display->pointer = input->pointer; + wl_pointer_set_user_data(input->pointer, input); + wl_pointer_add_listener(input->pointer, &pointer_listener, + input); + } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) { + wl_pointer_destroy(input->pointer); + input->pointer = NULL; + input->display->pointer = NULL; + } + + if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) { + SDL_AddTouch(1, "wayland_touch"); + input->touch = wl_seat_get_touch(seat); + wl_touch_set_user_data(input->touch, input); + wl_touch_add_listener(input->touch, &touch_listener, + input); + } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) { + SDL_DelTouch(1); + wl_touch_destroy(input->touch); + input->touch = NULL; + } + + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) { + input->keyboard = wl_seat_get_keyboard(seat); + wl_keyboard_set_user_data(input->keyboard, input); + wl_keyboard_add_listener(input->keyboard, &keyboard_listener, + input); + } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) { + wl_keyboard_destroy(input->keyboard); + input->keyboard = NULL; + } +} + +static const struct wl_seat_listener seat_listener = { + seat_handle_capabilities, + NULL, /* name */ +}; + +static void +data_source_handle_target(void *data, struct wl_data_source *wl_data_source, + const char *mime_type) +{ +} + +static void +data_source_handle_send(void *data, struct wl_data_source *wl_data_source, + const char *mime_type, int32_t fd) +{ + Wayland_data_source_send((SDL_WaylandDataSource *)data, mime_type, fd); +} + +static void +data_source_handle_cancelled(void *data, struct wl_data_source *wl_data_source) +{ + Wayland_data_source_destroy(data); +} + +static void +data_source_handle_dnd_drop_performed(void *data, struct wl_data_source *wl_data_source) +{ +} + +static void +data_source_handle_dnd_finished(void *data, struct wl_data_source *wl_data_source) +{ +} + +static void +data_source_handle_action(void *data, struct wl_data_source *wl_data_source, + uint32_t dnd_action) +{ +} + +static const struct wl_data_source_listener data_source_listener = { + data_source_handle_target, + data_source_handle_send, + data_source_handle_cancelled, + data_source_handle_dnd_drop_performed, // Version 3 + data_source_handle_dnd_finished, // Version 3 + data_source_handle_action, // Version 3 +}; + +SDL_WaylandDataSource* +Wayland_data_source_create(_THIS) +{ + SDL_WaylandDataSource *data_source = NULL; + SDL_VideoData *driver_data = NULL; + struct wl_data_source *id = NULL; + + if (_this == NULL || _this->driverdata == NULL) { + SDL_SetError("Video driver uninitialized"); + } else { + driver_data = _this->driverdata; + + if (driver_data->data_device_manager != NULL) { + id = wl_data_device_manager_create_data_source( + driver_data->data_device_manager); + } + + if (id == NULL) { + SDL_SetError("Wayland unable to create data source"); + } else { + data_source = SDL_calloc(1, sizeof *data_source); + if (data_source == NULL) { + SDL_OutOfMemory(); + wl_data_source_destroy(id); + } else { + WAYLAND_wl_list_init(&(data_source->mimes)); + data_source->source = id; + wl_data_source_set_user_data(id, data_source); + wl_data_source_add_listener(id, &data_source_listener, + data_source); + } + } + } + return data_source; +} + +static void +data_offer_handle_offer(void *data, struct wl_data_offer *wl_data_offer, + const char *mime_type) +{ + SDL_WaylandDataOffer *offer = data; + Wayland_data_offer_add_mime(offer, mime_type); +} + +static void +data_offer_handle_source_actions(void *data, struct wl_data_offer *wl_data_offer, + uint32_t source_actions) +{ +} + +static void +data_offer_handle_actions(void *data, struct wl_data_offer *wl_data_offer, + uint32_t dnd_action) +{ +} + +static const struct wl_data_offer_listener data_offer_listener = { + data_offer_handle_offer, + data_offer_handle_source_actions, // Version 3 + data_offer_handle_actions, // Version 3 +}; + +static void +data_device_handle_data_offer(void *data, struct wl_data_device *wl_data_device, + struct wl_data_offer *id) +{ + SDL_WaylandDataOffer *data_offer = NULL; + + data_offer = SDL_calloc(1, sizeof *data_offer); + if (data_offer == NULL) { + SDL_OutOfMemory(); + } else { + data_offer->offer = id; + data_offer->data_device = data; + WAYLAND_wl_list_init(&(data_offer->mimes)); + wl_data_offer_set_user_data(id, data_offer); + wl_data_offer_add_listener(id, &data_offer_listener, data_offer); + } +} + +static void +data_device_handle_enter(void *data, struct wl_data_device *wl_data_device, + uint32_t serial, struct wl_surface *surface, + wl_fixed_t x, wl_fixed_t y, struct wl_data_offer *id) +{ + SDL_WaylandDataDevice *data_device = data; + SDL_bool has_mime = SDL_FALSE; + uint32_t dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE; + + data_device->drag_serial = serial; + + if (id != NULL) { + data_device->drag_offer = wl_data_offer_get_user_data(id); + + /* TODO: SDL Support more mime types */ + has_mime = Wayland_data_offer_has_mime( + data_device->drag_offer, FILE_MIME); + + /* If drag_mime is NULL this will decline the offer */ + wl_data_offer_accept(id, serial, + (has_mime == SDL_TRUE) ? FILE_MIME : NULL); + + /* SDL only supports "copy" style drag and drop */ + if (has_mime == SDL_TRUE) { + dnd_action = WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY; + } + wl_data_offer_set_actions(data_device->drag_offer->offer, + dnd_action, dnd_action); + } +} + +static void +data_device_handle_leave(void *data, struct wl_data_device *wl_data_device) +{ + SDL_WaylandDataDevice *data_device = data; + SDL_WaylandDataOffer *offer = NULL; + + if (data_device->selection_offer != NULL) { + data_device->selection_offer = NULL; + Wayland_data_offer_destroy(offer); + } +} + +static void +data_device_handle_motion(void *data, struct wl_data_device *wl_data_device, + uint32_t time, wl_fixed_t x, wl_fixed_t y) +{ +} + +static void +data_device_handle_drop(void *data, struct wl_data_device *wl_data_device) +{ + SDL_WaylandDataDevice *data_device = data; + void *buffer = NULL; + size_t length = 0; + + const char *current_uri = NULL; + const char *last_char = NULL; + char *current_char = NULL; + + if (data_device->drag_offer != NULL) { + /* TODO: SDL Support more mime types */ + buffer = Wayland_data_offer_receive(data_device->drag_offer, + &length, FILE_MIME, SDL_FALSE); + + /* uri-list */ + current_uri = (const char *)buffer; + last_char = (const char *)buffer + length; + for (current_char = buffer; current_char < last_char; ++current_char) { + if (*current_char == '\n' || *current_char == 0) { + if (*current_uri != 0 && *current_uri != '#') { + *current_char = 0; + SDL_SendDropFile(NULL, current_uri); + } + current_uri = (const char *)current_char + 1; + } + } + + SDL_free(buffer); + } +} + +static void +data_device_handle_selection(void *data, struct wl_data_device *wl_data_device, + struct wl_data_offer *id) +{ + SDL_WaylandDataDevice *data_device = data; + SDL_WaylandDataOffer *offer = NULL; + + if (id != NULL) { + offer = wl_data_offer_get_user_data(id); + } + + if (data_device->selection_offer != offer) { + Wayland_data_offer_destroy(data_device->selection_offer); + data_device->selection_offer = offer; + } + + SDL_SendClipboardUpdate(); +} + +static const struct wl_data_device_listener data_device_listener = { + data_device_handle_data_offer, + data_device_handle_enter, + data_device_handle_leave, + data_device_handle_motion, + data_device_handle_drop, + data_device_handle_selection +}; + +void +Wayland_display_add_input(SDL_VideoData *d, uint32_t id) +{ + struct SDL_WaylandInput *input; + SDL_WaylandDataDevice *data_device = NULL; + + input = SDL_calloc(1, sizeof *input); + if (input == NULL) + return; + + input->display = d; + input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1); + input->sx_w = wl_fixed_from_int(0); + input->sy_w = wl_fixed_from_int(0); + d->input = input; + + if (d->data_device_manager != NULL) { + data_device = SDL_calloc(1, sizeof *data_device); + if (data_device == NULL) { + return; + } + + data_device->data_device = wl_data_device_manager_get_data_device( + d->data_device_manager, input->seat + ); + data_device->video_data = d; + + if (data_device->data_device == NULL) { + SDL_free(data_device); + } else { + wl_data_device_set_user_data(data_device->data_device, data_device); + wl_data_device_add_listener(data_device->data_device, + &data_device_listener, data_device); + input->data_device = data_device; + } + } + + wl_seat_add_listener(input->seat, &seat_listener, input); + wl_seat_set_user_data(input->seat, input); + + WAYLAND_wl_display_flush(d->display); +} + +void Wayland_display_destroy_input(SDL_VideoData *d) +{ + struct SDL_WaylandInput *input = d->input; + + if (!input) + return; + + if (input->data_device != NULL) { + Wayland_data_device_clear_selection(input->data_device); + if (input->data_device->selection_offer != NULL) { + Wayland_data_offer_destroy(input->data_device->selection_offer); + } + if (input->data_device->drag_offer != NULL) { + Wayland_data_offer_destroy(input->data_device->drag_offer); + } + if (input->data_device->data_device != NULL) { + wl_data_device_release(input->data_device->data_device); + } + SDL_free(input->data_device); + } + + if (input->keyboard) + wl_keyboard_destroy(input->keyboard); + + if (input->pointer) + wl_pointer_destroy(input->pointer); + + if (input->touch) { + SDL_DelTouch(1); + wl_touch_destroy(input->touch); + } + + if (input->seat) + wl_seat_destroy(input->seat); + + if (input->xkb.state) + WAYLAND_xkb_state_unref(input->xkb.state); + + if (input->xkb.keymap) + WAYLAND_xkb_keymap_unref(input->xkb.keymap); + + SDL_free(input); + d->input = NULL; +} + +SDL_WaylandDataDevice* Wayland_get_data_device(struct SDL_WaylandInput *input) +{ + if (input == NULL) { + return NULL; + } + + return input->data_device; +} + +/* !!! FIXME: just merge these into display_handle_global(). */ +void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id) +{ + d->relative_pointer_manager = + wl_registry_bind(d->registry, id, + &zwp_relative_pointer_manager_v1_interface, 1); +} + +void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d) +{ + if (d->relative_pointer_manager) + zwp_relative_pointer_manager_v1_destroy(d->relative_pointer_manager); +} + +void Wayland_display_add_pointer_constraints(SDL_VideoData *d, uint32_t id) +{ + d->pointer_constraints = + wl_registry_bind(d->registry, id, + &zwp_pointer_constraints_v1_interface, 1); +} + +void Wayland_display_destroy_pointer_constraints(SDL_VideoData *d) +{ + if (d->pointer_constraints) + zwp_pointer_constraints_v1_destroy(d->pointer_constraints); +} + +static void +relative_pointer_handle_relative_motion(void *data, + struct zwp_relative_pointer_v1 *pointer, + uint32_t time_hi, + uint32_t time_lo, + wl_fixed_t dx_w, + wl_fixed_t dy_w, + wl_fixed_t dx_unaccel_w, + wl_fixed_t dy_unaccel_w) +{ + struct SDL_WaylandInput *input = data; + SDL_VideoData *d = input->display; + SDL_WindowData *window = input->pointer_focus; + double dx_unaccel; + double dy_unaccel; + double dx; + double dy; + + dx_unaccel = wl_fixed_to_double(dx_unaccel_w); + dy_unaccel = wl_fixed_to_double(dy_unaccel_w); + + /* Add left over fraction from last event. */ + dx_unaccel += input->dx_frac; + dy_unaccel += input->dy_frac; + + input->dx_frac = modf(dx_unaccel, &dx); + input->dy_frac = modf(dy_unaccel, &dy); + + if (input->pointer_focus && d->relative_mouse_mode) { + SDL_SendMouseMotion(window->sdlwindow, 0, 1, (int)dx, (int)dy); + } +} + +static const struct zwp_relative_pointer_v1_listener relative_pointer_listener = { + relative_pointer_handle_relative_motion, +}; + +static void +locked_pointer_locked(void *data, + struct zwp_locked_pointer_v1 *locked_pointer) +{ +} + +static void +locked_pointer_unlocked(void *data, + struct zwp_locked_pointer_v1 *locked_pointer) +{ +} + +static const struct zwp_locked_pointer_v1_listener locked_pointer_listener = { + locked_pointer_locked, + locked_pointer_unlocked, +}; + +static void +lock_pointer_to_window(SDL_Window *window, + struct SDL_WaylandInput *input) +{ + SDL_WindowData *w = window->driverdata; + SDL_VideoData *d = input->display; + struct zwp_locked_pointer_v1 *locked_pointer; + + if (w->locked_pointer) + return; + + locked_pointer = + zwp_pointer_constraints_v1_lock_pointer(d->pointer_constraints, + w->surface, + input->pointer, + NULL, + ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); + zwp_locked_pointer_v1_add_listener(locked_pointer, + &locked_pointer_listener, + window); + + w->locked_pointer = locked_pointer; +} + +int Wayland_input_lock_pointer(struct SDL_WaylandInput *input) +{ + SDL_VideoDevice *vd = SDL_GetVideoDevice(); + SDL_VideoData *d = input->display; + SDL_Window *window; + struct zwp_relative_pointer_v1 *relative_pointer; + + if (!d->relative_pointer_manager) + return -1; + + if (!d->pointer_constraints) + return -1; + + if (!input->relative_pointer) { + relative_pointer = + zwp_relative_pointer_manager_v1_get_relative_pointer( + d->relative_pointer_manager, + input->pointer); + zwp_relative_pointer_v1_add_listener(relative_pointer, + &relative_pointer_listener, + input); + input->relative_pointer = relative_pointer; + } + + for (window = vd->windows; window; window = window->next) + lock_pointer_to_window(window, input); + + d->relative_mouse_mode = 1; + + return 0; +} + +int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input) +{ + SDL_VideoDevice *vd = SDL_GetVideoDevice(); + SDL_VideoData *d = input->display; + SDL_Window *window; + SDL_WindowData *w; + + for (window = vd->windows; window; window = window->next) { + w = window->driverdata; + if (w->locked_pointer) + zwp_locked_pointer_v1_destroy(w->locked_pointer); + w->locked_pointer = NULL; + } + + zwp_relative_pointer_v1_destroy(input->relative_pointer); + input->relative_pointer = NULL; + + d->relative_mouse_mode = 0; + + return 0; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandevents_c.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandevents_c.h new file mode 100644 index 0000000..1c5ffe5 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandevents_c.h @@ -0,0 +1,51 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#ifndef SDL_waylandevents_h_ +#define SDL_waylandevents_h_ + +#include "SDL_waylandvideo.h" +#include "SDL_waylandwindow.h" +#include "SDL_waylanddatamanager.h" + +struct SDL_WaylandInput; + +extern void Wayland_PumpEvents(_THIS); + +extern void Wayland_display_add_input(SDL_VideoData *d, uint32_t id); +extern void Wayland_display_destroy_input(SDL_VideoData *d); + +extern SDL_WaylandDataDevice* Wayland_get_data_device(struct SDL_WaylandInput *input); + +extern void Wayland_display_add_pointer_constraints(SDL_VideoData *d, uint32_t id); +extern void Wayland_display_destroy_pointer_constraints(SDL_VideoData *d); + +extern int Wayland_input_lock_pointer(struct SDL_WaylandInput *input); +extern int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input); + +extern void Wayland_display_add_relative_pointer_manager(SDL_VideoData *d, uint32_t id); +extern void Wayland_display_destroy_relative_pointer_manager(SDL_VideoData *d); + +#endif /* SDL_waylandevents_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandmouse.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandmouse.c new file mode 100644 index 0000000..c77b53e --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandmouse.c @@ -0,0 +1,396 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +#include <sys/types.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <limits.h> + +#include "../SDL_sysvideo.h" + +#include "SDL_mouse.h" +#include "../../events/SDL_mouse_c.h" +#include "SDL_waylandvideo.h" +#include "SDL_waylandevents_c.h" + +#include "SDL_waylanddyn.h" +#include "wayland-cursor.h" + +#include "SDL_assert.h" + + +typedef struct { + struct wl_buffer *buffer; + struct wl_surface *surface; + + int hot_x, hot_y; + int w, h; + + /* Either a preloaded cursor, or one we created ourselves */ + struct wl_cursor *cursor; + void *shm_data; +} Wayland_CursorData; + +static int +wayland_create_tmp_file(off_t size) +{ + static const char template[] = "/sdl-shared-XXXXXX"; + char *xdg_path; + char tmp_path[PATH_MAX]; + int fd; + + xdg_path = SDL_getenv("XDG_RUNTIME_DIR"); + if (!xdg_path) { + return -1; + } + + SDL_strlcpy(tmp_path, xdg_path, PATH_MAX); + SDL_strlcat(tmp_path, template, PATH_MAX); + + fd = mkostemp(tmp_path, O_CLOEXEC); + if (fd < 0) + return -1; + + if (ftruncate(fd, size) < 0) { + close(fd); + return -1; + } + + return fd; +} + +static void +mouse_buffer_release(void *data, struct wl_buffer *buffer) +{ +} + +static const struct wl_buffer_listener mouse_buffer_listener = { + mouse_buffer_release +}; + +static int +create_buffer_from_shm(Wayland_CursorData *d, + int width, + int height, + uint32_t format) +{ + SDL_VideoDevice *vd = SDL_GetVideoDevice(); + SDL_VideoData *data = (SDL_VideoData *) vd->driverdata; + struct wl_shm_pool *shm_pool; + + int stride = width * 4; + int size = stride * height; + + int shm_fd; + + shm_fd = wayland_create_tmp_file(size); + if (shm_fd < 0) + { + return SDL_SetError("Creating mouse cursor buffer failed."); + } + + d->shm_data = mmap(NULL, + size, + PROT_READ | PROT_WRITE, + MAP_SHARED, + shm_fd, + 0); + if (d->shm_data == MAP_FAILED) { + d->shm_data = NULL; + close (shm_fd); + return SDL_SetError("mmap() failed."); + } + + shm_pool = wl_shm_create_pool(data->shm, shm_fd, size); + d->buffer = wl_shm_pool_create_buffer(shm_pool, + 0, + width, + height, + stride, + format); + wl_buffer_add_listener(d->buffer, + &mouse_buffer_listener, + d); + + wl_shm_pool_destroy (shm_pool); + close (shm_fd); + + return 0; +} + +static SDL_Cursor * +Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) +{ + SDL_Cursor *cursor; + + cursor = calloc(1, sizeof (*cursor)); + if (cursor) { + SDL_VideoDevice *vd = SDL_GetVideoDevice (); + SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata; + Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData)); + if (!data) { + SDL_OutOfMemory(); + free(cursor); + return NULL; + } + cursor->driverdata = (void *) data; + + /* Assume ARGB8888 */ + SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); + SDL_assert(surface->pitch == surface->w * 4); + + /* Allocate shared memory buffer for this cursor */ + if (create_buffer_from_shm (data, + surface->w, + surface->h, + WL_SHM_FORMAT_ARGB8888) < 0) + { + free (cursor->driverdata); + free (cursor); + return NULL; + } + + SDL_memcpy(data->shm_data, + surface->pixels, + surface->h * surface->pitch); + + data->surface = wl_compositor_create_surface(wd->compositor); + wl_surface_set_user_data(data->surface, NULL); + + data->hot_x = hot_x; + data->hot_y = hot_y; + data->w = surface->w; + data->h = surface->h; + } else { + SDL_OutOfMemory(); + } + + return cursor; +} + +static SDL_Cursor * +CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor) +{ + SDL_Cursor *cursor; + + cursor = calloc(1, sizeof (*cursor)); + if (cursor) { + Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData)); + if (!data) { + SDL_OutOfMemory(); + free(cursor); + return NULL; + } + cursor->driverdata = (void *) data; + + data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]); + data->surface = wl_compositor_create_surface(d->compositor); + wl_surface_set_user_data(data->surface, NULL); + data->hot_x = wlcursor->images[0]->hotspot_x; + data->hot_y = wlcursor->images[0]->hotspot_y; + data->w = wlcursor->images[0]->width; + data->h = wlcursor->images[0]->height; + data->cursor= wlcursor; + } else { + SDL_OutOfMemory (); + } + + return cursor; +} + +static SDL_Cursor * +Wayland_CreateDefaultCursor() +{ + SDL_VideoDevice *device = SDL_GetVideoDevice(); + SDL_VideoData *data = device->driverdata; + + return CreateCursorFromWlCursor (data, + WAYLAND_wl_cursor_theme_get_cursor(data->cursor_theme, + "left_ptr")); +} + +static SDL_Cursor * +Wayland_CreateSystemCursor(SDL_SystemCursor id) +{ + SDL_VideoDevice *vd = SDL_GetVideoDevice(); + SDL_VideoData *d = vd->driverdata; + + struct wl_cursor *cursor = NULL; + + switch(id) + { + default: + SDL_assert(0); + return NULL; + case SDL_SYSTEM_CURSOR_ARROW: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr"); + break; + case SDL_SYSTEM_CURSOR_IBEAM: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm"); + break; + case SDL_SYSTEM_CURSOR_WAIT: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "watch"); + break; + case SDL_SYSTEM_CURSOR_CROSSHAIR: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + case SDL_SYSTEM_CURSOR_WAITARROW: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "watch"); + break; + case SDL_SYSTEM_CURSOR_SIZENWSE: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + case SDL_SYSTEM_CURSOR_SIZENESW: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + case SDL_SYSTEM_CURSOR_SIZEWE: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + case SDL_SYSTEM_CURSOR_SIZENS: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + case SDL_SYSTEM_CURSOR_SIZEALL: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + case SDL_SYSTEM_CURSOR_NO: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm"); + break; + case SDL_SYSTEM_CURSOR_HAND: + cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1"); + break; + } + + return CreateCursorFromWlCursor(d, cursor); +} + +static void +Wayland_FreeCursor(SDL_Cursor *cursor) +{ + Wayland_CursorData *d; + + if (!cursor) + return; + + d = cursor->driverdata; + + /* Probably not a cursor we own */ + if (!d) + return; + + if (d->buffer && !d->cursor) + wl_buffer_destroy(d->buffer); + + if (d->surface) + wl_surface_destroy(d->surface); + + /* Not sure what's meant to happen to shm_data */ + free (cursor->driverdata); + SDL_free(cursor); +} + +static int +Wayland_ShowCursor(SDL_Cursor *cursor) +{ + SDL_VideoDevice *vd = SDL_GetVideoDevice(); + SDL_VideoData *d = vd->driverdata; + + struct wl_pointer *pointer = d->pointer; + + if (!pointer) + return -1; + + if (cursor) + { + Wayland_CursorData *data = cursor->driverdata; + + wl_pointer_set_cursor (pointer, 0, + data->surface, + data->hot_x, + data->hot_y); + wl_surface_attach(data->surface, data->buffer, 0, 0); + wl_surface_damage(data->surface, 0, 0, data->w, data->h); + wl_surface_commit(data->surface); + } + else + { + wl_pointer_set_cursor (pointer, 0, + NULL, + 0, + 0); + } + + return 0; +} + +static void +Wayland_WarpMouse(SDL_Window *window, int x, int y) +{ + SDL_Unsupported(); +} + +static int +Wayland_WarpMouseGlobal(int x, int y) +{ + return SDL_Unsupported(); +} + +static int +Wayland_SetRelativeMouseMode(SDL_bool enabled) +{ + SDL_VideoDevice *vd = SDL_GetVideoDevice(); + SDL_VideoData *data = (SDL_VideoData *) vd->driverdata; + + if (enabled) + return Wayland_input_lock_pointer(data->input); + else + return Wayland_input_unlock_pointer(data->input); +} + +void +Wayland_InitMouse(void) +{ + SDL_Mouse *mouse = SDL_GetMouse(); + + mouse->CreateCursor = Wayland_CreateCursor; + mouse->CreateSystemCursor = Wayland_CreateSystemCursor; + mouse->ShowCursor = Wayland_ShowCursor; + mouse->FreeCursor = Wayland_FreeCursor; + mouse->WarpMouse = Wayland_WarpMouse; + mouse->WarpMouseGlobal = Wayland_WarpMouseGlobal; + mouse->SetRelativeMouseMode = Wayland_SetRelativeMouseMode; + + SDL_SetDefaultCursor(Wayland_CreateDefaultCursor()); +} + +void +Wayland_FiniMouse(void) +{ + /* This effectively assumes that nobody else + * touches SDL_Mouse which is effectively + * a singleton */ +} +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandmouse.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandmouse.h new file mode 100644 index 0000000..2c50e5f --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandmouse.h @@ -0,0 +1,31 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" +#include "SDL_mouse.h" +#include "SDL_waylandvideo.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +extern void Wayland_InitMouse(void); +extern void Wayland_FiniMouse(void); + +#endif diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandopengles.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandopengles.c new file mode 100644 index 0000000..9c0b845 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandopengles.c @@ -0,0 +1,93 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL + +#include "SDL_waylandvideo.h" +#include "SDL_waylandopengles.h" +#include "SDL_waylandwindow.h" +#include "SDL_waylandevents_c.h" +#include "SDL_waylanddyn.h" + +/* EGL implementation of SDL OpenGL ES support */ + +int +Wayland_GLES_LoadLibrary(_THIS, const char *path) { + int ret; + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; + + ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, 0); + + Wayland_PumpEvents(_this); + WAYLAND_wl_display_flush(data->display); + + return ret; +} + + +SDL_GLContext +Wayland_GLES_CreateContext(_THIS, SDL_Window * window) +{ + SDL_GLContext context; + context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + + return context; +} + +int +Wayland_GLES_SwapWindow(_THIS, SDL_Window *window) +{ + if (SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface) < 0) { + return -1; + } + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + return 0; +} + +int +Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) +{ + int ret; + + if (window && context) { + ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); + } + else { + ret = SDL_EGL_MakeCurrent(_this, NULL, NULL); + } + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); + + return ret; +} + +void +Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context) +{ + SDL_EGL_DeleteContext(_this, context); + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandopengles.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandopengles.h new file mode 100644 index 0000000..58d7f9b --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandopengles.h @@ -0,0 +1,49 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ +#include "../../SDL_internal.h" + +#ifndef SDL_waylandopengles_h_ +#define SDL_waylandopengles_h_ + +#include "../SDL_sysvideo.h" +#include "../SDL_egl_c.h" + +typedef struct SDL_PrivateGLESData +{ + int dummy; +} SDL_PrivateGLESData; + +/* OpenGLES functions */ +#define Wayland_GLES_GetAttribute SDL_EGL_GetAttribute +#define Wayland_GLES_GetProcAddress SDL_EGL_GetProcAddress +#define Wayland_GLES_UnloadLibrary SDL_EGL_UnloadLibrary +#define Wayland_GLES_SetSwapInterval SDL_EGL_SetSwapInterval +#define Wayland_GLES_GetSwapInterval SDL_EGL_GetSwapInterval + +extern int Wayland_GLES_LoadLibrary(_THIS, const char *path); +extern SDL_GLContext Wayland_GLES_CreateContext(_THIS, SDL_Window * window); +extern int Wayland_GLES_SwapWindow(_THIS, SDL_Window * window); +extern int Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context); +extern void Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context); + +#endif /* SDL_waylandopengles_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandsym.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandsym.h new file mode 100644 index 0000000..77783df --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandsym.h @@ -0,0 +1,127 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* *INDENT-OFF* */ + +#ifndef SDL_WAYLAND_MODULE +#define SDL_WAYLAND_MODULE(modname) +#endif + +#ifndef SDL_WAYLAND_SYM +#define SDL_WAYLAND_SYM(rc,fn,params) +#endif + +#ifndef SDL_WAYLAND_INTERFACE +#define SDL_WAYLAND_INTERFACE(iface) +#endif + +SDL_WAYLAND_MODULE(WAYLAND_CLIENT) +SDL_WAYLAND_SYM(void, wl_proxy_marshal, (struct wl_proxy *, uint32_t, ...)) +SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_create, (struct wl_proxy *, const struct wl_interface *)) +SDL_WAYLAND_SYM(void, wl_proxy_destroy, (struct wl_proxy *)) +SDL_WAYLAND_SYM(int, wl_proxy_add_listener, (struct wl_proxy *, void (**)(void), void *)) +SDL_WAYLAND_SYM(void, wl_proxy_set_user_data, (struct wl_proxy *, void *)) +SDL_WAYLAND_SYM(void *, wl_proxy_get_user_data, (struct wl_proxy *)) +SDL_WAYLAND_SYM(uint32_t, wl_proxy_get_id, (struct wl_proxy *)) +SDL_WAYLAND_SYM(const char *, wl_proxy_get_class, (struct wl_proxy *)) +SDL_WAYLAND_SYM(void, wl_proxy_set_queue, (struct wl_proxy *, struct wl_event_queue *)) +SDL_WAYLAND_SYM(struct wl_display *, wl_display_connect, (const char *)) +SDL_WAYLAND_SYM(struct wl_display *, wl_display_connect_to_fd, (int)) +SDL_WAYLAND_SYM(void, wl_display_disconnect, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_get_fd, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch_queue, (struct wl_display *, struct wl_event_queue *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch_queue_pending, (struct wl_display *, struct wl_event_queue *)) +SDL_WAYLAND_SYM(int, wl_display_dispatch_pending, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_get_error, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_flush, (struct wl_display *)) +SDL_WAYLAND_SYM(int, wl_display_roundtrip, (struct wl_display *)) +SDL_WAYLAND_SYM(struct wl_event_queue *, wl_display_create_queue, (struct wl_display *)) +SDL_WAYLAND_SYM(void, wl_log_set_handler_client, (wl_log_func_t)) +SDL_WAYLAND_SYM(void, wl_list_init, (struct wl_list *)) +SDL_WAYLAND_SYM(void, wl_list_insert, (struct wl_list *, struct wl_list *) ) +SDL_WAYLAND_SYM(void, wl_list_remove, (struct wl_list *)) +SDL_WAYLAND_SYM(int, wl_list_length, (const struct wl_list *)) +SDL_WAYLAND_SYM(int, wl_list_empty, (const struct wl_list *)) +SDL_WAYLAND_SYM(void, wl_list_insert_list, (struct wl_list *, struct wl_list *)) + +/* These functions are available in Wayland >= 1.4 */ +SDL_WAYLAND_MODULE(WAYLAND_CLIENT_1_4) +SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_marshal_constructor, (struct wl_proxy *, uint32_t opcode, const struct wl_interface *interface, ...)) + +SDL_WAYLAND_MODULE(WAYLAND_CLIENT_1_10) +SDL_WAYLAND_SYM(struct wl_proxy *, wl_proxy_marshal_constructor_versioned, (struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, ...)) + +SDL_WAYLAND_INTERFACE(wl_seat_interface) +SDL_WAYLAND_INTERFACE(wl_surface_interface) +SDL_WAYLAND_INTERFACE(wl_shm_pool_interface) +SDL_WAYLAND_INTERFACE(wl_buffer_interface) +SDL_WAYLAND_INTERFACE(wl_registry_interface) +SDL_WAYLAND_INTERFACE(wl_shell_surface_interface) +SDL_WAYLAND_INTERFACE(wl_region_interface) +SDL_WAYLAND_INTERFACE(wl_pointer_interface) +SDL_WAYLAND_INTERFACE(wl_keyboard_interface) +SDL_WAYLAND_INTERFACE(wl_compositor_interface) +SDL_WAYLAND_INTERFACE(wl_output_interface) +SDL_WAYLAND_INTERFACE(wl_shell_interface) +SDL_WAYLAND_INTERFACE(wl_shm_interface) +SDL_WAYLAND_INTERFACE(wl_data_device_interface) +SDL_WAYLAND_INTERFACE(wl_data_source_interface) +SDL_WAYLAND_INTERFACE(wl_data_offer_interface) +SDL_WAYLAND_INTERFACE(wl_data_device_manager_interface) + +SDL_WAYLAND_MODULE(WAYLAND_EGL) +SDL_WAYLAND_SYM(struct wl_egl_window *, wl_egl_window_create, (struct wl_surface *, int, int)) +SDL_WAYLAND_SYM(void, wl_egl_window_destroy, (struct wl_egl_window *)) +SDL_WAYLAND_SYM(void, wl_egl_window_resize, (struct wl_egl_window *, int, int, int, int)) +SDL_WAYLAND_SYM(void, wl_egl_window_get_attached_size, (struct wl_egl_window *, int *, int *)) + +SDL_WAYLAND_MODULE(WAYLAND_CURSOR) +SDL_WAYLAND_SYM(struct wl_cursor_theme *, wl_cursor_theme_load, (const char *, int , struct wl_shm *)) +SDL_WAYLAND_SYM(void, wl_cursor_theme_destroy, (struct wl_cursor_theme *)) +SDL_WAYLAND_SYM(struct wl_cursor *, wl_cursor_theme_get_cursor, (struct wl_cursor_theme *, const char *)) +SDL_WAYLAND_SYM(struct wl_buffer *, wl_cursor_image_get_buffer, (struct wl_cursor_image *)) +SDL_WAYLAND_SYM(int, wl_cursor_frame, (struct wl_cursor *, uint32_t)) + +SDL_WAYLAND_MODULE(WAYLAND_XKB) +SDL_WAYLAND_SYM(int, xkb_state_key_get_syms, (struct xkb_state *, xkb_keycode_t, const xkb_keysym_t **)) +SDL_WAYLAND_SYM(int, xkb_keysym_to_utf8, (xkb_keysym_t, char *, size_t) ) +SDL_WAYLAND_SYM(struct xkb_keymap *, xkb_keymap_new_from_string, (struct xkb_context *, const char *, enum xkb_keymap_format, enum xkb_keymap_compile_flags)) +SDL_WAYLAND_SYM(struct xkb_state *, xkb_state_new, (struct xkb_keymap *) ) +SDL_WAYLAND_SYM(void, xkb_keymap_unref, (struct xkb_keymap *) ) +SDL_WAYLAND_SYM(void, xkb_state_unref, (struct xkb_state *) ) +SDL_WAYLAND_SYM(void, xkb_context_unref, (struct xkb_context *) ) +SDL_WAYLAND_SYM(struct xkb_context *, xkb_context_new, (enum xkb_context_flags flags) ) +SDL_WAYLAND_SYM(enum xkb_state_component, xkb_state_update_mask, (struct xkb_state *state,\ + xkb_mod_mask_t depressed_mods,\ + xkb_mod_mask_t latched_mods,\ + xkb_mod_mask_t locked_mods,\ + xkb_layout_index_t depressed_layout,\ + xkb_layout_index_t latched_layout,\ + xkb_layout_index_t locked_layout) ) + +#undef SDL_WAYLAND_MODULE +#undef SDL_WAYLAND_SYM +#undef SDL_WAYLAND_INTERFACE + +/* *INDENT-ON* */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandtouch.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandtouch.c new file mode 100644 index 0000000..1cf37c1 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandtouch.c @@ -0,0 +1,265 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* Contributed by Thomas Perl <thomas.perl@jollamobile.com> */ + +#include "../../SDL_internal.h" + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + +#include "SDL_log.h" +#include "SDL_waylandtouch.h" +#include "../../events/SDL_touch_c.h" + +struct SDL_WaylandTouch { + struct qt_touch_extension *touch_extension; +}; + + +/** + * Qt TouchPointState + * adapted from qtbase/src/corelib/global/qnamespace.h + **/ +enum QtWaylandTouchPointState { + QtWaylandTouchPointPressed = 0x01, + QtWaylandTouchPointMoved = 0x02, + /* + Never sent by the server: + QtWaylandTouchPointStationary = 0x04, + */ + QtWaylandTouchPointReleased = 0x08, +}; + +static void +touch_handle_touch(void *data, + struct qt_touch_extension *qt_touch_extension, + uint32_t time, + uint32_t id, + uint32_t state, + int32_t x, + int32_t y, + int32_t normalized_x, + int32_t normalized_y, + int32_t width, + int32_t height, + uint32_t pressure, + int32_t velocity_x, + int32_t velocity_y, + uint32_t flags, + struct wl_array *rawdata) +{ + /** + * Event is assembled in QtWayland in TouchExtensionGlobal::postTouchEvent + * (src/compositor/wayland_wrapper/qwltouch.cpp) + **/ + + float FIXED_TO_FLOAT = 1. / 10000.; + float xf = FIXED_TO_FLOAT * x; + float yf = FIXED_TO_FLOAT * y; + + float PRESSURE_TO_FLOAT = 1. / 255.; + float pressuref = PRESSURE_TO_FLOAT * pressure; + + uint32_t touchState = state & 0xFFFF; + /* + Other fields that are sent by the server (qwltouch.cpp), + but not used at the moment can be decoded in this way: + + uint32_t sentPointCount = state >> 16; + uint32_t touchFlags = flags & 0xFFFF; + uint32_t capabilities = flags >> 16; + */ + + SDL_TouchID deviceId = 1; + if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { + SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); + } + + switch (touchState) { + case QtWaylandTouchPointPressed: + case QtWaylandTouchPointReleased: + SDL_SendTouch(deviceId, (SDL_FingerID)id, + (touchState == QtWaylandTouchPointPressed) ? SDL_TRUE : SDL_FALSE, + xf, yf, pressuref); + break; + case QtWaylandTouchPointMoved: + SDL_SendTouchMotion(deviceId, (SDL_FingerID)id, xf, yf, pressuref); + break; + default: + /* Should not happen */ + break; + } +} + +static void +touch_handle_configure(void *data, + struct qt_touch_extension *qt_touch_extension, + uint32_t flags) +{ +} + + +/* wayland-qt-touch-extension.c BEGINS */ + +static const struct qt_touch_extension_listener touch_listener = { + touch_handle_touch, + touch_handle_configure, +}; + +static const struct wl_interface *qt_touch_extension_types[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static const struct wl_message qt_touch_extension_requests[] = { + { "dummy", "", qt_touch_extension_types + 0 }, +}; + +static const struct wl_message qt_touch_extension_events[] = { + { "touch", "uuuiiiiiiuiiua", qt_touch_extension_types + 0 }, + { "configure", "u", qt_touch_extension_types + 0 }, +}; + +WL_EXPORT const struct wl_interface qt_touch_extension_interface = { + "qt_touch_extension", 1, + 1, qt_touch_extension_requests, + 2, qt_touch_extension_events, +}; + +/* wayland-qt-touch-extension.c ENDS */ + +/* wayland-qt-windowmanager.c BEGINS */ +static const struct wl_interface *qt_windowmanager_types[] = { + NULL, + NULL, +}; + +static const struct wl_message qt_windowmanager_requests[] = { + { "open_url", "us", qt_windowmanager_types + 0 }, +}; + +static const struct wl_message qt_windowmanager_events[] = { + { "hints", "i", qt_windowmanager_types + 0 }, + { "quit", "", qt_windowmanager_types + 0 }, +}; + +WL_EXPORT const struct wl_interface qt_windowmanager_interface = { + "qt_windowmanager", 1, + 1, qt_windowmanager_requests, + 2, qt_windowmanager_events, +}; +/* wayland-qt-windowmanager.c ENDS */ + +/* wayland-qt-surface-extension.c BEGINS */ +extern const struct wl_interface qt_extended_surface_interface; +#ifndef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC +extern const struct wl_interface wl_surface_interface; +#endif + +static const struct wl_interface *qt_surface_extension_types[] = { + NULL, + NULL, + &qt_extended_surface_interface, +#ifdef SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC + /* FIXME: Set this dynamically to (*WAYLAND_wl_surface_interface) ? + * The value comes from auto generated code and does + * not appear to actually be used anywhere + */ + NULL, +#else + &wl_surface_interface, +#endif +}; + +static const struct wl_message qt_surface_extension_requests[] = { + { "get_extended_surface", "no", qt_surface_extension_types + 2 }, +}; + +WL_EXPORT const struct wl_interface qt_surface_extension_interface = { + "qt_surface_extension", 1, + 1, qt_surface_extension_requests, + 0, NULL, +}; + +static const struct wl_message qt_extended_surface_requests[] = { + { "update_generic_property", "sa", qt_surface_extension_types + 0 }, + { "set_content_orientation", "i", qt_surface_extension_types + 0 }, + { "set_window_flags", "i", qt_surface_extension_types + 0 }, +}; + +static const struct wl_message qt_extended_surface_events[] = { + { "onscreen_visibility", "i", qt_surface_extension_types + 0 }, + { "set_generic_property", "sa", qt_surface_extension_types + 0 }, + { "close", "", qt_surface_extension_types + 0 }, +}; + +WL_EXPORT const struct wl_interface qt_extended_surface_interface = { + "qt_extended_surface", 1, + 3, qt_extended_surface_requests, + 3, qt_extended_surface_events, +}; + +/* wayland-qt-surface-extension.c ENDS */ + +void +Wayland_touch_create(SDL_VideoData *data, uint32_t id) +{ + struct SDL_WaylandTouch *touch; + + if (data->touch) { + Wayland_touch_destroy(data); + } + + /* !!! FIXME: check for failure, call SDL_OutOfMemory() */ + data->touch = SDL_malloc(sizeof(struct SDL_WaylandTouch)); + + touch = data->touch; + touch->touch_extension = wl_registry_bind(data->registry, id, &qt_touch_extension_interface, 1); + qt_touch_extension_add_listener(touch->touch_extension, &touch_listener, data); +} + +void +Wayland_touch_destroy(SDL_VideoData *data) +{ + if (data->touch) { + struct SDL_WaylandTouch *touch = data->touch; + if (touch->touch_extension) { + qt_touch_extension_destroy(touch->touch_extension); + } + + SDL_free(data->touch); + data->touch = NULL; + } +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandtouch.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandtouch.h new file mode 100644 index 0000000..eba0da8 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandtouch.h @@ -0,0 +1,352 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef SDL_waylandtouch_h_ +#define SDL_waylandtouch_h_ + +#include "../../SDL_internal.h" + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + +#include "SDL_waylandvideo.h" +#include <stdint.h> +#include <stddef.h> +#include "wayland-util.h" +#include "SDL_waylanddyn.h" + + +void Wayland_touch_create(SDL_VideoData *data, uint32_t id); +void Wayland_touch_destroy(SDL_VideoData *data); + +struct qt_touch_extension; + +/* Autogenerated QT headers */ + +/* + Support for Wayland with QmlCompositor as Server +================================================ + +The Wayland video driver has support for some additional features when +using QtWayland's "qmlcompositor" as Wayland server. This is needed for touch +input when running SDL applications under a qmlcompositor Wayland server. + +The files following headers have been +generated from the Wayland XML Protocol Definition in QtWayland as follows: + +Clone QtWayland from Git: + http://qt.gitorious.org/qt/qtwayland/ + +Generate headers and glue code: + for extension in touch-extension surface-extension windowmanager; do + wayland-scanner client-header < src/extensions/$extension.xml > wayland-qt-$extension.h + wayland-scanner code < src/extensions/$extension.xml > wayland-qt-$extension.c + done + +*/ + +/* wayland-qt-surface-extension.h */ + +struct wl_client; +struct wl_resource; + +struct qt_surface_extension; +struct qt_extended_surface; + +extern const struct wl_interface qt_surface_extension_interface; +extern const struct wl_interface qt_extended_surface_interface; + +#define QT_SURFACE_EXTENSION_GET_EXTENDED_SURFACE 0 + +static inline void +qt_surface_extension_set_user_data(struct qt_surface_extension *qt_surface_extension, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) qt_surface_extension, user_data); +} + +static inline void * +qt_surface_extension_get_user_data(struct qt_surface_extension *qt_surface_extension) +{ + return wl_proxy_get_user_data((struct wl_proxy *) qt_surface_extension); +} + +static inline void +qt_surface_extension_destroy(struct qt_surface_extension *qt_surface_extension) +{ + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_surface_extension); +} + +static inline struct qt_extended_surface * +qt_surface_extension_get_extended_surface(struct qt_surface_extension *qt_surface_extension, struct wl_surface *surface) +{ + struct wl_proxy *id; + + id = wl_proxy_create((struct wl_proxy *) qt_surface_extension, + &qt_extended_surface_interface); + if (!id) + return NULL; + + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_surface_extension, + QT_SURFACE_EXTENSION_GET_EXTENDED_SURFACE, id, surface); + + return (struct qt_extended_surface *) id; +} + +#ifndef QT_EXTENDED_SURFACE_ORIENTATION_ENUM +#define QT_EXTENDED_SURFACE_ORIENTATION_ENUM +enum qt_extended_surface_orientation { + QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION = 0, + QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION = 1, + QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION = 2, + QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION = 4, + QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION = 8, +}; +#endif /* QT_EXTENDED_SURFACE_ORIENTATION_ENUM */ + +#ifndef QT_EXTENDED_SURFACE_WINDOWFLAG_ENUM +#define QT_EXTENDED_SURFACE_WINDOWFLAG_ENUM +enum qt_extended_surface_windowflag { + QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES = 1, + QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP = 2, +}; +#endif /* QT_EXTENDED_SURFACE_WINDOWFLAG_ENUM */ + +struct qt_extended_surface_listener { + /** + * onscreen_visibility - (none) + * @visible: (none) + */ + void (*onscreen_visibility)(void *data, + struct qt_extended_surface *qt_extended_surface, + int32_t visible); + /** + * set_generic_property - (none) + * @name: (none) + * @value: (none) + */ + void (*set_generic_property)(void *data, + struct qt_extended_surface *qt_extended_surface, + const char *name, + struct wl_array *value); + /** + * close - (none) + */ + void (*close)(void *data, + struct qt_extended_surface *qt_extended_surface); +}; + +static inline int +qt_extended_surface_add_listener(struct qt_extended_surface *qt_extended_surface, + const struct qt_extended_surface_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) qt_extended_surface, + (void (**)(void)) listener, data); +} + +#define QT_EXTENDED_SURFACE_UPDATE_GENERIC_PROPERTY 0 +#define QT_EXTENDED_SURFACE_SET_CONTENT_ORIENTATION 1 +#define QT_EXTENDED_SURFACE_SET_WINDOW_FLAGS 2 + +static inline void +qt_extended_surface_set_user_data(struct qt_extended_surface *qt_extended_surface, void *user_data) +{ + WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_extended_surface, user_data); +} + +static inline void * +qt_extended_surface_get_user_data(struct qt_extended_surface *qt_extended_surface) +{ + return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_extended_surface); +} + +static inline void +qt_extended_surface_destroy(struct qt_extended_surface *qt_extended_surface) +{ + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_extended_surface); +} + +static inline void +qt_extended_surface_update_generic_property(struct qt_extended_surface *qt_extended_surface, const char *name, struct wl_array *value) +{ + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, + QT_EXTENDED_SURFACE_UPDATE_GENERIC_PROPERTY, name, value); +} + +static inline void +qt_extended_surface_set_content_orientation(struct qt_extended_surface *qt_extended_surface, int32_t orientation) +{ + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, + QT_EXTENDED_SURFACE_SET_CONTENT_ORIENTATION, orientation); +} + +static inline void +qt_extended_surface_set_window_flags(struct qt_extended_surface *qt_extended_surface, int32_t flags) +{ + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_extended_surface, + QT_EXTENDED_SURFACE_SET_WINDOW_FLAGS, flags); +} + +/* wayland-qt-touch-extension.h */ + +extern const struct wl_interface qt_touch_extension_interface; + +#ifndef QT_TOUCH_EXTENSION_FLAGS_ENUM +#define QT_TOUCH_EXTENSION_FLAGS_ENUM +enum qt_touch_extension_flags { + QT_TOUCH_EXTENSION_FLAGS_MOUSE_FROM_TOUCH = 0x1, +}; +#endif /* QT_TOUCH_EXTENSION_FLAGS_ENUM */ + +struct qt_touch_extension_listener { + /** + * touch - (none) + * @time: (none) + * @id: (none) + * @state: (none) + * @x: (none) + * @y: (none) + * @normalized_x: (none) + * @normalized_y: (none) + * @width: (none) + * @height: (none) + * @pressure: (none) + * @velocity_x: (none) + * @velocity_y: (none) + * @flags: (none) + * @rawdata: (none) + */ + void (*touch)(void *data, + struct qt_touch_extension *qt_touch_extension, + uint32_t time, + uint32_t id, + uint32_t state, + int32_t x, + int32_t y, + int32_t normalized_x, + int32_t normalized_y, + int32_t width, + int32_t height, + uint32_t pressure, + int32_t velocity_x, + int32_t velocity_y, + uint32_t flags, + struct wl_array *rawdata); + /** + * configure - (none) + * @flags: (none) + */ + void (*configure)(void *data, + struct qt_touch_extension *qt_touch_extension, + uint32_t flags); +}; + +static inline int +qt_touch_extension_add_listener(struct qt_touch_extension *qt_touch_extension, + const struct qt_touch_extension_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) qt_touch_extension, + (void (**)(void)) listener, data); +} + +#define QT_TOUCH_EXTENSION_DUMMY 0 + +static inline void +qt_touch_extension_set_user_data(struct qt_touch_extension *qt_touch_extension, void *user_data) +{ + WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_touch_extension, user_data); +} + +static inline void * +qt_touch_extension_get_user_data(struct qt_touch_extension *qt_touch_extension) +{ + return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_touch_extension); +} + +static inline void +qt_touch_extension_destroy(struct qt_touch_extension *qt_touch_extension) +{ + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_touch_extension); +} + +static inline void +qt_touch_extension_dummy(struct qt_touch_extension *qt_touch_extension) +{ + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_touch_extension, + QT_TOUCH_EXTENSION_DUMMY); +} + + +/* wayland-qt-windowmanager.h */ + +extern const struct wl_interface qt_windowmanager_interface; + +struct qt_windowmanager_listener { + /** + * hints - (none) + * @show_is_fullscreen: (none) + */ + void (*hints)(void *data, + struct qt_windowmanager *qt_windowmanager, + int32_t show_is_fullscreen); + /** + * quit - (none) + */ + void (*quit)(void *data, + struct qt_windowmanager *qt_windowmanager); +}; + +static inline int +qt_windowmanager_add_listener(struct qt_windowmanager *qt_windowmanager, + const struct qt_windowmanager_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) qt_windowmanager, + (void (**)(void)) listener, data); +} + +#define QT_WINDOWMANAGER_OPEN_URL 0 + +static inline void +qt_windowmanager_set_user_data(struct qt_windowmanager *qt_windowmanager, void *user_data) +{ + WAYLAND_wl_proxy_set_user_data((struct wl_proxy *) qt_windowmanager, user_data); +} + +static inline void * +qt_windowmanager_get_user_data(struct qt_windowmanager *qt_windowmanager) +{ + return WAYLAND_wl_proxy_get_user_data((struct wl_proxy *) qt_windowmanager); +} + +static inline void +qt_windowmanager_destroy(struct qt_windowmanager *qt_windowmanager) +{ + WAYLAND_wl_proxy_destroy((struct wl_proxy *) qt_windowmanager); +} + +static inline void +qt_windowmanager_open_url(struct qt_windowmanager *qt_windowmanager, uint32_t remaining, const char *url) +{ + WAYLAND_wl_proxy_marshal((struct wl_proxy *) qt_windowmanager, + QT_WINDOWMANAGER_OPEN_URL, remaining, url); +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + +#endif /* SDL_waylandtouch_h_ */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvideo.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvideo.c new file mode 100644 index 0000000..b6155e7 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvideo.c @@ -0,0 +1,517 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND + +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "SDL_stdinc.h" +#include "../../events/SDL_events_c.h" + +#include "SDL_waylandvideo.h" +#include "SDL_waylandevents_c.h" +#include "SDL_waylandwindow.h" +#include "SDL_waylandopengles.h" +#include "SDL_waylandmouse.h" +#include "SDL_waylandtouch.h" +#include "SDL_waylandclipboard.h" +#include "SDL_waylandvulkan.h" + +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <xkbcommon/xkbcommon.h> + +#include "SDL_waylanddyn.h" +#include <wayland-util.h> + +#include "xdg-shell-client-protocol.h" +#include "xdg-shell-unstable-v6-client-protocol.h" + +#define WAYLANDVID_DRIVER_NAME "wayland" + +/* Initialization/Query functions */ +static int +Wayland_VideoInit(_THIS); + +static void +Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display); +static int +Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode); + +static void +Wayland_VideoQuit(_THIS); + +/* Find out what class name we should use + * Based on src/video/x11/SDL_x11video.c */ +static char * +get_classname() +{ +/* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec: + "The surface class identifies the general class of applications + to which the surface belongs. A common convention is to use the + file name (or the full path if it is a non-standard location) of + the application's .desktop file as the class." */ + + char *spot; +#if defined(__LINUX__) || defined(__FREEBSD__) + char procfile[1024]; + char linkfile[1024]; + int linksize; +#endif + + /* First allow environment variable override */ + spot = SDL_getenv("SDL_VIDEO_WAYLAND_WMCLASS"); + if (spot) { + return SDL_strdup(spot); + } else { + /* Fallback to the "old" envvar */ + spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS"); + if (spot) { + return SDL_strdup(spot); + } + } + + /* Next look at the application's executable name */ +#if defined(__LINUX__) || defined(__FREEBSD__) +#if defined(__LINUX__) + SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid()); +#elif defined(__FREEBSD__) + SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", + getpid()); +#else +#error Where can we find the executable name? +#endif + linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1); + if (linksize > 0) { + linkfile[linksize] = '\0'; + spot = SDL_strrchr(linkfile, '/'); + if (spot) { + return SDL_strdup(spot + 1); + } else { + return SDL_strdup(linkfile); + } + } +#endif /* __LINUX__ || __FREEBSD__ */ + + /* Finally use the default we've used forever */ + return SDL_strdup("SDL_App"); +} + +/* Wayland driver bootstrap functions */ +static int +Wayland_Available(void) +{ + struct wl_display *display = NULL; + if (SDL_WAYLAND_LoadSymbols()) { + display = WAYLAND_wl_display_connect(NULL); + if (display != NULL) { + WAYLAND_wl_display_disconnect(display); + } + SDL_WAYLAND_UnloadSymbols(); + } + + return (display != NULL); +} + +static void +Wayland_DeleteDevice(SDL_VideoDevice *device) +{ + SDL_free(device); + SDL_WAYLAND_UnloadSymbols(); +} + +static SDL_VideoDevice * +Wayland_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + + if (!SDL_WAYLAND_LoadSymbols()) { + return NULL; + } + + /* Initialize all variables that we clean on shutdown */ + device = SDL_calloc(1, sizeof(SDL_VideoDevice)); + if (!device) { + SDL_WAYLAND_UnloadSymbols(); + SDL_OutOfMemory(); + return NULL; + } + + /* Set the function pointers */ + device->VideoInit = Wayland_VideoInit; + device->VideoQuit = Wayland_VideoQuit; + device->SetDisplayMode = Wayland_SetDisplayMode; + device->GetDisplayModes = Wayland_GetDisplayModes; + device->GetWindowWMInfo = Wayland_GetWindowWMInfo; + + device->PumpEvents = Wayland_PumpEvents; + + device->GL_SwapWindow = Wayland_GLES_SwapWindow; + device->GL_GetSwapInterval = Wayland_GLES_GetSwapInterval; + device->GL_SetSwapInterval = Wayland_GLES_SetSwapInterval; + device->GL_MakeCurrent = Wayland_GLES_MakeCurrent; + device->GL_CreateContext = Wayland_GLES_CreateContext; + device->GL_LoadLibrary = Wayland_GLES_LoadLibrary; + device->GL_UnloadLibrary = Wayland_GLES_UnloadLibrary; + device->GL_GetProcAddress = Wayland_GLES_GetProcAddress; + device->GL_DeleteContext = Wayland_GLES_DeleteContext; + + device->CreateSDLWindow = Wayland_CreateWindow; + device->ShowWindow = Wayland_ShowWindow; + device->SetWindowFullscreen = Wayland_SetWindowFullscreen; + device->MaximizeWindow = Wayland_MaximizeWindow; + device->RestoreWindow = Wayland_RestoreWindow; + device->SetWindowSize = Wayland_SetWindowSize; + device->SetWindowTitle = Wayland_SetWindowTitle; + device->DestroyWindow = Wayland_DestroyWindow; + device->SetWindowHitTest = Wayland_SetWindowHitTest; + + device->SetClipboardText = Wayland_SetClipboardText; + device->GetClipboardText = Wayland_GetClipboardText; + device->HasClipboardText = Wayland_HasClipboardText; + +#if SDL_VIDEO_VULKAN + device->Vulkan_LoadLibrary = Wayland_Vulkan_LoadLibrary; + device->Vulkan_UnloadLibrary = Wayland_Vulkan_UnloadLibrary; + device->Vulkan_GetInstanceExtensions = Wayland_Vulkan_GetInstanceExtensions; + device->Vulkan_CreateSurface = Wayland_Vulkan_CreateSurface; +#endif + + device->free = Wayland_DeleteDevice; + + return device; +} + +VideoBootStrap Wayland_bootstrap = { + WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver", + Wayland_Available, Wayland_CreateDevice +}; + +static void +display_handle_geometry(void *data, + struct wl_output *output, + int x, int y, + int physical_width, + int physical_height, + int subpixel, + const char *make, + const char *model, + int transform) + +{ + SDL_VideoDisplay *display = data; + + display->name = SDL_strdup(model); + display->driverdata = output; +} + +static void +display_handle_mode(void *data, + struct wl_output *output, + uint32_t flags, + int width, + int height, + int refresh) +{ + SDL_VideoDisplay *display = data; + SDL_DisplayMode mode; + + SDL_zero(mode); + mode.format = SDL_PIXELFORMAT_RGB888; + mode.w = width; + mode.h = height; + mode.refresh_rate = refresh / 1000; // mHz to Hz + mode.driverdata = display->driverdata; + SDL_AddDisplayMode(display, &mode); + + if (flags & WL_OUTPUT_MODE_CURRENT) { + display->current_mode = mode; + display->desktop_mode = mode; + } +} + +static void +display_handle_done(void *data, + struct wl_output *output) +{ + SDL_VideoDisplay *display = data; + SDL_AddVideoDisplay(display); + SDL_free(display->name); + SDL_free(display); +} + +static void +display_handle_scale(void *data, + struct wl_output *output, + int32_t factor) +{ + // TODO: do HiDPI stuff. +} + +static const struct wl_output_listener output_listener = { + display_handle_geometry, + display_handle_mode, + display_handle_done, + display_handle_scale +}; + +static void +Wayland_add_display(SDL_VideoData *d, uint32_t id) +{ + struct wl_output *output; + SDL_VideoDisplay *display = SDL_malloc(sizeof *display); + if (!display) { + SDL_OutOfMemory(); + return; + } + SDL_zero(*display); + + output = wl_registry_bind(d->registry, id, &wl_output_interface, 2); + if (!output) { + SDL_SetError("Failed to retrieve output."); + SDL_free(display); + return; + } + + wl_output_add_listener(output, &output_listener, display); +} + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH +static void +windowmanager_hints(void *data, struct qt_windowmanager *qt_windowmanager, + int32_t show_is_fullscreen) +{ +} + +static void +windowmanager_quit(void *data, struct qt_windowmanager *qt_windowmanager) +{ + SDL_SendQuit(); +} + +static const struct qt_windowmanager_listener windowmanager_listener = { + windowmanager_hints, + windowmanager_quit, +}; +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + + +static void +handle_ping_zxdg_shell(void *data, struct zxdg_shell_v6 *zxdg, uint32_t serial) +{ + zxdg_shell_v6_pong(zxdg, serial); +} + +static const struct zxdg_shell_v6_listener shell_listener_zxdg = { + handle_ping_zxdg_shell +}; + + +static void +handle_ping_xdg_wm_base(void *data, struct xdg_wm_base *xdg, uint32_t serial) +{ + xdg_wm_base_pong(xdg, serial); +} + +static const struct xdg_wm_base_listener shell_listener_xdg = { + handle_ping_xdg_wm_base +}; + + +static void +display_handle_global(void *data, struct wl_registry *registry, uint32_t id, + const char *interface, uint32_t version) +{ + SDL_VideoData *d = data; + + if (strcmp(interface, "wl_compositor") == 0) { + d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1); + } else if (strcmp(interface, "wl_output") == 0) { + Wayland_add_display(d, id); + } else if (strcmp(interface, "wl_seat") == 0) { + Wayland_display_add_input(d, id); + } else if (strcmp(interface, "xdg_wm_base") == 0) { + d->shell.xdg = wl_registry_bind(d->registry, id, &xdg_wm_base_interface, 1); + xdg_wm_base_add_listener(d->shell.xdg, &shell_listener_xdg, NULL); + } else if (strcmp(interface, "zxdg_shell_v6") == 0) { + d->shell.zxdg = wl_registry_bind(d->registry, id, &zxdg_shell_v6_interface, 1); + zxdg_shell_v6_add_listener(d->shell.zxdg, &shell_listener_zxdg, NULL); + } else if (strcmp(interface, "wl_shell") == 0) { + d->shell.wl = wl_registry_bind(d->registry, id, &wl_shell_interface, 1); + } else if (strcmp(interface, "wl_shm") == 0) { + d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1); + d->cursor_theme = WAYLAND_wl_cursor_theme_load(NULL, 32, d->shm); + } else if (strcmp(interface, "zwp_relative_pointer_manager_v1") == 0) { + Wayland_display_add_relative_pointer_manager(d, id); + } else if (strcmp(interface, "zwp_pointer_constraints_v1") == 0) { + Wayland_display_add_pointer_constraints(d, id); + } else if (strcmp(interface, "wl_data_device_manager") == 0) { + d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3); + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + } else if (strcmp(interface, "qt_touch_extension") == 0) { + Wayland_touch_create(d, id); + } else if (strcmp(interface, "qt_surface_extension") == 0) { + d->surface_extension = wl_registry_bind(registry, id, + &qt_surface_extension_interface, 1); + } else if (strcmp(interface, "qt_windowmanager") == 0) { + d->windowmanager = wl_registry_bind(registry, id, + &qt_windowmanager_interface, 1); + qt_windowmanager_add_listener(d->windowmanager, &windowmanager_listener, d); +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + } +} + +static const struct wl_registry_listener registry_listener = { + display_handle_global, + NULL, /* global_remove */ +}; + +int +Wayland_VideoInit(_THIS) +{ + SDL_VideoData *data = SDL_malloc(sizeof *data); + if (data == NULL) + return SDL_OutOfMemory(); + memset(data, 0, sizeof *data); + + _this->driverdata = data; + + data->xkb_context = WAYLAND_xkb_context_new(0); + if (!data->xkb_context) { + return SDL_SetError("Failed to create XKB context"); + } + + data->display = WAYLAND_wl_display_connect(NULL); + if (data->display == NULL) { + return SDL_SetError("Failed to connect to a Wayland display"); + } + + data->registry = wl_display_get_registry(data->display); + if (data->registry == NULL) { + return SDL_SetError("Failed to get the Wayland registry"); + } + + wl_registry_add_listener(data->registry, ®istry_listener, data); + + // First roundtrip to receive all registry objects. + WAYLAND_wl_display_roundtrip(data->display); + + // Second roundtrip to receive all output events. + WAYLAND_wl_display_roundtrip(data->display); + + Wayland_InitMouse(); + + /* Get the surface class name, usually the name of the application */ + data->classname = get_classname(); + + WAYLAND_wl_display_flush(data->display); + + return 0; +} + +static void +Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display) +{ + // Nothing to do here, everything was already done in the wl_output + // callbacks. +} + +static int +Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +{ + return SDL_Unsupported(); +} + +void +Wayland_VideoQuit(_THIS) +{ + SDL_VideoData *data = _this->driverdata; + int i, j; + + Wayland_FiniMouse (); + + for (i = 0; i < _this->num_displays; ++i) { + SDL_VideoDisplay *display = &_this->displays[i]; + wl_output_destroy(display->driverdata); + display->driverdata = NULL; + + for (j = display->num_display_modes; j--;) { + display->display_modes[j].driverdata = NULL; + } + display->desktop_mode.driverdata = NULL; + } + + Wayland_display_destroy_input(data); + Wayland_display_destroy_pointer_constraints(data); + Wayland_display_destroy_relative_pointer_manager(data); + + if (data->xkb_context) { + WAYLAND_xkb_context_unref(data->xkb_context); + data->xkb_context = NULL; + } +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + if (data->windowmanager) + qt_windowmanager_destroy(data->windowmanager); + + if (data->surface_extension) + qt_surface_extension_destroy(data->surface_extension); + + Wayland_touch_destroy(data); +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + + if (data->shm) + wl_shm_destroy(data->shm); + + if (data->cursor_theme) + WAYLAND_wl_cursor_theme_destroy(data->cursor_theme); + + if (data->shell.wl) + wl_shell_destroy(data->shell.wl); + + if (data->shell.xdg) + xdg_wm_base_destroy(data->shell.xdg); + + if (data->shell.zxdg) + zxdg_shell_v6_destroy(data->shell.zxdg); + + if (data->compositor) + wl_compositor_destroy(data->compositor); + + if (data->registry) + wl_registry_destroy(data->registry); + + if (data->display) { + WAYLAND_wl_display_flush(data->display); + WAYLAND_wl_display_disconnect(data->display); + } + + SDL_free(data->classname); + SDL_free(data); + _this->driverdata = NULL; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvideo.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvideo.h new file mode 100644 index 0000000..c16c0bd --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvideo.h @@ -0,0 +1,85 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#ifndef SDL_waylandvideo_h_ +#define SDL_waylandvideo_h_ + + +/* +!!! FIXME: xdg_wm_base is the stable replacement for zxdg_shell_v6. While it's +!!! FIXME: harmless to leave it here, consider deleting the obsolete codepath +!!! FIXME: soon, since Wayland (with xdg_wm_base) will probably be mainline +!!! FIXME: by the time people are relying on this SDL target. It's available +!!! FIXME: in Ubuntu 18.04 (and other distros). +*/ + + +#include <EGL/egl.h> +#include "wayland-util.h" + +struct xkb_context; +struct SDL_WaylandInput; + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH +struct SDL_WaylandTouch; +struct qt_surface_extension; +struct qt_windowmanager; +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + +typedef struct { + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_shm *shm; + struct wl_cursor_theme *cursor_theme; + struct wl_pointer *pointer; + struct { + struct xdg_wm_base *xdg; + struct zxdg_shell_v6 *zxdg; + struct wl_shell *wl; + } shell; + struct zwp_relative_pointer_manager_v1 *relative_pointer_manager; + struct zwp_pointer_constraints_v1 *pointer_constraints; + struct wl_data_device_manager *data_device_manager; + + EGLDisplay edpy; + EGLContext context; + EGLConfig econf; + + struct xkb_context *xkb_context; + struct SDL_WaylandInput *input; + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + struct SDL_WaylandTouch *touch; + struct qt_surface_extension *surface_extension; + struct qt_windowmanager *windowmanager; +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + + char *classname; + + int relative_mouse_mode; +} SDL_VideoData; + +#endif /* SDL_waylandvideo_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvulkan.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvulkan.c new file mode 100644 index 0000000..d67472c --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvulkan.c @@ -0,0 +1,176 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's + * SDL_x11vulkan.c. + */ + +#include "../../SDL_internal.h" + +#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WAYLAND + +#include "SDL_waylandvideo.h" +#include "SDL_waylandwindow.h" +#include "SDL_assert.h" + +#include "SDL_loadso.h" +#include "SDL_waylandvulkan.h" +#include "SDL_syswm.h" + +int Wayland_Vulkan_LoadLibrary(_THIS, const char *path) +{ + VkExtensionProperties *extensions = NULL; + Uint32 i, extensionCount = 0; + SDL_bool hasSurfaceExtension = SDL_FALSE; + SDL_bool hasWaylandSurfaceExtension = SDL_FALSE; + PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL; + if(_this->vulkan_config.loader_handle) + return SDL_SetError("Vulkan already loaded"); + + /* Load the Vulkan loader library */ + if(!path) + path = SDL_getenv("SDL_VULKAN_LIBRARY"); + if(!path) + path = "libvulkan.so.1"; + _this->vulkan_config.loader_handle = SDL_LoadObject(path); + if(!_this->vulkan_config.loader_handle) + return -1; + SDL_strlcpy(_this->vulkan_config.loader_path, path, + SDL_arraysize(_this->vulkan_config.loader_path)); + vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( + _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr"); + if(!vkGetInstanceProcAddr) + goto fail; + _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr; + _this->vulkan_config.vkEnumerateInstanceExtensionProperties = + (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)( + VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties"); + if(!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) + goto fail; + extensions = SDL_Vulkan_CreateInstanceExtensionsList( + (PFN_vkEnumerateInstanceExtensionProperties) + _this->vulkan_config.vkEnumerateInstanceExtensionProperties, + &extensionCount); + if(!extensions) + goto fail; + for(i = 0; i < extensionCount; i++) + { + if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + hasSurfaceExtension = SDL_TRUE; + else if(SDL_strcmp(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) + hasWaylandSurfaceExtension = SDL_TRUE; + } + SDL_free(extensions); + if(!hasSurfaceExtension) + { + SDL_SetError("Installed Vulkan doesn't implement the " + VK_KHR_SURFACE_EXTENSION_NAME " extension"); + goto fail; + } + else if(!hasWaylandSurfaceExtension) + { + SDL_SetError("Installed Vulkan doesn't implement the " + VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "extension"); + goto fail; + } + return 0; + +fail: + SDL_UnloadObject(_this->vulkan_config.loader_handle); + _this->vulkan_config.loader_handle = NULL; + return -1; +} + +void Wayland_Vulkan_UnloadLibrary(_THIS) +{ + if(_this->vulkan_config.loader_handle) + { + SDL_UnloadObject(_this->vulkan_config.loader_handle); + _this->vulkan_config.loader_handle = NULL; + } +} + +SDL_bool Wayland_Vulkan_GetInstanceExtensions(_THIS, + SDL_Window *window, + unsigned *count, + const char **names) +{ + static const char *const extensionsForWayland[] = { + VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME + }; + if(!_this->vulkan_config.loader_handle) + { + SDL_SetError("Vulkan is not loaded"); + return SDL_FALSE; + } + return SDL_Vulkan_GetInstanceExtensions_Helper( + count, names, SDL_arraysize(extensionsForWayland), + extensionsForWayland); +} + +SDL_bool Wayland_Vulkan_CreateSurface(_THIS, + SDL_Window *window, + VkInstance instance, + VkSurfaceKHR *surface) +{ + SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; + PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = + (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; + PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR = + (PFN_vkCreateWaylandSurfaceKHR)vkGetInstanceProcAddr( + (VkInstance)instance, + "vkCreateWaylandSurfaceKHR"); + VkWaylandSurfaceCreateInfoKHR createInfo; + VkResult result; + + if(!_this->vulkan_config.loader_handle) + { + SDL_SetError("Vulkan is not loaded"); + return SDL_FALSE; + } + + if(!vkCreateWaylandSurfaceKHR) + { + SDL_SetError(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME + " extension is not enabled in the Vulkan instance."); + return SDL_FALSE; + } + SDL_zero(createInfo); + createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; + createInfo.pNext = NULL; + createInfo.flags = 0; + createInfo.display = windowData->waylandData->display; + createInfo.surface = windowData->surface; + result = vkCreateWaylandSurfaceKHR(instance, &createInfo, + NULL, surface); + if(result != VK_SUCCESS) + { + SDL_SetError("vkCreateWaylandSurfaceKHR failed: %s", + SDL_Vulkan_GetResultString(result)); + return SDL_FALSE; + } + return SDL_TRUE; +} + +#endif + +/* vim: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvulkan.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvulkan.h new file mode 100644 index 0000000..5ad3a46 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandvulkan.h @@ -0,0 +1,52 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + * @author Mark Callow, www.edgewise-consulting.com. Based on Jacob Lifshay's + * SDL_x11vulkan.h. + */ + +#include "../../SDL_internal.h" + +#ifndef SDL_waylandvulkan_h_ +#define SDL_waylandvulkan_h_ + +#include "../SDL_vulkan_internal.h" +#include "../SDL_sysvideo.h" + +#if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_WAYLAND + +int Wayland_Vulkan_LoadLibrary(_THIS, const char *path); +void Wayland_Vulkan_UnloadLibrary(_THIS); +SDL_bool Wayland_Vulkan_GetInstanceExtensions(_THIS, + SDL_Window *window, + unsigned *count, + const char **names); +SDL_bool Wayland_Vulkan_CreateSurface(_THIS, + SDL_Window *window, + VkInstance instance, + VkSurfaceKHR *surface); + +#endif + +#endif /* SDL_waylandvulkan_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandwindow.c b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandwindow.c new file mode 100644 index 0000000..aa72991 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandwindow.c @@ -0,0 +1,676 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL + +#include "../SDL_sysvideo.h" +#include "../../events/SDL_windowevents_c.h" +#include "../SDL_egl_c.h" +#include "SDL_waylandevents_c.h" +#include "SDL_waylandwindow.h" +#include "SDL_waylandvideo.h" +#include "SDL_waylandtouch.h" +#include "SDL_waylanddyn.h" +#include "SDL_hints.h" + +#include "xdg-shell-client-protocol.h" +#include "xdg-shell-unstable-v6-client-protocol.h" + +/* On modern desktops, we probably will use the xdg-shell protocol instead + of wl_shell, but wl_shell might be useful on older Wayland installs that + don't have the newer protocol, or embedded things that don't have a full + window manager. */ + +static void +handle_ping_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface, + uint32_t serial) +{ + wl_shell_surface_pong(shell_surface, serial); +} + +static void +handle_configure_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface, + uint32_t edges, int32_t width, int32_t height) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + struct wl_region *region; + + /* wl_shell_surface spec states that this is a suggestion. + Ignore if less than or greater than max/min size. */ + + if (width == 0 || height == 0) { + return; + } + + if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { + if ((window->flags & SDL_WINDOW_RESIZABLE)) { + if (window->max_w > 0) { + width = SDL_min(width, window->max_w); + } + width = SDL_max(width, window->min_w); + + if (window->max_h > 0) { + height = SDL_min(height, window->max_h); + } + height = SDL_max(height, window->min_h); + } else { + return; + } + } + + WAYLAND_wl_egl_window_resize(wind->egl_window, width, height, 0, 0); + region = wl_compositor_create_region(wind->waylandData->compositor); + wl_region_add(region, 0, 0, width, height); + wl_surface_set_opaque_region(wind->surface, region); + wl_region_destroy(region); + + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); + window->w = width; + window->h = height; +} + +static void +handle_popup_done_wl_shell_surface(void *data, struct wl_shell_surface *shell_surface) +{ +} + +static const struct wl_shell_surface_listener shell_surface_listener_wl = { + handle_ping_wl_shell_surface, + handle_configure_wl_shell_surface, + handle_popup_done_wl_shell_surface +}; + + + + +static void +handle_configure_zxdg_shell_surface(void *data, struct zxdg_surface_v6 *zxdg, uint32_t serial) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + struct wl_region *region; + + wind->shell_surface.zxdg.initial_configure_seen = SDL_TRUE; + + WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); + + region = wl_compositor_create_region(wind->waylandData->compositor); + wl_region_add(region, 0, 0, window->w, window->h); + wl_surface_set_opaque_region(wind->surface, region); + wl_region_destroy(region); + zxdg_surface_v6_ack_configure(zxdg, serial); +} + +static const struct zxdg_surface_v6_listener shell_surface_listener_zxdg = { + handle_configure_zxdg_shell_surface +}; + + +static void +handle_configure_zxdg_toplevel(void *data, + struct zxdg_toplevel_v6 *zxdg_toplevel_v6, + int32_t width, + int32_t height, + struct wl_array *states) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + + /* wl_shell_surface spec states that this is a suggestion. + Ignore if less than or greater than max/min size. */ + + if (width == 0 || height == 0) { + return; + } + + if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { + if ((window->flags & SDL_WINDOW_RESIZABLE)) { + if (window->max_w > 0) { + width = SDL_min(width, window->max_w); + } + width = SDL_max(width, window->min_w); + + if (window->max_h > 0) { + height = SDL_min(height, window->max_h); + } + height = SDL_max(height, window->min_h); + } else { + return; + } + } + + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); + window->w = width; + window->h = height; +} + +static void +handle_close_zxdg_toplevel(void *data, struct zxdg_toplevel_v6 *zxdg_toplevel_v6) +{ + SDL_WindowData *window = (SDL_WindowData *)data; + SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0); +} + +static const struct zxdg_toplevel_v6_listener toplevel_listener_zxdg = { + handle_configure_zxdg_toplevel, + handle_close_zxdg_toplevel +}; + + + +static void +handle_configure_xdg_shell_surface(void *data, struct xdg_surface *xdg, uint32_t serial) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + struct wl_region *region; + + wind->shell_surface.xdg.initial_configure_seen = SDL_TRUE; + + WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); + + region = wl_compositor_create_region(wind->waylandData->compositor); + wl_region_add(region, 0, 0, window->w, window->h); + wl_surface_set_opaque_region(wind->surface, region); + wl_region_destroy(region); + xdg_surface_ack_configure(xdg, serial); +} + +static const struct xdg_surface_listener shell_surface_listener_xdg = { + handle_configure_xdg_shell_surface +}; + + +static void +handle_configure_xdg_toplevel(void *data, + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height, + struct wl_array *states) +{ + SDL_WindowData *wind = (SDL_WindowData *)data; + SDL_Window *window = wind->sdlwindow; + + /* wl_shell_surface spec states that this is a suggestion. + Ignore if less than or greater than max/min size. */ + + if (width == 0 || height == 0) { + return; + } + + if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { + if ((window->flags & SDL_WINDOW_RESIZABLE)) { + if (window->max_w > 0) { + width = SDL_min(width, window->max_w); + } + width = SDL_max(width, window->min_w); + + if (window->max_h > 0) { + height = SDL_min(height, window->max_h); + } + height = SDL_max(height, window->min_h); + } else { + return; + } + } + + if (width == window->w && height == window->h) { + return; + } + + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, width, height); + window->w = width; + window->h = height; +} + +static void +handle_close_xdg_toplevel(void *data, struct xdg_toplevel *xdg_toplevel) +{ + SDL_WindowData *window = (SDL_WindowData *)data; + SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0); +} + +static const struct xdg_toplevel_listener toplevel_listener_xdg = { + handle_configure_xdg_toplevel, + handle_close_xdg_toplevel +}; + + + + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH +static void +handle_onscreen_visibility(void *data, + struct qt_extended_surface *qt_extended_surface, int32_t visible) +{ +} + +static void +handle_set_generic_property(void *data, + struct qt_extended_surface *qt_extended_surface, const char *name, + struct wl_array *value) +{ +} + +static void +handle_close(void *data, struct qt_extended_surface *qt_extended_surface) +{ + SDL_WindowData *window = (SDL_WindowData *)data; + SDL_SendWindowEvent(window->sdlwindow, SDL_WINDOWEVENT_CLOSE, 0, 0); +} + +static const struct qt_extended_surface_listener extended_surface_listener = { + handle_onscreen_visibility, + handle_set_generic_property, + handle_close, +}; +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + +SDL_bool +Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) +{ + SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + const Uint32 version = ((((Uint32) info->version.major) * 1000000) + + (((Uint32) info->version.minor) * 10000) + + (((Uint32) info->version.patch))); + + /* Before 2.0.6, it was possible to build an SDL with Wayland support + (SDL_SysWMinfo will be large enough to hold Wayland info), but build + your app against SDL headers that didn't have Wayland support + (SDL_SysWMinfo could be smaller than Wayland needs. This would lead + to an app properly using SDL_GetWindowWMInfo() but we'd accidentally + overflow memory on the stack or heap. To protect against this, we've + padded out the struct unconditionally in the headers and Wayland will + just return an error for older apps using this function. Those apps + will need to be recompiled against newer headers or not use Wayland, + maybe by forcing SDL_VIDEODRIVER=x11. */ + if (version < 2000006) { + info->subsystem = SDL_SYSWM_UNKNOWN; + SDL_SetError("Version must be 2.0.6 or newer"); + return SDL_FALSE; + } + + info->info.wl.display = data->waylandData->display; + info->info.wl.surface = data->surface; + info->info.wl.shell_surface = data->shell_surface.wl; + info->subsystem = SDL_SYSWM_WAYLAND; + + return SDL_TRUE; +} + +int +Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled) +{ + return 0; /* just succeed, the real work is done elsewhere. */ +} + +static void +SetFullscreen(_THIS, SDL_Window * window, struct wl_output *output) +{ + const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata; + SDL_WindowData *wind = window->driverdata; + + if (viddata->shell.xdg) { + if (output) { + xdg_toplevel_set_fullscreen(wind->shell_surface.xdg.roleobj.toplevel, output); + } else { + xdg_toplevel_unset_fullscreen(wind->shell_surface.xdg.roleobj.toplevel); + } + } else if (viddata->shell.zxdg) { + if (output) { + zxdg_toplevel_v6_set_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel, output); + } else { + zxdg_toplevel_v6_unset_fullscreen(wind->shell_surface.zxdg.roleobj.toplevel); + } + } else { + if (output) { + wl_shell_surface_set_fullscreen(wind->shell_surface.wl, + WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, + 0, output); + } else { + wl_shell_surface_set_toplevel(wind->shell_surface.wl); + } + } + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + +void Wayland_ShowWindow(_THIS, SDL_Window *window) +{ + struct wl_output *output = (struct wl_output *) window->fullscreen_mode.driverdata; + SetFullscreen(_this, window, (window->flags & SDL_WINDOW_FULLSCREEN) ? output : NULL); +} + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH +static void SDLCALL +QtExtendedSurface_OnHintChanged(void *userdata, const char *name, + const char *oldValue, const char *newValue) +{ + struct qt_extended_surface *qt_extended_surface = userdata; + + if (name == NULL) { + return; + } + + if (strcmp(name, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION) == 0) { + int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION; + + if (newValue != NULL) { + if (strcmp(newValue, "portrait") == 0) { + orientation = QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION; + } else if (strcmp(newValue, "landscape") == 0) { + orientation = QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION; + } else if (strcmp(newValue, "inverted-portrait") == 0) { + orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION; + } else if (strcmp(newValue, "inverted-landscape") == 0) { + orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION; + } + } + + qt_extended_surface_set_content_orientation(qt_extended_surface, orientation); + } else if (strcmp(name, SDL_HINT_QTWAYLAND_WINDOW_FLAGS) == 0) { + uint32_t flags = 0; + + if (newValue != NULL) { + char *tmp = strdup(newValue); + char *saveptr = NULL; + + char *flag = strtok_r(tmp, " ", &saveptr); + while (flag) { + if (strcmp(flag, "OverridesSystemGestures") == 0) { + flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES; + } else if (strcmp(flag, "StaysOnTop") == 0) { + flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP; + } else if (strcmp(flag, "BypassWindowManager") == 0) { + // See https://github.com/qtproject/qtwayland/commit/fb4267103d + flags |= 4 /* QT_EXTENDED_SURFACE_WINDOWFLAG_BYPASSWINDOWMANAGER */; + } + + flag = strtok_r(NULL, " ", &saveptr); + } + + free(tmp); + } + + qt_extended_surface_set_window_flags(qt_extended_surface, flags); + } +} + +static void QtExtendedSurface_Subscribe(struct qt_extended_surface *surface, const char *name) +{ + SDL_AddHintCallback(name, QtExtendedSurface_OnHintChanged, surface); +} + +static void QtExtendedSurface_Unsubscribe(struct qt_extended_surface *surface, const char *name) +{ + SDL_DelHintCallback(name, QtExtendedSurface_OnHintChanged, surface); +} +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + +void +Wayland_SetWindowFullscreen(_THIS, SDL_Window * window, + SDL_VideoDisplay * _display, SDL_bool fullscreen) +{ + struct wl_output *output = (struct wl_output *) _display->driverdata; + SetFullscreen(_this, window, fullscreen ? output : NULL); +} + +void +Wayland_RestoreWindow(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + const SDL_VideoData *viddata = (const SDL_VideoData *) _this->driverdata; + + if (viddata->shell.xdg) { + } else if (viddata->shell.zxdg) { + } else { + wl_shell_surface_set_toplevel(wind->shell_surface.wl); + } + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + +void +Wayland_MaximizeWindow(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata; + + if (viddata->shell.xdg) { + xdg_toplevel_set_maximized(wind->shell_surface.xdg.roleobj.toplevel); + } else if (viddata->shell.zxdg) { + zxdg_toplevel_v6_set_maximized(wind->shell_surface.zxdg.roleobj.toplevel); + } else { + wl_shell_surface_set_maximized(wind->shell_surface.wl, NULL); + } + + WAYLAND_wl_display_flush( viddata->display ); +} + +int Wayland_CreateWindow(_THIS, SDL_Window *window) +{ + SDL_WindowData *data; + SDL_VideoData *c; + struct wl_region *region; + + data = calloc(1, sizeof *data); + if (data == NULL) + return SDL_OutOfMemory(); + + c = _this->driverdata; + window->driverdata = data; + + if (!(window->flags & SDL_WINDOW_OPENGL)) { + SDL_GL_LoadLibrary(NULL); + window->flags |= SDL_WINDOW_OPENGL; + } + + if (window->x == SDL_WINDOWPOS_UNDEFINED) { + window->x = 0; + } + if (window->y == SDL_WINDOWPOS_UNDEFINED) { + window->y = 0; + } + + data->waylandData = c; + data->sdlwindow = window; + + data->surface = + wl_compositor_create_surface(c->compositor); + wl_surface_set_user_data(data->surface, data); + + if (c->shell.xdg) { + data->shell_surface.xdg.surface = xdg_wm_base_get_xdg_surface(c->shell.xdg, data->surface); + /* !!! FIXME: add popup role */ + data->shell_surface.xdg.roleobj.toplevel = xdg_surface_get_toplevel(data->shell_surface.xdg.surface); + xdg_toplevel_add_listener(data->shell_surface.xdg.roleobj.toplevel, &toplevel_listener_xdg, data); + xdg_toplevel_set_app_id(data->shell_surface.xdg.roleobj.toplevel, c->classname); + } else if (c->shell.zxdg) { + data->shell_surface.zxdg.surface = zxdg_shell_v6_get_xdg_surface(c->shell.zxdg, data->surface); + /* !!! FIXME: add popup role */ + data->shell_surface.zxdg.roleobj.toplevel = zxdg_surface_v6_get_toplevel(data->shell_surface.zxdg.surface); + zxdg_toplevel_v6_add_listener(data->shell_surface.zxdg.roleobj.toplevel, &toplevel_listener_zxdg, data); + zxdg_toplevel_v6_set_app_id(data->shell_surface.zxdg.roleobj.toplevel, c->classname); + } else { + data->shell_surface.wl = wl_shell_get_shell_surface(c->shell.wl, data->surface); + wl_shell_surface_set_class(data->shell_surface.wl, c->classname); + } + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + if (c->surface_extension) { + data->extended_surface = qt_surface_extension_get_extended_surface( + c->surface_extension, data->surface); + + QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION); + QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS); + } +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + + data->egl_window = WAYLAND_wl_egl_window_create(data->surface, + window->w, window->h); + + /* Create the GLES window surface */ + data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window); + + if (data->egl_surface == EGL_NO_SURFACE) { + return SDL_SetError("failed to create a window surface"); + } + + if (c->shell.xdg) { + if (data->shell_surface.xdg.surface) { + xdg_surface_set_user_data(data->shell_surface.xdg.surface, data); + xdg_surface_add_listener(data->shell_surface.xdg.surface, &shell_surface_listener_xdg, data); + } + } else if (c->shell.zxdg) { + if (data->shell_surface.zxdg.surface) { + zxdg_surface_v6_set_user_data(data->shell_surface.zxdg.surface, data); + zxdg_surface_v6_add_listener(data->shell_surface.zxdg.surface, &shell_surface_listener_zxdg, data); + } + } else { + if (data->shell_surface.wl) { + wl_shell_surface_set_user_data(data->shell_surface.wl, data); + wl_shell_surface_add_listener(data->shell_surface.wl, &shell_surface_listener_wl, data); + } + } + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + if (data->extended_surface) { + qt_extended_surface_set_user_data(data->extended_surface, data); + qt_extended_surface_add_listener(data->extended_surface, + &extended_surface_listener, data); + } +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + + region = wl_compositor_create_region(c->compositor); + wl_region_add(region, 0, 0, window->w, window->h); + wl_surface_set_opaque_region(data->surface, region); + wl_region_destroy(region); + + if (c->relative_mouse_mode) { + Wayland_input_lock_pointer(c->input); + } + + wl_surface_commit(data->surface); + WAYLAND_wl_display_flush(c->display); + + /* we have to wait until the surface gets a "configure" event, or + use of this surface will fail. This is a new rule for xdg_shell. */ + if (c->shell.xdg) { + if (data->shell_surface.xdg.surface) { + while (!data->shell_surface.xdg.initial_configure_seen) { + WAYLAND_wl_display_flush(c->display); + WAYLAND_wl_display_dispatch(c->display); + } + } + } else if (c->shell.zxdg) { + if (data->shell_surface.zxdg.surface) { + while (!data->shell_surface.zxdg.initial_configure_seen) { + WAYLAND_wl_display_flush(c->display); + WAYLAND_wl_display_dispatch(c->display); + } + } + } + + return 0; +} + +void Wayland_SetWindowSize(_THIS, SDL_Window * window) +{ + SDL_VideoData *data = _this->driverdata; + SDL_WindowData *wind = window->driverdata; + struct wl_region *region; + + WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); + + region =wl_compositor_create_region(data->compositor); + wl_region_add(region, 0, 0, window->w, window->h); + wl_surface_set_opaque_region(wind->surface, region); + wl_region_destroy(region); +} + +void Wayland_SetWindowTitle(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata; + + if (window->title != NULL) { + if (viddata->shell.xdg) { + xdg_toplevel_set_title(wind->shell_surface.xdg.roleobj.toplevel, window->title); + } else if (viddata->shell.zxdg) { + zxdg_toplevel_v6_set_title(wind->shell_surface.zxdg.roleobj.toplevel, window->title); + } else { + wl_shell_surface_set_title(wind->shell_surface.wl, window->title); + } + } + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + +void Wayland_DestroyWindow(_THIS, SDL_Window *window) +{ + SDL_VideoData *data = _this->driverdata; + SDL_WindowData *wind = window->driverdata; + + if (data) { + SDL_EGL_DestroySurface(_this, wind->egl_surface); + WAYLAND_wl_egl_window_destroy(wind->egl_window); + + if (data->shell.xdg) { + if (wind->shell_surface.xdg.roleobj.toplevel) { + xdg_toplevel_destroy(wind->shell_surface.xdg.roleobj.toplevel); + } + if (wind->shell_surface.zxdg.surface) { + xdg_surface_destroy(wind->shell_surface.xdg.surface); + } + } else if (data->shell.zxdg) { + if (wind->shell_surface.zxdg.roleobj.toplevel) { + zxdg_toplevel_v6_destroy(wind->shell_surface.zxdg.roleobj.toplevel); + } + if (wind->shell_surface.zxdg.surface) { + zxdg_surface_v6_destroy(wind->shell_surface.zxdg.surface); + } + } else { + if (wind->shell_surface.wl) { + wl_shell_surface_destroy(wind->shell_surface.wl); + } + } + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + if (wind->extended_surface) { + QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION); + QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS); + qt_extended_surface_destroy(wind->extended_surface); + } +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ + wl_surface_destroy(wind->surface); + + SDL_free(wind); + WAYLAND_wl_display_flush(data->display); + } + window->driverdata = NULL; +} + +#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/source/3rd-party/SDL2/src/video/wayland/SDL_waylandwindow.h b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandwindow.h new file mode 100644 index 0000000..69b9889 --- /dev/null +++ b/source/3rd-party/SDL2/src/video/wayland/SDL_waylandwindow.h @@ -0,0 +1,88 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "../../SDL_internal.h" + +#ifndef SDL_waylandwindow_h_ +#define SDL_waylandwindow_h_ + +#include "../SDL_sysvideo.h" +#include "SDL_syswm.h" + +#include "SDL_waylandvideo.h" + +struct SDL_WaylandInput; + +typedef struct { + struct zxdg_surface_v6 *surface; + union { + struct zxdg_toplevel_v6 *toplevel; + struct zxdg_popup_v6 *popup; + } roleobj; + SDL_bool initial_configure_seen; +} SDL_zxdg_shell_surface; + +typedef struct { + struct xdg_surface *surface; + union { + struct xdg_toplevel *toplevel; + struct xdg_popup *popup; + } roleobj; + SDL_bool initial_configure_seen; +} SDL_xdg_shell_surface; + +typedef struct { + SDL_Window *sdlwindow; + SDL_VideoData *waylandData; + struct wl_surface *surface; + union { + SDL_xdg_shell_surface xdg; + SDL_zxdg_shell_surface zxdg; + struct wl_shell_surface *wl; + } shell_surface; + struct wl_egl_window *egl_window; + struct SDL_WaylandInput *keyboard_device; + EGLSurface egl_surface; + struct zwp_locked_pointer_v1 *locked_pointer; + +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH + struct qt_extended_surface *extended_surface; +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ +} SDL_WindowData; + +extern void Wayland_ShowWindow(_THIS, SDL_Window *window); +extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window, + SDL_VideoDisplay * _display, + SDL_bool fullscreen); +extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window); +extern void Wayland_RestoreWindow(_THIS, SDL_Window * window); +extern int Wayland_CreateWindow(_THIS, SDL_Window *window); +extern void Wayland_SetWindowSize(_THIS, SDL_Window * window); +extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window); +extern void Wayland_DestroyWindow(_THIS, SDL_Window *window); + +extern SDL_bool +Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info); +extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled); + +#endif /* SDL_waylandwindow_h_ */ + +/* vi: set ts=4 sw=4 expandtab: */ |