diff --git a/docs/changelog.rst b/docs/changelog.rst index e4cfc2e94..592ec41a2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -112,6 +112,8 @@ To update |kitty|, :doc:`follow the instructions `. - All tab bar margins are now drawn using the general background color, instead of drawing only the left and right margins with the tab bar background color +- Add support for OSC 777 based desktop notifications + 0.23.1 [2021-08-17] ---------------------- diff --git a/kitty/notify.py b/kitty/notify.py index 935df40f6..eb4d69ff1 100644 --- a/kitty/notify.py +++ b/kitty/notify.py @@ -67,6 +67,9 @@ class NotificationCommand: body: str = '' actions: str = '' + 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})' + def parse_osc_9(raw: str) -> NotificationCommand: ans = NotificationCommand() @@ -74,6 +77,15 @@ def parse_osc_9(raw: str) -> NotificationCommand: return ans +def parse_osc_777(raw: str) -> NotificationCommand: + parts = raw.split(';', 1) + ans = NotificationCommand() + ans.title = parts[0] + if len(parts) > 1: + ans.body = parts[1] + return ans + + def parse_osc_99(raw: str) -> NotificationCommand: cmd = NotificationCommand() metadata, payload = raw.partition(';')[::2] @@ -201,3 +213,8 @@ def handle_notification_cmd( if osc_code == 9: cmd = parse_osc_9(raw_data) notify_with_command(cmd, window_id, notify_implementation) + return cmd + if osc_code == 777: + cmd = parse_osc_777(raw_data) + notify_with_command(cmd, window_id, notify_implementation) + return cmd diff --git a/kitty/parser.c b/kitty/parser.c index 93c7ffcbf..97be57c9b 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -420,6 +420,7 @@ dispatch_osc(Screen *screen, PyObject DUMP_UNUSED *dump_callback) { break; case 9: case 99: + case 777: START_DISPATCH DISPATCH_OSC_WITH_CODE(desktop_notify) END_DISPATCH diff --git a/kitty/window.py b/kitty/window.py index 24a9a366b..c9ecd2698 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -620,6 +620,11 @@ class Window: self.title_updated() def desktop_notify(self, osc_code: int, raw_data: str) -> None: + if osc_code == 777: + if not raw_data.startswith('notify;'): + log_error(f'Ignoring unknown OSC 777: {raw_data}') + return # unknown OSC 777 + raw_data = raw_data[len('notify;'):] cmd = handle_notification_cmd(osc_code, raw_data, self.id, self.prev_osc99_cmd) if cmd is not None and osc_code == 99: self.prev_osc99_cmd = cmd