Skip to content

Commit

Permalink
input-capture: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
3l0w committed Sep 30, 2024
1 parent d22653e commit 13b376f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ protocolnew("staging/drm-lease" "drm-lease-v1" false)
protocolnew("staging/linux-drm-syncobj" "linux-drm-syncobj-v1" false)
protocolnew("staging/xdg-dialog" "xdg-dialog-v1" false)
protocolnew("staging/single-pixel-buffer" "single-pixel-buffer-v1" false)

protocolnew("subprojects/hyprland-protocols/protocols" "hyprland-input-capture-v1"
true)

protocolwayland()

# tools
Expand Down
43 changes: 17 additions & 26 deletions src/protocols/InputCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,60 @@ CInputCaptureProtocol::CInputCaptureProtocol(const wl_interface* iface, const in
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();

RESOURCE->setOnDestroy([this](CHyprlandInputCaptureManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setOnDestroy([this](CHyprlandInputCaptureManagerV1* p) { std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == p->resource(); }); });

RESOURCE->setCapture([this](CHyprlandInputCaptureManagerV1* p) { this->onCapture(p); });
RESOURCE->setRelease([this](CHyprlandInputCaptureManagerV1* p) { this->onRelease(p); });
}

void CInputCaptureProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
}

void CInputCaptureProtocol::onCapture(CHyprlandInputCaptureManagerV1* pMgr) {
Debug::log(LOG, "[input-capture] Input captured");
active = true;
}

void CInputCaptureProtocol::onRelease(CHyprlandInputCaptureManagerV1* pMgr) {
Debug::log(LOG, "[input-capture] Input released");
active = false;
RESOURCE->setCapture([this](CHyprlandInputCaptureManagerV1* p) {
Debug::log(LOG, "[input-capture] Input captured");
active = true;
});
RESOURCE->setRelease([this](CHyprlandInputCaptureManagerV1* p) {
Debug::log(LOG, "[input-capture] Input released");
active = false;
});
}

bool CInputCaptureProtocol::isCaptured() {
return active;
}

void CInputCaptureProtocol::sendMotion(const Vector2D& absolutePosition, const Vector2D& delta) {
for (const UP<CHyprlandInputCaptureManagerV1>& 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));
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::sendKey(uint32_t keyCode, hyprlandInputCaptureManagerV1KeyState state) {
for (const UP<CHyprlandInputCaptureManagerV1>& manager : m_vManagers) {
for (const auto& manager : m_vManagers) {
manager->sendKey(keyCode, state);
}
}

void CInputCaptureProtocol::sendButton(uint32_t button, hyprlandInputCaptureManagerV1ButtonState state) {
for (const UP<CHyprlandInputCaptureManagerV1>& manager : m_vManagers) {
for (const auto& manager : m_vManagers) {
manager->sendButton(button, state);
}
}

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

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

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

void CInputCaptureProtocol::sendFrame() {
for (const UP<CHyprlandInputCaptureManagerV1>& manager : m_vManagers) {
for (const auto& manager : m_vManagers) {
manager->sendFrame();
}
}
7 changes: 1 addition & 6 deletions src/protocols/InputCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 sendMotion(const Vector2D& absolutePosition, const Vector2D& delta);
Expand All @@ -23,11 +23,6 @@ class CInputCaptureProtocol : public IWaylandProtocol {

private:
bool active = false;

void onManagerResourceDestroy(wl_resource* res);
void onCapture(CHyprlandInputCaptureManagerV1* pMgr);
void onRelease(CHyprlandInputCaptureManagerV1* pMgr);

//
std::vector<UP<CHyprlandInputCaptureManagerV1>> m_vManagers;
};
Expand Down

0 comments on commit 13b376f

Please sign in to comment.