From 94e13b7bb09d0aa082a54334da9b4d8cc4eccd6f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 22 Oct 2021 15:30:36 -0700 Subject: [PATCH 1/4] shims: Fix some bugs for ruled.tag. --- tests/examples/shims/client.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/examples/shims/client.lua b/tests/examples/shims/client.lua index d3f69d7b..10d7d14f 100644 --- a/tests/examples/shims/client.lua +++ b/tests/examples/shims/client.lua @@ -5,6 +5,8 @@ local clients = {} local client, meta = awesome._shim_fake_class() +rawset(client, "_autotags", true) + -- Keep an history of the geometry for validation and images local function push_geometry(c) table.insert(c._old_geo, c:geometry()) @@ -227,15 +229,18 @@ function client.gen_fake(args) function ret:tags(new) --FIXME if new then ret._tags = new + ret:emit_signal("property::tags") end if ret._tags then return ret._tags end - for _, t in ipairs(root._tags) do - if t.screen == ret.screen then - return {t} + if client._autotags then + for _, t in ipairs(root._tags) do + if t.screen == ret.screen then + return {t} + end end end @@ -330,7 +335,6 @@ function client.gen_fake(args) return meta.__index(self, key) end, __newindex = function(self, key, value) - if properties["set_"..key] then return properties["set_"..key](self, value) end From 8c9e270477eb0c20ce59c8ea5086a7e77c7fdf9d Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 22 Oct 2021 15:41:02 -0700 Subject: [PATCH 2/4] tests: Improve the sequence template. * Fix a typo * Add some initialization signals * Refactor the geometry code to be more resilient * Put more data into the memento --- tests/examples/sequences/template.lua | 50 ++++++++++++++++++--------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/tests/examples/sequences/template.lua b/tests/examples/sequences/template.lua index 760efb70..6110cce4 100644 --- a/tests/examples/sequences/template.lua +++ b/tests/examples/sequences/template.lua @@ -342,10 +342,11 @@ local function gen_fake_clients(tag, args) if not tag.client_geo then return end for _, geom in ipairs(tag.client_geo) do - local x = (geom.x*w)/sgeo.width - local y = (geom.y*h)/sgeo.height + local x = ( (geom.x - sgeo.x) * w)/sgeo.width + local y = ( (geom.y - sgeo.y) * h)/sgeo.height local width = (geom.width*w)/sgeo.width local height = (geom.height*h)/sgeo.height + cr:set_source(color(geom.color or beautiful.bg_normal)) cr:rectangle(x,y,width,height) cr:fill_preserve() @@ -552,7 +553,7 @@ local function gen_screens(l, screens, args) local ret = wibox.layout.manual() - local sreen_copies = {} + local screen_copies = {} -- Keep a copy because it can change. local rw, rh = root.size() @@ -571,7 +572,7 @@ local function gen_screens(l, screens, args) scr_cpy[prop] = s[prop] end - table.insert(sreen_copies, scr_cpy) + table.insert(screen_copies, scr_cpy) end function ret:fit() @@ -581,7 +582,7 @@ local function gen_screens(l, screens, args) end -- Add the rulers. - for _, s in ipairs(sreen_copies) do + for _, s in ipairs(screen_copies) do ret:add_at( gen_ruler("vertical" , 1/screen_scale_factor, margins), {x=margins.left+s.x/screen_scale_factor, y =margins.top/2} @@ -601,21 +602,28 @@ local function gen_screens(l, screens, args) end -- Print an outline for the screens - for k, s in ipairs(sreen_copies) do + for k, s in ipairs(screen_copies) do s.widget = wibox.widget.base.make_widget() local wb = gen_fake_taglist_wibar(screens[k].tags) wb.forced_width = s.width/screen_scale_factor - -- The clients have an absolute geometry, transform to relative. - if screens[k].tags[1] then - for _, geo in ipairs(screens[k].tags[1].client_geo) do - geo.x = geo.x - s.x - geo.y = geo.y - s.y + local sel = nil + + -- AwesomeWM always use the layout from the first selected tag. + for _, t in ipairs(screens[k].tags) do + if t.selected then + sel = t + break end end - local clients_w = gen_fake_clients(screens[k].tags[1], args) + -- Fallback because some older examples don't select tags. + if not sel then + sel = screens[k].tags[1] + end + + local clients_w = gen_fake_clients(sel, args) local content = wibox.widget { wb, @@ -642,9 +650,9 @@ local function gen_screens(l, screens, args) end function s.widget:after_draw_children(_, cr) - if args.display_mouse and mouse.screen.index == s.index then - local rel_x = mouse.coords().x - s.x - local rel_y = mouse.coords().y - s.y + if args.display_mouse and screens[k].cursor_screen == s.index then + local rel_x = screens[k].cursor_position.x - s.x + local rel_y = screens[k].cursor_position.y - s.y draw_mouse(cr, rel_x/screen_scale_factor+5, rel_y/screen_scale_factor+5) end end @@ -699,6 +707,12 @@ local function gen_timeline(args) l:add(gen_label("Begin")) + -- Run the some steps of the Initialization. + client.emit_signal("scanning") + + -- Finish the initialization. + awesome.startup = false --luacheck: ignore + for _, event in ipairs(history) do local ret = event.callback() if event.event == "event" then @@ -791,7 +805,11 @@ function module.display_tags() }) assert(#st[#st].client_geo == #get_all_tag_clients(t)) end - table.insert(ret, {tags=st}) + table.insert(ret, { + tags = st, + cursor_screen = mouse.screen.index, + cursor_position = gtable.clone(mouse.coords()) + }) end return ret end From 7d6892992cd4d26f0b289ccc46ba3f184247643c Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 27 Oct 2021 17:58:16 -0700 Subject: [PATCH 3/4] client: Change the `relative_move` behavior. The old behavior would move the client when `nil` was passed by an almost arbitrary value. It would most of the time go off screen. While this is a behavior change, what it replaces was so broken I doubt anybody actually used `nil` in `relative_move`. --- docs/89-NEWS.md | 2 ++ lib/awful/client.lua | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/89-NEWS.md b/docs/89-NEWS.md index 2e027f36..18d315cb 100644 --- a/docs/89-NEWS.md +++ b/docs/89-NEWS.md @@ -74,6 +74,8 @@ This document was last updated at commit v4.3-197-g9085ed631. * Setting `awful.rules.rules` now append the rules to the existing set. Clearing the rules was never officially supported. If you *really* want the old behavior, use `awful.rules.rules = {}; awful.rules.rules = my_new_rules`. + * `client:relative_move()` now default `nil` values to zero. The previous + behavior made no sense. # Awesome window manager framework version 4.3 changes diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 16085ab4..8e665a7d 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -523,16 +523,16 @@ end -- -- @method relative_move -- @see geometry --- @tparam[opt=c.x] number x The relative x coordinate. --- @tparam[opt=c.y] number y The relative y coordinate. --- @tparam[opt=c.width] number w The relative width. --- @tparam[opt=c.height] number h The relative height. +-- @tparam[opt=0] number x The relative x coordinate. +-- @tparam[opt=0] number y The relative y coordinate. +-- @tparam[opt=0] number w The relative width. +-- @tparam[opt=0] number h The relative height. function client.object.relative_move(self, x, y, w, h) local geometry = self:geometry() - geometry['x'] = geometry['x'] + (x or geometry.x) - geometry['y'] = geometry['y'] + (y or geometry.y) - geometry['width'] = geometry['width'] + (w or geometry.width) - geometry['height'] = geometry['height'] + (h or geometry.height) + geometry['x'] = geometry['x'] + (x or 0) + geometry['y'] = geometry['y'] + (y or 0) + geometry['width'] = geometry['width'] + (w or 0) + geometry['height'] = geometry['height'] + (h or 0) self:geometry(geometry) end From a3c7ed166fb53c7d56e35abb962780b3deeb0584 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 27 Oct 2021 18:04:40 -0700 Subject: [PATCH 4/4] tests: Modify the client.relative_move test for the new behavior. Also add more asserts. --- .../sequences/client/relative_move1.lua | 21 +++++++++++++++++-- .../client/relative_move1.output.txt | 5 +++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/examples/sequences/client/relative_move1.lua b/tests/examples/sequences/client/relative_move1.lua index fd9ecec6..d35b5c02 100644 --- a/tests/examples/sequences/client/relative_move1.lua +++ b/tests/examples/sequences/client/relative_move1.lua @@ -6,6 +6,7 @@ awful.placement = require("awful.placement") require("awful.ewmh") screen[1]:fake_resize(0, 0, 800, 480) awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, screen[1], awful.layout.suit.tile) +local original_geo, geo function awful.spawn(name) client.gen_fake{class = name, name = name, x = 4, y=10, width = 60, height =50, screen=screen[1]} @@ -22,6 +23,7 @@ module.add_event("Spawn a floating client.", function() client.get()[1].floating = true --DOC_NEWLINE + --DOC_HIDE_START end) @@ -29,14 +31,25 @@ module.display_tags() module.add_event("Move it.", function() --DOC_HIDE_END + geo = client.get()[1]:geometry() + print("Client geometry:", geo.x, geo.y, geo.width, geo.height) + original_geo = geo --DOC_HIDE + + --DOC_NEWLINE + client.get()[1]:relative_move(100, 100) --DOC_NEWLINE - local geo = client.get()[1]:geometry() + geo = client.get()[1]:geometry() print("Client geometry:", geo.x, geo.y, geo.width, geo.height) --DOC_NEWLINE --DOC_HIDE_START + assert(original_geo.width == geo.width) + assert(original_geo.height == geo.height) + assert(original_geo.x == geo.x - 100) + assert(original_geo.y == geo.y - 100) + original_geo.x, original_geo.y = geo.x, geo.y end) module.display_tags() @@ -46,10 +59,14 @@ module.add_event("Resize it.", function() client.get()[1]:relative_move(nil, nil, 100, 100) --DOC_NEWLINE - local geo = client.get()[1]:geometry() + geo = client.get()[1]:geometry() print("Client geometry:", geo.x, geo.y, geo.width, geo.height) --DOC_HIDE_START + assert(original_geo.width == geo.width - 100) + assert(original_geo.height == geo.height - 100) + assert(original_geo.x == geo.x) + assert(original_geo.y == geo.y) end) module.display_tags() diff --git a/tests/examples/sequences/client/relative_move1.output.txt b/tests/examples/sequences/client/relative_move1.output.txt index 3bdf3709..bc95f9db 100644 --- a/tests/examples/sequences/client/relative_move1.output.txt +++ b/tests/examples/sequences/client/relative_move1.output.txt @@ -1,2 +1,3 @@ -Client geometry: 110 110 120 100 -Client geometry: 220 220 220 200 +Client geometry: 4 10 60 50 +Client geometry: 104 110 60 50 +Client geometry: 104 110 160 150