Repository: Hammerspoon/hammerspoon

Issue #3224: hs.window:moveToScreen() behaves weirdly in macOS 12.4 when applied to a Google Chrome window.
Created: 2022-05-31T05:54:48Z
After upgrading to macOS 12.4 Monterey, I've noticed two issues:

While moving a Google Chrome window using the moveAndResize function in the WinWin Spoon, the target window shows an animation while moving/resizing. Windows of other applications do not behave like this: they just immediately resize/move to the required shape and location.
While moving a Google Chrome window to another screen using moveToScreen() in WinWin, instead of moving to the target screen, the target window shrinks to roughly half of the original length and width. Same as above, windows of other applications show the desired behavior.

Further debugging showed that calling hs.window:moveToScreen() directly shares the same issue.
You may reproduce this issue by opening a Google Chrome window, navigate to https://www.hammerspoon.org/docs/hs.window.html, and run the following snippet in the Hammerspoon console:
c = hs.window.find("Hammerspoon docs: hs.window")
s = c:screen()
c:moveToScreen(s:next())
Version information:

macOS: 12.4
Hammerspoon: 0.9.97 (6267)
Google Chrome: 101.0.4951.64 (Official Build) (x86_64)

Duplicate issue #3689: hs.grid.adjustWindow() stopped working properly
Created: 2024-09-17T17:21:22Z
What's expected?
Calling my function move() should snap the focused window to the next spot in my map of grid coordinates.
What's happening?
The window moves to weird and unexpected places. This behavior only started recently, possibly with a Mac update. I added a lot of logging and after much investigation, I am fairly convinced that the cell is being set correctly, but the actual coordinates on the window are not.
It's not easy to read these logs, but they often show an x coordinate that was clearly wrong (like showing -3840 which is the left of the screen when the window was beyond the left or sometimes not quite at the left). It almost seems like Hammerspoon is working but it isn't able to properly translate to the Mac APIs.
Relevant Code
function obj:move(direction)
	obj.logger.d("moving " .. direction)
	local window = hs.window.frontmostWindow()
	normalizeLocation(window)
	local c

	hs.grid.adjustWindow(function(cell)
		local location = string.sub(cell.x, 1, 1) .. string.sub(cell.w, 1, 1)

		for index, value in ipairs(sizes) do
			if value == location then
				local newIndex = index + actions[direction]

				if newIndex < 1 then
					if window:screen():toWest() == nil then
						return
					end
					window:moveOneScreenWest()
					newIndex = #sizes
				end
				if newIndex > #sizes then
					if window:screen():toEast() == nil then
						return
					end
					window:moveOneScreenEast()
					newIndex = 1
				end

				local newSize = sizes[newIndex]

				cell.x = tonumber(string.sub(newSize, 1, 1))
				cell.w = tonumber(string.sub(newSize, 2, 2))

				obj.logger:d("adjust window cell: " .. hs.inspect(cell))
				c = cell
				return
			end
		end
		obj.logger:e("couldn't find location " .. location)
	end, window)
	obj.logger:d("SCREEN GRID: " .. hs.inspect(hs.grid.getGrid(window:screen())))
	hs.grid.set(window, c)
	obj.logger:d(
		"name: "
			.. window:application():name()
			.. "\nsize "
			.. hs.inspect(window:size())
			.. "\nloc "
			.. hs.inspect(window:topLeft())
	)
	obj.logger:d("cell: " .. hs.inspect(hs.grid.get(window)))
end
Log Sample
2024-09-17 10:05:13:                          moving right
2024-09-17 10:05:13:                          table: 0x600003478380 adjust window cell: { -- hs.geometry.rect(3,0.0,3,1)
  _h = 1,
  _w = 3,
  _x = 3,
  _y = 0.0
}
2024-09-17 10:05:13:                          table: 0x600003478380 SCREEN GRID: { -- hs.geometry.size(6,1)
  _h = 1,
  _w = 6
}
2024-09-17 10:05:13:                          table: 0x600003478380 name: Google Chrome
size { -- hs.geometry.size(1920,2135)
  _h = 2135,
  _w = 1920
}
loc { -- hs.geometry.point(1920,25)
  _x = 1920,
  _y = 25
}
2024-09-17 10:05:13:                          table: 0x600003478380 cell: { -- hs.geometry.rect(3.0,0.0,3.0,1)
  _h = 1,
  _w = 3.0,
  _x = 3.0,
  _y = 0.0
}
2024-09-17 10:05:13:                          moving right
2024-09-17 10:05:13:                          table: 0x600003478380 adjust window cell: { -- hs.geometry.rect(4,0.0,2,1)
  _h = 1,
  _w = 2,
  _x = 4,
  _y = 0.0
}
2024-09-17 10:05:13:                          table: 0x600003478380 SCREEN GRID: { -- hs.geometry.size(6,1)
  _h = 1,
  _w = 6
}
2024-09-17 10:05:13:                          table: 0x600003478380 name: Google Chrome
size { -- hs.geometry.size(1280,2135)
  _h = 2135,
  _w = 1280
}
loc { -- hs.geometry.point(2560,25)
  _x = 2560,
  _y = 25
}
2024-09-17 10:05:13:                          table: 0x600003478380 cell: { -- hs.geometry.rect(4.0,0.0,2.0,1)
  _h = 1,
  _w = 2.0,
  _x = 4.0,
  _y = 0.0
}
2024-09-17 10:05:13:                          moving right
2024-09-17 10:05:13:                          table: 0x600003478380 SCREEN GRID: { -- hs.geometry.size(6,1)
  _h = 1,
  _w = 6
}
2024-09-17 10:05:13: 10:05:13 ERROR:   LuaSkin: hs.hotkey callback: ...ammerspoon.app/Contents/Resources/extensions/hs/grid.lua:312: Cannot create geometry object, wrong arguments
stack traceback:
	[C]: in function 'error'
	...rspoon.app/Contents/Resources/extensions/hs/geometry.lua:138: in function 'hs.geometry.rect'
	...ammerspoon.app/Contents/Resources/extensions/hs/grid.lua:312: in function 'hs.grid.set'
	/Users/alex/.hammerspoon/modules/windows.lua:84: in function 'modules.windows.move'
	/Users/alex/.hammerspoon/init.lua:241: in function </Users/alex/.hammerspoon/init.lua:240>
2024-09-17 10:05:14: 10:05:14    windows:     moving right
2024-09-17 10:05:14:                          table: 0x600003478380 SCREEN GRID: { -- hs.geometry.size(6,1)
  _h = 1,
  _w = 6
}

Version

macOS: 14.6.1 (23G93)
Hammerspoon: 1.0.0

Closing comment (2024-09-18T15:05:38Z): Possibly related to #3224 etc. To check:
for _, app in ipairs(hs.application.runningApplications()) do
	local axApp = hs.axuielement.applicationElement(app)
	if axApp.AXEnhancedUserInterface then
		return "yes"
	end
end
return "no"
If so, there are a number of things that could have caused it to start happening for you, including but not limited to:

Installing certain software:

1Password
Grammarly
VimMode.spoon
Anything else that uses the Accessibility API to look inside other apps, and wants to make sure it works properly with Chrome
Firefox also does it to itself only, but you seem to be having it happen with Chrome, so…


Enabling certain accessibility-related system features:

VoiceOver
Hover text
Accessibility Keyboard (a.k.a. Keyboard Viewer)
Voice Control?



Workarounds are in #3224 (comment) and following comments.