awful.screen: Deprecate functions, add methods
This commit is contained in:
parent
5927c1ceed
commit
00d782f3d3
|
@ -11,7 +11,6 @@
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local type = type
|
local type = type
|
||||||
local util = require("awful.util")
|
local util = require("awful.util")
|
||||||
local ascreen = require("awful.screen")
|
|
||||||
local capi = {
|
local capi = {
|
||||||
screen = screen,
|
screen = screen,
|
||||||
mouse = mouse,
|
mouse = mouse,
|
||||||
|
@ -138,16 +137,16 @@ function layout.parameters(t, screen)
|
||||||
|
|
||||||
local useless_gap = t and tag.getgap(t, #client.tiled(screen)) or 0
|
local useless_gap = t and tag.getgap(t, #client.tiled(screen)) or 0
|
||||||
|
|
||||||
p.workarea = ascreen.get_bounding_geometry(screen, {
|
p.workarea = screen:get_bounding_geometry {
|
||||||
honor_padding = true,
|
honor_padding = true,
|
||||||
honor_workarea = true,
|
honor_workarea = true,
|
||||||
margins = useless_gap,
|
margins = useless_gap,
|
||||||
})
|
}
|
||||||
|
|
||||||
p.geometry = screen.geometry
|
p.geometry = screen.geometry
|
||||||
p.clients = client.tiled(screen)
|
p.clients = client.tiled(screen)
|
||||||
p.screen = screen.index
|
p.screen = screen.index
|
||||||
p.padding = ascreen.padding(screen)
|
p.padding = screen.padding
|
||||||
p.useless_gap = useless_gap
|
p.useless_gap = useless_gap
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
--
|
--
|
||||||
-- **honor_padding** (*boolean*):
|
-- **honor_padding** (*boolean*):
|
||||||
--
|
--
|
||||||
-- Take the screen padding into account (see `awful.screen.padding`)
|
-- Take the screen padding into account (see `screen.padding`)
|
||||||
--
|
--
|
||||||
-- **tag** (*tag*):
|
-- **tag** (*tag*):
|
||||||
--
|
--
|
||||||
|
@ -158,7 +158,7 @@ local function geometry_common(obj, args, new_geo, ignore_border_width)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- It is a screen, it doesn't support setting new sizes.
|
-- It is a screen, it doesn't support setting new sizes.
|
||||||
return a_screen.get_bounding_geometry(obj, args)
|
return obj:get_bounding_geometry(args)
|
||||||
else
|
else
|
||||||
assert(false, "Invalid object")
|
assert(false, "Invalid object")
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,13 +45,25 @@ local function apply_geometry_ajustments(geo, delta)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the square distance between a `screen` and a point
|
--- Get the square distance between a `screen` and a point
|
||||||
|
-- @deprecated awful.screen.getdistance_sq
|
||||||
-- @param s Screen
|
-- @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)
|
||||||
s = get_screen(s)
|
util.deprecate "Use s:get_square_distance(x, y) instead of awful.screen.getdistance_sq"
|
||||||
local geom = s.geometry
|
|
||||||
|
return screen.object.get_square_distance(s, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get the square distance between a `screen` and a point
|
||||||
|
-- @function screen.get_square_distance
|
||||||
|
-- @tparam number x X coordinate of point
|
||||||
|
-- @tparam number y Y coordinate of point
|
||||||
|
-- @treturn number The squared distance of the screen to the provided point
|
||||||
|
function screen.object.get_square_distance(self, x, y)
|
||||||
|
self = get_screen(self)
|
||||||
|
local geom = self.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
|
||||||
|
@ -75,9 +87,9 @@ end
|
||||||
-- @param y The y coordinate
|
-- @param y The y coordinate
|
||||||
function screen.getbycoord(x, y)
|
function screen.getbycoord(x, y)
|
||||||
local s = capi.screen[1]
|
local s = capi.screen[1]
|
||||||
local dist = screen.getdistance_sq(s, x, y)
|
local dist = screen.object.get_square_distance(s, x, y)
|
||||||
for i in capi.screen do
|
for i in capi.screen do
|
||||||
local d = screen.getdistance_sq(i, x, y)
|
local d = screen.object.get_square_distance(i, x, y)
|
||||||
if d < dist then
|
if d < dist then
|
||||||
s, dist = capi.screen[i], d
|
s, dist = capi.screen[i], d
|
||||||
end
|
end
|
||||||
|
@ -153,12 +165,51 @@ function screen.focus_relative(i)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get or set the screen padding.
|
--- Get or set the screen padding.
|
||||||
|
-- @deprecated awful.screen.padding
|
||||||
-- @param _screen The screen object to change the padding on
|
-- @param _screen The screen object to change the padding on
|
||||||
-- @param[opt=nil] padding The padding, a table with 'top', 'left', 'right' and/or
|
-- @param[opt=nil] padding The padding, a table with 'top', 'left', 'right' and/or
|
||||||
-- 'bottom' or a number value to apply set the same padding on all sides. Can be
|
-- 'bottom' or a number value to apply set the same padding on all sides. Can be
|
||||||
-- nil if you only want to retrieve padding
|
-- nil if you only want to retrieve padding
|
||||||
-- @treturn table A table with left, right, top and bottom number values.
|
-- @treturn table A table with left, right, top and bottom number values.
|
||||||
|
-- @see padding
|
||||||
function screen.padding(_screen, padding)
|
function screen.padding(_screen, padding)
|
||||||
|
util.deprecate "Use _screen.padding = value instead of awful.screen.padding"
|
||||||
|
|
||||||
|
if padding then
|
||||||
|
screen.object.set_padding(_screen, padding)
|
||||||
|
end
|
||||||
|
|
||||||
|
return screen.object.get_padding(_screen)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- The screen padding.
|
||||||
|
-- Add a "buffer" section on each side of the screen where the tiled client
|
||||||
|
-- wont be.
|
||||||
|
--
|
||||||
|
-- **Signal:**
|
||||||
|
--
|
||||||
|
-- * *property::padding*
|
||||||
|
--
|
||||||
|
-- @property padding
|
||||||
|
-- @param table
|
||||||
|
-- @tfield integer table.x The horizontal position
|
||||||
|
-- @tfield integer table.y The vertical position
|
||||||
|
-- @tfield integer table.width The width
|
||||||
|
-- @tfield integer table.height The height
|
||||||
|
|
||||||
|
function screen.object.get_padding(self)
|
||||||
|
local p = data.padding[self] or {}
|
||||||
|
|
||||||
|
-- Create a copy to avoid accidental mutation and nil values
|
||||||
|
return {
|
||||||
|
left = p.left or 0,
|
||||||
|
right = p.right or 0,
|
||||||
|
top = p.top or 0,
|
||||||
|
bottom = p.bottom or 0,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function screen.object.set_padding(self, padding)
|
||||||
if type(padding) == "number" then
|
if type(padding) == "number" then
|
||||||
padding = {
|
padding = {
|
||||||
left = padding,
|
left = padding,
|
||||||
|
@ -168,21 +219,11 @@ function screen.padding(_screen, padding)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
_screen = get_screen(_screen)
|
self = get_screen(self)
|
||||||
if padding then
|
if padding then
|
||||||
data.padding[_screen] = padding
|
data.padding[self] = padding
|
||||||
_screen:emit_signal("padding")
|
self:emit_signal("padding")
|
||||||
end
|
end
|
||||||
|
|
||||||
local p = data.padding[_screen] or {}
|
|
||||||
|
|
||||||
-- Create a copy to avoid accidental mutation and nil values
|
|
||||||
return {
|
|
||||||
left = p.left or 0,
|
|
||||||
right = p.right or 0,
|
|
||||||
top = p.top or 0,
|
|
||||||
bottom = p.bottom or 0,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- The defaults arguments for `awful.screen.focused`
|
--- The defaults arguments for `awful.screen.focused`
|
||||||
|
@ -197,7 +238,7 @@ end
|
||||||
-- @tparam[opt] table args
|
-- @tparam[opt] table args
|
||||||
-- @tparam[opt=false] boolean args.client Use the client screen instead of the
|
-- @tparam[opt=false] boolean args.client Use the client screen instead of the
|
||||||
-- mouse screen.
|
-- mouse screen.
|
||||||
-- @tparam[opt=true] boolean args.screen Use the mouse screen
|
-- @tparam[opt=true] boolean args.mouse Use the mouse screen
|
||||||
-- @treturn ?screen The focused screen object, or `nil` in case no screen is
|
-- @treturn ?screen The focused screen object, or `nil` in case no screen is
|
||||||
-- present currently.
|
-- present currently.
|
||||||
function screen.focused(args)
|
function screen.focused(args)
|
||||||
|
@ -219,24 +260,31 @@ end
|
||||||
-- * **bounding_rect**: A bounding rectangle. This parameter is incompatible with
|
-- * **bounding_rect**: A bounding rectangle. This parameter is incompatible with
|
||||||
-- `honor_workarea`.
|
-- `honor_workarea`.
|
||||||
--
|
--
|
||||||
-- @tparam[opt=mouse.screen] screen s A screen
|
-- @function screen.get_bounding_geometry
|
||||||
-- @tparam[opt={}] table args The arguments
|
-- @tparam[opt={}] table args The arguments
|
||||||
-- @treturn table A table with *x*, *y*, *width* and *height*.
|
-- @treturn table A table with *x*, *y*, *width* and *height*.
|
||||||
function screen.get_bounding_geometry(s, args)
|
-- @usage local geo = screen:get_bounding_geometry {
|
||||||
|
-- honor_padding = true,
|
||||||
|
-- honor_workarea = true,
|
||||||
|
-- margins = {
|
||||||
|
-- left = 20,
|
||||||
|
-- },
|
||||||
|
-- }
|
||||||
|
function screen.object.get_bounding_geometry(self, args)
|
||||||
args = args or {}
|
args = args or {}
|
||||||
|
|
||||||
-- If the tag has a geometry, assume it is right
|
-- If the tag has a geometry, assume it is right
|
||||||
if args.tag then
|
if args.tag then
|
||||||
s = args.tag.screen
|
self = args.tag.screen
|
||||||
end
|
end
|
||||||
|
|
||||||
s = get_screen(s or capi.mouse.screen)
|
self = get_screen(self or capi.mouse.screen)
|
||||||
|
|
||||||
local geo = args.bounding_rect or (args.parent and args.parent:geometry()) or
|
local geo = args.bounding_rect or (args.parent and args.parent:geometry()) or
|
||||||
s[args.honor_workarea and "workarea" or "geometry"]
|
self[args.honor_workarea and "workarea" or "geometry"]
|
||||||
|
|
||||||
if (not args.parent) and (not args.bounding_rect) and args.honor_padding then
|
if (not args.parent) and (not args.bounding_rect) and args.honor_padding then
|
||||||
local padding = screen.padding(s)
|
local padding = self.padding
|
||||||
geo = apply_geometry_ajustments(geo, padding)
|
geo = apply_geometry_ajustments(geo, padding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -271,7 +319,11 @@ end
|
||||||
capi.screen.add_signal("padding")
|
capi.screen.add_signal("padding")
|
||||||
|
|
||||||
-- Extend the luaobject
|
-- Extend the luaobject
|
||||||
object.properties(capi.screen, {auto_emit=true})
|
object.properties(capi.screen, {
|
||||||
|
getter_class = screen.object,
|
||||||
|
setter_class = screen.object,
|
||||||
|
auto_emit = true,
|
||||||
|
})
|
||||||
|
|
||||||
return screen
|
return screen
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ function object.capi_index_fallback(class, args)
|
||||||
if args.getter_class and args.getter_class[prop] then
|
if args.getter_class and args.getter_class[prop] then
|
||||||
return args.getter_class[prop]
|
return args.getter_class[prop]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- In case there is already a "dumb" getter like `awful.tag.getproperty'
|
-- In case there is already a "dumb" getter like `awful.tag.getproperty'
|
||||||
if args.getter_fallback then
|
if args.getter_fallback then
|
||||||
return args.getter_fallback(cobj, prop)
|
return args.getter_fallback(cobj, prop)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
local gears_obj = require("gears.object")
|
local gears_obj = require("gears.object")
|
||||||
|
|
||||||
local screen = awesome._shim_fake_class()
|
local screen, meta = awesome._shim_fake_class()
|
||||||
|
|
||||||
screen.count = 1
|
screen.count = 1
|
||||||
|
|
||||||
|
@ -42,8 +42,11 @@ local function create_screen(args)
|
||||||
width = geo.width - 2*wa,
|
width = geo.width - 2*wa,
|
||||||
height = geo.height - 2*wa,
|
height = geo.height - 2*wa,
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return meta.__index(_, key)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
__new_index = function(...) return meta.__new_index(...) end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue