diff --git a/lib/awful/autofocus.lua b/lib/awful/autofocus.lua index 0112cfc2..f0e9090a 100644 --- a/lib/awful/autofocus.lua +++ b/lib/awful/autofocus.lua @@ -21,7 +21,7 @@ local timer = require("gears.timer") local function check_focus(obj) -- When no visible client has the focus... if not client.focus or not client.focus:isvisible() then - local c = aclient.focus.history.get(obj.screen, 0, aclient.focus.filter) + local c = aclient.focus.history.get(screen[obj.screen], 0, aclient.focus.filter) if c then c:emit_signal("request::activate", "autofocus.check_focus", {raise=false}) @@ -41,8 +41,9 @@ end local function check_focus_tag(t) local s = atag.getscreen(t) if not s then return end + s = screen[s] check_focus({ screen = s }) - if client.focus and client.focus.screen ~= s then + if client.focus and screen[client.focus.screen] ~= s then local c = aclient.focus.history.get(s, 0, aclient.focus.filter) if c then c:emit_signal("request::activate", "autofocus.check_focus_tag", diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 77d51bee..46b3fa4b 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -25,6 +25,10 @@ local capi = awesome = awesome, } +local function get_screen(s) + return s and capi.screen[s] +end + -- We use a metatable to prevent circular dependency loops. local screen do @@ -63,9 +67,9 @@ client.shape = require("awful.client.shape") -- @client c the client to jump to -- @tparam bool merge If true then merge tags when clients are not visible. function client.jumpto(c, merge) - local s = screen.focused() + local s = get_screen(screen.focused()) -- focus the screen - if s ~= c.screen then + if s ~= get_screen(c.screen) then screen.focus(c.screen) end @@ -171,7 +175,7 @@ end --- Get the latest focused client for a screen in history. -- --- @tparam int s The screen number to look for. +-- @tparam int|screen s The screen to look for. -- @tparam int idx The index: 0 will return first candidate, -- 1 will return second, etc. -- @tparam function filter An optional filter. If no client is found in the @@ -179,11 +183,12 @@ end -- client. -- @treturn client.object A client. function client.focus.history.get(s, idx, filter) + s = get_screen(s) -- When this counter is equal to idx, we return the client local counter = 0 local vc = client.visible(s, true) for _, c in ipairs(client.data.focus) do - if c.screen == s then + if get_screen(c.screen) == s then if not filter or filter(c) then for _, vcc in ipairs(vc) do if vcc == c then @@ -223,7 +228,7 @@ end --- Get visible clients from a screen. -- --- @tparam[opt] integer s The screen number, or nil for all screens. +-- @tparam[opt] integer|screen s The screen, or nil for all screens. -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) -- @treturn table A table with all visible clients. function client.visible(s, stacked) @@ -239,7 +244,7 @@ end --- Get visible and tiled clients -- --- @tparam integer s The screen number, or nil for all screens. +-- @tparam integer|screen s The screen, or nil for all screens. -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) -- @treturn table A table with all visible and tiled clients. function client.tiled(s, stacked) @@ -325,7 +330,7 @@ end -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) function client.focus.global_bydirection(dir, c, stacked) local sel = c or capi.client.focus - local scr = sel and sel.screen or screen.focused() + local scr = get_screen(sel and sel.screen or screen.focused()) -- change focus inside the screen client.focus.bydirection(dir, sel) @@ -333,13 +338,13 @@ function client.focus.global_bydirection(dir, c, stacked) -- if focus not changed, we must change screen if sel == capi.client.focus then screen.focus_bydirection(dir, scr) - if scr ~= screen.focused() then + if scr ~= get_screen(screen.focused()) then local cltbl = client.visible(screen.focused(), stacked) local geomtbl = {} for i,cl in ipairs(cltbl) do geomtbl[i] = cl:geometry() end - local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[scr].geometry) + local target = util.get_rectangle_in_direction(dir, geomtbl, scr.geometry) if target then cltbl[target]:emit_signal("request::activate", @@ -388,7 +393,7 @@ end -- @client[opt] sel The client. function client.swap.global_bydirection(dir, sel) sel = sel or capi.client.focus - local scr = sel and sel.screen or screen.focused() + local scr = get_screen(sel and sel.screen or screen.focused()) if sel then -- move focus @@ -396,15 +401,15 @@ function client.swap.global_bydirection(dir, sel) local c = capi.client.focus -- swapping inside a screen - if sel.screen == c.screen and sel ~= c then + if get_screen(sel.screen) == get_screen(c.screen) and sel ~= c then c:swap(sel) -- swapping to an empty screen - elseif sel.screen ~= c.screen and sel == c then + elseif get_screen(sel.screen) ~= get_screen(c.screen) and sel == c then client.movetoscreen(sel, screen.focused()) -- swapping to a nonempty screen - elseif sel.screen ~= c.screen and sel ~= c then + elseif get_screen(sel.screen) ~= get_screen(c.screen) and sel ~= c then client.movetoscreen(sel, c.screen) client.movetoscreen(c, scr) end @@ -515,7 +520,7 @@ end function client.toggletag(target, c) local sel = c or capi.client.focus -- Check that tag and client screen are identical - if sel and sel.screen == tag.getscreen(target) then + if sel and get_screen(sel.screen) == get_screen(tag.getscreen(target)) then local tags = sel:tags() local index = nil; for i, v in ipairs(tags) do @@ -537,7 +542,7 @@ end --- Move a client to a screen. Default is next screen, cycling. -- @client c The client to move. --- @param s The screen number, default to current + 1. +-- @param s The screen, default to current + 1. function client.movetoscreen(c, s) local sel = c or capi.client.focus if sel then @@ -545,8 +550,9 @@ function client.movetoscreen(c, s) if not s then s = sel.screen + 1 end - if s > sc then s = 1 elseif s < 1 then s = sc end - if sel.screen ~= s then + if type(s) == "number" and s > sc then s = 1 elseif s < 1 then s = sc end + s = get_screen(s) + if get_screen(sel.screen) ~= s then local sel_is_focused = sel == capi.client.focus sel.screen = s screen.focus(s) diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index 8921a9ab..de35637c 100644 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -23,6 +23,10 @@ local tag = require("awful.tag") local client = require("awful.client") local timer = require("gears.timer") +local function get_screen(s) + return s and capi.screen[s] +end + local layout = {} --- Default predefined layouts @@ -57,7 +61,7 @@ local arrange_lock = false local delayed_arrange = {} --- Get the current layout. --- @param screen The screen number. +-- @param screen The screen. -- @return The layout function. function layout.get(screen) local t = tag.selected(screen) @@ -66,7 +70,7 @@ end --- Change the layout of the current tag. -- @param i Relative index. --- @param s The screen number. +-- @param s The screen. -- @param[opt] layouts A table of layouts. function layout.inc(i, s, layouts) if type(i) == "table" then @@ -74,6 +78,7 @@ function layout.inc(i, s, layouts) -- this was changed so that 'layouts' can be an optional parameter layouts, i, s = i, s, layouts end + s = get_screen(s) local t = tag.selected(s) layouts = layouts or layout.layouts if t then @@ -124,20 +129,21 @@ end -- geometry (x, y, width, height), the clients, the screen and sometime, a -- "geometries" table with client as keys and geometry as value function layout.parameters(t, screen) + screen = get_screen(screen) t = t or tag.selected(screen) if not t then return end - screen = tag.getscreen(t) or 1 + screen = get_screen(tag.getscreen(t) or 1) local p = {} - p.workarea = capi.screen[screen].workarea + p.workarea = screen.workarea local useless_gap = tag.getgap(t, #client.tiled(screen)) -- Handle padding - local padding = ascreen.padding(capi.screen[screen]) or {} + local padding = ascreen.padding(screen) or {} p.workarea.x = p.workarea.x + (padding.left or 0) + useless_gap @@ -149,9 +155,9 @@ function layout.parameters(t, screen) p.workarea.height = p.workarea.height - ((padding.top or 0) + (padding.bottom or 0) + useless_gap * 2) - p.geometry = capi.screen[screen].geometry + p.geometry = screen.geometry p.clients = client.tiled(screen) - p.screen = screen + p.screen = screen.index p.padding = padding p.useless_gap = useless_gap @@ -161,6 +167,7 @@ end --- Arrange a screen using its current layout. -- @param screen The screen to arrange. function layout.arrange(screen) + screen = get_screen(screen) if not screen or delayed_arrange[screen] then return end delayed_arrange[screen] = true @@ -181,7 +188,7 @@ function layout.arrange(screen) g.y = g.y + useless_gap c:geometry(g) end - capi.screen[screen]:emit_signal("arrange") + screen:emit_signal("arrange") arrange_lock = false delayed_arrange[screen] = nil @@ -235,10 +242,10 @@ capi.tag.connect_signal("tagged", arrange_tag) for s = 1, capi.screen.count() do capi.screen[s]:connect_signal("property::workarea", function(screen) - layout.arrange(screen.index) + layout.arrange(screen) end) capi.screen[s]:connect_signal("padding", function (screen) - layout.arrange(screen.index) + layout.arrange(screen) end) end diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index 2e29179d..24d6899c 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -120,8 +120,8 @@ local function item_position(_menu, child) end -local function set_coords(_menu, screen_idx, m_coords) - local s_geometry = capi.screen[screen_idx].workarea +local function set_coords(_menu, s, m_coords) + local s_geometry = s.workarea local screen_w = s_geometry.x + s_geometry.width local screen_h = s_geometry.y + s_geometry.height @@ -313,10 +313,10 @@ end function menu:show(args) args = args or {} local coords = args.coords or nil - local screen_index = screen.focused() + local s = capi.screen[screen.focused()] if not set_size(self) then return end - set_coords(self, screen_index, coords) + set_coords(self, s, coords) keygrabber.run(self._keygrabber) self.wibox.visible = true diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index f7469c80..7f07ce1c 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -23,6 +23,10 @@ local layout = require("awful.layout") local a_screen = require("awful.screen") local dpi = require("beautiful").xresources.apply_dpi +local function get_screen(s) + return s and capi.screen[s] +end + local placement = {} --- Check if an area intersect another area. @@ -121,8 +125,8 @@ end function placement.no_offscreen(c, screen) c = c or capi.client.focus local geometry = get_area(c) - screen = screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y) - local screen_geometry = capi.screen[screen].workarea + screen = get_screen(screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y)) + local screen_geometry = screen.workarea if geometry.x + geometry.width > screen_geometry.x + screen_geometry.width then geometry.x = screen_geometry.x + screen_geometry.width - geometry.width @@ -145,10 +149,10 @@ end -- @param c The client. function placement.no_overlap(c) local geometry = get_area(c) - local screen = c.screen or a_screen.getbycoord(geometry.x, geometry.y) + local screen = get_screen(c.screen or a_screen.getbycoord(geometry.x, geometry.y)) local cls = client.visible(screen) local curlay = layout.get() - local areas = { capi.screen[screen].workarea } + local areas = { screen.workarea } for _, cl in pairs(cls) do if cl ~= c and cl.type ~= "desktop" and (client.floating.get(cl) or curlay == layout.suit.floating) then areas = area_remove(areas, get_area(cl)) @@ -249,12 +253,12 @@ end function placement.centered(c, p) c = c or capi.client.focus local c_geometry = get_area(c) - local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) + local screen = get_screen(c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y)) local s_geometry if p then s_geometry = get_area(p) else - s_geometry = capi.screen[screen].geometry + s_geometry = screen.geometry end return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2, y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) @@ -267,12 +271,12 @@ end function placement.center_horizontal(c, p) c = c or capi.client.focus local c_geometry = get_area(c) - local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) + local screen = get_screen(c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y)) local s_geometry if p then s_geometry = get_area(p) else - s_geometry = capi.screen[screen].geometry + s_geometry = screen.geometry end return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 }) end @@ -284,12 +288,12 @@ end function placement.center_vertical(c, p) c = c or capi.client.focus local c_geometry = get_area(c) - local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) + local screen = get_screen(c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y)) local s_geometry if p then s_geometry = get_area(p) else - s_geometry = capi.screen[screen].geometry + s_geometry = screen.geometry end return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) end diff --git a/lib/awful/screen.lua b/lib/awful/screen.lua index 5fff4f0f..51c1f8bb 100644 --- a/lib/awful/screen.lua +++ b/lib/awful/screen.lua @@ -16,6 +16,10 @@ local capi = } local util = require("awful.util") +local function get_screen(s) + return s and screen[s] +end + -- we use require("awful.client") inside functions to prevent circular dependencies. local client @@ -26,12 +30,13 @@ data.padding = {} screen.mouse_per_screen = {} --- @param s Screen number +-- @param s Screen -- @param x X coordinate of point -- @param y Y coordinate of point -- @return The squared distance of the screen to the provided point function screen.getdistance_sq(s, x, y) - local geom = capi.screen[s].geometry + s = get_screen(s) + local geom = s.geometry local dist_x, dist_y = 0, 0 if x < geom.x then dist_x = geom.x - x @@ -47,21 +52,21 @@ function screen.getdistance_sq(s, x, y) end --- --- Return Xinerama screen number corresponding to the given (pixel) coordinates. +-- Return screen number corresponding to the given (pixel) coordinates. -- The number returned can be used as an index into the global -- `screen` table/object. -- @param x The x coordinate -- @param y The y coordinate function screen.getbycoord(x, y) - local s = 1 + local s = screen[1] local dist = screen.getdistance_sq(s, x, y) for i = 2, capi.screen:count() do local d = screen.getdistance_sq(i, x, y) if d < dist then - s, dist = i, d + s, dist = screen[i], d end end - return s + return s.index end --- Give the focus to a screen, and move pointer to last known position on this @@ -69,21 +74,22 @@ end -- @param _screen Screen number (defaults / falls back to mouse.screen). function screen.focus(_screen) client = client or require("awful.client") - if _screen > capi.screen.count() then _screen = screen.focused() end + if type(_screen) == "number" and _screen > capi.screen.count() then _screen = screen.focused() end + _screen = get_screen(_screen) -- screen and pos for current screen - local s = capi.mouse.screen + local s = get_screen(capi.mouse.screen) local pos if not screen.mouse_per_screen[_screen] then -- This is the first time we enter this screen, -- keep relative mouse position on the new screen pos = capi.mouse.coords() - local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width - local rely = (pos.y - capi.screen[s].geometry.y) / capi.screen[s].geometry.height + local relx = (pos.x - s.geometry.x) / s.geometry.width + local rely = (pos.y - s.geometry.y) / s.geometry.height - pos.x = capi.screen[_screen].geometry.x + relx * capi.screen[_screen].geometry.width - pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height + pos.x = _screen.geometry.x + relx * _screen.geometry.width + pos.y = _screen.geometry.y + rely * _screen.geometry.height else -- restore mouse position pos = screen.mouse_per_screen[_screen] @@ -104,15 +110,15 @@ end --- Give the focus to a screen, and move pointer to last known position on this -- screen, or keep position relative to the current focused screen -- @param dir The direction, can be either "up", "down", "left" or "right". --- @param _screen Screen number. +-- @param _screen Screen. function screen.focus_bydirection(dir, _screen) - local sel = _screen or screen.focused() + local sel = get_screen(_screen or screen.focused()) if sel then local geomtbl = {} for s = 1, capi.screen.count() do geomtbl[s] = capi.screen[s].geometry end - local target = util.get_rectangle_in_direction(dir, geomtbl, capi.screen[sel].geometry) + local target = util.get_rectangle_in_direction(dir, geomtbl, sel.geometry) if target then return screen.focus(target) end @@ -132,6 +138,7 @@ end -- @param padding The padding, an table with 'top', 'left', 'right' and/or -- 'bottom'. Can be nil if you only want to retrieve padding function screen.padding(_screen, padding) + _screen = get_screen(_screen) if padding then data.padding[_screen] = padding _screen:emit_signal("padding") diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua index feba135c..b24860b4 100644 --- a/lib/awful/tag.lua +++ b/lib/awful/tag.lua @@ -24,6 +24,10 @@ local capi = root = root } +local function get_screen(s) + return s and capi.screen[s] +end + -- we use require("awful.client") inside functions to prevent circular dependencies. local client @@ -45,7 +49,7 @@ tag.history.limit = 20 -- selected tag is used. function tag.move(new_index, target_tag) target_tag = target_tag or tag.selected() - local scr = tag.getscreen(target_tag) + local scr = get_screen(tag.getscreen(target_tag)) local tmp_tags = tag.gettags(scr) if (not new_index) or (new_index < 1) or (new_index > #tmp_tags) then @@ -94,7 +98,7 @@ function tag.add(name, props) -- connected to property::activated to be called without a valid tag. -- set properties cannot be used as this has to be set before the first -- signal is sent - properties.screen = properties.screen or ascreen.focused() + properties.screen = get_screen(properties.screen or ascreen.focused()) -- Index is also required properties.index = (#tag.gettags(properties.screen))+1 @@ -119,7 +123,7 @@ end -- @param layout The layout or layout table to set for this tags by default. -- @return A table with all created tags. function tag.new(names, screen, layout) - screen = screen or 1 + screen = get_screen(screen or 1) local tags = {} for id, name in ipairs(names) do table.insert(tags, id, tag.add(name, {screen = screen, @@ -135,7 +139,7 @@ function tag.new(names, screen, layout) end --- Find a suitable fallback tag. --- @param screen The screen number to look for a tag on. [awful.screen.focused()] +-- @param screen The screen to look for a tag on. [awful.screen.focused()] -- @param invalids A table of tags we consider unacceptable. [selectedlist(scr)] function tag.find_fallback(screen, invalids) local scr = screen or ascreen.focused() @@ -159,7 +163,7 @@ function tag.delete(target_tag, fallback_tag) target_tag = target_tag or tag.selected() if target_tag == nil or target_tag.activated == false then return end - local target_scr = tag.getscreen(target_tag) + local target_scr = get_screen(tag.getscreen(target_tag)) local tags = tag.gettags(target_scr) local idx = tag.getidx(target_tag) local ntags = #tags @@ -214,7 +218,7 @@ end --- Update the tag history. -- @param obj Screen object. function tag.history.update(obj) - local s = obj.index + local s = get_screen(obj) local curtags = tag.selectedlist(s) -- create history table if not data.history[s] then @@ -252,12 +256,12 @@ function tag.history.update(obj) end --- Revert tag history. --- @param screen The screen number. +-- @param screen The screen. -- @param idx Index in history. Defaults to "previous" which is a special index -- toggling between last two selected sets of tags. Number (eg 1) will go back -- to the given index in history. function tag.history.restore(screen, idx) - local s = screen or ascreen.focused() + local s = get_screen(screen or ascreen.focused()) local i = idx or "previous" local sel = tag.selectedlist(s) -- do nothing if history empty @@ -281,16 +285,17 @@ function tag.history.restore(screen, idx) -- remove the reverted history entry if i ~= "previous" then table.remove(data.history[s], i) end - capi.screen[s]:emit_signal("tag::history::update") + s:emit_signal("tag::history::update") end --- Get a list of all tags on a screen --- @param s Screen number +-- @param s Screen -- @return A table with all available tags function tag.gettags(s) + s = get_screen(s) local tags = {} for _, t in ipairs(root.tags()) do - if tag.getscreen(t) == s then + if get_screen(tag.getscreen(t)) == s then table.insert(tags, t) end end @@ -302,7 +307,7 @@ function tag.gettags(s) end --- Set a tag's screen --- @param s Screen number +-- @param s Screen -- @param t tag object function tag.setscreen(s, t) @@ -312,7 +317,7 @@ function tag.setscreen(s, t) s, t = t, s end - s = s or ascreen.focused() + s = get_screen(s or ascreen.focused()) local sel = tag.selected local old_screen = tag.getproperty(t, "screen") if s == old_screen then return end @@ -347,11 +352,12 @@ end -- @return Screen number function tag.getscreen(t) t = t or tag.selected() - return tag.getproperty(t, "screen") + local prop = tag.getproperty(t, "screen") + return prop and prop.index end --- Return a table with all visible tags --- @param s Screen number. +-- @param s Screen. -- @return A table with all selected tags. function tag.selectedlist(s) local screen = s or ascreen.focused() @@ -366,7 +372,7 @@ function tag.selectedlist(s) end --- Return only the first visible tag. --- @param s Screen number. +-- @param s Screen. function tag.selected(s) return tag.selectedlist(s)[1] end @@ -517,7 +523,8 @@ end function tag.incnmaster(add, t, sensible) if sensible then client = client or require("awful.client") - local ntiled = #client.tiled(tag.getscreen(t)) + local screen = get_screen(tag.getscreen(t)) + local ntiled = #client.tiled(screen) local nmaster = tag.getnmaster(t) if nmaster > ntiled then @@ -575,7 +582,8 @@ end function tag.incncol(add, t, sensible) if sensible then client = client or require("awful.client") - local ntiled = #client.tiled(tag.getscreen(t)) + local screen = get_screen(tag.getscreen(t)) + local ntiled = #client.tiled(screen) local nmaster = tag.getnmaster(t) local nsecondary = ntiled - nmaster @@ -595,7 +603,7 @@ function tag.incncol(add, t, sensible) end --- View no tag. --- @tparam[opt] int screen The screen number. +-- @tparam[opt] int|screen screen The screen. function tag.viewnone(screen) local tags = tag.gettags(screen or ascreen.focused()) for _, t in pairs(tags) do @@ -605,9 +613,9 @@ end --- View a tag by its taglist index. -- @param i The relative index to see. --- @param[opt] screen The screen number. +-- @param[opt] screen The screen. function tag.viewidx(i, screen) - screen = screen or ascreen.focused() + screen = get_screen(screen or ascreen.focused()) local tags = tag.gettags(screen) local showntags = {} for _, t in ipairs(tags) do @@ -622,7 +630,7 @@ function tag.viewidx(i, screen) showntags[util.cycle(#showntags, k + i)].selected = true end end - capi.screen[screen]:emit_signal("tag::history::update") + screen:emit_signal("tag::history::update") end --- Get a tag's index in the gettags() table. @@ -640,13 +648,13 @@ function tag.getidx(query_tag) end --- View next tag. This is the same as tag.viewidx(1). --- @param screen The screen number. +-- @param screen The screen. function tag.viewnext(screen) return tag.viewidx(1, screen) end --- View previous tag. This is the same a tag.viewidx(-1). --- @param screen The screen number. +-- @param screen The screen. function tag.viewprev(screen) return tag.viewidx(-1, screen) end @@ -670,9 +678,9 @@ end --- View only a set of tags. -- @param tags A table with tags to view only. --- @param[opt] screen The screen number of the tags. +-- @param[opt] screen The screen of the tags. function tag.viewmore(tags, screen) - screen = screen or ascreen.focused() + screen = get_screen(screen or ascreen.focused()) local screen_tags = tag.gettags(screen) for _, _tag in ipairs(screen_tags) do if not util.table.hasitem(tags, _tag) then @@ -682,7 +690,7 @@ function tag.viewmore(tags, screen) for _, _tag in ipairs(tags) do _tag.selected = true end - capi.screen[screen]:emit_signal("tag::history::update") + screen:emit_signal("tag::history::update") end --- Toggle selection of a tag @@ -736,7 +744,7 @@ end function tag.withcurrent(c) local tags = {} for _, t in ipairs(c:tags()) do - if tag.getscreen(t) == c.screen then + if get_screen(tag.getscreen(t)) == get_screen(c.screen) then table.insert(tags, t) end end @@ -752,8 +760,9 @@ function tag.withcurrent(c) end local function attached_connect_signal_screen(screen, sig, func) + screen = get_screen(screen) capi.tag.connect_signal(sig, function(_tag) - if tag.getscreen(_tag) == screen then + if get_screen(tag.getscreen(_tag)) == screen then func(_tag) end end) diff --git a/lib/awful/wibox.lua b/lib/awful/wibox.lua index 7d7978b2..ee944048 100644 --- a/lib/awful/wibox.lua +++ b/lib/awful/wibox.lua @@ -25,6 +25,10 @@ local wibox = require("wibox") local beautiful = require("beautiful") local round = require("awful.util").round +local function get_screen(s) + return s and screen[s] +end + local awfulwibox = { mt = {} } --- Array of table with wiboxes inside. @@ -49,7 +53,7 @@ end -- @param screen If the wibox it not attached to a screen, specified on which -- screen the position should be set. function awfulwibox.set_position(wb, position, screen) - local area = capi.screen[screen].geometry + local area = get_screen(screen).geometry -- The "length" of a wibox is always chosen to be the optimal size -- (non-floating). @@ -107,8 +111,9 @@ end -- will be attached. -- @param wb The wibox to attach. -- @param position The position of the wibox: top, bottom, left or right. --- @param screen TODO, this seems to be unused +-- @param screen The screen to attach to function awfulwibox.attach(wb, position, screen) + screen = get_screen(screen) -- Store wibox as attached in a weak-valued table local wibox_prop_table -- Start from end since we sometimes remove items @@ -144,10 +149,11 @@ end -- @param wb The wibox. -- @param align The alignment: left, right or center. -- @param screen If the wibox is not attached to any screen, you can specify the --- screen where to align. Otherwise 1 is assumed. +-- screen where to align. function awfulwibox.align(wb, align, screen) + screen = get_screen(screen) local position = awfulwibox.get_position(wb) - local area = capi.screen[screen].workarea + local area = screen.workarea if position == "right" then if align == "right" then @@ -192,8 +198,9 @@ end -- @param screen The screen to stretch on, or the wibox screen. function awfulwibox.stretch(wb, screen) if screen then + screen = get_screen(screen) local position = awfulwibox.get_position(wb) - local area = capi.screen[screen].workarea + local area = screen.workarea if position == "right" or position == "left" then wb.height = area.height - (2 * wb.border_width) wb.y = area.y @@ -216,7 +223,7 @@ function awfulwibox.new(arg) arg = arg or {} local position = arg.position or "top" local has_to_stretch = true - local screen = arg.screen or 1 + local screen = get_screen(arg.screen or 1) arg.type = arg.type or "dock" @@ -234,7 +241,7 @@ function awfulwibox.new(arg) if arg.screen then local hp = tostring(arg.height):match("(%d+)%%") if hp then - arg.height = round(capi.screen[arg.screen].geometry.height * hp / 100) + arg.height = round(screen.geometry.height * hp / 100) end end end @@ -245,7 +252,7 @@ function awfulwibox.new(arg) if arg.screen then local wp = tostring(arg.width):match("(%d+)%%") if wp then - arg.width = round(capi.screen[arg.screen].geometry.width * wp / 100) + arg.width = round(screen.geometry.width * wp / 100) end end end diff --git a/lib/awful/widget/layoutbox.lua b/lib/awful/widget/layoutbox.lua index 11e7fcaf..a72aa088 100644 --- a/lib/awful/widget/layoutbox.lua +++ b/lib/awful/widget/layoutbox.lua @@ -8,24 +8,30 @@ --------------------------------------------------------------------------- local setmetatable = setmetatable +local capi = { screen = screen } local layout = require("awful.layout") local tooltip = require("awful.tooltip") local tag = require("awful.tag") local beautiful = require("beautiful") local imagebox = require("wibox.widget.imagebox") +local function get_screen(s) + return s and capi.screen[s] +end + local layoutbox = { mt = {} } local boxes = nil local function update(w, screen) + screen = get_screen(screen) local name = layout.getname(layout.get(screen)) w._layoutbox_tooltip:set_text(name or "[no name]") w:set_image(name and beautiful["layout_" .. name]) end local function update_from_tag(t) - local screen = tag.getscreen(t) + local screen = get_screen(tag.getscreen(t)) local w = boxes[screen] if w then update(w, screen) @@ -37,7 +43,7 @@ end -- @param screen The screen number that the layout will be represented for. -- @return An imagebox widget configured as a layoutbox. function layoutbox.new(screen) - screen = screen or 1 + screen = get_screen(screen or 1) -- Do we already have the update callbacks registered? if boxes == nil then diff --git a/lib/awful/widget/taglist.lua b/lib/awful/widget/taglist.lua index c7f64833..b0cd32c0 100644 --- a/lib/awful/widget/taglist.lua +++ b/lib/awful/widget/taglist.lua @@ -23,6 +23,10 @@ local fixed = require("wibox.layout.fixed") local surface = require("gears.surface") local timer = require("gears.timer") +local function get_screen(s) + return s and capi.screen[s] +end + local taglist = { mt = {} } taglist.filter = {} @@ -153,6 +157,7 @@ end -- @param[opt] base_widget.squares_resize True or false to resize squares. -- @param base_widget.font The font. function taglist.new(screen, filter, buttons, style, update_function, base_widget) + screen = get_screen(screen) local uf = update_function or common.list_update local w = base_widget or fixed.horizontal() @@ -172,7 +177,7 @@ function taglist.new(screen, filter, buttons, style, update_function, base_widge if instances == nil then instances = {} local function u(s) - local i = instances[s] + local i = instances[get_screen(s)] if i then for _, tlist in pairs(i) do tlist._do_taglist_update() diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index b26b4935..130a6723 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -21,6 +21,10 @@ local tag = require("awful.tag") local flex = require("wibox.layout.flex") local timer = require("gears.timer") +local function get_screen(s) + return s and screen[s] +end + local tasklist = { mt = {} } local instances @@ -165,6 +169,7 @@ end -- @param base_widget.maximized_vertical Symbol to use for clients that have been vertically maximized. -- @param base_widget.font The font. function tasklist.new(screen, filter, buttons, style, update_function, base_widget) + screen = get_screen(screen) local uf = update_function or common.list_update local w = base_widget or flex.horizontal() @@ -187,7 +192,7 @@ function tasklist.new(screen, filter, buttons, style, update_function, base_widg if instances == nil then instances = {} local function us(s) - local i = instances[s] + local i = instances[get_screen(s)] if i then for _, tlist in pairs(i) do tlist._do_tasklist_update() @@ -256,7 +261,7 @@ end -- @return true if c is on screen, false otherwise function tasklist.filter.alltags(c, screen) -- Only print client on the same screen as this widget - return c.screen == screen + return get_screen(c.screen) == get_screen(screen) end --- Filtering function to include only the clients from currently selected tags. @@ -264,8 +269,9 @@ end -- @param screen The screen we are drawing on. -- @return true if c is in a selected tag on screen, false otherwise function tasklist.filter.currenttags(c, screen) + screen = get_screen(screen) -- Only print client on the same screen as this widget - if c.screen ~= screen then return false end + if get_screen(c.screen) ~= screen then return false end -- Include sticky client too if c.sticky then return true end local tags = tag.gettags(screen) @@ -287,8 +293,9 @@ end -- @param screen The screen we are drawing on. -- @return true if c is in a selected tag on screen and is minimized, false otherwise function tasklist.filter.minimizedcurrenttags(c, screen) + screen = get_screen(screen) -- Only print client on the same screen as this widget - if c.screen ~= screen then return false end + if get_screen(c.screen) ~= screen then return false end -- Check client is minimized if not c.minimized then return false end -- Include sticky client @@ -314,7 +321,7 @@ end -- @return true if c is focused on screen, false otherwise function tasklist.filter.focused(c, screen) -- Only print client on the same screen as this widget - return c.screen == screen and capi.client.focus == c + return get_screen(c.screen) == get_screen(screen) and capi.client.focus == c end function tasklist.mt:__call(...) diff --git a/lib/beautiful/xresources.lua b/lib/beautiful/xresources.lua index 333d5aa4..20cdfa79 100644 --- a/lib/beautiful/xresources.lua +++ b/lib/beautiful/xresources.lua @@ -9,6 +9,7 @@ -- Grab environment local awesome = awesome +local screen = screen local round = require("awful.util").round local gears_debug = require("gears.debug") @@ -66,10 +67,15 @@ end local dpi_per_screen = {} +local function get_screen(s) + return s and screen[s] +end + --- Get global or per-screen DPI value falling back to xrdb. --- @tparam[opt=focused] integer s The screen. +-- @tparam[opt] integer|screen s The screen. -- @treturn number DPI value. function xresources.get_dpi(s) + s = get_screen(s) if dpi_per_screen[s] then return dpi_per_screen[s] end @@ -90,6 +96,7 @@ end -- @tparam number dpi DPI value. -- @tparam[opt] integer s Screen. function xresources.set_dpi(dpi, s) + s = get_screen(s) if not s then xresources.dpi = dpi else @@ -100,7 +107,7 @@ end --- Compute resulting size applying current DPI value (optionally per screen). -- @tparam number size Size --- @tparam[opt] integer s The screen. +-- @tparam[opt] integer|screen s The screen. -- @treturn integer Resulting size (rounded to integer). function xresources.apply_dpi(size, s) return round(size / 96 * xresources.get_dpi(s)) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 53e94eb1..cd1199a1 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -31,6 +31,10 @@ local common = require("awful.widget.common") local theme = require("beautiful") local wibox = require("wibox") +local function get_screen(s) + return s and capi.screen[s] +end + -- menubar local menubar = { mt = {}, menu_entries = {} } menubar.menu_gen = require("menubar.menu_gen") @@ -122,9 +126,10 @@ end --- Cut item list to return only current page. -- @tparam table all_items All items list. -- @tparam str query Search query. --- @tparam number scr Screen number +-- @tparam number|screen scr Screen -- @return table List of items for current page. local function get_current_page(all_items, query, scr) + scr = get_screen(scr) if not instance.prompt.width then instance.prompt.width = compute_text_width(instance.prompt.prompt, scr) end @@ -161,7 +166,7 @@ end --- Update the menubar according to the command entered by user. -- @tparam str query Search query. --- @tparam number scr Screen number +-- @tparam number|screen scr Screen local function menulist_update(query, scr) query = query or "" shownitems = {} @@ -288,7 +293,7 @@ local function prompt_keypressed_callback(mod, key, comm) end --- Show the menubar on the given screen. --- @param scr Screen number. +-- @param scr Screen. function menubar.show(scr) if not instance.wibox then initialize() @@ -300,6 +305,7 @@ function menubar.show(scr) -- Set position and size scr = scr or awful.screen.focused() or 1 + scr = get_screen(scr) local scrgeom = capi.screen[scr].workarea local geometry = menubar.geometry instance.geometry = {x = geometry.x or scrgeom.x, diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index da9ecd1a..c61c5ff1 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -12,6 +12,7 @@ local io = io local table = table local ipairs = ipairs local string = string +local screen = screen local awful_util = require("awful.util") local theme = require("beautiful") local glib = require("lgi").GLib @@ -257,17 +258,17 @@ end --- Compute textbox width. -- @tparam wibox.widget.textbox textbox Textbox instance. --- @tparam number s Screen number +-- @tparam number|screen s Screen -- @treturn int Text width. function utils.compute_textbox_width(textbox, s) - s = s or mouse.screen + s = screen[s or mouse.screen] local w, _ = textbox:get_preferred_size(s) return w end --- Compute text width. -- @tparam str text Text. --- @tparam number s Screen number +-- @tparam number|screen s Screen -- @treturn int Text width. function utils.compute_text_width(text, s) return utils.compute_textbox_width(wibox.widget.textbox(awful_util.escape(text)), s) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index f9a86395..aab73602 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -25,6 +25,10 @@ local surface = require("gears.surface") local cairo = require("lgi").cairo local dpi = require("beautiful").xresources.apply_dpi +local function get_screen(s) + return s and capi.screen[s] +end + local naughty = {} --[[-- @@ -140,7 +144,7 @@ local suspended = false -- @table notifications naughty.notifications = { suspended = { } } for s = 1, capi.screen.count() do - naughty.notifications[s] = { + naughty.notifications[get_screen(s)] = { top_left = {}, top_middle = {}, top_right = {}, @@ -189,7 +193,8 @@ end -- @param height Popup height -- @return Absolute position and index in { x = X, y = Y, idx = I } table local function get_offset(s, position, idx, width, height) - local ws = capi.screen[s].workarea + s = get_screen(s) + local ws = s.workarea local v = {} idx = idx or #naughty.notifications[s][position] + 1 width = width or naughty.notifications[s][position][idx].width @@ -290,6 +295,7 @@ end 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 p in pairs(naughty.notifications[s]) do for _, notification in pairs(naughty.notifications[s][p]) do if notification.id == id then @@ -386,7 +392,7 @@ end -- @int[opt=5] args.timeout Time in seconds after which popup expires. -- Set 0 for no timeout. -- @int[opt] args.hover_timeout Delay in seconds after which hovered popup disappears. --- @int[opt=focused] args.screen Target screen for the notification. +-- @tparam[opt=focused] integer|screen args.screen Target screen for the notification. -- @string[opt="top_right"] args.position Corner of the workarea displaying the popups. -- Values: `"top_right"`, `"top_left"`, `"bottom_left"`, -- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`. @@ -431,7 +437,7 @@ function naughty.notify(args) local icon_size = args.icon_size or preset.icon_size local text = args.text or preset.text local title = args.title or preset.title - local s = args.screen or preset.screen or screen.focused() + local s = get_screen(args.screen or preset.screen or screen.focused()) local ontop = args.ontop or preset.ontop local width = args.width or preset.width local height = args.height or preset.height @@ -609,7 +615,7 @@ function naughty.notify(args) height = height + actions_total_height -- crop to workarea size if too big - local workarea = capi.screen[s].workarea + local workarea = s.workarea if width > workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0) then width = workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0) end diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index 59bce59f..64111ec4 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -10,7 +10,8 @@ local drawable = {} local capi = { awesome = awesome, - root = root + root = root, + screen = screen } local beautiful = require("beautiful") local cairo = require("lgi").cairo @@ -32,10 +33,10 @@ local function screen_getbycoord(x, y) 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 - return i + return capi.screen[i] end end - return 1 + return capi.screen[1] end -- Get the widget context. This should always return the same table (if diff --git a/lib/wibox/widget/textbox.lua b/lib/wibox/widget/textbox.lua index 1159359a..89bcfc0c 100644 --- a/lib/wibox/widget/textbox.lua +++ b/lib/wibox/widget/textbox.lua @@ -66,7 +66,7 @@ end --- Get the preferred size of a textbox. -- This returns the size that the textbox would use if infinite space were -- available. --- @tparam integer s The screen number on which the textbox will be displayed. +-- @tparam integer|screen s The screen on which the textbox will be displayed. -- @treturn number The preferred width. -- @treturn number The preferred height. function textbox:get_preferred_size(s) @@ -77,7 +77,7 @@ end -- This returns the height that the textbox would use when it is limited to the -- given width. -- @tparam number width The available width. --- @tparam integer s The screen number on which the textbox will be displayed. +-- @tparam integer|screen s The screen on which the textbox will be displayed. -- @treturn number The needed height. function textbox:get_height_for_width(width, s) return self:get_height_for_width_at_dpi(width, beautiful.xresources.get_dpi(s))