tests: Implement dynamic properties for the client shims.

This way enough signal are sent to display clients modified by the
rules.
This commit is contained in:
Emmanuel Lepage Vallee 2019-07-18 00:29:56 -04:00
parent 9283719bfb
commit 84a0ca56a2
1 changed files with 92 additions and 9 deletions

View File

@ -22,6 +22,45 @@ local function titlebar_meta(c)
end
end
local properties = {}
-- Emit the request::geometry signal to make immobilized and awful.ewmh work.
for _, prop in ipairs {
"maximized", "maximized_horizontal", "maximized_vertical", "fullscreen" } do
properties["get_"..prop] = function(self)
return self.data[prop] or false
end
properties["set_"..prop] = function(self, value)
self.data[prop] = value or false
if value then
self:emit_signal("request::geometry", prop, nil)
end
self:emit_signal("property::"..prop, value)
end
end
function properties.get_screen(self)
return self.data.screen or screen[1]
end
function properties.set_screen(self, s)
s = screen[s]
self.data.screen = s
if self.x < s.geometry.x or self.x > s.geometry.x+s.geometry.width then
self:geometry { x = s.geometry.x }
end
if self.y < s.geometry.y or self.y > s.geometry.y+s.geometry.height then
self:geometry { y = s.geometry.y }
end
self:emit_signal("property::screen")
end
-- Create fake clients to move around
function client.gen_fake(args)
local ret = gears_obj()
@ -50,6 +89,7 @@ function client.gen_fake(args)
-- Tests should always set a geometry, but just in case
for _, v in ipairs{"x","y","width","height"} do
ret[v] = ret[v] or 1
assert((not args[v]) or ret[v] == args[v])
end
-- Emulate capi.client.geometry
@ -90,6 +130,10 @@ function client.gen_fake(args)
return nil
end
function ret:set_xproperty(prop, value)
ret[prop] = value
end
function ret:get_icon(_)
return require("beautiful").awesome_icon
end
@ -102,6 +146,10 @@ function client.gen_fake(args)
--TODO
end
function ret:apply_size_hints(w, h)
return w or ret.width, h or ret.height
end
function ret:kill()
local old_tags = ret:tags() or {}
@ -123,6 +171,7 @@ function client.gen_fake(args)
assert(not ret.valid)
end
titlebar_meta(ret)
function ret:tags(new) --FIXME
@ -159,14 +208,39 @@ function client.gen_fake(args)
return ret.data._struts
end
-- Set a dummy one for now since set_screen will corrupt it.
ret._old_geo = {}
-- Set the screen attributes.
local s = args.screen
-- Pick the screen from the geometry.
if not s then
for s2 in screen do
local geo = s2.geometry
if geo.x >= ret.x and geo.y >= ret.y and ret.x < geo.x+geo.width
and ret.y < geo.y+geo.height then
s = s2
end
end
end
-- This will happen if the screen coords are not {0,0} and the client had
-- an unspecified position.
s = s or screen[1]
properties.set_screen(ret, s)
-- Set the geometry *again* because the screen possibly overwrote it.
for _, v in ipairs{"x","y","width","height"} do
ret[v] = args[v] or ret[v]
end
-- Record the geometry
ret._old_geo = {}
push_geometry(ret)
ret._old_geo[1]._hide = args.hide_first
-- Set the attributes
ret.screen = args.screen or screen[1]
-- Good enough for the geometry and border
ret.drawin = ret
ret.drawable = ret
@ -176,10 +250,6 @@ function client.gen_fake(args)
ret.below = false
ret.above = false
ret.sticky = false
ret.maximized = false
ret.fullscreen = false
ret.maximized_vertical = false
ret.maximized_horizontal = false
-- Add to the client list
table.insert(clients, ret)
@ -187,8 +257,21 @@ function client.gen_fake(args)
client.focus = ret
setmetatable(ret, {
__index = function(...) return meta.__index(...) end,
__newindex = function(...) return meta.__newindex(...) end
__index = function(self, key)
if properties["get_"..key] then
return properties["get_"..key](self)
end
return meta.__index(self, key)
end,
__newindex = function(self, key, value)
if properties["set_"..key] then
return properties["set_"..key](self, value)
end
return meta.__newindex(self, key, value)
end
})
client.emit_signal("manage", ret)