Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Jul 17, 2024
1 parent af7d96d commit cd152b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
28 changes: 28 additions & 0 deletions DesktopClock/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// The date and time to countdown to, or <c>null</c> if regular clock is desired.
Expand All @@ -40,6 +43,12 @@ public partial class MainWindow : Window
[ObservableProperty]
private string _currentTimeOrCountdownString;

/// <summary>
/// The amount of margin applied in order to shift the clock's pixels and help prevent burn-in.
/// </summary>
[ObservableProperty]
private Thickness _pixelShift;

public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -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);
}

/// <summary>
/// Handles the event when the system clock timer signals a second change.
/// </summary>
Expand All @@ -203,6 +229,8 @@ private void SystemClockTimer_SecondChanged(object sender, EventArgs e)
UpdateTimeString();

TryPlaySound();

Dispatcher.Invoke(ShiftWindow);
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions DesktopClock/Properties/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ private Settings()
/// </remarks>
public bool RightAligned { get; set; } = false;

/// <summary>
/// Experimental: Shifts the clock's pixels and makes the background more transparent in order to prevent burn-in.
/// </summary>
public bool BurnInMitigation { get; set; } = false;

/// <summary>
/// Path to a WAV file to be played on a specified interval.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions DesktopClock/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@
FontSize="10"
Margin="0,0,0,12" />

<CheckBox Content="Right Aligned" IsChecked="{Binding Settings.RightAligned, Mode=TwoWay}" />
<TextBlock Text="Experimental: Keeps the clock window aligned to the right when the size changes."
FontStyle="Italic"
FontSize="10"
Margin="0,0,0,12" />

<CheckBox Content="Burn-in Mitigation" IsChecked="{Binding Settings.BurnInMitigation, Mode=TwoWay}" />
<TextBlock Text="Experimental: Shifts the clock's pixels and makes the background more transparent in order to prevent burn-in."
FontStyle="Italic"
FontSize="10"
Margin="0,0,0,12" />

<TextBlock Text="WAV File Path:" />
<Grid>
<Grid.ColumnDefinitions>
Expand Down

0 comments on commit cd152b2

Please sign in to comment.