rxhanson / Rectangle

Move and resize windows on macOS with keyboard shortcuts and snap areas
https://rectangleapp.com
Other
26.07k stars 789 forks source link

Broken resize/reposition behaviour sometimes, on some apps #29

Closed dylan-chong closed 4 years ago

dylan-chong commented 5 years ago

With some apps, sometime after rebooting the machine, resizing does not resize a window to its proper size.

On the screen recording, I am trying to resize the window to the left half by repeatedly pressing command+alt+left. As you can see, the window does not get repositioned/resized properly

ezgif-4-5e6caee4f299

I am using Mac OS 10.14.6 on a 13 inch MacBook Pro, with a 1440p display. The issue happens on any size display

A similar issue also happens with spectacle

rxhanson commented 5 years ago

I added a Troubleshooting section to the readme. Most importantly there, you'll need to enable logging and add some logs to this issue.

Which apps are affected? Do some apps move/resize properly? Does the issue resolve itself at some point and start working properly? Do the windows move/resize properly for the initial time period after a reboot? Is there anything that triggers the issue, like starting an application or adding/removing displays? How long does it work properly before the issue is seen?

dylan-chong commented 5 years ago

I have just realised that this seems to work the first time I open an app (e.g. with Spotlight), but if I switch apps then switch back (commands tab twice), then the issue starts to happen.

the behaviour of the above is rather inconsistent. The above happened with Kitty (terminal) the first time I opened it after restarting my computer, but for every other app, the problem always happens as far as i can tell.

This affects notes, Safari, finder, Spotify, Kitty basically anything as far as I can tell.

There doesn't appear to be any debug messages with the filter process:Rectangle any:calculatedRect, however removing the any:calculatedRect filter shows the following logs when I press cmd+alt+left

debug   13:24:25.283306 +1300   Rectangle   Getting process information for [ 0x0/0x6a06a]  from shared memory failed, so asking server for it
debug   13:24:25.283364 +1300   Rectangle   sending={asn=434282U, restrictto=["Hidden","LSApplicationHasSignalledItIsReady","LSDisplayName","ApplicationType","pid","ChangeCount"], command=360, }
debug   13:24:25.283780 +1300   Rectangle    reply={result={ApplicationType="Foreground", LSApplicationHasSignalledItIsReady=true, ChangeCount=530, pid=926, Hidden=false, LSDisplayName="Console", }, success=true, cacheable=false, }
debug   13:24:25.924970 +1300   Rectangle   Getting process information for [ 0x0/0x6a06a]  from shared memory failed, so asking server for it
debug   13:24:25.925027 +1300   Rectangle   sending={asn=434282U, restrictto=["Hidden","LSApplicationHasSignalledItIsReady","LSDisplayName","ApplicationType","pid","ChangeCount"], command=360, }
debug   13:24:25.925455 +1300   Rectangle    reply={result={ApplicationType="Foreground", LSApplicationHasSignalledItIsReady=true, ChangeCount=530, pid=926, Hidden=false, LSDisplayName="Console", }, success=true, cacheable=false, }
debug   13:24:27.177393 +1300   Rectangle   Getting process information for [ 0x0/0x6a06a]  from shared memory failed, so asking server for it
debug   13:24:27.177459 +1300   Rectangle   sending={asn=434282U, restrictto=["Hidden","LSApplicationHasSignalledItIsReady","LSDisplayName","ApplicationType","pid","ChangeCount"], command=360, }
debug   13:24:27.177904 +1300   Rectangle    reply={result={ApplicationType="Foreground", LSApplicationHasSignalledItIsReady=true, ChangeCount=530, pid=926, Hidden=false, LSDisplayName="Console", }, success=true, cacheable=false, }
rxhanson commented 5 years ago

Did you restart Rectangle after enabling debug logging?

Can you reboot your machine and not use kitty at all and see if the problem exists? Just want to narrow out kitty as a potential problem.

dylan-chong commented 5 years ago

