.config/awesome/rc.lua

This commit is contained in:
Tom Willemsen 2012-10-03 02:47:17 +02:00
parent df6be90649
commit b4e8c45e18
3 changed files with 153 additions and 130 deletions

67
.config/awesome/ext.lua Normal file
View file

@ -0,0 +1,67 @@
local client=client
local awful=awful
local pairs=pairs
local table=table
module("ext")
-- Returns true if all pairs in table1 are present in table2
function match(table1, table2)
for k, v in pairs(table1) do
if table[k] ~= v and not table2[k]:find(v) then
return false
end
end
return true
end
--- Spawns cmd if no client can be found matching properties
-- If such a client can be found, pop to first tag where it is
-- visible, and give it focus
function run_or_raise(cmd, properties)
local clients = client.get()
local focused = awful.client.next(0)
local findex = 0
local matched_clients = { }
local n = 0
for i, c in pairs(clients) do
-- make an array of matched clients
if match(properties, c) then
n = n + 1
matched_clients[n] = c
if n == focused then
findex = n
end
end
end
if n > 0 then
local c = matched_clients[1]
-- if the focused window matched switch focus to next in list
if 0 < findex and findex < n then
c = matched_clients[findex + 1]
end
local ctags = c:tags()
if table.getn(ctags) == 0 then
-- ctags is empty, show client on current tag
local curtag = awful.tag.selected()
awful.client.movetotag(curtag, c)
else
-- Otherwise, pop to first tag client is visible on
awful.tag.viewonly(ctags[1])
end
-- And then focus the client
client.focus = c
c:raise()
awful.screen.focus(c.screen)
return
end
awful.util.spawn(cmd)
end

73
.config/awesome/oni.lua Normal file
View file

@ -0,0 +1,73 @@
local awful = awful
local beautiful = beautiful
local client = client
local ext = require("ext")
local lfs = require("lfs")
local pairs = pairs
local string = string
local table = table
local widget = widget
module("oni")
local maildirfmt = "/home/slash/documents/mail/%s/inbox/new/"
function mailcount(account)
local i = 0
local dir = string.format(maildirfmt, account)
for file in lfs.dir(dir) do
if file ~= "." and file ~= ".." then
i = i + 1
end
end
return i
end
local function showmail(name)
awful.util.spawn("emacsclient -e '(oni:view-mail \"" .. name .. "\")'")
end
function mailcount_widgets(label, account, name)
widgets = {}
widgets.label = widget({ type = "textbox" })
widgets.label.text = string.format(" %s: ", label)
widgets.count = widget({ type = "textbox" })
widgets.count.text = string.format(" %d ", mailcount(account))
widgets.count.bg = beautiful.bg_focus
widgets.count:buttons(
awful.util.table.join(
awful.button({ }, 1, function (c) showmail(name) end)))
return widgets
end
function focus_raise(direction)
awful.client.focus.bydirection(direction)
if client.focus then client.focus:raise() end
end
function ror_browser()
ext.run_or_raise("conkeror", { class = "Conkeror" })
end
function ror_editor()
ext.run_or_raise("emacsclient -c -a emacs", { class = "Emacs" })
end
function ror_term()
ext.run_or_raise("urxvt", { class = "URxvt" })
end
function run_browser()
awful.util.spawn("conkeror")
end
function run_editor()
awful.util.spawn("emacsclient -c -a emacs")
end
function run_term()
awful.util.spawn("urxvt")
end

View file

