[client] Add client.name_set() function and hook on title update

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-25 17:51:45 +02:00
parent 2654b5b938
commit f6f74c4565
3 changed files with 29 additions and 0 deletions

View File

@ -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 },

11
lua.c
View File

@ -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 }
};

View File

@ -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;
};