render notification summaries in a layer-shell
This commit is contained in:
parent
42d5d8f4e6
commit
2d5e530939
@ -3,10 +3,12 @@
|
|||||||
(local Gio lgi.Gio)
|
(local Gio lgi.Gio)
|
||||||
(local GLib lgi.GLib)
|
(local GLib lgi.GLib)
|
||||||
(local GV lgi.GLib.Variant)
|
(local GV lgi.GLib.Variant)
|
||||||
|
(local GtkLayerShell lgi.GtkLayerShell)
|
||||||
(local variant dbus.variant)
|
(local variant dbus.variant)
|
||||||
(local inspect (require :inspect))
|
|
||||||
(local Gtk lgi.Gtk)
|
(local Gtk lgi.Gtk)
|
||||||
|
|
||||||
|
(local inspect (require :inspect))
|
||||||
|
|
||||||
|
|
||||||
(local dbus-service-attrs
|
(local dbus-service-attrs
|
||||||
{
|
{
|
||||||
@ -47,11 +49,63 @@
|
|||||||
DBUS_REQUEST_NAME_REPLY_EXISTS
|
DBUS_REQUEST_NAME_REPLY_EXISTS
|
||||||
(error "already running")))
|
(error "already running")))
|
||||||
|
|
||||||
|
;; for each open message there is a widget
|
||||||
|
;; when a message is closed, we need to find its widget
|
||||||
|
;; and remove it from the container
|
||||||
|
;; if there are no messages left, hide the windox
|
||||||
|
|
||||||
|
(fn make-window []
|
||||||
|
(let [window (Gtk.Window {:width 360
|
||||||
|
:on_destroy Gtk.main_quit})
|
||||||
|
box (Gtk.Box {
|
||||||
|
:orientation Gtk.Orientation.VERTICAL
|
||||||
|
})]
|
||||||
|
(window:add box)
|
||||||
|
(when true
|
||||||
|
(GtkLayerShell.init_for_window window)
|
||||||
|
(GtkLayerShell.set_layer window GtkLayerShell.Layer.TOP)
|
||||||
|
(GtkLayerShell.auto_exclusive_zone_enable window)
|
||||||
|
(GtkLayerShell.set_margin window GtkLayerShell.Edge.TOP 1)
|
||||||
|
(GtkLayerShell.set_margin window GtkLayerShell.Edge.BOTTOM 10)
|
||||||
|
(GtkLayerShell.set_anchor window GtkLayerShell.Edge.TOP 1))
|
||||||
|
(window:hide)
|
||||||
|
{:window window :box box}))
|
||||||
|
|
||||||
|
(local window (make-window))
|
||||||
|
|
||||||
|
(local notifications {})
|
||||||
|
|
||||||
|
(fn update-window []
|
||||||
|
(each [id widget (pairs notifications)]
|
||||||
|
(print id (widget:get_parent))
|
||||||
|
(if (not (widget:get_parent))
|
||||||
|
(window.box:pack_start widget false false 5)))
|
||||||
|
(if (next notifications) (window.window:show_all) (window:hide)))
|
||||||
|
|
||||||
(var notification-id 10)
|
(var notification-id 10)
|
||||||
(fn next-id []
|
(fn next-notification-id []
|
||||||
(set notification-id (+ notification-id 1))
|
(set notification-id (+ notification-id 1))
|
||||||
notification-id)
|
notification-id)
|
||||||
|
|
||||||
|
(fn update-notification-widget [widget noti]
|
||||||
|
(set widget.label noti.summary))
|
||||||
|
|
||||||
|
(fn add-notification [noti]
|
||||||
|
(let [id (if (= noti.id 0) (next-notification-id) noti.id)
|
||||||
|
widget (or (. notifications id)
|
||||||
|
(Gtk.Label))]
|
||||||
|
(update-notification-widget widget noti)
|
||||||
|
(tset notifications id widget)
|
||||||
|
(update-window)
|
||||||
|
id))
|
||||||
|
|
||||||
|
(fn make-notification [params]
|
||||||
|
{
|
||||||
|
:sender (. params 1)
|
||||||
|
:id (. params 2)
|
||||||
|
:summary (. params 4)
|
||||||
|
:body (. params 6)
|
||||||
|
})
|
||||||
|
|
||||||
(fn handle-dbus-method-call [conn sender path interface method params invocation]
|
(fn handle-dbus-method-call [conn sender path interface method params invocation]
|
||||||
(when (and (= path dbus-service-attrs.path)
|
(when (and (= path dbus-service-attrs.path)
|
||||||
@ -68,9 +122,11 @@
|
|||||||
"1.2"]))
|
"1.2"]))
|
||||||
|
|
||||||
"Notify"
|
"Notify"
|
||||||
(let [p params]
|
(let [p (dbus.variant.strip params)
|
||||||
(print (inspect (dbus.variant.strip p)))
|
n (make-notification p)]
|
||||||
(invocation:return_value (GV "(u)" [(next-id)]))))))
|
(invocation:return_value (GV "(u)"
|
||||||
|
[(add-notification n)])))
|
||||||
|
)))
|
||||||
|
|
||||||
(fn handle-dbus-get [conn sender path interface name]
|
(fn handle-dbus-get [conn sender path interface name]
|
||||||
(when (and (= path dbus-service-attrs.path)
|
(when (and (= path dbus-service-attrs.path)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
, fetchurl
|
, fetchurl
|
||||||
, gobject-introspection
|
, gobject-introspection
|
||||||
, gtk3
|
, gtk3
|
||||||
|
, gtk-layer-shell
|
||||||
, lib
|
, lib
|
||||||
, librsvg
|
, librsvg
|
||||||
, lua53Packages
|
, lua53Packages
|
||||||
@ -35,7 +36,12 @@ in stdenv.mkDerivation {
|
|||||||
src =./.;
|
src =./.;
|
||||||
inherit fennel;
|
inherit fennel;
|
||||||
|
|
||||||
buildInputs = [ lua gtk3 gobject-introspection.dev ];
|
buildInputs = [
|
||||||
|
gobject-introspection.dev
|
||||||
|
gtk-layer-shell
|
||||||
|
gtk3
|
||||||
|
lua
|
||||||
|
];
|
||||||
nativeBuildInputs = [ lua makeWrapper ];
|
nativeBuildInputs = [ lua makeWrapper ];
|
||||||
|
|
||||||
makeFlags = [ "PREFIX=${placeholder "out"}" ];
|
makeFlags = [ "PREFIX=${placeholder "out"}" ];
|
||||||
|
Loading…
Reference in New Issue
Block a user