Changeset View
Standalone View
intern/ghost/intern/GHOST_SystemWayland.cpp
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| #include <pointer-constraints-client-protocol.h> | #include <pointer-constraints-client-protocol.h> | ||||
| #include <relative-pointer-client-protocol.h> | #include <relative-pointer-client-protocol.h> | ||||
| #include <wayland-cursor.h> | #include <wayland-cursor.h> | ||||
| #include <xkbcommon/xkbcommon.h> | #include <xkbcommon/xkbcommon.h> | ||||
| #include <fcntl.h> | #include <fcntl.h> | ||||
| #include <sys/mman.h> | #include <sys/mman.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <linux/version.h> | |||||
| #include <cstring> | #include <cstring> | ||||
| /* selected input event code defines from 'linux/input-event-codes.h' | /* 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 | * 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 | * only available in more recent kernel versions. The event codes are used to | ||||
| * to differentiate from which mouse button an event comes from. | * to differentiate from which mouse button an event comes from. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 1,739 Lines • ▼ Show 20 Lines | if (d->inputs.empty()) { | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| cursor_t *cursor = &d->inputs[0]->cursor; | cursor_t *cursor = &d->inputs[0]->cursor; | ||||
| static const int32_t stride = sizex * 4; /* ARGB */ | static const int32_t stride = sizex * 4; /* ARGB */ | ||||
| cursor->file_buffer->size = size_t(stride * sizey); | cursor->file_buffer->size = size_t(stride * sizey); | ||||
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0) | |||||
brecht: Not sure it's worth having Linux-specific code at all, especially if we want to have this… | |||||
Done Inline ActionsI don't think it is worth bothering about BSD until it is seriously considered to replace X11 for them and there is at least one distribution that makes use of Wayland by default. Further to this, I have no way (and interest) in testing this on BSD. Someone else has to provide the patches and test this on BSD with Wayland. christian.rauch: I don't think it is worth bothering about BSD until it is seriously considered to replace X11… | |||||
Done Inline ActionsNot expecting anyone to test this on BSD soon. But I just don't see the benefit in keeping the Linux-specific code when we now have a portable alternative. brecht: Not expecting anyone to test this on BSD soon. But I just don't see the benefit in keeping the… | |||||
Done Inline ActionsThis mkostemp + unlink is just a workaround, not identical behaviour. From https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/4:
in memory, without any backing file on the filesystem and the race It is Linux specific API, but it was created for a reason. The HAVE_MEMFD_CREATE solution in this pull request is actually a much better (portable) solution compared to my kernel version comparison. I am going to use this one too. christian.rauch: This `mkostemp` + `unlink` is just a workaround, not identical behaviour.
From https://gitlab. | |||||
Done Inline ActionsI cannot change my comment (and I cannot preview the formatting), but this is the fixed citation from the PR that justifies the use of memfd_create:
condition which could ensue when unlink()ing it. christian.rauch: I cannot change my comment (and I cannot preview the formatting), but this is the fixed… | |||||
Done Inline ActionsOk, one last try:
I really don't like this Blender review system :-) christian.rauch: Ok, one last try:
> This (so-far) Linux-only API lets users create file descriptors purely in… | |||||
| const int fd = memfd_create("blender-cursor-custom", MFD_CLOEXEC | MFD_ALLOW_SEALING); | const int fd = memfd_create("blender-cursor-custom", MFD_CLOEXEC | MFD_ALLOW_SEALING); | ||||
| fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK); | fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK); | ||||
| #else | |||||
| char *tmpname; | |||||
| asprintf(&tmpname, "%s/%s", getenv("XDG_RUNTIME_DIR"), "blender-XXXXXX"); | |||||
Done Inline Actionsgetenv("XDG_RUNTIME_DIR") can return NULL, needs to be checked. brecht: `getenv("XDG_RUNTIME_DIR")` can return `NULL`, needs to be checked. | |||||
| const int fd = mkostemp(tmpname, O_CLOEXEC); | |||||
| if (fd >= 0) { | |||||
| unlink(tmpname); | |||||
| } | |||||
| free(tmpname); | |||||
| if (fd < 0) { | |||||
| return GHOST_kFailure; | |||||
| } | |||||
| #endif | |||||
| posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)); | posix_fallocate(fd, 0, int32_t(cursor->file_buffer->size)); | ||||
| cursor->file_buffer->data = mmap( | cursor->file_buffer->data = mmap( | ||||
| nullptr, cursor->file_buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | nullptr, cursor->file_buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||||
Done Inline ActionsHandle mmap failure, and close fd in that case. brecht: Handle `mmap` failure, and close `fd` in that case. | |||||
| struct wl_shm_pool *pool = wl_shm_create_pool(d->shm, fd, int32_t(cursor->file_buffer->size)); | 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( | wl_buffer *buffer = wl_shm_pool_create_buffer( | ||||
| pool, 0, sizex, sizey, stride, WL_SHM_FORMAT_ARGB8888); | pool, 0, sizex, sizey, stride, WL_SHM_FORMAT_ARGB8888); | ||||
| wl_shm_pool_destroy(pool); | wl_shm_pool_destroy(pool); | ||||
| close(fd); | close(fd); | ||||
| ▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines | |||||
Not sure it's worth having Linux-specific code at all, especially if we want to have this running on BSDs as well eventually.