ikeyboard: move to CFileDescriptor

use CFileDescriptor instead of manual fd handling.
This commit is contained in:
Tom Englund 2024-11-21 04:08:54 +01:00
parent ee1e636d08
commit 983e67633f
3 changed files with 10 additions and 11 deletions

View file

@ -41,13 +41,10 @@ void IKeyboard::clearManuallyAllocd() {
if (xkbKeymap)
xkb_keymap_unref(xkbKeymap);
if (xkbKeymapFD >= 0)
close(xkbKeymapFD);
xkbKeymapFD.reset();
xkbKeymap = nullptr;
xkbState = nullptr;
xkbStaticState = nullptr;
xkbKeymapFD = -1;
}
void IKeyboard::setKeymap(const SStringRuleNames& rules) {
@ -143,9 +140,8 @@ void IKeyboard::setKeymap(const SStringRuleNames& rules) {
void IKeyboard::updateKeymapFD() {
Debug::log(LOG, "Updating keymap fd for keyboard {}", deviceName);
if (xkbKeymapFD >= 0)
close(xkbKeymapFD);
xkbKeymapFD = -1;
if (xkbKeymapFD.isValid())
xkbKeymapFD.reset();
auto cKeymapStr = xkb_keymap_get_as_string(xkbKeymap, XKB_KEYMAP_FORMAT_TEXT_V1);
xkbKeymapString = cKeymapStr;
@ -163,11 +159,11 @@ void IKeyboard::updateKeymapFD() {
} else {
memcpy(keymapFDDest, xkbKeymapString.c_str(), xkbKeymapString.length());
munmap(keymapFDDest, xkbKeymapString.length() + 1);
xkbKeymapFD = ro;
xkbKeymapFD = CFileDescriptor(ro);
}
}
Debug::log(LOG, "Updated keymap fd to {}", xkbKeymapFD);
Debug::log(LOG, "Updated keymap fd to {}", xkbKeymapFD.get());
}
void IKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) {

View file

@ -6,6 +6,9 @@
#include <optional>
#include <xkbcommon/xkbcommon.h>
#include <hyprutils/os/FileDescriptor.hpp>
using namespace Hyprutils::OS;
AQUAMARINE_FORWARD(IKeyboard);
@ -96,7 +99,7 @@ class IKeyboard : public IHID {
std::string xkbFilePath = "";
std::string xkbKeymapString = "";
int xkbKeymapFD = -1;
CFileDescriptor xkbKeymapFD;
SStringRuleNames currentRules;
int repeatRate = 0;

View file

@ -322,7 +322,7 @@ void CWLKeyboardResource::sendKeymap(SP<IKeyboard> keyboard) {
uint32_t size;
if (keyboard) {
keymap = keyboard->xkbKeymapString;
fd = keyboard->xkbKeymapFD;
fd = keyboard->xkbKeymapFD.get();
size = keyboard->xkbKeymapString.length() + 1;
} else {
fd = open("/dev/null", O_RDONLY | O_CLOEXEC);