Restoring windows positions under Wayland

tl;dr How do I create a wxPython application/window so its position is kept between the launches under Wayland?

I have a few wxPython programs I wrote for myself that need to remember their window’s position and size when closed, and restore it when launched again. On Windows and on Linux under X11 I used a simple combination of GetRect()/SetSize(). On Linux under Wayland the “size” part of those functions still works, but an attempt to get the position, through GetRect(), GetPosition() or whatever, always returns (0, 0), and an attempt to set the position yields no result (the window is just centered on the default display or something, looks particularly hilarious for an application that creates multiple windows and they all appear in the center). As I understand after some reading and googling, that is by design - Wayland doesn’t allow applications to manipulate their windows’ position. However, I see some applications still remembering and restoring their windows’ positions between the launches - by themselves, or by somehow delegating that to the desktop environment, I do not know. Sadly, none of them that I have are written in wxPython to look at the sources. How do I create a wxPython application/window so its position is kept between the launches under Wayland?

Here’s my code example for the reference (the positioning part doesn’t work under Wayland - what do I need to change?):

#!/usr/bin/env python3
import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, window_id, title):		
        wx.Frame.__init__(self, parent, window_id, title)
        self.Bind(wx.EVT_CLOSE, self.OnClose)		
        self.Show(True)

    def ReadSettings(self):
        rect = [0, 0, 100, 100]
        try:
            with open("settings.txt", "r") as f:
                rect = [int(s) for s in f.read().split(",")]
        except:
            pass
        self.SetSize(*rect)

    def WriteSettings(self):
        with open("settings.txt", "w") as f:
            f.write(",".join((str(s) for s in self.GetRect())))
    
    def OnClose(self, evt):
        self.WriteSettings()
        self.Destroy()

app = wx.App(0)
frame = MainWindow(None, -1, "Test")
frame.ReadSettings()
frame.Show(1)
app.MainLoop()

I think self.GetPosition() and self.SetPosition() should do this. Does that not work with Wayland?

No, they don’t: self.GetPosition() returns zeros, self.SetPosition() has no effect.

Ah, sorry I should have read your original message more closely.
It does look like a deliberate choice by Wayland.

It is a deliberate choice by Wayland. I’ve read some decade-old discussions on the subject with developers of Wayland (turned out, I wasn’t the first one who missed the feature), those were like “well, you don’t need it, but if you need it, think again, you don’t really need it, and also it would create some security risks (how did X11 survived through all these years, being exposed to such huge security risks, I wonder?), but if you still think you need it, switch to a tiling window manager or something, and, while we’re at it, screw you.” For the time being, it’s quite possible to avoid Wayland, which I do, but I am not sure if that is a viable long term strategy - my preferred Linux distribution switched to Wayland by default with its latest release, may as well switch to Wayland only with the next one, for all I know. I thought I should investigate the possibilities while there’s still time.

The closest I’ve got is using KDE Window Rules, where you can make it to remember windows positions (among other things), based on a few window attributes, such as the class (seems to be always <application name>.py), the window title, and a few more I don’t understand. Looks neither convenient nor reliable. Besides, there are applications that remember their positions without all that - for example, Obsidian does, and KeePassXC, and Skype for Linux used to while it was alive. So it’s not something unthinkable even with Wayland.

Thanks, yes it does seem that Wayland insists on not supporting screen positioning, leaving that to a Window manager or “compositor”. A GUI toolkit for desktop apps like wxWidgets and wxPython should be able to talk to the appropriate Window manager, and request positioning values. Yes, some managers might be unable to meet all requests, but others should be able to.