input-capture: impl keymap

This commit is contained in:
Gwilherm Folliot 2024-10-07 14:48:52 +02:00
parent ad6cbb0f46
commit e0321f721e
No known key found for this signature in database
GPG key ID: 90236D3623DCD660
4 changed files with 54 additions and 17 deletions

View file

@ -4,6 +4,7 @@
#include "../protocols/DataDeviceWlr.hpp" #include "../protocols/DataDeviceWlr.hpp"
#include "../protocols/PrimarySelection.hpp" #include "../protocols/PrimarySelection.hpp"
#include "../protocols/core/Compositor.hpp" #include "../protocols/core/Compositor.hpp"
#include "../protocols/InputCapture.hpp"
#include "../Compositor.hpp" #include "../Compositor.hpp"
#include "../devices/IKeyboard.hpp" #include "../devices/IKeyboard.hpp"
#include "wlr-layer-shell-unstable-v1.hpp" #include "wlr-layer-shell-unstable-v1.hpp"
@ -98,6 +99,7 @@ void CSeatManager::updateActiveKeyboardData() {
if (keyboard) if (keyboard)
PROTO::seat->updateRepeatInfo(keyboard->repeatRate, keyboard->repeatDelay); PROTO::seat->updateRepeatInfo(keyboard->repeatRate, keyboard->repeatDelay);
PROTO::seat->updateKeymap(); PROTO::seat->updateKeymap();
PROTO::inputCapture->updateKeymap();
} }
void CSeatManager::setKeyboardFocus(SP<CWLSurfaceResource> surf) { void CSeatManager::setKeyboardFocus(SP<CWLSurfaceResource> surf) {

View file

@ -1,11 +1,15 @@
#include "InputCapture.hpp" #include "InputCapture.hpp"
#include "../devices/IKeyboard.hpp"
#include "managers/SeatManager.hpp"
#include <fcntl.h>
CInputCaptureProtocol::CInputCaptureProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { CInputCaptureProtocol::CInputCaptureProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
; ;
} }
void CInputCaptureProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { void CInputCaptureProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CHyprlandInputCaptureManagerV1>(client, ver, id)).get(); const auto& RESOURCE = m_vManagers.emplace_back(std::make_unique<CHyprlandInputCaptureManagerV1>(client, ver, id));
RESOURCE->setOnDestroy([this](CHyprlandInputCaptureManagerV1* p) { std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == p->resource(); }); }); RESOURCE->setOnDestroy([this](CHyprlandInputCaptureManagerV1* p) { std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == p->resource(); }); });
@ -17,50 +21,78 @@ void CInputCaptureProtocol::bindManager(wl_client* client, void* data, uint32_t
Debug::log(LOG, "[input-capture] Input released"); Debug::log(LOG, "[input-capture] Input released");
active = false; active = false;
}); });
sendKeymap(g_pSeatManager->keyboard.lock(), RESOURCE);
} }
bool CInputCaptureProtocol::isCaptured() { bool CInputCaptureProtocol::isCaptured() {
return active; return active;
} }
void CInputCaptureProtocol::updateKeymap() {
for (const auto& manager : m_vManagers)
sendKeymap(g_pSeatManager->keyboard.lock(), manager);
}
void CInputCaptureProtocol::sendMotion(const Vector2D& absolutePosition, const Vector2D& delta) { void CInputCaptureProtocol::sendMotion(const Vector2D& absolutePosition, const Vector2D& delta) {
for (const auto& manager : m_vManagers) { for (const auto& manager : m_vManagers) {
manager->sendMotion(wl_fixed_from_double(absolutePosition.x), wl_fixed_from_double(absolutePosition.y), wl_fixed_from_double(delta.x), wl_fixed_from_double(delta.y)); manager->sendMotion(wl_fixed_from_double(absolutePosition.x), wl_fixed_from_double(absolutePosition.y), wl_fixed_from_double(delta.x), wl_fixed_from_double(delta.y));
} }
} }
void CInputCaptureProtocol::sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state) { void CInputCaptureProtocol::sendKeymap(SP<IKeyboard> keyboard, const std::unique_ptr<CHyprlandInputCaptureManagerV1>& manager) {
for (const auto& manager : m_vManagers) { if (!keyboard)
manager->sendKey(keyCode, state); return;
hyprlandInputCaptureManagerV1KeymapFormat format;
int fd;
uint32_t size;
if (keyboard) {
format = HYPRLAND_INPUT_CAPTURE_MANAGER_V1_KEYMAP_FORMAT_XKB_V1;
fd = keyboard->xkbKeymapFD;
size = keyboard->xkbKeymapString.length() + 1;
} else {
format = HYPRLAND_INPUT_CAPTURE_MANAGER_V1_KEYMAP_FORMAT_NO_KEYMAP;
fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
if (fd < 0) {
LOGM(ERR, "Failed to open /dev/null");
return;
} }
size = 0;
}
manager->sendKeymap(format, fd, size);
if (!keyboard)
close(fd);
}
void CInputCaptureProtocol::sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state) {
for (const auto& manager : m_vManagers)
manager->sendKey(keyCode, state);
} }
void CInputCaptureProtocol::sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state) { void CInputCaptureProtocol::sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state) {
for (const auto& manager : m_vManagers) { for (const auto& manager : m_vManagers)
manager->sendButton(button, state); manager->sendButton(button, state);
} }
}
void CInputCaptureProtocol::sendAxis(hyprlandInputCaptureManagerV1Axis axis, double value) { void CInputCaptureProtocol::sendAxis(hyprlandInputCaptureManagerV1Axis axis, double value) {
for (const auto& manager : m_vManagers) { for (const auto& manager : m_vManagers)
manager->sendAxis(axis, value); manager->sendAxis(axis, value);
} }
}
void CInputCaptureProtocol::sendAxisValue120(hyprlandInputCaptureManagerV1Axis axis, int32_t value120) { void CInputCaptureProtocol::sendAxisValue120(hyprlandInputCaptureManagerV1Axis axis, int32_t value120) {
for (const auto& manager : m_vManagers) { for (const auto& manager : m_vManagers)
manager->sendAxisValue120(axis, value120); manager->sendAxisValue120(axis, value120);
} }
}
void CInputCaptureProtocol::sendAxisStop(hyprlandInputCaptureManagerV1Axis axis) { void CInputCaptureProtocol::sendAxisStop(hyprlandInputCaptureManagerV1Axis axis) {
for (const auto& manager : m_vManagers) { for (const auto& manager : m_vManagers)
manager->sendAxisStop(axis); manager->sendAxisStop(axis);
} }
}
void CInputCaptureProtocol::sendFrame() { void CInputCaptureProtocol::sendFrame() {
for (const auto& manager : m_vManagers) { for (const auto& manager : m_vManagers)
manager->sendFrame(); manager->sendFrame();
} }
}

View file

@ -9,9 +9,10 @@ class CInputCaptureProtocol : public IWaylandProtocol {
CInputCaptureProtocol(const wl_interface* iface, const int& ver, const std::string& name); CInputCaptureProtocol(const wl_interface* iface, const int& ver, const std::string& name);
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
//
bool isCaptured(); bool isCaptured();
// void updateKeymap();
void sendMotion(const Vector2D& absolutePosition, const Vector2D& delta); void sendMotion(const Vector2D& absolutePosition, const Vector2D& delta);
void sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state); void sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state);
void sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state); void sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state);
@ -22,6 +23,8 @@ class CInputCaptureProtocol : public IWaylandProtocol {
void sendFrame(); void sendFrame();
private: private:
void sendKeymap(SP<IKeyboard> keyboard, const std::unique_ptr<CHyprlandInputCaptureManagerV1>& manager);
bool active = false; bool active = false;
// //
std::vector<UP<CHyprlandInputCaptureManagerV1>> m_vManagers; std::vector<UP<CHyprlandInputCaptureManagerV1>> m_vManagers;

@ -1 +1 @@
Subproject commit 479cc226451c264396a4c442710d6b56dce2fa46 Subproject commit d3674e1f4eac730efc01c08e794a988be31ec73e