Skip to content

Commit

Permalink
app: fix offline display arrival
Browse files Browse the repository at this point in the history
  • Loading branch information
nomi-san committed Jun 7, 2024
1 parent 907b73a commit 5d3a6e6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ protected override void OnSourceInitialized(EventArgs e)

Handle = new WindowInteropHelper(this).EnsureHandle();
Helper.EnableDropShadow(Handle);

var source = HwndSource.FromHwnd(Handle);
source.AddHook(new HwndSourceHook(WndProc));

}

protected override void OnClosing(CancelEventArgs e)
Expand Down Expand Up @@ -98,14 +102,15 @@ private void Window_Unloaded(object sender, RoutedEventArgs e)
SystemEvents.DisplaySettingsChanged -= DisplayChanged;
}

private void DisplayChanged(object sender, EventArgs e)
private void DisplayChanged(object sender, EventArgs e)
{
Dispatcher.Invoke(() =>
{
var displays = ParsecVDD.GetDisplays(out bool noMonitors);
xDisplays.Children.Clear();
xNoDisplay.Visibility = displays.Count <= 0 ? Visibility.Visible : Visibility.Hidden;
xNoDisplay.Visibility = displays.Count > 0
? Visibility.Hidden : Visibility.Visible;
foreach (var display in displays)
{
Expand Down Expand Up @@ -206,5 +211,15 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
}
}
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == 0x0219 && unchecked((int)wParam) == 0x7)
{
DisplayChanged(this, EventArgs.Empty);
}

return IntPtr.Zero;
}
}
}

0 comments on commit 5d3a6e6

Please sign in to comment.