macos: don't recreate canvas on app switcher

This commit is contained in:
Noah Masur 2023-03-08 10:30:25 -05:00
parent 31170a616f
commit 12682a57e1

View File

@ -8,44 +8,44 @@ obj.name = "Launcher"
obj.version = "0.1" obj.version = "0.1"
obj.license = "MIT - https://opensource.org/licenses/MIT" obj.license = "MIT - https://opensource.org/licenses/MIT"
function DrawSwitcher() local width = hs.screen.mainScreen():fullFrame().w
-- Drawing local switcherWidth = 500
local width = hs.screen.mainScreen():fullFrame().w obj.canvas = hs.canvas.new({
local switcherWidth = 500 x = width / 2 - switcherWidth / 2,
local canv = hs.canvas.new({ y = 1,
x = width / 2 - switcherWidth / 2, h = 3,
y = 1, w = switcherWidth,
h = 3, })
w = switcherWidth, -- Draw switcher
}) obj.canvas[#obj.canvas + 1] = {
canv[#canv + 1] = { action = "build",
action = "build", type = "rectangle",
type = "rectangle", }
} obj.canvas[#obj.canvas + 1] = {
canv[#canv + 1] = { type = "rectangle",
type = "rectangle", fillColor = { alpha = 1, red = 0.8, green = 0.6, blue = 0.3 },
fillColor = { alpha = 1, red = 0.8, green = 0.6, blue = 0.3 }, action = "fill",
action = "fill", }
}
return canv:show()
end
function obj:init() function obj:init()
-- Begin launcher mode -- Begin launcher mode
if self.launcher == nil then if self.launcher == nil then
self.launcher = hs.hotkey.modal.new("ctrl", "space") self.launcher = hs.hotkey.modal.new("ctrl", "space")
print(self.canvas)
print(obj.canvas)
end end
-- Behaviors on enter -- Behaviors on enter
function self.launcher:entered() function self.launcher:entered()
-- hs.alert("Entered mode") -- hs.alert("Entered mode")
self.canv = DrawSwitcher() obj.canvas:show()
end end
-- Behaviors on exit -- Behaviors on exit
function self.launcher:exited() function self.launcher:exited()
-- hs.alert("Exited mode") -- hs.alert("Exited mode")
self.canv:hide() obj.canvas:hide()
end end
-- Use escape to exit launcher mode -- Use escape to exit launcher mode
@ -54,7 +54,8 @@ function obj:init()
end) end)
-- Launcher shortcuts -- Launcher shortcuts
self.launcher:bind("ctrl", "space", function() end) self.launcher:bind("ctrl", "space", function()
end)
self.launcher:bind("", "return", function() self.launcher:bind("", "return", function()
self:switch("@kitty@") self:switch("@kitty@")
end) end)