diff options
Diffstat (limited to 'intern/ghost/intern/GHOST_SystemWayland.cpp')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWayland.cpp | 83 |
1 files changed, 60 insertions, 23 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index f54a022f249..38700845405 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -47,12 +47,20 @@ #include <xkbcommon/xkbcommon.h> #include <fcntl.h> -#include <linux/input-event-codes.h> #include <sys/mman.h> #include <unistd.h> #include <cstring> +/* selected input event code defines from 'linux/input-event-codes.h' + * We include some of the button input event codes here, since the header is + * only available in more recent kernel versions. The event codes are used to + * to differentiate from which mouse button an event comes from. + */ +#define BTN_LEFT 0x110 +#define BTN_RIGHT 0x111 +#define BTN_MIDDLE 0x112 + struct buffer_t { void *data; size_t size; @@ -468,7 +476,7 @@ static const zwp_relative_pointer_v1_listener relative_pointer_listener = { static void dnd_events(const input_t *const input, const GHOST_TEventType event) { - const GHOST_TUns64 time = input->system->getMilliSeconds(); + const uint64_t time = input->system->getMilliSeconds(); GHOST_IWindow *const window = static_cast<GHOST_WindowWayland *>( wl_surface_get_user_data(input->focus_pointer)); for (const std::string &type : mime_preference_order) { @@ -718,10 +726,9 @@ static void data_device_drop(void *data, struct wl_data_device * /*wl_data_devic GHOST_TStringArray *flist = static_cast<GHOST_TStringArray *>( malloc(sizeof(GHOST_TStringArray))); flist->count = int(uris.size()); - flist->strings = static_cast<GHOST_TUns8 **>(malloc(uris.size() * sizeof(GHOST_TUns8 *))); + flist->strings = static_cast<uint8_t **>(malloc(uris.size() * sizeof(uint8_t *))); for (size_t i = 0; i < uris.size(); i++) { - flist->strings[i] = static_cast<GHOST_TUns8 *>( - malloc((uris[i].size() + 1) * sizeof(GHOST_TUns8))); + flist->strings[i] = static_cast<uint8_t *>(malloc((uris[i].size() + 1) * sizeof(uint8_t))); memcpy(flist->strings[i], uris[i].data(), uris[i].size() + 1); } GHOST_IWindow *win = static_cast<GHOST_WindowWayland *>( @@ -1171,7 +1178,7 @@ static void keyboard_key(void *data, .key_data = key_data, }); - auto cb = [](GHOST_ITimerTask *task, GHOST_TUns64 /*time*/) { + auto cb = [](GHOST_ITimerTask *task, uint64_t /*time*/) { struct key_repeat_payload_t *payload = static_cast<key_repeat_payload_t *>( task->getUserData()); payload->system->pushEvent(new GHOST_EventKey(payload->system->getMilliSeconds(), @@ -1511,14 +1518,14 @@ GHOST_TSuccess GHOST_SystemWayland::getButtons(GHOST_Buttons &buttons) const return GHOST_kFailure; } -GHOST_TUns8 *GHOST_SystemWayland::getClipboard(bool /*selection*/) const +char *GHOST_SystemWayland::getClipboard(bool /*selection*/) const { - GHOST_TUns8 *clipboard = static_cast<GHOST_TUns8 *>(malloc((selection.size() + 1))); + char *clipboard = static_cast<char *>(malloc((selection.size() + 1))); memcpy(clipboard, selection.data(), selection.size() + 1); return clipboard; } -void GHOST_SystemWayland::putClipboard(GHOST_TInt8 *buffer, bool /*selection*/) const +void GHOST_SystemWayland::putClipboard(const char *buffer, bool /*selection*/) const { if (!d->data_device_manager || d->inputs.empty()) { return; @@ -1545,12 +1552,12 @@ void GHOST_SystemWayland::putClipboard(GHOST_TInt8 *buffer, bool /*selection*/) } } -GHOST_TUns8 GHOST_SystemWayland::getNumDisplays() const +uint8_t GHOST_SystemWayland::getNumDisplays() const { - return d ? GHOST_TUns8(d->outputs.size()) : 0; + return d ? uint8_t(d->outputs.size()) : 0; } -GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(GHOST_TInt32 &x, GHOST_TInt32 &y) const +GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(int32_t &x, int32_t &y) const { if (!d->inputs.empty() && (d->inputs[0]->focus_pointer != nullptr)) { x = d->inputs[0]->x; @@ -1562,12 +1569,12 @@ GHOST_TSuccess GHOST_SystemWayland::getCursorPosition(GHOST_TInt32 &x, GHOST_TIn } } -GHOST_TSuccess GHOST_SystemWayland::setCursorPosition(GHOST_TInt32 /*x*/, GHOST_TInt32 /*y*/) +GHOST_TSuccess GHOST_SystemWayland::setCursorPosition(int32_t /*x*/, int32_t /*y*/) { return GHOST_kFailure; } -void GHOST_SystemWayland::getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const +void GHOST_SystemWayland::getMainDisplayDimensions(uint32_t &width, uint32_t &height) const { if (getNumDisplays() > 0) { /* We assume first output as main. */ @@ -1576,7 +1583,7 @@ void GHOST_SystemWayland::getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TU } } -void GHOST_SystemWayland::getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const +void GHOST_SystemWayland::getAllDisplayDimensions(uint32_t &width, uint32_t &height) const { getMainDisplayDimensions(width, height); } @@ -1640,10 +1647,10 @@ GHOST_TSuccess GHOST_SystemWayland::disposeContext(GHOST_IContext *context) } GHOST_IWindow *GHOST_SystemWayland::createWindow(const char *title, - GHOST_TInt32 left, - GHOST_TInt32 top, - GHOST_TUns32 width, - GHOST_TUns32 height, + int32_t left, + int32_t top, + uint32_t width, + uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type, GHOST_GLSettings glSettings, @@ -1780,8 +1787,8 @@ GHOST_TSuccess GHOST_SystemWayland::hasCursorShape(GHOST_TStandardCursor cursorS return GHOST_TSuccess(cursors.count(cursorShape) && !cursors.at(cursorShape).empty()); } -GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(GHOST_TUns8 *bitmap, - GHOST_TUns8 *mask, +GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap, + uint8_t *mask, int sizex, int sizey, int hotX, @@ -1797,13 +1804,43 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(GHOST_TUns8 *bitmap, static const int32_t stride = sizex * 4; /* ARGB */ cursor->file_buffer->size = size_t(stride * sizey); +#ifdef HAVE_MEMFD_CREATE const int fd = memfd_create("blender-cursor-custom", MFD_CLOEXEC | MFD_ALLOW_SEALING); - fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK); - posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)); + if (fd >= 0) { + fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL); + } +#else + char *path = getenv("XDG_RUNTIME_DIR"); + if (!path) { + errno = ENOENT; + return GHOST_kFailure; + } + + char *tmpname; + asprintf(&tmpname, "%s/%s", path, "blender-XXXXXX"); + const int fd = mkostemp(tmpname, O_CLOEXEC); + if (fd >= 0) { + unlink(tmpname); + } + free(tmpname); +#endif + + if (fd < 0) { + return GHOST_kFailure; + } + + if (posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)) != 0) { + return GHOST_kFailure; + } cursor->file_buffer->data = mmap( nullptr, cursor->file_buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (cursor->file_buffer->data == MAP_FAILED) { + close(fd); + return GHOST_kFailure; + } + struct wl_shm_pool *pool = wl_shm_create_pool(d->shm, fd, int32_t(cursor->file_buffer->size)); wl_buffer *buffer = wl_shm_pool_create_buffer( |