[client] Create luaA_client_userdata_new() function

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-23 22:49:39 +02:00
parent 495b99f1c5
commit db5430420d
4 changed files with 23 additions and 32 deletions

View file

@ -199,9 +199,7 @@ static void
client_unfocus(client_t *c)
{
/* Call hook */
client_t **lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
luaA_settype(globalconf.L, "client");
luaA_client_userdata_new(globalconf.focus->client);
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1);
focus_client_push(NULL);
@ -232,7 +230,6 @@ client_ban(client_t *c)
bool
client_focus(client_t *c, int screen, bool raise)
{
client_t **lc;
int phys_screen;
/* if c is NULL or invisible, take next client in the focus history */
@ -266,9 +263,7 @@ client_focus(client_t *c, int screen, bool raise)
phys_screen = c->phys_screen;
/* execute hook */
lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
luaA_settype(globalconf.L, "client");
luaA_client_userdata_new(globalconf.focus->client);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1);
}
else
@ -343,7 +338,7 @@ client_stack(client_t *c)
void
client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
{
client_t **lc, *c, *t = NULL;
client_t *c, *t = NULL;
xcb_window_t trans;
bool rettrans, retloadprops;
tag_t *tag;
@ -430,9 +425,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
ewmh_update_net_client_list(c->phys_screen);
/* call hook */
lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
luaA_settype(globalconf.L, "client");
luaA_client_userdata_new(c);
luaA_dofunction(globalconf.L, globalconf.hooks.newclient, 1);
}
@ -801,15 +794,13 @@ static int
luaA_client_get(lua_State *L)
{
int i = 1;
client_t *c, **cobj;
client_t *c;
lua_newtable(L);
for(c = globalconf.clients; c; c = c->next)
{
cobj = lua_newuserdata(L, sizeof(client_t *));
*cobj = c;
luaA_settype(L, "client");
luaA_client_userdata_new(c);
lua_rawseti(L, -2, i++);
}
@ -850,7 +841,7 @@ static int
luaA_client_visible_get(lua_State *L)
{
int i = 1;
client_t *c, **cobj;
client_t *c;
int screen = luaL_checknumber(L, 1) - 1;
luaA_checkscreen(screen);
@ -860,9 +851,7 @@ luaA_client_visible_get(lua_State *L)
for(c = globalconf.clients; c; c = c->next)
if(!c->skip && client_isvisible(c, screen))
{
cobj = lua_newuserdata(L, sizeof(client_t *));
*cobj = c;
luaA_settype(L, "client");
luaA_client_userdata_new(c);
lua_rawseti(L, -2, i++);
}
@ -870,16 +859,12 @@ luaA_client_visible_get(lua_State *L)
}
static int
luaA_client_focus_get(lua_State *L)
luaA_client_focus_get(lua_State *L __attribute__ ((unused)))
{
client_t **cobj;
if(!globalconf.focus->client)
return 0;
cobj = lua_newuserdata(L, sizeof(client_t *));
*cobj = globalconf.focus->client;
luaA_settype(L, "client");
luaA_client_userdata_new(globalconf.focus->client);
return 1;
}
@ -1104,6 +1089,14 @@ luaA_client_name_get(lua_State *L)
return 1;
}
int
luaA_client_userdata_new(client_t *c)
{
client_t **lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
return luaA_settype(globalconf.L, "client");
}
const struct luaL_reg awesome_client_methods[] =
{
{ "get", luaA_client_get },

View file

@ -43,6 +43,8 @@ void client_kill(client_t *);
void client_setfloating(client_t *, bool, layer_t);
char * client_markup_parse(client_t *, const char *, ssize_t);
int luaA_client_userdata_new(client_t *);
DO_SLIST(client_t, client, p_delete)
#endif

View file

@ -298,7 +298,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
xcb_connection_t *connection __attribute__ ((unused)),
xcb_enter_notify_event_t *ev)
{
client_t *c, **lc;
client_t *c;
if(ev->mode != XCB_NOTIFY_MODE_NORMAL
|| (ev->root_x == globalconf.pointer_x
@ -318,9 +318,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
globalconf.pointer_x = ev->root_x;
globalconf.pointer_y = ev->root_y;
lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
luaA_settype(globalconf.L, "client");
luaA_client_userdata_new(c);
luaA_dofunction(globalconf.L, globalconf.hooks.mouseover, 1);
}
else

View file

@ -218,9 +218,7 @@ tasklist_button_press(widget_node_t *w, statusbar_t *statusbar,
for(b = w->widget->buttons; b; b = b->next)
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
{
lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
luaA_settype(globalconf.L, "client");
luaA_client_userdata_new(c);
luaA_dofunction(globalconf.L, b->fct, 1);
}
}