diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-05-01 16:41:17 +0100 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-05-01 16:41:17 +0100 |
| commit | 8bcccf9f0f0f69986e315d4288dfdbf119dd19db (patch) | |
| tree | eebb6714fc1e41a0df2784ed22752f0efe2bbdc1 /src/helpers | |
| parent | 4ed6b69b68a544a81cec583a1ad8aff218f7db5d (diff) | |
ime-v2: move to new impl
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 35 | ||||
| -rw-r--r-- | src/helpers/MiscFunctions.hpp | 1 | ||||
| -rw-r--r-- | src/helpers/WLClasses.hpp | 8 |
3 files changed, 36 insertions, 8 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index b8061bef..22aa48f4 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -2,9 +2,12 @@ #include "../defines.hpp" #include <algorithm> #include "../Compositor.hpp" +#include "../managers/TokenManager.hpp" #include <optional> #include <set> #include <sys/utsname.h> +#include <sys/mman.h> +#include <fcntl.h> #include <iomanip> #include <sstream> #ifdef HAS_EXECINFO @@ -834,3 +837,35 @@ bool envEnabled(const std::string& env) { return false; return std::string(ENV) == "1"; } + +std::pair<int, std::string> openExclusiveShm() { + std::string name = g_pTokenManager->getRandomUUID(); + + for (size_t i = 0; i < 69; ++i) { + int fd = shm_open(name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); + if (fd >= 0) + return {fd, name}; + } + + return {-1, ""}; +} + +int allocateSHMFile(size_t len) { + auto [fd, name] = openExclusiveShm(); + if (fd < 0) + return -1; + + shm_unlink(name.c_str()); + + int ret; + do { + ret = ftruncate(fd, len); + } while (ret < 0 && errno == EINTR); + + if (ret < 0) { + close(fd); + return -1; + } + + return fd; +} diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index d8a86b95..80103eac 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -38,6 +38,7 @@ void throwError(const std::string& err); uint32_t drmFormatToGL(uint32_t drm); uint32_t glFormatToType(uint32_t gl); bool envEnabled(const std::string& env); +int allocateSHMFile(size_t len); template <typename... Args> [[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) { diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 024ac38d..2f14059b 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -218,14 +218,6 @@ struct SSwipeGesture { CMonitor* pMonitor = nullptr; }; -struct SIMEKbGrab { - wlr_input_method_keyboard_grab_v2* pWlrKbGrab = nullptr; - - wlr_keyboard* pKeyboard = nullptr; - - DYNLISTENER(grabDestroy); -}; - struct STouchDevice { wlr_input_device* pWlrDevice = nullptr; |
