summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-05-04 18:24:41 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-05-04 18:41:57 +0200
commit390a228ae47d5c9d6fac0647d80f83d221ac4663 (patch)
tree79ec258261511d3eb8d27b7e7f052606c140eb6e
parent760cdb1f1bc6b0b5c11ce06ee2be9f0025191e6b (diff)
downloaddotfiles-390a228ae47d5c9d6fac0647d80f83d221ac4663.tar.gz
dotfiles-390a228ae47d5c9d6fac0647d80f83d221ac4663.tar.bz2
dotfiles-390a228ae47d5c9d6fac0647d80f83d221ac4663.zip
awesome: Add switcher (Alt-Tab like)
-rw-r--r--.config/awesome/awesome.lua25
-rw-r--r--.config/awesome/switcher.lua111
2 files changed, 128 insertions, 8 deletions
diff --git a/.config/awesome/awesome.lua b/.config/awesome/awesome.lua
index 4b069c4..f0b3e6d 100644
--- a/.config/awesome/awesome.lua
+++ b/.config/awesome/awesome.lua
@@ -9,6 +9,8 @@ require("naughty")
-- Dynamic tagging
require("eminent")
+require("switcher")
+
-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init(os.getenv("HOME") .. "/.local/share/awesome/themes/zenburn/theme.lua")
@@ -187,6 +189,14 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, }, "Right", awful.tag.viewnext ),
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
+ awful.key({ modkey, }, "Tab", function()
+ switcher.start( 1, "Super_L", "Tab", "ISO_Left_Tab")
+ end),
+
+ awful.key({ modkey, }, "ISO_Left_Tab", function()
+ switcher.start(-1, "Super_L", "Tab", "ISO_Left_Tab")
+ end),
+
awful.key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
@@ -205,13 +215,6 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
- awful.key({ modkey, }, "Tab",
- function ()
- awful.client.focus.history.previous()
- if client.focus then
- client.focus:raise()
- end
- end),
-- Standard program
awful.key({ modkey, }, "x", function () awful.util.spawn(terminal) end),
@@ -362,10 +365,16 @@ client.add_signal("manage", function (c, startup)
awful.placement.no_offscreen(c)
end
end
+ c:add_signal("marked", function(c) c.border_color = beautiful.border_marked end)
+ c:add_signal("unmarked", function(c)
+ if client.focus ~= c then
+ c.border_color = beautiful.border_normal
+ end
+ end)
end)
client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}
--- vim: softtabstop=4:expandtab
+-- vim: softtabstop=4:expandtab:shiftwidth=4
diff --git a/.config/awesome/switcher.lua b/.config/awesome/switcher.lua
new file mode 100644
index 0000000..6066879
--- /dev/null
+++ b/.config/awesome/switcher.lua
@@ -0,0 +1,111 @@
+----------------------------------------------------------------
+-- ALt-Tab-style switcher.
+----------------------------------------------------------------
+-- Benjamin Franzke <benjaminfranzke@googlemail.com
+-- Licensed under the GPL-3
+----------------------------------------------------------------
+-- To use this module add:
+-- require("switcher")
+-- to the top of your rc.lua.
+--
+-- And add the following to your global keybindings:
+-- awful.key({ modkey, }, "Tab", function()
+-- switcher.start( 1, "Super_L", "Tab", "ISO_Left_Tab")
+-- end),
+--
+-- awful.key({ modkey, }, "ISO_Left_Tab", function()
+-- switcher.start(-1, "Super_L", "Tab", "ISO_Left_Tab")
+-- end),
+--
+----------------------------------------------------------------
+
+-- Grab environment
+local ipairs = ipairs
+local pairs = pairs
+local awful = require("awful")
+local naughty = require("naughty")
+local table = table
+local capi = {
+ tag = tag,
+ mouse = mouse,
+ client = client,
+ screen = screen,
+ wibox = wibox,
+ timer = timer,
+ keygrabber = keygrabber,
+}
+
+-- Switcher: Alt-Tab-like switching
+module("switcher")
+
+local state = {
+ switcher_idx = 0,
+ key_mod = "Super_L",
+ key_next = "Tab",
+ key_prev = "ISO_Left_Tab",
+}
+
+local function switcher_next(rel)
+
+ local cla = awful.client.focus.history.get(capi.mouse.screen, state.switcher_idx)
+ local cli = awful.client.focus.history.get(capi.mouse.screen, state.switcher_idx + rel)
+
+ awful.client.unmark(cla)
+
+ state.switcher_idx = state.switcher_idx + rel
+
+ if not cli then
+ if rel > 0 then
+ state.switcher_idx = rel
+ elseif rel < 0 then
+ local i = 0
+ local c = awful.client.focus.history.get(capi.mouse.screen, 0)
+ while c do
+ i = i + 1
+ c = awful.client.focus.history.get(capi.mouse.screen, i)
+ end
+ state.switcher_idx = i - rel
+ end
+
+ cli = awful.client.focus.history.get(capi.mouse.screen, switcher_idx)
+ end
+
+ cli:raise()
+
+ awful.client.mark(cli)
+end
+
+local function switcher_end()
+ local c = awful.client.focus.history.get(capi.mouse.screen, state.switcher_idx)
+ state.switcher_idx = 0
+ c:raise()
+ awful.client.unmark(c)
+ capi.client.focus = c
+end
+
+function switch(modifiers, key, event)
+ if event == "press" and key == state.key_next then
+ switcher_next(1)
+ elseif event == "press" and key == state.key_prev then
+ switcher_next(-1)
+ end
+
+ if event == "release" and key == state.key_mod then
+ switcher_end()
+ capi.keygrabber.stop()
+ return false
+ end
+
+ return true
+end
+
+function start(rel, key_mod, key_next, key_prev)
+ state.switcher_idx = 0
+ state.key_mod = key_mod
+ state.key_next = key_next
+ state.key_prev = key_prev
+
+ switcher_next(rel)
+ capi.keygrabber.run(switch)
+end
+