diff --git a/client.c b/client.c index 8996bac3..b87ab153 100644 --- a/client.c +++ b/client.c @@ -191,6 +191,11 @@ client_updatetitle(client_t *c) p_delete(&c->name); c->name = name; + + /* call hook */ + luaA_client_userdata_new(c); + luaA_dofunction(globalconf.L, globalconf.hooks.titleupdate, 1); + titlebar_draw(c); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); } @@ -1102,6 +1107,16 @@ luaA_client_name_get(lua_State *L) return 1; } +static int +luaA_client_name_set(lua_State *L) +{ + client_t **c = luaL_checkudata(L, 1, "client"); + const char *name = luaL_checkstring(L, 2); + p_delete(&(*c)->name); + (*c)->name = a_strdup(name); + return 0; +} + int luaA_client_userdata_new(client_t *c) { @@ -1121,6 +1136,7 @@ const struct luaL_reg awesome_client_methods[] = const struct luaL_reg awesome_client_meta[] = { { "name_get", luaA_client_name_get }, + { "name_set", luaA_client_name_set }, { "titlebar_set", luaA_client_titlebar_set }, { "screen_set", luaA_client_screen_set }, { "screen_get", luaA_client_screen_get }, diff --git a/lua.c b/lua.c index 3d465941..9d15fe56 100644 --- a/lua.c +++ b/lua.c @@ -267,6 +267,16 @@ luaA_hooks_arrange(lua_State *L) return 0; } +static int +luaA_hooks_titleupdate(lua_State *L) +{ + luaA_checkfunction(L, 1); + if(globalconf.hooks.titleupdate) + luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.titleupdate); + globalconf.hooks.titleupdate = luaL_ref(L, LUA_REGISTRYINDEX); + return 0; +} + static void luaA_openlib(lua_State *L, const char *name, const struct luaL_reg methods[], @@ -335,6 +345,7 @@ luaA_parserc(const char *rcfile) { "newclient", luaA_hooks_newclient }, { "mouseover", luaA_hooks_mouseover }, { "arrange", luaA_hooks_arrange }, + { "titleupdate", luaA_hooks_titleupdate }, { NULL, NULL } }; diff --git a/structs.h b/structs.h index 02136f29..8567b990 100644 --- a/structs.h +++ b/structs.h @@ -418,6 +418,8 @@ struct awesome_t luaA_function mouseover; /** Command to run on arrange */ luaA_function arrange; + /** Command to run on title change */ + luaA_function titleupdate; } hooks; };