input-capture: impl force release

This commit is contained in:
Gwilherm Folliot 2024-10-21 10:46:56 +02:00
parent 99121e00b2
commit cec147fb09
No known key found for this signature in database
GPG key ID: 90236D3623DCD660
3 changed files with 19 additions and 8 deletions

View file

@ -16,6 +16,8 @@
CInputCapturePortal::CInputCapturePortal(SP<CCHyprlandInputCaptureManagerV1> mgr) : m_sState(mgr) { CInputCapturePortal::CInputCapturePortal(SP<CCHyprlandInputCaptureManagerV1> mgr) : m_sState(mgr) {
Debug::log(LOG, "[input-capture] initializing input capture portal"); Debug::log(LOG, "[input-capture] initializing input capture portal");
mgr->setForceRelease([this](CCHyprlandInputCaptureManagerV1* r) { onForceRelease(); });
mgr->setMotion([this](CCHyprlandInputCaptureManagerV1* r, wl_fixed_t x, wl_fixed_t y, wl_fixed_t dx, wl_fixed_t dy) { mgr->setMotion([this](CCHyprlandInputCaptureManagerV1* r, wl_fixed_t x, wl_fixed_t y, wl_fixed_t dx, wl_fixed_t dy) {
onMotion(wl_fixed_to_double(x), wl_fixed_to_double(y), wl_fixed_to_double(dx), wl_fixed_to_double(dy)); onMotion(wl_fixed_to_double(x), wl_fixed_to_double(y), wl_fixed_to_double(dx), wl_fixed_to_double(dy));
}); });
@ -102,6 +104,9 @@ void CInputCapturePortal::onCreateSession(sdbus::MethodCall& call) {
session->session = createDBusSession(sessionHandle); session->session = createDBusSession(sessionHandle);
session->session->onDestroy = [session, this]() { session->session->onDestroy = [session, this]() {
disable(session->sessionHandle); disable(session->sessionHandle);
session->status = STOPPED;
session->eis->stopServer();
session->eis.reset();
Debug::log(LOG, "[input-capture] Session {} destroyed", session->sessionHandle.c_str()); Debug::log(LOG, "[input-capture] Session {} destroyed", session->sessionHandle.c_str());
@ -250,8 +255,10 @@ void CInputCapturePortal::onEnable(sdbus::MethodCall& call) {
Debug::log(LOG, "[input-capture] | {}", sessionHandle.c_str()); Debug::log(LOG, "[input-capture] | {}", sessionHandle.c_str());
Debug::log(LOG, "[input-capture] | appid: {}", appID); Debug::log(LOG, "[input-capture] | appid: {}", appID);
if (!sessionValid(sessionHandle)) if (!sessions.contains(sessionHandle)) {
Debug::log(WARN, "[input-capture] Unknown session handle: {}", sessionHandle.c_str());
return complete(call); return complete(call);
}
sessions[sessionHandle]->status = ENABLED; sessions[sessionHandle]->status = ENABLED;
@ -324,6 +331,12 @@ bool CInputCapturePortal::sessionValid(sdbus::ObjectPath sessionHandle) {
return sessions[sessionHandle]->status != STOPPED; return sessions[sessionHandle]->status != STOPPED;
} }
void CInputCapturePortal::onForceRelease() {
Debug::log(LOG, "[input-capture] Released every captures");
for (auto [key, value] : sessions)
disable(key);
}
bool get_line_intersection(double p0_x, double p0_y, double p1_x, double p1_y, double p2_x, double p2_y, double p3_x, double p3_y, double* i_x, double* i_y) { bool get_line_intersection(double p0_x, double p0_y, double p1_x, double p1_y, double p2_x, double p2_y, double p3_x, double p3_y, double* i_x, double* i_y) {
float s1_x, s1_y, s2_x, s2_y; float s1_x, s1_y, s2_x, s2_y;
s1_x = p1_x - p0_x; s1_x = p1_x - p0_x;
@ -510,10 +523,7 @@ void CInputCapturePortal::disable(sdbus::ObjectPath sessionHandle) {
if (!session->disable()) if (!session->disable())
return; return;
session->eis->stopServer(); auto signal = m_pObject->createSignal(INTERFACE_NAME, "Disabled");
session->eis.reset();
auto signal = m_pObject->createSignal(INTERFACE_NAME, "Disable");
signal << sessionHandle; signal << sessionHandle;
std::unordered_map<std::string, sdbus::Variant> options; std::unordered_map<std::string, sdbus::Variant> options;
@ -523,8 +533,8 @@ void CInputCapturePortal::disable(sdbus::ObjectPath sessionHandle) {
} }
bool CInputCapturePortal::SSession::disable() { bool CInputCapturePortal::SSession::disable() {
status = STOPPED; status = CREATED;
barriers.clear();
Debug::log(LOG, "[input-capture] Session {} disabled", sessionHandle.c_str()); Debug::log(LOG, "[input-capture] Session {} disabled", sessionHandle.c_str());
return true; return true;
} }

View file

@ -29,6 +29,7 @@ class CInputCapturePortal {
void onRelease(sdbus::MethodCall& methodCall); void onRelease(sdbus::MethodCall& methodCall);
void onConnectToEIS(sdbus::MethodCall& methodCall); void onConnectToEIS(sdbus::MethodCall& methodCall);
void onForceRelease();
void onMotion(double x, double y, double dx, double dy); void onMotion(double x, double y, double dx, double dy);
void onKeymap(int32_t fd, uint32_t size); void onKeymap(int32_t fd, uint32_t size);
void onKey(uint32_t key, bool pressed); void onKey(uint32_t key, bool pressed);

@ -1 +1 @@
Subproject commit d3674e1f4eac730efc01c08e794a988be31ec73e Subproject commit 0c7cf263faeae9429942c6ffbc1e9b5dfd709bf4