diff --git a/globalconf.h b/globalconf.h index f936369e3..4d44d9d96 100644 --- a/globalconf.h +++ b/globalconf.h @@ -80,6 +80,8 @@ typedef struct xcb_key_symbols_t *keysyms; /** Logical screens */ screen_array_t screens; + /** The primary screen, access through screen_get_primary() */ + screen_t *primary_screen; /** Root window key bindings */ key_array_t keys; /** Root window mouse bindings */ diff --git a/mouse.c b/mouse.c index af080b286..cf7bf4989 100644 --- a/mouse.c +++ b/mouse.c @@ -135,7 +135,7 @@ luaA_mouse_index(lua_State *L) if (globalconf.focus.client) luaA_pushscreen(L, globalconf.focus.client->screen); else - luaA_pushscreen(L, globalconf.screens.tab[0]); + luaA_pushscreen(L, screen_get_primary()); return 1; } diff --git a/objects/screen.c b/objects/screen.c index 3026c827c..d0cecc527 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -44,6 +44,7 @@ /** 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 * 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. * * @tfield table geometry The screen coordinates. Immutable. @@ -536,6 +537,14 @@ screen_get_index(screen_t *s) 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. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -548,10 +557,15 @@ luaA_screen_module_index(lua_State *L) const char *name; 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(output, (*screen)->outputs) if(A_STREQ(output->name, name)) return luaA_object_push(L, screen); + } return luaA_object_push(L, luaA_checkscreen(L, 2)); } diff --git a/objects/screen.h b/objects/screen.h index 95cf5d821..9cad113c4 100644 --- a/objects/screen.h +++ b/objects/screen.h @@ -47,6 +47,7 @@ bool screen_coord_in_screen(screen_t *, int, int); int screen_get_index(screen_t *); area_t display_area_get(void); void screen_client_moveto(client_t *, screen_t *, bool); +screen_t *screen_get_primary(void); void luaA_pushscreen(lua_State *, screen_t *); screen_t *luaA_checkscreen(lua_State *, int);