diff --git a/DesktopClock/MainWindow.xaml.cs b/DesktopClock/MainWindow.xaml.cs index 4ad443c..30b74e8 100644 --- a/DesktopClock/MainWindow.xaml.cs +++ b/DesktopClock/MainWindow.xaml.cs @@ -23,10 +23,13 @@ namespace DesktopClock; [ObservableObject] public partial class MainWindow : Window { + private readonly Random _random = new(); private readonly SystemClockTimer _systemClockTimer; private TaskbarIcon _trayIcon; private TimeZoneInfo _timeZone; private SoundPlayer _soundPlayer; + private double totalShiftX; + private double totalShiftY; /// /// The date and time to countdown to, or null if regular clock is desired. @@ -40,6 +43,12 @@ public partial class MainWindow : Window [ObservableProperty] private string _currentTimeOrCountdownString; + /// + /// The amount of margin applied in order to shift the clock's pixels and help prevent burn-in. + /// + [ObservableProperty] + private Thickness _pixelShift; + public MainWindow() { InitializeComponent(); @@ -195,6 +204,23 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) } } + private void ShiftWindow() + { + const int MaxTotalShift = 10; + const int MaxShiftPerTick = 5; + + double ApplyShift(ref double totalShift) + { + var shift = _random.Next(-MaxShiftPerTick, MaxShiftPerTick + 1); + totalShift += shift; + + return Math.Min(MaxTotalShift, totalShift); + } + + Left += ApplyShift(ref totalShiftX); + Top += ApplyShift(ref totalShiftY); + } + /// /// Handles the event when the system clock timer signals a second change. /// @@ -203,6 +229,8 @@ private void SystemClockTimer_SecondChanged(object sender, EventArgs e) UpdateTimeString(); TryPlaySound(); + + Dispatcher.Invoke(ShiftWindow); } /// diff --git a/DesktopClock/Properties/Settings.cs b/DesktopClock/Properties/Settings.cs index 11e4af8..802447b 100644 --- a/DesktopClock/Properties/Settings.cs +++ b/DesktopClock/Properties/Settings.cs @@ -179,6 +179,11 @@ private Settings() /// public bool RightAligned { get; set; } = false; + /// + /// Experimental: Shifts the clock's pixels and makes the background more transparent in order to prevent burn-in. + /// + public bool BurnInMitigation { get; set; } = false; + /// /// Path to a WAV file to be played on a specified interval. /// diff --git a/DesktopClock/SettingsWindow.xaml b/DesktopClock/SettingsWindow.xaml index 3862b4f..7a3f15a 100644 --- a/DesktopClock/SettingsWindow.xaml +++ b/DesktopClock/SettingsWindow.xaml @@ -195,6 +195,18 @@ FontSize="10" Margin="0,0,0,12" /> + + + + + +