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

[Linux][MacOS] Rendering is stopped after system restores previously minimized and hidden window #18148

Open
Shivansps opened this issue Feb 8, 2025 · 4 comments

Comments

@Shivansps
Copy link

Shivansps commented Feb 8, 2025

Describe the bug

Calling .Hide() on the main window yields diferent results based on the OS. This happens when i .Hide() the main window after clicking minimize button on the window.

On Windows:
-Is completely hidden, dissapears from the taskbar as expected and can only bring back by code by calling .Show()
-By calling .Show() the app icon will be displayed on the taskbar again.

This is i assume the expected behaviour.

On Linux:
-By calling .Hide() the window is hidden but that taskbar icon is still there if i click it it will bring back the main window but the content is not show, as if it where IsVisible = false;
-Calling .Show() will restore the main window content.
Now, Windows behaviour can be achived on linux by also setting .ShowInTaskbar = false after calling .Hide(), and then set to to true after calling .Show().

On Mac:
-It has the same problems as in Linux but with the difference that "ShowInTaskbar" does nothing so it cant be fixed.

To Reproduce

in app.axlm.cs:

desktop.MainWindow = new MainWindow
{
    DataContext = new MainWindowViewModel()
};

desktop.MainWindow.PropertyChanged += (v, p) =>
{
    if (p.Property.Name == nameof(WindowState) && p.NewValue != null && ((WindowState)p.NewValue) == WindowState.Minimized)
    {
        desktop.MainWindow.Hide();
    }
};

Then restore the window with .Show() some time later.

Expected behavior

Same results in Linux and MacOS as in Windows.

Avalonia version

11.2.3

OS

Windows, macOS, Linux

Additional context

Trying to create a "minimize to tray" function

@Shivansps Shivansps added the bug label Feb 8, 2025
@maxkatz6
Copy link
Member

maxkatz6 commented Feb 8, 2025

On Windows OS, task bar shows icons of each window, grouping them by app (which can also be disabled). When window is hidden - icon is also hidden. Which is excepted.

On MacOS (and some linux distros), dock displays applications, and not individual windows. Furthermore, it's common for MacOS native apps to keep application icon on the dock as well as whole process running, even when there are no windows opened at all (in case of avalonia, it can be achieved by ShutdownMode property).

Linux behavior you described sounds like a bug, especially window appearing without any content.
MacOS behavior is by design, as there is no taskbar nor window icons fundamentally.

Trying to create a "minimize to tray" function

Close the window then. "Minimize to tray" essentially is just a tray icon defined without any window opened, while keeping process alive.

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 8, 2025

I didn't test your code, but from looking at it, I wonder if renderer is failing to restart itself when minimized and then hidden window is shown by Linux OS.

@Shivansps
Copy link
Author

Shivansps commented Feb 8, 2025

The empty content also happens on mac when you click the icon on the dock, it restores the main window by changing its state to whatever it was but the content is actually still hidden.
Linux does this exact same thing if you click the icon left on the taskbar if you dont set the ShowTaskBar icon to false.

Now, i dont really want to close the view, i would have to reload all data into the viewmodels, there is stuff that can still run in the background that will have to continue and restored into a new vm, like download and decompressing with progress tracking, etc.
Well if nothing can be done about the MacOS dock icon ill have to figure out some workaround.

Also i found a crashing bug with the tray icon on linux, i will create a diferent issue for it.

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 8, 2025

If you use mvvm, and keep your data in the view model, you don't really have to reload it, once it's there. Since it's separated from the window for a reason.

@maxkatz6 maxkatz6 changed the title Window .Hide() and .Show() behaviour are not consistent in all Desktop OS. [Linux][MacOS] Rendering is stopped after system restores previously minimized and hidden window Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants