commit
7020a9707f
|
@ -631,6 +631,7 @@ function rules.execute(c, props, callbacks)
|
||||||
if props.titlebars_enabled and (type(props.titlebars_enabled) ~= "function"
|
if props.titlebars_enabled and (type(props.titlebars_enabled) ~= "function"
|
||||||
or props.titlebars_enabled(c,props)) then
|
or props.titlebars_enabled(c,props)) then
|
||||||
c:emit_signal("request::titlebars", "rules", {properties=props})
|
c:emit_signal("request::titlebars", "rules", {properties=props})
|
||||||
|
c._request_titlebars_called = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Border width will also cause geometry related properties to fail
|
-- Border width will also cause geometry related properties to fail
|
||||||
|
|
|
@ -453,6 +453,32 @@ local function get_titlebar_function(c, position)
|
||||||
end
|
end
|
||||||
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.
|
--- Get a client's titlebar.
|
||||||
-- @tparam client c The client for which a titlebar is wanted.
|
-- @tparam client c The client for which a titlebar is wanted.
|
||||||
-- @tparam[opt={}] table args A table with extra arguments for the titlebar.
|
-- @tparam[opt={}] table args A table with extra arguments for the titlebar.
|
||||||
|
@ -530,6 +556,7 @@ end
|
||||||
-- "right", "top", "bottom". Default is "top".
|
-- "right", "top", "bottom". Default is "top".
|
||||||
function titlebar.show(c, position)
|
function titlebar.show(c, position)
|
||||||
position = position or "top"
|
position = position or "top"
|
||||||
|
if load_titlebars(c, true, position) then return end
|
||||||
local bars = all_titlebars[c]
|
local bars = all_titlebars[c]
|
||||||
local data = bars and bars[position]
|
local data = bars and bars[position]
|
||||||
local args = data and data.args
|
local args = data and data.args
|
||||||
|
@ -551,6 +578,7 @@ end
|
||||||
-- "right", "top", "bottom". Default is "top".
|
-- "right", "top", "bottom". Default is "top".
|
||||||
function titlebar.toggle(c, position)
|
function titlebar.toggle(c, position)
|
||||||
position = position or "top"
|
position = position or "top"
|
||||||
|
if load_titlebars(c, true, position) then return end
|
||||||
local _, size = get_titlebar_function(c, position)(c)
|
local _, size = get_titlebar_function(c, position)(c)
|
||||||
if size == 0 then
|
if size == 0 then
|
||||||
titlebar.show(c, position)
|
titlebar.show(c, position)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue