rxhanson / Rectangle

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

2nd monitor issue #845

Closed maticboncina closed 2 years ago

maticboncina commented 2 years ago

Hello,

I've noticed a "huge" bug in Rectangle, which is breaking the default MacOS behaviour.

The situation is a bit weird so I will do my best to explain it.

General description of the problem with the app: When a 2nd monitor is plugged into HDMI port, MacOS detects it and the image is displayed normally. However, if this monitor is then turned off (not unplugged), the Mac still thinks the displays is there and all apps, stay there. You can even move to it with a mouse even if it's not there anymore. This doesn't happen on freshly erased macOS (below, I have described expected behaviour).

Recording of default behaviour (simulated): https://img.titanblast.pro/4yTfiR

https://user-images.githubusercontent.com/54638868/177035651-7a1d0bd5-8afc-4d30-b82e-f0f8b6ac492c.mp4

Record of behaviour when Rectangle is installed: https://img.titanblast.pro/9K0m71 - You can see how the mouse can go through and above where my 2nd monitor normally is).

https://user-images.githubusercontent.com/54638868/177035629-3d925ffd-a9ef-4012-838b-8341f9362f5b.mp4

This is how monitor setup looks in the Display settings: https://img.titanblast.pro/MYRRCu CleanShot%202022-07-03%20at%2012 12 29

In both cases, the display is only turned off and not unplugged. If display gets physically unplugged the issue goes away and default MacOS behaviour is seen (likely because there's just 1 screen present). It's important to note that it only happens if you turn the monitor off.

Expected behaviour: When 2nd monitor is turned off all the apps are moved to the active/built in display, and you cannot go outside main display anymore. So it stops at the top/left/right wherever it's set in Display settings.

Steps to reproduce:

  1. Install Rectangle
  2. Plug in the external display
  3. Wait for picture to show
  4. Turn off the monitor with a power button (don't unplug the cable)
  5. Issue should happen

I've tried on 2 external monitors from different manufacturers and it happened on both.

System information: Macbook Pro 16 2021 (M1 Pro) Monterey 12.4 (21F79) - Latest at the time of report External HDMI display connected either via USB-C adapter (USD C to HDMI and some other ports) OR directly connected to the MacBook's built in HDMI port. It happens on both outputs.

Let me know if you need any more info on the case. Videos and images also attached through the issue.

All the best, Matic

rxhanson commented 2 years ago

Thanks for the detailed report!

I'm not looking to dodge or dismiss this issue, and I won't rule out that it could be somehow related to Rectangle. But, it would be really unlikely that Rectangle would cause this behavior, and unfortunately there's not really anything that could be done about it from Rectangle's side if somehow this was a side effect of having Rectangle installed/running. All Rectangle does is query the available screens and their dimensions, which is a commonly used API in macOS. It does not have capabilities to change anything about the displays. This is OS level functionality and shouldn't be affected by apps that query the screens, and if it is then it should be fixed in macOS.

My guess as to what's going on here is that it is related to how macOS handles displays and could be specific to third party display hardware capabilities (the behavior I've always seen is what you consider not working properly).

rxhanson commented 2 years ago

(side note) I did notice that Rectangle is running in both of your videos.

maticboncina commented 2 years ago

Thanks for the detailed report!

I'm not looking to dodge or dismiss this issue, and I won't rule out that it could be somehow related to Rectangle. But, it would be really unlikely that Rectangle would cause this behavior, and unfortunately there's not really anything that could be done about it from Rectangle's side if somehow this was a side effect of having Rectangle installed/running. All Rectangle does is query the available screens and their dimensions, which is a commonly used API in macOS. It does not have capabilities to change anything about the displays. This is OS level functionality and shouldn't be affected by apps that query the screens, and if it is then it should be fixed in macOS.

My guess as to what's going on here is that it is related to how macOS handles displays and could be specific to third party display hardware capabilities (the behavior I've always seen is what you consider not working properly).

Hi, so basically in short I assume there’s nothing that can be done really? :( - I would love to get to the bottom of this as it’s pretty annoying and if there’s any troubleshooting step I can take I’d much be welcomed to try it out.

(side note) I did notice that Rectangle is running in both of your videos.

Yes Rectangle is running in both demos. That’s why I put “simulated”. I just unplugged the monitor to demonstrate how it was supposed to be. Didn’t want to go through a hassle of reinstalling and reconfiguring all custom shortcuts again.

I can assure that it worked normally before rectangle was installed.

Thinking of it it (remind on an issue from my programming job) could it be that maybe it continues to remember the old monitor even after it is turned off because it is still being queried through the API, thus MacOS thinks monitor is there as program is trying to reach it?

Basically in a way it produces a ghost monitor where because of quering the API macos thinks it’s there but in physical world it’s not anymore 😅

All the best, Matic

rxhanson commented 2 years ago

Yes Rectangle is running in both demos. That’s why I put “simulated”. I just unplugged the monitor to demonstrate how it was supposed to be. Didn’t want to go through a hassle of reinstalling and reconfiguring all custom shortcuts again.

Ah got it :)

Thinking of it it (remind on an issue from my programming job) could it be that maybe it continues to remember the old monitor even after it is turned off because it is still being queried through the API, thus MacOS thinks monitor is there as program is trying to reach it?

Even if Rectangle had a strong reference on the NSScreens query and retained the NSScreen unnecessarily, it's on macOS to keep tabs on the connected displays and determine if the cursor should be able to go outside of a display or not. I don't like to point a finger and brush it off, but in my opinion this is something that should properly be handled by macOS, and even if there were some sort of workaround in Rectangle (which seems unlikely off the top of my head), there's still a bug in macOS.

Hi, so basically in short I assume there’s nothing that can be done really? :( - I would love to get to the bottom of this as it’s pretty annoying and if there’s any troubleshooting step I can take I’d much be welcomed to try it out.

I definitely welcome any outside contribution on this, but I don't think it's something that I will dive into. If I were to start troubleshooting this one, here's what I would do:

Create a new Mac app with nothing in it, except for an NSScreen query. You can look at what Rectangle does in the ScreenDetection file. If you make something with a query that doesn't cause this issue, then you'd want to add more pieces of Rectangle to see where an issue might be. It could even be that Rectangle uses the Accessibility API, and that API is causing the issue (I've seen other weird stuff like that before). Therefore, the next logical piece to add would be some Accessibility API usage (see AccessibilityElement) and try to move/resize a window. Let me know if you have more questions there.

steffex commented 2 years ago

In my understanding this behaviour is caused by OS X, because turning the device off does not register as the monitor being disconnected (at least when in combination with HDMI).

I can reproduce the same result as when I power down my second screen. The mouse continues through the display border, even when Rectangle wasn't opened. I've tested this with my M1 MacBook pro connected to a second display via usb-c adapter to HDMI cable, using this scenario:

  1. Make sure Rectangle doesn't start at login
  2. Quit Rectangle
  3. Restart Mac
  4. Make sure no apps are opened after login
  5. Wait for reboot to be complete
  6. Turn off second monitor
  7. Reproduce the same result!

This should verify that Rectangle has nothing to do with this "bug".