Compare commits

...

3 commits

Author SHA1 Message Date
GaspardCulis
a99d3b531e
feat(eww -> notifications): Imlement notification timeout 2024-06-23 12:51:44 +02:00
GaspardCulis
ea759f6791
fix(eww -> bar): Fixed invalid defaults producting errors 2024-06-22 21:17:31 +02:00
GaspardCulis
0fc899f637
feat(eww): Added "notification widget" 2024-06-22 21:16:35 +02:00
6 changed files with 156 additions and 3 deletions

View file

@ -15,8 +15,8 @@
`date +" %H:%M  %a, %b %d"`)
(defpoll power_profile :interval "10s" :initial "" "~/.config/eww/scripts/power_profile")
(defpoll gpu_status :initial "active" :interval "2s" "cat /sys/bus/pci/devices/0000:01:00.0/power/runtime_status")
(defpoll power_now :initial "active" :interval "5s" "cat /sys/class/power_supply/BAT0/power_now")
(defpoll energy_now :initial "active" :interval "5s" "cat /sys/class/power_supply/BAT0/energy_now")
(defpoll power_now :initial "0" :interval "5s" "cat /sys/class/power_supply/BAT0/power_now")
(defpoll energy_now :initial "0" :interval "5s" "cat /sys/class/power_supply/BAT0/energy_now")
(defpoll refresh_rate :interval "10s" :initial "165" "~/.config/eww/scripts/refresh_rate")
(defpoll vpn_status :interval "60s" :initial '{"connected": false}' "~/.config/eww/scripts/vpn_status")
@ -67,7 +67,6 @@
connectivity.state == "wireless" ? connectivity.wifi.ssid :
connectivity.state == "tethering" ? "USB tethering" : ''
}"
:tooltip "${connectivity.ip.local}"
:limit-width 14)
)
)

View file

@ -3,6 +3,7 @@
@import "./music/style.scss";
@import "./timer/style.scss";
@import "./freqtrade/style.scss";
@import "./notification/style.scss";
* {
all: unset;

View file

@ -2,5 +2,6 @@
(include "./music/widget.yuck")
(include "./timer/widget.yuck")
(include "./freqtrade/widget.yuck")
(include "./notification/widget.yuck")

View 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;
}
}
}
}

View 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}")
)
)
)

View file

@ -0,0 +1,56 @@
#!/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()