-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscratch.lua
60 lines (50 loc) · 1.65 KB
/
scratch.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
local client = client
local awful = require("awful")
local util = require("awful.util")
local scratch = {}
local defaultRule = {instance = "scratch"}
-- Turn on this scratch window client (add current tag to window's tags,
-- then set focus to the window)
local function turn_on(c)
local current_tag = awful.tag.selected(c.screen)
ctags = {current_tag}
for k,tag in pairs(c:tags()) do
if tag ~= current_tag then table.insert(ctags, tag) end
end
c:tags(ctags)
c:raise()
client.focus = c
end
-- Turn off this scratch window client (remove current tag from window's tags)
local function turn_off(c)
local current_tag = awful.tag.selected(c.screen)
local ctags = {}
for k,tag in pairs(c:tags()) do
if tag ~= current_tag then table.insert(ctags, tag) end
end
c:tags(ctags)
end
function scratch.raise(cmd, rule)
local rule = rule or defaultRule
local function matcher(c) return awful.rules.match(c, rule) end
-- logic mostly copied form awful.client.run_or_raise, except we don't want
-- to change to or merge with scratchpad tag, just show the window
local clients = client.get()
local findex = util.table.hasitem(clients, client.focus) or 1
local start = util.cycle(#clients, findex + 1)
for c in awful.client.iterate(matcher, start) do
turn_on(c)
return
end
-- client not found, spawn it
util.spawn(cmd)
end
function scratch.toggle(cmd, rule, alwaysclose)
local rule = rule or defaultRule
if client.focus and awful.rules.match(client.focus, rule) then
turn_off(client.focus)
else
scratch.raise(cmd, rule)
end
end
return scratch