tests: Implement the fake_* screen methods
This commit is contained in:
parent
f0b6e36ac1
commit
9283719bfb
|
@ -4,6 +4,29 @@ local gears_tab = require("gears.table")
|
|||
local screen, meta = awesome._shim_fake_class()
|
||||
screen._count, screen._deleted = 0, {}
|
||||
|
||||
local function compute_workarea(s)
|
||||
local struts = {top=0,bottom=0,left=0,right=0}
|
||||
|
||||
for _, c in ipairs(drawin.get()) do
|
||||
for k,v in pairs(struts) do
|
||||
struts[k] = v + (c:struts()[k] or 0)
|
||||
end
|
||||
end
|
||||
|
||||
for _, c in ipairs(client.get()) do
|
||||
for k,v in pairs(struts) do
|
||||
struts[k] = v + (c:struts()[k] or 0)
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
x = s.geometry.x + struts.left,
|
||||
y = s.geometry.y + struts.top ,
|
||||
width = s.geometry.width - struts.left - struts.right ,
|
||||
height = s.geometry.height - struts.top - struts.bottom,
|
||||
}
|
||||
end
|
||||
|
||||
local function create_screen(args)
|
||||
local s = gears_obj()
|
||||
awesome._forward_class(s, screen)
|
||||
|
@ -28,9 +51,40 @@ local function create_screen(args)
|
|||
s:emit_signal("property::geometry", old)
|
||||
end
|
||||
|
||||
s.outputs = { ["LVDS1"] = {
|
||||
mm_width = 0,
|
||||
mm_height = 0,
|
||||
function s.fake_resize(self, x, y, width, height)
|
||||
self._resize {
|
||||
x=x,y=y,width=width,height=height
|
||||
}
|
||||
end
|
||||
|
||||
function s:fake_remove()
|
||||
local i = s.index
|
||||
table.remove(screen, i)
|
||||
screen._deleted[s] = true
|
||||
s:emit_signal("removed")
|
||||
screen[screen[i]] = nil
|
||||
s.valid = false
|
||||
end
|
||||
|
||||
function s:swap(other_s)
|
||||
local s1geo = gears_tab.clone(s.geometry)
|
||||
local s2geo = gears_tab.clone(other_s.geometry)
|
||||
|
||||
s:fake_resize(
|
||||
s2geo.x, s2geo.y, s2geo.width, s2geo.height
|
||||
)
|
||||
other_s:fake_resize(
|
||||
s1geo.x, s1geo.y, s1geo.width, s1geo.height
|
||||
)
|
||||
|
||||
s:emit_signal("swapped",other_s)
|
||||
other_s:emit_signal("swapped",s)
|
||||
end
|
||||
|
||||
s.outputs = { LVDS1 ={
|
||||
name = "LVDS1",
|
||||
mm_width = (geo.width /96)*25.4,
|
||||
mm_height = (geo.height/96)*25.4,
|
||||
}}
|
||||
|
||||
local wa = args.workarea_sides or 10
|
||||
|
@ -46,12 +100,16 @@ local function create_screen(args)
|
|||
height = geo.height,
|
||||
}
|
||||
elseif key == "workarea" then
|
||||
return {
|
||||
x = (geo.x or 0) + wa ,
|
||||
y = (geo.y or 0) + wa ,
|
||||
width = geo.width - 2*wa,
|
||||
height = geo.height - 2*wa,
|
||||
}
|
||||
if screen._track_workarea then
|
||||
return compute_workarea(s)
|
||||
else
|
||||
return {
|
||||
x = (geo.x or 0) + wa ,
|
||||
y = (geo.y or 0) + wa ,
|
||||
width = geo.width - 2*wa,
|
||||
height = geo.height - 2*wa,
|
||||
}
|
||||
end
|
||||
else
|
||||
return meta.__index(_, key)
|
||||
end
|
||||
|
@ -72,6 +130,8 @@ function screen._add_screen(args)
|
|||
screen[#screen+1] = s
|
||||
screen[s] = s
|
||||
screen._count = screen._count + 1
|
||||
|
||||
return s
|
||||
end
|
||||
|
||||
function screen._get_extents()
|
||||
|
@ -92,7 +152,18 @@ end
|
|||
-- problematic since it can cause invalid screens to be "resurrected".
|
||||
local function catch_invalid(_, s)
|
||||
-- The CAPI implementation allows `nil`
|
||||
if s == nil or type(s) == "string" then return end
|
||||
if s == nil then return end
|
||||
|
||||
-- Try to get the screens by output name.
|
||||
if type(s) == "string" then
|
||||
for s2 in screen do
|
||||
for out in pairs(s2.outputs or {}) do
|
||||
if out == s then
|
||||
return s2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert(screen ~= s, "Some code tried (and failed) to shadow the global `screen`")
|
||||
|
||||
|
@ -152,11 +223,21 @@ local function iter_scr(_, _, s)
|
|||
|
||||
local i = s.index
|
||||
|
||||
if i + 1 < #screen then
|
||||
if i < #screen then
|
||||
return screen[i+1], i+1
|
||||
end
|
||||
end
|
||||
|
||||
function screen._areas()
|
||||
return {}
|
||||
end
|
||||
|
||||
function screen.fake_add(x,y,width,height)
|
||||
return screen._add_screen {
|
||||
x=x,y=y,width=width,height=height
|
||||
}
|
||||
end
|
||||
|
||||
screen._add_screen {width=320, height=240}
|
||||
|
||||
screen._grid_vertical_margin = 10
|
||||
|
@ -164,6 +245,8 @@ screen._grid_horizontal_margin = 10
|
|||
|
||||
screen.primary = screen[1]
|
||||
|
||||
screen._track_workarea = false
|
||||
|
||||
function screen.count()
|
||||
return screen._count
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue