From 3ffbe4c03bbb9371c05d7b0fa0fe254896db76aa Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 5 Nov 2017 20:29:47 +0100 Subject: [PATCH 1/2] client: Prevent an error when using the "after" mode Fix: #2101 --- lib/awful/mouse/resize.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/awful/mouse/resize.lua b/lib/awful/mouse/resize.lua index 15bfe8dd1..2e555caab 100644 --- a/lib/awful/mouse/resize.lua +++ b/lib/awful/mouse/resize.lua @@ -156,11 +156,12 @@ local function handler(_, client, context, args) --luacheck: no unused_args capi.mousegrabber.run(function (_mouse) if not client.valid then return end - -- Resize everytime the mouse moves (default behavior). - if args.mode == "live" then - -- Get the new geometry - geo = setmetatable(args.placement(client, args), {__index=args}) - end + -- Resize everytime the mouse moves (default behavior) in live mode, + -- otherwise keep the current geometry + geo = setmetatable( + args.mode == "live" and args.placement(client, args) or client:geometry(), + {__index=args} + ) -- Execute the move callbacks. This can be used to add features such as -- snap or adding fancy graphical effects. @@ -182,7 +183,9 @@ local function handler(_, client, context, args) --luacheck: no unused_args end -- In case it was modified - setmetatable(geo,{__index=args}) + if geo then + setmetatable(geo, {__index=args}) + end if args.mode == "live" then -- Ask the resizing handler to resize the client From dcdd491ce375742dd61c3286f137e86037d08046 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 5 Nov 2017 21:54:45 +0100 Subject: [PATCH 2/2] tests: Check that the "after" resize mode doesn't print errors Something is broken elsewhere that makes the test irrelevant, but it proves there is no errors. --- tests/test-resize.lua | 59 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tests/test-resize.lua b/tests/test-resize.lua index df76b69ab..d1d4e6027 100644 --- a/tests/test-resize.lua +++ b/tests/test-resize.lua @@ -103,7 +103,7 @@ table.insert(steps, function() return true end) --- Shirnk the client by 100px from the top right +-- Shrink the client by 100px from the top right table.insert(steps, function() local c = client.get()[1] @@ -113,6 +113,51 @@ table.insert(steps, function() -- assert(c:geometry().width == 200-2*c.border_width) --FIXME off by border width... -- assert(c:geometry().height == 200-2*c.border_width) --FIXME off by border width... + + -- Now do a couple check with the "after" mode to make sure it doesn't + -- regress. + root.fake_input("button_release",1) + + mousegrabber.stop() + + amouse.resize.set_mode("after") + c.border_width = 0 + c:geometry { + x = 100, + y = 200, + width = 300, + height = 200, + } + assert(c:geometry().x == 100) + assert(c:geometry().y == 200) + assert(c:geometry().width == 300) + assert(c:geometry().height == 200) + + root.fake_input("button_press",1) + amouse.client.resize(c) + + mouse.coords {x = 500, y= 500} + + return true +end) + +-- Grow the client by 100px from the top left ("after" mode) +table.insert(steps, function() + + -- local c = client.get()[1] + + -- if not mousegrabber.isrunning then --FIXME it should work, but doesn't + -- return true + -- end + + --FIXME, the mousegrabber callback says the mouse buttons are not pressed, + -- theirfor the test is broken + -- Nothing should have changed until button_release is done + --assert(c:geometry().x == 100) + --assert(c:geometry().y == 200) + --assert(c:geometry().width == 300) + --assert(c:geometry().height == 200) + mouse.coords {x = 300, y= 200} return true @@ -120,11 +165,17 @@ end) -- Stop the resize table.insert(steps, function() + + local c = client.get()[1] + root.fake_input("button_release",1) - -- if not mousegrabber.isrunning then --FIXME it should work, but doesn't - -- return true - -- end + assert(c:geometry().x == 100) + assert(c:geometry().y == 200) + assert(c:geometry().width == 400) + assert(c:geometry().height == 300) + + amouse.resize.set_mode("live") mousegrabber.stop()