Merge pull request #708 from psychon/less_screen_indicies2

Less screen indicies
This commit is contained in:
Daniel Hahler 2016-02-28 22:15:37 +01:00
commit 2bcff5af27
17 changed files with 201 additions and 121 deletions

View File

@ -21,7 +21,7 @@ local timer = require("gears.timer")
local function check_focus(obj) local function check_focus(obj)
-- When no visible client has the focus... -- When no visible client has the focus...
if not client.focus or not client.focus:isvisible() then 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 if c then
c:emit_signal("request::activate", "autofocus.check_focus", c:emit_signal("request::activate", "autofocus.check_focus",
{raise=false}) {raise=false})
@ -41,8 +41,9 @@ end
local function check_focus_tag(t) local function check_focus_tag(t)
local s = atag.getscreen(t) local s = atag.getscreen(t)
if not s then return end if not s then return end
s = screen[s]
check_focus({ 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) local c = aclient.focus.history.get(s, 0, aclient.focus.filter)
if c then if c then
c:emit_signal("request::activate", "autofocus.check_focus_tag", c:emit_signal("request::activate", "autofocus.check_focus_tag",

View File

@ -25,6 +25,10 @@ local capi =
awesome = awesome, awesome = awesome,
} }
local function get_screen(s)
return s and capi.screen[s]
end
-- We use a metatable to prevent circular dependency loops. -- We use a metatable to prevent circular dependency loops.
local screen local screen
do do
@ -63,9 +67,9 @@ client.shape = require("awful.client.shape")
-- @client c the client to jump to -- @client c the client to jump to
-- @tparam bool merge If true then merge tags when clients are not visible. -- @tparam bool merge If true then merge tags when clients are not visible.
function client.jumpto(c, merge) function client.jumpto(c, merge)
local s = screen.focused() local s = get_screen(screen.focused())
-- focus the screen -- focus the screen
if s ~= c.screen then if s ~= get_screen(c.screen) then
screen.focus(c.screen) screen.focus(c.screen)
end end
@ -171,7 +175,7 @@ end
--- Get the latest focused client for a screen in history. --- 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, -- @tparam int idx The index: 0 will return first candidate,
-- 1 will return second, etc. -- 1 will return second, etc.
-- @tparam function filter An optional filter. If no client is found in the -- @tparam function filter An optional filter. If no client is found in the
@ -179,11 +183,12 @@ end
-- client. -- client.
-- @treturn client.object A client. -- @treturn client.object A client.
function client.focus.history.get(s, idx, filter) function client.focus.history.get(s, idx, filter)
s = get_screen(s)
-- When this counter is equal to idx, we return the client -- When this counter is equal to idx, we return the client
local counter = 0 local counter = 0
local vc = client.visible(s, true) local vc = client.visible(s, true)
for _, c in ipairs(client.data.focus) do 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 if not filter or filter(c) then
for _, vcc in ipairs(vc) do for _, vcc in ipairs(vc) do
if vcc == c then if vcc == c then
@ -223,7 +228,7 @@ end
--- Get visible clients from a screen. --- 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) -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
-- @treturn table A table with all visible clients. -- @treturn table A table with all visible clients.
function client.visible(s, stacked) function client.visible(s, stacked)
@ -239,7 +244,7 @@ end
--- Get visible and tiled clients --- 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) -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
-- @treturn table A table with all visible and tiled clients. -- @treturn table A table with all visible and tiled clients.
function client.tiled(s, stacked) function client.tiled(s, stacked)
@ -325,7 +330,7 @@ end
-- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom)
function client.focus.global_bydirection(dir, c, stacked) function client.focus.global_bydirection(dir, c, stacked)
local sel = c or capi.client.focus 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 -- change focus inside the screen
client.focus.bydirection(dir, sel) 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 focus not changed, we must change screen
if sel == capi.client.focus then if sel == capi.client.focus then
screen.focus_bydirection(dir, scr) 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 cltbl = client.visible(screen.focused(), stacked)
local geomtbl = {} local geomtbl = {}
for i,cl in ipairs(cltbl) do for i,cl in ipairs(cltbl) do
geomtbl[i] = cl:geometry() geomtbl[i] = cl:geometry()
end 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 if target then
cltbl[target]:emit_signal("request::activate", cltbl[target]:emit_signal("request::activate",
@ -388,7 +393,7 @@ end
-- @client[opt] sel The client. -- @client[opt] sel The client.
function client.swap.global_bydirection(dir, sel) function client.swap.global_bydirection(dir, sel)
sel = sel or capi.client.focus 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 if sel then
-- move focus -- move focus
@ -396,15 +401,15 @@ function client.swap.global_bydirection(dir, sel)
local c = capi.client.focus local c = capi.client.focus
-- swapping inside a screen -- 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) c:swap(sel)
-- swapping to an empty screen -- 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()) client.movetoscreen(sel, screen.focused())
-- swapping to a nonempty screen -- 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(sel, c.screen)
client.movetoscreen(c, scr) client.movetoscreen(c, scr)
end end
@ -515,7 +520,7 @@ end
function client.toggletag(target, c) function client.toggletag(target, c)
local sel = c or capi.client.focus local sel = c or capi.client.focus
-- Check that tag and client screen are identical -- 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 tags = sel:tags()
local index = nil; local index = nil;
for i, v in ipairs(tags) do for i, v in ipairs(tags) do
@ -537,7 +542,7 @@ end
--- Move a client to a screen. Default is next screen, cycling. --- Move a client to a screen. Default is next screen, cycling.
-- @client c The client to move. -- @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) function client.movetoscreen(c, s)
local sel = c or capi.client.focus local sel = c or capi.client.focus
if sel then if sel then
@ -545,8 +550,9 @@ function client.movetoscreen(c, s)
if not s then if not s then
s = sel.screen + 1 s = sel.screen + 1
end end
if s > sc then s = 1 elseif s < 1 then s = sc end if type(s) == "number" and s > sc then s = 1 elseif s < 1 then s = sc end
if sel.screen ~= s then s = get_screen(s)
if get_screen(sel.screen) ~= s then
local sel_is_focused = sel == capi.client.focus local sel_is_focused = sel == capi.client.focus
sel.screen = s sel.screen = s
screen.focus(s) screen.focus(s)

