Skip to content

Commit

Permalink
Fixed window will never show up again if the window is closed when mi…
Browse files Browse the repository at this point in the history
…nimized (vrcx-team#977)

* `Show()` must be called before changing `WindowState`, otherwise the internal state of the window will be messed up.

If you don't do this, when the window is closed when minimized, even if you click the tray menu icon, it will never show up.

* Remember window state before minimized. If window was maximized before minimized, it should be restore to maximized when `Focus_Window` called.
  • Loading branch information
ColorlessColor authored and Natsumi-sama committed Nov 11, 2024
1 parent e05c7b6 commit 4ca9f56
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions Dotnet/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,25 @@ public partial class MainForm : WinformBase
private int LastSizeWidth;
private int LastSizeHeight;

private FormWindowState _LastWindowStateToRestore = FormWindowState.Normal;
private FormWindowState LastWindowStateToRestore
{
get => _LastWindowStateToRestore;
set
{
// Used to restore window state after minimized
if (FormWindowState.Minimized != value)
{
_LastWindowStateToRestore = value;
}
}
}

public MainForm()
{
Instance = this;
InitializeComponent();

// adding a 5s delay here to avoid excessive writes to disk
_saveTimer = new Timer();
_saveTimer.Interval = 5000;
Expand Down Expand Up @@ -129,28 +143,32 @@ private void MainForm_Load(object sender, System.EventArgs e)
jslogger.Error(ex);
}

LastWindowStateToRestore = WindowState;

// 가끔 화면 위치가 안맞음.. 이걸로 해결 될지는 모르겠음
Browser.Invalidate();
}

private void MainForm_Resize(object sender, System.EventArgs e)
{
LastWindowStateToRestore = WindowState;

if (WindowState != FormWindowState.Normal)
{
return;
}
LastSizeWidth = Size.Width;
LastSizeHeight = Size.Height;

_saveTimer?.Start();
}

private void SaveTimer_Tick(object sender, EventArgs e)
{
SaveWindowState();
_saveTimer?.Stop();
}

private void MainForm_Move(object sender, System.EventArgs e)
{
if (WindowState != FormWindowState.Normal)
Expand All @@ -159,7 +177,7 @@ private void MainForm_Move(object sender, System.EventArgs e)
}
LastLocationX = Location.X;
LastLocationY = Location.Y;

_saveTimer?.Start();
}

Expand All @@ -172,7 +190,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
Hide();
}
}

private void SaveWindowState()
{
VRCXStorage.Instance.Set("VRCX_LocationX", LastLocationX.ToString());
Expand Down Expand Up @@ -203,11 +221,11 @@ private void TrayMenu_Open_Click(object sender, System.EventArgs e)

public void Focus_Window()
{
Show();
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
WindowState = LastWindowStateToRestore;
}
Show();
// Focus();
Activate();
}
Expand Down

0 comments on commit 4ca9f56

Please sign in to comment.