diff options
-rw-r--r-- | programs/dotfiles/awesome/rc.lua | 7 | ||||
-rw-r--r-- | programs/dotfiles/awesome/scratch.lua | 54 |
2 files changed, 61 insertions, 0 deletions
diff --git a/programs/dotfiles/awesome/rc.lua b/programs/dotfiles/awesome/rc.lua index f8cc3d6..ccd1d1a 100644 --- a/programs/dotfiles/awesome/rc.lua +++ b/programs/dotfiles/awesome/rc.lua @@ -21,6 +21,9 @@ local naughty = require("naughty") local menubar = require("menubar") local hotkeys_popup = require("awful.hotkeys_popup") +-- Scratch pad +local scratch = require("scratch") + -- Enable hotkeys help widget for VIM and other apps -- when client with a matching name is opened: require("awful.hotkeys_popup.keys") @@ -390,6 +393,9 @@ globalkeys = gears.table.join( {description = "open a terminal", group = "launcher"}), awful.key({ modkey, }, "w", function () awful.spawn(webbrowser) end, {description = "open the web browser", group = "launcher"}), + awful.key({ modkey, }, "`", function() scratch.toggle("kitty --name scratch-terminal", + { instance = "scratch-terminal" }) end, + {description = "spawn a terminal scratch-pad", group = "launcher"}), awful.key({ modkey, "Control" }, "r", awesome.restart, {description = "reload awesome", group = "awesome"}), @@ -578,6 +584,7 @@ awful.rules.rules = { "DTA", -- Firefox addon DownThemAll. "copyq", -- Includes session name in class. "pinentry", + "scratch-terminal", }, class = { "Arandr", 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 |