Skip to content

Commit

Permalink
Add a global shortcut portal
Browse files Browse the repository at this point in the history
It's designed so that applications can register actions that can be
triggered globally (i.e. regarless of the system's state, like focus).
  • Loading branch information
aleixpol committed Feb 16, 2022
1 parent bceb762 commit ad69435
Show file tree
Hide file tree
Showing 6 changed files with 849 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dist_introspection_DATA = \
data/org.freedesktop.portal.FileTransfer.xml \
data/org.freedesktop.portal.GameMode.xml \
data/org.freedesktop.portal.Inhibit.xml \
data/org.freedesktop.portal.GlobalShortcuts.xml \
data/org.freedesktop.portal.Location.xml \
data/org.freedesktop.portal.MemoryMonitor.xml \
data/org.freedesktop.portal.NetworkMonitor.xml \
Expand All @@ -34,6 +35,7 @@ dist_introspection_DATA = \
data/org.freedesktop.impl.portal.Background.xml \
data/org.freedesktop.impl.portal.Email.xml \
data/org.freedesktop.impl.portal.FileChooser.xml \
data/org.freedesktop.impl.portal.GlobalShortcuts.xml \
data/org.freedesktop.impl.portal.Inhibit.xml \
data/org.freedesktop.impl.portal.Lockdown.xml \
data/org.freedesktop.impl.portal.Notification.xml \
Expand Down
149 changes: 149 additions & 0 deletions data/org.freedesktop.impl.portal.GlobalShortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2022 Aleix Pol Gonzalez <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
Author: Aleix Pol Gonzalez <[email protected]>
-->

<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<!--
org.freedesktop.impl.portal.GlobalShortcut:
@short_description: GlobalShortcut portal backend interface
This this portal lets applications register global shortcuts so they can
act regardless of the system state upon an input event.
-->
<interface name="org.freedesktop.impl.portal.GlobalShortcuts">
<!--
CreateSession:
@handle: Object path for the #org.freedesktop.impl.portal.Request object representing this call
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session being created
@app_id: App id of the application
@results: Vardict with the results of the call
Create a global shortcuts session.
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>session_id s</term>
<listitem><para>
The session id. A string representing the created global shortcuts session.
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="CreateSession">
<arg type="o" name="handle" direction="in"/>
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="app_id" direction="in"/>
<arg type="a{sv}" name="results" direction="out"/>
</method>

<!--
Shortcuts:
@handle: Object path for the #org.freedesktop.impl.portal.Request object representing this call
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@results: Vardict with the results of the call
List the shortcuts registered in the @p handle session.
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>names a{sv}</term>
<listitem><para>
The different shortcut names that have been registered mapped to user-readable descriptions for the app to present that describes the shortcut.
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="Shortcuts">
<arg type="o" name="handle" direction="in"/>
<arg type="o" name="session_handle" direction="in"/>
<arg type="a{sv}" name="results" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
</method>

<!--
Register:
@handle: Object path for the #org.freedesktop.impl.portal.Request object representing this call
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@shortcut_name: The identifier of the shortcut we intend to register
@results: Vardict with the results of the call
Register a new global shortcut named @p shortcut_name within the @p session_handle session.
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>description</term>
<listitem><para>
The user-readable description of the registered binding. This is intended for the app to be able to render the shortcut into the UI, allowing the user to learn the shortcut
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="Register">
<arg type="o" name="handle" direction="in"/>
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
<arg type="a{sv}" name="results" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
</method>

<!--
Unregister:
@handle: Object path for the #org.freedesktop.impl.portal.Request object representing this call
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@shortcut_name: The identifier of the shortcut we intend to register
@successful: whether it was unregistered successfully
-->
<method name="Unregister">
<arg type="o" name="handle" direction="in"/>
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
<arg type="b" name="successful" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
</method>

<!--
Activated:
Notifies about a shortcut becoming active.
@session_handle: Session that requested the shortcut
@shortcut_name: the application-provided ID for the notification
-->
<signal name="Activated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
</signal>

<!--
Deactivated:
Notifies that a shortcut is not active anymore.
@session_handle: Session that requested the shortcut
@shortcut_name: the application-provided ID for the notification
-->
<signal name="Deactivated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
</signal>

<property name="version" type="u" access="read"/>
</interface>
</node>
139 changes: 139 additions & 0 deletions data/org.freedesktop.portal.GlobalShortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2022 Aleix Pol Gonzalez <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
Author: Aleix Pol Gonzalez <[email protected]>
-->

<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<!--
org.freedesktop.portal.GlobalShortcut:
@short_description: GlobalShortcut portal backend interface
This this portal lets applications register global shortcuts so they can
act regardless of the system state upon an input event.
To use this, an app will first create a session under which its actions
will be collected. Then shortcuts can be registered, listed and eventually
unregistered. It's up to the portal implementation to perform the registration
and tracking of that shortcut throughout the session's lifespan.
Upon a shortcut trigger, Activated will be emitted until when it's not
triggered anymore, then Deactivated will be issued.
-->
<interface name="org.freedesktop.portal.GlobalShortcuts">
<!--
CreateSession:
@options: Unused so far
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session being created
Creates a global shortcuts session.
</variablelist>
-->
<method name="CreateSession">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="o" name="session_handle" direction="out"/>
</method>

<!--
Shortcuts:
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@request_handle: Object path for the #org.freedesktop.portal.Request object representing this call
Create a global shortcuts session.
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>names a{sv}</term>
<listitem><para>
The different shortcut names that have been registered mapped to user-readable descriptions for the app to present that describes the shortcut.
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="Shortcuts">
<arg type="o" name="session_handle" direction="in"/>
<arg type="o" name="request_handle" direction="out"/>
</method>

<!--
Register:
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@shortcut_name: The identifier of the shortcut we intend to register
@request_handle: Object path for the #org.freedesktop.portal.Request object representing this call
Create a global shortcuts session.
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>description</term>
<listitem><para>
The user-readable description of the registered binding. This is intended for the app to be able to render the shortcut into the UI, allowing the user to learn the shortcut
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="Register">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
<arg type="o" name="request_handle" direction="out"/>
</method>

<!--
Unregister:
@session_handle: Object path for the #org.freedesktop.portal.Session object
@shortcut_name: Identifier of the global shortcut to unregister
@request_handle: Object path for the #org.freedesktop.portal.Request object representing this call
Unregister a global shortcut.
The resulting request will have one "successful" field defining if it was properly unregistered.
-->
<method name="Unregister">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
<arg type="o" name="request_handle" direction="out"/>
</method>

<!--
Activated:
Notifies about a shortcut becoming active.
@session_handle: Session that requested the shortcut
@shortcut_name: the application-provided ID for the notification
-->
<signal name="Activated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
</signal>

<!--
Deactivated:
Notifies that a shortcut is not active anymore.
@session_handle: Session that requested the shortcut
@shortcut_name: the application-provided ID for the notification
-->
<signal name="Deactivated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_name" direction="in"/>
</signal>

<property name="version" type="u" access="read"/>
</interface>
</node>
4 changes: 4 additions & 0 deletions src/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ PORTAL_IFACE_FILES =\
data/org.freedesktop.portal.Secret.xml \
data/org.freedesktop.portal.Wallpaper.xml \
data/org.freedesktop.portal.PowerProfileMonitor.xml \
data/org.freedesktop.portal.GlobalShortcuts.xml \
$(NULL)

PORTAL_IMPL_IFACE_FILES =\
Expand All @@ -65,6 +66,7 @@ PORTAL_IMPL_IFACE_FILES =\
data/org.freedesktop.impl.portal.Background.xml \
data/org.freedesktop.impl.portal.Secret.xml \
data/org.freedesktop.impl.portal.Wallpaper.xml \
data/org.freedesktop.impl.portal.GlobalShortcuts.xml \
$(NULL)

$(xdp_dbus_built_sources) : $(PORTAL_IFACE_FILES)
Expand Down Expand Up @@ -174,6 +176,8 @@ xdg_desktop_portal_SOURCES = \
src/flatpak-instance.h \
src/portal-impl.h \
src/portal-impl.c \
src/globalshortcuts.h \
src/globalshortcuts.c \
$(NULL)

if HAVE_PIPEWIRE
Expand Down
Loading

0 comments on commit ad69435

Please sign in to comment.