From ba3aa9cd9341542d363f75e51d1837bfc78eab8e Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sat, 16 Apr 2022 16:50:03 -0400 Subject: [PATCH] draw switcher indicator on screen --- .../Spoons/Launcher.spoon/init.lua | 131 ++++++++++-------- 1 file changed, 74 insertions(+), 57 deletions(-) diff --git a/hammerspoon.symlink/Spoons/Launcher.spoon/init.lua b/hammerspoon.symlink/Spoons/Launcher.spoon/init.lua index 7eee53d..fb637a8 100644 --- a/hammerspoon.symlink/Spoons/Launcher.spoon/init.lua +++ b/hammerspoon.symlink/Spoons/Launcher.spoon/init.lua @@ -8,70 +8,87 @@ obj.name = "Launcher" obj.version = "0.1" obj.license = "MIT - https://opensource.org/licenses/MIT" +function drawSwitcher() + -- Drawing + canv = hs.canvas.new({ x = 850, y = 1, h = 3, w = 120 }) + 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 + function obj:init() - -- Begin launcher mode - self.launcher = hs.hotkey.modal.new("ctrl", "space") + -- Begin launcher mode + self.launcher = hs.hotkey.modal.new("ctrl", "space") - -- Behaviors on enter - function self.launcher:entered() - -- hs.alert'Entered mode' - end - -- Behaviors on exit - function self.launcher:exited() - -- hs.alert'Exited mode' - end + -- Behaviors on enter + function self.launcher:entered() + -- hs.alert("Entered mode") + self.canv = drawSwitcher() + end + -- Behaviors on exit + function self.launcher:exited() + -- hs.alert("Exited mode") + self.canv:hide() + end - -- Use escape to exit launcher mode - self.launcher:bind("", "escape", function() - self.launcher:exit() - end) + -- Use escape to exit launcher mode + self.launcher:bind("", "escape", function() + self.launcher:exit() + end) - -- Launcher shortcuts - self.launcher:bind("", "space", function() - hs.hints.windowHints() - self.launcher:exit() - end) - self.launcher:bind("", "return", function() - self:switch("Alacritty.app") - end) - self.launcher:bind("", "C", function() - self:switch("Calendar.app") - end) - self.launcher:bind("", "D", function() - self:switch("Discord.app") - end) - self.launcher:bind("", "E", function() - self:switch("Mail.app") - end) - self.launcher:bind("", "F", function() - self:switch("Firefox.app") - end) - self.launcher:bind("", "G", function() - self:switch("Mimestream.app") - end) - self.launcher:bind("", "M", function() - self:switch("Messages.app") - end) - self.launcher:bind("", "O", function() - self:switch("Obsidian.app") - end) - self.launcher:bind("", "P", function() - self:switch("System Preferences.app") - end) - self.launcher:bind("", "R", function() - hs.reload() - end) - self.launcher:bind("", "S", function() - self:switch("Slack.app") - end) - self.launcher:bind("", "Z", function() - self:switch("zoom.us.app") - end) + -- Launcher shortcuts + self.launcher:bind("", "space", function() + hs.hints.windowHints() + self.launcher:exit() + end) + self.launcher:bind("", "return", function() + self:switch("Alacritty.app") + end) + self.launcher:bind("", "C", function() + self:switch("Calendar.app") + end) + self.launcher:bind("", "D", function() + self:switch("Discord.app") + end) + self.launcher:bind("", "E", function() + self:switch("Mail.app") + end) + self.launcher:bind("", "F", function() + self:switch("Firefox.app") + end) + self.launcher:bind("", "G", function() + self:switch("Mimestream.app") + end) + self.launcher:bind("", "M", function() + self:switch("Messages.app") + end) + self.launcher:bind("", "O", function() + self:switch("Obsidian.app") + end) + self.launcher:bind("", "P", function() + self:switch("System Preferences.app") + end) + self.launcher:bind("", "R", function() + hs.reload() + end) + self.launcher:bind("", "S", function() + self:switch("Slack.app") + end) + self.launcher:bind("", "Z", function() + self:switch("zoom.us.app") + end) end function obj:switch(app) - hs.application.launchOrFocus(app) - self.launcher:exit() + hs.application.launchOrFocus(app) + self.launcher:exit() end return obj