Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window Position in XAML not honored on startup #3387

Closed
HankG opened this issue Dec 22, 2019 · 5 comments
Closed

Window Position in XAML not honored on startup #3387

HankG opened this issue Dec 22, 2019 · 5 comments
Labels

Comments

@HankG
Copy link
Contributor

HankG commented Dec 22, 2019

Experimenting in 0.9 and setting position of the window with something like Position="500,600" is not working on Linux but does work on Windows and Mac. At first I thought it was an out of bounds issue by setting it to 0,0, which the upper left corner of the deskop is not on my Linux (I get 1,23 for that on Mint MATE and 0,57 on Ubuntu 18.04 not counting the dock and 67,57 when not going past it). However even setting it to something close to but not the default location.

The behavior is manifesting differently on MATE and on Ubuntu 18.04 GNOME. On MATE it simply does nothing. If I capture the PositionChanged event after setting the Position to 500,500 (so no bounds problems) I can see it still draws it at 1130,570 just like if I didn't set it at all. On GNOME 3 I end up getting two position changed events. The first moves it to the requested 500,500 but then it seems to get some sort of default position from GNOME to throw it to wherever it decides to. Sometimes that's the next offset stacked window position. Sometimes it's aligned with the bottom of the terminal window I used to launch it. etc.

@colejohnson66
Copy link

We found a workaround. You can't change Position before the window is shown. So, in our method where we were setting Position = new PixelPoint(newX, newY), we instead save the new PixelPoint to a class variable, then override OnOpened to actually set Position:

public MyWindow()
{
    ...
    newPosition = new(newX, newY);
}

private PixelPoint newPosition = default;
protected override void OnOpened(EventArgs e)
{
    Position = newPosition;
    base.OnOpened(e);
}

@maxkatz6 maxkatz6 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2024
@colejohnson66
Copy link

@maxkatz6 Why is this not planned? Is it not possible to fix in X11 or Wayland?

@timunie
Copy link
Contributor

timunie commented Jan 3, 2024

@colejohnson66 in case you know a reliable way to solve it for Avalonia, a PR is welcome. Until today, we think that not all Windowmanager support it by design and thus we cannot really solve it.

@NickBarton
Copy link

We found a workaround. You can't change Position before the window is shown. So, in our method where we were setting Position = new PixelPoint(newX, newY), we instead save the new PixelPoint to a class variable, then override OnOpened to actually set Position:

public MyWindow()
{
    ...
    newPosition = new(newX, newY);
}

private PixelPoint newPosition = default;
protected override void OnOpened(EventArgs e)
{
    Position = newPosition;
    base.OnOpened(e);
}

This doesn't work on Linux Ubuntu on WSL2. On Hide then Show, the window position is restored to a random position.

@colejohnson66
Copy link

As @timunie said, not all window managers support setting the position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants