feat(eww): Added "notification widget"
This commit is contained in:
parent
f88b2f52d8
commit
0fc899f637
5 changed files with 142 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
@import "./music/style.scss";
|
||||
@import "./timer/style.scss";
|
||||
@import "./freqtrade/style.scss";
|
||||
@import "./notification/style.scss";
|
||||
|
||||
* {
|
||||
all: unset;
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
(include "./music/widget.yuck")
|
||||
(include "./timer/widget.yuck")
|
||||
(include "./freqtrade/widget.yuck")
|
||||
(include "./notification/widget.yuck")
|
||||
|
||||
|
||||
|
|
26
bar/eww/notification/style.scss
Normal file
26
bar/eww/notification/style.scss
Normal file
|
@ -0,0 +1,26 @@
|
|||
.notifications-container {
|
||||
padding: 8px;
|
||||
|
||||
.notification {
|
||||
padding: 6px;
|
||||
background-color: $background;
|
||||
border-radius: 20px;
|
||||
|
||||
.notification-icon {
|
||||
min-width: 128px;
|
||||
min-height: 128px;
|
||||
|
||||
background-size: cover;
|
||||
background-position: center center;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.notification-text-container {
|
||||
padding-top: 6px;
|
||||
|
||||
.notification-summary {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
70
bar/eww/notification/widget.yuck
Normal file
70
bar/eww/notification/widget.yuck
Normal file
|
@ -0,0 +1,70 @@
|
|||
(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")
|
||||
|
||||
(defwidget notification [notif]
|
||||
(box
|
||||
:class "notification"
|
||||
:space-evenly false
|
||||
:orientation "v"
|
||||
:spacing 6
|
||||
(box :orientation "h" :spacing 8 :space-evenly false
|
||||
(image
|
||||
:path "/usr/share/icons/Qogir-ubuntu/scalable/apps/spotify.svg"
|
||||
:image-width 24
|
||||
:image-height 24)
|
||||
(label
|
||||
:text "${notif.app_name}"
|
||||
:halign "start"
|
||||
:hexpand true)
|
||||
(button :onclick "dbus-send --session --dest=org.freedesktop.Notifications --type=method_call /org/freedesktop/Notifications org.freedesktop.Notifications.CloseNotification uint32:${notif.id}"
|
||||
(image
|
||||
:path "${close_icon}"
|
||||
:image-width 24
|
||||
:image-height 24)
|
||||
)
|
||||
)
|
||||
(box :orientation "h" :space-evenly false :spacing 8
|
||||
(box
|
||||
:class "${notif.app_icon != "" ? "notification-icon" : ""}"
|
||||
:style "background-image: url('${notif.app_icon}');"
|
||||
)
|
||||
(box
|
||||
:class "notification-text-container"
|
||||
:orientation "v"
|
||||
:hexpand true
|
||||
:space-evenly false
|
||||
(label
|
||||
:class "notification-summary"
|
||||
:text "${notif.summary}"
|
||||
:halign "start")
|
||||
(label
|
||||
:text "${notif.body}"
|
||||
:wrap true
|
||||
:halign "fill"
|
||||
:vexpand true)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defwindow notification_overlay
|
||||
:namespace "eww.notification_overlay"
|
||||
:monitor 0
|
||||
:geometry (geometry
|
||||
:width "400px"
|
||||
:anchor "bottom right")
|
||||
:stacking "overlay"
|
||||
:focusable false
|
||||
:exclusive true
|
||||
(box
|
||||
:class "notifications-container"
|
||||
:orientation "v"
|
||||
:halign "end"
|
||||
:valign "end"
|
||||
:spacing 6
|
||||
(for notif in {jq(notifications, '[.[] | select(.dismissed == false)]')}
|
||||
(notification :notif "${notif}")
|
||||
)
|
||||
)
|
||||
)
|
44
bar/eww/scripts/get-notifications
Executable file
44
bar/eww/scripts/get-notifications
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import json
|
||||
import dbus
|
||||
from random import randint
|
||||
from gi.repository import GLib
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
|
||||
notification_history = []
|
||||
|
||||
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)
|
||||
case "CloseNotification":
|
||||
notification_id = int(args[0])
|
||||
for notification in notification_history:
|
||||
if notification["id"] == notification_id:
|
||||
notification["dismissed"] = True
|
||||
case _:
|
||||
return
|
||||
|
||||
print(json.dumps(notification_history), flush=True)
|
||||
|
||||
def handle_notification_dismiss(_, message):
|
||||
print("jaaj")
|
||||
print(message)
|
||||
|
||||
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