|
4 | 4 | -- @author Anton Lobov <[email protected]>
|
5 | 5 | -- @copyright 2010 Anton Lobov
|
6 | 6 | -- @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 | +----------------------------------------------------------------------- |
9 | 9 |
|
10 | 10 | -- Grab only needed enviroment
|
11 | 11 | local awful = require("awful")
|
@@ -145,11 +145,13 @@ end
|
145 | 145 | -- @param output sep-separated string of values
|
146 | 146 | -- @param format Format string
|
147 | 147 | -- @param sep Separator of values in string
|
148 |
| -function util.format(parts, format, sep) |
| 148 | +function util.format(parts, format, escape) |
149 | 149 | -- For each part with number "k" replace corresponding "$k" variable in format string
|
150 | 150 | for k,part in pairs(parts) do
|
151 | 151 | 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 |
153 | 155 | format = string.gsub(format, "$" .. k, part)
|
154 | 156 | end
|
155 | 157 |
|
@@ -203,34 +205,64 @@ function util.create_timers_table()
|
203 | 205 | end
|
204 | 206 | end
|
205 | 207 |
|
| 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 | + |
206 | 228 | function util.update_widget_field(widget, valuess)
|
| 229 | + |
| 230 | + local wid = util.get_widget_meta(widget) |
| 231 | + wid.update(valuess) |
| 232 | + |
| 233 | + |
207 | 234 | -- 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 |
225 | 252 | end
|
226 | 253 |
|
227 | 254 | --- Update widget from values
|
228 | 255 | function util.update_widget(widget, values, format)
|
229 | 256 | if widget ~= nil then
|
| 257 | + local w = util.get_widget_meta(widget) |
230 | 258 | 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")) |
232 | 260 | 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 |
234 | 266 | end
|
235 | 267 | end
|
236 | 268 | end
|
|
0 commit comments