@ -4,12 +4,9 @@ require("awful.rules")
require("beautiful")
require("bowl")
require("keychain")
require("lfs")
require("naughty")
oni = { } -- Container for custom functions.
oni.maildirfmt = "/home/slash/documents/mail/%s/inbox/new/"
require("ext")
require("oni")
--- Error handling
-- Check if awesome encountered an error during startup and fell back to
@ -35,111 +32,6 @@ do
end)
end
--- Functions
function oni.focus_raise(direction)
awful.client.focus.bydirection(direction)
if client.focus then client.focus:raise() end
end
function oni.mailcount(account)
local i = 0
local dir = string.format(oni.maildirfmt, account)
for file in lfs.dir(dir) do
if file ~= "." and file ~= ".." then
i = i + 1
end
end
return i
end
function oni.mailcount_text()
return string.format(" ryu: %d aet: %d gmail: %d 9f: %d --",
oni.mailcount("ryuslash.org"),
oni.mailcount("aethon"),
oni.mailcount("gmail"),
oni.mailcount("ninthfloor"))
end
function oni.mailcount_widgets(label, account, name)
widgets = {}
widgets.label = widget({ type = "textbox" })
widgets.label.text = string.format(" %s: ", label)
widgets.count = widget({ type = "textbox" })
widgets.count.text = string.format(" %d ", oni.mailcount(account))
widgets.count.bg = beautiful.bg_focus
widgets.count:buttons(
awful.util.table.join(
awful.button({ }, 1,
function (c)
awful.util.spawn("emacsclient -e '(oni:view-mail \"" .. name .. "\")'")
end)))
return widgets
end
-- Returns true if all pairs in table1 are present in table2
function oni.match(table1, table2)
for k, v in pairs(table1) do
if table[k] ~= v and not table2[k]:find(v) then
return false
end
end
return true
end
--- Spawns cmd if no client can be found matching properties
-- If such a client can be found, pop to first tag where it is
-- visible, and give it focus
function oni.run_or_raise(cmd, properties)
local clients = client.get()
local focused = awful.client.next(0)
local findex = 0
local matched_clients = { }
local n = 0
for i, c in pairs(clients) do
-- make an array of matched clients
if oni.match(properties, c) then
n = n + 1
matched_clients[n] = c
if n == focused then
findex = n
end
end
end
if n > 0 then
local c = matched_clients[1]
-- if the focused window matched switch focus to next in list
if 0 < findex and findex < n then
c = matched_clients[findex + 1]
end
local ctags = c:tags()
if table.getn(ctags) == 0 then
-- ctags is empty, show client on current tag
local curtag = awful.tag.selected()
awful.client.movetotag(curtag, c)
else
-- Otherwise, pop to first tag client is visible on
awful.tag.viewonly(ctags[1])
end
-- And then focus the client
client.focus = c
c:raise()
awful.screen.focus(c.screen)
return
end
awful.util.spawn(cmd)
end
-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init("/home/slash/.config/awesome/themes/custom/theme.lua")
@ -347,29 +239,20 @@ globalkeys = awful.util.table.join(
sub({ }, "f", function () oni.focus_raise("right") end),
sub({ }, "b", function () oni.focus_raise("left") end),
sub({ }, "n", function () oni.focus_raise("down") end),
sub({ }, "p", function () oni.focus_raise("up") end),
sub({ }, "e",
function () oni.run_or_raise("emacsclient -c -a emacs",
{ class = "Emacs" }) end),
sub({ "Shift", }, "e",
function () awful.util.spawn("emacsclient -c -a emacs") end),
sub({ }, "c",
function () oni.run_or_raise("urxvt",
{ class = "URxvt" }) end),
sub({ "Shift", }, "c",
function () awful.util.spawn("urxvt") end),
sub({ }, "w",
function () oni.run_or_raise("conkeror",
{ class = "Conkeror" }) end),
sub({ "Shift", }, "w",
function () awful.util.spawn("conkeror") end) }),
sub({ }, "p", function () oni.focus_raise("up") end) }),
awful.key({ "Control", "Mod1" }, "l",
function () awful.util.spawn("i3lock -c 000000") end),
awful.key({ "Mod4", }, "c", oni.ror_term),
awful.key({ "Mod4", "Shift" }, "c", oni.run_term),
awful.key({ "Mod4", }, "e", oni.ror_editor),
awful.key({ "Mod4", "Shift" }, "e", oni.run_editor),
awful.key({ "Mod4", }, "w", oni.ror_browser),
awful.key({ "Mod4", "Shift" }, "w", oni.run_browser),
awful.key({ modkey, }, "Left", awful.tag.viewprev ),
awful.key({ modkey, }, "Right", awful.tag.viewnext ),
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
-- awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),