/** Mouse library. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lfield coords Mouse coordinates. * \lfield screen Mouse screen number. */ static int 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")) return luaA_default_index(L); if (!mouse_query_pointer_root(&mouse_x, &mouse_y, NULL, NULL)) { /* Nothing ever handles mouse.screen being nil. Lying is better than * having lots of lua errors in this case. */ if (globalconf.focus.client) lua_pushnumber(L, screen_get_index(globalconf.focus.client->screen)); else lua_pushnumber(L, 1); return 1; } screen = screen_getbycoord(mouse_x, mouse_y); lua_pushnumber(L, screen_get_index(screen)); return 1; }
/** Mouse library. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lfield coords Mouse coordinates. * \lfield screen Mouse screen number. */ static int 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")) return 0; if (!mouse_query_pointer_root(&mouse_x, &mouse_y, NULL, NULL)) return 0; screen = screen_getbycoord(mouse_x, mouse_y); lua_pushnumber(L, screen_array_indexof(&globalconf.screens, screen) + 1); return 1; }