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:
Kovid Goyal
2021-10-25 10:46:00 +05:30
parent 24d5fc5f15
commit 0f193141af
4 changed files with 25 additions and 0 deletions

View File

@@ -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