update the documents
This commit is contained in:
parent
014e787658
commit
76ad9523f7
12
README.md
12
README.md
|
@ -1,6 +1,17 @@
|
|||
# revelation.lua
|
||||
|
||||
Provides Mac OSX like 'Expose' view of all clients.
|
||||
It is modified from the original revelation.lua.
|
||||
|
||||
##Changes from the original revelation
|
||||
* add support of multiple screens. Now the revelation will be trigged on
|
||||
the on the multiple screens at the same time.
|
||||
|
||||
* The way of select and active the client was changed. The previous
|
||||
movement by the keystroke "j,h,k,l" was deprecated and is replaced
|
||||
by the same way in the module hint.
|
||||
|
||||
|
||||
|
||||
## Use
|
||||
|
||||
|
@ -76,6 +87,7 @@ Provides Mac OSX like 'Expose' view of all clients.
|
|||
})
|
||||
end)
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
### Maintenance
|
||||
|
|
235
init.lua
235
init.lua
|
@ -1,33 +1,41 @@
|
|||
-- revelation.lua
|
||||
-- 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
|
||||
-- @auther Quan Guo guotsuan@gmail.com
|
||||
--
|
||||
-- @copyright 2008 Espen Wiborg, Julien Danjou
|
||||
--
|
||||
|
||||
local awful = require('awful')
|
||||
local aw_rules = require('awful.rules')
|
||||
local pairs = pairs
|
||||
|
||||
local beautiful = require("beautiful")
|
||||
local wibox = require("wibox")
|
||||
local awful = require('awful')
|
||||
local aw_rules = require('awful.rules')
|
||||
local pairs = pairs
|
||||
local setmetatable = setmetatable
|
||||
local table = table
|
||||
local capi = {
|
||||
tag = tag,
|
||||
client = client,
|
||||
keygrabber = keygrabber,
|
||||
mousegrabber = mousegrabber,
|
||||
mouse = mouse,
|
||||
screen = screen
|
||||
local naughty = require("naughty")
|
||||
local table = table
|
||||
local tostring = tostring
|
||||
local capi = {
|
||||
tag = tag,
|
||||
client = client,
|
||||
keygrabber = keygrabber,
|
||||
mousegrabber = mousegrabber,
|
||||
mouse = mouse,
|
||||
screen = screen
|
||||
}
|
||||
|
||||
local revelation ={}
|
||||
local clientData = {} -- table that holds the positions and sizes of floating clients
|
||||
|
||||
module("revelation")
|
||||
charorder = "jkluiopyhnmfdsatgvcewqzx1234567890"
|
||||
hintbox = {} -- Table of letter wiboxes with characters as the keys
|
||||
|
||||
config = {
|
||||
local default_config = {
|
||||
-- Name of expose tag.
|
||||
tag_name = "Revelation",
|
||||
|
||||
|
@ -42,10 +50,12 @@ config = {
|
|||
},
|
||||
}
|
||||
|
||||
local config = revelation_config or default_config
|
||||
|
||||
-- Executed when user selects a client from expose view.
|
||||
--
|
||||
-- @param restore Function to reset the current tags view.
|
||||
function selectfn(restore)
|
||||
local function selectfn(restore)
|
||||
return function(c)
|
||||
restore()
|
||||
-- Pop to client tag
|
||||
|
@ -60,8 +70,9 @@ end
|
|||
-- @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
|
||||
local function match_clients(rule, clients, t, is_exluded)
|
||||
local mfc = rule.any and config.match.any or config.match.exact
|
||||
local mf = is_exluded and function(c,rule) return not mfc(c,rule) end or mfc
|
||||
for _, c in pairs(clients) do
|
||||
if mf(c, rule) then
|
||||
-- Store geometry before setting their tags
|
||||
|
@ -78,85 +89,164 @@ function match_clients(rule, clients, t)
|
|||
end
|
||||
|
||||
-- Arrow keys and 'hjkl' move focus, Return selects, Escape cancels. Ignores
|
||||
-- modifiers.
|
||||
-- modifiers. was deprecated by gq in favor of hintbox
|
||||
--
|
||||
-- @param restore a function to call if the user presses escape
|
||||
-- @return keyboardhandler
|
||||
function keyboardhandler (restore)
|
||||
local 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())
|
||||
if event == "release" then return true end
|
||||
|
||||
if hintindex[key] then
|
||||
selectfn(restore)(hintindex[key])
|
||||
|
||||
for i,j in pairs(hintindex) do
|
||||
hintbox[i].visible = false
|
||||
end
|
||||
return true
|
||||
return false
|
||||
end
|
||||
|
||||
if key == "Escape" then
|
||||
for i,j in pairs(hintindex) do
|
||||
hintbox[i].visible = false
|
||||
end
|
||||
restore()
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
-- Implement Exposé (ala Mac OS X).
|
||||
--
|
||||
-- @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=""}
|
||||
local scr = s or capi.mouse.screen
|
||||
|
||||
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)
|
||||
|
||||
function revelation.expose(rule, is_exluded)
|
||||
local rule = rule or {class=""}
|
||||
local t={}
|
||||
local zt={}
|
||||
|
||||
for scr=1,capi.screen.count() do
|
||||
t[scr] = awful.tag.new({config.tag_name},
|
||||
scr,
|
||||
awful.layout.suit.fair)[1]
|
||||
zt[scr] = awful.tag.new({config.tag_name.."_zoom"},
|
||||
scr,
|
||||
awful.layout.suit.fair)[1]
|
||||
|
||||
awful.tag.viewonly(t[scr], t.screen)
|
||||
match_clients(rule, capi.client.get(scr), t[scr], is_exluded)
|
||||
end
|
||||
|
||||
|
||||
local hintindex = {} -- Table of visible clients with the hint letter as the keys
|
||||
local clientlist = awful.client.visible()
|
||||
for i,thisclient in pairs(clientlist) do
|
||||
-- Move wiboxes to center of visible windows and populate hintindex
|
||||
local char = charorder:sub(i,i)
|
||||
hintindex[char] = thisclient
|
||||
local geom = thisclient.geometry(thisclient)
|
||||
hintbox[char].visible = true
|
||||
hintbox[char].x = geom.x + geom.width/2 - hintsize/2
|
||||
hintbox[char].y = geom.y + geom.height/2 - hintsize/2
|
||||
hintbox[char].screen = thisclient.screen
|
||||
end
|
||||
|
||||
local function restore()
|
||||
awful.tag.history.restore()
|
||||
t.screen = nil
|
||||
for scr=1, capi.screen.count() do
|
||||
awful.tag.history.restore(scr)
|
||||
t[scr].screen = nil
|
||||
--zt[scr].screen = nil
|
||||
end
|
||||
capi.keygrabber.stop()
|
||||
capi.mousegrabber.stop()
|
||||
for scr=1, capi.screen.count() do
|
||||
t[scr].activated = false
|
||||
zt[scr].activated = false
|
||||
end
|
||||
|
||||
for _, c in pairs(capi.client.get(src)) do
|
||||
if clientData[c] then
|
||||
c:geometry(clientData[c]) -- Restore positions and sizes
|
||||
awful.client.floating.set(c, true)
|
||||
for scr=1, capi.screen.count() do
|
||||
for _, c in pairs(capi.client.get(scr)) do
|
||||
if clientData[c] then
|
||||
c:geometry(clientData[c]) -- Restore positions and sizes
|
||||
|
||||
awful.client.floating.set(c, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
capi.keygrabber.run(keyboardhandler(restore))
|
||||
capi.keygrabber.run(function (mod, key, event)
|
||||
if event == "release" then return true end
|
||||
|
||||
if hintindex[key] then
|
||||
--client.focus = hintindex[key]
|
||||
--hintindex[key]:raise()
|
||||
selectfn(restore)(hintindex[key])
|
||||
|
||||
for i,j in pairs(hintindex) do
|
||||
hintbox[i].visible = false
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
if key == "Escape" then
|
||||
for i,j in pairs(hintindex) do
|
||||
hintbox[i].visible = false
|
||||
end
|
||||
restore()
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end)
|
||||
|
||||
|
||||
local pressedMiddle = false
|
||||
local pressedRight = false
|
||||
local zoomed = false
|
||||
local zoomedClient = nil
|
||||
|
||||
capi.mousegrabber.run(function(mouse)
|
||||
local c = awful.mouse.client_under_pointer()
|
||||
if mouse.buttons[1] == true then
|
||||
selectfn(restore)(c)
|
||||
|
||||
for i,j in pairs(hintindex) do
|
||||
hintbox[i].visible = false
|
||||
end
|
||||
return false
|
||||
elseif mouse.buttons[2] == true and pressedMiddle == false and c ~= nil then -- is true whenever the button is down.
|
||||
pressedMiddle = true -- extra variable needed to prevent script from spam-closing windows
|
||||
elseif mouse.buttons[2] == true and pressedMiddle == false and c ~= nil then
|
||||
-- is true whenever the button is down.
|
||||
pressedMiddle = true
|
||||
-- extra variable needed to prevent script from spam-closing windows
|
||||
c:kill()
|
||||
return true
|
||||
elseif mouse.buttons[2] == false and pressedMiddle == true then
|
||||
pressedMiddle = false
|
||||
elseif mouse.buttons[3] == true and pressedRight == false then
|
||||
if not zoomed and c ~= nil then
|
||||
awful.tag.viewonly(zt[capi.mouse.screen], capi.mouse.screen)
|
||||
awful.client.toggletag(zt[capi.mouse.screen], c)
|
||||
zoomedClient = c
|
||||
zoomed = true
|
||||
elseif zoomedClient ~= nil then
|
||||
awful.tag.history.restore(capi.mouse.screen)
|
||||
awful.client.toggletag(zt[capi.mouse.screen], zoomedClient)
|
||||
zoomedClient = nil
|
||||
zoomed = false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--for i,j in pairs(hintindex) do
|
||||
--hintbox[i].visible = false
|
||||
--end
|
||||
return true
|
||||
--Strange but on my machine only fleur worked as a string.
|
||||
--stole it from
|
||||
|
@ -164,4 +254,25 @@ function expose(rule, s)
|
|||
end,"fleur")
|
||||
end
|
||||
|
||||
setmetatable(_M, { __call = function(_, ...) return expose(...) end })
|
||||
-- Create the wiboxes, but don't show them
|
||||
function revelation.init()
|
||||
hintsize = 60
|
||||
local fontcolor = beautiful.fg_normal
|
||||
local letterbox = {}
|
||||
for i = 1, #charorder do
|
||||
local char = charorder:sub(i,i)
|
||||
hintbox[char] = wibox({fg=beautiful.fg_normal, bg=beautiful.bg_focus, border_color=beautiful.border_focus, border_width=beautiful.border_width})
|
||||
hintbox[char].ontop = true
|
||||
hintbox[char].width = hintsize
|
||||
hintbox[char].height = hintsize
|
||||
letterbox[char] = wibox.widget.textbox()
|
||||
letterbox[char]:set_markup("<span color=\"" .. beautiful.fg_normal.."\"" .. ">" .. char.upper(char) .. "</span>")
|
||||
letterbox[char]:set_font("dejavu sans mono 40")
|
||||
letterbox[char]:set_align("center")
|
||||
hintbox[char]:set_widget(letterbox[char])
|
||||
end
|
||||
end
|
||||
|
||||
setmetatable(revelation, { __call = function(_, ...) return revelation.expose(...) end })
|
||||
|
||||
return revelation
|
||||
|
|
Loading…
Reference in New Issue