From 678ead26341bd2e0aa27a4b4707b562b1b5c770f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 25 Oct 2017 15:36:00 +0200 Subject: [PATCH] Add client.object.immobilized_{horizontal,vertical} (#2066) ewmh.client_geometry_requests: ignore immobilized clients Fixes https://github.com/awesomeWM/awesome/issues/1676. Fixes https://github.com/awesomeWM/awesome/issues/2036. --- lib/awful/client.lua | 34 +++++++++++++++++++++++++++ lib/awful/ewmh.lua | 10 ++++++++ spec/awful/ewmh_spec.lua | 50 ++++++++++++++++++++++++++++++++++++++++ tests/test-maximize.lua | 14 +++++++++++ 4 files changed, 108 insertions(+) create mode 100644 spec/awful/ewmh_spec.lua diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 72da12904..ea5457cb0 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -634,6 +634,40 @@ function client.object.is_fixed(c) return false end +--- Is the client immobilized horizontally? +-- +-- Does the client have a fixed horizontal position and width, i.e. is it +-- fullscreen, maximized, or horizontally maximized? +-- +-- This property is read only. +-- @property immobilized +-- @param boolean The immobilized state +-- @see maximized +-- @see maximized_horizontal +-- @see maximized_vertical +-- @see fullscreen + +function client.object.is_immobilized_horizontal(c) + return c.fullscreen or c.maximized or c.maximized_horizontal +end + +--- Is the client immobilized vertically? +-- +-- Does the client have a fixed vertical position and width, i.e. is it +-- fullscreen, maximized, or vertically maximized? +-- +-- This property is read only. +-- @property immobilized +-- @param boolean The immobilized state +-- @see maximized +-- @see maximized_horizontal +-- @see maximized_vertical +-- @see fullscreen + +function client.object.is_immobilized_vertical(c) + return c.fullscreen or c.maximized or c.maximized_vertical +end + --- Get a client floating state. -- @client c A client. -- @see floating diff --git a/lib/awful/ewmh.lua b/lib/awful/ewmh.lua index 50631506b..4657a372f 100644 --- a/lib/awful/ewmh.lua +++ b/lib/awful/ewmh.lua @@ -374,6 +374,16 @@ end -- @tparam[opt={}] table hints The hints to pass to the handler function ewmh.client_geometry_requests(c, context, hints) if context == "ewmh" and hints then + if c.immobilized_horizontal then + hints = gtable.clone(hints) + hints.x = nil + hints.width = nil + end + if c.immobilized_vertical then + hints = gtable.clone(hints) + hints.y = nil + hints.height = nil + end c:geometry(hints) end end diff --git a/spec/awful/ewmh_spec.lua b/spec/awful/ewmh_spec.lua new file mode 100644 index 000000000..058b77781 --- /dev/null +++ b/spec/awful/ewmh_spec.lua @@ -0,0 +1,50 @@ +describe("awful.ewmh.client_geometry_requests", function() + package.loaded["awful.client"] = {} + package.loaded["awful.layout"] = {} + package.loaded["awful.screen"] = {} + package.loaded["awful.tag"] = {} + package.loaded["gears.timer"] = {} + _G.client = { + connect_signal = function() end, + get = function() return {} end, + } + _G.screen = { + connect_signal = function() end, + } + + local ewmh = require("awful.ewmh") + + it("removes x/y/width/height when immobilized", function() + local c = {} + local s = stub.new(c, "geometry") + + ewmh.client_geometry_requests(c, "ewmh", {}) + assert.stub(s).was_called_with(c, {}) + + ewmh.client_geometry_requests(c, "ewmh", {x=0, width=400}) + assert.stub(s).was_called_with(c, {x=0, width=400}) + + c.immobilized_horizontal = true + c.immobilized_vertical = false + ewmh.client_geometry_requests(c, "ewmh", {x=0, width=400}) + assert.stub(s).was_called_with(c, {}) + + ewmh.client_geometry_requests(c, "ewmh", {x=0, width=400, y=0}) + assert.stub(s).was_called_with(c, {y=0}) + + c.immobilized_horizontal = true + c.immobilized_vertical = true + ewmh.client_geometry_requests(c, "ewmh", {x=0, width=400, y=0}) + assert.stub(s).was_called_with(c, {}) + + c.immobilized_horizontal = false + c.immobilized_vertical = true + local hints = {x=0, width=400, y=0} + ewmh.client_geometry_requests(c, "ewmh", hints) + assert.stub(s).was_called_with(c, {x=0, width=400}) + -- Table passed as argument should not have been modified. + assert.is.same(hints, {x=0, width=400, y=0}) + end) +end) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/test-maximize.lua b/tests/test-maximize.lua index 72c30b864..1ea6d0d21 100644 --- a/tests/test-maximize.lua +++ b/tests/test-maximize.lua @@ -38,8 +38,12 @@ for _, gravity in ipairs { "NORTH_WEST", "NORTH", "NORTH_EAST", "WEST", assert(not c.maximized_vertical ) assert(not c.maximized ) assert(not c.fullscreen ) + assert(not c.immobilized_horizontal) + assert(not c.immobilized_vertical) c.maximized_horizontal = true + assert(c.immobilized_horizontal) + assert(not c.immobilized_vertical) return true end, function() @@ -53,6 +57,7 @@ for _, gravity in ipairs { "NORTH_WEST", "NORTH", "NORTH_EAST", "WEST", --assert(new_geo.width+2*c.border_width==sgeo.width) --FIXME off by 4px c.maximized_horizontal = false + assert(not c.immobilized_horizontal) return true end, @@ -102,6 +107,8 @@ for _, gravity in ipairs { "NORTH_WEST", "NORTH", "NORTH_EAST", "WEST", local bw = c.border_width assert(c.fullscreen) + assert(c.immobilized_horizontal) + assert(c.immobilized_vertical) assert(new_geo.x==sgeo.x) assert(new_geo.y==sgeo.y) @@ -140,6 +147,8 @@ for _, gravity in ipairs { "NORTH_WEST", "NORTH", "NORTH_EAST", "WEST", assert(c.floating) assert(new_geo.x==sgeo.x) assert(new_geo.y==sgeo.y) + assert(c.immobilized_horizontal) + assert(c.immobilized_vertical) c.maximized = false @@ -191,6 +200,8 @@ gears.table.merge(steps, { assert(not c.maximized_horizontal) assert(not c.maximized_vertical) assert(c.maximized) + assert(c.immobilized_horizontal) + assert(c.immobilized_vertical) c:kill() @@ -214,6 +225,9 @@ gears.table.merge(steps, { -- It might happen in the second try if not c.maximized then return end + assert(c.immobilized_horizontal) + assert(c.immobilized_vertical) + c:kill() return true