commit 70901c8a9f48ca64210dd2d5ec6b051b3f000543 Author: Perry Hargrave Date: Tue Aug 23 14:37:11 2011 -0700 Initialize revelation as a module diff --git a/README.md b/README.md new file mode 100644 index 0000000..7209fdd --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# revelation.lua + +Provides Mac OSX like 'Expose' view of all clients. + +## Use + (From user's awesome configuration directory, usually ~/.config/awesome) + + 1. Clone repository: + + git clone https://bioe007@github.com/bioe007/awesome-revelation.git + + 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) + + **NOTE:** Always double check this key binding syntax against the version of + Awesome that you are using. + + 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__ or __hjkl__ keys then press __Enter__ to + select or __Escape__ to abort. + + This is a modification of the original awesome library that implemented + expose like behavior. + +## Credits + + * Perry Hargrave resixian@gmail.com + * Espen Wiborg espenhw@grumblesmurf.org + * Julien Danjou julien@danjou.info + +## License + (c) 2008 Espen Wiborg, Julien Danjou diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..16f3edc --- /dev/null +++ b/init.lua @@ -0,0 +1,120 @@ +-- revelation.lua +-- +-- Library that implements Expose like behavior. +-- +-- @author Perry Hargrave resixian@gmail.com +-- @author Espen Wiborg espenhw@grumblesmurf.org +-- @author Julien Danjou julien@danjou.info +-- +-- @copyright 2008 Espen Wiborg, Julien Danjou +-- + +local awful = awful +local pairs = pairs +local setmetatable = setmetatable +local table = table +local capi = { + tag = tag, + client = client, + keygrabber = keygrabber, + mouse = mouse, + screen = screen +} + +module("revelation") + +-- FIXME: 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 + +-- 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 + +-- Arrow keys and 'hjkl' move focus, Return selects, Escape cancels. Ignores +-- modifiers. +-- +-- @param restore a function to call if the user presses escape +-- @return keyboardhandler +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 + +-- Implement Exposé (ala 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 expose(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 + +setmetatable(_M, { __call = function(_, ...) return expose(...) end })