2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local math = math
|
2008-10-23 11:22:58 +02:00
|
|
|
local pairs = pairs
|
2008-09-29 16:49:18 +02:00
|
|
|
local otable = otable
|
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
wibox = wibox,
|
|
|
|
widget = widget,
|
|
|
|
button = button,
|
|
|
|
client = client,
|
|
|
|
}
|
2008-10-09 16:27:37 +02:00
|
|
|
local beautiful = require("awful.beautiful")
|
2008-09-29 16:49:18 +02:00
|
|
|
local hooks = require("awful.hooks")
|
|
|
|
local util = require("awful.util")
|
2008-10-09 16:27:37 +02:00
|
|
|
local widget = require("awful.widget")
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
--- Titlebar module for awful
|
|
|
|
module("awful.titlebar")
|
|
|
|
|
|
|
|
-- Privata data
|
|
|
|
local data = otable()
|
|
|
|
|
|
|
|
--- Create a standard titlebar.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param args Arguments.
|
|
|
|
-- fg: the foreground color.
|
|
|
|
-- bg: the background color.
|
|
|
|
-- fg_focus: the foreground color for focused window.
|
|
|
|
-- fg_focus: the background color for focused window.
|
|
|
|
-- width: the titlebar width
|
|
|
|
function add(c, args)
|
|
|
|
if not c or c.type ~= "normal" then return end
|
|
|
|
if not args then args = {} end
|
2008-10-09 16:27:37 +02:00
|
|
|
local theme = beautiful.get()
|
2008-09-29 16:49:18 +02:00
|
|
|
-- Store colors
|
|
|
|
data[c] = {}
|
|
|
|
data[c].fg = args.fg or theme.titlebar_fg_normal or theme.fg_normal
|
|
|
|
data[c].bg = args.bg or theme.titlebar_bg_normal or theme.bg_normal
|
|
|
|
data[c].fg_focus = args.fg_focus or theme.titlebar_fg_focus or theme.fg_focus
|
|
|
|
data[c].bg_focus = args.bg_focus or theme.titlebar_bg_focus or theme.bg_focus
|
|
|
|
data[c].width = args.width
|
|
|
|
|
2008-10-12 17:14:44 +02:00
|
|
|
local tb = capi.wibox(args)
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
local title = capi.widget({ type = "textbox", name = "title", align = "flex" })
|
|
|
|
title.text = " " .. util.escape(c.name) .. " "
|
|
|
|
local bts =
|
|
|
|
{
|
|
|
|
capi.button({ }, 1, function (t) t.client:mouse_move() end),
|
|
|
|
capi.button({ args.modkey }, 3, function (t) t.client:mouse_resize() end)
|
|
|
|
}
|
|
|
|
title:buttons(bts)
|
|
|
|
|
|
|
|
local appicon = capi.widget({ type = "imagebox", name = "appicon", align = "left" })
|
|
|
|
appicon.image = c.icon
|
|
|
|
|
|
|
|
if theme.titlebar_close_button == "true" then
|
|
|
|
local closef = widget.button({ name = "closef", align = "right",
|
|
|
|
image = theme.titlebar_close_button_focus
|
|
|
|
or theme.titlebar_close_button_img_focus
|
|
|
|
or "@AWESOME_ICON_PATH@/titlebar/closer.png" })
|
|
|
|
local close = widget.button({ name = "close", align = "right",
|
|
|
|
image = theme.titlebar_close_button_normal
|
|
|
|
or theme.titlebar_close_button_img_normal
|
|
|
|
or "@AWESOME_ICON_PATH@/titlebar/close.png" })
|
|
|
|
|
|
|
|
-- Bind kill button
|
|
|
|
local b = capi.button({ }, 1, nil, function (t) t.client:kill() end)
|
|
|
|
local bts = closef:buttons()
|
|
|
|
bts[#bts + 1] = b
|
|
|
|
closef:buttons(bts)
|
|
|
|
|
|
|
|
bts = close:buttons()
|
|
|
|
bts[#bts + 1] = b
|
|
|
|
close:buttons(bts)
|
|
|
|
|
2008-10-19 19:14:55 +02:00
|
|
|
tb.widgets = { appicon, title, closef, close }
|
2008-09-29 16:49:18 +02:00
|
|
|
else
|
2008-10-19 19:14:55 +02:00
|
|
|
tbx.widgets = { appicon, title }
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
c.titlebar = tb
|
|
|
|
|
|
|
|
update(c)
|
|
|
|
update(c, "geometry")
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Update a titlebar. This should be called in some hooks.
|
|
|
|
-- @param c The client to update.
|
|
|
|
-- @param prop The property name which has changed.
|
|
|
|
function update(c, prop)
|
|
|
|
if c.titlebar and data[c] then
|
2008-10-19 19:14:55 +02:00
|
|
|
local widgets = c.titlebar.widgets
|
2008-09-29 16:49:18 +02:00
|
|
|
local title, close, closef
|
2008-10-23 11:22:58 +02:00
|
|
|
for k, v in pairs(widgets) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if v.name == "title" then title = v
|
|
|
|
elseif v.name == "close" then close = v
|
|
|
|
elseif v.name == "closef" then closef = v
|
|
|
|
elseif v.name == "appicon" then appicon = v end
|
|
|
|
if title and close and closef and appicon then break end
|
|
|
|
end
|
|
|
|
if prop == "name" then
|
|
|
|
if title then
|
|
|
|
title.text = " " .. util.escape(c.name) .. " "
|
|
|
|
end
|
|
|
|
elseif prop == "icon" then
|
|
|
|
if appicon then
|
|
|
|
appicon.image = c.icon
|
|
|
|
end
|
|
|
|
elseif prop == "geometry" then
|
|
|
|
if data[c].width then
|
|
|
|
if c.titlebar.position == "top"
|
|
|
|
or c.titlebar.position == "bottom" then
|
2008-10-21 16:25:06 +02:00
|
|
|
local w = math.min(data[c].width, c:geometry().width + 2 * c.border_width)
|
2008-09-29 16:49:18 +02:00
|
|
|
c.titlebar:geometry({ width = w })
|
|
|
|
else
|
2008-10-21 16:25:06 +02:00
|
|
|
local w = math.min(data[c].width, c:geometry().height + 2 * c.border_width)
|
2008-09-29 16:49:18 +02:00
|
|
|
c.titlebar:geometry({ height = w })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if capi.client.focus == c then
|
|
|
|
c.titlebar.fg = data[c].fg_focus
|
|
|
|
c.titlebar.bg = data[c].bg_focus
|
|
|
|
if closef then closef.visible = true end
|
|
|
|
if close then close.visible = false end
|
|
|
|
else
|
|
|
|
c.titlebar.fg = data[c].fg
|
|
|
|
c.titlebar.bg = data[c].bg
|
|
|
|
if closef then closef.visible = false end
|
|
|
|
if close then close.visible = true end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Remove a titlebar from a client.
|
|
|
|
-- @param c The client.
|
|
|
|
function remove(c)
|
|
|
|
c.titlebar = nil
|
|
|
|
data[c] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Register standards hooks
|
|
|
|
hooks.focus.register(update)
|
|
|
|
hooks.unfocus.register(update)
|
|
|
|
hooks.property.register(update)
|
|
|
|
hooks.unmanage.register(remove)
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|