How to make Hammerspoon resize windows smoothly on OSX?

3

1

I'm using Hammerspoon to resize my windows on OSX. Particularly, I want to be able to make windows take up half the screen, either vertically or horizontally, as well as take up the entire screen.
However, there is major redrawing lag when I switch between axes (e.g. vertical to horizontal). Previously I've used Spectacle, which performs the same task snappily.

To demonstrate, here are short clips of me resizing windows in Hammerspoon vs Spectacle.
Hammerspoon - https://vid.me/xg8o
Spectacle - https://vid.me/7dLP

Is this a limitation of how Hammerspoon resizes windows or could I optimize my config better?

Here's my init.lua

--
-- Window management
--
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Left", function()
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local max = win:screen():frame()

  f.x = max.x
  f.y = max.y
  f.w = max.w / 2
  f.h = max.h
  win:setFrame(f)
end)

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Right", function()
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local max = win:screen():frame()

  f.x = max.w / 2
  f.y = max.y
  f.w = max.w / 2
  f.h = max.h
  win:setFrame(f)
end)

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Up", function()
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local max = win:screen():frame()

  f.x = max.x
  f.y = max.y
  f.w = max.w
  f.h = max.h / 2
  win:setFrame(f)
end)

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Down", function()
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local max = win:screen():frame()

  f.x = max.x
  f.y = max.h / 2
  f.w = max.w
  f.h = max.h / 2
  win:setFrame(f)
end)

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "f", function()
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local max = win:screen():frame()

  f.x = max.x
  f.y = max.y
  f.w = max.w
  f.h = max.h
  win:setFrame(f)
end)

Prashanth Chandra

Posted 2016-11-29T03:46:03.267

Reputation: 221

Answers

1

Looks like you have window animation turned on, you can turn it off with hs.window.animationDuration = 0

http://www.hammerspoon.org/docs/hs.window.html#animationDuration

Adam Aviner

Posted 2016-11-29T03:46:03.267

Reputation: 11

1

The previous answer is good (the default animationDuration value is 0.2), but you will be changing a global value. Locally, instead of win:setFrame(f) you can do

win:setFrame(f, 0)

it will have the same effect.

ttarchala

Posted 2016-11-29T03:46:03.267

Reputation: 771