Permalink
Browse files

Trying out revelation plugin

  • Loading branch information...
1 parent 4dfc019 commit 76720083e584a30f1f167686caf2ced4b86dbe69 @AndrewRadev committed Sep 28, 2010
Showing with 150 additions and 0 deletions.
  1. +4 −0 rc.lua
  2. +146 −0 revelation.lua
View
@@ -18,6 +18,8 @@ require("vicious")
require ("lib.ror")
local run_or_raise = lib.ror.run_or_raise
+require("revelation")
+
-- {{{ Variable definitions
local spawn = awful.util.spawn
@@ -253,6 +255,8 @@ globalkeys = awful.util.table.join(
-- screengrabbing
awful.key({ modkey }, "F12", function () spawn("scrot -e 'mv $f /home/andrew/images/shots/'") end),
+ awful.key({ modkey }, "e", revelation.revelation),
+
awful.key({ modkey }, "x",
function ()
awful.prompt.run({ prompt = "Run Lua code: " },
View
@@ -0,0 +1,146 @@
+-- revelation.lua
+-- This is a modification of the original awesome library that implemented
+-- expose like behavior.
+--
+-- @author Perry Hargrave (aka bioe007)
+-- perry)dot(hargrave)at(gmail.com
+-- awesome v3.4-20-g8e02306 (Closing In)
+--
+-- original file information:
+-- @author Espen Wiborg <espenhw@grumblesmurf.org>
+-- @author Julien Danjou <julien@danjou.info>
+-- @copyright 2008 Espen Wiborg, Julien Danjou
+--
+-- USE:
+-- 1. save this file as $HOME/.config/awesome/revelation.lua
+-- 2. put near the top of your rc.lua
+-- require("revelation")
+-- 3. make a global keybinding for revelation in your rc.lua:
+-- awful.key({ modkey }, "e", revelation.revelation)
+-- 4. reload rc.lua and try the keybinding. It should bring all clients to the
+-- current tag and set the layout to fair. You can focus clients with
+-- cursor(arrow) or 'hjkl' keys then press <enter> to select or <escape> to
+-- abort
+--
+-- NOTES: I have dumbed this down to simply merge all clients to the current tag
+-- the class filter is of little use (to me?) but I could reimplement it
+-- if anyone is interested
+--
+local math = math
+local table = table
+local pairs = pairs
+local button = button
+local awful = awful
+local capi =
+{
+ tag = tag,
+ client = client,
+ keygrabber = keygrabber,
+ mouse = mouse,
+ screen = screen
+}
+local print = print
+--- Expose implementation
+module("revelation")
+
+--{{{ clients
+-- a now unused filter to grab clients based on their class
+--
+-- @param class the class string to find
+-- @s the screen
+function clients(class, s)
+ local clients
+ if class then
+ clients = {}
+ for k, c in pairs(capi.client.get(s)) do
+ if c.class == class then
+ table.insert(clients, c)
+ end
+ end
+ else
+ clients = capi.client.get(s)
+ end
+ return clients
+end
+--}}}
+
+--{{{ selectfn
+-- executed when user selects a client from expose view
+--
+-- @param restore function to reset the current tags view
+function selectfn(restore)
+ return function(c)
+ restore()
+ -- Pop to client tag
+ awful.tag.viewonly(c:tags()[1], c.screen)
+ -- Focus and raise
+ capi.client.focus = c
+ c:raise()
+ end
+end
+--}}}
+
+--{{{ keyboardhandler
+-- Returns keyboardhandler.
+-- Arrow keys and 'hjkl' move focus, Return selects, Escape cancels. Ignores
+-- modifiers.
+--
+-- @param restore a function to call if the user presses escape
+function keyboardhandler (restore)
+ return function (mod, key, event)
+ if event ~= "press" then return true end
+ -- translate vim-style home keys to directions
+ if key == "j" or key == "k" or key == "h" or key == "l" then
+ if key == "j" then
+ key = "Down"
+ elseif key == "k" then
+ key = "Up"
+ elseif key == "h" then
+ key = "Left"
+ elseif key == "l" then
+ key = "Right"
+ end
+ end
+
+ --
+ if key == "Escape" then
+ restore()
+ return false
+ elseif key == "Return" then
+ selectfn(restore)(capi.client.focus)
+ return false
+ elseif key == "Left" or key == "Right" or
+ key == "Up" or key == "Down" then
+ awful.client.focus.bydirection(key:lower())
+ end
+ return true
+ end
+end
+--}}}
+
+--{{{ revelation
+-- Implement Expose (from Mac OS X).
+-- @param class The class of clients to expose, or nil for all clients.
+-- @param fn A binary function f(t, n) to set the layout for tag t for n
+-- clients, or nil for the default layout.
+-- @param s The screen to consider clients of, or nil for "current screen".
+function revelation(class, fn, s)
+ local scr = s or capi.mouse.screen
+ local t = capi.screen[scr]:tags()[1]
+ local oldlayout = awful.tag.getproperty( t, "layout" )
+
+ awful.tag.viewmore( capi.screen[scr]:tags(), t.screen )
+ awful.layout.set(awful.layout.suit.fair,t)
+
+ local function restore()
+ awful.layout.set(oldlayout,t)
+ awful.tag.viewonly(t)
+
+ capi.keygrabber.stop()
+ end
+
+ capi.keygrabber.run(keyboardhandler(restore))
+end
+--}}}
+
+-- vim:set ft=lua fdm=marker ts=4 sw=4 et ai si: --

0 comments on commit 7672008

Please sign in to comment.