Skip to content

Commit ec7f597

Browse files
author
Anton Lobov
committed
0.6.2: fix markup bug, also move widget detection code to separate func
1 parent b8dd569 commit ec7f597

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

bashets.lua

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
-- @author Anton Lobov <[email protected]>
55
-- @copyright 2010 Anton Lobov
66
-- @license GPLv3
7-
-- @release 0.6.1 (meant to be backwards compatible with older versions)
8-
------------------------------------------------------------------------
7+
-- @release 0.6.2 for Awesome-git
8+
-----------------------------------------------------------------------
99

1010
-- Grab only needed enviroment
1111
local awful = require("awful")
@@ -145,11 +145,13 @@ end
145145
-- @param output sep-separated string of values
146146
-- @param format Format string
147147
-- @param sep Separator of values in string
148-
function util.format(parts, format, sep)
148+
function util.format(parts, format, escape)
149149
-- For each part with number "k" replace corresponding "$k" variable in format string
150150
for k,part in pairs(parts) do
151151
local part = string.gsub(part, "%%", "%1%1") --percent fix for next gsub (bug found in Wicked)
152-
part = awful.util.escape(part) --escape XML entities for correct Pango markup
152+
if escape then
153+
part = awful.util.escape(part) --escape XML entities for correct Pango markup
154+
end
153155
format = string.gsub(format, "$" .. k, part)
154156
end
155157

@@ -203,34 +205,64 @@ function util.create_timers_table()
203205
end
204206
end
205207

208+
209+
function util.get_widget_meta(widget)
210+
if widget.type == "imagebox" then --imagebox (old API)
211+
return {wtype = "imagebox", update = function (v) widget["image"] = image(v) end}
212+
elseif widget.set_image ~= nil then --imagebox (new API)
213+
return {wtype = "imagebox", update = function (v) widget:set_image(v) end}
214+
elseif widget.type == "textbox" then --textbox (old API)
215+
return {wtype = "textbox", update = function (v) widget["text"] = v end}
216+
elseif widget.set_markup ~= nil then
217+
return {wtype = "textbox", update = function (v) widget:set_markup(v) end} --textbox (new API)
218+
elseif widget.set_value ~= nil then --progressbar (new API)
219+
return {wtype = "progressbar", update = function (v) widget:set_value(tonumber(v)) end}
220+
elseif widget.add_value ~= nil then --graph (new API)
221+
return {wtype = "graph", update = function (v) widget:add_value(tonumber(v)) end}
222+
else
223+
return {wtype = "unknown", update = function (v) error("bashets: unknown widget type to deal with") end}
224+
end
225+
end
226+
227+
206228
function util.update_widget_field(widget, valuess)
229+
230+
local wid = util.get_widget_meta(widget)
231+
wid.update(valuess)
232+
233+
207234
-- print(widget.type)
208-
if widget.type == "imagebox" then --imagebox (old API)
209-
widget["image"] = image(valuess)
210-
elseif widget.set_image ~= nil then --imagebox (new API)
211-
--widget["image"] = capi.oocairo.image_surface_create_from_png(valuess)
212-
--widget:set_image(capi.oocairo.image_surface_create_from_png(valuess))
213-
widget:set_image(valuess)
214-
elseif widget.type == "textbox" then --textbox (old API)
215-
widget["text"] = valuess
216-
elseif widget.set_markup ~= nil then --textbox (new API)
217-
widget:set_markup(valuess)
218-
--elseif widget["widget"] ~= nil then
219-
elseif widget.set_value ~= nil then --progressbar
220-
widget:set_value(tonumber(valuess))
221-
elseif widget.add_value ~= nil then --graph
222-
widget:add_value(tonumber(valuess))
223-
end
224-
--end
235+
-- if widget.type == "imagebox" then --imagebox (old API)
236+
-- widget["image"] = image(valuess)
237+
-- elseif widget.set_image ~= nil then --imagebox (new API)
238+
-- --widget["image"] = capi.oocairo.image_surface_create_from_png(valuess)
239+
-- --widget:set_image(capi.oocairo.image_surface_create_from_png(valuess))
240+
-- widget:set_image(valuess)
241+
-- elseif widget.type == "textbox" then --textbox (old API)
242+
-- widget["text"] = valuess
243+
-- elseif widget.set_markup ~= nil then --textbox (new API)
244+
-- widget:set_markup(valuess)
245+
-- --elseif widget["widget"] ~= nil then
246+
-- elseif widget.set_value ~= nil then --progressbar
247+
-- widget:set_value(tonumber(valuess))
248+
-- elseif widget.add_value ~= nil then --graph
249+
-- widget:add_value(tonumber(valuess))
250+
-- end
251+
-- --end
225252
end
226253

227254
--- Update widget from values
228255
function util.update_widget(widget, values, format)
229256
if widget ~= nil then
257+
local w = util.get_widget_meta(widget)
230258
if type(values) == "table" then
231-
util.update_widget_field(widget, util.format(values, format))
259+
util.update_widget_field(widget, util.format(values, format, w.wtype == "textbox"))
232260
else
233-
util.update_widget_field(widget, values)
261+
if (w.wtype == "textbox") then
262+
util.update_widget_field(widget, awful.util.escape(values))
263+
else
264+
util.update_widget_field(widget, values)
265+
end
234266
end
235267
end
236268
end

0 commit comments

Comments
 (0)