eww -> notification: Refactor widget to work with end-rs
This commit is contained in:
parent
13f8a8707c
commit
63c1da3f34
3 changed files with 66 additions and 95 deletions
|
@ -1,26 +1,45 @@
|
||||||
.notifications-container {
|
.notification {
|
||||||
padding: 8px;
|
padding: 6px;
|
||||||
|
margin-right: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
background-color: $background;
|
||||||
|
border-radius: 20px;
|
||||||
|
|
||||||
.notification {
|
.notification-app-icon {
|
||||||
padding: 6px;
|
min-width: 24px;
|
||||||
background-color: $background;
|
min-height: 24px;
|
||||||
border-radius: 20px;
|
|
||||||
|
|
||||||
.notification-icon {
|
background-size: cover;
|
||||||
min-width: 128px;
|
background-position: center center;
|
||||||
min-height: 128px;
|
}
|
||||||
|
|
||||||
background-size: cover;
|
.notification-icon {
|
||||||
background-position: center center;
|
min-width: 128px;
|
||||||
border-radius: 16px;
|
min-height: 128px;
|
||||||
|
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center center;
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notification-text-container {
|
||||||
|
padding-top: 6px;
|
||||||
|
|
||||||
|
.notification-summary {
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.notification-text-container {
|
.notification-buttons {
|
||||||
padding-top: 6px;
|
margin-top: 6px;
|
||||||
|
|
||||||
.notification-summary {
|
.notification-button {
|
||||||
font-weight: bold;
|
color: $text;
|
||||||
}
|
font-size: 0.8em;
|
||||||
|
padding: 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-right: 12px;
|
||||||
|
border: 1px solid $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
(defvar close_icon "/usr/share/icons/Qogir-ubuntu-dark/16/actions/window-close.svg")
|
(defvar close_icon "/usr/share/icons/Qogir-ubuntu-dark/16/actions/window-close.svg")
|
||||||
|
|
||||||
(deflisten notifications :initial '[{"id": 69, "dismissed": false, "app_name": "notify-send", "replaces_id": 0, "app_icon": "/home/gaspard/Images/memes/vroom.png", "summary": "Work period over", "body": "You can take a little nap now.", "actions": [], "hints": {"urgency": 1, "sender-pid": 12406}, "expire_timeout": -1}]' "~/.config/eww/scripts/get-notifications")
|
(defvar end-binary "~/.cargo/bin/end-rs")
|
||||||
|
(defvar end-notifications '')
|
||||||
|
(defvar end-histories '')
|
||||||
|
(defvar end-replies '')
|
||||||
|
(defvar end-reply-text '')
|
||||||
|
|
||||||
(defwidget notification [notif]
|
(defwidget notification[notification]
|
||||||
(box
|
(box
|
||||||
:class "notification"
|
:class "notification"
|
||||||
:space-evenly false
|
:space-evenly false
|
||||||
:orientation "v"
|
:orientation "v"
|
||||||
:spacing 6
|
:spacing 6
|
||||||
(box :orientation "h" :spacing 8 :space-evenly false
|
(box :orientation "h" :spacing 8 :space-evenly false
|
||||||
(image
|
(box
|
||||||
:path "/usr/share/icons/Qogir-ubuntu/scalable/apps/spotify.svg"
|
:class "${notification.app_icon ?: "" != "" ? "notification-app-icon" : ""}"
|
||||||
:image-width 24
|
:style "background-image: url('${notification.app_icon}');"
|
||||||
:image-height 24)
|
)
|
||||||
(label
|
(label
|
||||||
:text "${notif.app_name}"
|
:text "${notification.application}"
|
||||||
:halign "start"
|
:halign "start"
|
||||||
:hexpand true)
|
:hexpand true)
|
||||||
(button :onclick "dbus-send --session --dest=org.freedesktop.Notifications --type=method_call /org/freedesktop/Notifications org.freedesktop.Notifications.CloseNotification uint32:${notif.id}"
|
(button :onclick "${end-binary} close ${notification.id}"
|
||||||
(image
|
(image
|
||||||
:path "${close_icon}"
|
:path "${close_icon}"
|
||||||
:image-width 24
|
:image-width 24
|
||||||
|
@ -26,8 +30,8 @@
|
||||||
)
|
)
|
||||||
(box :orientation "h" :space-evenly false :spacing 8
|
(box :orientation "h" :space-evenly false :spacing 8
|
||||||
(box
|
(box
|
||||||
:class "${notif.app_icon != "" ? "notification-icon" : ""}"
|
:class "${notification.icon != "" ? "notification-icon" : ""}"
|
||||||
:style "background-image: url('${notif.app_icon}');"
|
:style "background-image: url('${notification.icon}');"
|
||||||
)
|
)
|
||||||
(box
|
(box
|
||||||
:class "notification-text-container"
|
:class "notification-text-container"
|
||||||
|
@ -36,13 +40,26 @@
|
||||||
:space-evenly false
|
:space-evenly false
|
||||||
(label
|
(label
|
||||||
:class "notification-summary"
|
:class "notification-summary"
|
||||||
:text "${notif.summary}"
|
:text "${notification.summary}"
|
||||||
:halign "start")
|
:halign "start")
|
||||||
(label
|
(label
|
||||||
:text "${notif.body}"
|
:text "${notification.body}"
|
||||||
:wrap true
|
:wrap true
|
||||||
:halign "fill"
|
:halign "fill"
|
||||||
:vexpand true)
|
:vexpand true)
|
||||||
|
(box
|
||||||
|
:class "notification-buttons"
|
||||||
|
:orientation "horizontal"
|
||||||
|
:space-evenly false
|
||||||
|
:halign "end"
|
||||||
|
:vexpand false
|
||||||
|
(for action in {notification.actions}
|
||||||
|
(button
|
||||||
|
:class "notification-button"
|
||||||
|
:onclick "${end-binary} action ${notification.id} ${action.id}"
|
||||||
|
:vexpand false
|
||||||
|
{action.text}))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -57,14 +74,5 @@
|
||||||
:stacking "overlay"
|
:stacking "overlay"
|
||||||
:focusable false
|
:focusable false
|
||||||
:exclusive true
|
:exclusive true
|
||||||
(box
|
(literal :content end-notifications)
|
||||||
:class "notifications-container"
|
|
||||||
:orientation "v"
|
|
||||||
:halign "end"
|
|
||||||
:valign "end"
|
|
||||||
:spacing 6
|
|
||||||
(for notif in {jq(notifications, '[.[] | select(.dismissed == false)]')}
|
|
||||||
(notification :notif "${notif}")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import json
|
|
||||||
import dbus
|
|
||||||
from random import randint
|
|
||||||
from threading import Timer
|
|
||||||
from gi.repository import GLib
|
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
|
||||||
|
|
||||||
DEFAULT_NOTIF_TIMEOUT = 10 * 1000
|
|
||||||
|
|
||||||
notification_history = []
|
|
||||||
|
|
||||||
def set_timeout(fn, ms, *args, **kwargs):
|
|
||||||
t = Timer(ms / 1000, fn, args=args, kwargs=kwargs)
|
|
||||||
t.start()
|
|
||||||
return t
|
|
||||||
|
|
||||||
def dismiss_notification(notification_id: int):
|
|
||||||
for notification in notification_history:
|
|
||||||
if notification["id"] == notification_id:
|
|
||||||
notification["dismissed"] = True
|
|
||||||
|
|
||||||
print(json.dumps(notification_history), flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_notification(_, message):
|
|
||||||
keys = ["app_name", "replaces_id", "app_icon", "summary",
|
|
||||||
"body", "actions", "hints", "expire_timeout"]
|
|
||||||
args = message.get_args_list()
|
|
||||||
match message.get_member() :
|
|
||||||
case "Notify":
|
|
||||||
notification = dict([(keys[i], args[i]) for i in range(8)])
|
|
||||||
notification["dismissed"] = False
|
|
||||||
notification["id"] = randint(0, 8192 * 2)
|
|
||||||
notification_history.append(notification)
|
|
||||||
|
|
||||||
expire_timeout = int(notification["expire_timeout"])
|
|
||||||
set_timeout(dismiss_notification, expire_timeout if expire_timeout > 0 else DEFAULT_NOTIF_TIMEOUT, notification["id"])
|
|
||||||
|
|
||||||
print(json.dumps(notification_history), flush=True)
|
|
||||||
case "CloseNotification":
|
|
||||||
dismiss_notification(int(args[0]))
|
|
||||||
case _:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
DBusGMainLoop(set_as_default=True)
|
|
||||||
|
|
||||||
notification_bus = dbus.SessionBus()
|
|
||||||
notification_bus.add_match_string("type='method_call',interface='org.freedesktop.Notifications',eavesdrop=true")
|
|
||||||
notification_bus.add_message_filter(handle_notification)
|
|
||||||
|
|
||||||
loop = GLib.MainLoop()
|
|
||||||
loop.run()
|
|
Loading…
Reference in a new issue