-
Notifications
You must be signed in to change notification settings - Fork 0
/
revelation.lua
135 lines (122 loc) · 3.78 KB
/
revelation.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---------------------------------------------------------------------------
-- @author Espen Wiborg <espenhw@grumblesmurf.org>
-- @author Julien Danjou <julien@danjou.info>
-- @copyright 2008 Espen Wiborg, Julien Danjou
-- @release v3.1-rc3-14-gc7ee83f
--
-- note: rewritten by Perry Hargrave perry)dot(hargrave)at(gmail.com
-- note: this is a version of revelation.lua modified for awesome 3.1.223+
--
---------------------------------------------------------------------------
local math = math
local table = table
local pairs = pairs
local button = button
local awful = require("awful")
local capi =
{
tag = tag,
client = client,
keygrabber = keygrabber,
mouse = mouse,
screen = screen
}
--- Exposé implementation
module("revelation")
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
function selectfn(restore)
return function(c)
restore()
-- Pop to client tag
awful.tag.viewonly(c:tags()[1])
-- Focus and raise
capi.client.focus = c
c:raise()
end
end
--- Returns keyboardhandler.
-- Arrow keys move focus, Return selects, Escape cancels.
-- Ignores modifiers.
function keyboardhandler (restore)
return function (mod, key, event)
if event ~= "press" then return true end
-- translate vim-style home keys to directions
translate = {
j = "Down",
k = "Up",
h = "Left",
l = "Right"
}
key = translate[key] or key
if key == "Escape" then
restore()
-- awful.tag.history.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é (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 screen = s or capi.mouse.screen
local t = awful.tag.selected()
local data = {}
local clients = clients(class, screen)
local oset = {}
oset.mwfact = awful.tag.getmwfact(t)
oset.ncol = awful.tag.getncol(t)
oset.nmaster = awful.tag.getnmaster(t)
oset.layout = awful.tag.getproperty(t,"layout")
oset.clients = t.clients(t)
local allc = capi.client.get(screen)
if #allc == 0 then
return
end
awful.tag.setproperty(t,"layout",awful.layout.suit.fair )
t:clients(allc)
local function restore()
local t = awful.tag.selected()
for i,c in pairs(allc) do
-- Restore client mouse bindings
c:buttons(data[c])
data[c] = nil
if not oset.clients[c] then
awful.client.toggletag(t,c)
end
end
awful.tag.setproperty(t,"layout",oset.layout)
awful.tag.setnmaster(oset.nmaster,t)
awful.tag.setmwfact(oset.mwfact, t)
awful.tag.setncol(oset.ncol, t)
awful.tag.viewonly(t)
capi.keygrabber.stop()
end
for k, c in pairs(clients) do
data[c] = c:buttons()
c:buttons(awful.util.table.join(awful.button({}, 1, selectfn(restore)) ))
end
awful.tag.viewonly(t)
capi.keygrabber.run(keyboardhandler(restore))
end