1 ---------------------------------------------------------------------------
2 -- @author Espen Wiborg <espenhw@grumblesmurf.org>
3 -- @author Julien Danjou <julien@danjou.info>
4 -- @copyright 2008 Espen Wiborg, Julien Danjou
5 -- @release @AWESOME_VERSION@
6 ---------------------------------------------------------------------------
15 tag = require("awful.tag"),
16 client
= require("awful.client")
22 keygrabber
= keygrabber
,
26 --- Exposé implementation
32 --- The default layout function for revelation
33 -- Tries to arrange clients in an approximated square grid, by
34 -- calculating c = floor(sqrt(n)) and arranging for c columns in a
36 -- @param t The tag to do revelation on.
37 -- @param n The number of clients to reveal.
38 function layout
.default (t
, n
)
40 local columns
= math
.floor(math
.sqrt(n
))
43 t
.mwfact
= 1 / columns
46 t
.nmaster
= n
/ columns
49 function clients(class
, s
)
53 for k
, c
in pairs(capi
.client
.get(s
)) do
54 if c
.class
== class
then
55 table.insert(clients
, c
)
59 clients
= capi
.client
.get(s
)
64 function selectfn(restore
)
68 awful
.tag.viewonly(c
:tags()[1])
75 --- Returns keyboardhandler.
76 -- Arrow keys move focus, Return selects, Escape cancels.
78 function keyboardhandler (restore
)
79 return function (mod, key
)
80 if key
== "Escape" then
82 awful
.tag.history
.restore()
84 elseif key
== "Return" then
85 selectfn(restore
)(capi
.client
.focus
)
92 --- Implement Exposé (from Mac OS X).
93 -- @param class The class of clients to expose, or nil for all clients.
94 -- @param fn A binary function f(t, n) to set the layout for tag t for n clients, or nil for the default layout.
95 -- @param s The screen to consider clients of, or nil for "current screen".
96 function revelation(class
, fn
, s
)
97 local screen
= s
or capi
.mouse
.screen
98 local layout_fn
= fn
or layout
.default
101 local clients
= clients(class
, screen
)
102 if #clients
== 0 then
106 local tag = capi
.tag({ name
= "Revelation" })
109 layout_fn(tag, #clients
)
111 local function restore()
112 for k
, cl
in pairs(tag:clients()) do
113 -- Clear revelation tag
114 local tags
= cl
:tags()
116 tags
[tags
[tag]]
= nil
119 -- Restore client mouse bindings
124 capi
.keygrabber
.stop()
127 for k
, c
in pairs(clients
) do
128 data
[c
] = c
:buttons()
129 c
:buttons({ button({}, 1, selectfn(restore
)) })
132 awful
.tag.viewonly(tag)
133 capi
.keygrabber
.run(keyboardhandler(restore
))