-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hs.window:moveToScreen() behaves weirdly in macOS 12.4 when applied to a Google Chrome window. #3224
Comments
I did not use that function for my code, since i wrote some on my own... Here is an excerpt from my code. I found some things from that online and derived this from it. local function initWindowValues()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
return win, f, screen, max
end
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "/", function ()
local win, f, screen = initWindowValues()
local screens = hs.screen.allScreens()
local i = 0
local screenNo = 0
for i = 1, #screens do
if screens[i]:id()==screen:id() then
screenNo = i
end
end
local newScreenNo = screenNo+1
if newScreenNo>#screens then
newScreenNo = 1
end
win:moveToScreen(screens[newScreenNo])
end) May be this helps you a little bit to fix that function stuff. |
I've recently observed the same thing happening with Firefox (101.0) on macOS 12.4 and Hammerspoon 0.9.97 (6267), but I'm using So out of curiosity, are you also using 1password 8 with the new Universal Autofill feature? If so, we might be seeing the same issue related to it. If not, sorry for the tangent on your thread. 😄 |
That's exactly my situation too. 1PW 8, Chrome, latest macOS. I think you're on to something here. |
Maybe related: pqrs-org/Karabiner-Elements#3075 (comment). Weirdly, the comment mentions the problem being solved after upgrading to macOS 12.4. |
FWIW, I see the same behavior with Safari and 1password with Universal Autofill... and I'm already running 12.4, so... Not sure what's up, but I'll check out the 1password forums later today and submit a bug report if it's not already known. I'm pretty sure it's not anything Hammerspoon is doing, so it's either a macOS change/bug that we're not aware of or an issue with 1password and how it's tapping into things for the autofill support. |
I'm having this issue, and I'm also a 1Password user.
I tried a couple other combos inconclusively - it could be that, in some percentage of cases, closing and relaunching Chrome temporarily fixes the problem regardless of whether 1Password is involved. |
Just adding another +1 for the weirdness @zackfern mentioned above. Only my browser window shows the animation and requires multiple attempts to move the window to the correct location. App Versions
|
Another +1 here, happens in both chrome and edge and with 1password 7, not 8 App Versions
|
Same issue here. I do have Karabiner Elements installed as well as 1password 8. It's only that the shortcuts I created in hammerspoon to move windows fast to a desired position in a desired size don't work properly for Firefox. It's slow and often misplaced. Only a second hit moves it correctly (most of the times). I'm using
|
For me, this issue has been resolved. It was in fact an odd interaction between 1Password's MacOS app and Chrome plugin. I worked on this with Paul from 1Password support, sending him here and explaining how to set up Hammerspoon and reproduce the issue. I installed a desktop app update on July 12th and haven't seen this problem since. FWIW my 1Password for Mac reports version 8.9.0, 80900001 on BETA channel. |
Hmm, I'm not a 1Password user, but I'm using LastPass. I don't remember hitting this issue in Firefox, where LastPass is also installed. Also, after moving to an M1, I'm no longer able to reproduce this issue. |
I think this issue is now resolved. |
I still have the issue.
|
This issue was resolved a few weeks ago but I think you may have to be
using the 1Password beta.
I'm on 1Password Extension Beta v.2.4.3, and 1Password for Mac 8.9.0.
monty
…On Mon, Aug 15, 2022 at 3:14 PM François Côté ***@***.***> wrote:
I still have the issue.
- macOS 12.5
- Chrome 104.0.5112.79
- Hammerspoon 0.9.97
- 1Password Extension 2.3.7
—
Reply to this email directly, view it on GitHub
<#3224 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAANG2DKNVQY2G5JVZQSUDDVZKQLFANCNFSM5XMK6HCA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I tested some more, and now I am pretty sure this is not related to 1Password. I was able to reproduce on a machine without 1Password installed, with a fresh installation of google chrome stable.
|
and I found my own personal culprit. It is caused by the Gramarly Desktop app. As soon as I quit this app and restart Chrome, everything is instant again. Just dropping this here in case it helps someone else. It seemed that this can be caused by any app that creates overlay windows on top of electron-based apps. |
It was Grammarly for me as well. Thank you so much! This was driving me crazy 😂 |
I have contacted Grammarly regarding this issue and haven't received any solution. Is there something that can be done from Hammerspoon's side? I debugged the Lua code for hammerspoon/extensions/window/libwindow.m Line 227 in 1bd0c18
Can anybody shed some light on what's happening under the hood? Thanks! |
I don't use 1Password or Grammarly myself, but they both sound like they would be using the Accessibility API to see what's going on in other apps. Chrome/Chromium and its derivatives (including Electron) don't create the full tree of accessibility info by default (for performance reasons, if I remember correctly) - they only do so if something sets the Unfortunately, there seems to be a system bug that messes up attempts at moving/resizing a window through the Accessibility API when the window's app has Rectangle worked around it in this pull request, by temporarily disabling -- win = some `hs.window` instance
local axApp = hs.axuielement.applicationElement(win:application())
local wasEnhanced = axApp.AXEnhancedUserInterface
if wasEnhanced then
axApp.AXEnhancedUserInterface = false
end
win:setFrame(newFrame) -- or win:moveToScreen(someScreen), etc.
if wasEnhanced then
axApp.AXEnhancedUserInterface = true
end (Electron added an |
This is amazing. Thank you so much for sharing it! I implemented a couple of helper functions that implement your suggested fix. It is working like a charm: function axHotfix(win)
if not win then win = hs.window.frontmostWindow() end
local axApp = hs.axuielement.applicationElement(win:application())
local wasEnhanced = axApp.AXEnhancedUserInterface
if wasEnhanced then
axApp.AXEnhancedUserInterface = false
end
return function()
if wasEnhanced then
axApp.AXEnhancedUserInterface = true
end
end
end
function withAxHotfix(fn, position)
if not position then position = 1 end
return function(...)
local args = {...}
local revert = axHotfix(args[position])
fn(...)
revert()
end
end The former wraps around the received window object, and returns a function that reverts the hack. The latter wraps a function. The usage is something like this: local patchedPushWindowUp = withAxHotfix(grid.pushWindowUp) Or, if the wrapped function receives the window in a different position, something like this: local patchedAdjustWindow = withAxHotfix(grid.adjustWindow, 2) If no window is passed, it takes the frontmost window. I think this matches most of hammerspoon APIs. Cheers! |
I think that 'revert' function inside |
Whoops, I messed up when I copy-pasted some code. I'll edit it, so people don't get confused. Thanks! |
This would be a fairly easy fix to add to the |
The only thing I know of is movement and resizing, but I can't say for sure. Doing some experimenting in the Hammerspoon console, it looks like what's happening is that when (On a possibly-related note, why does Footnotes |
Thanks for the explanation @Rhys-T. Although disabling My approach is to move the window to the top left first and then make it a full screen. The code looks like this: function fullscreen(win)
local screenFrame = win:screen():frame()
win:setTopLeft(screenFrame.x, screenFrame.y)
-- Waiting 0.4 seconds to make the two step transition work
-- You might need to adjust this.
hs.timer.usleep(0.4 * 1000 * 1000)
win:setFrame(screenFrame)
return win
end This makes it two steps with a delay, but I found it quicker than controlling This is quite hacky, but I hope someone finds it helpful. |
Good to know. If that workaround is slowing things down, maybe it shouldn't be built into |
Possibly related to the lag mentioned above: Chrome apparently has a recent bug (#1364487) causing it to lag whenever anything turns its |
Looks like that particular bug has been fixed in recent Chromium/Chrome versions. May take some time to propagate to other Chromium-based browsers, though (and Electron apps, if they're affected). |
I ran across this issue today when installing a new system (amongst others, Safari was affected). I was a bit surprised since I never had this problem on another, almost identical system. Or at least so I thought. In fact, both systems show the behavior, but only if my Hammerspoon config is (re-)loaded while the corresponding app is still open. If Hammerspoon has loaded and I quit and reopen the app, everything works fine. My other system always loaded Hammerspoon at startup and I rarely reloaded the config… |
@pitkling That's odd - as far as I know, the only thing that should be controlling whether the issue occurs or not is the state of the app that's being controlled (specifically, its Are you by any chance using the VimMode spoon, or any other HS code that might turn on |
@Rhys-T: You're completely right, thanks for pointing that out! I actually started to use VimMode recently and deactivating it removes the problem altogether. I wasn't aware that VimMode is also affected by this, but makes sense (and similar issues seem to have been reported there, e.g., dbalatero/VimMode.spoon#45 and dbalatero/VimMode.spoon#68). |
@pitkling Sounds like with VimMode loaded, the role of "app that turns on everyone else's |
@Rhys-T Works like a charm, thanks. Just for reference, in case someone else wants to use that workaround with window object methods like
Also, just wondering:
Is it still considered to built this into |
Hammerspoon/hammerspoon#3224 Unfortunately this loses resize animations, but resizes work the first time.
For me, Quit this app and restart computer fixed my issue |
Hmm… that definitely sounds like the sort of app that might turn on |
I am still experiencing this, albeit just on Firefox. The frustrating part is that I'm using Macos 14.1.1 |
I don't know why I hadn't thought of this earlier, but Another thing I noticed is that if we set it back to The following works for me for hs.grid! Fix for animationDurationlocal function axHotfix(win)
if not win then win = hs.window.frontmostWindow() end
local axApp = hs.axuielement.applicationElement(win:application())
local wasEnhanced = axApp.AXEnhancedUserInterface
axApp.AXEnhancedUserInterface = false
return function()
hs.timer.doAfter(hs.window.animationDuration * 2, function()
axApp.AXEnhancedUserInterface = wasEnhanced
end)
end
end
local function withAxHotfix(fn, position)
if not position then position = 1 end
return function(...)
local revert = axHotfix(select(position, ...))
fn(...)
revert()
end
end Fix for
|
I noticed the other day that Firefox was getting local fx = hs.axuielement.applicationElement(hs.application'Firefox')
fx.AXEnhancedUserInterface = false
return fx.AXEnhancedUserInterface, fx.AXRole, fx.AXEnhancedUserInterface
-- false AXApplication true
|
Thanks for looking into FF! I had tried disabling everything requiring accessibility permissions and it was still enabled, I thought it was my work's mdm/antivirus/spyware for a moment |
Relevant Firefox bugs tracking this issue:
|
I patched just the local windowMT = hs.getObjectMetatable("hs.window")
windowMT.setFrame = withAxHotfix(windowMT.setFrame) but one nitpick I see here because of the delayed reset: when I have this commands: local externalScreen = hs.screen.allScreens()[2]
local window = hs.window.frontmostWindow()
window:moveToScreen(externalScreen, false, true)
window:setFrame({
x = exterwnalScreen:frame().x + (externalScreen:frame().w / 2),
y = externalScreen:frame().y,
w = externalScreen:frame().w / 2,
h = externalScreen:frame().h,
}) then the hotfix is fired twice. one with the |
In my environment, this issue disappeared for quite a while but resurfaced recently, but with some differences:
I applied the trick suggested by @xaviergmail in this comment, and it worked. |
After upgrading to macOS 12.4 Monterey, I've noticed two issues:
moveAndResize
function in theWinWin
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.moveToScreen()
inWinWin
, 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:
Version information:
The text was updated successfully, but these errors were encountered: