Skip to content

Instantly share code, notes, and snippets.

@jakemayeux
Created December 16, 2020 19:14
Show Gist options
  • Save jakemayeux/9439566439534e048ee729e30d90c26b to your computer and use it in GitHub Desktop.
Save jakemayeux/9439566439534e048ee729e30d90c26b to your computer and use it in GitHub Desktop.
icon = hs.menubar.new()
-- icon2 = hs.menubar.new()
icon:setMenu({
{ title = hs.battery.capacity().." mAh"},
})
icon:setTitle(hs.battery.amperage().." mAh")
function mAhUpdate()
icon:setTitle(hs.battery.amperage().." mAh")
end
hs.timer.doEvery(30, mAhUpdate)
function mouseMove()
hs.window.focusedWindow():setTopLeft(hs.geometry.copy(winpos):move(hs.geometry(hs.mouse.getAbsolutePosition()):move(smpos)))
end
moveTimer = hs.timer.new(0.02, mouseMove)
hs.hotkey.bind('alt', 'a', function ()
smpos = hs.geometry(hs.mouse.getAbsolutePosition()):scale(-1)
winpos = hs.window.focusedWindow():topLeft()
moveTimer:start()
end, function()
moveTimer:stop()
end)
function mouseSize()
dx = hs.mouse.getAbsolutePosition().x - sx
dy = hs.mouse.getAbsolutePosition().y - sy
hs.window.focusedWindow():setSize(hs.geometry({w=sw+dx,h=sh+dy}))
--hs.window.focusedWindow():setTopLeft(hs.geometry.copy(winofs):move({-dx/2,-dy/2}))
end
sizeTimer = hs.timer.new(0.02, mouseSize)
hs.hotkey.bind('alt', 's', function ()
--winofs = hs.window.focusedWindow():topLeft()
sx = hs.mouse.getAbsolutePosition().x
sy = hs.mouse.getAbsolutePosition().y
sw = hs.window.focusedWindow():size().w
sh = hs.window.focusedWindow():size().h
sizeTimer:start()
end, function()
sizeTimer:stop()
end)
hs.hotkey.bind({'alt', 'shift'}, 'k', function ()
local screen = hs.screen.mainScreen()
local window = hs.window.focusedWindow()
window:setTopLeft(screen:localToAbsolute({0,0}))
window:setSize(screen:frame())
end)
hs.hotkey.bind({'alt', 'shift'}, 'l', function ()
local screen = hs.screen.mainScreen()
local window = hs.window.focusedWindow()
local frame = screen:frame()
local log = hs.logger.new('LOGGER', 'debug')
log.i(frame.w)
window:setTopLeft(screen:localToAbsolute({frame.w / 2, 0}))
window:setSize(hs.geometry.size(frame.w / 2, frame.h))
end)
hs.hotkey.bind({'alt', 'shift'}, 'h', function ()
local screen = hs.screen.mainScreen()
local window = hs.window.focusedWindow()
local frame = screen:frame()
local log = hs.logger.new('LOGGER', 'debug')
log.i(frame.w)
window:setTopLeft(screen:localToAbsolute({0, 0}))
window:setSize(hs.geometry.size(frame.w / 2, frame.h))
end)
-- https://superuser.com/questions/303424/can-i-enable-scrolling-with-middle-button-drag-in-os-x
-- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED
local scrollMouseButton = 2
local deferred = false
overrideOtherMouseDown = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDown }, function(e)
-- print("down")
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if scrollMouseButton == pressedMouseButton
then
deferred = true
return true
end
end)
overrideOtherMouseUp = hs.eventtap.new({ hs.eventtap.event.types.otherMouseUp }, function(e)
-- print("up")
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
if scrollMouseButton == pressedMouseButton
then
if (deferred) then
overrideOtherMouseDown:stop()
overrideOtherMouseUp:stop()
hs.eventtap.otherClick(e:location(), pressedMouseButton)
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
return true
end
return false
end
return false
end)
local oldmousepos = {}
local scrollmult = 2 -- negative multiplier makes mouse work like traditional scrollwheel
local mouseDownPos
dragOtherToScroll = hs.eventtap.new({ hs.eventtap.event.types.otherMouseDragged }, function(e)
local pressedMouseButton = e:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber'])
-- print ("pressed mouse " .. pressedMouseButton)
if scrollMouseButton == pressedMouseButton
then
-- print("scroll");
deferred = false
-- oldmousepos = hs.mouse.getAbsolutePosition()
local dx = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaX'])
local dy = e:getProperty(hs.eventtap.event.properties['mouseEventDeltaY'])
local scroll = hs.eventtap.event.newScrollEvent({-dx * scrollmult, -dy * scrollmult},{},'pixel')
-- put the mouse back
-- hs.mouse.setAbsolutePosition(oldmousepos)
return true, {scroll}
else
return false, {}
end
end)
overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
dragOtherToScroll:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment