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 Sep 5, 2022
1 parent 753fba1 commit d37bb4f
Show file tree
Hide file tree
Showing 10 changed files with 966 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PORTAL_IFACE_FILES =\
$(top_srcdir)/data/org.freedesktop.portal.FileChooser.xml \
$(top_srcdir)/data/org.freedesktop.portal.FileTransfer.xml \
$(top_srcdir)/data/org.freedesktop.portal.GameMode.xml \
$(top_srcdir)/data/org.freedesktop.portal.GlobalShortcuts.xml \
$(top_srcdir)/data/org.freedesktop.portal.Inhibit.xml \
$(top_srcdir)/data/org.freedesktop.portal.Location.xml \
$(top_srcdir)/data/org.freedesktop.portal.MemoryMonitor.xml \
Expand Down Expand Up @@ -38,6 +39,7 @@ PORTAL_IMPL_IFACE_FILES =\
$(top_srcdir)/data/org.freedesktop.impl.portal.DynamicLauncher.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.Email.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.FileChooser.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.GlobalShortcuts.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.Inhibit.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.Lockdown.xml \
$(top_srcdir)/data/org.freedesktop.impl.portal.Notification.xml \
Expand Down
4 changes: 3 additions & 1 deletion data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ portal_sources = files(
'org.freedesktop.portal.FileChooser.xml',
'org.freedesktop.portal.FileTransfer.xml',
'org.freedesktop.portal.GameMode.xml',
'org.freedesktop.portal.GlobalShortcuts.xml',
'org.freedesktop.portal.Inhibit.xml',
'org.freedesktop.portal.Location.xml',
'org.freedesktop.portal.MemoryMonitor.xml',
Expand Down Expand Up @@ -41,6 +42,7 @@ portal_impl_sources = files(
'org.freedesktop.impl.portal.DynamicLauncher.xml',
'org.freedesktop.impl.portal.Email.xml',
'org.freedesktop.impl.portal.FileChooser.xml',
'org.freedesktop.impl.portal.GlobalShortcuts.xml',
'org.freedesktop.impl.portal.Inhibit.xml',
'org.freedesktop.impl.portal.Lockdown.xml',
'org.freedesktop.impl.portal.Notification.xml',
Expand All @@ -58,4 +60,4 @@ portal_impl_sources = files(

install_data([portal_sources, portal_impl_sources],
install_dir: datadir / 'dbus-1' / 'interfaces',
)
)
168 changes: 168 additions & 0 deletions data/org.freedesktop.impl.portal.GlobalShortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?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 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
@options: Vardict with optional further information. See @org.freedesktop.portal.GlobalShortcuts.CreateSession
@response: Numeric Request response
@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>shortcuts a(sa{sv})</term>
<listitem><para>
The different shortcut ids that the app needs. For those that had already been bound on previous runs, they are mapped to user-readable descriptions of the trigger. This can be used by the app to describe the shortcut to the user.
By default these shortcuts are not bound. To bind them, BindShortcuts needs to be called for the portal
to assign a trigger to a shortcut.
They are mapped to a list of pairs including:
- description: User-readable text describing what the shortcut does
- shortcut: A string that contains a suggestion of a default shortcut, defined as described in the "shortcuts" xdg-spec.
</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="options" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QVariantMap"/>
<arg type="u" name="response" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
<arg type="a{sv}" name="results" direction="out"/>
</method>

<!--
ListShortcuts:
@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>shortcuts a(sa{sv})</term>
<listitem><para>
The registered shortcut ids mapped to a list of pairs including:
- description: User-readable text describing what the shortcut does
- trigger: User-readable text describing how to trigger the shortcut
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="ListShortcuts">
<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.Out0" value="QVariantMap"/>
</method>

<!--
BindShortcuts:
@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
@parent_window: Identifier for the application window, see <link linkend="parent_window">Common Conventions</link>
@shortcuts: The identifier of the shortcuts we intend to register, empty for all shortcuts
@results: Vardict with the results of the call
Shows a dialog with all shortcuts to configure and offers them back to the app when done.
The results get returned via the #org.freedesktop.portal.Request::Response signal. See ListShortcuts results format.
-->
<method name="BindShortcuts">
<arg type="o" name="handle" direction="in"/>
<arg type="o" name="session_handle" direction="in"/>
<arg type="as" name="shortcuts" direction="in"/>
<arg type="s" name="parent_window" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<arg type="a{sv}" name="results" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantMap"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
</method>

<!--
Activated:
Notifies about a shortcut becoming active.
@session_handle: Session that requested the shortcut
@shortcut_id: the application-provided ID for the notification
@timestamp: The timestamp, as seconds and microseconds since the Unix epoch.
@options: unused
-->
<signal name="Activated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_id" direction="in"/>
<arg type="t" name="timestamp" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantMap"/>
</signal>

<!--
Deactivated:
Notifies that a shortcut is not active anymore.
@session_handle: Session that requested the shortcut
@shortcut_id: the application-provided ID for the notification
@timestamp: The timestamp, as seconds and microseconds since the Unix epoch.
@options: unused
-->
<signal name="Deactivated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_id" direction="in"/>
<arg type="t" name="timestamp" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantMap"/>
</signal>

<!--
ShortcutsChanged:
@session_handle: Session that requested the shortcut
@shortcuts: The different shortcut ids that have been registered. They are mapped to a list of pairs including:
- description: User-readable text describing what the shortcut does
- trigger: User-readable text describing how to trigger the shortcut
-->
<signal name="ShortcutsChanged">
<arg type="o" name="session_handle" direction="out"/>
<arg type="a(sa{sv})" name="shortcuts" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QMap&lt;QString,QVariantMap&gt;"/>
</signal>

<property name="version" type="u" access="read"/>
</interface>
</node>
188 changes: 188 additions & 0 deletions data/org.freedesktop.portal.GlobalShortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?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 portal lets applications register global shortcuts. These shortcuts can be
used by apps to react to the user input, regardless of the input focus state.
To use this, an app has to create a session under which its actions
will be collected. Then shortcuts can be bound (see Bind), listed (see ListShortcuts).
The portal implementation performs the registration and tracks the shortcuts throughout
the session's lifespan.
When a shortcut triggers, Activated is emitted. When it is not triggered anymore, then
Deactivated is issued.
-->
<interface name="org.freedesktop.portal.GlobalShortcuts">
<!--
CreateSession:
@options: Vardict with optional further information
@handle: Object path for the #org.freedesktop.portal.Request object representing this call
Creates a global shortcuts session.
Supported keys in the @options vardict include:
<variablelist>
<varlistentry>
<term>shortcuts a(sa{sv})</term>
<listitem><para>
The different shortcut ids that are supported by the app. They are mapped to a list of pairs including:
- description: User-readable text describing what the shortcut does
- shortcut: A string that contains a suggestion of a default shortcut, defined as described in the "shortcuts" xdg-spec.
</para></listitem>
</varlistentry>
<varlistentry>
<term>handle_token s</term>
<listitem><para>
A string that will be used as the last element of the @handle. Must be a valid
object path element. See the #org.freedesktop.portal.Request documentation for
more information about the @handle.
</para></listitem>
</varlistentry>
<varlistentry>
<term>session_handle_token s</term>
<listitem><para>
A string that will be used as the last element of the session handle. Must be a valid
object path element. See the #org.freedesktop.portal.Session documentation for
more information about the session handle.
</para></listitem>
</varlistentry>
</variablelist>
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>session_handle o</term>
<listitem><para>
The session handle. An object path for the
#org.freedesktop.portal.Session object representing the created
session.
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="CreateSession">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="o" name="handle" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
</method>

<!--
ListShortcuts:
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@options: Unused so far
List all the shortcuts with their invocation descriptions.
The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>shortcuts a(sa{sv})</term>
<listitem><para>
The registered shortcut ids mapped to a list of pairs including:
- description: User-readable text describing what the shortcut does
- trigger: User-readable text describing how to trigger the shortcut
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="ListShortcuts">
<arg type="o" name="session_handle" direction="in"/>
<arg type="o" name="request_handle" direction="out"/>
</method>

<!--
BindShortcuts:
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@shortcuts: The identifier of the shortcuts we intend to register, empty for all shortcuts
@parent_window: Identifier for the application window, see <link linkend="parent_window">Common Conventions</link>
@request_handle: Object path for the #org.freedesktop.portal.Request object representing this call
Shows a dialog with all shortcuts to configure and offers them back to the app when done.
The results get returned via the #org.freedesktop.portal.Request::Response signal. See ListShortcuts results format.
</variablelist>
-->
<method name="BindShortcuts">
<arg type="o" name="session_handle" direction="in"/>
<arg type="as" name="shortcuts" direction="in"/>
<arg type="s" name="parent_window" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<arg type="o" name="request_handle" direction="out"/>

<annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QVariantMap"/>
</method>

<!--
Activated:
Notifies about a shortcut becoming active.
@session_handle: Session that requested the shortcut
@shortcut_id: the application-provided ID for the notification
@timestamp: The timestamp, as seconds and microseconds since the Unix epoch.
@options: unused
-->
<signal name="Activated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_id" direction="in"/>
<arg type="t" name="timestamp" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantMap"/>
</signal>

<!--
Deactivated:
Notifies that a shortcut is not active anymore.
@session_handle: Session that requested the shortcut
@shortcut_id: the application-provided ID for the notification
@timestamp: The timestamp, as seconds and microseconds since the Unix epoch.
@options: unused
-->
<signal name="Deactivated">
<arg type="o" name="session_handle" direction="in"/>
<arg type="s" name="shortcut_id" direction="in"/>
<arg type="t" name="timestamp" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In4" value="QVariantMap"/>
</signal>

<!--
ShortcutsChanged:
@session_handle: Session that requested the shortcut
@shortcuts: The different shortcut ids that have been registered. They are mapped to a list of pairs including:
- description: User-readable text describing what the shortcut does
- trigger: User-readable text describing how to trigger the shortcut
Indicates that the information associated with some of the shortcuts has changed.
-->
<signal name="ShortcutsChanged">
<arg type="o" name="session_handle" direction="out"/>
<arg type="a(sa{sv})" name="shortcuts" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QMap&lt;QString,QVariantMap&gt;"/>
</signal>

<property name="version" type="u" access="read"/>
</interface>
</node>
Loading

0 comments on commit d37bb4f

Please sign in to comment.