diff --git a/awesomerc.lua.in b/awesomerc.lua.in
index f4f2d885..6de7c00c 100644
--- a/awesomerc.lua.in
+++ b/awesomerc.lua.in
@@ -91,7 +91,12 @@ mytasklist = widget({ type = "tasklist", name = "mytasklist" })
mytasklist:mouse_add(mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end))
mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focus(1) end))
mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focus(-1) end))
-mytasklist.text_focus = " "
+function mytasklist.label(c)
+ if client.focus_get() == c then
+ return " "
+ end
+ return "
"
+end
-- Create a textbox widget
mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" })
diff --git a/client.c b/client.c
index 6a058f49..7c501bf0 100644
--- a/client.c
+++ b/client.c
@@ -166,7 +166,7 @@ client_updatetitle(client_t *c)
/* call hook */
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, globalconf.hooks.titleupdate, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.titleupdate, 1, 0);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
@@ -181,7 +181,7 @@ client_unfocus(client_t *c)
{
/* Call hook */
luaA_client_userdata_new(globalconf.L, globalconf.focus->client);
- luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
focus_client_push(NULL);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
@@ -240,7 +240,7 @@ client_focus(client_t *c, int screen)
/* execute hook */
luaA_client_userdata_new(globalconf.L, globalconf.focus->client);
- luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
}
else
{
@@ -433,7 +433,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
/* call hook */
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
if(c->floating_placement
&& !retloadprops
@@ -668,7 +668,7 @@ client_unmanage(client_t *c)
/* call hook */
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
/* The server grab construct avoids race conditions. */
xcb_grab_server(globalconf.connection);
@@ -723,7 +723,7 @@ client_updatewmhints(client_t *c)
{
/* execute hook */
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1, 0);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
}
diff --git a/common/tokenize.gperf b/common/tokenize.gperf
index 8212fe05..3ffd5aba 100644
--- a/common/tokenize.gperf
+++ b/common/tokenize.gperf
@@ -27,6 +27,7 @@ hide
honorsizehints
icon_path
image
+label
layout
left
line
diff --git a/event.c b/event.c
index 84e42f92..5be4e371 100644
--- a/event.c
+++ b/event.c
@@ -59,10 +59,10 @@ event_handle_mouse_button_press(client_t *c,
if(c)
{
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, b->fct, 1);
+ luaA_dofunction(globalconf.L, b->fct, 1, 0);
}
else
- luaA_dofunction(globalconf.L, b->fct, 0);
+ luaA_dofunction(globalconf.L, b->fct, 0, 0);
}
}
@@ -341,7 +341,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
globalconf.pointer_y = ev->root_y;
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, globalconf.hooks.mouseover, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.mouseover, 1, 0);
}
else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY,
@@ -414,7 +414,7 @@ event_handle_keypress(void *data __attribute__ ((unused)),
{
keybinding_t *k = keybinding_find(ev);
if (k && k->fct != LUA_REFNIL)
- luaA_dofunction(globalconf.L, k->fct, 0);
+ luaA_dofunction(globalconf.L, k->fct, 0, 0);
}
return 0;
diff --git a/ewmh.c b/ewmh.c
index 141ae575..4fd9b843 100644
--- a/ewmh.c
+++ b/ewmh.c
@@ -352,7 +352,7 @@ ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
c->isurgent = true;
/* execute hook */
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1, 0);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
}
}
diff --git a/layout.c b/layout.c
index 56323816..cb504c91 100644
--- a/layout.c
+++ b/layout.c
@@ -87,7 +87,7 @@ arrange(int screen)
/* call hook */
lua_pushnumber(globalconf.L, screen + 1);
- luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1);
+ luaA_dofunction(globalconf.L, globalconf.hooks.arrange, 1, 0);
}
/** Refresh the screen disposition
diff --git a/lua.c b/lua.c
index 83e05493..7ac640dc 100644
--- a/lua.c
+++ b/lua.c
@@ -208,16 +208,6 @@ luaA_screen_coords_get(lua_State *L)
return 1;
}
-static int
-luaA_registerfct(lua_State *L, luaA_function *fct)
-{
- luaA_checkfunction(L, -1);
- if(*fct != LUA_REFNIL)
- luaL_unref(L, LUA_REGISTRYINDEX, *fct);
- *fct = luaL_ref(L, LUA_REGISTRYINDEX);
- return 0;
-}
-
/** Set the function called each time a client gets focus. This function is
* called with the client object as argument.
* \param L The Lua VM state.
@@ -693,7 +683,7 @@ luaA_cs_cleanup(void)
void
luaA_on_timer(EV_P_ ev_timer *w, int revents)
{
- luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0);
+ luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0, 0);
}
void
diff --git a/lua.h b/lua.h
index 01e902a4..8b895f93 100644
--- a/lua.h
+++ b/lua.h
@@ -77,14 +77,14 @@ typedef int luaA_function;
lua_tostring(L, -1)); \
} while(0)
-#define luaA_dofunction(L, f, n) \
+#define luaA_dofunction(L, f, n, r) \
do { \
if(f) \
{ \
lua_rawgeti(L, LUA_REGISTRYINDEX, f); \
if(n) \
lua_insert(L, - (n + 1)); \
- if(lua_pcall(L, n, 0, 0)) \
+ if(lua_pcall(L, n, r, 0)) \
warn("error running function: %s", \
lua_tostring(L, -1)); \
} \
@@ -189,6 +189,16 @@ luaA_usemetatable(lua_State *L, int idxobj, int idxfield)
return 0;
}
+static inline int
+luaA_registerfct(lua_State *L, luaA_function *fct)
+{
+ luaA_checkfunction(L, -1);
+ if(*fct != LUA_REFNIL)
+ luaL_unref(L, LUA_REGISTRYINDEX, *fct);
+ *fct = luaL_ref(L, LUA_REGISTRYINDEX);
+ return 0;
+}
+
void luaA_init(void);
void luaA_parserc(const char *);
void luaA_pushpointer(lua_State *, void *, awesome_type_t);
diff --git a/widget.c b/widget.c
index 3d546470..543735cd 100644
--- a/widget.c
+++ b/widget.c
@@ -75,7 +75,7 @@ widget_common_button_press(widget_node_t *w,
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
{
luaA_pushpointer(globalconf.L, p, type);
- luaA_dofunction(globalconf.L, b->fct, 1);
+ luaA_dofunction(globalconf.L, b->fct, 1, 0);
}
}
diff --git a/widgets/taglist.c b/widgets/taglist.c
index 39f5f0f2..832d533d 100644
--- a/widgets/taglist.c
+++ b/widgets/taglist.c
@@ -283,7 +283,7 @@ taglist_button_press(widget_node_t *w,
{
luaA_pushpointer(globalconf.L, object, type);
luaA_tag_userdata_new(globalconf.L, tag);
- luaA_dofunction(globalconf.L, b->fct, 2);
+ luaA_dofunction(globalconf.L, b->fct, 2, 0);
return;
}
}
diff --git a/widgets/tasklist.c b/widgets/tasklist.c
index c4b4b986..4a145f3d 100644
--- a/widgets/tasklist.c
+++ b/widgets/tasklist.c
@@ -41,7 +41,7 @@ typedef struct
{
showclient_t show;
bool show_icons;
- char *text_normal, *text_urgent, *text_focus;
+ luaA_function label;
} tasklist_data_t;
struct tasklist_hook_data
@@ -115,9 +115,11 @@ tasklist_draw(draw_context_t *ctx, int screen,
tasklist_data_t *d = w->widget->data;
area_t area;
char *text;
+ const char *buf;
int n = 0, i = 0, box_width = 0, icon_width = 0, box_width_rest = 0;
netwm_icon_t *icon;
draw_image_t *image;
+ size_t len;
if(used >= ctx->width)
return (w->area.width = 0);
@@ -143,14 +145,21 @@ tasklist_draw(draw_context_t *ctx, int screen,
{
icon_width = 0;
- if(globalconf.focus->client == c)
- text = d->text_focus;
- else if(c->isurgent)
- text = d->text_urgent;
- else
- text = d->text_normal;
+ /* push client */
+ luaA_client_userdata_new(globalconf.L, c);
+ /* call label function with client as argument and wait for one
+ * result */
+ luaA_dofunction(globalconf.L, d->label, 1, 1);
- text = client_markup_parse(c, text, a_strlen(text));
+ if(lua_isstring(globalconf.L, -1))
+ {
+ buf = lua_tolstring(globalconf.L, -1, &len);
+ text = client_markup_parse(c, buf, len);
+ }
+ else
+ text = NULL;
+
+ lua_pop(globalconf.L, 1);
if(d->show_icons)
{
@@ -209,12 +218,6 @@ tasklist_draw(draw_context_t *ctx, int screen,
draw_text(ctx, globalconf.font, area, text, NULL);
p_delete(&text);
-
- if(c->isfloating || c->ismax)
- draw_circle(ctx, w->area.x + icon_width + box_width * i,
- w->area.y,
- (globalconf.font->height + 2) / 4,
- c->ismax, &ctx->fg);
i++;
}
@@ -270,7 +273,7 @@ tasklist_button_press(widget_node_t *w,
{
luaA_pushpointer(globalconf.L, object, type);
luaA_client_userdata_new(globalconf.L, c);
- luaA_dofunction(globalconf.L, b->fct, 2);
+ luaA_dofunction(globalconf.L, b->fct, 2, 0);
}
}
@@ -287,15 +290,6 @@ luaA_tasklist_index(lua_State *L, awesome_token_t token)
switch(token)
{
- case A_TK_TEXT_NORMAL:
- lua_pushstring(L, d->text_normal);
- return 1;
- case A_TK_TEXT_FOCUS:
- lua_pushstring(L, d->text_focus);
- return 1;
- case A_TK_TEXT_URGENT:
- lua_pushstring(L, d->text_urgent);
- return 1;
case A_TK_SHOW_ICONS:
lua_pushboolean(L, d->show_icons);
return 1;
@@ -315,6 +309,9 @@ luaA_tasklist_index(lua_State *L, awesome_token_t token)
return 0;
}
return 1;
+ case A_TK_LABEL:
+ lua_rawgeti(L, LUA_REGISTRYINDEX, d->label);
+ return 1;
default:
return 0;
}
@@ -335,27 +332,6 @@ luaA_tasklist_newindex(lua_State *L, awesome_token_t token)
switch(token)
{
- case A_TK_TEXT_NORMAL:
- if((buf = luaL_checkstring(L, 3)))
- {
- p_delete(&d->text_normal);
- d->text_normal = a_strdup(buf);
- }
- break;
- case A_TK_TEXT_FOCUS:
- if((buf = luaL_checkstring(L, 3)))
- {
- p_delete(&d->text_focus);
- d->text_focus = a_strdup(buf);
- }
- break;
- case A_TK_TEXT_URGENT:
- if((buf = luaL_checkstring(L, 3)))
- {
- p_delete(&d->text_urgent);
- d->text_urgent = a_strdup(buf);
- }
- break;
case A_TK_SHOW_ICONS:
d->show_icons = luaA_checkboolean(L, 3);
break;
@@ -376,6 +352,9 @@ luaA_tasklist_newindex(lua_State *L, awesome_token_t token)
break;
}
break;
+ case A_TK_LABEL:
+ luaA_registerfct(L, &d->label);
+ break;
default:
return 0;
}
@@ -392,10 +371,6 @@ static void
tasklist_destructor(widget_t *widget)
{
tasklist_data_t *d = widget->data;
-
- p_delete(&d->text_normal);
- p_delete(&d->text_focus);
- p_delete(&d->text_urgent);
p_delete(&d);
}
@@ -418,12 +393,10 @@ tasklist_new(alignment_t align __attribute__ ((unused)))
w->newindex = luaA_tasklist_newindex;
w->data = d = p_new(tasklist_data_t, 1);
w->destructor = tasklist_destructor;
-
- d->text_normal = a_strdup(" ");
- d->text_focus = a_strdup(" ");
- d->text_urgent = a_strdup(" ");
+
d->show_icons = true;
d->show = ShowTags;
+ d->label = LUA_REFNIL;
/* Set cache property */
w->cache_flags = WIDGET_CACHE_CLIENTS;
diff --git a/widgets/textbox.c b/widgets/textbox.c
index 7a0ca7bf..b1e85a96 100644
--- a/widgets/textbox.c
+++ b/widgets/textbox.c
@@ -60,8 +60,10 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
draw_parser_data_init(&pdata);
w->area.width = draw_text_extents(ctx->connection, ctx->phys_screen,
globalconf.font, d->text, &pdata).width;
+
if(w->area.width > ctx->width - used)
w->area.width = ctx->width - used;
+
if(pdata.bg_image)
w->area.width = MAX(w->area.width, pdata.bg_resize ? w->area.height : pdata.bg_image->width);