Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clock click action settings #992

Merged
merged 14 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions RetroBar/Controls/Clock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public DateTime Now
}

private readonly DispatcherTimer clock = new DispatcherTimer(DispatcherPriority.Background);
private readonly DispatcherTimer singleClick = new DispatcherTimer(DispatcherPriority.Input);
dremin marked this conversation as resolved.
Show resolved Hide resolved

private bool _isLoaded;

Expand All @@ -38,9 +37,6 @@ public Clock()

clock.Interval = TimeSpan.FromMilliseconds(200);
clock.Tick += Clock_Tick;

singleClick.Interval = TimeSpan.FromMilliseconds(System.Windows.Forms.SystemInformation.DoubleClickTime);
singleClick.Tick += SingleClick_Tick;
}

private void Initialize()
Expand All @@ -65,7 +61,7 @@ private void StartClock()
SetTime();

clock.Start();

Visibility = Visibility.Visible;
}

Expand Down Expand Up @@ -96,22 +92,6 @@ private void Clock_Tick(object sender, EventArgs args)
SetTime();
}

private void SingleClick_Tick(object sender, EventArgs args)
{
// Windows 10-11 single-click action
// A double-click will cancel the timer so that this doesn't run

singleClick.Stop();
if (EnvironmentHelper.IsWindows11OrBetter)
{
ShellHelper.ShowNotificationCenter();
}
else
{
ShellHelper.ShowActionCenter();
}
}

private void TimeChanged(object sender, EventArgs e)
{
TimeZoneInfo.ClearCachedData();
Expand Down Expand Up @@ -181,15 +161,30 @@ private void SetTime()

private void Clock_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (EnvironmentHelper.IsWindows10OrBetter)
switch (Settings.Instance.ClockClickAction)
{
singleClick.Start();
case ClockClickOption.OpenModernCalendar:
ClockFlyoutLauncher.ShowClockFlyout();
break;
case ClockClickOption.OpenAeroCalendar:
IntPtr hWnd = (PresentationSource.FromVisual(this) as System.Windows.Interop.HwndSource).Handle;
ClockFlyoutLauncher.ShowAeroClockFlyout(hWnd);
break;
case ClockClickOption.OpenNotificationCenter:
if (EnvironmentHelper.IsWindows11OrBetter)
{
ShellHelper.ShowNotificationCenter();
}
else if (EnvironmentHelper.IsWindows10OrBetter)
{
ShellHelper.ShowActionCenter();
}
break;
}
}

private void Clock_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
singleClick.Stop();
ShellHelper.StartProcess("timedate.cpl");

e.Handled = true;
Expand Down
7 changes: 7 additions & 0 deletions RetroBar/Languages/English (United Kingdom).xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
xmlns:s="clr-namespace:System;assembly=mscorlib">

<s:String x:Key="customize">_Customise...</s:String>
<x:Array x:Key="clock_click_action_values" Type="s:String">
<s:String>Do nothing</s:String>
<s:String>Open Aero calendar</s:String>
<s:String>Open Modern calendar</s:String>
<s:String>Open Notification Centre</s:String>
</x:Array>

