Center new window on screen

Hi all:

I’m working on a program that needs to show a notification to the user in the form of a window with a progress bar. Currently I’m using a GtkWindow “as is”, but the problem is that it appears always at the top-left corner, when I want it to be “centered”. Of course, I’m using Wayland.

Is there a way of notifying Gnome Shell that this window is some kind of notification and that it should be shown centered? I tried gtk_window_set_position() but it doesn’t work.

Thanks.

On Wayland the compositor, Mutter, does global window placement and the Wayland backend for GTK doesn’t currently expose a way for apps to set global window coordinates.

I suspect what you are after is a “splash screen” of sorts? The “Wayland” way to solve that is to introduce a splash screen surface role. See Draft: Add xdg-splash protocol (!140) · Merge requests · wayland / wayland-protocols · GitLab for an effort to introduce that.

@jadahl Yes, that was the idea!!! I’ll check it. Thanks!

I know that Wayland doesn’t allow to set the coordinates. But what I ask is how to send a hint to the window manager to say that this is a window that should be shown “centered”, and let the window manager to do that. Like a “splash screen”, as said by jadahl.

@jadahl Ok, as I see, it is just a proposal, but isn’t implemented yet :frowning: Is there a way of doing it NOW? I mean… is there a case where the current mutter algorithm centers the window instead of putting it on the top-left corner? Something like… “when the window has no decorations” or something like that… I don’t care that it is something that can change in the future.

No, it seems the proposal stalled for some reason.

Something like… “when the window has no decorations” or something like that…

All windows in Wayland “have decorations”. Sometimes they are effectively empty, but we can’t and shouldn’t try to detect that.

Yes, I know that now decorations are client-side… What I mean is if there is any case where the Gnome Shell logic decides to place a window in the center of the screen instead of putting it at the top-left corner. And it doesn’t matter if is something “obscure”, “convoluted” or “that can change tomorrow and stop working as a trick for this”.

If you need a temporary solution and you only care about GNOME Shell, you can write a shell extension to move the window.

But IMO none of this is actually good for what you are trying to do. Even if that protocol were stabilized, the window manager could still decide to not center the window for whatever reason, as is the same with X11 window managers. And the user could have trouble dismissing it or getting it back later, etc. What would be best is to have progress notifications supported by the shell: https://gitlab.gnome.org/Teams/Design/os-mockups/-/issues/193

I would LOVE to be able to use those notifications!!!

About using an extension to move the window… well, I always can borrow some code from Desktop Icons NG :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.