Support screen objects in some of awful

This commits makes a random selection of modules in awful support screen objects
and accept them as parameters everywhere where a screen index is accepted.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-26 19:08:35 +01:00
parent 65b403c34a
commit 2792fe731e
5 changed files with 58 additions and 38 deletions

View File

@ -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].index, 0, aclient.focus.filter)
if c then
c:emit_signal("request::activate", "autofocus.check_focus",
{raise=false})
@ -41,9 +41,10 @@ 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
local c = aclient.focus.history.get(s, 0, aclient.focus.filter)
if client.focus and client.focus.screen ~= s.index then
local c = aclient.focus.history.get(s.index, 0, aclient.focus.filter)
if c then
c:emit_signal("request::activate", "autofocus.check_focus_tag",
{raise=false})

View File

@ -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,16 +61,17 @@ 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)
screen = get_screen(screen)
local t = tag.selected(screen and screen.index)
return tag.getproperty(t, "layout") or layout.suit.floating
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,7 +79,8 @@ function layout.inc(i, s, layouts)
-- this was changed so that 'layouts' can be an optional parameter
layouts, i, s = i, s, layouts
end
local t = tag.selected(s)
s = get_screen(s)
local t = tag.selected(s and s.index)
layouts = layouts or layout.layouts
if t then
local curlayout = layout.get(s)
@ -124,20 +130,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)
t = t or tag.selected(screen)
screen = get_screen(screen)
t = t or tag.selected(screen and screen.index)
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))
local useless_gap = tag.getgap(t, #client.tiled(screen.index))
-- 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 +156,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 +168,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 +189,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

View File

@ -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

View File

@ -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 cls = client.visible(screen)
local screen = get_screen(c.screen or a_screen.getbycoord(geometry.x, geometry.y))
local cls = client.visible(screen.index)
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

View File

@ -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