mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-22 03:57:30 +03:00
Add support for OSC 777 based desktop notifications
Might as well, since we also support OSC 9, so why not yet another poorly designed legacy scheme.
This commit is contained in:
parent
24d5fc5f15
commit
0f193141af
@ -112,6 +112,8 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
- 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]
|
||||
----------------------
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -620,6 +620,11 @@ def set_title(self, title: Optional[str]) -> None:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user