2016-03-19 09:57:37 +01:00
|
|
|
local gears_obj = require("gears.object")
|
2019-07-18 06:20:58 +02:00
|
|
|
local gears_tab = require("gears.table")
|
2016-03-19 09:57:37 +01:00
|
|
|
|
2016-04-05 05:35:03 +02:00
|
|
|
local screen, meta = awesome._shim_fake_class()
|
2019-04-27 21:45:56 +02:00
|
|
|
screen._count, screen._deleted = 0, {}
|
2016-03-19 09:57:37 +01:00
|
|
|
|
2019-07-18 06:26:10 +02:00
|
|
|
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
|
|
|
|
|
2016-03-19 09:57:37 +01:00
|
|
|
local function create_screen(args)
|
|
|
|
local s = gears_obj()
|
2019-03-08 19:55:55 +01:00
|
|
|
awesome._forward_class(s, screen)
|
|
|
|
|
2016-09-30 11:03:56 +02:00
|
|
|
s.data = {}
|
2017-05-15 08:24:52 +02:00
|
|
|
s.valid = true
|
2016-03-19 09:57:37 +01:00
|
|
|
|
|
|
|
-- Copy the geo in case the args are mutated
|
|
|
|
local geo = {
|
|
|
|
x = args.x ,
|
|
|
|
y = args.y ,
|
|
|
|
width = args.width ,
|
|
|
|
height = args.height,
|
|
|
|
}
|
|
|
|
|
|
|
|
function s._resize(args2)
|
2019-07-18 06:20:58 +02:00
|
|
|
local old = gears_tab.clone(s.geometry)
|
2016-03-19 09:57:37 +01:00
|
|
|
geo.x = args2.x or geo.x
|
|
|
|
geo.y = args2.y or geo.y
|
|
|
|
geo.width = args2.width or geo.width
|
|
|
|
geo.height = args2.height or geo.height
|
2019-03-08 20:09:24 +01:00
|
|
|
s:emit_signal("property::geometry", old)
|
2016-03-19 09:57:37 +01:00
|
|
|
end
|
|
|
|
|
2019-07-18 06:26:10 +02:00
|
|
|
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,
|
2018-07-24 23:12:04 +02:00
|
|
|
}}
|
|
|
|
|
2016-03-19 09:57:37 +01:00
|
|
|
local wa = args.workarea_sides or 10
|
|
|
|
|
|
|
|
return setmetatable(s,{ __index = function(_, key)
|
2019-04-27 21:45:56 +02:00
|
|
|
assert(s.valid)
|
|
|
|
|
2019-04-27 22:43:02 +02:00
|
|
|
if key == "geometry" then
|
|
|
|
return {
|
|
|
|
x = geo.x or 0,
|
|
|
|
y = geo.y or 0,
|
|
|
|
width = geo.width ,
|
|
|
|
height = geo.height,
|
|
|
|
}
|
|
|
|
elseif key == "workarea" then
|
2019-07-18 06:26:10 +02:00
|
|
|
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
|
2019-04-27 22:43:02 +02:00
|
|
|
else
|
|
|
|
return meta.__index(_, key)
|
|
|
|
end
|
|
|
|
end,
|
2019-04-27 21:45:56 +02:00
|
|
|
__newindex = function(...) assert(s.valid); return meta.__newindex(...) end
|
2019-04-27 22:43:02 +02:00
|
|
|
})
|
2016-03-19 09:57:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local screens = {}
|
|
|
|
|
|
|
|
function screen._add_screen(args)
|
|
|
|
local s = create_screen(args)
|
|
|
|
table.insert(screens, s)
|
2017-05-15 08:24:52 +02:00
|
|
|
|
|
|
|
-- Skip the metatable or it will have side effects
|
|
|
|
rawset(s, "index", #screens)
|
|
|
|
|
2016-03-19 09:57:37 +01:00
|
|
|
screen[#screen+1] = s
|
|
|
|
screen[s] = s
|
2018-07-24 23:12:04 +02:00
|
|
|
screen._count = screen._count + 1
|
2019-07-18 06:26:10 +02:00
|
|
|
|
|
|
|
return s
|
2016-03-19 09:57:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function screen._get_extents()
|
|
|
|
local xmax, ymax
|
2019-08-11 10:06:09 +02:00
|
|
|
for v in screen do
|
2016-03-19 09:57:37 +01:00
|
|
|
if not xmax or v.geometry.x+v.geometry.width > xmax.geometry.x+xmax.geometry.width then
|
|
|
|
xmax = v
|
|
|
|
end
|
|
|
|
if not ymax or v.geometry.y+v.geometry.height > ymax.geometry.y+ymax.geometry.height then
|
|
|
|
ymax = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return xmax.geometry.x+xmax.geometry.width, ymax.geometry.y+ymax.geometry.height
|
|
|
|
end
|
|
|
|
|
2019-04-27 21:45:56 +02:00
|
|
|
-- The way the `screen` module is used to store both number and object is
|
|
|
|
-- problematic since it can cause invalid screens to be "resurrected".
|
|
|
|
local function catch_invalid(_, s)
|
|
|
|
-- The CAPI implementation allows `nil`
|
2019-07-18 06:26:10 +02:00
|
|
|
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
|
2019-04-27 21:45:56 +02:00
|
|
|
|
|
|
|
assert(screen ~= s, "Some code tried (and failed) to shadow the global `screen`")
|
|
|
|
|
|
|
|
-- Valid numbers wont get this far.
|
|
|
|
assert(type(s) == "table", "Expected a table, but got a "..type(s))
|
|
|
|
|
|
|
|
if type(s) == "number" then return end
|
|
|
|
|
|
|
|
assert(s.geometry, "The object is not a screen")
|
|
|
|
assert(s.outputs, "The object is not a screen")
|
|
|
|
|
|
|
|
assert((not screen._deleted[s]) or (not s.valid), "The shims are broken")
|
|
|
|
|
|
|
|
assert(not screen._deleted[s], "The screen "..tostring(s).."has been deleted")
|
|
|
|
|
|
|
|
-- Other errors. If someone place an object in the `screen` module, it wont
|
|
|
|
-- get this far. So the remaining cases are probably bugs.
|
|
|
|
assert(false)
|
|
|
|
end
|
|
|
|
|
2016-03-19 09:57:37 +01:00
|
|
|
function screen._clear()
|
2019-04-27 21:45:56 +02:00
|
|
|
assert(#screen == screen._count)
|
2016-03-19 09:57:37 +01:00
|
|
|
for i=1, #screen do
|
2019-04-27 21:45:56 +02:00
|
|
|
screen._deleted[screen[i]] = true
|
|
|
|
screen[i].valid = false
|
2016-03-19 09:57:37 +01:00
|
|
|
screen[screen[i]] = nil
|
|
|
|
screen[i] = nil
|
|
|
|
end
|
|
|
|
screens = {}
|
2018-07-24 23:12:04 +02:00
|
|
|
|
|
|
|
if mouse then
|
|
|
|
mouse.screen = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
screen._count = 0
|
2016-03-19 09:57:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function screen._setup_grid(w, h, rows, args)
|
|
|
|
args = args or {}
|
|
|
|
screen._clear()
|
|
|
|
for i, row in ipairs(rows) do
|
|
|
|
for j=1, row do
|
2018-07-24 23:12:04 +02:00
|
|
|
args.x = (j-1)*w + (j-1)*screen._grid_horizontal_margin
|
|
|
|
args.y = (i-1)*h + (i-1)*screen._grid_vertical_margin
|
2016-03-19 09:57:37 +01:00
|
|
|
args.width = w
|
|
|
|
args.height = h
|
|
|
|
screen._add_screen(args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-15 08:24:52 +02:00
|
|
|
local function iter_scr(_, _, s)
|
|
|
|
if not s then
|
|
|
|
assert(screen[1])
|
|
|
|
return screen[1], 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local i = s.index
|
|
|
|
|
2019-07-18 06:26:10 +02:00
|
|
|
if i < #screen then
|
2017-05-15 08:24:52 +02:00
|
|
|
return screen[i+1], i+1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-25 03:54:26 +02:00
|
|
|
function screen._viewports()
|
2019-07-18 06:26:10 +02:00
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function screen.fake_add(x,y,width,height)
|
|
|
|
return screen._add_screen {
|
|
|
|
x=x,y=y,width=width,height=height
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-03-19 09:57:37 +01:00
|
|
|
screen._add_screen {width=320, height=240}
|
|
|
|
|
2018-07-24 23:12:04 +02:00
|
|
|
screen._grid_vertical_margin = 10
|
|
|
|
screen._grid_horizontal_margin = 10
|
|
|
|
|
2019-03-10 20:00:57 +01:00
|
|
|
screen.primary = screen[1]
|
2018-07-24 23:12:04 +02:00
|
|
|
|
2019-07-18 06:26:10 +02:00
|
|
|
screen._track_workarea = false
|
|
|
|
|
2018-07-24 23:12:04 +02:00
|
|
|
function screen.count()
|
|
|
|
return screen._count
|
|
|
|
end
|
|
|
|
|
2017-05-15 08:24:52 +02:00
|
|
|
return setmetatable(screen, {
|
2019-04-27 21:45:56 +02:00
|
|
|
__call = iter_scr,
|
|
|
|
__index = catch_invalid
|
2017-05-15 08:24:52 +02:00
|
|
|
})
|
2016-03-19 09:57:37 +01:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|