Yes and I noticed the problem happen before opening Kitty

On 18/11/2019, at 9:30 PM, Ryan Hanson notifications@github.com wrote:

 Did you restart Rectangle after enabling debug logging?

Can you reboot your machine and not use kitty at all and see if the problem exists? Just want to narrow out kitty as a potential problem.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

rxhanson commented 5 years ago

Make sure that you're running with v0.9.1.

We're kind of stuck without getting the logs.

dylan-chong commented 5 years ago

The check for updates button says 0.9 is the latest version

rxhanson commented 5 years ago

https://github.com/rxhanson/Rectangle/releases/tag/v0.9.1

I didn't push v0.9.1 on the update channel because logging is literally the only addition to it (no need to prompt everyone to update when less than 1% of users need this).

dylan-chong commented 5 years ago

Ok, interesting. After installing 0.9.1 Rectangle is working perfectly on all the apps i listed previously except Finder.

But using finder these are the logs (doing the same as the screen recording but with finder and on the main display to make the x/y coordinates easier to read)

debug   09:58:54.994550 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 1120.0, 1050.0), resultRect: (364.0, 333.0, 1120.0, 717.0)
debug   09:59:07.955265 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 560.0, 1050.0), resultRect: (364.0, 333.0, 560.0, 717.0)
debug   09:59:09.141358 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 840.0, 1050.0), resultRect: (364.0, 333.0, 840.0, 717.0)
debug   09:59:09.705249 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 1120.0, 1050.0), resultRect: (364.0, 333.0, 1120.0, 717.0)
debug   09:59:10.470090 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 560.0, 1050.0), resultRect: (364.0, 333.0, 560.0, 717.0)
debug   09:59:10.872717 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 840.0, 1050.0), resultRect: (364.0, 333.0, 840.0, 717.0)
debug   09:59:11.242462 +1300   Rectangle   leftHalf | display: (0.0, 0.0, 1680.0, 1050.0), calculatedRect: (0.0, 0.0, 1120.0, 1050.0), resultRect: (364.0, 333.0, 1120.0, 717.0)
rxhanson commented 5 years ago

Thanks! That's some pretty strange behavior. Unfortunately, I'll have to add a bit more logging to get a bit more insight. At least we've narrowed this behavior down to the code that's moving the windows.

Since it'll take a little bit of time to get that out the door, it would be awesome if you could test out this build in the meantime:

https://github.com/rxhanson/Rectangle/releases/tag/v0.9.1.a

There's an off-chance that it could fix it. That build removes some questionable logic that was inherited from Spectacle.

dylan-chong commented 5 years ago

Exact same behaviour with 0.9.1a

rxhanson commented 5 years ago

Great, thanks for testing out 0.9.1.a. That actually helps tailor down the debug logging that I need. Try v0.10

https://github.com/rxhanson/Rectangle/releases/tag/v0.10

Since 0.9.1.a does not work, my hunch is that it's something I have no control over in Rectangle - that there is either some other application that's causing this behavior or there's some buggy behavior in macOS itself. Both reasons have been observed on other similar issues previously, so neither would surprise me. At the very least, v0.10's logs should give some confirmation.

dylan-chong commented 5 years ago

there's some buggy behavior in macOS itself

I suspect it is this as well.

What may be interesting is talon does window resizing that works perfectly. https://github.com/dwiel/talon_community/blob/4b4559141589b1290f1c223465a44c72f440cd56/misc/window_snap.py#L65

They have a slack channel (see the Chat button at the top) https://talonvoice.com and it might be worth inquiring how the guy solved that problem himself.

I'll be trying 0.10 to see how it goes in the next few days

dylan-chong commented 5 years ago

Hi again,

The problem just happened again on 0.10. It seems like the problem appears somewhat randomly - the problem is less likely to happen after rebooting, but is more and more likely to happen if the computer has not been rebooted in a day or so (maybe 6h+ usage as a guess).

rxhanson commented 5 years ago

