input-capture: fixes

This commit is contained in:
Gwilherm Folliot 2024-09-30 17:13:37 +02:00
parent 124582b8d2
commit ad6cbb0f46
No known key found for this signature in database
GPG key ID: 90236D3623DCD660
2 changed files with 18 additions and 32 deletions

View file

@ -7,24 +7,16 @@ 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) {
RESOURCE->setCapture([this](CHyprlandInputCaptureManagerV1* p) {
Debug::log(LOG, "[input-capture] Input captured");
active = true;
}
void CInputCaptureProtocol::onRelease(CHyprlandInputCaptureManagerV1* pMgr) {
});
RESOURCE->setRelease([this](CHyprlandInputCaptureManagerV1* p) {
Debug::log(LOG, "[input-capture] Input released");
active = false;
});
}
bool CInputCaptureProtocol::isCaptured() {
@ -32,44 +24,43 @@ bool CInputCaptureProtocol::isCaptured() {
}
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();
}
}

View file

@ -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;
};