From f819e30b03dffcf9e74af4b8552e4a8ab8f54c58 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Fri, 29 Sep 2023 14:22:24 -0400 Subject: major reorganizing to seperate modules --- modules/desktop/awesome/scratch.lua | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/desktop/awesome/scratch.lua (limited to 'modules/desktop/awesome/scratch.lua') diff --git a/modules/desktop/awesome/scratch.lua b/modules/desktop/awesome/scratch.lua new file mode 100644 index 0000000..aa1fd1e --- /dev/null +++ b/modules/desktop/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 -- cgit v1.2.1