2013-08-31 23:54:57 +02:00
|
|
|
-- revelation .lua
|
2011-08-23 23:37:11 +02:00
|
|
|
--
|
|
|
|
-- Library that implements Expose like behavior.
|
|
|
|
--
|
|
|
|
-- @author Perry Hargrave resixian@gmail.com
|
|
|
|
-- @author Espen Wiborg espenhw@grumblesmurf.org
|
|
|
|
-- @author Julien Danjou julien@danjou.info
|
2013-08-31 23:54:57 +02:00
|
|
|
-- @auther Quan Guo guotsuan@gmail.com
|
2011-08-23 23:37:11 +02:00
|
|
|
--
|
|
|
|
-- @copyright 2008 Espen Wiborg, Julien Danjou
|
|
|
|
--
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
local wibox = require("wibox")
|
|
|
|
local awful = require('awful')
|
|
|
|
local aw_rules = require('awful.rules')
|
|
|
|
local pairs = pairs
|
2011-08-23 23:37:11 +02:00
|
|
|
local setmetatable = setmetatable
|
2013-08-31 23:54:57 +02:00
|
|
|
local naughty = require("naughty")
|
|
|
|
local table = table
|
|
|
|
local tostring = tostring
|
|
|
|
local capi = {
|
|
|
|
tag = tag,
|
|
|
|
client = client,
|
|
|
|
keygrabber = keygrabber,
|
|
|
|
mousegrabber = mousegrabber,
|
|
|
|
mouse = mouse,
|
|
|
|
screen = screen
|
2011-08-23 23:37:11 +02:00
|
|
|
}
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
local revelation ={}
|
2011-12-22 17:21:31 +01:00
|
|
|
local clientData = {} -- table that holds the positions and sizes of floating clients
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
charorder = "jkluiopyhnmfdsatgvcewqzx1234567890"
|
|
|
|
hintbox = {} -- Table of letter wiboxes with characters as the keys
|
2011-08-23 23:37:11 +02:00
|
|
|
|
2013-12-30 22:42:52 +01:00
|
|
|
revelation = {
|
2011-10-21 00:26:37 +02:00
|
|
|
-- 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
|
|
|
|
},
|
2013-12-31 22:27:03 +01:00
|
|
|
tags_data = {},
|
2011-10-21 00:26:37 +02:00
|
|
|
}
|
2011-08-23 23:37:11 +02:00
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
|
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.
|
2013-08-31 23:54:57 +02:00
|
|
|
local function selectfn(restore)
|
2011-08-23 23:37:11 +02:00
|
|
|
return function(c)
|
|
|
|
restore()
|
|
|
|
-- Pop to client tag
|
|
|
|
awful.tag.viewonly(c:tags()[1], c.screen)
|
|
|
|
-- Focus and raise
|
|
|
|
capi.client.focus = c
|
2013-09-08 17:21:57 +02:00
|
|
|
awful.screen.focus(c.screen)
|
2011-08-23 23:37:11 +02:00
|
|
|
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.
|
2013-12-30 22:50:54 +01:00
|
|
|
local function match_clients(rule, clients, t, is_excluded)
|
2013-12-30 22:42:52 +01:00
|
|
|
local mfc = rule.any and revelation.match.any or revelation.match.exact
|
2013-12-30 22:50:54 +01:00
|
|
|
local mf = is_excluded and function(c,rule) return not mfc(c,rule) end or mfc
|
2011-10-21 00:26:37 +02:00
|
|
|
for _, c in pairs(clients) do
|
|
|
|
if mf(c, rule) then
|
2011-12-22 22:49:53 +01:00
|
|
|
-- Store geometry before setting their tags
|
|
|
|
if awful.client.floating.get(c) then
|
|
|
|
clientData[c] = c:geometry()
|
|
|
|
awful.client.floating.set(c, false)
|
|
|
|
end
|
2011-12-22 17:21:31 +01:00
|
|
|
|
2011-10-21 00:26:37 +02:00
|
|
|
awful.client.toggletag(t, c)
|
|
|
|
c.minimized = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return clients
|
|
|
|
end
|
|
|
|
|
2011-08-23 23:37:11 +02:00
|
|
|
|
|
|
|
-- 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=""}]
|
2013-08-31 23:54:57 +02:00
|
|
|
|
|
|
|
|
2013-12-30 22:50:54 +01:00
|
|
|
function revelation.expose(args)
|
2013-12-31 01:43:39 +01:00
|
|
|
local args = args or {}
|
2013-12-30 22:50:54 +01:00
|
|
|
local rule = args.rule or {}
|
|
|
|
local is_excluded = args.is_excluded or false
|
|
|
|
local curr_tag_only = args.curr_tag_only or false
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
local t={}
|
|
|
|
local zt={}
|
2013-12-30 23:41:46 +01:00
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
|
|
|
|
for scr=1,capi.screen.count() do
|
2013-12-30 22:42:52 +01:00
|
|
|
|
2013-12-30 23:41:46 +01:00
|
|
|
all_tags = awful.tag.gettags(scr)
|
|
|
|
|
2013-12-30 22:42:52 +01:00
|
|
|
t[scr] = awful.tag.new({revelation.tag_name},
|
2013-08-31 23:54:57 +02:00
|
|
|
scr,
|
|
|
|
awful.layout.suit.fair)[1]
|
2013-12-30 22:42:52 +01:00
|
|
|
zt[scr] = awful.tag.new({revelation.tag_name.."_zoom"},
|
2013-08-31 23:54:57 +02:00
|
|
|
scr,
|
|
|
|
awful.layout.suit.fair)[1]
|
|
|
|
|
2013-12-30 22:42:52 +01:00
|
|
|
|
|
|
|
if curr_tag_only then
|
2013-12-30 22:50:54 +01:00
|
|
|
match_clients(rule, awful.client.visible(scr), t[scr], is_excluded)
|
2013-12-30 22:42:52 +01:00
|
|
|
else
|
2013-12-30 22:50:54 +01:00
|
|
|
match_clients(rule, capi.client.get(scr), t[scr], is_excluded)
|
2013-12-30 22:42:52 +01:00
|
|
|
end
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
awful.tag.viewonly(t[scr], t.screen)
|
|
|
|
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
|
2011-08-23 23:37:11 +02:00
|
|
|
|
|
|
|
local function restore()
|
2013-08-31 23:54:57 +02:00
|
|
|
for scr=1, capi.screen.count() do
|
|
|
|
awful.tag.history.restore(scr)
|
|
|
|
t[scr].screen = nil
|
|
|
|
end
|
2011-08-23 23:37:11 +02:00
|
|
|
capi.keygrabber.stop()
|
2011-10-01 23:03:12 +02:00
|
|
|
capi.mousegrabber.stop()
|
2013-08-31 23:54:57 +02:00
|
|
|
for scr=1, capi.screen.count() do
|
|
|
|
t[scr].activated = false
|
|
|
|
zt[scr].activated = false
|
|
|
|
end
|
2011-12-22 17:21:31 +01:00
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
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
|
2011-12-22 17:21:31 +01:00
|
|
|
end
|
|
|
|
end
|
2013-12-30 23:41:46 +01:00
|
|
|
|
|
|
|
for i,j in pairs(hintindex) do
|
|
|
|
hintbox[i].visible = false
|
|
|
|
end
|
2013-12-31 22:27:03 +01:00
|
|
|
|
2011-08-23 23:37:11 +02:00
|
|
|
end
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
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)
|
|
|
|
|
2011-10-01 23:03:12 +02:00
|
|
|
|
2011-12-21 22:42:20 +01:00
|
|
|
local pressedMiddle = false
|
2013-08-31 23:54:57 +02:00
|
|
|
local pressedRight = false
|
|
|
|
local zoomed = false
|
|
|
|
local zoomedClient = nil
|
|
|
|
|
2011-10-01 23:03:12 +02:00
|
|
|
capi.mousegrabber.run(function(mouse)
|
2011-12-21 22:42:20 +01:00
|
|
|
local c = awful.mouse.client_under_pointer()
|
2011-10-21 00:26:37 +02:00
|
|
|
if mouse.buttons[1] == true then
|
2011-10-01 23:03:12 +02:00
|
|
|
selectfn(restore)(c)
|
2013-08-31 23:54:57 +02:00
|
|
|
|
|
|
|
for i,j in pairs(hintindex) do
|
|
|
|
hintbox[i].visible = false
|
|
|
|
end
|
2011-10-21 00:26:37 +02:00
|
|
|
return false
|
2013-08-31 23:54:57 +02:00
|
|
|
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
|
2011-12-21 22:42:20 +01:00
|
|
|
c:kill()
|
|
|
|
return true
|
|
|
|
elseif mouse.buttons[2] == false and pressedMiddle == true then
|
|
|
|
pressedMiddle = false
|
2013-08-31 23:54:57 +02:00
|
|
|
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
|
2011-10-01 23:03:12 +02:00
|
|
|
end
|
2011-12-21 22:42:20 +01:00
|
|
|
|
2011-10-01 23:03:12 +02:00
|
|
|
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
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
-- Create the wiboxes, but don't show them
|
2014-01-10 16:04:34 +01:00
|
|
|
function revelation.init(args)
|
2013-08-31 23:54:57 +02:00
|
|
|
hintsize = 60
|
|
|
|
local fontcolor = beautiful.fg_normal
|
|
|
|
local letterbox = {}
|
2013-12-30 22:42:52 +01:00
|
|
|
|
|
|
|
local args = args or {}
|
|
|
|
|
|
|
|
revelation.tag_name = args.tag_name or revelation.tag_name
|
|
|
|
if args.match then
|
|
|
|
revelation.match.exact = args.match.exact or revelation.match.exact
|
2014-01-10 16:04:34 +01:00
|
|
|
revelation.match.any = args.match.any or revelation.match.any
|
2013-12-30 22:42:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-31 23:54:57 +02:00
|
|
|
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
|
|
|
|
|
2013-12-30 23:41:46 +01:00
|
|
|
local function debuginfo( message )
|
|
|
|
nid = naughty.notify({ text = message, timeout = 10 })
|
|
|
|
end
|
2013-08-31 23:54:57 +02:00
|
|
|
setmetatable(revelation, { __call = function(_, ...) return revelation.expose(...) end })
|
|
|
|
|
|
|
|
return revelation
|