-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expose screen dimensions #1519
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
Expose screen dimensions #1519
Conversation
|
Thanks for this! 🚀 To answer your questions:
I think it's ok. The thing to keep in mind sometimes people have multiple monitors, which will affect the API.
Do you mean the DPI of the screens? This is handled behind the scenes for most scenarios. I think it's ok not to report that in this instance.
I'll add more documentation on how to do this and use this as an example for that. The only places you've left out are the darwin+windows implementations of the method but I'm assuming that's deliberate for now. These aren't auto-generated but that's not a bad idea ;-)
I think I agree with you that it needs to be in a new "namespace". You suggested "Screen" and that's not a bad option.
Testing is hard for gui apps, but unit tests can be added using the
You're doing well - keep going! 👍
Always in
All GUI functions should normally happen on the main thread or else they have a habit of going a bit mental. This causes issues when you need to return values as now they are happening on a different thread. The wait groups are there to coordinate this and wait until the call has completed before returning the result. See it as an async to sync mechanism. |
|
Thank you for the feedback. I'm working on this. Will post back when I have something working for Linux with a new 'screen' api. |
I was getting the following errors due to some bad casts. Gdk-CRITICAL **: 18:58:51.943: gdk_monitor_get_geometry: assertion 'GDK_IS_MONITOR (monitor)' failed Gdk-CRITICAL **: 18:58:51.943: gdk_display_get_monitor_at_window: assertion 'GDK_IS_DISPLAY (display)' failed This commit fixes these errors
…into expose-dimensions
|
@leaanthony , This PR now exposes a Here is some sample go and js on my system (with outputs) func (a *App) OnDomReady(ctx context.Context) {
screens, err := runtime.ScreenGetAll(ctx)
if err != nil {
fmt.Printf("Error getting screens: %v\n", err)
return
}
for _, screen := range screens {
fmt.Printf("{height=%v, width=%v IsCurrent=%v, IsPrimary=%v}\n", screen.Height, screen.Width, screen.IsCurrent, screen.IsPrimary)
}
}Output runtime.ScreenGetAll().then(screens=>{
screens.forEach(screen=>{
console.log(screen)
})
})Output {isCurrent: true, isPrimary: true, width: 1280, height: 720}
{isCurrent: false, isPrimary: false, width: 960, height: 540}Is this API OK now? Should I get started on Windows/MacOS, or are there some changes/a different that you'd like to see? |
| GdkMonitor* getCurrentMonitor(GtkWindow *window) { | ||
| // Get the monitor that the window is currently on | ||
| GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(window)); | ||
| GdkWindow *gdk_window = gtk_widget_get_window(GTK_WIDGET(window)); |
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 should be removed from this PR and put into a different PR and a different commit. In fact, this isn't even the change I meant to introduce (however, there is a bug in this code that I have a fix for).
|
Looking good so far 👍 |
|
Glad to report that the windows implementation is working! As an aside @leaanthony how have you debugged on windows? I couldn't get the windows commant prompt or powershell to output to stdout, it simply opens the windows which is another process. I attmpeted to use procmon and windows debugger but I couldn't figure out how to view simple |
|
I just use the |
|
@leaanthony , all three platforms have been implemented. What should the next steps be? |
|
Need to find time to review it 👍 |
leaanthony
left a comment
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 looking and working great! My only comment is that on MacOS, the screen height looks to be affected if the task bar is there. If I'm on a screen with a taskbar, it reports 64 pixels less than when the taskbar is hidden. I think this is because the code is using visibleFrame instead of frame. So we could either return both, or keep it consistent between the platforms (report full screen size for all platforms). Thoughts?
| * // Gets the all screens. Call this anew each time you want to refresh data from the underlying windowing system. | ||
| * | ||
| * @export | ||
| * @return {Promise<{isCurrent: boolean; isPrimary: boolean; width : number height : number}>} The screens |
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.
Does this return an array of objects?
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.
Yes, this is a mistake. In fact, my IDE complains about this syntax anyway. BTW, what syntax is this documentation written in?
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.
JSDoc, though I think you can use typescript syntax.
| first.RcWork.Bottom == second.RcWork.Bottom && | ||
| first.RcWork.Right == second.RcWork.Right && | ||
| first.RcWork.Left == second.RcWork.Left && | ||
| first.DwFlags == second.DwFlags |
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 looks like a duplicate comparison
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 didn't know if comparing RcMonitor only instead of also comparing RcWork was enough to guarantee uniqueness of a monitor. Does RcMonitor carry enough uniqueness to drop the comparison with RcWork
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.
Sorry, I meant you have first.DwFlags == second.DwFlags twice
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.
Ah, I missed that. Yes, I'll remove that.
|
#1519 (review) Overall I would like to get your feedback on the rest of the questions I left i response and clean the code up a bit (I think I have a typo in a function name somewhere, I need to find it). Should squash the commits that I think don't contribute anything? Or would you prefer I leave the history as is? |
…into expose-dimensions
To use frame instead of visibleframe to keep into account the space the the dock takes up We want to include that space in the calculation in order to keep the sizes of screens consistent across platforms
It used to say it returned a single screen object. Now it says that it returns an array of screen objects
|
I've taken care of all of the changes requested. Anything else you'd like me to do here? BTW, this question still stands:
|
|
I'll check it out over the weekend. We'll squash merge so all good 👍 |
|
@all-contributors please add @skamensky for code, ideas and docs 👍 |
|
I've put up a pull request to add @skamensky! 🎉 |
|
Nice one! This is a fantastic contribution 🎉 |
|
Yay thank you for guiding me through my first open source contribution! |
|
First? Really? You did a fantastic job! 👏 |

PR for issue #1518
Status: working for linux
Upcoming changes: macos and windows implementation of get dimensions
Requested feedback before I continue working on this:
Some other questions
When do we put c implementation in the
/v2/internal/ffenestri/ffenestri_{platform}.cfiles and when do we put them in the/v2/internal/frontend/desktop/{platform}/window.gofiles?When do we need wait groups+invokeOnMainThread?
for example I see a wait group here
wails/v2/internal/frontend/desktop/linux/window.go
Lines 709 to 719 in 41d1bf3
But none here
wails/v2/internal/frontend/desktop/linux/window.go
Lines 733 to 737 in 41d1bf3
When do we need to add to this switch statement?
wails/v2/internal/frontend/dispatcher/systemcalls.go
Lines 23 to 41 in 41d1bf3