summaryrefslogtreecommitdiffstats
path: root/.config
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-09-13 01:57:14 +0200
committerGravatar Tom Willemsen2012-09-13 01:57:14 +0200
commit0228c95a0b433216382334194852fb0e70da82ff (patch)
tree47c1432b6a48d948332ce90726ec27bd5752811f /.config
parentb08f6026edcc8c7918aa50ad3e830593c055538b (diff)
downloaddotfiles-0228c95a0b433216382334194852fb0e70da82ff.tar.gz
dotfiles-0228c95a0b433216382334194852fb0e70da82ff.zip
.config/awesome/rc.lua
Diffstat (limited to '.config')
-rw-r--r--.config/awesome/rc.lua99
1 files changed, 88 insertions, 11 deletions
diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua
index 12ddae7..099d3c5 100644
--- a/.config/awesome/rc.lua
+++ b/.config/awesome/rc.lua
@@ -9,6 +9,8 @@ require("naughty")
require("bowl")
require("keychain")
+oni = { } -- Container for custom functions.
+
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
@@ -34,6 +36,71 @@ do
end
-- }}}
+function oni.focus_raise(direction)
+ awful.client.focus.bydirection(direction)
+ if client.focus then client.focus:raise() end
+end
+
+-- 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 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 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()
+ return
+ end
+ awful.util.spawn(cmd)
+end
+
-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init("/usr/share/awesome/themes/default/theme.lua")
@@ -196,11 +263,6 @@ root.buttons(awful.util.table.join(
))
-- }}}
-function focus_raise(direction)
- awful.client.focus.bydirection(direction)
- if client.focus then client.focus:raise() end
-end
-
-- {{{ Key bindings
local bind = keychain
local sub = keychain.sub
@@ -215,10 +277,19 @@ globalkeys = awful.util.table.join(
function () awful.screen.focus_relative(1) end),
sub({ "Shift", }, "1",
function () mypromptbox[mouse.screen]:run() end),
- sub({ }, "f", function () focus_raise("right") end),
- sub({ }, "b", function () focus_raise("left") end),
- sub({ }, "n", function () focus_raise("down") end),
- sub({ }, "p", function () focus_raise("up") end) }),
+ 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({ }, "c",
+ function () oni.run_or_raise("urxvt",
+ { class = "URxvt" }) end),
+ sub({ }, "w",
+ function () oni.run_or_raise("conkeror",
+ { class = "Conkeror" }) end) }),
awful.key({ modkey, }, "Left", awful.tag.viewprev ),
awful.key({ modkey, }, "Right", awful.tag.viewnext ),
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
@@ -349,9 +420,15 @@ awful.rules.rules = {
properties = { floating = true } },
{ rule = { class = "gimp" },
properties = { floating = true } },
+ { rule = { class = "Emacs" },
+ properties = { tag = tags[1][1] } },
-- Set Firefox to always map on tags number 2 of screen 1.
- -- { rule = { class = "Firefox" },
- -- properties = { tag = tags[1][2] } },
+ { rule = { class = "Firefox" },
+ properties = { tag = tags[2][1] } },
+ { rule = { class = "Conkeror" },
+ properties = { tag = tags[2][1] } },
+ { rule = { class = "URxvt" },
+ properties = { tag = tags[2][1] } },
}
-- }}}