draw: remove bg color markup, move to textbox
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
b5fb612ea3
commit
9adf3fd869
|
@ -45,7 +45,6 @@ http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html.
|
||||||
List of *awesome* markup elements and their attributes:
|
List of *awesome* markup elements and their attributes:
|
||||||
|
|
||||||
* bg
|
* bg
|
||||||
- color: background color
|
|
||||||
- image: path to a background image
|
- image: path to a background image
|
||||||
- align: background image alignment
|
- align: background image alignment
|
||||||
- resize: resize background image to text size
|
- resize: resize background image to text size
|
||||||
|
|
19
draw.c
19
draw.c
|
@ -158,9 +158,6 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
|
||||||
{
|
{
|
||||||
draw_parser_data_t *data = p->priv;
|
draw_parser_data_t *data = p->priv;
|
||||||
|
|
||||||
xcolor_init_request_t reqs[3];
|
|
||||||
int8_t i, bg_color_nbr = -1, reqs_nbr = -1;
|
|
||||||
|
|
||||||
/* hack: markup.c validates tags so we can avoid strcmps here */
|
/* hack: markup.c validates tags so we can avoid strcmps here */
|
||||||
switch (*elem) {
|
switch (*elem) {
|
||||||
case 'b':
|
case 'b':
|
||||||
|
@ -180,13 +177,6 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
|
||||||
for(; *names; names++, values++)
|
for(; *names; names++, values++)
|
||||||
switch(a_tokenize(*names, -1))
|
switch(a_tokenize(*names, -1))
|
||||||
{
|
{
|
||||||
case A_TK_COLOR:
|
|
||||||
reqs[++reqs_nbr] = xcolor_init_unchecked(&data->bg_color,
|
|
||||||
*values,
|
|
||||||
a_strlen(*values));
|
|
||||||
|
|
||||||
bg_color_nbr = reqs_nbr;
|
|
||||||
break;
|
|
||||||
case A_TK_IMAGE:
|
case A_TK_IMAGE:
|
||||||
if(data->bg_image)
|
if(data->bg_image)
|
||||||
image_delete(&data->bg_image);
|
image_delete(&data->bg_image);
|
||||||
|
@ -202,12 +192,6 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i <= reqs_nbr; i++)
|
|
||||||
if(i == bg_color_nbr)
|
|
||||||
data->has_bg_color = xcolor_init_reply(reqs[i]);
|
|
||||||
else
|
|
||||||
xcolor_init_reply(reqs[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -311,9 +295,6 @@ draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrap
|
||||||
len = pdata->len;
|
len = pdata->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pdata->has_bg_color)
|
|
||||||
draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color);
|
|
||||||
|
|
||||||
if(pdata->bg_image)
|
if(pdata->bg_image)
|
||||||
{
|
{
|
||||||
x = area.x;
|
x = area.x;
|
||||||
|
|
2
draw.h
2
draw.h
|
@ -165,8 +165,6 @@ typedef struct
|
||||||
{
|
{
|
||||||
int top, left;
|
int top, left;
|
||||||
} bg_margin;
|
} bg_margin;
|
||||||
bool has_bg_color;
|
|
||||||
xcolor_t bg_color;
|
|
||||||
image_t *bg_image;
|
image_t *bg_image;
|
||||||
alignment_t bg_align;
|
alignment_t bg_align;
|
||||||
bool bg_resize;
|
bool bg_resize;
|
||||||
|
|
|
@ -51,7 +51,7 @@ local function taglist_update (screen, w, label, buttons, data)
|
||||||
end
|
end
|
||||||
-- Update widgets text
|
-- Update widgets text
|
||||||
for k, tag in ipairs(tags) do
|
for k, tag in ipairs(tags) do
|
||||||
w[k].text = label(tag)
|
w[k].text, w[k].bg = label(tag)
|
||||||
if buttons then
|
if buttons then
|
||||||
if not data[tag] then
|
if not data[tag] then
|
||||||
-- Replace press function by a new one calling with tags as
|
-- Replace press function by a new one calling with tags as
|
||||||
|
@ -112,7 +112,7 @@ end
|
||||||
-- squares_sel Optional: a user provided image for selected squares.
|
-- squares_sel Optional: a user provided image for selected squares.
|
||||||
-- squares_unsel Optional: a user provided image for unselected squares.
|
-- squares_unsel Optional: a user provided image for unselected squares.
|
||||||
-- squares_resize Optional: true or false to resize squares.
|
-- squares_resize Optional: true or false to resize squares.
|
||||||
-- @return A string to print.
|
-- @return A string to print and a background color.
|
||||||
function taglist.label.all(t, args)
|
function taglist.label.all(t, args)
|
||||||
if not args then args = {} end
|
if not args then args = {} end
|
||||||
local theme = beautiful.get()
|
local theme = beautiful.get()
|
||||||
|
@ -150,13 +150,13 @@ function taglist.label.all(t, args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if bg_color and fg_color then
|
if fg_color then
|
||||||
text = text .. "<bg "..background.." color='"..bg_color.."'/> <span color='"..util.color_strip_alpha(fg_color).."'>"..util.escape(t.name).."</span> "
|
text = text .. "<bg "..background.." /> <span color='"..util.color_strip_alpha(fg_color).."'>"..util.escape(t.name).."</span> "
|
||||||
else
|
else
|
||||||
text = text .. " <bg "..background.." />"..util.escape(t.name).." "
|
text = text .. " <bg "..background.." />"..util.escape(t.name).." "
|
||||||
end
|
end
|
||||||
text = text .. "</span>"
|
text = text .. "</span>"
|
||||||
return text
|
return text, bg_color
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Return labels for a taglist widget with all *non empty* tags from screen.
|
--- Return labels for a taglist widget with all *non empty* tags from screen.
|
||||||
|
@ -220,7 +220,8 @@ local function tasklist_update(w, buttons, label, data)
|
||||||
w[k]:buttons(data[c])
|
w[k]:buttons(data[c])
|
||||||
w[k + 1]:buttons(data[c])
|
w[k + 1]:buttons(data[c])
|
||||||
end
|
end
|
||||||
w[k + 1].text, w[k].bg = label(clients[(k + 1) / 2])
|
w[k + 1].text, w[k + 1].bg = label(clients[(k + 1) / 2])
|
||||||
|
w[k].bg = w[k + 1].bg
|
||||||
if w[k + 1].text then
|
if w[k + 1].text then
|
||||||
-- Set icon
|
-- Set icon
|
||||||
w[k].image = clients[(k + 1) / 2].icon
|
w[k].image = clients[(k + 1) / 2].icon
|
||||||
|
@ -288,15 +289,15 @@ local function widget_tasklist_label_common(c, args)
|
||||||
name = util.escape(c.name) or ""
|
name = util.escape(c.name) or ""
|
||||||
end
|
end
|
||||||
if capi.client.focus == c then
|
if capi.client.focus == c then
|
||||||
if bg_focus and fg_focus then
|
bg = bg_focus
|
||||||
bg = bg_focus
|
if fg_focus then
|
||||||
text = text .. "<bg color='"..bg_focus.."'/><span color='"..util.color_strip_alpha(fg_focus).."'>"..name.."</span>"
|
text = text .. "<span color='"..util.color_strip_alpha(fg_focus).."'>"..name.."</span>"
|
||||||
else
|
else
|
||||||
text = text .. name
|
text = text .. name
|
||||||
end
|
end
|
||||||
elseif c.urgent and bg_urgent and fg_urgent then
|
elseif c.urgent and fg_urgent then
|
||||||
bg = bg_urgent
|
bg = bg_urgent
|
||||||
text = text .. "<bg color='"..bg_urgent.."'/><span color='"..util.color_strip_alpha(fg_urgent).."'>"..name.."</span>"
|
text = text .. "<span color='"..util.color_strip_alpha(fg_urgent).."'>"..name.."</span>"
|
||||||
else
|
else
|
||||||
text = text .. name
|
text = text .. name
|
||||||
end
|
end
|
||||||
|
@ -315,7 +316,7 @@ end
|
||||||
-- fg_focus The foreground color for focused client.
|
-- fg_focus The foreground color for focused client.
|
||||||
-- bg_urgent The background color for urgent clients.
|
-- bg_urgent The background color for urgent clients.
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
-- fg_urgent The foreground color for urgent clients.
|
||||||
-- @return A string to print.
|
-- @return A string to print and a background color.
|
||||||
function tasklist.label.allscreen(c, screen, args)
|
function tasklist.label.allscreen(c, screen, args)
|
||||||
return widget_tasklist_label_common(c, args)
|
return widget_tasklist_label_common(c, args)
|
||||||
end
|
end
|
||||||
|
@ -331,7 +332,7 @@ end
|
||||||
-- fg_focus The foreground color for focused client.
|
-- fg_focus The foreground color for focused client.
|
||||||
-- bg_urgent The background color for urgent clients.
|
-- bg_urgent The background color for urgent clients.
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
-- fg_urgent The foreground color for urgent clients.
|
||||||
-- @return A string to print.
|
-- @return A string to print and a background color.
|
||||||
function tasklist.label.alltags(c, screen, args)
|
function tasklist.label.alltags(c, screen, args)
|
||||||
-- Only print client on the same screen as this widget
|
-- Only print client on the same screen as this widget
|
||||||
if c.screen ~= screen then return end
|
if c.screen ~= screen then return end
|
||||||
|
@ -349,7 +350,7 @@ end
|
||||||
-- fg_focus The foreground color for focused client.
|
-- fg_focus The foreground color for focused client.
|
||||||
-- bg_urgent The background color for urgent clients.
|
-- bg_urgent The background color for urgent clients.
|
||||||
-- fg_urgent The foreground color for urgent clients.
|
-- fg_urgent The foreground color for urgent clients.
|
||||||
-- @return A string to print.
|
-- @return A string to print and a background color.
|
||||||
function tasklist.label.currenttags(c, screen, args)
|
function tasklist.label.currenttags(c, screen, args)
|
||||||
-- Only print client on the same screen as this widget
|
-- Only print client on the same screen as this widget
|
||||||
if c.screen ~= screen then return end
|
if c.screen ~= screen then return end
|
||||||
|
|
|
@ -49,6 +49,8 @@ typedef struct
|
||||||
alignment_t align;
|
alignment_t align;
|
||||||
/** Margin */
|
/** Margin */
|
||||||
padding_t margin;
|
padding_t margin;
|
||||||
|
/** Background color */
|
||||||
|
xcolor_t bg;
|
||||||
} textbox_data_t;
|
} textbox_data_t;
|
||||||
|
|
||||||
static area_t
|
static area_t
|
||||||
|
@ -87,6 +89,9 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry,
|
||||||
{
|
{
|
||||||
textbox_data_t *d = widget->data;
|
textbox_data_t *d = widget->data;
|
||||||
|
|
||||||
|
if(d->bg.initialized)
|
||||||
|
draw_rectangle(ctx, geometry, 1.0, true, &d->bg);
|
||||||
|
|
||||||
if(d->border.width > 0)
|
if(d->border.width > 0)
|
||||||
draw_rectangle(ctx, geometry, d->border.width, false, &d->border.color);
|
draw_rectangle(ctx, geometry, d->border.width, false, &d->border.color);
|
||||||
|
|
||||||
|
@ -134,6 +139,7 @@ luaA_textbox_margin(lua_State *L)
|
||||||
* \lfield border_color The border color.
|
* \lfield border_color The border color.
|
||||||
* \lfield align Text alignment, left, center or right.
|
* \lfield align Text alignment, left, center or right.
|
||||||
* \lfield margin Method to pass text margin: a table with top, left, right and bottom keys.
|
* \lfield margin Method to pass text margin: a table with top, left, right and bottom keys.
|
||||||
|
* \lfield bg Background color.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_textbox_index(lua_State *L, awesome_token_t token)
|
luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
|
@ -143,6 +149,8 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
|
||||||
|
|
||||||
switch(token)
|
switch(token)
|
||||||
{
|
{
|
||||||
|
case A_TK_BG:
|
||||||
|
return luaA_pushcolor(L, &d->bg);
|
||||||
case A_TK_MARGIN:
|
case A_TK_MARGIN:
|
||||||
lua_pushcfunction(L, luaA_textbox_margin);
|
lua_pushcfunction(L, luaA_textbox_margin);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -209,6 +217,12 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
|
||||||
|
|
||||||
switch(token)
|
switch(token)
|
||||||
{
|
{
|
||||||
|
case A_TK_BG:
|
||||||
|
if(lua_isnil(L, 3))
|
||||||
|
p_clear(&d->bg, 1);
|
||||||
|
else if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
|
xcolor_init_reply(xcolor_init_unchecked(&d->bg, buf, len));
|
||||||
|
break;
|
||||||
case A_TK_ALIGN:
|
case A_TK_ALIGN:
|
||||||
if((buf = luaL_checklstring(L, 3, &len)))
|
if((buf = luaL_checklstring(L, 3, &len)))
|
||||||
d->align = draw_align_fromstr(buf, len);
|
d->align = draw_align_fromstr(buf, len);
|
||||||
|
|
Loading…
Reference in New Issue