diff --git a/lib/awful/titlebar.lua.in b/lib/awful/titlebar.lua.in index b6e2ad39..b4e867b2 100644 --- a/lib/awful/titlebar.lua.in +++ b/lib/awful/titlebar.lua.in @@ -35,6 +35,20 @@ local function get_color(name, c, args) return get(args) or get(beautiful) 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 -- @class function -- @param c The client for which a titlebar is wanted. @@ -47,19 +61,7 @@ local function new(c, args) local args = args or {} local position = args.position or "top" local size = args.size or beautiful.get_font_height(args.font) * 1.5 - local d - - 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 + local d = get_titlebar_function(c, position)(c, size) -- Make sure that there is never more than one titlebar for any given client local bars = all_titlebars[c] @@ -97,6 +99,41 @@ local function new(c, args) return ret 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. -- 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.