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
)
87 elseif key
== "Left" or key
== "Right" or
88 key
== "Up" or key
== "Down" then
89 awful
.client
.focus
.bydirection(key
:lower())
95 --- Implement Exposé (from Mac OS X).
96 -- @param class The class of clients to expose, or nil for all clients.
97 -- @param fn A binary function f(t, n) to set the layout for tag t for n clients, or nil for the default layout.
98 -- @param s The screen to consider clients of, or nil for "current screen".
99 function revelation(class
, fn
, s
)
100 local screen
= s
or capi
.mouse
.screen
101 local layout_fn
= fn
or layout
.default
102 local data
= otable()
104 local clients
= clients(class
, screen
)
105 if #clients
== 0 then
109 local tag = capi
.tag({ name
= "Revelation" })
112 layout_fn(tag, #clients
)
114 local function restore()
115 for k
, cl
in pairs(tag:clients()) do
116 -- Clear revelation tag
117 local tags
= cl
:tags()
119 tags
[tags
[tag]]
= nil
122 -- Restore client mouse bindings
127 capi
.keygrabber
.stop()
130 for k
, c
in pairs(clients
) do
131 data
[c
] = c
:buttons()
132 c
:buttons({ button({}, 1, selectfn(restore
)) })
135 awful
.tag.viewonly(tag)
136 capi
.keygrabber
.run(keyboardhandler(restore
))