How to hide/unhide GtkWindow while preserving its location

If I have a widget that is a window:

GtkWidget* wdg = GTK_WIDGET(wnd);

Then, when I hide this widget (window) using:

gtk_widget_set_visible(wdg, false);

and later make it visible again with:

gtk_widget_set_visible(wdg, true);

the window appears in a different location.

Is there a way to hide and unhide the window while preserving its location?

No: the location is determined by the window manager, and applications have no say in that.

Windows and macOS provide hide/unhide mechanisms that preserve windows location and size. I expected that on windows and macOS hide/unhide shouldn’t cause window reappearing at different location. I tested on both systems… and it simply reappears in the middle of the screen. I think this is not a big issue to fix.

There is nothing to fix: GTK does not support positioning windows, and defers to the window management stack for everything related to the location of a window on every platform.

You do not need to reposition anything. Just to use proper methods for hiding/unhiding windows on windows at least. On windows it is very simple call ShowWindow(hwnd, true|false).

First of all, that’s not a thing anywhere else; on Wayland, for instance, the native surface gets destroyed on hide.

Second of all:

If you want to change this behaviour on Windows, file an issue against the Windows backend of GTK.

Well, it’s just Wayland without support for window movement. Other desktop managers do.

And again hide/unhide shouldn’t reposition anything.

I do not know where to change it. Anyway I will fix it on my (client) side.

I do hope someone interested it gtk’s well being beyond linux, will see this and fix it accordingly.