awful: add beautiful support

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-06 15:15:13 +02:00
parent f28fac6107
commit 1755dd51fe
2 changed files with 91 additions and 55 deletions

View File

@ -5,12 +5,10 @@ require("awful")
require("tabulous") require("tabulous")
require("beautiful") require("beautiful")
beautiful.init("@AWESOME_THEMES_PATH@/default")
-- Uncomment this to activate autotabbing
-- tabulous.autotab_start()
-- {{{ Variable definitions -- {{{ Variable definitions
-- This is a file path to a theme file which will defines colors.
theme_path = "@AWESOME_THEMES_PATH@/default"
-- This is used later as the default terminal to run. -- This is used later as the default terminal to run.
terminal = "xterm" terminal = "xterm"
@ -35,24 +33,37 @@ layouts =
"floating" "floating"
} }
-- Table of clients that should be set floating -- Table of clients that should be set floating.
floatings = floatings =
{ {
["mplayer"] = true, ["mplayer"] = true,
["pinentry"] = true ["pinentry"] = true
} }
-- Define if we want to use titlebar on all applications -- Define if we want to use titlebar on all applications.
use_titlebar = false use_titlebar = false
-- }}} -- }}}
-- {{{ Initialization
-- Initialize theme (colors).
beautiful.init(theme_path)
-- Register theme in awful.
-- This allows to not pass plenty of arguments to each function
-- to inform it about colors we want it to draw.
awful.beautiful.register(beautiful)
-- Uncomment this to activate autotabbing
-- tabulous.autotab_start()
-- }}}
-- {{{ Tags -- {{{ Tags
-- Define tags table -- Define tags table.
tags = {} tags = {}
for s = 1, screen.count() do for s = 1, screen.count() do
-- Each screen has its own tag table -- Each screen has its own tag table.
tags[s] = {} tags[s] = {}
-- Create 9 tags per screen -- Create 9 tags per screen.
for tagnumber = 1, 9 do for tagnumber = 1, 9 do
tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] }) tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
-- Add tags to screen one by one -- Add tags to screen one by one
@ -73,14 +84,14 @@ mytaglist:mouse_add(mouse({}, 3, function (object, tag) tag.selected = not tag.s
mytaglist:mouse_add(mouse({ modkey }, 3, function (object, tag) awful.client.toggletag(tag) end)) mytaglist:mouse_add(mouse({ modkey }, 3, function (object, tag) awful.client.toggletag(tag) end))
mytaglist:mouse_add(mouse({ }, 4, awful.tag.viewnext)) mytaglist:mouse_add(mouse({ }, 4, awful.tag.viewnext))
mytaglist:mouse_add(mouse({ }, 5, awful.tag.viewprev)) mytaglist:mouse_add(mouse({ }, 5, awful.tag.viewprev))
function mytaglist.label(t) return awful.widget.taglist.label.all(t, beautiful.bg_focus, beautiful.fg_focus, beautiful.bg_urgent, beautiful.fg_urgent) end mytaglist.label = awful.widget.taglist.label.all
-- Create a tasklist widget -- Create a tasklist widget
mytasklist = widget({ type = "tasklist", name = "mytasklist" }) mytasklist = widget({ type = "tasklist", name = "mytasklist" })
mytasklist:mouse_add(mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end)) mytasklist:mouse_add(mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end))
mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focusbyidx(1) end)) mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focusbyidx(1) end))
mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focusbyidx(-1) end)) mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focusbyidx(-1) end))
function mytasklist.label(c, screen) return awful.widget.tasklist.label.currenttags(c, screen, beautiful.bg_focus, beautiful.fg_focus, beautiful.bg_urgent, beautiful.fg_urgent) end mytasklist.label = awful.widget.tasklist.label.currenttags
-- Create a textbox widget -- Create a textbox widget
mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" }) mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" })
@ -210,10 +221,10 @@ keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -
-- Prompt -- Prompt
keybinding({ modkey }, "F1", function () keybinding({ modkey }, "F1", function ()
awful.prompt({ prompt = "Run: ", cursor_fg = beautiful.fg_focus, cursor_bg = beautiful.bg_focus }, mypromptbox, awful.spawn, awful.completion.bash) awful.prompt({ prompt = "Run: " }, mypromptbox, awful.spawn, awful.completion.bash)
end):add() end):add()
keybinding({ modkey }, "F4", function () keybinding({ modkey }, "F4", function ()
awful.prompt({ prompt = "Run Lua code: ", cursor_fg = beautiful.fg_focus, cursor_bg = beautiful.bg_focus }, mypromptbox, awful.eval) awful.prompt({ prompt = "Run Lua code: " }, mypromptbox, awful.eval)
end):add() end):add()
--- Tabulous, tab manipulation --- Tabulous, tab manipulation
@ -315,11 +326,7 @@ function hook_manage(c)
c.floating_placement = "smart" c.floating_placement = "smart"
if use_titlebar then if use_titlebar then
-- Add a titlebar -- Add a titlebar
awful.titlebar.add(c, { fg = beautiful.fg_normal, awful.titlebar.add(c, { modkey = modkey })
bg = beautiful.bg_normal,
fg_focus = beautiful.fg_focus,
bg_focus = beautiful.bg_focus,
modkey = modkey })
end end
-- Add mouse bindings -- Add mouse bindings
c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end)) c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))

