Wrong window position after fullscreen

I use this code:

        # toggle fullscreen
        if key == "f":
            if not self.winProps.getFullscreen():
                self.winProps.setTitle("Camera Test New")
                self.winProps.setSize(
                    self.maxWinWidth, self.maxWinHeight)
                self.winProps.setFullscreen(True)
                base.win.requestProperties(self.winProps)
            else:
                self.winProps.setSize(
                    self.oldWinWidth, self.oldWinHeight)
                self.winProps.setFullscreen(False)
                base.win.requestProperties(self.winProps)
                self.winProps.setOrigin(self.oldWinX, self.oldWinY)
                base.win.requestProperties(self.winProps)

            if self.winProps.hasOrigin():
                print(self.winProps.getXOrigin(), self.winProps.getYOrigin())

The toggle of fullscreen works. But the position of the window after fullscreen is not the oldWinX and oldWinY. It is just top left on the screen. But the getXOrigin and getYOrigin have the correct values.

Can someone check what I am doing wrong?

Hi, welcome to the community!

Please note you’re using WindowProperties incorrectly. It’s meant to be a delta of properties, you’re supposed to just specify the properties you want to change, and preferably both in one go:

changes = WindowProperties()
changes.setSize(self.oldWinWidth, self.oldWinHeight)
changes.setOrigin(...)
changes.setFullscreen(False)
base.win.requestProperties(changes)

Thanks, but it didn’t work. The window is still in the top left of the screen…

What happens if you place the window on the frame after you exit fullscreen mode?

My thinking is that perhaps the window-position isn’t being successfully applied because, at the point at which the system attempts to do so, fullscreen mode hasn’t yet been exited–the new mode has been requested, but not yet enacted. And since positioning a fullscreen window presumably has little effect, the attempt to position the window fails.

Placing the window in the next frame might be done via the use of the task-manager’s “doMethodLater” method, passing in a delay of “0”, I believe. Something like this:

def exitFullscreen(self):
    changes = WindowProperties()
    changes.setSize(self.oldWinWidth, self.oldWinHeight)
    changers.setFullscreen(False)
    self.showBaseObject.win.requestProperties(changes)

    self.showBaseObject.taskMgr.doMethodLater(0, self.placeWindow)

def placeWindow(self):
    changes = WindowProperties()
    changes.setOrigin(self.oldWinX, self.oldWinY)
    self.showBaseObject.win.requestProperties(changes)