If you don't mind, logs from 0.10 would be much appreciated! Thanks for going through the effort to try out each version that I've sent your way.

I'm still going to dig into talon and see if I can figure out what they did there. A quick glance through their code didn't reveal a solution.

dylan-chong commented 5 years ago

If you don't mind, logs from 0.10 would be much appreciated! Thanks for going through the effort to try out each version that I've sent your way.

Not a problem. No logs appear for the filter process:Rectangle on 0.10.

I'm still going to dig into talon and see if I can figure out what they did there. A quick glance through their code didn't reveal a solution.

I thnk the actual implementation isn't open source, but the guy on the slack channel will probably be happy to help you on the implementation of the api used in the code I linked above

dylan-chong commented 4 years ago

Ok i dont remember closing this. Reopening

rxhanson commented 4 years ago

So I haven't tried figuring out what talon did, but the latest pre-release version might actually fix it for you. https://github.com/rxhanson/Rectangle/releases/tag/v0.13 That release also has the updated simpler way to grab logs (see https://github.com/rxhanson/Rectangle#view-debug-logging).

Let me know when you get a chance to try it and we'll go from there.

dylan-chong commented 4 years ago

Thanks I'll give it a shot

rxhanson commented 4 years ago

v0.15 has a decent shot at fixing this. You can update to it from within the app, or at https://github.com/rxhanson/Rectangle/releases/tag/v0.15

If you still have issues on v0.15, send some logs my way. Thanks!

dylan-chong commented 4 years ago

Thank you so much for having a go at this!

I still get the same problem although i think the size is correctly sized:

Logs for spamming resize to right half/third/two-thirds shortcut:

