Desktop notifications protocol: Add support for specifying urgency

This commit is contained in:
Kovid Goyal 2024-05-16 21:38:43 +05:30
parent 176dab37d9
commit 865f662216
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 19 additions and 4 deletions

View File

@ -70,6 +70,8 @@ Detailed list of changes
- Wayland: Fix infinite loop causing bad performance when using IME via fcitx5 due to a change in fcitx5 (:iss:`7396`)
- Desktop notifications protocol: Add support for specifying urgency
- Improve rendering of Unicode shade character to avoid Moire patterns (:pull:`7401`)
- kitten @ send-key: Fix some keys being sent in kitty keyboard protocol encoding when not using socket for remote control

View File

@ -120,12 +120,16 @@ Key Value Default Description
and not visible to the user, for example, because it is in an inactive tab or
its OS window is not currently active.
``always`` is the default and always honors the request.
``u`` ``0, 1 or 2`` ``unset`` The *urgency* of the notification. ``0`` is low, ``1`` is normal and ``2`` is critical.
If not specified normal is used.
======= ==================== ========== =================
.. note::
.. versionadded:: 0.35.0
Support for the ``u`` key to specify urgency
.. versionadded:: 0.31.0
Support for the ``o`` key to prevent notifications from focused windows
was added in kitty version 0.31.0
.. note::

View File

@ -93,9 +93,12 @@ class NotificationCommand:
body: str = ''
actions: str = ''
only_when: OnlyWhen = OnlyWhen.unset
urgency: Optional[Urgency] = None
def __repr__(self) -> str:
return f'NotificationCommand(identifier={self.identifier!r}, title={self.title!r}, body={self.body!r}, actions={self.actions!r}, done={self.done!r})'
return (
f'NotificationCommand(identifier={self.identifier!r}, title={self.title!r}, body={self.body!r},'
f'actions={self.actions!r}, done={self.done!r}, urgency={self.urgency})')
def parse_osc_9(raw: str) -> NotificationCommand:
@ -147,6 +150,9 @@ def parse_osc_99(raw: str) -> NotificationCommand:
elif k == 'o':
with suppress(ValueError):
cmd.only_when = OnlyWhen(v)
elif k == 'u':
with suppress(Exception):
cmd.urgency = Urgency(int(v))
if payload_type not in ('body', 'title'):
log_error(f'Malformed OSC 99: unknown payload type: {payload_type}')
return NotificationCommand()
@ -177,6 +183,8 @@ def merge_osc_99(prev: NotificationCommand, cmd: NotificationCommand) -> Notific
cmd.body = limit_size(prev.body + cmd.body)
if cmd.only_when is OnlyWhen.unset:
cmd.only_when = prev.only_when
if cmd.urgency is None:
cmd.urgency = prev.urgency
return cmd
@ -234,6 +242,7 @@ def notify_with_command(cmd: NotificationCommand, window_id: int, notify_impleme
body = cmd.body if cmd.title else ''
if not title:
return
urgency = Urgency.Normal if cmd.urgency is None else cmd.urgency
if cmd.only_when is not OnlyWhen.always and cmd.only_when is not OnlyWhen.unset:
w = get_boss().window_id_map.get(window_id)
if w is None:
@ -247,7 +256,7 @@ def notify_with_command(cmd: NotificationCommand, window_id: int, notify_impleme
return # window is in the active OS window and the active tab and is visible in the tab layout
if title:
identifier = f'i{next(id_counter)}'
notify_implementation(title, body, identifier)
notify_implementation(title, body, identifier, urgency)
register_identifier(identifier, cmd, window_id)