Gtk4 X11 seem to start application windows in top left corner

I have been porting my software to Gtk4, and found that under X11 my ApplicationWindows always start up in the upper left corner of the left most display.

It does work correctly under Wayland. This is on Fedora 34 system.

I find with xprop that:

WM_NORMAL_HINTS(WM_SIZE_HINTS):
		program specified location: 0, 0
		program specified minimum size: 46 by 46

I looked though the gtk sources and it seems gdk_display_create_surface() has x, y arguments
that are passed wired at 0, 0 most places, which
could be setting up the hook in gdk/x11/gdksurface-x11.c. I am not familar enough with X11 WM hints
to follow exactly what is going on.

Is this a bug I should report?

GTK does not set the position of a window on the screen, whether it’s the initial position or any subsequent one: it’s up to the window manager to do so. GTK4 is modelled on Wayland, which does not have global screen coordinates available to clients, unlike X11. This means that all windowing system surfaces have a (0, 0, width, height) coordinate space.

If the behaviour of GNOME Shell is different between X11 and Wayland, then please: feel free to open an issue against Mutter.

If, as you say, “GTK does not set the position of a window on the screen”, then why is it telling the X server though its X hints that the window should be positioned at (0, 0)? This was not being done in Gtk-3.0.

I don’t know where these hints are being set, but its probably somewhere in the GtkSurface X11 setup.

The Gnome developers seem so obsessed with pushing back against people who have complained about GTK not letting an application set the position of a window on a screen, that they ignore the face that Gtk4 is trying to do just that – very badly.

That is why I am reluctant to submit a bug report, which will get ignored because it will be seen as a reference to window positioning and miss-think I am asking for it. [As you just did].

The bug itself seems such a glaring oversight, that I wanted to confirm
here whether others have seen the problem, or if I was doing something very wrong. All the messages about the topic I found searching the net seems to be about complaints that window centering hints are being ignored, which is not my issue, and has been already argued to death elsewhere. Personally I have never used window manager hints, other than the still accepted setting of preferred initial window size.

It does not do you any good to be this confrontational in the only place where people can help you. If you just want to rant, there are many other places you can go instead of GNOME’s Discourse instance.

Plus, this has nothing to do with GNOME: the GTK developers decided to stop modelling its behaviour on X11 and use Wayland, instead, as X11 is to be considered legacy, at this point.

Of course, since GNOME Shell is still a hybrid X11/Wayland compositor, it should behave as similarly as possible in either X11 or Wayland sessions.

Of course, if you start by this position then nothing will ever come out of it.

GTK does not set an initial position; even if it explicitly sets (0, 0) as the initial position of the window, nothing prevents the window manager to position the window elsewhere—in fact, it’s expected to happen; that’s why there’s a ConfigureEvent that gives you the (x, y) position of the window.

There’s no need to add a hint, either.

Sorry for the confrontational attitude. I apologize.

Maybe I am miss-understand what you are saying. You say:

GTK does not set an initial position; even if it explicitly sets (0, 0) as the initial position of the window, nothing prevents the window manager to position the window elsewhere—in fact, it’s expected to happen; that’s why there’s a ConfigureEvent that gives you the (x, y) position of the window.

Gtk is setting the initial position, which I thought the xprop output showed.

I don’t know what the use of that would be. I don’t want to position the window.

There’s no need to add a hint, either.

I don’t want a hint. I want Gtk4 to not set a hint. Gtk-3.0 does not give a hint so thing work correctly under X. I would submit a bug fix if I could figure out where in the code this was being done. I don’t have a very clear picture of Gnome’s code-base and all of my Gtk programming has been in languages other than C.

I would be using Wayland, and not have a problem, but unfortunately on my hardware, I get too may window system lock-up events to make that practical. Since Gtk-3.0, I have removed all the X11 specific references in my code.

Let me clarify: there is no mechanism by which GTK allows the user of its API to set a position. The default is (0, 0). There’s also no need whatsoever for the window manager to take (0, 0) and use it as the position for a top level. In fact, it’s expected for the window manager to position any top level window the way it sees fit. The only windows that should be left alone and positioned explicitly by the toolkit are override-redirect windows, which are typically positioned relative to their “parent” window.

GTK 3 is, for all intents and purposes, another toolkit, so you cannot use it as a reference.

Again: you should file an issue against Mutter and discuss the difference between X11 and Wayland top-levels.

Again: you should file an issue against Mutter and discuss the difference between X11 and Wayland top-levels.

I do not understand how the Mutter composition works. Under Wayland, I assumed the XWayland server converted the X protocol to Wayland’s API, and sat in front of the Mutter composer. But with an X hardware level server, there would be some X level window manager for gnome-shell. I don’t see any process labeled 'Mutter".

I only brought up Gtk 3 because I thought it illustrates that it is not a Mutter problem. Maybe I’m confused. If Mutter is setting the hints, then why is it not happening with Gtk 3. It may be as you say a different toolkit, but shouldn’t they both look the same to Mutter.

I guess the window manager (which you tell me is Mutter) could ignore all the hints it is being given. This seems a kludge. Shouldn’t Gtk not try to tell it what to do? Shouldn’t Gtk work on window systems other than Wayland? Isn’t that one of its goals?

Are you saying the position hints are coming from someplace else? Then why don’t other toolkits have a issue?

The difference is that if an X11 window provides hints about its placement, it is considered good practice to respect that as much as possible. It is true that the window manager is free to ignore such hints, but instead of assuming that hints are ignored, GTK shouldn’t set them in the first place.

2 Likes

Thanks, Florian! I didn’t realise we didn’t remove the flag during the cleanup.

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