hammerspoon
hammerspoon copied to clipboard
"Center On Screen" doesn't work like it should
I would have expected these to blocks to function the same but the first example doesn't take into account the space occupied by the dock and results in the window appearing behind the dock.
hyper = { 'alt', 'ctrl', 'cmd' }
hs.hotkey.bind(hyper, 'c', function() hs.window.focusedWindow():centerOnScreen() end)
hyper = { 'alt', 'ctrl', 'cmd' }
hs.hotkey.bind(hyper, 'c', function()
local win = hs.window.focusedWindow()
local f = win:frame()
local max = win:screen():frame()
local x = f
x.x = ((max.w - f.w) / 2) + max.x
x.y = ((max.h - f.h) / 2) + max.y
win:setFrame(x)
end)
The way I check for the failure is by making a focused window frame.h = window:screen:frame:h then I try to center it. The first example results in the frame being moved behind the dock and the 2nd example doesn't.
EDIT: fixed formula