Add screen.primary

Right now this just always returns the first screens, but this can easily be
implemented properly later.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-27 15:44:25 +01:00
parent a2301ae8f3
commit 110893d9cb
4 changed files with 18 additions and 1 deletions

View File

@ -80,6 +80,8 @@ typedef struct
xcb_key_symbols_t *keysyms; xcb_key_symbols_t *keysyms;
/** Logical screens */ /** Logical screens */
screen_array_t screens; screen_array_t screens;
/** The primary screen, access through screen_get_primary() */
screen_t *primary_screen;
/** Root window key bindings */ /** Root window key bindings */
key_array_t keys; key_array_t keys;
/** Root window mouse bindings */ /** Root window mouse bindings */

View File

@ -135,7 +135,7 @@ luaA_mouse_index(lua_State *L)
if (globalconf.focus.client) if (globalconf.focus.client)
luaA_pushscreen(L, globalconf.focus.client->screen); luaA_pushscreen(L, globalconf.focus.client->screen);
else else
luaA_pushscreen(L, globalconf.screens.tab[0]); luaA_pushscreen(L, screen_get_primary());
return 1; return 1;
} }

View File

@ -44,6 +44,7 @@
/** Screen is a table where indexes are screen numbers. You can use `screen[1]` /** Screen is a table where indexes are screen numbers. You can use `screen[1]`
* to get access to the first screen, etc. Alternatively, if RANDR information * to get access to the first screen, etc. Alternatively, if RANDR information
* is available, you can use output names for finding screen objects. * is available, you can use output names for finding screen objects.
* The primary screen can be accessed as `screen.primary`.
* Each screen has a set of properties. * Each screen has a set of properties.
* *
* @tfield table geometry The screen coordinates. Immutable. * @tfield table geometry The screen coordinates. Immutable.
@ -536,6 +537,14 @@ screen_get_index(screen_t *s)
return 0; return 0;
} }
screen_t *
screen_get_primary(void)
{
if (!globalconf.primary_screen && globalconf.screens.len > 0)
globalconf.primary_screen = globalconf.screens.tab[0];
return globalconf.primary_screen;
}
/** Screen module. /** Screen module.
* \param L The Lua VM state. * \param L The Lua VM state.
* \return The number of elements pushed on stack. * \return The number of elements pushed on stack.
@ -548,10 +557,15 @@ luaA_screen_module_index(lua_State *L)
const char *name; const char *name;
if(lua_type(L, 2) == LUA_TSTRING && (name = lua_tostring(L, 2))) if(lua_type(L, 2) == LUA_TSTRING && (name = lua_tostring(L, 2)))
{
if(A_STREQ(name, "primary"))
return luaA_object_push(L, screen_get_primary());
foreach(screen, globalconf.screens) foreach(screen, globalconf.screens)
foreach(output, (*screen)->outputs) foreach(output, (*screen)->outputs)
if(A_STREQ(output->name, name)) if(A_STREQ(output->name, name))
return luaA_object_push(L, screen); return luaA_object_push(L, screen);
}
return luaA_object_push(L, luaA_checkscreen(L, 2)); return luaA_object_push(L, luaA_checkscreen(L, 2));
} }

View File

@ -47,6 +47,7 @@ bool screen_coord_in_screen(screen_t *, int, int);
int screen_get_index(screen_t *); 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);
screen_t *screen_get_primary(void);
void luaA_pushscreen(lua_State *, screen_t *); void luaA_pushscreen(lua_State *, screen_t *);
screen_t *luaA_checkscreen(lua_State *, int); screen_t *luaA_checkscreen(lua_State *, int);