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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-27 10:57:07 +01:00
parent f02b75f826
commit a2301ae8f3
4 changed files with 15 additions and 11 deletions

View File

@ -122,7 +122,6 @@ luaA_mouse_index(lua_State *L)
{ {
const char *attr = luaL_checkstring(L, 2); const char *attr = luaL_checkstring(L, 2);
int16_t mouse_x, mouse_y; int16_t mouse_x, mouse_y;
screen_t *screen;
/* attr is not "screen"?! */ /* attr is not "screen"?! */
if (A_STRNEQ(attr, "screen")) if (A_STRNEQ(attr, "screen"))
@ -134,14 +133,13 @@ luaA_mouse_index(lua_State *L)
* having lots of lua errors in this case. * having lots of lua errors in this case.
*/ */
if (globalconf.focus.client) if (globalconf.focus.client)
lua_pushinteger(L, screen_get_index(globalconf.focus.client->screen)); luaA_pushscreen(L, globalconf.focus.client->screen);
else else
lua_pushinteger(L, 1); luaA_pushscreen(L, globalconf.screens.tab[0]);
return 1; return 1;
} }
screen = screen_getbycoord(mouse_x, mouse_y); luaA_pushscreen(L, screen_getbycoord(mouse_x, mouse_y));
lua_pushinteger(L, screen_get_index(screen));
return 1; return 1;
} }

View File

@ -2226,7 +2226,7 @@ luaA_client_get_screen(lua_State *L, client_t *c)
{ {
if(!c->screen) if(!c->screen)
return 0; return 0;
lua_pushinteger(L, screen_get_index(c->screen)); luaA_pushscreen(L, c->screen);
return 1; return 1;
} }

View File

@ -80,6 +80,12 @@ screen_wipe(screen_t *s)
screen_output_array_wipe(&s->outputs); 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 */ /** Get a screen argument from the lua stack */
screen_t * screen_t *
luaA_checkscreen(lua_State *L, int sidx) 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(); lua_State *L = globalconf_get_lua_State();
screen_t *old_screen = c->screen; screen_t *old_screen = c->screen;
int old_screen_idx = screen_get_index(old_screen);
area_t from, to; area_t from, to;
bool had_focus = false; bool had_focus = false;
@ -465,8 +470,8 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize)
if(!doresize) if(!doresize)
{ {
luaA_object_push(L, c); luaA_object_push(L, c);
if(old_screen_idx != 0) if(old_screen != NULL)
lua_pushinteger(L, old_screen_idx); luaA_pushscreen(L, old_screen);
else else
lua_pushnil(L); lua_pushnil(L);
luaA_object_emit_signal(L, -2, "property::screen", 1); 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) if(old_screen != c->screen)
{ {
luaA_object_push(L, c); luaA_object_push(L, c);
if(old_screen_idx != 0) if(old_screen != NULL)
lua_pushinteger(L, old_screen_idx); luaA_pushscreen(L, old_screen);
else else
lua_pushnil(L); lua_pushnil(L);
luaA_object_emit_signal(L, -2, "property::screen", 1); luaA_object_emit_signal(L, -2, "property::screen", 1);

View File

@ -48,6 +48,7 @@ int screen_get_index(screen_t *);
area_t display_area_get(void); area_t display_area_get(void);
void screen_client_moveto(client_t *, screen_t *, bool); void screen_client_moveto(client_t *, screen_t *, bool);
void luaA_pushscreen(lua_State *, screen_t *);
screen_t *luaA_checkscreen(lua_State *, int); screen_t *luaA_checkscreen(lua_State *, int);
#endif #endif