Skip to content

Commit

Permalink
fix(display): crash on display item after custom resolution removal (n…
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyd-dev committed Feb 1, 2025
1 parent b6ee794 commit 58f08a9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app/Components/DisplayItem.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -115,6 +116,24 @@ private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
});
}

// Handle removed custom resolution
if (SelectedResolution == null)
{
SelectedResolution = new Display.ModeSet
{
Width = Display.CurrentMode.Width,
Height = Display.CurrentMode.Height,
RefreshRates = new List<int> { Display.CurrentMode.Hz }
};

xResolution.Items.Add(new MenuItem
{
IsCheckable = false,
IsChecked = true,
Header = $"{SelectedResolution.Width} × {SelectedResolution.Height} [UnSupported]",
});
}

UpdateRefreshRates();

int oridentationIndex = (int)Display.CurrentOrientation;
Expand All @@ -124,12 +143,18 @@ private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)

private void ChangeResolution(object sender, RoutedEventArgs e)
{
if (Active && e.OriginalSource != null)
if (Active && e.OriginalSource != null && e.OriginalSource is MenuItem)
{
var srcItem = e.OriginalSource as MenuItem;
if (srcItem.Header.ToString().Contains("[UnSupported]"))
{
return;
}

for (int i = 0; i < xResolution.Items.Count; i++)
{
var item = xResolution.Items[i] as MenuItem;
if (item == e.OriginalSource)
if (item == srcItem)
{
item.IsChecked = true;
SelectedResolution = Display.SupportedResolutions[i];
Expand Down

0 comments on commit 58f08a9

Please sign in to comment.