8
8
#include " global_hotkeys_manager.hpp"
9
9
10
10
#include < QDebug>
11
+ #include < QRandomGenerator>
11
12
12
13
#include " config.h"
13
14
#include " dbus_portal_request_inf.h"
@@ -103,12 +104,16 @@ void global_hotkeys_manager::handle_portal_activated(
103
104
emit hotkey_activated (action_id, {});
104
105
}
105
106
106
- void global_hotkeys_manager::create_portal_session () {
107
+ void global_hotkeys_manager::create_portal_session (bool force_bind ) {
107
108
LOGD (" [dbus] call CreateSession" );
108
109
110
+ auto handle_token = QStringLiteral (APP_ID " _%1" )
111
+ .arg (QRandomGenerator::global ()->generate ());
112
+ m_force_bind = force_bind;
113
+
109
114
auto reply = m_portal_inf.CreateSession ({
110
- {QLatin1String (" session_handle_token" ), APP_ID },
111
- {QLatin1String (" handle_token" ), APP_ID },
115
+ {QLatin1String (" session_handle_token" ), handle_token },
116
+ {QLatin1String (" handle_token" ), handle_token },
112
117
});
113
118
114
119
reply.waitForFinished ();
@@ -152,7 +157,7 @@ void global_hotkeys_manager::fetch_portal_shortcuts() {
152
157
return ;
153
158
}
154
159
155
- auto req = new OrgFreedesktopPortalRequestInterface (
160
+ auto * req = new OrgFreedesktopPortalRequestInterface (
156
161
DBUS_SERVICE_NAME, reply.value ().path (), QDBusConnection::sessionBus (),
157
162
this );
158
163
@@ -178,7 +183,6 @@ void global_hotkeys_manager::handle_list_shortcuts_response(
178
183
const auto arg = results[" shortcuts" ].value <QDBusArgument>();
179
184
arg >> s;
180
185
181
- QString desc;
182
186
for (auto it = s.cbegin (), it_end = s.cend (); it != it_end; ++it) {
183
187
LOGD (" portal hotkey: " << it->first << " "
184
188
<< it->second [" description" ].toString () << " "
@@ -187,6 +191,7 @@ void global_hotkeys_manager::handle_list_shortcuts_response(
187
191
188
192
if (s.isEmpty ()) {
189
193
set_portal_bindings ();
194
+ m_force_bind = false ;
190
195
return ;
191
196
}
192
197
@@ -204,11 +209,13 @@ void global_hotkeys_manager::handle_list_shortcuts_response(
204
209
return true ;
205
210
}();
206
211
207
- if (all_shortcuts_configured) {
212
+ if (all_shortcuts_configured && !m_force_bind ) {
208
213
LOGD (" portal global shortcuts already configured" );
209
214
} else {
210
215
set_portal_bindings ();
211
216
}
217
+
218
+ m_force_bind = false ;
212
219
}
213
220
214
221
void global_hotkeys_manager::handle_bind_shortcuts_response (
@@ -329,4 +336,15 @@ void global_hotkeys_manager::handle_x11_activated() {
329
336
emit hotkey_activated (action_id, {});
330
337
}
331
338
339
+ void global_hotkeys_manager::reset_portal_connection () {
340
+ if (!is_portal_supported ()) {
341
+ LOGW (" portal not supported" );
342
+ return ;
343
+ }
344
+
345
+ disable_portal ();
346
+
347
+ create_portal_session (/* force_bind=*/ true );
348
+ }
349
+
332
350
#endif // USE_X11_FEATURES
0 commit comments