<s:String x:Key="customize_notifications">Customise Notifications</s:String>
<s:String x:Key="customize_notifications_info">RetroBar displays icons for active and urgent notifications, and hides inactive ones. You can change this behaviour for items in the list below.</s:String>
<s:String x:Key="customize_notifications_instruction">Select an item, then choose its notification behaviour:</s:String>
Expand Down
7 changes: 7 additions & 0 deletions RetroBar/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<s:String>Open a new instance</s:String>
<s:String>Close the task</s:String>
</x:Array>
<s:String x:Key="clock_click_action">_Clock click action:</s:String>
<x:Array x:Key="clock_click_action_values" Type="s:String">
<s:String>Do nothing</s:String>
<s:String>Open Aero calendar</s:String>
<s:String>Open Modern calendar</s:String>
<s:String>Open Notification Center</s:String>
</x:Array>
<s:String x:Key="version">Version {0}</s:String>
<s:String x:Key="visit_on_github">Visit RetroBar on GitHub</s:String>
<s:String x:Key="taskbar_scale">Taskbar scale</s:String>
Expand Down
7 changes: 7 additions & 0 deletions RetroBar/Languages/español.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<s:String>Abrir una nueva instancia</s:String>
<s:String>Cerrar la tarea</s:String>
</x:Array>
<s:String x:Key="clock_click_action">_Acción al hacer clic en el reloj:</s:String>
<x:Array x:Key="clock_click_action_values" Type="s:String">
<s:String>No hacer nada</s:String>
<s:String>Abrir el calendario Aero</s:String>
<s:String>Abrir el calendario Moderno</s:String>
<s:String>Abrir el Centro de notificaciones</s:String>
</x:Array>
<s:String x:Key="version">Versión {0}</s:String>
<s:String x:Key="visit_on_github">Visitar RetroBar en GitHub</s:String>
<s:String x:Key="taskbar_scale">Escala de barra de tareas</s:String>
Expand Down
13 changes: 11 additions & 2 deletions RetroBar/PropertiesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@
ToolTip="{DynamicResource language_tip}" />
</Label>
<ComboBox Name="cboLanguageSelect"
SelectedValue="{Binding Source={x:Static Settings:Settings.Instance}, Path=Language, UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="cboLanguageSelect_SelectionChanged" />
SelectedValue="{Binding Source={x:Static Settings:Settings.Instance}, Path=Language, UpdateSourceTrigger=PropertyChanged}" />
</DockPanel>
<DockPanel>
<Label VerticalAlignment="Center"
Expand Down Expand Up @@ -362,6 +361,16 @@
SelectedIndex="{Binding Source={x:Static Settings:Settings.Instance}, Path=TaskMiddleClickAction, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource enumConverter}}"
SelectionChanged="cboMiddleMouseAction_SelectionChanged" />
</DockPanel>
<DockPanel>
<Label VerticalAlignment="Center"
Target="{Binding ElementName=cboClockAction}">
<AccessText Text="{DynamicResource clock_click_action}" />
</Label>
<ComboBox x:Name="cboClockAction"
ItemsSource="{DynamicResource clock_click_action_values}"
SelectedIndex="{Binding Source={x:Static Settings:Settings.Instance}, Path=ClockClickAction, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource enumConverter}}"
SelectionChanged="cboClockAction_SelectionChanged" />
</DockPanel>
<DockPanel>
<Label VerticalAlignment="Center"
Target="{Binding ElementName=cboInvertIconsMode}">
Expand Down
40 changes: 37 additions & 3 deletions RetroBar/PropertiesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ private PropertiesWindow(NotificationArea notificationArea, DictionaryManager di
LoadLanguages();
LoadRows();
LoadThemes();
LoadVersion();
LoadWidth();
LoadVersion();
LoadClockActions();

Settings.Instance.PropertyChanged += Settings_PropertyChanged;
}
Expand All @@ -97,6 +98,11 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
LoadPreviewHeight();
}
else if (e.PropertyName == nameof(Settings.Language))
{
LoadVersion();
LoadClockActions();
}
}

public static PropertiesWindow Open(NotificationArea notificationArea, DictionaryManager dictionaryManager, AppBarScreen screen, double dpiScale, double barSize)
Expand Down Expand Up @@ -274,9 +280,29 @@ private void AutoStartCheckBox_OnChecked(object sender, RoutedEventArgs e)
}
}

private void cboLanguageSelect_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
private void LoadClockActions()
{
LoadVersion();
if (EnvironmentHelper.IsWindows10OrBetter)
{
return;
}

// Remove options unsupported prior to Windows 10.
var availableClockActions = (FindResource("clock_click_action_values") as Array)?.Cast<object>().ToList();
if (availableClockActions == null)
{
return;
}

if (Settings.Instance.ClockClickAction > ClockClickOption.OpenAeroCalendar)
{
// ClockClickAction is out of range; reverting to default
cboClockAction.SelectedValue = availableClockActions[(int)ClockClickOption.DoNothing];
}

availableClockActions.RemoveAt((int)ClockClickOption.OpenNotificationCenter);
availableClockActions.RemoveAt((int)ClockClickOption.OpenModernCalendar);
cboClockAction.ItemsSource = availableClockActions;
}

private void cboEdgeSelect_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
Expand Down Expand Up @@ -311,6 +337,14 @@ private void cboMiddleMouseAction_SelectionChanged(object sender, System.Windows
}
}

private void cboClockAction_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (cboClockAction.SelectedItem == null)
{
cboClockAction.SelectedValue = cboClockAction.Items[(int)Settings.Instance.ClockClickAction];
}
}

private void cboRowCount_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (cboRowCount.SelectedItem == null)
Expand Down
Loading