How to move a window next/prev between all screens?

775 views
Skip to first unread message

Brad Parks

unread,
Dec 1, 2015, 9:51:37 PM12/1/15
to Hammerspoon
Hey! I've got the following, which is intended to move a window from one screen to the next screen, and maximize it.

But it doesn't seem to work... I have 3 monitors, and it only moves between 2 monitors, never a third. It recognizes all 3.. That meaning I can start in any monitor, and move backwards and forwards to another monitor, but one of the monitors is always skipped... Do you know why?

Thanks!

Brad

function toggleFullScreen(s)
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local screen = s or win:screen()
  local max = screen:frame()

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

function moveWindowNext()
  local s = hs.screen.mainScreen():next()
  toggleFullScreen(s)
end

function moveWindowPrev()
  local s = hs.screen.mainScreen():previous()
  toggleFullScreen(s)
end

hs.hotkey.bind({"cmd", "option"}, "right", moveWindowNext)
hs.hotkey.bind({"cmd", "option"}, "left", moveWindowPrev)

Chris Jones

unread,
Dec 2, 2015, 4:21:56 AM12/2/15
to Brad Parks, Hammerspoon
Hi

It's possible we have a bug in hs.screen:next()/previous() which is mis-identifying which monitor is closest, in your arrangement. It might be interesting to see what this outputs in the Hammerspoon Console:

  hs.fnutils.each(hs.screen.allScreens(), function(screen) print(screen:fullFrame()) end)

In the meantime, you might also want to experiment with something like:

  function moveScreenAndMaximize(isWest)
    local win = hs.window.focusedWindow()
    if isWest then
      win:moveOneScreenWest(0)
    else
      win:moveOneScreenEast(0)
    end
    win:maximize()
  end

Cheers,
Chris

--
You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon...@googlegroups.com.
To post to this group, send email to hamme...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/576918f1-679f-4f76-874d-a58c34070587%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad Parks

unread,
Dec 2, 2015, 7:29:19 AM12/2/15
to Hammerspoon, brad...@gmail.com
here's the dump from that command:


hs.geometry.rect(0.0,0.0,1152.0,720.0)

hs.geometry.rect(-886.0,-900.0,1440.0,900.0)

hs.geometry.rect(554.0,-1000.0,1600.0,1000.0)


and i'll play around with different solutions like your above idea... thanks!

Reply all
Reply to author
Forward
0 new messages