View File

@ -48,7 +48,11 @@ function ObjectTable.new()
return o return o
end end
-- Various structure -- Local variable handling theme
local theme = {}
-- Various public structures
beautiful = {}
hooks = {} hooks = {}
hooks.user = {} hooks.user = {}
prompt = {} prompt = {}
@ -783,18 +787,18 @@ local function prompt_text_with_cursor(text, text_color, cursor_color, cursor_po
end end
--- Run a prompt in a box. --- Run a prompt in a box.
-- @param args A table with optional arguments: cursor_fg, cursor_bg, prompt. -- @param args A table with optional arguments: fg_cursor, bg_cursor, prompt.
-- @param textbox The textbox to use for the prompt. -- @param textbox The textbox to use for the prompt.
-- @param exe_callback The callback function to call with command as argument when finished. -- @param exe_callback The callback function to call with command as argument when finished.
-- @param completion_callback The callback function to call to get completion. -- @param completion_callback The callback function to call to get completion.
function prompt(args, textbox, exe_callback, completion_callback) function prompt(args, textbox, exe_callback, completion_callback)
if not args then return end if not args then args = {} end
local command = "" local command = ""
local command_before_comp local command_before_comp
local cur_pos_before_comp local cur_pos_before_comp
local prompt = args.prompt or "" local prompt = args.prompt or ""
local inv_col = args.cursor_fg or "black" local inv_col = args.fg_cursor or theme.fg_focus or "black"
local cur_col = args.cursor_bg or "white" local cur_col = args.bg_cursor or theme.bg_focus or "white"
-- The cursor position -- The cursor position
local cur_pos = 1 local cur_pos = 1
-- The completion element to use on completion request. -- The completion element to use on completion request.
@ -967,12 +971,18 @@ end
-- It returns the tag name and set a special -- It returns the tag name and set a special
-- foreground and background color for selected tags. -- foreground and background color for selected tags.
-- @param t The tag. -- @param t The tag.
-- @param bg_focus The background color for selected tag. -- @param args The arguments table.
-- @param fg_focus The foreground color for selected tag. -- bg_focus The background color for selected tag.
-- @param bg_urgent The background color for urgent tags. -- fg_focus The foreground color for selected tag.
-- @param fg_urgent The foreground color for urgent tags. -- bg_urgent The background color for urgent tags.
-- fg_urgent The foreground color for urgent tags.
-- @return A string to print. -- @return A string to print.
function widget.taglist.label.all(t, bg_focus, fg_focus, bg_urgent, fg_urgent) function widget.taglist.label.all(t, args)
if not args then args = {} end
local fg_focus = args.fg_focus or theme.fg_focus
local bg_focus = args.bg_focus or theme.bg_focus
local fg_urgent = args.fg_urgent or theme.fg_urgent
local bg_urgent = args.bg_urgent or theme.bg_urgent
local text local text
local background = "" local background = ""
local sel = capi.client.focus_get() local sel = capi.client.focus_get()
@ -1003,7 +1013,12 @@ function widget.taglist.label.all(t, bg_focus, fg_focus, bg_urgent, fg_urgent)
return text return text
end end
local function widget_tasklist_label_common(c, bg_focus, fg_focus, bg_urgent, fg_urgent) local function widget_tasklist_label_common(c, args)
if not args then args = {} end
local fg_focus = args.fg_focus or theme.fg_focus
local bg_focus = args.bg_focus or theme.bg_focus
local fg_urgent = args.fg_urgent or theme.fg_urgent
local bg_urgent = args.bg_urgent or theme.bg_urgent
local text = "" local text = ""
if c.floating then if c.floating then
text = "<bg image=\"@AWESOME_ICON_PATH@/tasklist/floatingw.png\" align=\"right\"/>" text = "<bg image=\"@AWESOME_ICON_PATH@/tasklist/floatingw.png\" align=\"right\"/>"
@ -1024,13 +1039,14 @@ end
-- It also puts a special icon for floating windows. -- It also puts a special icon for floating windows.
-- @param c The client. -- @param c The client.
-- @param screen The screen we are drawing on. -- @param screen The screen we are drawing on.
-- @param bg_focus The background color for focused client. -- @param args The arguments table.
-- @param fg_focus The foreground color for focused client. -- bg_focus The background color for focused client.
-- @param bg_urgent The background color for urgent clients. -- fg_focus The foreground color for focused client.
-- @param fg_urgent The foreground color for urgent clients. -- bg_urgent The background color for urgent clients.
-- @return A string to pring. -- fg_urgent The foreground color for urgent clients.
function widget.tasklist.label.allscreen(c, screen, bg_focus, fg_focus, bg_urgent, fg_urgent) -- @return A string to print.
return widget_tasklist_label_common(c, bg_focus, fg_focus, bg_urgent, fg_urgent) function widget.tasklist.label.allscreen(c, screen, args)
return widget_tasklist_label_common(c, args)
end end
--- Return labels for a tasklist widget with clients from all tags. --- Return labels for a tasklist widget with clients from all tags.
@ -1039,15 +1055,16 @@ end
-- It also puts a special icon for floating windows. -- It also puts a special icon for floating windows.
-- @param c The client. -- @param c The client.
-- @param screen The screen we are drawing on. -- @param screen The screen we are drawing on.
-- @param bg_focus The background color for focused client. -- @param args The arguments table.
-- @param fg_focus The foreground color for focused client. -- bg_focus The background color for focused client.
-- @param bg_urgent The background color for urgent clients. -- fg_focus The foreground color for focused client.
-- @param fg_urgent The foreground color for urgent clients. -- bg_urgent The background color for urgent clients.
-- @return A string to pring. -- fg_urgent The foreground color for urgent clients.
function widget.tasklist.label.alltags(c, screen, bg_focus, fg_focus, bg_urgent, fg_urgent) -- @return A string to print.
function widget.tasklist.label.alltags(c, screen, args)
-- Only print client on the same screen as this widget -- Only print client on the same screen as this widget
if c.screen ~= screen then return end if c.screen ~= screen then return end
return widget_tasklist_label_common(c, bg_focus, fg_focus, bg_urgent, fg_urgent) return widget_tasklist_label_common(c, args)
end end
--- Return labels for a tasklist widget with clients from currently selected tags. --- Return labels for a tasklist widget with clients from currently selected tags.
@ -1056,17 +1073,18 @@ end
-- It also puts a special icon for floating windows. -- It also puts a special icon for floating windows.
-- @param c The client. -- @param c The client.
-- @param screen The screen we are drawing on. -- @param screen The screen we are drawing on.
-- @param bg_focus The background color for focused client. -- @param args The arguments table.
-- @param fg_focus The foreground color for focused client. -- bg_focus The background color for focused client.
-- @param bg_urgent The background color for urgent clients. -- fg_focus The foreground color for focused client.
-- @param fg_urgent The foreground color for urgent clients. -- bg_urgent The background color for urgent clients.
-- @return A string to pring. -- fg_urgent The foreground color for urgent clients.
function widget.tasklist.label.currenttags(c, screen, bg_focus, fg_focus, bg_urgent, fg_urgent) -- @return A string to print.
function widget.tasklist.label.currenttags(c, screen, args)
-- Only print client on the same screen as this widget -- Only print client on the same screen as this widget
if c.screen ~= screen then return end if c.screen ~= screen then return end
for k, t in pairs(capi.tag.get(screen)) do for k, t in pairs(capi.tag.get(screen)) do
if t.selected and c:istagged(t) then if t.selected and c:istagged(t) then
return widget_tasklist_label_common(c, bg_focus, fg_focus, bg_urgent, fg_urgent) return widget_tasklist_label_common(c, args)
end end
end end
end end
@ -1079,12 +1097,13 @@ end
-- fg_focus: the foreground color for focused window. -- fg_focus: the foreground color for focused window.
-- fg_focus: the background color for focused window. -- fg_focus: the background color for focused window.
function titlebar.add(c, args) function titlebar.add(c, args)
if not args then args = {} end
-- Store colors -- Store colors
titlebar.data[c] = {} titlebar.data[c] = {}
titlebar.data[c].fg = args.fg titlebar.data[c].fg = args.fg or theme.fg_normal
titlebar.data[c].bg = args.bg titlebar.data[c].bg = args.bg or theme.bg_normal
titlebar.data[c].fg_focus = args.fg_focus titlebar.data[c].fg_focus = args.fg_focus or theme.fg_focus
titlebar.data[c].bg_focus = args.bg_focus titlebar.data[c].bg_focus = args.bg_focus or theme.bg_focus
-- Built args -- Built args
local targs = {} local targs = {}
@ -1139,6 +1158,16 @@ function titlebar.remove(c)
titlebar.data[c] = nil titlebar.data[c] = nil
end end
--- Set the beautiful theme if any.
-- @param The beautiful theme.
function beautiful.register(btheme)
if btheme then
theme = btheme
else
theme = {}
end
end
-- Register standards hooks -- Register standards hooks
hooks.arrange.register(tag.history.update) hooks.arrange.register(tag.history.update)