4
4
-- @author Anton Lobov <[email protected] >
5
5
-- @copyright 2010 Anton Lobov
6
6
-- @license GPLv3
7
- -- @release 0.5 for Awesome-git
7
+ -- @release 0.6 for Awesome-git
8
8
---- -------------------------------------------------------------------
9
9
10
10
-- Grab only needed enviroment
@@ -16,10 +16,10 @@ local pairs = pairs
16
16
-- local timer = timer
17
17
local type = type
18
18
-- local image = image
19
- local capi = {oocairo = oocairo , timer = timer }
19
+ local capi = {oocairo = oocairo , timer = timer , dbus = dbus }
20
20
local tonumber = tonumber
21
21
local print = print
22
-
22
+ local error = error
23
23
24
24
--- Bashets module
25
25
module (" bashets" )
@@ -275,7 +275,7 @@ function start()
275
275
end
276
276
277
277
-- 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)
279
279
280
280
-- Run all externals
281
281
for _ , wgt in pairs (ewidgets ) do
@@ -361,11 +361,11 @@ function schedule_e(script, widget, callback, format, updtime, sep)
361
361
ewidgets [key ].format = format
362
362
ewidgets [key ].separator = sep
363
363
ewidgets [key ].cmd = util .fullpath (defaults .updater ) .. " \" " .. ascript .. " \" " .. key .. " " .. updtime
364
+ -- print(ewidgets[key].cmd)
364
365
365
366
-- awful.util.spawn_with_shell()
366
367
end
367
368
368
-
369
369
function external_w (raw_data , key )
370
370
371
371
local callback = ewidgets [key ].callback or nil
@@ -385,6 +385,40 @@ function external_w(raw_data, key)
385
385
end
386
386
end
387
387
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
+
388
422
389
423
390
424
--- Register script for text widget
@@ -412,6 +446,8 @@ function register(object, options)
412
446
local sep = options .separator or defaults .separator
413
447
local callback = options .callback
414
448
local async = options .async or false
449
+ local isdbus = options .dbus or false
450
+ local busname = options .busname or " session"
415
451
local readfile = options .read_file or false
416
452
local widget = options .widget
417
453
local external = options .external or false
@@ -452,6 +488,9 @@ function register(object, options)
452
488
elseif external then -- Script provides external data through dbus
453
489
local script = util .fullpath (object )
454
490
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 .. "\"")
455
494
else -- Fast script that can be read through pread
456
495
local script = util .fullpath (object )
457
496
0 commit comments