View File

@ -23,6 +23,10 @@ local tag = require("awful.tag")
local client = require("awful.client") local client = require("awful.client")
local timer = require("gears.timer") local timer = require("gears.timer")
local function get_screen(s)
return s and capi.screen[s]
end
local layout = {} local layout = {}
--- Default predefined layouts --- Default predefined layouts
@ -57,7 +61,7 @@ local arrange_lock = false
local delayed_arrange = {} local delayed_arrange = {}
--- Get the current layout. --- Get the current layout.
-- @param screen The screen number. -- @param screen The screen.
-- @return The layout function. -- @return The layout function.
function layout.get(screen) function layout.get(screen)
local t = tag.selected(screen) local t = tag.selected(screen)
@ -66,7 +70,7 @@ end
--- Change the layout of the current tag. --- Change the layout of the current tag.
-- @param i Relative index. -- @param i Relative index.
-- @param s The screen number. -- @param s The screen.
-- @param[opt] layouts A table of layouts. -- @param[opt] layouts A table of layouts.
function layout.inc(i, s, layouts) function layout.inc(i, s, layouts)
if type(i) == "table" then 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 -- this was changed so that 'layouts' can be an optional parameter
layouts, i, s = i, s, layouts layouts, i, s = i, s, layouts
end end
s = get_screen(s)
local t = tag.selected(s) local t = tag.selected(s)
layouts = layouts or layout.layouts layouts = layouts or layout.layouts
if t then if t then
@ -124,20 +129,21 @@ end
-- geometry (x, y, width, height), the clients, the screen and sometime, a -- geometry (x, y, width, height), the clients, the screen and sometime, a
-- "geometries" table with client as keys and geometry as value -- "geometries" table with client as keys and geometry as value
function layout.parameters(t, screen) function layout.parameters(t, screen)
screen = get_screen(screen)
t = t or tag.selected(screen) t = t or tag.selected(screen)
if not t then return end if not t then return end
screen = tag.getscreen(t) or 1 screen = get_screen(tag.getscreen(t) or 1)
local p = {} local p = {}
p.workarea = capi.screen[screen].workarea p.workarea = screen.workarea
local useless_gap = tag.getgap(t, #client.tiled(screen)) local useless_gap = tag.getgap(t, #client.tiled(screen))
-- Handle padding -- 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 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) + p.workarea.height = p.workarea.height - ((padding.top or 0) +
(padding.bottom or 0) + useless_gap * 2) (padding.bottom or 0) + useless_gap * 2)
p.geometry = capi.screen[screen].geometry p.geometry = screen.geometry
p.clients = client.tiled(screen) p.clients = client.tiled(screen)
p.screen = screen p.screen = screen.index
p.padding = padding p.padding = padding
p.useless_gap = useless_gap p.useless_gap = useless_gap
@ -161,6 +167,7 @@ end
--- Arrange a screen using its current layout. --- Arrange a screen using its current layout.
-- @param screen The screen to arrange. -- @param screen The screen to arrange.
function layout.arrange(screen) function layout.arrange(screen)
screen = get_screen(screen)
if not screen or delayed_arrange[screen] then return end if not screen or delayed_arrange[screen] then return end
delayed_arrange[screen] = true delayed_arrange[screen] = true
@ -181,7 +188,7 @@ function layout.arrange(screen)
g.y = g.y + useless_gap g.y = g.y + useless_gap
c:geometry(g) c:geometry(g)
end end
capi.screen[screen]:emit_signal("arrange") screen:emit_signal("arrange")
arrange_lock = false arrange_lock = false
delayed_arrange[screen] = nil delayed_arrange[screen] = nil
@ -235,10 +242,10 @@ capi.tag.connect_signal("tagged", arrange_tag)
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
capi.screen[s]:connect_signal("property::workarea", function(screen) capi.screen[s]:connect_signal("property::workarea", function(screen)
layout.arrange(screen.index) layout.arrange(screen)
end) end)
capi.screen[s]:connect_signal("padding", function (screen) capi.screen[s]:connect_signal("padding", function (screen)
layout.arrange(screen.index) layout.arrange(screen)
end) end)
end end

View File

@ -120,8 +120,8 @@ local function item_position(_menu, child)
end end
local function set_coords(_menu, screen_idx, m_coords) local function set_coords(_menu, s, m_coords)
local s_geometry = capi.screen[screen_idx].workarea local s_geometry = s.workarea
local screen_w = s_geometry.x + s_geometry.width local screen_w = s_geometry.x + s_geometry.width
local screen_h = s_geometry.y + s_geometry.height local screen_h = s_geometry.y + s_geometry.height
@ -313,10 +313,10 @@ end
function menu:show(args) function menu:show(args)
args = args or {} args = args or {}
local coords = args.coords or nil 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 if not set_size(self) then return end
set_coords(self, screen_index, coords) set_coords(self, s, coords)
keygrabber.run(self._keygrabber) keygrabber.run(self._keygrabber)
self.wibox.visible = true self.wibox.visible = true

View File

