From db5430420da9f144cafa9d5d710412b4504f8f25 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 23 May 2008 22:49:39 +0200 Subject: [PATCH] [client] Create luaA_client_userdata_new() function Signed-off-by: Julien Danjou --- client.c | 43 ++++++++++++++++++------------------------- client.h | 2 ++ event.c | 6 ++---- widgets/tasklist.c | 4 +--- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/client.c b/client.c index 0856c73e..0a7c3a39 100644 --- a/client.c +++ b/client.c @@ -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 }, diff --git a/client.h b/client.h index 0fe4a85e..de657f95 100644 --- a/client.h +++ b/client.h @@ -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 diff --git a/event.c b/event.c index 03dbd69b..0467a716 100644 --- a/event.c +++ b/event.c @@ -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 diff --git a/widgets/tasklist.c b/widgets/tasklist.c index ce003ab8..a278924e 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -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); } }