2011-08-23 23:37:11 +02:00
|
|
|
-- 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
|
|
|
|
--
|
|
|
|
|
2011-12-06 23:59:12 +01:00
|
|
|
local awful = require('awful')
|
2011-10-21 00:26:37 +02:00
|
|
|
local aw_rules = require('awful.rules')
|
2011-08-23 23:37:11 +02:00
|
|
|
local pairs = pairs
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local table = table
|
|
|
|
local capi = {
|
|
|
|
tag = tag,
|
|
|
|
client = client,
|
|
|
|
keygrabber = keygrabber,
|
2011-10-01 23:03:12 +02:00
|
|
|
mousegrabber = mousegrabber,
|
2011-08-23 23:37:11 +02:00
|
|
|
mouse = mouse,
|
|
|
|
screen = screen
|
|
|
|
}
|
|
|
|
|
|
|
|
module("revelation")
|
|
|
|
|
2011-10-21 00:26:37 +02:00
|
|
|
config = {
|
|
|
|
-- Name of expose tag.
|
|
|
|
tag_name = "Revelation",
|
|
|
|
|
|
|
|
-- Match function can be defined by user.
|
|
|
|
-- Must accept a `rule` and `client` and return `boolean`.
|
|
|
|
-- The rule forms follow `awful.rules` syntax except we also check the
|
|
|
|
-- special `rule.any` key. If its true, then we use the `match.any` function
|
|
|
|
-- for comparison.
|
|
|
|
match = {
|
|
|
|
exact = aw_rules.match,
|
|
|
|
any = aw_rules.match_any
|
|
|
|
},
|
|
|
|
}
|
2011-08-23 23:37:11 +02:00
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2011-10-21 00:26:37 +02:00
|
|
|
-- Tags all matching clients with tag t
|
|
|
|
-- @param rule The rule. Conforms to awful.rules syntax.
|
|
|
|
-- @param clients A table of clients to check.
|
|
|
|
-- @param t The tag to give matching clients.
|
|
|
|
function match_clients(rule, clients, t)
|
|
|
|
local mf = rule.any and config.match.any or config.match.exact
|
|
|
|
for _, c in pairs(clients) do
|
|
|
|
if mf(c, rule) then
|
|
|
|
awful.client.toggletag(t, c)
|
|
|
|
c.minimized = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return clients
|
|
|
|
end
|
|
|
|
|
2011-08-23 23:37:11 +02:00
|
|
|
-- 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).
|
|
|
|
--
|
2011-10-21 00:26:37 +02:00
|
|
|
-- @param rule A table with key and value to match. [{class=""}]
|
|
|
|
-- @param s The screen to consider clients of. [mouse.screen].
|
|
|
|
function expose(rule, s)
|
|
|
|
local rule = rule or {class=""}
|
2011-08-23 23:37:11 +02:00
|
|
|
local scr = s or capi.mouse.screen
|
|
|
|
|
2011-10-21 00:26:37 +02:00
|
|
|
local t = awful.tag.new({config.tag_name},
|
|
|
|
scr,
|
|
|
|
awful.layout.suit.fair)[1]
|
|
|
|
awful.tag.viewonly(t, t.screen)
|
|
|
|
match_clients(rule, capi.client.get(scr), t)
|
2011-08-23 23:37:11 +02:00
|
|
|
local function restore()
|
2011-10-21 00:26:37 +02:00
|
|
|
awful.tag.history.restore()
|
|
|
|
t.screen = nil
|
2011-08-23 23:37:11 +02:00
|
|
|
capi.keygrabber.stop()
|
2011-10-01 23:03:12 +02:00
|
|
|
capi.mousegrabber.stop()
|
2011-08-23 23:37:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
capi.keygrabber.run(keyboardhandler(restore))
|
2011-10-01 23:03:12 +02:00
|
|
|
|
|
|
|
capi.mousegrabber.run(function(mouse)
|
2011-10-21 00:26:37 +02:00
|
|
|
if mouse.buttons[1] == true then
|
2011-10-01 23:03:12 +02:00
|
|
|
local c = awful.mouse.client_under_pointer()
|
|
|
|
selectfn(restore)(c)
|
2011-10-21 00:26:37 +02:00
|
|
|
return false
|
2011-10-01 23:03:12 +02:00
|
|
|
end
|
|
|
|
return true
|
2011-10-21 00:26:37 +02:00
|
|
|
--Strange but on my machine only fleur worked as a string.
|
|
|
|
--stole it from
|
2011-10-01 23:03:12 +02:00
|
|
|
--https://github.com/Elv13/awesome-configs/blob/master/widgets/layout/desktopLayout.lua#L175
|
|
|
|
end,"fleur")
|
2011-08-23 23:37:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return expose(...) end })
|