@ -23,6 +23,10 @@ local layout = require("awful.layout")
local a_screen = require("awful.screen") local a_screen = require("awful.screen")
local dpi = require("beautiful").xresources.apply_dpi local dpi = require("beautiful").xresources.apply_dpi
local function get_screen(s)
return s and capi.screen[s]
end
local placement = {} local placement = {}
--- Check if an area intersect another area. --- Check if an area intersect another area.
@ -121,8 +125,8 @@ end
function placement.no_offscreen(c, screen) function placement.no_offscreen(c, screen)
c = c or capi.client.focus c = c or capi.client.focus
local geometry = get_area(c) local geometry = get_area(c)
screen = screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y) screen = get_screen(screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y))
local screen_geometry = capi.screen[screen].workarea local screen_geometry = screen.workarea
if geometry.x + geometry.width > screen_geometry.x + screen_geometry.width then if geometry.x + geometry.width > screen_geometry.x + screen_geometry.width then
geometry.x = screen_geometry.x + screen_geometry.width - geometry.width geometry.x = screen_geometry.x + screen_geometry.width - geometry.width
@ -145,10 +149,10 @@ end
-- @param c The client. -- @param c The client.
function placement.no_overlap(c) function placement.no_overlap(c)
local geometry = get_area(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 cls = client.visible(screen)
local curlay = layout.get() local curlay = layout.get()
local areas = { capi.screen[screen].workarea } local areas = { screen.workarea }
for _, cl in pairs(cls) do for _, cl in pairs(cls) do
if cl ~= c and cl.type ~= "desktop" and (client.floating.get(cl) or curlay == layout.suit.floating) then 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)) areas = area_remove(areas, get_area(cl))
@ -249,12 +253,12 @@ end
function placement.centered(c, p) function placement.centered(c, p)
c = c or capi.client.focus c = c or capi.client.focus
local c_geometry = get_area(c) 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 local s_geometry
if p then if p then
s_geometry = get_area(p) s_geometry = get_area(p)
else else
s_geometry = capi.screen[screen].geometry s_geometry = screen.geometry
end end
return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2, 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 }) y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 })
@ -267,12 +271,12 @@ end
function placement.center_horizontal(c, p) function placement.center_horizontal(c, p)
c = c or capi.client.focus c = c or capi.client.focus
local c_geometry = get_area(c) 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 local s_geometry
if p then if p then
s_geometry = get_area(p) s_geometry = get_area(p)
else else
s_geometry = capi.screen[screen].geometry s_geometry = screen.geometry
end end
return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 }) return c:geometry({ x = s_geometry.x + (s_geometry.width - c_geometry.width) / 2 })
end end
@ -284,12 +288,12 @@ end
function placement.center_vertical(c, p) function placement.center_vertical(c, p)
c = c or capi.client.focus c = c or capi.client.focus
local c_geometry = get_area(c) 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 local s_geometry
if p then if p then
s_geometry = get_area(p) s_geometry = get_area(p)
else else
s_geometry = capi.screen[screen].geometry s_geometry = screen.geometry
end end
return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 }) return c:geometry({ y = s_geometry.y + (s_geometry.height - c_geometry.height) / 2 })
end end

View File

@ -16,6 +16,10 @@ local capi =
} }
local util = require("awful.util") 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. -- we use require("awful.client") inside functions to prevent circular dependencies.
local client local client
@ -26,12 +30,13 @@ data.padding = {}
screen.mouse_per_screen = {} screen.mouse_per_screen = {}
-- @param s Screen number -- @param s Screen
-- @param x X coordinate of point -- @param x X coordinate of point
-- @param y Y coordinate of point -- @param y Y coordinate of point
-- @return The squared distance of the screen to the provided point -- @return The squared distance of the screen to the provided point
function screen.getdistance_sq(s, x, y) 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 local dist_x, dist_y = 0, 0
if x < geom.x then if x < geom.x then
dist_x = geom.x - x dist_x = geom.x - x
@ -47,21 +52,21 @@ function screen.getdistance_sq(s, x, y)
end 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 -- The number returned can be used as an index into the global
-- `screen` table/object. -- `screen` table/object.
-- @param x The x coordinate -- @param x The x coordinate
-- @param y The y coordinate -- @param y The y coordinate
function screen.getbycoord(x, y) function screen.getbycoord(x, y)
local s = 1 local s = screen[1]
local dist = screen.getdistance_sq(s, x, y) local dist = screen.getdistance_sq(s, x, y)
for i = 2, capi.screen:count() do for i = 2, capi.screen:count() do
local d = screen.getdistance_sq(i, x, y) local d = screen.getdistance_sq(i, x, y)
if d < dist then if d < dist then
s, dist = i, d s, dist = screen[i], d
end end
end end
return s return s.index
end end
--- Give the focus to a screen, and move pointer to last known position on this --- 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). -- @param _screen Screen number (defaults / falls back to mouse.screen).
function screen.focus(_screen) function screen.focus(_screen)
client = client or require("awful.client") 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 -- screen and pos for current screen
local s = capi.mouse.screen local s = get_screen(capi.mouse.screen)
local pos local pos
if not screen.mouse_per_screen[_screen] then if not screen.mouse_per_screen[_screen] then
-- This is the first time we enter this screen, -- This is the first time we enter this screen,
-- keep relative mouse position on the new screen -- keep relative mouse position on the new screen
pos = capi.mouse.coords() pos = capi.mouse.coords()
local relx = (pos.x - capi.screen[s].geometry.x) / capi.screen[s].geometry.width local relx = (pos.x - s.geometry.x) / s.geometry.width
local rely = (pos.y - capi.screen[s].geometry.y) / capi.screen[s].geometry.height local rely = (pos.y - s.geometry.y) / s.geometry.height
pos.x = capi.screen[_screen].geometry.x + relx * capi.screen[_screen].geometry.width pos.x = _screen.geometry.x + relx * _screen.geometry.width
pos.y = capi.screen[_screen].geometry.y + rely * capi.screen[_screen].geometry.height pos.y = _screen.geometry.y + rely * _screen.geometry.height
else else
-- restore mouse position -- restore mouse position
pos = screen.mouse_per_screen[_screen] 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 --- 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 -- screen, or keep position relative to the current focused screen
-- @param dir The direction, can be either "up", "down", "left" or "right". -- @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) function screen.focus_bydirection(dir, _screen)
local sel = _screen or screen.focused() local sel = get_screen(_screen or screen.focused())
if sel then if sel then
local geomtbl = {} local geomtbl = {}
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
geomtbl[s] = capi.screen[s].geometry geomtbl[s] = capi.screen[s].geometry
end 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 if target then
return screen.focus(target) return screen.focus(target)
end end
@ -132,6 +138,7 @@ end
-- @param padding The padding, an table with 'top', 'left', 'right' and/or -- @param padding The padding, an table with 'top', 'left', 'right' and/or
-- 'bottom'. Can be nil if you only want to retrieve padding -- 'bottom'. Can be nil if you only want to retrieve padding
function screen.padding(_screen, padding) function screen.padding(_screen, padding)
_screen = get_screen(_screen)
if padding then if padding then
data.padding[_screen] = padding data.padding[_screen] = padding
_screen:emit_signal("padding") _screen:emit_signal("padding")

