add a dbus object to show/hide the launcher
This commit is contained in:
parent
c871ad2550
commit
bbba059634
@ -1,4 +1,7 @@
|
|||||||
|
(local lgi (require :lgi))
|
||||||
|
(local Gio lgi.Gio)
|
||||||
(local dbus (require :dbus_proxy))
|
(local dbus (require :dbus_proxy))
|
||||||
|
(local inspect (require :inspect))
|
||||||
|
|
||||||
(local bus (dbus.Proxy:new
|
(local bus (dbus.Proxy:new
|
||||||
{
|
{
|
||||||
@ -8,6 +11,19 @@
|
|||||||
:path "/org/freedesktop/DBus"
|
:path "/org/freedesktop/DBus"
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
(local interface-info
|
||||||
|
(let [xml
|
||||||
|
"<node>
|
||||||
|
<interface name='net.telent.saturn'>
|
||||||
|
<method name='SetVisible'>
|
||||||
|
<arg type='b' name='visible' direction='in'/>
|
||||||
|
</method>
|
||||||
|
</interface>
|
||||||
|
</node>"
|
||||||
|
node-info (Gio.DBusNodeInfo.new_for_xml xml)]
|
||||||
|
(. node-info.interfaces 1)))
|
||||||
|
|
||||||
|
|
||||||
(local DBUS_NAME_FLAG_DO_NOT_QUEUE 4)
|
(local DBUS_NAME_FLAG_DO_NOT_QUEUE 4)
|
||||||
(let [ret (bus:RequestName "net.telent.saturn" DBUS_NAME_FLAG_DO_NOT_QUEUE)]
|
(let [ret (bus:RequestName "net.telent.saturn" DBUS_NAME_FLAG_DO_NOT_QUEUE)]
|
||||||
(if (or (= ret 1) (= ret 4))
|
(if (or (= ret 1) (= ret 4))
|
||||||
@ -19,14 +35,12 @@
|
|||||||
(print "already running")
|
(print "already running")
|
||||||
(os.exit 0))))
|
(os.exit 0))))
|
||||||
|
|
||||||
;; https://vwangsf.medium.com/creating-a-d-bus-service-with-dbus-python-and-polkit-authentication-4acc9bc5ed29
|
|
||||||
|
|
||||||
(local lfs (require :lfs))
|
(local lfs (require :lfs))
|
||||||
(local inifile (require :inifile))
|
(local inifile (require :inifile))
|
||||||
(local inspect (require :inspect))
|
(local inspect (require :inspect))
|
||||||
(local posix (require :posix))
|
(local posix (require :posix))
|
||||||
|
|
||||||
(local lgi (require :lgi))
|
|
||||||
(local Gtk lgi.Gtk)
|
(local Gtk lgi.Gtk)
|
||||||
(local Pango lgi.Pango)
|
(local Pango lgi.Pango)
|
||||||
|
|
||||||
@ -95,25 +109,43 @@
|
|||||||
:on_clicked #(launch app) })
|
:on_clicked #(launch app) })
|
||||||
(: :set_image app.IconImage)))
|
(: :set_image app.IconImage)))
|
||||||
|
|
||||||
|
(local window (Gtk.Window {
|
||||||
|
:title "Saturn V"
|
||||||
|
:default_width 720
|
||||||
|
:default_height 800
|
||||||
|
:on_destroy Gtk.main_quit
|
||||||
|
}))
|
||||||
|
(fn handle-dbus-method-call [conn sender path interface method params invocation]
|
||||||
|
(when (and (= path "/net/telent/saturn")
|
||||||
|
(= interface "net.telent.saturn")
|
||||||
|
(= method "SetVisible"))
|
||||||
|
(let [[value] (dbus.variant.strip params)]
|
||||||
|
(if value (window:show_all) (window:hide))
|
||||||
|
(invocation:return_value nil))))
|
||||||
|
|
||||||
|
(Gio.DBusConnection.register_object
|
||||||
|
bus.connection
|
||||||
|
"/net/telent/saturn"
|
||||||
|
interface-info
|
||||||
|
(lgi.GObject.Closure handle-dbus-method-call)
|
||||||
|
(lgi.GObject.Closure (fn [a] (print "get")))
|
||||||
|
(lgi.GObject.Closure (fn [a] (print "set"))))
|
||||||
|
|
||||||
|
(local grid-columns 4)
|
||||||
|
|
||||||
(let [grid (Gtk.Grid {
|
(let [grid (Gtk.Grid {
|
||||||
:column_spacing 5
|
:column_spacing 2
|
||||||
:row_spacing 5
|
:row_spacing 5
|
||||||
})
|
})
|
||||||
scrolled-window (Gtk.ScrolledWindow {})
|
scrolled-window (Gtk.ScrolledWindow {})]
|
||||||
window (Gtk.Window {
|
|
||||||
:title "Saturn V"
|
|
||||||
:default_width 720
|
|
||||||
:default_height 800
|
|
||||||
:on_destroy Gtk.main_quit
|
|
||||||
})]
|
|
||||||
(var i 0)
|
(var i 0)
|
||||||
(each [_ app (pairs (all-apps))]
|
(each [_ app (pairs (all-apps))]
|
||||||
(let [x (% i 4)
|
(let [x (% i grid-columns)
|
||||||
y (// i 4)]
|
y (// i grid-columns)]
|
||||||
(set i (+ i 1))
|
(set i (+ i 1))
|
||||||
(grid:attach (button-for app) x y 1 1)))
|
(grid:attach (button-for app) x y 1 1)))
|
||||||
(scrolled-window:add grid)
|
(scrolled-window:add grid)
|
||||||
(window:add scrolled-window)
|
(window:add scrolled-window))
|
||||||
(window:show_all))
|
|
||||||
|
|
||||||
|
(window:show_all)
|
||||||
(Gtk:main)
|
(Gtk:main)
|
||||||
|
Loading…
Reference in New Issue
Block a user