Skip to content

Commit

Permalink
input-capture: impl keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
3l0w committed Oct 7, 2024
1 parent 13b376f commit 29214bb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/managers/SeatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../protocols/DataDeviceWlr.hpp"
#include "../protocols/PrimarySelection.hpp"
#include "../protocols/core/Compositor.hpp"
#include "../protocols/InputCapture.hpp"
#include "../Compositor.hpp"
#include "../devices/IKeyboard.hpp"
#include "wlr-layer-shell-unstable-v1.hpp"
Expand Down Expand Up @@ -98,6 +99,7 @@ void CSeatManager::updateActiveKeyboardData() {
if (keyboard)
PROTO::seat->updateRepeatInfo(keyboard->repeatRate, keyboard->repeatDelay);
PROTO::seat->updateKeymap();
PROTO::inputCapture->updateKeymap();
}

void CSeatManager::setKeyboardFocus(SP<CWLSurfaceResource> surf) {
Expand Down
58 changes: 45 additions & 13 deletions src/protocols/InputCapture.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#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) {
;
}

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(); }); });

Expand All @@ -17,50 +21,78 @@ void CInputCaptureProtocol::bindManager(wl_client* client, void* data, uint32_t
Debug::log(LOG, "[input-capture] Input released");
active = false;
});

sendKeymap(g_pSeatManager->keyboard.lock(), RESOURCE);
}

bool CInputCaptureProtocol::isCaptured() {
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) {
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));
}
}

void CInputCaptureProtocol::sendKeymap(SP<IKeyboard> keyboard, const std::unique_ptr<CHyprlandInputCaptureManagerV1>& manager) {
if (!keyboard)
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) {
for (const auto& manager : m_vManagers)
manager->sendKey(keyCode, 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);
}
}

void CInputCaptureProtocol::sendAxis(hyprlandInputCaptureManagerV1Axis axis, double value) {
for (const auto& manager : m_vManagers) {
for (const auto& manager : m_vManagers)
manager->sendAxis(axis, value);
}
}

void CInputCaptureProtocol::sendAxisValue120(hyprlandInputCaptureManagerV1Axis axis, int32_t value120) {
for (const auto& manager : m_vManagers) {
for (const auto& manager : m_vManagers)
manager->sendAxisValue120(axis, value120);
}
}

void CInputCaptureProtocol::sendAxisStop(hyprlandInputCaptureManagerV1Axis axis) {
for (const auto& manager : m_vManagers) {
for (const auto& manager : m_vManagers)
manager->sendAxisStop(axis);
}
}

void CInputCaptureProtocol::sendFrame() {
for (const auto& manager : m_vManagers) {
for (const auto& manager : m_vManagers)
manager->sendFrame();
}
}
7 changes: 5 additions & 2 deletions src/protocols/InputCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class CInputCaptureProtocol : public IWaylandProtocol {
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);

bool isCaptured();

//
bool isCaptured();

void updateKeymap();
void sendMotion(const Vector2D& absolutePosition, const Vector2D& delta);
void sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state);
void sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state);
Expand All @@ -22,6 +23,8 @@ class CInputCaptureProtocol : public IWaylandProtocol {
void sendFrame();

private:
void sendKeymap(SP<IKeyboard> keyboard, const std::unique_ptr<CHyprlandInputCaptureManagerV1>& manager);

bool active = false;
//
std::vector<UP<CHyprlandInputCaptureManagerV1>> m_vManagers;
Expand Down
2 changes: 1 addition & 1 deletion subprojects/hyprland-protocols

0 comments on commit 29214bb

Please sign in to comment.