View File

@ -24,6 +24,10 @@ local capi =
root = root 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. -- we use require("awful.client") inside functions to prevent circular dependencies.
local client local client
@ -45,7 +49,7 @@ tag.history.limit = 20
-- selected tag is used. -- selected tag is used.
function tag.move(new_index, target_tag) function tag.move(new_index, target_tag)
target_tag = target_tag or tag.selected() 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) local tmp_tags = tag.gettags(scr)
if (not new_index) or (new_index < 1) or (new_index > #tmp_tags) then 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. -- 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 -- set properties cannot be used as this has to be set before the first
-- signal is sent -- signal is sent
properties.screen = properties.screen or ascreen.focused() properties.screen = get_screen(properties.screen or ascreen.focused())
-- Index is also required -- Index is also required
properties.index = (#tag.gettags(properties.screen))+1 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. -- @param layout The layout or layout table to set for this tags by default.
-- @return A table with all created tags. -- @return A table with all created tags.
function tag.new(names, screen, layout) function tag.new(names, screen, layout)
screen = screen or 1 screen = get_screen(screen or 1)
local tags = {} local tags = {}
for id, name in ipairs(names) do for id, name in ipairs(names) do
table.insert(tags, id, tag.add(name, {screen = screen, table.insert(tags, id, tag.add(name, {screen = screen,
@ -135,7 +139,7 @@ function tag.new(names, screen, layout)
end end
--- Find a suitable fallback tag. --- 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)] -- @param invalids A table of tags we consider unacceptable. [selectedlist(scr)]
function tag.find_fallback(screen, invalids) function tag.find_fallback(screen, invalids)
local scr = screen or ascreen.focused() local scr = screen or ascreen.focused()
@ -159,7 +163,7 @@ function tag.delete(target_tag, fallback_tag)
target_tag = target_tag or tag.selected() target_tag = target_tag or tag.selected()
if target_tag == nil or target_tag.activated == false then return end 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 tags = tag.gettags(target_scr)
local idx = tag.getidx(target_tag) local idx = tag.getidx(target_tag)
local ntags = #tags local ntags = #tags
@ -214,7 +218,7 @@ end
--- Update the tag history. --- Update the tag history.
-- @param obj Screen object. -- @param obj Screen object.
function tag.history.update(obj) function tag.history.update(obj)
local s = obj.index local s = get_screen(obj)
local curtags = tag.selectedlist(s) local curtags = tag.selectedlist(s)
-- create history table -- create history table
if not data.history[s] then if not data.history[s] then
@ -252,12 +256,12 @@ function tag.history.update(obj)
end end
--- Revert tag history. --- 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 -- @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 -- toggling between last two selected sets of tags. Number (eg 1) will go back
-- to the given index in history. -- to the given index in history.
function tag.history.restore(screen, idx) 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 i = idx or "previous"
local sel = tag.selectedlist(s) local sel = tag.selectedlist(s)
-- do nothing if history empty -- do nothing if history empty
@ -281,16 +285,17 @@ function tag.history.restore(screen, idx)
-- remove the reverted history entry -- remove the reverted history entry
if i ~= "previous" then table.remove(data.history[s], i) end 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 end
--- Get a list of all tags on a screen --- Get a list of all tags on a screen
-- @param s Screen number -- @param s Screen
-- @return A table with all available tags -- @return A table with all available tags
function tag.gettags(s) function tag.gettags(s)
s = get_screen(s)
local tags = {} local tags = {}
for _, t in ipairs(root.tags()) do 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) table.insert(tags, t)
end end
end end
@ -302,7 +307,7 @@ function tag.gettags(s)
end end
--- Set a tag's screen --- Set a tag's screen
-- @param s Screen number -- @param s Screen
-- @param t tag object -- @param t tag object
function tag.setscreen(s, t) function tag.setscreen(s, t)
@ -312,7 +317,7 @@ function tag.setscreen(s, t)
s, t = t, s s, t = t, s
end end
s = s or ascreen.focused() s = get_screen(s or ascreen.focused())
local sel = tag.selected local sel = tag.selected
local old_screen = tag.getproperty(t, "screen") local old_screen = tag.getproperty(t, "screen")
if s == old_screen then return end if s == old_screen then return end
@ -347,11 +352,12 @@ end
-- @return Screen number -- @return Screen number
function tag.getscreen(t) function tag.getscreen(t)
t = t or tag.selected() t = t or tag.selected()
return tag.getproperty(t, "screen") local prop = tag.getproperty(t, "screen")
return prop and prop.index
end end
--- Return a table with all visible tags --- Return a table with all visible tags
-- @param s Screen number. -- @param s Screen.
-- @return A table with all selected tags. -- @return A table with all selected tags.
function tag.selectedlist(s) function tag.selectedlist(s)
local screen = s or ascreen.focused() local screen = s or ascreen.focused()
@ -366,7 +372,7 @@ function tag.selectedlist(s)
end end
--- Return only the first visible tag. --- Return only the first visible tag.
-- @param s Screen number. -- @param s Screen.
function tag.selected(s) function tag.selected(s)
return tag.selectedlist(s)[1] return tag.selectedlist(s)[1]
end end
@ -517,7 +523,8 @@ end
function tag.incnmaster(add, t, sensible) function tag.incnmaster(add, t, sensible)
if sensible then if sensible then
client = client or require("awful.client") 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 nmaster = tag.getnmaster(t)
if nmaster > ntiled then if nmaster > ntiled then
@ -575,7 +582,8 @@ end
function tag.incncol(add, t, sensible) function tag.incncol(add, t, sensible)
if sensible then if sensible then
client = client or require("awful.client") 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 nmaster = tag.getnmaster(t)
local nsecondary = ntiled - nmaster local nsecondary = ntiled - nmaster
@ -595,7 +603,7 @@ function tag.incncol(add, t, sensible)
end end
--- View no tag. --- View no tag.
-- @tparam[opt] int screen The screen number. -- @tparam[opt] int|screen screen The screen.
function tag.viewnone(screen) function tag.viewnone(screen)
local tags = tag.gettags(screen or ascreen.focused()) local tags = tag.gettags(screen or ascreen.focused())
for _, t in pairs(tags) do for _, t in pairs(tags) do
@ -605,9 +613,9 @@ end
--- View a tag by its taglist index. --- View a tag by its taglist index.
-- @param i The relative index to see. -- @param i The relative index to see.
-- @param[opt] screen The screen number. -- @param[opt] screen The screen.
function tag.viewidx(i, screen) function tag.viewidx(i, screen)
screen = screen or ascreen.focused() screen = get_screen(screen or ascreen.focused())
local tags = tag.gettags(screen) local tags = tag.gettags(screen)
local showntags = {} local showntags = {}
for _, t in ipairs(tags) do for _, t in ipairs(tags) do
@ -622,7 +630,7 @@ function tag.viewidx(i, screen)
showntags[util.cycle(#showntags, k + i)].selected = true showntags[util.cycle(#showntags, k + i)].selected = true
end end
end end
capi.screen[screen]:emit_signal("tag::history::update") screen:emit_signal("tag::history::update")
end end
--- Get a tag's index in the gettags() table. --- Get a tag's index in the gettags() table.
@ -640,13 +648,13 @@ function tag.getidx(query_tag)
end end
--- View next tag. This is the same as tag.viewidx(1). --- View next tag. This is the same as tag.viewidx(1).
-- @param screen The screen number. -- @param screen The screen.
function tag.viewnext(screen) function tag.viewnext(screen)
return tag.viewidx(1, screen) return tag.viewidx(1, screen)
end end
--- View previous tag. This is the same a tag.viewidx(-1). --- View previous tag. This is the same a tag.viewidx(-1).
-- @param screen The screen number. -- @param screen The screen.
function tag.viewprev(screen) function tag.viewprev(screen)
return tag.viewidx(-1, screen) return tag.viewidx(-1, screen)
end end
@ -670,9 +678,9 @@ end
--- View only a set of tags. --- View only a set of tags.
-- @param tags A table with tags to view only. -- @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) function tag.viewmore(tags, screen)
screen = screen or ascreen.focused() screen = get_screen(screen or ascreen.focused())
local screen_tags = tag.gettags(screen) local screen_tags = tag.gettags(screen)
for _, _tag in ipairs(screen_tags) do for _, _tag in ipairs(screen_tags) do
if not util.table.hasitem(tags, _tag) then if not util.table.hasitem(tags, _tag) then
@ -682,7 +690,7 @@ function tag.viewmore(tags, screen)
for _, _tag in ipairs(tags) do for _, _tag in ipairs(tags) do
_tag.selected = true _tag.selected = true
end end
capi.screen[screen]:emit_signal("tag::history::update") screen:emit_signal("tag::history::update")
end end
--- Toggle selection of a tag --- Toggle selection of a tag
@ -736,7 +744,7 @@ end
function tag.withcurrent(c) function tag.withcurrent(c)
local tags = {} local tags = {}
for _, t in ipairs(c:tags()) do 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) table.insert(tags, t)
end end
end end
@ -752,8 +760,9 @@ function tag.withcurrent(c)
end end
local function attached_connect_signal_screen(screen, sig, func) local function attached_connect_signal_screen(screen, sig, func)
screen = get_screen(screen)
capi.tag.connect_signal(sig, function(_tag) capi.tag.connect_signal(sig, function(_tag)
if tag.getscreen(_tag) == screen then if get_screen(tag.getscreen(_tag)) == screen then
func(_tag) func(_tag)
end end
end) end)

View File

@ -25,6 +25,10 @@ local wibox = require("wibox")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local round = require("awful.util").round local round = require("awful.util").round
local function get_screen(s)
return s and screen[s]
end
local awfulwibox = { mt = {} } local awfulwibox = { mt = {} }
--- Array of table with wiboxes inside. --- 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 -- @param screen If the wibox it not attached to a screen, specified on which
-- screen the position should be set. -- screen the position should be set.
function awfulwibox.set_position(wb, position, screen) 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 -- The "length" of a wibox is always chosen to be the optimal size
-- (non-floating). -- (non-floating).
@ -107,8 +111,9 @@ end
-- will be attached. -- will be attached.
-- @param wb The wibox to attach. -- @param wb The wibox to attach.
-- @param position The position of the wibox: top, bottom, left or right. -- @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) function awfulwibox.attach(wb, position, screen)
screen = get_screen(screen)
-- Store wibox as attached in a weak-valued table -- Store wibox as attached in a weak-valued table
local wibox_prop_table local wibox_prop_table
-- Start from end since we sometimes remove items -- Start from end since we sometimes remove items
@ -144,10 +149,11 @@ end
-- @param wb The wibox. -- @param wb The wibox.
-- @param align The alignment: left, right or center. -- @param align The alignment: left, right or center.
-- @param screen If the wibox is not attached to any screen, you can specify the -- @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) function awfulwibox.align(wb, align, screen)
screen = get_screen(screen)
local position = awfulwibox.get_position(wb) local position = awfulwibox.get_position(wb)
local area = capi.screen[screen].workarea local area = screen.workarea
if position == "right" then if position == "right" then
if align == "right" then if align == "right" then
@ -192,8 +198,9 @@ end
-- @param screen The screen to stretch on, or the wibox screen. -- @param screen The screen to stretch on, or the wibox screen.
function awfulwibox.stretch(wb, screen) function awfulwibox.stretch(wb, screen)
if screen then if screen then
screen = get_screen(screen)
local position = awfulwibox.get_position(wb) local position = awfulwibox.get_position(wb)
local area = capi.screen[screen].workarea local area = screen.workarea
if position == "right" or position == "left" then if position == "right" or position == "left" then
wb.height = area.height - (2 * wb.border_width) wb.height = area.height - (2 * wb.border_width)
wb.y = area.y wb.y = area.y
@ -216,7 +223,7 @@ function awfulwibox.new(arg)
arg = arg or {} arg = arg or {}
local position = arg.position or "top" local position = arg.position or "top"
local has_to_stretch = true 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" arg.type = arg.type or "dock"
@ -234,7 +241,7 @@ function awfulwibox.new(arg)
if arg.screen then if arg.screen then
local hp = tostring(arg.height):match("(%d+)%%") local hp = tostring(arg.height):match("(%d+)%%")
if hp then 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 end
end end
@ -245,7 +252,7 @@ function awfulwibox.new(arg)
if arg.screen then if arg.screen then
local wp = tostring(arg.width):match("(%d+)%%") local wp = tostring(arg.width):match("(%d+)%%")
if wp then 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 end
end end

View File

@ -8,24 +8,30 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local setmetatable = setmetatable local setmetatable = setmetatable
local capi = { screen = screen }
local layout = require("awful.layout") local layout = require("awful.layout")
local tooltip = require("awful.tooltip") local tooltip = require("awful.tooltip")
local tag = require("awful.tag") local tag = require("awful.tag")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local imagebox = require("wibox.widget.imagebox") local imagebox = require("wibox.widget.imagebox")
local function get_screen(s)
return s and capi.screen[s]
end
local layoutbox = { mt = {} } local layoutbox = { mt = {} }
local boxes = nil local boxes = nil
local function update(w, screen) local function update(w, screen)
screen = get_screen(screen)
local name = layout.getname(layout.get(screen)) local name = layout.getname(layout.get(screen))
w._layoutbox_tooltip:set_text(name or "[no name]") w._layoutbox_tooltip:set_text(name or "[no name]")
w:set_image(name and beautiful["layout_" .. name]) w:set_image(name and beautiful["layout_" .. name])
end end
local function update_from_tag(t) local function update_from_tag(t)
local screen = tag.getscreen(t) local screen = get_screen(tag.getscreen(t))
local w = boxes[screen] local w = boxes[screen]
if w then if w then
update(w, screen) update(w, screen)
@ -37,7 +43,7 @@ end
-- @param screen The screen number that the layout will be represented for. -- @param screen The screen number that the layout will be represented for.
-- @return An imagebox widget configured as a layoutbox. -- @return An imagebox widget configured as a layoutbox.
function layoutbox.new(screen) function layoutbox.new(screen)
screen = screen or 1 screen = get_screen(screen or 1)
-- Do we already have the update callbacks registered? -- Do we already have the update callbacks registered?
if boxes == nil then if boxes == nil then

View File

@ -23,6 +23,10 @@ local fixed = require("wibox.layout.fixed")
local surface = require("gears.surface") local surface = require("gears.surface")
local timer = require("gears.timer") local timer = require("gears.timer")
local function get_screen(s)
return s and capi.screen[s]
end
local taglist = { mt = {} } local taglist = { mt = {} }
taglist.filter = {} taglist.filter = {}
@ -153,6 +157,7 @@ end
-- @param[opt] base_widget.squares_resize True or false to resize squares. -- @param[opt] base_widget.squares_resize True or false to resize squares.
-- @param base_widget.font The font. -- @param base_widget.font The font.
function taglist.new(screen, filter, buttons, style, update_function, base_widget) function taglist.new(screen, filter, buttons, style, update_function, base_widget)
screen = get_screen(screen)
local uf = update_function or common.list_update local uf = update_function or common.list_update
local w = base_widget or fixed.horizontal() 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 if instances == nil then
instances = {} instances = {}
local function u(s) local function u(s)
local i = instances[s] local i = instances[get_screen(s)]
if i then if i then
for _, tlist in pairs(i) do for _, tlist in pairs(i) do
tlist._do_taglist_update() tlist._do_taglist_update()

View File

@ -21,6 +21,10 @@ local tag = require("awful.tag")
local flex = require("wibox.layout.flex") local flex = require("wibox.layout.flex")
local timer = require("gears.timer") local timer = require("gears.timer")
local function get_screen(s)
return s and screen[s]
end
local tasklist = { mt = {} } local tasklist = { mt = {} }
local instances 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.maximized_vertical Symbol to use for clients that have been vertically maximized.
-- @param base_widget.font The font. -- @param base_widget.font The font.
function tasklist.new(screen, filter, buttons, style, update_function, base_widget) function tasklist.new(screen, filter, buttons, style, update_function, base_widget)
screen = get_screen(screen)
local uf = update_function or common.list_update local uf = update_function or common.list_update
local w = base_widget or flex.horizontal() 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 if instances == nil then
instances = {} instances = {}
local function us(s) local function us(s)
local i = instances[s] local i = instances[get_screen(s)]
if i then if i then
for _, tlist in pairs(i) do for _, tlist in pairs(i) do
tlist._do_tasklist_update() tlist._do_tasklist_update()
@ -256,7 +261,7 @@ end
-- @return true if c is on screen, false otherwise -- @return true if c is on screen, false otherwise
function tasklist.filter.alltags(c, screen) function tasklist.filter.alltags(c, screen)
-- Only print client on the same screen as this widget -- Only print client on the same screen as this widget
return c.screen == screen return get_screen(c.screen) == get_screen(screen)
end end
--- Filtering function to include only the clients from currently selected tags. --- Filtering function to include only the clients from currently selected tags.
@ -264,8 +269,9 @@ end
-- @param screen The screen we are drawing on. -- @param screen The screen we are drawing on.
-- @return true if c is in a selected tag on screen, false otherwise -- @return true if c is in a selected tag on screen, false otherwise
function tasklist.filter.currenttags(c, screen) function tasklist.filter.currenttags(c, screen)
screen = get_screen(screen)
-- Only print client on the same screen as this widget -- 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 -- Include sticky client too
if c.sticky then return true end if c.sticky then return true end
local tags = tag.gettags(screen) local tags = tag.gettags(screen)
@ -287,8 +293,9 @@ end
-- @param screen The screen we are drawing on. -- @param screen The screen we are drawing on.
-- @return true if c is in a selected tag on screen and is minimized, false otherwise -- @return true if c is in a selected tag on screen and is minimized, false otherwise
function tasklist.filter.minimizedcurrenttags(c, screen) function tasklist.filter.minimizedcurrenttags(c, screen)
screen = get_screen(screen)
-- Only print client on the same screen as this widget -- 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 -- Check client is minimized
if not c.minimized then return false end if not c.minimized then return false end
-- Include sticky client -- Include sticky client
@ -314,7 +321,7 @@ end
-- @return true if c is focused on screen, false otherwise -- @return true if c is focused on screen, false otherwise
function tasklist.filter.focused(c, screen) function tasklist.filter.focused(c, screen)
-- Only print client on the same screen as this widget -- 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 end
function tasklist.mt:__call(...) function tasklist.mt:__call(...)

View File

@ -9,6 +9,7 @@
-- Grab environment -- Grab environment
local awesome = awesome local awesome = awesome
local screen = screen
local round = require("awful.util").round local round = require("awful.util").round
local gears_debug = require("gears.debug") local gears_debug = require("gears.debug")
@ -66,10 +67,15 @@ end
local dpi_per_screen = {} 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. --- 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. -- @treturn number DPI value.
function xresources.get_dpi(s) function xresources.get_dpi(s)
s = get_screen(s)
if dpi_per_screen[s] then if dpi_per_screen[s] then
return dpi_per_screen[s] return dpi_per_screen[s]
end end
@ -90,6 +96,7 @@ end
-- @tparam number dpi DPI value. -- @tparam number dpi DPI value.
-- @tparam[opt] integer s Screen. -- @tparam[opt] integer s Screen.
function xresources.set_dpi(dpi, s) function xresources.set_dpi(dpi, s)
s = get_screen(s)
if not s then if not s then
xresources.dpi = dpi xresources.dpi = dpi
else else
@ -100,7 +107,7 @@ end
--- Compute resulting size applying current DPI value (optionally per screen). --- Compute resulting size applying current DPI value (optionally per screen).
-- @tparam number size Size -- @tparam number size Size
-- @tparam[opt] integer s The screen. -- @tparam[opt] integer|screen s The screen.
-- @treturn integer Resulting size (rounded to integer). -- @treturn integer Resulting size (rounded to integer).
function xresources.apply_dpi(size, s) function xresources.apply_dpi(size, s)
return round(size / 96 * xresources.get_dpi(s)) return round(size / 96 * xresources.get_dpi(s))

View File

@ -31,6 +31,10 @@ local common = require("awful.widget.common")
local theme = require("beautiful") local theme = require("beautiful")
local wibox = require("wibox") local wibox = require("wibox")
local function get_screen(s)
return s and capi.screen[s]
end
-- menubar -- menubar
local menubar = { mt = {}, menu_entries = {} } local menubar = { mt = {}, menu_entries = {} }
menubar.menu_gen = require("menubar.menu_gen") menubar.menu_gen = require("menubar.menu_gen")
@ -122,9 +126,10 @@ end
--- Cut item list to return only current page. --- Cut item list to return only current page.
-- @tparam table all_items All items list. -- @tparam table all_items All items list.
-- @tparam str query Search query. -- @tparam str query Search query.
-- @tparam number scr Screen number -- @tparam number|screen scr Screen
-- @return table List of items for current page. -- @return table List of items for current page.
local function get_current_page(all_items, query, scr) local function get_current_page(all_items, query, scr)
scr = get_screen(scr)
if not instance.prompt.width then if not instance.prompt.width then
instance.prompt.width = compute_text_width(instance.prompt.prompt, scr) instance.prompt.width = compute_text_width(instance.prompt.prompt, scr)
end end
@ -161,7 +166,7 @@ end
--- Update the menubar according to the command entered by user. --- Update the menubar according to the command entered by user.
-- @tparam str query Search query. -- @tparam str query Search query.
-- @tparam number scr Screen number -- @tparam number|screen scr Screen
local function menulist_update(query, scr) local function menulist_update(query, scr)
query = query or "" query = query or ""
shownitems = {} shownitems = {}
@ -288,7 +293,7 @@ local function prompt_keypressed_callback(mod, key, comm)
end end
--- Show the menubar on the given screen. --- Show the menubar on the given screen.
-- @param scr Screen number. -- @param scr Screen.
function menubar.show(scr) function menubar.show(scr)
if not instance.wibox then if not instance.wibox then
initialize() initialize()
@ -300,6 +305,7 @@ function menubar.show(scr)
-- Set position and size -- Set position and size
scr = scr or awful.screen.focused() or 1 scr = scr or awful.screen.focused() or 1
scr = get_screen(scr)
local scrgeom = capi.screen[scr].workarea local scrgeom = capi.screen[scr].workarea
local geometry = menubar.geometry local geometry = menubar.geometry
instance.geometry = {x = geometry.x or scrgeom.x, instance.geometry = {x = geometry.x or scrgeom.x,

View File

@ -12,6 +12,7 @@ local io = io
local table = table local table = table
local ipairs = ipairs local ipairs = ipairs
local string = string local string = string
local screen = screen
local awful_util = require("awful.util") local awful_util = require("awful.util")
local theme = require("beautiful") local theme = require("beautiful")
local glib = require("lgi").GLib local glib = require("lgi").GLib
@ -257,17 +258,17 @@ end
--- Compute textbox width. --- Compute textbox width.
-- @tparam wibox.widget.textbox textbox Textbox instance. -- @tparam wibox.widget.textbox textbox Textbox instance.
-- @tparam number s Screen number -- @tparam number|screen s Screen
-- @treturn int Text width. -- @treturn int Text width.
function utils.compute_textbox_width(textbox, s) 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) local w, _ = textbox:get_preferred_size(s)
return w return w
end end
--- Compute text width. --- Compute text width.
-- @tparam str text Text. -- @tparam str text Text.
-- @tparam number s Screen number -- @tparam number|screen s Screen
-- @treturn int Text width. -- @treturn int Text width.
function utils.compute_text_width(text, s) function utils.compute_text_width(text, s)
return utils.compute_textbox_width(wibox.widget.textbox(awful_util.escape(text)), s) return utils.compute_textbox_width(wibox.widget.textbox(awful_util.escape(text)), s)

View File

@ -25,6 +25,10 @@ local surface = require("gears.surface")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local dpi = require("beautiful").xresources.apply_dpi local dpi = require("beautiful").xresources.apply_dpi
local function get_screen(s)
return s and capi.screen[s]
end
local naughty = {} local naughty = {}
--[[-- --[[--
@ -140,7 +144,7 @@ local suspended = false
-- @table notifications -- @table notifications
naughty.notifications = { suspended = { } } naughty.notifications = { suspended = { } }
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
naughty.notifications[s] = { naughty.notifications[get_screen(s)] = {
top_left = {}, top_left = {},
top_middle = {}, top_middle = {},
top_right = {}, top_right = {},
@ -189,7 +193,8 @@ end
-- @param height Popup height -- @param height Popup height
-- @return Absolute position and index in { x = X, y = Y, idx = I } table -- @return Absolute position and index in { x = X, y = Y, idx = I } table
local function get_offset(s, position, idx, width, height) 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 = {} local v = {}
idx = idx or #naughty.notifications[s][position] + 1 idx = idx or #naughty.notifications[s][position] + 1
width = width or naughty.notifications[s][position][idx].width width = width or naughty.notifications[s][position][idx].width
@ -290,6 +295,7 @@ end
function naughty.getById(id) function naughty.getById(id)
-- iterate the notifications to get the notfications with the correct ID -- iterate the notifications to get the notfications with the correct ID
for s = 1, capi.screen.count() do for s = 1, capi.screen.count() do
s = get_screen(s)
for p in pairs(naughty.notifications[s]) do for p in pairs(naughty.notifications[s]) do
for _, notification in pairs(naughty.notifications[s][p]) do for _, notification in pairs(naughty.notifications[s][p]) do
if notification.id == id then if notification.id == id then
@ -386,7 +392,7 @@ end
-- @int[opt=5] args.timeout Time in seconds after which popup expires. -- @int[opt=5] args.timeout Time in seconds after which popup expires.
-- Set 0 for no timeout. -- Set 0 for no timeout.
-- @int[opt] args.hover_timeout Delay in seconds after which hovered popup disappears. -- @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. -- @string[opt="top_right"] args.position Corner of the workarea displaying the popups.
-- Values: `"top_right"`, `"top_left"`, `"bottom_left"`, -- Values: `"top_right"`, `"top_left"`, `"bottom_left"`,
-- `"bottom_right"`, `"top_middle"`, `"bottom_middle"`. -- `"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 icon_size = args.icon_size or preset.icon_size
local text = args.text or preset.text local text = args.text or preset.text
local title = args.title or preset.title 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 ontop = args.ontop or preset.ontop
local width = args.width or preset.width local width = args.width or preset.width
local height = args.height or preset.height local height = args.height or preset.height
@ -609,7 +615,7 @@ function naughty.notify(args)
height = height + actions_total_height height = height + actions_total_height
-- crop to workarea size if too big -- 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 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) width = workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0)
end end

View File

@ -10,7 +10,8 @@
local drawable = {} local drawable = {}
local capi = { local capi = {
awesome = awesome, awesome = awesome,
root = root root = root,
screen = screen
} }
local beautiful = require("beautiful") local beautiful = require("beautiful")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
@ -32,10 +33,10 @@ local function screen_getbycoord(x, y)
local geometry = screen[i].geometry local geometry = screen[i].geometry
if x >= geometry.x and x < geometry.x + geometry.width if x >= geometry.x and x < geometry.x + geometry.width
and y >= geometry.y and y < geometry.y + geometry.height then and y >= geometry.y and y < geometry.y + geometry.height then
return i return capi.screen[i]
end end
end end
return 1 return capi.screen[1]
end end
-- Get the widget context. This should always return the same table (if -- Get the widget context. This should always return the same table (if

View File

@ -66,7 +66,7 @@ end
--- Get the preferred size of a textbox. --- Get the preferred size of a textbox.
-- This returns the size that the textbox would use if infinite space were -- This returns the size that the textbox would use if infinite space were
-- available. -- 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 width.
-- @treturn number The preferred height. -- @treturn number The preferred height.
function textbox:get_preferred_size(s) 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 -- This returns the height that the textbox would use when it is limited to the
-- given width. -- given width.
-- @tparam number width The available 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. -- @treturn number The needed height.
function textbox:get_height_for_width(width, s) function textbox:get_height_for_width(width, s)
return self:get_height_for_width_at_dpi(width, beautiful.xresources.get_dpi(s)) return self:get_height_for_width_at_dpi(width, beautiful.xresources.get_dpi(s))