mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-22 23:55:37 +00:00
remove window launcher from hammerspoon, reformat
This commit is contained in:
parent
34049fa5fb
commit
6827aa4369
@ -8,113 +8,105 @@
|
|||||||
--- combination with another key, then provide the normal `control` key
|
--- combination with another key, then provide the normal `control` key
|
||||||
--- behavior.
|
--- behavior.
|
||||||
|
|
||||||
local obj={}
|
local obj = {}
|
||||||
obj.__index = obj
|
obj.__index = obj
|
||||||
|
|
||||||
-- Metadata
|
-- Metadata
|
||||||
obj.name = 'ControlEscape'
|
obj.name = "ControlEscape"
|
||||||
obj.version = '0.1'
|
obj.version = "0.1"
|
||||||
obj.author = 'Jason Rudolph <jason@jasonrudolph.com>'
|
obj.author = "Jason Rudolph <jason@jasonrudolph.com>"
|
||||||
obj.homepage = 'https://github.com/jasonrudolph/ControlEscape.spoon'
|
obj.homepage = "https://github.com/jasonrudolph/ControlEscape.spoon"
|
||||||
obj.license = 'MIT - https://opensource.org/licenses/MIT'
|
obj.license = "MIT - https://opensource.org/licenses/MIT"
|
||||||
|
|
||||||
function obj:init()
|
function obj:init()
|
||||||
self.movements = 0
|
self.movements = 0
|
||||||
self.sendEscape = false
|
self.sendEscape = false
|
||||||
self.lastModifiers = {}
|
self.lastModifiers = {}
|
||||||
|
|
||||||
-- Create an eventtap to run each time the modifier keys change (i.e., each
|
-- Create an eventtap to run each time the modifier keys change (i.e., each
|
||||||
-- time a key like control, shift, option, or command is pressed or released)
|
-- time a key like control, shift, option, or command is pressed or released)
|
||||||
self.controlTap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged},
|
self.controlTap = hs.eventtap.new({ hs.eventtap.event.types.flagsChanged }, function(event)
|
||||||
function(event)
|
local newModifiers = event:getFlags()
|
||||||
local newModifiers = event:getFlags()
|
|
||||||
|
|
||||||
-- If this change to the modifier keys does not involve a *change* to the
|
-- If this change to the modifier keys does not involve a *change* to the
|
||||||
-- up/down state of the `control` key (i.e., it was up before and it's
|
-- up/down state of the `control` key (i.e., it was up before and it's
|
||||||
-- still up, or it was down before and it's still down), then don't take
|
-- still up, or it was down before and it's still down), then don't take
|
||||||
-- any action.
|
-- any action.
|
||||||
if self.lastModifiers['ctrl'] == newModifiers['ctrl'] then
|
if self.lastModifiers["ctrl"] == newModifiers["ctrl"] then
|
||||||
return false
|
return false
|
||||||
end
|
|
||||||
|
|
||||||
-- Control was not down but is now
|
|
||||||
if not self.lastModifiers['ctrl'] then
|
|
||||||
|
|
||||||
-- Only prepare to send escape if no other modifier keys are in use
|
|
||||||
self.lastModifiers = newModifiers
|
|
||||||
if (not self.lastModifiers['cmd'] and not self.lastModifiers['alt']) then
|
|
||||||
self.sendEscape = true
|
|
||||||
self.movements = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Control was down and is up, hasn't been blocked by another key, and
|
-- Control was not down but is now
|
||||||
-- isn't above the movement threshold
|
if not self.lastModifiers["ctrl"] then
|
||||||
elseif (self.sendEscape == true and not newModifiers['ctrl'] and self.movements < 30) then
|
-- Only prepare to send escape if no other modifier keys are in use
|
||||||
|
self.lastModifiers = newModifiers
|
||||||
|
if not self.lastModifiers["cmd"] and not self.lastModifiers["alt"] then
|
||||||
|
self.sendEscape = true
|
||||||
|
self.movements = 0
|
||||||
|
end
|
||||||
|
|
||||||
self.lastModifiers = newModifiers
|
-- Control was down and is up, hasn't been blocked by another key, and
|
||||||
|
-- isn't above the movement threshold
|
||||||
|
elseif self.sendEscape == true and not newModifiers["ctrl"] and self.movements < 30 then
|
||||||
|
self.lastModifiers = newModifiers
|
||||||
|
|
||||||
-- Allow for shift-escape
|
-- Allow for shift-escape
|
||||||
if newModifiers['shift'] then
|
if newModifiers["shift"] then
|
||||||
hs.eventtap.keyStroke({'shift'}, 'escape', 0)
|
hs.eventtap.keyStroke({ "shift" }, "escape", 0)
|
||||||
|
else
|
||||||
|
hs.eventtap.keyStroke(newModifiers, "escape", 0)
|
||||||
|
end
|
||||||
|
self.sendEscape = false
|
||||||
|
self.movements = 0
|
||||||
|
self.numberOfCharacters = 0
|
||||||
|
|
||||||
|
-- Control was down and is up, but isn't ready to send escape
|
||||||
else
|
else
|
||||||
hs.eventtap.keyStroke(newModifiers, 'escape', 0)
|
self.lastModifiers = newModifiers
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- If any other key is pressed, don't send escape
|
||||||
|
self.asModifier = hs.eventtap.new({ hs.eventtap.event.types.keyDown }, function(_)
|
||||||
self.sendEscape = false
|
self.sendEscape = false
|
||||||
self.movements = 0
|
print("Don't sent escape")
|
||||||
self.numberOfCharacters = 0
|
end)
|
||||||
|
|
||||||
-- Control was down and is up, but isn't ready to send escape
|
-- If mouse is moving significantly, don't send escape
|
||||||
else
|
self.scrolling = hs.eventtap.new({ hs.eventtap.event.types.gesture }, function(event)
|
||||||
self.lastModifiers = newModifiers
|
local touches = event:getTouches()
|
||||||
|
local i, v = next(touches, nil)
|
||||||
end
|
while i do
|
||||||
end
|
if v["phase"] == "moved" then
|
||||||
)
|
-- Increment the movement counter
|
||||||
|
self.movements = self.movements + 1
|
||||||
-- If any other key is pressed, don't send escape
|
end
|
||||||
self.asModifier = hs.eventtap.new({hs.eventtap.event.types.keyDown},
|
i, v = next(touches, i) -- get next index
|
||||||
function(event)
|
|
||||||
self.sendEscape = false
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
-- If mouse is moving significantly, don't send escape
|
|
||||||
self.scrolling = hs.eventtap.new({hs.eventtap.event.types.gesture},
|
|
||||||
function(event)
|
|
||||||
local touches = event:getTouches()
|
|
||||||
local i, v = next(touches, nil)
|
|
||||||
while i do
|
|
||||||
if v["phase"] == "moved" then
|
|
||||||
-- Increment the movement counter
|
|
||||||
self.movements = self.movements + 1
|
|
||||||
end
|
end
|
||||||
i, v = next(touches, i) -- get next index
|
end)
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- ControlEscape:start()
|
--- ControlEscape:start()
|
||||||
--- Method
|
--- Method
|
||||||
--- Start sending `escape` when `control` is pressed and released in isolation
|
--- Start sending `escape` when `control` is pressed and released in isolation
|
||||||
function obj:start()
|
function obj:start()
|
||||||
self.controlTap:start()
|
self.controlTap:start()
|
||||||
self.asModifier:start()
|
self.asModifier:start()
|
||||||
self.scrolling:start()
|
self.scrolling:start()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- ControlEscape:stop()
|
--- ControlEscape:stop()
|
||||||
--- Method
|
--- Method
|
||||||
--- Stop sending `escape` when `control` is pressed and released in isolation
|
--- Stop sending `escape` when `control` is pressed and released in isolation
|
||||||
function obj:stop()
|
function obj:stop()
|
||||||
-- Stop monitoring keystrokes
|
-- Stop monitoring keystrokes
|
||||||
self.controlTap:stop()
|
self.controlTap:stop()
|
||||||
self.asModifier:stop()
|
self.asModifier:stop()
|
||||||
self.scrolling:stop()
|
self.scrolling:stop()
|
||||||
|
|
||||||
-- Reset state
|
-- Reset state
|
||||||
self.sendEscape = false
|
self.sendEscape = false
|
||||||
self.lastModifiers = {}
|
self.lastModifiers = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
@ -8,11 +8,11 @@ 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()
|
function DrawSwitcher()
|
||||||
-- Drawing
|
-- Drawing
|
||||||
width = hs.screen.mainScreen():fullFrame().w
|
local width = hs.screen.mainScreen():fullFrame().w
|
||||||
switcherWidth = 500
|
local switcherWidth = 500
|
||||||
canv = hs.canvas.new({
|
local canv = hs.canvas.new({
|
||||||
x = width / 2 - switcherWidth / 2,
|
x = width / 2 - switcherWidth / 2,
|
||||||
y = 1,
|
y = 1,
|
||||||
h = 3,
|
h = 3,
|
||||||
@ -39,8 +39,9 @@ function obj:init()
|
|||||||
-- 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()
|
self.canv = DrawSwitcher()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Behaviors on exit
|
-- Behaviors on exit
|
||||||
function self.launcher:exited()
|
function self.launcher:exited()
|
||||||
-- hs.alert("Exited mode")
|
-- hs.alert("Exited mode")
|
||||||
@ -54,10 +55,6 @@ function obj:init()
|
|||||||
|
|
||||||
-- Launcher shortcuts
|
-- Launcher shortcuts
|
||||||
self.launcher:bind("ctrl", "space", function() end)
|
self.launcher:bind("ctrl", "space", function() end)
|
||||||
self.launcher:bind("", "space", function()
|
|
||||||
hs.hints.windowHints()
|
|
||||||
self.launcher:exit()
|
|
||||||
end)
|
|
||||||
self.launcher:bind("", "return", function()
|
self.launcher:bind("", "return", function()
|
||||||
self:switch("Alacritty.app")
|
self:switch("Alacritty.app")
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user