Skip to content

Commit 280c128

Browse files
authored
Support globalshortcuts
1 parent 4779b54 commit 280c128

9 files changed

Lines changed: 1628 additions & 1 deletion

File tree

libportal/globalshortcuts.c

Lines changed: 1203 additions & 0 deletions
Large diffs are not rendered by default.

libportal/globalshortcuts.h

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* This file is free software; you can redistribute it and/or modify it
3+
* under the terms of the GNU Lesser General Public License as
4+
* published by the Free Software Foundation, version 3.0 of the
5+
* License.
6+
*
7+
* This file is distributed in the hope that it will be useful, but
8+
* WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10+
* Lesser General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU Lesser General Public
13+
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*
15+
* SPDX-License-Identifier: LGPL-3.0-only
16+
*/
17+
18+
#pragma once
19+
20+
#include <libportal/portal-helpers.h>
21+
#include <libportal/session.h>
22+
23+
G_BEGIN_DECLS
24+
25+
#define XDP_TYPE_GLOBAL_SHORTCUTS_SESSION (xdp_global_shortcuts_session_get_type ())
26+
27+
XDP_PUBLIC
28+
G_DECLARE_FINAL_TYPE (XdpGlobalShortcutsSession,
29+
xdp_global_shortcuts_session,
30+
XDP,
31+
GLOBAL_SHORTCUTS_SESSION,
32+
GObject)
33+
34+
#define XDP_TYPE_GLOBAL_SHORTCUT (xdp_global_shortcut_get_type ())
35+
#define XDP_TYPE_GLOBAL_SHORTCUT_ASSIGNED (xdp_global_shortcut_assigned_get_type ())
36+
37+
typedef struct _XdpGlobalShortcut XdpGlobalShortcut;
38+
typedef struct _XdpGlobalShortcutAssigned XdpGlobalShortcutAssigned;
39+
40+
XDP_PUBLIC
41+
GType xdp_global_shortcut_get_type (void) G_GNUC_CONST;
42+
43+
XDP_PUBLIC
44+
XdpGlobalShortcut *xdp_global_shortcut_new (const char *shortcut_id,
45+
const char *description,
46+
const char *preferred_trigger);
47+
48+
XDP_PUBLIC
49+
XdpGlobalShortcut *xdp_global_shortcut_copy (const XdpGlobalShortcut *shortcut);
50+
51+
XDP_PUBLIC
52+
void xdp_global_shortcut_free (XdpGlobalShortcut *shortcut);
53+
54+
XDP_PUBLIC
55+
const char *xdp_global_shortcut_get_shortcut_id (const XdpGlobalShortcut *shortcut);
56+
57+
XDP_PUBLIC
58+
const char *xdp_global_shortcut_get_description (const XdpGlobalShortcut *shortcut);
59+
60+
XDP_PUBLIC
61+
const char *xdp_global_shortcut_get_preferred_trigger (const XdpGlobalShortcut *shortcut);
62+
63+
XDP_PUBLIC
64+
void xdp_global_shortcut_set_description (XdpGlobalShortcut *shortcut,
65+
const char *description);
66+
67+
XDP_PUBLIC
68+
void xdp_global_shortcut_set_preferred_trigger (XdpGlobalShortcut *shortcut,
69+
const char *preferred_trigger);
70+
71+
XDP_PUBLIC
72+
GType xdp_global_shortcut_assigned_get_type (void) G_GNUC_CONST;
73+
74+
XDP_PUBLIC
75+
XdpGlobalShortcutAssigned *xdp_global_shortcut_assigned_copy (const XdpGlobalShortcutAssigned *shortcut);
76+
77+
XDP_PUBLIC
78+
void xdp_global_shortcut_assigned_free (XdpGlobalShortcutAssigned *shortcut);
79+
80+
XDP_PUBLIC
81+
const char *xdp_global_shortcut_assigned_get_shortcut_id (const XdpGlobalShortcutAssigned *shortcut);
82+
83+
XDP_PUBLIC
84+
const char *xdp_global_shortcut_assigned_get_description (const XdpGlobalShortcutAssigned *shortcut);
85+
86+
XDP_PUBLIC
87+
const char *xdp_global_shortcut_assigned_get_trigger_description (const XdpGlobalShortcutAssigned *shortcut);
88+
89+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (XdpGlobalShortcut, xdp_global_shortcut_free)
90+
G_DEFINE_AUTOPTR_CLEANUP_FUNC (XdpGlobalShortcutAssigned, xdp_global_shortcut_assigned_free)
91+
92+
XDP_PUBLIC
93+
void xdp_portal_create_global_shortcuts_session (XdpPortal *portal,
94+
GCancellable *cancellable,
95+
GAsyncReadyCallback callback,
96+
gpointer data);
97+
98+
XDP_PUBLIC
99+
XdpGlobalShortcutsSession *xdp_portal_create_global_shortcuts_session_finish (XdpPortal *portal,
100+
GAsyncResult *result,
101+
GError **error);
102+
103+
XDP_PUBLIC
104+
XdpSession *xdp_global_shortcuts_session_get_session (XdpGlobalShortcutsSession *session);
105+
106+
XDP_PUBLIC
107+
void xdp_global_shortcuts_session_close (XdpGlobalShortcutsSession *session);
108+
109+
XDP_PUBLIC
110+
void xdp_global_shortcuts_session_bind_shortcuts (XdpGlobalShortcutsSession *session,
111+
GPtrArray *shortcuts,
112+
const char *parent_window,
113+
GCancellable *cancellable,
114+
GAsyncReadyCallback callback,
115+
gpointer data);
116+
117+
XDP_PUBLIC
118+
GPtrArray *xdp_global_shortcuts_session_bind_shortcuts_finish (XdpGlobalShortcutsSession *session,
119+
GAsyncResult *result,
120+
GError **error);
121+
122+
XDP_PUBLIC
123+
void xdp_global_shortcuts_session_list_shortcuts (XdpGlobalShortcutsSession *session,
124+
GCancellable *cancellable,
125+
GAsyncReadyCallback callback,
126+
gpointer data);
127+
128+
XDP_PUBLIC
129+
GPtrArray *xdp_global_shortcuts_session_list_shortcuts_finish (XdpGlobalShortcutsSession *session,
130+
GAsyncResult *result,
131+
GError **error);
132+
133+
XDP_PUBLIC
134+
void xdp_global_shortcuts_session_configure_shortcuts (XdpGlobalShortcutsSession *session,
135+
const char *parent_window,
136+
const char *activation_token,
137+
GCancellable *cancellable,
138+
GAsyncReadyCallback callback,
139+
gpointer data);
140+
141+
XDP_PUBLIC
142+
gboolean xdp_global_shortcuts_session_configure_shortcuts_finish (XdpGlobalShortcutsSession *session,
143+
GAsyncResult *result,
144+
GError **error);
145+
146+
G_END_DECLS

