From 865f66221667117ab4d555bfd4bb81b4856f2a18 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 May 2024 21:38:43 +0530 Subject: [PATCH] Desktop notifications protocol: Add support for specifying urgency --- docs/changelog.rst | 2 ++ docs/desktop-notifications.rst | 8 ++++++-- kitty/notify.py | 13 +++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7ddf61a0a..4a07b8922 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 diff --git a/docs/desktop-notifications.rst b/docs/desktop-notifications.rst index 5e3217249..349629026 100644 --- a/docs/desktop-notifications.rst +++ b/docs/desktop-notifications.rst @@ -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:: diff --git a/kitty/notify.py b/kitty/notify.py index 3e4292dfc..d7aaf3416 100644 --- a/kitty/notify.py +++ b/kitty/notify.py @@ -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)