From 0228c95a0b433216382334194852fb0e70da82ff Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Thu, 13 Sep 2012 01:57:14 +0200 Subject: .config/awesome/rc.lua --- .config/awesome/rc.lua | 99 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 11 deletions(-) (limited to '.config/awesome') 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] } }, } -- }}} -- cgit v1.2.3-54-g00ecf