awful.titlebar: Add show, hide, toggle functions

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2013-09-19 14:37:07 +02:00
parent bcea1aab66
commit d82342e386
1 changed files with 50 additions and 13 deletions

View File

@ -35,6 +35,20 @@ local function get_color(name, c, args)
return get(args) or get(beautiful) return get(args) or get(beautiful)
end end
local function get_titlebar_function(c, position)
if position == "left" then
return c.titlebar_left
elseif position == "right" then
return c.titlebar_right
elseif position == "top" then
return c.titlebar_top
elseif position == "bottom" then
return c.titlebar_bottom
else
error("Invalid titlebar position '" .. position .. "'")
end
end
--- Get a client's titlebar --- Get a client's titlebar
-- @class function -- @class function
-- @param c The client for which a titlebar is wanted. -- @param c The client for which a titlebar is wanted.
@ -47,19 +61,7 @@ local function new(c, args)
local args = args or {} local args = args or {}
local position = args.position or "top" local position = args.position or "top"
local size = args.size or beautiful.get_font_height(args.font) * 1.5 local size = args.size or beautiful.get_font_height(args.font) * 1.5
local d local d = get_titlebar_function(c, position)(c, size)
if position == "left" then
d = c:titlebar_left(size)
elseif position == "right" then
d = c:titlebar_right(size)
elseif position == "top" then
d = c:titlebar_top(size)
elseif position == "bottom" then
d = c:titlebar_bottom(size)
else
error("Invalid titlebar position '" .. position .. "'")
end
-- Make sure that there is never more than one titlebar for any given client -- Make sure that there is never more than one titlebar for any given client
local bars = all_titlebars[c] local bars = all_titlebars[c]
@ -97,6 +99,41 @@ local function new(c, args)
return ret return ret
end end
--- Show a client's titlebar.
-- @param c The client whose titlebar is modified
-- @param position Optional position of the titlebar. Must be one of "left",
-- "right", "top", "bottom". Default is "top".
function titlebar.show(c, position)
local position = position or "top"
local bars = all_titlebars[c]
local data = bars and bars[position]
local args = data and data.args
new(c, args)
end
--- Hide a client's titlebar.
-- @param c The client whose titlebar is modified
-- @param position Optional position of the titlebar. Must be one of "left",
-- "right", "top", "bottom". Default is "top".
function titlebar.hide(c, position)
local position = position or "top"
get_titlebar_function(c, position)(c, 0)
end
--- Toggle a client's titlebar, hiding it if it is visible, otherwise showing it.
-- @param c The client whose titlebar is modified
-- @param position Optional position of the titlebar. Must be one of "left",
-- "right", "top", "bottom". Default is "top".
function titlebar.toggle(c, position)
local position = position or "top"
local drawable, size = get_titlebar_function(c, position)(c)
if size == 0 then
titlebar.show(c, position)
else
titlebar.hide(c, position)
end
end
--- Create a new titlewidget. A title widget displays the name of a client. --- Create a new titlewidget. A title widget displays the name of a client.
-- Please note that this returns a textbox and all of textbox' API is available. -- Please note that this returns a textbox and all of textbox' API is available.
-- This way, you can e.g. modify the font that is used. -- This way, you can e.g. modify the font that is used.