feat: support global shortcuts via GlobalShortcutsPortal feature with ozone/wayland (#45171)

* fix: backport patch to fix systemd unit activation in Chromium

This backports a patch from Chromium, which fixes systemd unit
activation. That is, a globalShortcuts feature that Chromium has
needs to create a systemd unit and rename it properly. Portal's
global shortcuts uses that name afterwards to map the app with
the shortcuts bound. However, there might be a race between
Chromium binding shortcuts and renaming the unit.

This is a first step to add Portal's globalShortcuts to
Electron.

* feat: Support global shortcuts via GlobalShortcutsPortal feature

Chromium has a new feature called GlobalShortcutsPortal. It
allows clients to use Portal's globalShortcuts to register and
listen to shortcuts.

This patches adds necessary bits, which allows Electron to
use that feature.

In order to make it work, one has to add
--enable-features=GlobalShortcutsPortal

Test: tested manually with a sample app.

* docs: add GlobalShortcutsPortal feature to globalShortcuts docs

Electron supports Portal's globalShortcuts API now via Chromium, and Electron
apps can use that in a Wayland session. Update the docs with the required
feature flag that must be passed to be able to use that implementation.
This commit is contained in:
Maksim Sisov 2025-01-22 12:59:48 +02:00 committed by GitHub
parent cf67dc8898
commit 3ea623364b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 591 additions and 9 deletions

View file

@ -44,6 +44,7 @@ class GlobalShortcut final
private:
typedef std::map<ui::Accelerator, base::RepeatingClosure>
AcceleratorCallbackMap;
typedef std::map<std::string, base::RepeatingClosure> CommandCallbackMap;
bool RegisterAll(const std::vector<ui::Accelerator>& accelerators,
const base::RepeatingClosure& callback);
@ -60,6 +61,7 @@ class GlobalShortcut final
const std::string& command_id) override;
AcceleratorCallbackMap accelerator_callback_map_;
CommandCallbackMap command_callback_map_;
};
} // namespace electron::api