awful: add titlebar support

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-29 15:44:09 +02:00
parent 731b309c85
commit 8649c6cb8c
6 changed files with 59 additions and 2 deletions

View file

@ -22,8 +22,7 @@ include_directories(
${AWESOME_OPTIONAL_INCLUDE_DIRS})
set(AWE_LUA_FILES
${SOURCE_DIR}/lib/tabulous.lua
${SOURCE_DIR}/lib/awful.lua)
${SOURCE_DIR}/lib/tabulous.lua)
set(AWE_CONF_FILE_DEFAULT ${BUILD_DIR}/awesomerc.lua)
set(AWE_CONF_FILE rc.lua)

View file

@ -261,6 +261,7 @@ set(AWESOME_ICON_PATH ${AWESOME_DATA_PATH}/icons)
set(AWESOME_CONFIGURE_FILES
config.h.in
awesomerc.lua.in
lib/awful.lua.in
awesome-version-internal.h.in
awesome.doxygen.in)

View file

@ -290,6 +290,7 @@ function hook_focus(c)
if not awful.client.ismarked(c) then
c.border_color = border_focus
end
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
end
-- Hook function to execute when unfocusing a client.
@ -297,6 +298,7 @@ function hook_unfocus(c)
if not awful.client.ismarked(c) then
c.border_color = border_normal
end
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
end
-- Hook function to execute when marking a client
@ -321,6 +323,9 @@ end
function hook_manage(c)
-- Set floating placement to be smart!
c.floating_placement = "smart"
-- Add a titlebar
c.titlebar = awful.titlebar.new({ fg = fg, bg = bg })
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
-- Add mouse bindings
c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))
c:mouse_add(mouse({ modkey }, 1, function (c) c:mouse_move() end))
@ -368,6 +373,11 @@ function hook_timer ()
-- mytextbox.text = " " .. os.date() .. " "
end
function hook_titleupdate (c)
-- Update titlebar
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
end
-- Set up some hooks
awful.hooks.focus(hook_focus)
awful.hooks.unfocus(hook_unfocus)
@ -377,4 +387,5 @@ awful.hooks.manage(hook_manage)
awful.hooks.mouseover(hook_mouseover)
awful.hooks.arrange(hook_arrange)
awful.hooks.timer(1, hook_timer)
awful.hooks.titleupdate(hook_titleupdate)
-- }}}

BIN
icons/titlebar/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

BIN
icons/titlebar/closer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

View file

@ -26,6 +26,8 @@ local screen = screen
local client = client
local tag = tag
local mouse = mouse
local titlebar = titlebar
local widget = widget
local os = os
local table = table
local hooks = hooks
@ -43,6 +45,7 @@ P.screen = {}
P.layout = {}
P.client = {}
P.tag = {}
P.titlebar = {}
P.widget = {}
P.widget.taglist = {}
P.widget.taglist.label = {}
@ -836,4 +839,47 @@ function P.widget.tasklist.label.currenttags(c, screen, bg_focus, fg_focus)
end
end
--- Create a standard titlebar.
-- @param args Arguments.
-- fg: the foreground color,
-- bg: the background color.
-- text_align: the title text alignment.
-- @return A brand new titlebar.
function P.titlebar.new(args)
local tb = titlebar(args)
tb:widget_add(widget({ type = "textbox", name = "title" }))
local close_button= widget({ type = "textbox", name = "close", align = "right"})
close_button:mouse_add(mouse({ }, 1, function (t) t:client_get():kill() end))
tb:widget_add(close_button)
return tb
end
--- Update a titlebar. This should be called in some hooks.
-- @param c The client to update.
-- @param bg The background color for normal client.
-- @param fg The foreground color for normal client.
-- @param bg_focus The background color for focused client.
-- @param fg_focus The foreground color for focused client.
function P.titlebar.update(c, bg, fg, bg_focus, fg_focus)
if c.titlebar then
local widgets = c.titlebar:widget_get()
if widgets.title then
widgets.title.text = " " .. P.escape(c.name)
end
if client.focus_get() == c then
c.titlebar.bg = bg_focus
c.titlebar.fg = fg_focus
if widgets.close then
widgets.close.text = "<bg image=\"@AWESOME_ICON_PATH@/titlebar/closer.png\" resize=\"true\"/>"
end
else
c.titlebar.bg = bg
c.titlebar.fg = fg
if widgets.close then
widgets.close.text = "<bg image=\"@AWESOME_ICON_PATH@/titlebar/close.png\" resize=\"true\"/>"
end
end
end
end
return P