Also allow screen objects were screen indices are expected
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
271f084735
commit
fed199eee5
6
luaa.h
6
luaa.h
|
@ -39,12 +39,6 @@
|
|||
signal_object_emit(L, &global_signals, "debug::deprecation", 1); \
|
||||
} while(0)
|
||||
|
||||
#define luaA_checkscreen(screen) \
|
||||
do { \
|
||||
if(screen < 0 || screen >= globalconf.screens.len) \
|
||||
luaL_error(L, "invalid screen number: %d", screen + 1); \
|
||||
} while(0)
|
||||
|
||||
/** Print a warning about some Lua code.
|
||||
* This is less mean than luaL_error() which setjmp via lua_error() and kills
|
||||
* everything. This only warn, it's up to you to then do what's should be done.
|
||||
|
|
12
mouse.c
12
mouse.c
|
@ -133,19 +133,13 @@ static int
|
|||
luaA_mouse_newindex(lua_State *L)
|
||||
{
|
||||
const char *attr = luaL_checkstring(L, 2);
|
||||
int x, y = 0;
|
||||
int screen;
|
||||
screen_t *screen;
|
||||
|
||||
if (A_STRNEQ(attr, "screen"))
|
||||
return luaA_default_newindex(L);
|
||||
|
||||
screen = luaL_checknumber(L, 3) - 1;
|
||||
luaA_checkscreen(screen);
|
||||
|
||||
x = globalconf.screens.tab[screen]->geometry.x;
|
||||
y = globalconf.screens.tab[screen]->geometry.y;
|
||||
|
||||
mouse_warp_pointer(globalconf.screen->root, x, y);
|
||||
screen = luaA_checkscreen(L, 3);
|
||||
mouse_warp_pointer(globalconf.screen->root, screen->geometry.x, screen->geometry.y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1245,28 +1245,19 @@ client_kill(client_t *c)
|
|||
static int
|
||||
luaA_client_get(lua_State *L)
|
||||
{
|
||||
int i = 1, screen;
|
||||
int i = 1;
|
||||
screen_t *screen = NULL;
|
||||
|
||||
screen = luaL_optnumber(L, 1, 0) - 1;
|
||||
if(!lua_isnoneornil(L, 1))
|
||||
screen = luaA_checkscreen(L, 1);
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
if(screen == -1)
|
||||
foreach(c, globalconf.clients)
|
||||
if(screen == NULL || (*c)->screen == screen)
|
||||
{
|
||||
luaA_object_push(L, *c);
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
else
|
||||
{
|
||||
luaA_checkscreen(screen);
|
||||
foreach(c, globalconf.clients)
|
||||
if((*c)->screen == globalconf.screens.tab[screen])
|
||||
{
|
||||
luaA_object_push(L, *c);
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1682,10 +1673,7 @@ luaA_client_geometry(lua_State *L)
|
|||
static int
|
||||
luaA_client_set_screen(lua_State *L, client_t *c)
|
||||
{
|
||||
int screen = luaL_checknumber(L, -1) - 1;
|
||||
luaA_checkscreen(screen);
|
||||
screen_client_moveto(c, globalconf.screens.tab[screen], true);
|
||||
|
||||
screen_client_moveto(c, luaA_checkscreen(L, -1), true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,20 @@ screen_wipe(screen_t *s)
|
|||
screen_output_array_wipe(&s->outputs);
|
||||
}
|
||||
|
||||
/** Get a screen argument from the lua stack */
|
||||
screen_t *
|
||||
luaA_checkscreen(lua_State *L, int sidx)
|
||||
{
|
||||
if (lua_isnumber(L, sidx))
|
||||
{
|
||||
int screen = lua_tointeger(L, sidx);
|
||||
if(screen < 1 || screen > globalconf.screens.len)
|
||||
luaL_error(L, "invalid screen number: %d", screen);
|
||||
return globalconf.screens.tab[screen - 1];
|
||||
} else
|
||||
return luaA_checkudata(L, sidx, &screen_class);
|
||||
}
|
||||
|
||||
static inline area_t
|
||||
screen_xsitoarea(xcb_xinerama_screen_info_t si)
|
||||
{
|
||||
|
@ -439,9 +453,7 @@ luaA_screen_module_index(lua_State *L)
|
|||
if(A_STREQ(output->name, name))
|
||||
return luaA_object_push(L, screen);
|
||||
|
||||
int screen = luaL_checknumber(L, 2) - 1;
|
||||
luaA_checkscreen(screen);
|
||||
return luaA_object_push(L, globalconf.screens.tab[screen]);
|
||||
return luaA_object_push(L, luaA_checkscreen(L, 2));
|
||||
}
|
||||
|
||||
LUA_OBJECT_EXPORT_PROPERTY(screen, screen_t, geometry, luaA_pusharea)
|
||||
|
|
|
@ -45,5 +45,7 @@ int screen_get_index(screen_t *);
|
|||
area_t display_area_get(void);
|
||||
void screen_client_moveto(client_t *, screen_t *, bool);
|
||||
|
||||
screen_t *luaA_checkscreen(lua_State *, int);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||
|
|
Loading…
Reference in New Issue