From a2301ae8f3dc21bc3e7457cc470fc0fba153ac86 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 27 Feb 2016 10:57:07 +0100 Subject: [PATCH] Add and use luaA_pushscreen() Even when a screen is just an integer, the code becomes a bit more self-documenting. Even better, if we start to handle screen objects to Lua instead of screen indicies, there will only be one place that needs to be changed. Signed-off-by: Uli Schlachter --- mouse.c | 8 +++----- objects/client.c | 2 +- objects/screen.c | 15 ++++++++++----- objects/screen.h | 1 + 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mouse.c b/mouse.c index c6365ab72..af080b286 100644 --- a/mouse.c +++ b/mouse.c @@ -122,7 +122,6 @@ luaA_mouse_index(lua_State *L) { const char *attr = luaL_checkstring(L, 2); int16_t mouse_x, mouse_y; - screen_t *screen; /* attr is not "screen"?! */ if (A_STRNEQ(attr, "screen")) @@ -134,14 +133,13 @@ luaA_mouse_index(lua_State *L) * having lots of lua errors in this case. */ if (globalconf.focus.client) - lua_pushinteger(L, screen_get_index(globalconf.focus.client->screen)); + luaA_pushscreen(L, globalconf.focus.client->screen); else - lua_pushinteger(L, 1); + luaA_pushscreen(L, globalconf.screens.tab[0]); return 1; } - screen = screen_getbycoord(mouse_x, mouse_y); - lua_pushinteger(L, screen_get_index(screen)); + luaA_pushscreen(L, screen_getbycoord(mouse_x, mouse_y)); return 1; } diff --git a/objects/client.c b/objects/client.c index e5fd066bf..5a61869a3 100644 --- a/objects/client.c +++ b/objects/client.c @@ -2226,7 +2226,7 @@ luaA_client_get_screen(lua_State *L, client_t *c) { if(!c->screen) return 0; - lua_pushinteger(L, screen_get_index(c->screen)); + luaA_pushscreen(L, c->screen); return 1; } diff --git a/objects/screen.c b/objects/screen.c index 57be3561b..3026c827c 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -80,6 +80,12 @@ screen_wipe(screen_t *s) screen_output_array_wipe(&s->outputs); } +void +luaA_pushscreen(lua_State *L, screen_t *s) +{ + lua_pushinteger(L, screen_get_index(s)); +} + /** Get a screen argument from the lua stack */ screen_t * luaA_checkscreen(lua_State *L, int sidx) @@ -450,7 +456,6 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize) { lua_State *L = globalconf_get_lua_State(); screen_t *old_screen = c->screen; - int old_screen_idx = screen_get_index(old_screen); area_t from, to; bool had_focus = false; @@ -465,8 +470,8 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize) if(!doresize) { luaA_object_push(L, c); - if(old_screen_idx != 0) - lua_pushinteger(L, old_screen_idx); + if(old_screen != NULL) + luaA_pushscreen(L, old_screen); else lua_pushnil(L); luaA_object_emit_signal(L, -2, "property::screen", 1); @@ -504,8 +509,8 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize) if(old_screen != c->screen) { luaA_object_push(L, c); - if(old_screen_idx != 0) - lua_pushinteger(L, old_screen_idx); + if(old_screen != NULL) + luaA_pushscreen(L, old_screen); else lua_pushnil(L); luaA_object_emit_signal(L, -2, "property::screen", 1); diff --git a/objects/screen.h b/objects/screen.h index 009c64d4d..95cf5d821 100644 --- a/objects/screen.h +++ b/objects/screen.h @@ -48,6 +48,7 @@ int screen_get_index(screen_t *); area_t display_area_get(void); void screen_client_moveto(client_t *, screen_t *, bool); +void luaA_pushscreen(lua_State *, screen_t *); screen_t *luaA_checkscreen(lua_State *, int); #endif