mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-08 01:25:57 +01:00
unify session and request
This commit is contained in:
parent
f8a847109e
commit
3faa42ca5b
6 changed files with 96 additions and 47 deletions
|
@ -23,30 +23,6 @@ static const hyprland_global_shortcut_v1_listener shortcutListener = {
|
|||
|
||||
//
|
||||
|
||||
static void onCloseRequest(sdbus::MethodCall& call, CGlobalShortcutsPortal::SSession* sess) {
|
||||
Debug::log(TRACE, "[globalshortcuts] Close Request {}", (void*)sess);
|
||||
|
||||
if (!sess || !sess->request)
|
||||
return;
|
||||
|
||||
auto r = call.createReply();
|
||||
r.send();
|
||||
|
||||
sess->request.release();
|
||||
}
|
||||
|
||||
static void onCloseSession(sdbus::MethodCall& call, CGlobalShortcutsPortal::SSession* sess) {
|
||||
Debug::log(TRACE, "[globalshortcuts] Close Session {}", (void*)sess);
|
||||
|
||||
if (!sess || !sess->session)
|
||||
return;
|
||||
|
||||
auto r = call.createReply();
|
||||
r.send();
|
||||
|
||||
sess->session.release();
|
||||
}
|
||||
|
||||
CGlobalShortcutsPortal::SSession* CGlobalShortcutsPortal::getSession(sdbus::ObjectPath& path) {
|
||||
for (auto& s : m_vSessions) {
|
||||
if (s->sessionHandle == path)
|
||||
|
@ -73,14 +49,10 @@ void CGlobalShortcutsPortal::onCreateSession(sdbus::MethodCall& call) {
|
|||
const auto PSESSION = m_vSessions.emplace_back(std::make_unique<SSession>(appID, requestHandle, sessionHandle)).get();
|
||||
|
||||
// create objects
|
||||
PSESSION->request = sdbus::createObject(*g_pPortalManager->getConnection(), requestHandle);
|
||||
PSESSION->session = sdbus::createObject(*g_pPortalManager->getConnection(), sessionHandle);
|
||||
|
||||
PSESSION->request->registerMethod("org.freedesktop.impl.portal.Request", "Close", "", "", [PSESSION](sdbus::MethodCall c) { onCloseRequest(c, PSESSION); });
|
||||
PSESSION->session->registerMethod("org.freedesktop.impl.portal.Session", "Close", "", "", [PSESSION](sdbus::MethodCall c) { onCloseSession(c, PSESSION); });
|
||||
|
||||
PSESSION->request->finishRegistration();
|
||||
PSESSION->session->finishRegistration();
|
||||
PSESSION->session = createDBusSession(sessionHandle);
|
||||
PSESSION->session->onDestroy = [PSESSION]() { PSESSION->session.release(); };
|
||||
PSESSION->request = createDBusRequest(requestHandle);
|
||||
PSESSION->request->onDestroy = [PSESSION]() { PSESSION->request.release(); };
|
||||
|
||||
std::unordered_map<std::string, sdbus::Variant> opts;
|
||||
call >> opts;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
#include <protocols/hyprland-global-shortcuts-v1-protocol.h>
|
||||
#include "../shared/Session.hpp"
|
||||
|
||||
struct SKeybind {
|
||||
std::string id, description, preferredTrigger;
|
||||
|
@ -23,7 +24,8 @@ class CGlobalShortcutsPortal {
|
|||
struct SSession {
|
||||
std::string appid;
|
||||
sdbus::ObjectPath requestHandle, sessionHandle;
|
||||
std::unique_ptr<sdbus::IObject> request, session;
|
||||
std::unique_ptr<SDBusRequest> request;
|
||||
std::unique_ptr<SDBusSession> session;
|
||||
|
||||
bool registered = false;
|
||||
|
||||
|
|
|
@ -321,14 +321,10 @@ void CScreencopyPortal::onCreateSession(sdbus::MethodCall& call) {
|
|||
const auto PSESSION = m_vSessions.emplace_back(std::make_unique<SSession>(appID, requestHandle, sessionHandle)).get();
|
||||
|
||||
// create objects
|
||||
PSESSION->request = sdbus::createObject(*g_pPortalManager->getConnection(), requestHandle);
|
||||
PSESSION->session = sdbus::createObject(*g_pPortalManager->getConnection(), sessionHandle);
|
||||
|
||||
PSESSION->request->registerMethod("org.freedesktop.impl.portal.Request", "Close", "", "", [PSESSION](sdbus::MethodCall c) { onCloseRequest(c, PSESSION); });
|
||||
PSESSION->session->registerMethod("org.freedesktop.impl.portal.Session", "Close", "", "", [PSESSION](sdbus::MethodCall c) { onCloseSession(c, PSESSION); });
|
||||
|
||||
PSESSION->request->finishRegistration();
|
||||
PSESSION->session->finishRegistration();
|
||||
PSESSION->session = createDBusSession(sessionHandle);
|
||||
PSESSION->session->onDestroy = [PSESSION]() { PSESSION->session.release(); };
|
||||
PSESSION->request = createDBusRequest(requestHandle);
|
||||
PSESSION->request->onDestroy = [PSESSION]() { PSESSION->request.release(); };
|
||||
|
||||
auto reply = call.createReply();
|
||||
reply << (uint32_t)0;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <sdbus-c++/sdbus-c++.h>
|
||||
#include "../shared/ScreencopyShared.hpp"
|
||||
#include <gbm.h>
|
||||
#include "../shared/Session.hpp"
|
||||
|
||||
enum cursorModes
|
||||
{
|
||||
|
@ -61,13 +62,14 @@ class CScreencopyPortal {
|
|||
void onStart(sdbus::MethodCall& call);
|
||||
|
||||
struct SSession {
|
||||
std::string appid;
|
||||
sdbus::ObjectPath requestHandle, sessionHandle;
|
||||
uint32_t cursorMode = HIDDEN;
|
||||
uint32_t persistMode = 0;
|
||||
std::string appid;
|
||||
sdbus::ObjectPath requestHandle, sessionHandle;
|
||||
uint32_t cursorMode = HIDDEN;
|
||||
uint32_t persistMode = 0;
|
||||
|
||||
std::unique_ptr<sdbus::IObject> request, session;
|
||||
SSelectionData selection;
|
||||
std::unique_ptr<SDBusRequest> request;
|
||||
std::unique_ptr<SDBusSession> session;
|
||||
SSelectionData selection;
|
||||
|
||||
struct {
|
||||
bool active = false;
|
||||
|
|
59
src/shared/Session.cpp
Normal file
59
src/shared/Session.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "Session.hpp"
|
||||
#include "../core/PortalManager.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
|
||||
static void onCloseRequest(sdbus::MethodCall& call, SDBusRequest* req) {
|
||||
Debug::log(TRACE, "[internal] Close Request {}", (void*)req);
|
||||
|
||||
if (!req)
|
||||
return;
|
||||
|
||||
auto r = call.createReply();
|
||||
r.send();
|
||||
|
||||
req->onDestroy();
|
||||
req->object.release();
|
||||
}
|
||||
|
||||
static void onCloseSession(sdbus::MethodCall& call, SDBusSession* sess) {
|
||||
Debug::log(TRACE, "[internal] Close Session {}", (void*)sess);
|
||||
|
||||
if (!sess)
|
||||
return;
|
||||
|
||||
auto r = call.createReply();
|
||||
r.send();
|
||||
|
||||
sess->onDestroy();
|
||||
sess->object.release();
|
||||
}
|
||||
|
||||
std::unique_ptr<SDBusSession> createDBusSession(sdbus::ObjectPath handle) {
|
||||
Debug::log(TRACE, "[internal] Create Session {}", handle.c_str());
|
||||
|
||||
std::unique_ptr<SDBusSession> pSession = std::make_unique<SDBusSession>();
|
||||
const auto PSESSION = pSession.get();
|
||||
|
||||
pSession->object = sdbus::createObject(*g_pPortalManager->getConnection(), handle);
|
||||
|
||||
pSession->object->registerMethod("org.freedesktop.impl.portal.Session", "Close", "", "", [PSESSION](sdbus::MethodCall c) { onCloseSession(c, PSESSION); });
|
||||
|
||||
pSession->object->finishRegistration();
|
||||
|
||||
return pSession;
|
||||
}
|
||||
|
||||
std::unique_ptr<SDBusRequest> createDBusRequest(sdbus::ObjectPath handle) {
|
||||
Debug::log(TRACE, "[internal] Create Request {}", handle.c_str());
|
||||
|
||||
std::unique_ptr<SDBusRequest> pRequest = std::make_unique<SDBusRequest>();
|
||||
const auto PREQUEST = pRequest.get();
|
||||
|
||||
pRequest->object = sdbus::createObject(*g_pPortalManager->getConnection(), handle);
|
||||
|
||||
pRequest->object->registerMethod("org.freedesktop.impl.portal.Request", "Close", "", "", [PREQUEST](sdbus::MethodCall c) { onCloseRequest(c, PREQUEST); });
|
||||
|
||||
pRequest->object->finishRegistration();
|
||||
|
||||
return pRequest;
|
||||
}
|
18
src/shared/Session.hpp
Normal file
18
src/shared/Session.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
|
||||
struct SDBusSession {
|
||||
std::unique_ptr<sdbus::IObject> object;
|
||||
sdbus::ObjectPath handle;
|
||||
std::function<void()> onDestroy;
|
||||
};
|
||||
|
||||
struct SDBusRequest {
|
||||
std::unique_ptr<sdbus::IObject> object;
|
||||
sdbus::ObjectPath handle;
|
||||
std::function<void()> onDestroy;
|
||||
};
|
||||
|
||||
std::unique_ptr<SDBusSession> createDBusSession(sdbus::ObjectPath handle);
|
||||
std::unique_ptr<SDBusRequest> createDBusRequest(sdbus::ObjectPath handle);
|
Loading…
Reference in a new issue