Skip to content
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

Ability to make windows start centered #4376

Open
PlanetTeamSpeakk opened this issue Jan 18, 2024 · 5 comments
Open

Ability to make windows start centered #4376

PlanetTeamSpeakk opened this issue Jan 18, 2024 · 5 comments
Labels
api Changes or additions to APIs enhancement New feature or request

Comments

@PlanetTeamSpeakk
Copy link

It seems like it is not possible to make a window start in the center of the screen it launches on. I have found it's possible to set the position of the window before showing it, which, in combination with the size of the screen and of the window, can be used to make it start at the center, except it appears to be impossible to find out the size of the screen that the window will be shown on, hence it seems to be impossible to make it start centred.

Thus, I would like to request a feature to do this.

@ogoffart
Copy link
Member

Thanks for the feature request.
This was discussed in #3859

@ogoffart ogoffart added enhancement New feature or request api Changes or additions to APIs labels Jan 18, 2024
@PlanetTeamSpeakk
Copy link
Author

The linked discussion seems to have gotten about as far as I did. Afaik, it's not possible to get the monitor the window is on from winit to calculate the center with.

Also, the discussion mentions that there aren't many use cases for this, but I'd like to add that my personal use case is that my window is very small and having it open in the top left corner of my screen is very annoying. I have currently resorted to restoring the position from last session, but I'd still like for this feature to be added. A simple center_on_screen() function or something like that would be great.

@prof79
Copy link

prof79 commented Jan 28, 2024

I second that, MS XAML has WindowStartupLocation and other frameworks have their not-too-complicated ways (eg. https://wiki.qt.io/How_to_Center_a_Window_on_the_Screen, https://stackoverflow.com/questions/17908584/how-to-set-the-gtk-window-to-the-center-of-screen).

Especially small windows on big screens are a problem. With smaller windows I need to drag them in the middle because that's where my comfortable focus point for interaction is, regarding eye/head movement.

@prof79
Copy link

prof79 commented Jan 28, 2024

That was a tough act taking several hours, at least an idea of how this might be done. The dynamic AppWindow structure and winit API changes in-between didn't make things any easier.

https://github.com/prof79/slint-center-window

@ogoffart
Copy link
Member

@prof79 Thanks for sharing the example.

Btw, since this might be a common use case, I was thinking maybe we could add an enum in the WindowPosition enum to have it centered. https://slint.dev/docs/rust/slint/enum.WindowPosition
Too bad it isn't non_exhaustive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Changes or additions to APIs enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants