tryphotino / photino.NET

https://tryphotino.io
Apache License 2.0
884 stars 73 forks source link

[Linux] Closing secondary window also closes first window (WaitForClose returns) #170

Closed zeroskyx closed 7 months ago

zeroskyx commented 8 months ago

Greetings,

when closing a second window in Linux (via X), the main window also closes (WaitForClose returns).

This can be reproduced with the Photino.HelloPhotino.MultiWindow sample (note: in HelloPhotino.MultiWindow.csproj the value of <TargetFramework> needs to be changed to net8.0)

On Windows, closing the secondary window does not cause WaitForClose to return. The behavior on macOS is unknown.

Arch Linux 6.7 using GNOME 45.

Help is greatly appreciated.

Thanks in advance -Simon

SimonAnnetts commented 8 months ago

I also get the same issue with the sample multiwindow application. Photino.NET 2.3.0 nuget and net6.0 Ubuntu 22.04LTS, XFCE4

ottodobretsberger commented 8 months ago

Thank you for reporting this. We will have to investigate this issue. I have put that on our backlog of issues to go though before our next release.

philippjbauer commented 7 months ago

@zeroskyx @SimonAnnetts

The reference to the parent window is missing when the child window is created. The code to open a child window for the example needs to look like the following:

static void NewWindowMessageDelegate(object sender, string message)
        {
            var parent = (PhotinoWindow)sender;

            if (message == "random-window")
            {
                var random = new Random();

                int workAreaWidth = parent.MainMonitor.WorkArea.Width;
                int workAreaHeight = parent.MainMonitor.WorkArea.Height;

                int width = random.Next(400, 800);
                int height = (int)Math.Round(width * 0.625, 0);

                int offset = 20;
                int left = random.Next(offset, workAreaWidth - width - offset);
                int top = random.Next(offset, workAreaHeight - height - offset);

                _childCount++;

                new PhotinoWindow(parent) // <-- notice the added parent paramter!
                    .SetTitle($"Random Window ({_childCount})")
                    .SetUseOsDefaultSize(false)
                    .SetHeight(height)
                    .SetWidth(width)
                    .SetUseOsDefaultLocation(false)
                    .SetTop(top)
                    .SetLeft(left)
                    .RegisterWebMessageReceivedHandler(CloseWindowMessageDelegate)
                    .Load("wwwroot/random.html")
                    .WaitForClose();
            }

The change is available in the debug branch and will be published with other changes into master next time around.