@@ -65,15 +65,8 @@ SKeybind* CGlobalShortcutsPortal::registerShortcut(SSession* session, const DBus
6565 return PSHORTCUT;
6666}
6767
68- void CGlobalShortcutsPortal::onCreateSession (sdbus::MethodCall& call) {
69- sdbus::ObjectPath requestHandle, sessionHandle;
70-
71- call >> requestHandle;
72- call >> sessionHandle;
73-
74- std::string appID;
75- call >> appID;
76-
68+ dbUasv CGlobalShortcutsPortal::onCreateSession (sdbus::ObjectPath requestHandle, sdbus::ObjectPath sessionHandle, std::string appID,
69+ std::unordered_map<std::string, sdbus::Variant> opts) {
7770 Debug::log (LOG, " [globalshortcuts] New session:" );
7871 Debug::log (LOG, " [globalshortcuts] | {}" , requestHandle.c_str ());
7972 Debug::log (LOG, " [globalshortcuts] | {}" , sessionHandle.c_str ());
@@ -87,9 +80,6 @@ void CGlobalShortcutsPortal::onCreateSession(sdbus::MethodCall& call) {
8780 PSESSION->request = createDBusRequest (requestHandle);
8881 PSESSION->request ->onDestroy = [PSESSION]() { PSESSION->request .release (); };
8982
90- std::unordered_map<std::string, sdbus::Variant> opts;
91- call >> opts;
92-
9383 for (auto & [k, v] : opts) {
9484 if (k == " shortcuts" ) {
9585 PSESSION->registered = true ;
@@ -104,101 +94,86 @@ void CGlobalShortcutsPortal::onCreateSession(sdbus::MethodCall& call) {
10494 }
10595 }
10696
107- auto reply = call.createReply ();
108- reply << (uint32_t )0 ;
109- reply << std::unordered_map<std::string, sdbus::Variant>{};
110- reply.send ();
97+ return {0 , {}};
11198}
11299
113- void CGlobalShortcutsPortal::onBindShortcuts (sdbus::MethodCall& call) {
114- sdbus::ObjectPath sessionHandle, requestHandle;
115- call >> requestHandle;
116- call >> sessionHandle;
117-
100+ dbUasv CGlobalShortcutsPortal::onBindShortcuts (sdbus::ObjectPath requestHandle, sdbus::ObjectPath sessionHandle, std::vector<DBusShortcut> shortcuts, std::string appID,
101+ std::unordered_map<std::string, sdbus::Variant> opts) {
118102 Debug::log (LOG, " [globalshortcuts] Bind keys:" );
119103 Debug::log (LOG, " [globalshortcuts] | {}" , sessionHandle.c_str ());
120104
121- std::vector<DBusShortcut> shortcuts;
122- std::vector<DBusShortcut> shortcutsToReturn;
123- call >> shortcuts;
124-
125105 const auto PSESSION = getSession (sessionHandle);
126106
127107 if (!PSESSION) {
128108 Debug::log (ERR, " [globalshortcuts] No session?" );
129- return ;
109+ return { 1 , {}} ;
130110 }
131111
112+ std::vector<DBusShortcut> shortcutsToReturn;
113+
132114 PSESSION->registered = true ;
133115
134116 for (auto & s : shortcuts) {
135117 const auto * PSHORTCUT = registerShortcut (PSESSION, s);
136118
137119 std::unordered_map<std::string, sdbus::Variant> shortcutData;
138- shortcutData[" description" ] = PSHORTCUT->description ;
139- shortcutData[" trigger_description" ] = " " ;
120+ shortcutData[" description" ] = sdbus::Variant{ PSHORTCUT->description } ;
121+ shortcutData[" trigger_description" ] = sdbus::Variant{ " " } ;
140122 shortcutsToReturn.push_back ({PSHORTCUT->id , shortcutData});
141123 }
142124
143125 Debug::log (LOG, " [globalshortcuts] registered {} shortcuts" , shortcuts.size ());
144126
145- auto reply = call.createReply ();
146-
147127 std::unordered_map<std::string, sdbus::Variant> data;
148- data[" shortcuts" ] = shortcutsToReturn;
128+ data[" shortcuts" ] = sdbus::Variant{ shortcutsToReturn} ;
149129
150- reply << (uint32_t )0 ;
151- reply << data;
152- reply.send ();
130+ return {0 , data};
153131}
154132
155- void CGlobalShortcutsPortal::onListShortcuts (sdbus::MethodCall& call) {
156- sdbus::ObjectPath sessionHandle, requestHandle;
157- call >> requestHandle;
158- call >> sessionHandle;
159-
133+ dbUasv CGlobalShortcutsPortal::onListShortcuts (sdbus::ObjectPath sessionHandle, sdbus::ObjectPath requestHandle) {
160134 Debug::log (LOG, " [globalshortcuts] List keys:" );
161135 Debug::log (LOG, " [globalshortcuts] | {}" , sessionHandle.c_str ());
162136
163137 const auto PSESSION = getSession (sessionHandle);
164138
165139 if (!PSESSION) {
166140 Debug::log (ERR, " [globalshortcuts] No session?" );
167- return ;
141+ return { 1 , {}} ;
168142 }
169143
170144 std::vector<DBusShortcut> shortcuts;
171145
172146 for (auto & s : PSESSION->keybinds ) {
173147 std::unordered_map<std::string, sdbus::Variant> opts;
174- opts[" description" ] = s->description ;
175- opts[" trigger_description" ] = " " ;
148+ opts[" description" ] = sdbus::Variant{ s->description } ;
149+ opts[" trigger_description" ] = sdbus::Variant{ " " } ;
176150 shortcuts.push_back ({s->id , opts});
177151 }
178152
179- auto reply = call.createReply ();
180-
181153 std::unordered_map<std::string, sdbus::Variant> data;
182- data[" shortcuts" ] = shortcuts;
154+ data[" shortcuts" ] = sdbus::Variant{ shortcuts} ;
183155
184- reply << (uint32_t )0 ;
185- reply << data;
186- reply.send ();
156+ return {0 , data};
187157}
188158
189159CGlobalShortcutsPortal::CGlobalShortcutsPortal (SP<CCHyprlandGlobalShortcutsManagerV1> mgr) {
190160 m_sState.manager = mgr;
191161
192162 m_pObject = sdbus::createObject (*g_pPortalManager->getConnection (), OBJECT_PATH);
193163
194- m_pObject->registerMethod (INTERFACE_NAME, " CreateSession" , " oosa{sv}" , " ua{sv}" , [&](sdbus::MethodCall c) { onCreateSession (c); });
195- m_pObject->registerMethod (INTERFACE_NAME, " BindShortcuts" , " ooa(sa{sv})sa{sv}" , " ua{sv}" , [&](sdbus::MethodCall c) { onBindShortcuts (c); });
196- m_pObject->registerMethod (INTERFACE_NAME, " ListShortcuts" , " oo" , " ua{sv}" , [&](sdbus::MethodCall c) { onListShortcuts (c); });
197- m_pObject->registerSignal (INTERFACE_NAME, " Activated" , " osta{sv}" );
198- m_pObject->registerSignal (INTERFACE_NAME, " Deactivated" , " osta{sv}" );
199- m_pObject->registerSignal (INTERFACE_NAME, " ShortcutsChanged" , " oa(sa{sv})" );
200-
201- m_pObject->finishRegistration ();
164+ m_pObject
165+ ->addVTable (sdbus::registerMethod (" CreateSession" )
166+ .implementedAs ([this ](sdbus::ObjectPath o1, sdbus::ObjectPath o2, std::string s, std::unordered_map<std::string, sdbus::Variant> m) {
167+ return onCreateSession (o1, o2, s, m);
168+ }),
169+ sdbus::registerMethod (" BindShortcuts" )
170+ .implementedAs ([this ](sdbus::ObjectPath o1, sdbus::ObjectPath o2, std::vector<DBusShortcut> v1, std::string s1,
171+ std::unordered_map<std::string, sdbus::Variant> m2) { return onBindShortcuts (o1, o2, v1, s1, m2); }),
172+ sdbus::registerMethod (" ListShortcuts" ).implementedAs ([this ](sdbus::ObjectPath o1, sdbus::ObjectPath o2) { return onListShortcuts (o1, o2); }),
173+ sdbus::registerSignal (" Activated" ).withParameters <sdbus::ObjectPath, std::string, uint64_t , std::unordered_map<std::string, sdbus::Variant>>(),
174+ sdbus::registerSignal (" Deactivated" ).withParameters <sdbus::ObjectPath, std::string, uint64_t , std::unordered_map<std::string, sdbus::Variant>>(),
175+ sdbus::registerSignal (" ShortcutsChanged" ).withParameters <sdbus::ObjectPath, std::unordered_map<std::string, std::unordered_map<std::string, sdbus::Variant>>>())
176+ .forInterface (INTERFACE_NAME);
202177
203178 Debug::log (LOG, " [globalshortcuts] registered" );
204179}
@@ -208,25 +183,13 @@ void CGlobalShortcutsPortal::onActivated(SKeybind* pKeybind, uint64_t time) {
208183
209184 Debug::log (TRACE, " [gs] Session {} called activated on {}" , PSESSION->sessionHandle .c_str (), pKeybind->id );
210185
211- auto signal = m_pObject->createSignal (INTERFACE_NAME, " Activated" );
212- signal << PSESSION->sessionHandle ;
213- signal << pKeybind->id ;
214- signal << time;
215- signal << std::unordered_map<std::string, sdbus::Variant>{};
216-
217- m_pObject->emitSignal (signal);
186+ m_pObject->emitSignal (" Activated" ).onInterface (INTERFACE_NAME).withArguments (PSESSION->sessionHandle , pKeybind->id , time, std::unordered_map<std::string, sdbus::Variant>{});
218187}
219188
220189void CGlobalShortcutsPortal::onDeactivated (SKeybind* pKeybind, uint64_t time) {
221190 const auto PSESSION = (CGlobalShortcutsPortal::SSession*)pKeybind->session ;
222191
223192 Debug::log (TRACE, " [gs] Session {} called deactivated on {}" , PSESSION->sessionHandle .c_str (), pKeybind->id );
224193
225- auto signal = m_pObject->createSignal (INTERFACE_NAME, " Deactivated" );
226- signal << PSESSION->sessionHandle ;
227- signal << pKeybind->id ;
228- signal << time;
229- signal << std::unordered_map<std::string, sdbus::Variant>{};
230-
231- m_pObject->emitSignal (signal);
194+ m_pObject->emitSignal (" Deactivated" ).onInterface (INTERFACE_NAME).withArguments (PSESSION->sessionHandle , pKeybind->id , time, std::unordered_map<std::string, sdbus::Variant>{});
232195}
0 commit comments