Skip to main content

global-shortcut-portal

A pure-Python library for the Wayland Global Shortcut Portal (org.freedesktop.portal.GlobalShortcuts).
Lets any application register and receive global keyboard shortcuts on Wayland, without X11 key grabbing.

AI was used heavily during development, with human review and testing of all code.
This is a personal library I wanted and I'm sharing it in case it's useful to others.

Requirements

  • Python >= 3.10
  • dbus-next (pure Python, no C extensions)
  • A Wayland compositor with a Global Shortcuts portal backend (KDE Plasma 6+, GNOME 48+, Hyprland, etc.)

Installation

pip install global-shortcut-portal

On systems with an externally managed environment (e.g. recent Debian/Ubuntu, Fedora, Arch Linux with system Python) use pip install --user or a virtual environment. Alternatively, install with uv:

uv pip install global-shortcut-portal

For development, clone the repo and run:

uv sync --group dev

Reference Example

The repository includes a fully-commented reference app at examples/reference_example_app.py that demonstrates the complete session lifecycle with interactive controls:

Key Action
b Bind example shortcuts with default triggers
e Register shortcuts without triggers
c Open the native config dialog
r Reset the session
q Quit
python examples/reference_example_app.py

Documentation

Quick Start

import asyncio
from global_shortcut_portal import GlobalShortcutsSession, Portal, Shortcut, SessionCallback

class MyCallback(SessionCallback):
    def on_activated(self, event):
        print(f"Shortcut activated: {event.shortcut_id}")

    def on_deactivated(self, event):
        print(f"Shortcut deactivated: {event.shortcut_id}")

async def main():
    portal = Portal()
    await portal.connect()

    session = GlobalShortcutsSession(
        portal,
        app_id="org.example.MyApp",
        callback=MyCallback(),
    )
    await session.connect()

    shortcuts = [
        Shortcut(
            id="toggle-overlay",
            description="Toggle overlay window",
            preferred_trigger="<Control><Alt>space",
        ),
    ]
    bound = await session.bind(shortcuts)
    for s in bound:
        print(f"Bound: {s.id} -> {s.trigger_description}")

    await asyncio.Event().wait()

asyncio.run(main())

Features

  • Async API via dbus-next (pure Python asyncio D-Bus library)
  • Session life-cycle management (create, bind, list, configure, close)
  • Supports Registry.Register for xdg-desktop-portal >= 1.20
  • Full signal handling (Activated, Deactivated, ShortcutsChanged)
  • Shortcut trigger parsing and formatting (XDG shortcuts specification)
  • Version 2 portal features (ConfigureShortcuts)

Notes

  • Desktop environment persistence: Some DEs (notably Plasma/KDE) persist shortcut triggers per app_id. Once registered, BindShortcuts cannot overwrite these stored values. Use the native config dialog or remove entries in System Settings > Keyboard > Shortcuts while the app is closed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

global_shortcut_portal-0.1.1.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

global_shortcut_portal-0.1.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file global_shortcut_portal-0.1.1.tar.gz.

File metadata

  • Download URL: global_shortcut_portal-0.1.1.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for global_shortcut_portal-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a005e984dda356e411bdc547925cbc86abad992eefc003fd0d28272d14835427
MD5 72a19720016e6e7a061f7564ae7ca9c2
BLAKE2b-256 01efe089e450a536824ecf8fc161ab68ea585754ba89ab563b02ff21b752c090

See more details on using hashes here.

File details

Details for the file global_shortcut_portal-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for global_shortcut_portal-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a0f8611a6921b6151144de9cbd13e532a929c7c701506adbe7f4cfc024ddeeb
MD5 5e2d81552b7a0e9dddc77afcebfde0e2
BLAKE2b-256 aa5c2519d8c1f88e3d76b2c6c4b63bd7d6ad0083c7e81cb5499cd3f76f3e39c5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page