Skip to content

Commit

Permalink
FEAT(client): Add support to XDG Desktop Portal GlobalShortcuts
Browse files Browse the repository at this point in the history
This makes it possible to have global shortcuts on systems running the
XDG Desktop Portal service. This is especially relevant on Wayland where
we are not able to run a system-wide keylogger to get the global
shortcuts triggers.

Fixes #5257
  • Loading branch information
aleixpol committed Nov 28, 2022
1 parent fc4db91 commit a59e8f3
Show file tree
Hide file tree
Showing 10 changed files with 641 additions and 29 deletions.
268 changes: 268 additions & 0 deletions auxiliary_files/org.freedesktop.portal.GlobalShortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
<?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 create global shortcuts sessions, and
register shortcuts to them. These shortcuts are activated regardless of
the focused state of the application window.

To use this portal, applications have to create a session under which its
actions will be collected. Then shortcuts can be bound (see
org.freedesktop.portal.GlobalShortcuts.Bind), and listed (see
org.freedesktop.portal.GlobalShortcuts.ListShortcuts).

All global shortcuts are bound to a session, and all sessions are bound to
the application that created them.

The #org.freedesktop.portal.GlobalShortcuts::Activated and
#org.freedesktop.portal.GlobalShortcuts::Deactivated signals are emitted,
respecitvely, whenever a shortcut is activated and deactivated.

This documentation describes version 1 of this interface.
-->
<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>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>

<!--
BindShortcuts:
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@shortcuts: The list of shortcuts to bind
@parent_window: Identifier for the application window, see <link linkend="parent_window">Common Conventions</link>
@options: Vardict with optional further information
@request_handle: Object path for the #org.freedesktop.portal.Request object representing this call

Bind the shortcuts. This will typically result the portal presenting a
dialog showing the shortcuts and allowing users to configure the shortcuts.
An application can only attempt bind shortcuts of a session once.

Each element of the @shortcuts array is a tuple composed of a shortcut id,
and a vardict with the following keys:
<variablelist>
<varlistentry>
<term>description s</term>
<listitem><para>
User-readable text describing what the shortcut does.
</para></listitem>
</varlistentry>
<varlistentry>
<term>preferred_trigger s</term>
<listitem><para>
The preferred shortcut trigger, defined as described by the "shortcuts"
XDG specification. Optional.
</para></listitem>
</varlistentry>
</variablelist>

Supported keys in the @options vardict include:
<variablelist>
<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>
</variablelist>

The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>shortcuts a(sa{sv})</term>
<listitem><para>
A list of shortcuts. The list of keys it may contain is described
below, and is different from the @shortcuts variable of this method.
</para></listitem>
</varlistentry>
</variablelist>

Each element of the @shortcuts array returned by the
#org.freedesktop.portal.Request::Response signal is a tuple composed of
a shortcut id, and a vardict with the following keys:
<variablelist>
<varlistentry>
<term>description s</term>
<listitem><para>
User-readable text describing what the shortcut does.
</para></listitem>
</varlistentry>
<varlistentry>
<term>trigger_description s</term>
<listitem><para>
User-readable text describing how to trigger the shortcut for the
client to render.
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="BindShortcuts">
<arg type="o" name="session_handle" direction="in"/>
<arg type="a(sa{sv})" 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.In1" value="QList&lt;QPair&lt;QString,QVariantMap&gt;&gt;"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QVariantMap"/>
</method>

<!--
ListShortcuts:
@session_handle: Object path for the #org.freedesktop.impl.portal.Session object representing the session
@options: Vardict with optional further information

Lists all shortcuts.

Supported keys in the @options vardict include:
<variablelist>
<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>
</variablelist>

The following results get returned via the #org.freedesktop.portal.Request::Response signal:
<variablelist>
<varlistentry>
<term>shortcuts a(sa{sv})</term>
<listitem><para>
A list of shortcuts.

See the #org.freedesktop.portal.Request::Response signal of the
org.freedesktop.portal.GlobalShortcuts.BindShortcuts() method for
the list of supported properties of shortcuts.
</para></listitem>
</varlistentry>
</variablelist>
-->
<method name="ListShortcuts">
<arg type="o" name="session_handle" direction="in"/>
<arg type="a{sv}" name="options" direction="in"/>
<arg type="o" name="request_handle" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
</method>

<!--
Activated:
@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: Vardict with optional further information

