From 12682a57e1faa3ddf3155397efcb6abe3dd10c61 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 8 Mar 2023 10:30:25 -0500 Subject: [PATCH] macos: don't recreate canvas on app switcher --- .../Spoons/Launcher.spoon/init.lua | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua b/modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua index 971b3c8..0e6e988 100644 --- a/modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua +++ b/modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua @@ -8,44 +8,44 @@ obj.name = "Launcher" obj.version = "0.1" obj.license = "MIT - https://opensource.org/licenses/MIT" -function DrawSwitcher() - -- Drawing - local width = hs.screen.mainScreen():fullFrame().w - local switcherWidth = 500 - local canv = hs.canvas.new({ - x = width / 2 - switcherWidth / 2, - y = 1, - h = 3, - w = switcherWidth, - }) - canv[#canv + 1] = { - action = "build", - type = "rectangle", - } - canv[#canv + 1] = { - type = "rectangle", - fillColor = { alpha = 1, red = 0.8, green = 0.6, blue = 0.3 }, - action = "fill", - } - return canv:show() -end +local width = hs.screen.mainScreen():fullFrame().w +local switcherWidth = 500 +obj.canvas = hs.canvas.new({ + x = width / 2 - switcherWidth / 2, + y = 1, + h = 3, + w = switcherWidth, +}) +-- Draw switcher +obj.canvas[#obj.canvas + 1] = { + action = "build", + type = "rectangle", +} +obj.canvas[#obj.canvas + 1] = { + type = "rectangle", + fillColor = { alpha = 1, red = 0.8, green = 0.6, blue = 0.3 }, + action = "fill", +} function obj:init() -- Begin launcher mode if self.launcher == nil then self.launcher = hs.hotkey.modal.new("ctrl", "space") + + print(self.canvas) + print(obj.canvas) end -- Behaviors on enter function self.launcher:entered() -- hs.alert("Entered mode") - self.canv = DrawSwitcher() + obj.canvas:show() end -- Behaviors on exit function self.launcher:exited() -- hs.alert("Exited mode") - self.canv:hide() + obj.canvas:hide() end -- Use escape to exit launcher mode @@ -54,7 +54,8 @@ function obj:init() end) -- Launcher shortcuts - self.launcher:bind("ctrl", "space", function() end) + self.launcher:bind("ctrl", "space", function() + end) self.launcher:bind("", "return", function() self:switch("@kitty@") end)