2020-01-09T08:40:37+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:37+13:00: AX position proposed: (2151.0, -1440.0), result: (2151.0, -1440.0)
2020-01-09T08:40:37+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:37+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2151.0, -1440.0, 1280.0, 1440.0), resultRect: (1152.0, -1440.0, 1280.0, 1440.0)
2020-01-09T08:40:37+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:37+13:00: AX position proposed: (1725.0, -1440.0), result: (1725.0, -1440.0)
2020-01-09T08:40:37+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:37+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (1725.0, -1440.0, 1706.0, 1440.0), resultRect: (1206.0, -1440.0, 1706.0, 1440.0)
2020-01-09T08:40:38+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:38+13:00: AX position proposed: (2578.0, -1440.0), result: (2578.0, -1440.0)
2020-01-09T08:40:38+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:38+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2578.0, -1440.0, 853.0, 1440.0), resultRect: (1206.0, -1440.0, 853.0, 1440.0)
2020-01-09T08:40:39+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:39+13:00: AX position proposed: (2151.0, -1440.0), result: (2151.0, -1440.0)
2020-01-09T08:40:39+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:39+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2151.0, -1440.0, 1280.0, 1440.0), resultRect: (1206.0, -1440.0, 1280.0, 1440.0)
2020-01-09T08:40:39+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:39+13:00: AX position proposed: (1725.0, -1440.0), result: (1725.0, -1440.0)
2020-01-09T08:40:39+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:39+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (1725.0, -1440.0, 1706.0, 1440.0), resultRect: (1288.0, -1440.0, 1706.0, 1440.0)
2020-01-09T08:40:40+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:40+13:00: AX position proposed: (2578.0, -1440.0), result: (2578.0, -1440.0)
2020-01-09T08:40:40+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:40+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2578.0, -1440.0, 853.0, 1440.0), resultRect: (1288.0, -1440.0, 853.0, 1440.0)
2020-01-09T08:40:40+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:40+13:00: AX position proposed: (2151.0, -1440.0), result: (2151.0, -1440.0)
2020-01-09T08:40:40+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:40+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2151.0, -1440.0, 1280.0, 1440.0), resultRect: (1288.0, -1440.0, 1280.0, 1440.0)
2020-01-09T08:40:40+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:40+13:00: AX position proposed: (1725.0, -1440.0), result: (1725.0, -1440.0)
2020-01-09T08:40:40+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:40+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (1725.0, -1440.0, 1706.0, 1440.0), resultRect: (1288.0, -1440.0, 1706.0, 1440.0)
2020-01-09T08:40:41+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:41+13:00: AX position proposed: (2578.0, -1440.0), result: (2578.0, -1440.0)
2020-01-09T08:40:41+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:41+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2578.0, -1440.0, 853.0, 1440.0), resultRect: (1288.0, -1440.0, 853.0, 1440.0)
2020-01-09T08:40:41+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:41+13:00: AX position proposed: (2151.0, -1440.0), result: (2151.0, -1440.0)
2020-01-09T08:40:41+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:41+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2151.0, -1440.0, 1280.0, 1440.0), resultRect: (1288.0, -1440.0, 1280.0, 1440.0)
2020-01-09T08:40:41+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:41+13:00: AX position proposed: (1725.0, -1440.0), result: (1725.0, -1440.0)
2020-01-09T08:40:41+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:41+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (1725.0, -1440.0, 1706.0, 1440.0), resultRect: (1288.0, -1440.0, 1706.0, 1440.0)
2020-01-09T08:40:42+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:42+13:00: AX position proposed: (2578.0, -1440.0), result: (2578.0, -1440.0)
2020-01-09T08:40:42+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:42+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2578.0, -1440.0, 853.0, 1440.0), resultRect: (1288.0, -1440.0, 853.0, 1440.0)
2020-01-09T08:40:42+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:42+13:00: AX position proposed: (2151.0, -1440.0), result: (2151.0, -1440.0)
2020-01-09T08:40:42+13:00: AX sizing proposed: (1280.0, 1440.0), result: (1280.0, 1440.0)
2020-01-09T08:40:42+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2151.0, -1440.0, 1280.0, 1440.0), resultRect: (1288.0, -1440.0, 1280.0, 1440.0)
2020-01-09T08:40:43+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:43+13:00: AX position proposed: (1725.0, -1440.0), result: (1725.0, -1440.0)
2020-01-09T08:40:43+13:00: AX sizing proposed: (1706.0, 1440.0), result: (1706.0, 1440.0)
2020-01-09T08:40:43+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (1725.0, -1440.0, 1706.0, 1440.0), resultRect: (1288.0, -1440.0, 1706.0, 1440.0)
2020-01-09T08:40:43+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:43+13:00: AX position proposed: (2578.0, -1440.0), result: (2578.0, -1440.0)
2020-01-09T08:40:43+13:00: AX sizing proposed: (853.0, 1440.0), result: (853.0, 1440.0)
2020-01-09T08:40:43+13:00: rightHalf | display: (871.0, 1050.0, 2560.0, 1440.0), calculatedRect: (2578.0, -1440.0, 853.0, 1440.0), resultRect: (1288.0, -1440.0, 853.0, 1440.0)

I wonder if the 2nd animation (resize) prevents the first animation (reposition) from happening

dylan-chong commented 4 years ago

I have noticed that Talon sometimes performs two separate animations: 1st to reposition, then after that is complete, a second animation to resize. So I suspect that my above idea was correct

rxhanson commented 4 years ago

A note on the logs: AX sizing and AX position lines denote all of the actual calls from Rectangle to macOS, and their results. The fourth line for each window action is the result after everything's happened.

So, interpreting your logs: All of the commands issued by Rectangle to macOS are properly handled by macOS - the resulting size and positions are correct. After Rectangle has issued all of its move and resize commands, the window is not in the correct position.

There's two theories I see here:

Your theory is that the second resize is affecting the position. This would point to a straight up macOS bug. There's no documentation on exactly what should happen to the origin point of a window when setting the size, but the typical behavior noted is that the origin stays where it is and the window size is all that's changed. We could test out adding in delays to the window positioning logic, to try to see exactly what's going on in slow motion and see if it behaves differently when the calls are not made in quick succession, but since nobody else seems to be experiencing this other than the 1 person that +1'd this issue, I feel like it's not the best use of time. (Also there's very little traffic to this issue).

