From 789cf11d8d51a0f0070310a572cfe5c3cb927630 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 6 Oct 2018 18:11:23 -0400 Subject: [PATCH 1/2] titlebar: Emit `request::titlebars` from `awful.titlebar`. The toggle/show/hide function were incompatible with the current `rc.lua` is `titlebars_enabled` was removed from the rules because they were never created. This has always been the case but the introduction os `request::titlebars` in Awesome 4.0 allows to solve this longstanding issue. However until now it didn't. Fix #2419 --- lib/awful/rules.lua | 1 + lib/awful/titlebar.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index c652ede3..3af69bc9 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -584,6 +584,7 @@ function rules.execute(c, props, callbacks) -- This has to be done first, as it will impact geometry related props. if props.titlebars_enabled then c:emit_signal("request::titlebars", "rules", {properties=props}) + c._request_titlebars_called = true end -- Border width will also cause geometry related properties to fail diff --git a/lib/awful/titlebar.lua b/lib/awful/titlebar.lua index 969b4076..d6230f9b 100644 --- a/lib/awful/titlebar.lua +++ b/lib/awful/titlebar.lua @@ -453,6 +453,32 @@ local function get_titlebar_function(c, position) end end +--- Call `request::titlebars` to allow themes or rc.lua to create them even +-- when `titlebars_enabled` is not set in the rules. +-- @tparam client c The client. +-- @tparam[opt=false] boolean hide_all Hide all titlebars except `keep` +-- @tparam string keep Keep the titlebar at this position +-- @treturn boolean If the titlebars were loaded +local function load_titlebars(c, hide_all, keep) + if c._request_titlebars_called then return false end + + c:emit_signal("request::titlebars", "awful.titlebar", {}) + + if hide_all then + -- Don't bother checking if it has been created, `.hide` don't works + -- anyway. + for _, tb in ipairs {"top", "bottom", "left", "right"} do + if tb ~= keep then + titlebar.hide(c, tb) + end + end + end + + c._request_titlebars_called = true + + return true +end + --- Get a client's titlebar. -- @tparam client c The client for which a titlebar is wanted. -- @tparam[opt={}] table args A table with extra arguments for the titlebar. @@ -530,6 +556,7 @@ end -- "right", "top", "bottom". Default is "top". function titlebar.show(c, position) position = position or "top" + if load_titlebars(c, true, position) then return end local bars = all_titlebars[c] local data = bars and bars[position] local args = data and data.args @@ -551,6 +578,7 @@ end -- "right", "top", "bottom". Default is "top". function titlebar.toggle(c, position) position = position or "top" + if load_titlebars(c, true, position) then return end local _, size = get_titlebar_function(c, position)(c) if size == 0 then titlebar.show(c, position) From 6229783e16240f26008799b383e8ad7783e21382 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 6 Oct 2018 18:19:19 -0400 Subject: [PATCH 2/2] tests: Add a titlebar integration suite It doesn't do all that much, but will prevent #2419 from regressing --- tests/test-titlebar.lua | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/test-titlebar.lua diff --git a/tests/test-titlebar.lua b/tests/test-titlebar.lua new file mode 100644 index 00000000..38dd6413 --- /dev/null +++ b/tests/test-titlebar.lua @@ -0,0 +1,94 @@ +local runner = require("_runner") +local titlebar = require("awful.titlebar") +local rules = require("awful.rules") +local spawn = require("awful.spawn") + +local tiny_client = {"lua", "-e", [[ +local Gtk, class = require('lgi').require('Gtk'), 'client' +Gtk.init() +window = Gtk.Window {default_width=100, default_height=100, title='title'} +window:set_wmclass(class, class) +local app = Gtk.Application {} +function app:on_activate() + window.application = self + window:show_all() +end +app:run {''} +]]} + +-- Use the test client props +rules.rules = {} + +-- Too bad there's no way to disconnect the rc.lua request::titlebars function + +local steps = { + function() + assert(#client.get() == 0) + spawn(tiny_client) + return true + end, + function() + if #client.get() ~= 1 then return end + + local c = client.get()[1] + + -- The rules don't set any borders nor enable the titlebar + assert(not c._request_titlebars_called) + assert(c.width == 100 and c.height == 100) + + -- Should create the top titlebar + titlebar.toggle(c, "top") + + assert(c._request_titlebars_called) + + local h = c.height + assert(h > 100) + + -- Should do nothing, there is no titlebar at the bottom by default + titlebar.toggle(c, "bottom") + assert(h == c.height) + + -- Should hide the titlebar + titlebar.toggle(c, "top") + assert(c.height == 100) + + c:kill() + + return true + end, + function() + if #client.get() ~= 0 then return end + + spawn(tiny_client, {titlebars_enabled=true}) + + return true + end, + function() + if #client.get() ~= 1 then return end + + local c = client.get()[1] + + local h = c.height + assert(c.width == 100 and h > 100) + assert(c._request_titlebars_called) + + titlebar.hide(c, "top") + + assert(c.width == 100 and c.height == 100) + + titlebar.hide(c, "top") + + assert(c.width == 100 and c.height == 100) + titlebar.show(c, "top") + + assert(c.width == 100 and c.height == h) + + c:kill() + + return true + end, +} + +runner.run_steps(steps) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80