summaryrefslogtreecommitdiffstats
path: root/programs/dotfiles/awesome/scratch.lua
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2023-09-24 07:25:56 -0400
committerJon Santmyer <jon@jonsantmyer.com>2023-09-24 07:25:56 -0400
commit0395c7beb1e35d252d607c9e047a3037daa09832 (patch)
tree6ba8e5696799d69c6865b8f6991feec8afcc3977 /programs/dotfiles/awesome/scratch.lua
parent1a646f724ebd8c79bfecd89b57207842e25b93c7 (diff)
downloadnix-config-0395c7beb1e35d252d607c9e047a3037daa09832.tar.gz
nix-config-0395c7beb1e35d252d607c9e047a3037daa09832.tar.bz2
nix-config-0395c7beb1e35d252d607c9e047a3037daa09832.zip
add scratchpad to awesome
Diffstat (limited to 'programs/dotfiles/awesome/scratch.lua')
-rw-r--r--programs/dotfiles/awesome/scratch.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/programs/dotfiles/awesome/scratch.lua b/programs/dotfiles/awesome/scratch.lua
new file mode 100644
index 0000000..aa1fd1e
--- /dev/null
+++ b/programs/dotfiles/awesome/scratch.lua
@@ -0,0 +1,54 @@
+local client = client
+
+local awful = require("awful")
+local util = require("awful.util")
+
+local scratch = {}
+
+local function activate(c)
+ local ctag = awful.tag.selected(c.screen)
+ ctags = {ctag}
+ for k,tag in pairs(c:tags()) do
+ if tag ~= ctag then table.insert(ctags, tag) end
+ end
+ c:tags(ctags)
+ c:raise()
+ client.focus = c
+end
+
+local function deactivate(c)
+ local ctag = awful.tag.selected(c.screen)
+ ctags = {}
+ for k,tag in pairs(c:tags()) do
+ if tag ~= ctag then table.insert(ctags, tag) end
+ end
+ c:tags(ctags)
+end
+
+function scratch.raise(cmd, rule)
+ local rule = rule or { instance = "scratch" }
+ local function match(c) return awful.rules.match(c, rule) end
+
+ 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(match, start) do
+ activate(c)
+ return
+ end
+
+ util.spawn(cmd)
+end
+
+function scratch.toggle(cmd, rule)
+ local rule = rule or { instance = "scratch" }
+
+ if client.focus and awful.rules.match(client.focus, rule) then
+ deactivate(client.focus)
+ else
+ scratch.raise(cmd)
+ end
+end
+
+return scratch