libportal/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public_headers = [
1212
'dynamic-launcher.h',
1313
'email.h',
1414
'filechooser.h',
15+
'globalshortcuts.h',
1516
'inhibit.h',
1617
'inputcapture.h',
1718
'inputcapture-zone.h',
@@ -49,6 +50,7 @@ src = [
4950
'dynamic-launcher.c',
5051
'email.c',
5152
'filechooser.c',
53+
'globalshortcuts.c',
5254
'inhibit.c',
5355
'inputcapture.c',
5456
'inputcapture-zone.c',

libportal/portal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <libportal/dynamic-launcher.h>
2828
#include <libportal/email.h>
2929
#include <libportal/filechooser.h>
30+
#include <libportal/globalshortcuts.h>
3031
#include <libportal/inhibit.h>
3132
#include <libportal/inputcapture.h>
3233
#include <libportal/location.h>

libportal/session-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <libportal/remote.h>
2323
#include <libportal/inputcapture.h>
24+
#include <libportal/globalshortcuts.h>
2425

2526
struct _XdpSession {
2627
GObject parent_instance;
@@ -49,6 +50,7 @@ struct _XdpSession {
4950

5051
/* InputCapture */
5152
XdpInputCaptureSession *input_capture_session; /* weak ref */
53+
XdpGlobalShortcutsSession *global_shortcuts_session; /* weak ref */
5254
};
5355

5456
XdpSession * _xdp_session_new (XdpPortal *portal,

libportal/session.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ xdp_session_finalize (GObject *object)
6565
if (session->input_capture_session != NULL)
6666
g_critical ("XdpSession destroyed before XdpInputCaptureSesssion, you lost count of your session refs");
6767
session->input_capture_session = NULL;
68+
if (session->global_shortcuts_session != NULL)
69+
g_critical ("XdpSession destroyed before XdpGlobalShortcutsSession, you lost count of your session refs");
70+
session->global_shortcuts_session = NULL;
6871
g_clear_pointer (&session->selection_mime_types, g_strfreev);
6972

7073
G_OBJECT_CLASS (xdp_session_parent_class)->finalize (object);
@@ -160,6 +163,7 @@ _xdp_session_new (XdpPortal *portal,
160163
session->type = type;
161164
session->state = XDP_SESSION_INITIAL;
162165
session->input_capture_session = NULL;
166+
session->global_shortcuts_session = NULL;
163167

164168
session->signal_id = g_dbus_connection_signal_subscribe (portal->bus,
165169
PORTAL_BUS_NAME,

libportal/session.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ G_DECLARE_FINAL_TYPE (XdpSession, xdp_session, XDP, SESSION, GObject)
3333
* @XDP_SESSION_SCREENCAST: a screencast session.
3434
* @XDP_SESSION_REMOTE_DESKTOP: a remote desktop session.
3535
* @XDP_SESSION_INPUT_CAPTURE: an input capture session.
36+
* @XDP_SESSION_GLOBAL_SHORTCUTS: a global shortcuts session.
3637
*
3738
* The type of a session.
3839
*/
3940
typedef enum {
4041
XDP_SESSION_SCREENCAST,
4142
XDP_SESSION_REMOTE_DESKTOP,
4243
XDP_SESSION_INPUT_CAPTURE,
44+
XDP_SESSION_GLOBAL_SHORTCUTS,
4345
} XdpSessionType;
4446

4547
XDP_PUBLIC

0 commit comments

Comments
 (0)