The thing is, these logs also point to the other theory that something that is not Rectangle is changing your window position. This seems much more likely to me, mainly because you are one of the few people seeing this, and every single time there's been something else like this it's that someone has something else running that's manipulating windows. I know you've said that you've made sure you don't have any other window managers running, but to me this is still the theory that makes the most sense. The fact that it also happened with Spectacle also points to this theory, because Rectangle's window movement logic is not identical to Spectacle.

I'm going to close this one out, but if anyone else has this identical behavior then definitely comment and I'll take another look. In the meantime, @dylan-chong if you want to clone the repo and test it out, I can help you get it running. Sorry this one's not solved. Thanks for trying things out and reporting back, though!

dylan-chong commented 4 years ago

Hey thanks so much for the detailed answer!

I think it has to be a Mac OS bug. The creator of Talon mentioned that Dragon (the dictation software I'm using) enables an accessibility feature hidden and undocumented inside Mac OS. This could be why I'm the only one experiencing the problem.

I might eventually get around to having a quick look at the code one day. if my suspicion is correct, then it might be good to attempt to implement some set of logic like:

do you have any places in the code that will be good to look at?

rxhanson commented 4 years ago

do you have any places in the code that will be good to look at?

AccessibilityElement is where the AX api is called - see setRectOf. It calls methods for setting size and position. That function is where you can set some delay functionality.

If you peel back the onion, you'll see setRectOf is called by WindowMovers, which are called from the WindowManager. The WindowManager is where you have the meat of the logic for what to do when an action is executed.

I don't think you'll have to look anywhere else in the code.

If you give things a try, I'll be interested to hear what you find. If you come up with a solution, I'd definitely be willing to roll something into Rectangle. If it's an undesirable solution (like adding delay), I'd still be willing to add it in with a configurable flag.

dylan-chong commented 4 years ago

Thanks! will let you know if i can make a fix

nickola commented 4 years ago

@rxhanson, I am experiencing the same issue with Chrome. And similar issue with Spectacle.

I use Punto Switcher (as keyboard layout switcher, for ctrl-shift support): https://yandex.ru/soft/punto/ I see this issue only when Punto Switcher is running. Punto Switcher has accessibility permissions to control computer (same as Rectangle). If I stop Punto Switcher and restart Chrome, Rectangle works as expected.

Rectangle 0.20. Punto Switcher 2.1.5.1724. Chrome 79.0.3945.130. MacOS Catalina 10.15.3.

rxhanson commented 4 years ago

@nickola thanks for posting this! Now I can finally reproduce it. When I get some free time, I'll dig in a little more and see if I can figure anything out (no guarantees on when that might be, though).

Looks like it is introduced by other apps that have some interaction with the macOS event stream, potentially via the Accessibility API (or at least controlled by the flag of having Accessibility enabled). My guess is still that this is not something I can fix within Rectangle the way that it is implemented. Punto Switcher, and probably Dragon uses an installer, which means that it might be using a kext or something of the sort and it might be modifying the event stream at a lower level in the OS than Rectangle. The event stream can get messed up by other apps - I've even read posts where Magnet messes up the event stream for macOS trackpad input.

Magnet also shows the same issue here while Punto Switcher is running, although it's a little smoother behaving since it doesn't have the 1/2 -> 2/3 -> 1/3 subsequent actions that Rectangle & Spectacle have.

I have no idea why Chrome would show these issues but finder & terminal would not for me. Always when this issue exists, the windows show a resize animation, and I'm not sure why that's the case either.

Bottom line is that there are a lot of factors outside of Rectangle that are causing this, and at this time I honestly don't think Rectangle is the place where this should or can be fixed. Unfortunately, it's not something that I see Apple caring about enough to figure out what's going on, either.

rxhanson commented 3 years ago

This should now be fixed in v0.40.