summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2022-10-08 10:37:24 -0700
committerMike Crute <mike@crute.us>2022-10-08 10:37:24 -0700
commit422ae44cf64849d043240e9b4e0aec60fc628dad (patch)
tree6e6aff5cb45fb146ebec8772cd2d1955ee373235
parenta59a3486fbe17703df401d7153841268a604da6d (diff)
downloaddotfiles-422ae44cf64849d043240e9b4e0aec60fc628dad.tar.bz2
dotfiles-422ae44cf64849d043240e9b4e0aec60fc628dad.tar.xz
dotfiles-422ae44cf64849d043240e9b4e0aec60fc628dad.zip
More notes on dbus
-rw-r--r--.config/awesome/dbus_test.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/.config/awesome/dbus_test.lua b/.config/awesome/dbus_test.lua
index 4394029..50b9ff8 100644
--- a/.config/awesome/dbus_test.lua
+++ b/.config/awesome/dbus_test.lua
@@ -42,3 +42,68 @@ Gio.Async.call(function()
42 "GetAll" 42 "GetAll"
43 ) 43 )
44end)() 44end)()
45
46
47
48-- https://docs.gtk.org/gio/index.html
49
50-- From https://stackoverflow.com/questions/43588324/how-to-call-dbus-methods-in-awesome-wm
51
52local lgi = require("lgi")
53local Gio = lgi.require("Gio")
54local GLib = lgi.require("GLib")
55
56-- Workaround for https://github.com/pavouk/lgi/issues/142
57local function bus_get_async(type)
58 Gio.bus_get(type, nil, coroutine.running())
59 local a, b = coroutine.yield()
60 return Gio.bus_get_finish(b)
61end
62
63local function inhibit(bus, what, who, why, mode)
64 local name = "org.freedesktop.login1"
65 local object = "/org/freedesktop/login1"
66 local interface = "org.freedesktop.login1.Manager"
67 local message = Gio.DBusMessage.new_method_call(name, object, interface, "Inhibit")
68 message:set_body(GLib.Variant("(ssss)",
69 { what, who, why, mode }))
70
71 local timeout = -1 -- Just use the default
72 local result, err = bus:async_send_message_with_reply(message, Gio.DBusSendMessageFlags.NONE,
73 timeout, nil)
74
75 if err then
76 print("error: " .. tostring(err))
77 return
78 end
79
80 if result:get_message_type() == "ERROR" then
81 local _, err = result:to_gerror()
82 print("error: " .. tostring(err))
83 return
84 end
85
86 local fd_list = result:get_unix_fd_list()
87 local fd, err = fd_list:get(0)
88 if err then
89 print("error: " .. tostring(err))
90 return
91 end
92
93 -- Now... somehow turn this fd into something we can close
94 return Gio.UnixInputStream.new(fd, true)
95end
96
97Gio.Async.call(function()
98 local bus = bus_get_async(Gio.BusType.SYSTEM)
99 local a = inhibit(bus, "shutdown:sleep", "hi, it's me!", "Just because", "delay")
100 print("got lock")
101 io.popen("sleep 10"):read("*a")
102 a:async_close()
103 -- Speed up deletion of the GDBusMessage that still references the FD
104 collectgarbage("collect")
105 collectgarbage("collect")
106
107 print("released lock")
108 io.popen("sleep 10"):read("*a")
109end)()