Merge pull request #746 from psychon/indexless-screen-iteration

Indexless screen iteration
This commit is contained in:
Daniel Hahler 2016-03-07 00:26:22 +01:00
commit c5526ca336
7 changed files with 35 additions and 11 deletions

View File

@ -91,7 +91,7 @@ end
-- {{{ Wallpaper
if beautiful.wallpaper then
for s = 1, screen.count() do
for s in screen do
gears.wallpaper.maximized(beautiful.wallpaper, s, true)
end
end
@ -100,7 +100,7 @@ end
-- {{{ Tags
-- Define a tag table which hold all screen tags.
tags = {}
for s = 1, screen.count() do
for s in screen do
-- Each screen has its own tag table.
tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, awful.layout.layouts[1])
end
@ -175,7 +175,7 @@ mytasklist.buttons = awful.util.table.join(
awful.client.focus.byidx(-1)
end))
for s = 1, screen.count() do
for s in screen do
-- Create a promptbox for each screen
mypromptbox[s] = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using.

View File

@ -244,7 +244,7 @@ capi.screen.connect_signal("padding", layout.arrange)
capi.client.connect_signal("raised", function(c) layout.arrange(c.screen) end)
capi.client.connect_signal("lowered", function(c) layout.arrange(c.screen) end)
capi.client.connect_signal("list", function()
for screen = 1, capi.screen.count() do
for screen in capi.screen do
layout.arrange(screen)
end
end)

View File

@ -60,7 +60,7 @@ end
function screen.getbycoord(x, y)
local s = capi.screen[1]
local dist = screen.getdistance_sq(s, x, y)
for i = 2, capi.screen:count() do
for i in capi.screen do
local d = screen.getdistance_sq(i, x, y)
if d < dist then
s, dist = capi.screen[i], d
@ -115,7 +115,7 @@ function screen.focus_bydirection(dir, _screen)
local sel = get_screen(_screen or screen.focused())
if sel then
local geomtbl = {}
for s = 1, capi.screen.count() do
for s in capi.screen do
geomtbl[s] = capi.screen[s].geometry
end
local target = util.get_rectangle_in_direction(dir, geomtbl, sel.geometry)

View File

@ -21,7 +21,7 @@ do
width = geom.x + geom.width,
height = geom.y + geom.height
}
for s = 1, screen.count() do
for s in screen do
local g = screen[s].geometry
root_geom.width = math.max(root_geom.width, g.x + g.width)
root_geom.height = math.max(root_geom.height, g.y + g.height)

View File

@ -143,7 +143,7 @@ local suspended = false
-- @field id Unique notification id based on a counter
-- @table notifications
naughty.notifications = { suspended = { } }
for s = 1, capi.screen.count() do
for s in capi.screen do
naughty.notifications[get_screen(s)] = {
top_left = {},
top_middle = {},
@ -294,8 +294,7 @@ end
-- @return notification object if it was found, nil otherwise
function naughty.getById(id)
-- iterate the notifications to get the notfications with the correct ID
for s = 1, capi.screen.count() do
s = get_screen(s)
for s in pairs(naughty.notifications) do
for p in pairs(naughty.notifications[s]) do
for _, notification in pairs(naughty.notifications[s][p]) do
if notification.id == id then

View File

@ -29,7 +29,7 @@ local wallpaper = nil
-- This is awful.screen.getbycoord() which we sadly cannot use from here (cyclic
-- dependencies are bad!)
local function screen_getbycoord(x, y)
for i = 1, screen:count() do
for i in screen do
local geometry = screen[i].geometry
if x >= geometry.x and x < geometry.x + geometry.width
and y >= geometry.y and y < geometry.y + geometry.height then

View File

@ -640,6 +640,30 @@ luaA_screen_module_index(lua_State *L)
return luaA_object_push(L, luaA_checkscreen(L, 2));
}
/** Iterate over screens.
* @usage
* for s in screen do
* print("Oh, wow, we have screen " .. tostring(s))
* end
* @function screen
*/
static int
luaA_screen_module_call(lua_State *L)
{
int idx;
if (lua_isnoneornil(L, 3))
idx = 0;
else
idx = screen_get_index(luaA_checkscreen(L, 3));
if (idx >= 0 && idx < globalconf.screens.len)
/* No +1 needed, index starts at 1, C array at 0 */
luaA_pushscreen(L, globalconf.screens.tab[idx]);
else
lua_pushnil(L);
return 1;
}
LUA_OBJECT_EXPORT_PROPERTY(screen, screen_t, geometry, luaA_pusharea)
static int
@ -696,6 +720,7 @@ screen_class_setup(lua_State *L)
{ "count", luaA_screen_count },
{ "__index", luaA_screen_module_index },
{ "__newindex", luaA_default_newindex },
{ "__call", luaA_screen_module_call },
{ NULL, NULL }
};