hammerspoon: 10.11 — problems with moving windows between spaces

I have this strange problem: on Yosemite I was successfully using function below, to move windows between spaces, on 10.11 it works, but if I run it, let’s say move terminal window from space 2 to 3 (it works), I click ctrl-left to get back to space 2, once the space switching animation finished that terminal window appears. It helps if I click the titlebar, then the behaviour stops, so I suspect there’s something wrong with leftMouseUp?

function moveToSpace(win, space)
  local clickPoint = win:zoomButtonRect()
  local sleepTime = 2000
  local mousePosition = hs.mouse.getAbsolutePosition()

  clickPoint.x = clickPoint.x + clickPoint.w + 5
  clickPoint.y = clickPoint.y + clickPoint.h / 2

  hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseDown, clickPoint):post()

  hs.timer.usleep(sleepTime)

  hs.eventtap.keyStroke({ "ctrl" }, space)

  hs.timer.usleep(sleepTime)

  hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseUp, clickPoint):post()

  hs.mouse.setAbsolutePosition(mousePosition)
end

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

Ok, few tests and here’s what’s working for me on El Cap, with shortest possible (but working!) times:

function moveToSpace(win, space)
  local clickPoint    = win:zoomButtonRect()
  local sleepTime     = 1000
  local longSleepTime = 300000
  local mousePosition = hs.mouse.getAbsolutePosition()

  clickPoint.x = clickPoint.x + clickPoint.w + 5
  clickPoint.y = clickPoint.y + clickPoint.h / 2

  hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseDown, clickPoint):post()

  hs.timer.usleep(sleepTime)

  hs.eventtap.keyStroke({ "ctrl" }, space)

  hs.timer.usleep(longSleepTime)

  hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseUp, clickPoint):post()

  hs.mouse.setAbsolutePosition(mousePosition)
end