-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Added APIs for detecting multiple displays and setting windows on them. #1930
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments about the specific implementation; the comments I've added to the Cocoa implementation also apply to the other backends.
There's one other major comment: How do I test this?
As you should have seen from the last couple of PRs from you that I've merged, I've added manual test cases. This is just formalising what I have to do myself - in order to validate that a new feature works, I need to have a way to exercise that API. I presume you have tested this code as well - one way to prove to me that you have is to provide your testing app.
In this case, there's no need for an entirely new app - you can use the existing Window example app. Add a row of buttons where the number of buttons equals the number of screens returned by the screens API. Pressing button 1 moves the window to screen 1, and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need some advice on how to review this.
Yes, there is now an example app. However...
- It doesn't work in the multiple screen case... which is the one case you'd care about for a feature adding multiple screens. It always sends the window to the last discovered screen, because the
screen
variable is a closure over a variable that is modified in the loop. - It raises an error on macOS because an attribute is being used as a function
- On GTK, it raises numerous warnings about using deprecated APIs
- On Windows, the new buttons don't appear in the app's window unless you resize the app window. This isn't a bug that you've introduced (beyond the "the buttons all fitted previously"), but it's odd you didn't mention it, since it's a notable problem.
If there are known gaps in an implementation (e.g., I haven't been able to test this on macOS) it's a courtesy to let the reviewer know so that they're able to restrict the core of their review to what you, as the developer, have confirmed actually works.
If you're not able to verify the implementation at all... I have to wonder why you've decided to implement this feature. I understand that it's an offshoot of the original "min/max" API... but at no point in the process of discussing the implementation of this have you raised any potential issues with testing this feature; nor have you asked the question about whether this feature is a necessary pre-requisite of implementing the min/max APIs that we iterated on.
Outside of those bugs; it's not clear why the behavior you've implemented is "move the window to the origin on the new display" (and, on macOS, that position is bottom left, not top left of screen). Why not preserve the on screen position, but on a new window? Sure, not all windows have the same resolution, but most are similar; and would seem a lot less surprising to me.
I've flagged a couple of other things that stood out; but it's a little frustrating to be asked to review something when it appears significant portions of it haven't been tested.
You are correct. I apologize for any inconvenience caused due to this commit. I should have mentioned that thorough testing had not been done. Moving forward, I will always specify the testing status of the commit.
I have addressed this issue in the latest commit.
I have addressed the deprecated APIs and updated the code to follow the proper APIs. The deprecation warnings were raised as
Could you please also provide the specific error message, since I do not have access to a mac and haven't tested on it.
I mean the main box was using a Also, a related question, is there any particular reason for there to be a separate
Currently, the windows are set at the origin of the display to which they are moved. On MacOS, the origin happens to be the bottom left. Since, it is a native behavior, I thought of not messing with it to change it to the top left. If a window will be originally positioned between 2 displays, then preserving the original position can make it seem like the window didn't move to the other display.
Won't happen again. I will now always attach the test status of the latest commit before requesting a review. For the current commit, I have:
|
I don't see how. I can't see any change to the demo app.
I've pushed an update that fixes the API error (as well as simplifying the use of generators in favor of a simple comprehension. There's no benefit to a generator in this case).
It shouldn't need to be a scroll container. There's no specifier of window size; the window should size itself to fix the content. However, as I noted, this isn't a problem of your making.
No specific reason, beyond the fact that they're implemented with different widgets on every platform except the web.
Look at the implementation of
I'm not sure we're meaning the same thing. I mean "if the window is currently at 100,100 on screen 1, and I move to screen 2, it should be at 100,100 on screen 2". As an example why this matters: consider the behavior of
I don't see how this can be true, because the test app does not work as currently implemented. I can only assume your test regimen is "click the first display button", and see that the window moved screen. If you use all the available screen-move buttons, you should see that every button directs the window to the same screen. |
My apologizes. It seems that I had made changes to the demo app in a separate local branch and had forgot to merge with the working branch which was pushed to the origin. I have committed and pushed the changes of the demo app and now it should work as expected.
I agree that preserving the window positions would be better. I also propose that Since, there will be dedicated APIs for multi-screen, hence users would want to set window positions on a particular screen, instead of manually calculating the coordinates themselves. |
I would propose having the option to do it both ways. In some cases it could be easier to set window position by 1 coordinate system that includes all windows. Like for instance: In my app I currently have a window drag functionality that offsets the windows position as the user moves the mouse - this would be very difficult for me to do if I had to take monitors into account |
To clarify the use case here - is the issue being able to position the window on other screens relative to the current screen, or having an absolute position that is always present? i.e, if |
Yes, I think there should be an absolute position API. Maybe like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - on that basis, I'm going to say we should make window.position
relative to the current screen top-left, preserving the ability to move a window to a separate screen by providing a negative or larger-than-screen-size coordinate. We can also look at adding an window.absolute_position
attribute, which is always relative to screen 0's origin - but we can add that as a separate API if you want.
Hello Thanks |
@proneon267 Understood. Good luck with the exams; we'll see you back when your free time returns! |
4784eac
to
e07153a
Compare
Hello, I am back :) |
Yes, One other detail thats stand out from a quick re-review: The issue of preserving position as you move across desktops still exists. On macOS, the window is always positioned at the origin of the new screen - which, in native macOS coordinates, is the bottom left. I haven't tested Windows and GTK, but from a quick read, I suspect a similar problem exists. Two other details that have emerged in your absence:
|
Hello,
Based on it, I am suggesting to do something like this on the backend( Example: WinForms):
And as for preserving the original window position, a simple change of origin should be good like:
What do you think? As for the unit test and dummy backends, I will write them after we finalize the window position things. |
I think a code snippet in a comment is probably the worst way to review this sort of thing. However, it's not immediately clear to me that this requires 2 platform specific implementations. The implementation API is "set position". The public interface API of "set screen relative position" and "set absolute position" can both be expressed in a single underlying implementation API, and the math of "position of a window relative to the screen it is on" should be identical (AFAICT) on every platform. My other thought is whether we should reverse the naming to avoid a backwards incompatibility - retain |
Yeah, I should have submitted a new commit for review. I agree with you that:
Also:
Do you mean there should be a single backend function called
You mean the origin should be at the top left of the screen on every platform? |
No - I mean that there should be a single backend function called
I'm not sure what you're asking. There is not single "origin". The origin of the screen specific set position API should be the top left of the screen in question. The origin of the absolute set position API should be the top left of the "primary" screen. Regardless of platform, origin is always top left of a screen; the only question is which screen. |
Just a heads up, since #2155 is not merged, the current dpi scaling implementation is non-functional. So, try to run any app at 100% dpi scaling for expected and correct results. |
45de2c9
to
16b33ae
Compare
Ack - I've just rolled back the scaling changes that I made; I think we can wait until #2155 for a full fix (or, at least, merge this and fix the winforms scaling issue as part of #2155). |
Thanks. I'll try to complete that PR as soon as I get a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now passing on my macOS install, so it looks like we've finally nailed the retina fixes - nice work!
I've pushed a few other minor cleanups; so this PR is looking good... except for one thing that showed up in final testing: the take screenshot
button on the window
example doesn't seem to work - it's returning a "coroutine was never awaited" error.
At least part of the cause - the screen name is \\.DISPLAY1
... and the filename being saved is screenshot_{screen.name}.png
.... and hilarity ensues :-) I'm not familiar with Windows naming conventions for screens, but I wonder if it might be preferable to strip the \\.\
part of the display name.
Sure. I'll just quickly remove it and try to run the tests. |
I have removed the non-text part but even before removing it, the screenshot button worked correctly and didn't return the error that you got. |
Confirmed that the |
I don't see this error on macOS. I only see it on Winforms. |
Does this script produce the same error on winforms:
|
Can confirm that the error arises from the line:
|
Final Confirmation :-) The examples/window works on python I'm guessing the same is true for you, you have a newer version on macOS but an older version on windows and hence got the error. |
Nope. I'm running 3.10.5 on Windows, 3.10.11 on macOS. Your sample program works for me on macOS; fails on Winforms with the same "coroutine never awaited" error. |
Yeah also doesn't work on |
Nice catch! I can confirm that fixes the issue - although I'd be interested to know the exact bug that fixed the issue. With that resolved, I think we're good to go - the only issue I'm aware of that remains is the HiDPI screenshot issue with Winforms, which will be addressed by #2155. |
Thanks. I'll make the required changes of winforms screen in #2155. |
Implements the features described in #1884 for detecting multiple displays.
PR Checklist: