Skip to content

Commit dbbf7d6

Browse files
author
Anton Lobov
committed
Fixed autokill of runner script, added initial dbus support
1 parent b0123d8 commit dbbf7d6

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

bashets.lua

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- @author Anton Lobov <[email protected]>
55
-- @copyright 2010 Anton Lobov
66
-- @license GPLv3
7-
-- @release 0.5 for Awesome-git
7+
-- @release 0.6 for Awesome-git
88
-----------------------------------------------------------------------
99

1010
-- Grab only needed enviroment
@@ -16,10 +16,10 @@ local pairs = pairs
1616
--local timer = timer
1717
local type = type
1818
--local image = image
19-
local capi = {oocairo = oocairo, timer=timer}
19+
local capi = {oocairo = oocairo, timer = timer, dbus = dbus}
2020
local tonumber = tonumber
2121
local print = print
22-
22+
local error = error
2323

2424
--- Bashets module
2525
module("bashets")
@@ -275,7 +275,7 @@ function start()
275275
end
276276

277277
-- Kill all externals (if some were here from previous launch)
278-
awful.util.spawn_with_shell('killall ' .. defaults.updater)
278+
--awful.util.spawn_with_shell('killall ' .. defaults.updater)
279279

280280
-- Run all externals
281281
for _, wgt in pairs(ewidgets) do
@@ -361,11 +361,11 @@ function schedule_e(script, widget, callback, format, updtime, sep)
361361
ewidgets[key].format = format
362362
ewidgets[key].separator = sep
363363
ewidgets[key].cmd = util.fullpath(defaults.updater) .. " \"" .. ascript .. "\" " .. key .. " " ..updtime
364+
--print(ewidgets[key].cmd)
364365

365366
-- awful.util.spawn_with_shell()
366367
end
367368

368-
369369
function external_w(raw_data, key)
370370

371371
local callback = ewidgets[key].callback or nil
@@ -385,6 +385,40 @@ function external_w(raw_data, key)
385385
end
386386
end
387387

388+
function register_d(bus, iface, widget, callback, format)
389+
if capi.dbus then
390+
bus = bus or "session"
391+
capi.dbus.add_match(bus, "interface='" .. iface .. "'")
392+
393+
capi.dbus.connect_signal(iface, function (...)
394+
local argums = {...}
395+
local data = {}
396+
for _,v in pairs(argums) do
397+
if type(v) == "table" then
398+
for _,iv in pairs(v) do
399+
table.insert(data, iv)
400+
end
401+
else
402+
table.insert(data, v)
403+
end
404+
end
405+
406+
if callback ~= nil and type(callback) == "function" then
407+
if widget ~= nil then
408+
util.update_widget(widget, data, format)
409+
callback(data)
410+
else
411+
callback(data)
412+
end
413+
elseif widget ~= nil then
414+
util.update_widget(widget, data, format)
415+
end
416+
end)
417+
else
418+
error("bashets: You are trying to employ dbus, but no dbus api detected in your build of awesome")
419+
end
420+
end
421+
388422

389423

390424
--- Register script for text widget
@@ -412,6 +446,8 @@ function register(object, options)
412446
local sep = options.separator or defaults.separator
413447
local callback = options.callback
414448
local async = options.async or false
449+
local isdbus = options.dbus or false
450+
local busname = options.busname or "session"
415451
local readfile = options.read_file or false
416452
local widget = options.widget
417453
local external = options.external or false
@@ -452,6 +488,9 @@ function register(object, options)
452488
elseif external then -- Script provides external data through dbus
453489
local script = util.fullpath(object)
454490
schedule_e(script, widget, callback, format, updtime, sep)
491+
elseif isdbus then -- Data is fetched through a message bus
492+
register_d(busname, object, widget, callback, format)
493+
--print("registered with bus name \"" .. busname .. "\" and object \"" .. object .. "\"")
455494
else -- Fast script that can be read through pread
456495
local script = util.fullpath(object)
457496

0 commit comments

Comments
 (0)