mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 12:25:58 +01:00
ikeyboard: move to CFileDescriptor
use CFileDescriptor instead of manual fd handling.
This commit is contained in:
parent
ee1e636d08
commit
983e67633f
3 changed files with 10 additions and 11 deletions
|
@ -41,13 +41,10 @@ void IKeyboard::clearManuallyAllocd() {
|
||||||
if (xkbKeymap)
|
if (xkbKeymap)
|
||||||
xkb_keymap_unref(xkbKeymap);
|
xkb_keymap_unref(xkbKeymap);
|
||||||
|
|
||||||
if (xkbKeymapFD >= 0)
|
xkbKeymapFD.reset();
|
||||||
close(xkbKeymapFD);
|
|
||||||
|
|
||||||
xkbKeymap = nullptr;
|
xkbKeymap = nullptr;
|
||||||
xkbState = nullptr;
|
xkbState = nullptr;
|
||||||
xkbStaticState = nullptr;
|
xkbStaticState = nullptr;
|
||||||
xkbKeymapFD = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IKeyboard::setKeymap(const SStringRuleNames& rules) {
|
void IKeyboard::setKeymap(const SStringRuleNames& rules) {
|
||||||
|
@ -143,9 +140,8 @@ void IKeyboard::setKeymap(const SStringRuleNames& rules) {
|
||||||
void IKeyboard::updateKeymapFD() {
|
void IKeyboard::updateKeymapFD() {
|
||||||
Debug::log(LOG, "Updating keymap fd for keyboard {}", deviceName);
|
Debug::log(LOG, "Updating keymap fd for keyboard {}", deviceName);
|
||||||
|
|
||||||
if (xkbKeymapFD >= 0)
|
if (xkbKeymapFD.isValid())
|
||||||
close(xkbKeymapFD);
|
xkbKeymapFD.reset();
|
||||||
xkbKeymapFD = -1;
|
|
||||||
|
|
||||||
auto cKeymapStr = xkb_keymap_get_as_string(xkbKeymap, XKB_KEYMAP_FORMAT_TEXT_V1);
|
auto cKeymapStr = xkb_keymap_get_as_string(xkbKeymap, XKB_KEYMAP_FORMAT_TEXT_V1);
|
||||||
xkbKeymapString = cKeymapStr;
|
xkbKeymapString = cKeymapStr;
|
||||||
|
@ -163,11 +159,11 @@ void IKeyboard::updateKeymapFD() {
|
||||||
} else {
|
} else {
|
||||||
memcpy(keymapFDDest, xkbKeymapString.c_str(), xkbKeymapString.length());
|
memcpy(keymapFDDest, xkbKeymapString.c_str(), xkbKeymapString.length());
|
||||||
munmap(keymapFDDest, xkbKeymapString.length() + 1);
|
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) {
|
void IKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) {
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
#include <hyprutils/os/FileDescriptor.hpp>
|
||||||
|
|
||||||
|
using namespace Hyprutils::OS;
|
||||||
|
|
||||||
AQUAMARINE_FORWARD(IKeyboard);
|
AQUAMARINE_FORWARD(IKeyboard);
|
||||||
|
|
||||||
|
@ -96,7 +99,7 @@ class IKeyboard : public IHID {
|
||||||
|
|
||||||
std::string xkbFilePath = "";
|
std::string xkbFilePath = "";
|
||||||
std::string xkbKeymapString = "";
|
std::string xkbKeymapString = "";
|
||||||
int xkbKeymapFD = -1;
|
CFileDescriptor xkbKeymapFD;
|
||||||
|
|
||||||
SStringRuleNames currentRules;
|
SStringRuleNames currentRules;
|
||||||
int repeatRate = 0;
|
int repeatRate = 0;
|
||||||
|
|
|
@ -322,7 +322,7 @@ void CWLKeyboardResource::sendKeymap(SP<IKeyboard> keyboard) {
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
if (keyboard) {
|
if (keyboard) {
|
||||||
keymap = keyboard->xkbKeymapString;
|
keymap = keyboard->xkbKeymapString;
|
||||||
fd = keyboard->xkbKeymapFD;
|
fd = keyboard->xkbKeymapFD.get();
|
||||||
size = keyboard->xkbKeymapString.length() + 1;
|
size = keyboard->xkbKeymapString.length() + 1;
|
||||||
} else {
|
} else {
|
||||||
fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||||
|
|
Loading…
Reference in a new issue