Notifies about a shortcut becoming active.
-->
<signal name="Activated">
<arg type="o" name="session_handle" direction="out"/>
<arg type="s" name="shortcut_id" direction="out"/>
<arg type="t" name="timestamp" direction="out"/>
<arg type="a{sv}" name="options" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out3" value="QVariantMap"/>
</signal>

<!--
Deactivated:
@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: Vardict with optional further information

Notifies that a shortcut is not active anymore.
-->
<signal name="Deactivated">
<arg type="o" name="session_handle" direction="out"/>
<arg type="s" name="shortcut_id" direction="out"/>
<arg type="t" name="timestamp" direction="out"/>
<arg type="a{sv}" name="options" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out3" value="QVariantMap"/>
</signal>

<!--
ShortcutsChanged:
@session_handle: Session that requested the shortcut
@shortcuts: The different shortcuts that have been registered. See org.freedesktop.portal.GlobalShortcuts.

Indicates that the information associated with some of the shortcuts has changed.

See the #org.freedesktop.portal.Request::Response signal of the
org.freedesktop.portal.GlobalShortcuts.BindShortcuts() method for the
list of supported properties of shortcuts.
-->
<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="QList&lt;QPair&lt;QString,QVariantMap&gt;&gt;"/>
</signal>

<property name="version" type="u" access="read"/>
</interface>
</node>
86 changes: 86 additions & 0 deletions auxiliary_files/org.freedesktop.portal.Request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0"?>
<!--
Copyright (C) 2015 Red Hat, Inc.

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: Alexander Larsson <[email protected]>
-->

<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<!--
org.freedesktop.portal.Request:
@short_description: Shared request interface

The Request interface is shared by all portal interfaces. When a
portal method is called, the reply includes a handle (i.e. object path)
for a Request object, which will stay alive for the duration of the
user interaction related to the method call.

The portal indicates that a portal request interaction is over by
emitting the #org.freedesktop.portal.Request::Response signal on the
Request object.

The application can abort the interaction calling
org.freedesktop.portal.Request.Close() on the Request object.

Since version 0.9 of xdg-desktop-portal, the handle will be of the form
/org/freedesktop/portal/desktop/request/SENDER/TOKEN,
where SENDER is the callers unique name, with the initial ':' removed and
all '.' replaced by '_', and TOKEN is a unique token that the caller provided
with the handle_token key in the options vardict.

This change was made to let applications subscribe to the Response signal before
making the initial portal call, thereby avoiding a race condition. It is recommended
that the caller should verify that the returned handle is what it expected, and update
its signal subscription if it isn't. This ensures that applications will work with both
old and new versions of xdg-desktop-portal.

The token that the caller provides should be unique and not guessable. To avoid clashes
with calls made from unrelated libraries, it is a good idea to use a per-library prefix
combined with a random number.
-->
<interface name="org.freedesktop.portal.Request">

<!--
Close:

Closes the portal request to which this object refers and ends all
related user interaction (dialogs, etc).
A Response signal will not be emitted in this case.
-->
<method name="Close">
</method>

<!--
Response:
@response: Numeric response
@results: Vardict with results. The keys and values in the vardict depend on the request.

Emitted when the user interaction for a portal request is over.

The @response indicates how the user interaction ended:
<simplelist>
<member>0: Success, the request is carried out</member>
<member>1: The user cancelled the interaction</member>
<member>2: The user interaction was ended in some other way</member>
</simplelist>
-->
<signal name="Response">
<arg type="u" name="response"/>
<arg type="a{sv}" name="results"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
</signal>
</interface>
</node>
6 changes: 6 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,16 @@ if(dbus AND NOT WIN32 AND NOT APPLE)
PRIVATE
"DBus.cpp"
"DBus.h"
"GlobalShortcut_xdp.cpp"
)

qt5_add_dbus_interface(mumble_xdp_SRCS ${CMAKE_SOURCE_DIR}/auxiliary_files/org.freedesktop.portal.GlobalShortcuts.xml globalshortcuts_portal_interface)
qt5_add_dbus_interface(mumble_xdp_SRCS ${CMAKE_SOURCE_DIR}/auxiliary_files/org.freedesktop.portal.Request.xml portalsrequest_interface)
target_sources(mumble_client_object_lib PRIVATE ${mumble_xdp_SRCS})
target_compile_definitions(mumble_client_object_lib PUBLIC "USE_DBUS")
target_link_libraries(mumble_client_object_lib PUBLIC Qt5::DBus)
target_include_directories(mumble_client_object_lib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

endif()

if(translations)
Expand Down
Loading

0 comments on commit a59e8f3

Please sign in to comment.