IDesktopGlobalShortcuts interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDesktopGlobalShortcuts : IAsyncDisposable

Inherits or implements IAsyncDisposable.

The application's global shortcuts: keys that start named actions while another application has the focus. One set for the application; disposing it removes every binding.

Remarks

Windows registers each key with RegisterHotKey and macOS with RegisterEventHotKey, so the application chooses the keys, usually from its own settings UI. Linux uses the desktop's GlobalShortcuts portal: the desktop owns the bindings and the user changes them in its settings (IDesktopGlobalShortcuts.ConfigureAsync). Only key presses are reported, not releases, and a held key reports one press.

Methods

BindAsync

ValueTask<PlatformResult<ImmutableArray<DesktopGlobalShortcutBinding>>> BindAsync(ImmutableArray<DesktopGlobalShortcut> shortcuts, CancellationToken cancellationToken = default)

Replaces the whole set of actions and binds their keys.

Parameters

shortcuts

At most 32 actions with unique ids; an empty set removes every binding.

cancellationToken

Cancels the wait; the previous set may already be gone.

Returns

One binding per action, in the order given; a key that cannot be bound fails alone, with its status.

Exceptions

ArgumentException

The set has more than 32 actions, a repeated id, or an id or description outside its rule.

ConfigureAsync

ValueTask<PlatformResult<PlatformUnit>> ConfigureAsync(CancellationToken cancellationToken = default)

Opens the desktop's settings for these shortcuts, where the user assigns the keys.

Remarks

Linux desktops with version 2 of the GlobalShortcuts portal open their dialog. Windows and macOS have no such settings and report PlatformUnavailableReason.BackendUnavailable: the application offers its own.

ListAsync

ValueTask<PlatformResult<ImmutableArray<DesktopGlobalShortcutBinding>>> ListAsync(CancellationToken cancellationToken = default)

Gets the current bindings, with the user's changes on Linux; empty before the first IDesktopGlobalShortcuts.BindAsync.

Events

Activated

event EventHandler<DesktopGlobalShortcutActivation>? Activated

Raised on a worker thread for each press of a bound key; dispatch window work through its presentation.

BindingsChanged

event EventHandler<DesktopGlobalShortcutsChange>? BindingsChanged

Raised on a worker thread after the user or the desktop changed a binding, for example in the Linux desktop's settings or after a keyboard layout change on macOS.