diff options
-rw-r--r-- | src/protocols/core/Seat.cpp | 24 | ||||
-rw-r--r-- | src/protocols/core/Seat.hpp | 4 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/protocols/core/Seat.cpp b/src/protocols/core/Seat.cpp index 6ae0ddc4..d95e0e12 100644 --- a/src/protocols/core/Seat.cpp +++ b/src/protocols/core/Seat.cpp @@ -317,12 +317,13 @@ void CWLKeyboardResource::sendKeymap(SP<IKeyboard> keyboard) { if (!(PROTO::seat->currentCaps & eHIDCapabilityType::HID_INPUT_CAPABILITY_KEYBOARD)) return; - wl_keyboard_keymap_format format = keyboard ? WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 : WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP; - int fd; - uint32_t size; + std::string_view keymap; + int fd; + uint32_t size; if (keyboard) { - fd = keyboard->xkbKeymapFD; - size = keyboard->xkbKeymapString.length() + 1; + keymap = keyboard->xkbKeymapString; + fd = keyboard->xkbKeymapFD; + size = keyboard->xkbKeymapString.length() + 1; } else { fd = open("/dev/null", O_RDONLY | O_CLOEXEC); if (fd < 0) { @@ -332,6 +333,15 @@ void CWLKeyboardResource::sendKeymap(SP<IKeyboard> keyboard) { size = 0; } + if (keymap == lastKeymap) { + if (!keyboard) + close(fd); + return; + } + lastKeymap = keymap; + + const wl_keyboard_keymap_format format = keyboard ? WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 : WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP; + resource->sendKeymap(format, fd, size); if (!keyboard) @@ -396,8 +406,10 @@ void CWLKeyboardResource::sendMods(uint32_t depressed, uint32_t latched, uint32_ } void CWLKeyboardResource::repeatInfo(uint32_t rate, uint32_t delayMs) { - if (!owner || resource->version() < 4) + if (!owner || resource->version() < 4 || (rate == lastRate && delayMs == lastDelayMs)) return; + lastRate = rate; + lastDelayMs = delayMs; resource->sendRepeatInfo(rate, delayMs); } diff --git a/src/protocols/core/Seat.hpp b/src/protocols/core/Seat.hpp index 755a9c2f..1b43dd04 100644 --- a/src/protocols/core/Seat.hpp +++ b/src/protocols/core/Seat.hpp @@ -119,6 +119,10 @@ class CWLKeyboardResource { struct { CHyprSignalListener destroySurface; } listeners; + + std::string lastKeymap = "<none>"; + uint32_t lastRate = 0; + uint32_t lastDelayMs = 0; }; class CWLSeatResource { |