From 95e5bdf5d250b67525b22bbed615c9016e78638c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 6 Mar 2016 13:31:30 +0100 Subject: [PATCH] Use the new way to iterate over screens in Lua This gets us one step closer to removing screen indices. Signed-off-by: Uli Schlachter --- awesomerc.lua | 6 +++--- lib/awful/layout/init.lua | 2 +- lib/awful/screen.lua | 4 ++-- lib/gears/wallpaper.lua | 2 +- lib/naughty/core.lua | 5 ++--- lib/wibox/drawable.lua | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/awesomerc.lua b/awesomerc.lua index 5b8f64603..4fc5e5c16 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -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. diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index 3c7546e37..fb65b09d7 100644 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -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) diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 1da181495..e9ecec614 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -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) diff --git a/lib/gears/wallpaper.lua b/lib/gears/wallpaper.lua index 25a5f7377..873324bd2 100644 --- a/lib/gears/wallpaper.lua +++ b/lib/gears/wallpaper.lua @@ -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) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index aab736028..18aa9629f 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -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 diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index 64111ec41..341505e6c 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -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