widget.common.list_update: improve margins (dpi / imagebox)

Use `beautiful.xresources.apply_dpi` for `common.list_update`'s textbox
margins, and add a left margin for the imagebox, too.

The latter is useful/nicer with the default behavior of an inverted
style for the focused tasklist entry.
This commit is contained in:
Daniel Hahler 2015-07-13 23:27:24 +02:00
parent 09dce08fd4
commit 4a3589aad4
1 changed files with 18 additions and 10 deletions

View File

@ -17,6 +17,7 @@ local util = require("awful.util")
local wibox = require("wibox") local wibox = require("wibox")
local imagebox = require("wibox.widget.imagebox") local imagebox = require("wibox.widget.imagebox")
local textbox = require("wibox.widget.textbox") local textbox = require("wibox.widget.textbox")
local dpi = require("beautiful").xresources.apply_dpi
--- Common utilities for awful widgets --- Common utilities for awful widgets
local common = {} local common = {}
@ -56,23 +57,25 @@ function common.list_update(w, buttons, label, data, objects)
w:reset() w:reset()
for i, o in ipairs(objects) do for i, o in ipairs(objects) do
local cache = data[o] local cache = data[o]
local ib, tb, bgb, m, l local ib, tb, bgb, tbm, ibm, l
if cache then if cache then
ib = cache.ib ib = cache.ib
tb = cache.tb tb = cache.tb
bgb = cache.bgb bgb = cache.bgb
m = cache.m tbm = cache.tbm
ibm = cache.ibm
else else
ib = wibox.widget.imagebox() ib = wibox.widget.imagebox()
tb = wibox.widget.textbox() tb = wibox.widget.textbox()
bgb = wibox.widget.background() bgb = wibox.widget.background()
m = wibox.layout.margin(tb, 4, 4) tbm = wibox.layout.margin(tb, dpi(4), dpi(4))
ibm = wibox.layout.margin(ib, dpi(4))
l = wibox.layout.fixed.horizontal() l = wibox.layout.fixed.horizontal()
-- All of this is added in a fixed widget -- All of this is added in a fixed widget
l:fill_space(true) l:fill_space(true)
l:add(ib) l:add(ibm)
l:add(m) l:add(tbm)
-- And all of this gets a background -- And all of this gets a background
bgb:set_widget(l) bgb:set_widget(l)
@ -80,17 +83,18 @@ function common.list_update(w, buttons, label, data, objects)
bgb:buttons(common.create_buttons(buttons, o)) bgb:buttons(common.create_buttons(buttons, o))
data[o] = { data[o] = {
ib = ib, ib = ib,
tb = tb, tb = tb,
bgb = bgb, bgb = bgb,
m = m tbm = tbm,
ibm = ibm,
} }
end end
local text, bg, bg_image, icon = label(o) local text, bg, bg_image, icon = label(o)
-- The text might be invalid, so use pcall. -- The text might be invalid, so use pcall.
if text == nil or text == "" then if text == nil or text == "" then
m:set_margins(0) tbm:set_margins(0)
else else
if not pcall(tb.set_markup, tb, text) then if not pcall(tb.set_markup, tb, text) then
tb:set_markup("<i>&lt;Invalid text&gt;</i>") tb:set_markup("<i>&lt;Invalid text&gt;</i>")
@ -101,7 +105,11 @@ function common.list_update(w, buttons, label, data, objects)
bg_image = bg_image(tb,o,m,objects,i) bg_image = bg_image(tb,o,m,objects,i)
end end
bgb:set_bgimage(bg_image) bgb:set_bgimage(bg_image)
ib:set_image(icon) if icon then
ib:set_image(icon)
else
ibm:set_margins(0)
end
w:add(bgb) w:add(bgb)
end end
end end