Skip to content

Commit

Permalink
Add option to show popup when changing brightness/temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
tombayley committed Aug 28, 2024
1 parent 43c7ff5 commit 02c991b
Show file tree
Hide file tree
Showing 17 changed files with 422 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NightGlow/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<setting name="DdcConfigJson" serializeAs="String">
<value />
</setting>
<setting name="ShowBrightTempPopup" serializeAs="String">
<value>False</value>
</setting>
</NightGlow.Properties.Settings>
</userSettings>
</configuration>
7 changes: 7 additions & 0 deletions NightGlow/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
<SolidColorBrush x:Key="SecondaryHueMidBrush" Color="{DynamicResource AccentColor}" />
<SolidColorBrush x:Key="SecondaryHueMidForegroundBrush" Color="{DynamicResource TextColor}" />

<!-- Match/similar colors to the Windows volume popup for consistency -->
<!-- If changing Fore color, need to change color of popup SVGs too -->
<SolidColorBrush x:Key="WinVolPopupDarkBackColor" Color="#242424" />
<SolidColorBrush x:Key="WinVolPopupDarkForeColor" Color="#d9d6d6" />
<SolidColorBrush x:Key="WinVolPopupProgressDarkBackColor" Color="#7d7d7d" />
<SolidColorBrush x:Key="WinVolPopupDarkBorderColor" Color="#424242" />

<Style x:Key="SliderLimitPreview" TargetType="TextBlock">
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
Expand Down
2 changes: 2 additions & 0 deletions NightGlow/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ private void ConfigureServices(IServiceCollection services)

services.AddSingleton<NotifyIconViewModel>();
services.AddSingleton<MainWindowViewModel>();
services.AddSingleton<PopupViewModel>();

services.AddSingleton<PopupWindow>();
services.AddTransient<MainWindow>();
}

Expand Down
12 changes: 12 additions & 0 deletions NightGlow/Assets/popup-brightness.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions NightGlow/Assets/popup-temperature.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions NightGlow/NightGlow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<ItemGroup>
<None Remove="Assets\app-icon.ico" />
<None Remove="Assets\app-icon.png" />
<None Remove="Assets\popup-brightness.svg" />
<None Remove="Assets\popup-temperature.svg" />
</ItemGroup>

<ItemGroup>
Expand All @@ -21,11 +23,14 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="SharpVectors.Wpf" Version="1.8.4.2" />
</ItemGroup>

<ItemGroup>
<Resource Include="Assets\app-icon.ico" />
<Resource Include="Assets\app-icon.png" />
<Resource Include="Assets\popup-brightness.svg" />
<Resource Include="Assets\popup-temperature.svg" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 13 additions & 1 deletion NightGlow/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NightGlow/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
<Setting Name="DdcConfigJson" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="ShowBrightTempPopup" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
13 changes: 12 additions & 1 deletion NightGlow/Services/NightGlowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Linq;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using NightGlow.Views;
using Microsoft.Extensions.DependencyInjection;

namespace NightGlow.Services;

Expand All @@ -21,6 +23,8 @@ public class NightGlowService : ObservableObject, IDisposable
private readonly GammaService _gammaService;
private readonly DdcService _ddcService;

private readonly IServiceProvider _serviceProvider;

private readonly IDisposable _eventRegistration;

public double Brightness
Expand All @@ -41,13 +45,15 @@ public NightGlowService(
SettingsService settingsService,
HotKeyService hotKeyService,
GammaService gammaService,
DdcService ddcService
DdcService ddcService,
IServiceProvider serviceProvider
)
{
_settingsService = settingsService;
_hotKeyService = hotKeyService;
_gammaService = gammaService;
_ddcService = ddcService;
_serviceProvider = serviceProvider;

RegisterHotKeys();

Expand Down Expand Up @@ -184,6 +190,11 @@ private void ChangeConfig(double brightnessOffset, int temperatureOffset)
OnPropertyChanged(nameof(Temperature));

UpdateConfiguration();

if (_settingsService.ShowBrightTempPopup)
{
_serviceProvider.GetRequiredService<PopupWindow>().ShowPopup();
}
}

// Using the brightness value, check wheter to use ddc/gamma to set the brightness
Expand Down
11 changes: 11 additions & 0 deletions NightGlow/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public bool ExtendedGammaRange
set => _extendedGammaRange.Set = value;
}

public bool ShowBrightTempPopup
{
get => Settings.Default.ShowBrightTempPopup;
set
{
Settings.Default.ShowBrightTempPopup = value;
Settings.Default.Save();
OnPropertyChanged(nameof(ShowBrightTempPopup));
}
}

public bool FirstLaunch
{
get => Settings.Default.FirstLaunch;
Expand Down
5 changes: 4 additions & 1 deletion NightGlow/ViewModels/NotifyIconViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ NightGlowService nightGlowService

public void ShowWindow()
{
Application.Current.MainWindow ??= _serviceProvider.GetRequiredService<MainWindow>();
if (!(Application.Current.MainWindow is MainWindow))
{
Application.Current.MainWindow = _serviceProvider.GetRequiredService<MainWindow>();
}
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Activate();
}
Expand Down
21 changes: 21 additions & 0 deletions NightGlow/ViewModels/PopupViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using CommunityToolkit.Mvvm.ComponentModel;
using NightGlow.Services;

namespace NightGlow.ViewModels;

public partial class PopupViewModel : ObservableObject
{

private readonly SettingsService _settingsService;
private readonly NightGlowService _nightGlowService;

public SettingsService SettingsService { get => _settingsService; }
public NightGlowService NightGlowService { get => _nightGlowService; }

public PopupViewModel(SettingsService settingsService, NightGlowService nightGlowService)
{
_settingsService = settingsService;
_nightGlowService = nightGlowService;
}

}
61 changes: 61 additions & 0 deletions NightGlow/Views/Controls/PopupDisplayInfoView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<UserControl
x:Class="NightGlow.Views.Controls.PopupDisplayInfoView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:NightGlow.Views.Controls"
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
mc:Ignorable="d"
Padding="10"
>

<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="16"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="32"/>
</Grid.ColumnDefinitions>

<svgc:SvgViewbox
Source="{Binding Icon, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PopupDisplayInfoView}}}"
Width="16"
Height="16"
Grid.Column="0"
VerticalAlignment="Center"
/>

<materialDesign:Card
materialDesign:ElevationAssist.Elevation="Dp0"
UniformCornerRadius="2"
Grid.Column="1"
VerticalAlignment="Center"
Margin="12,2,10,0"
>

<ProgressBar
Value="{Binding SliderValue, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PopupDisplayInfoView}}}"
Minimum="{Binding SliderValueMin, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PopupDisplayInfoView}}}"
Maximum="{Binding SliderValueMax, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PopupDisplayInfoView}}}"
materialDesign:TransitionAssist.DisableTransitions="True"
Foreground="{DynamicResource WinVolPopupDarkForeColor}"
Background="{DynamicResource WinVolPopupProgressDarkBackColor}"
BorderThickness="0"
/>

</materialDesign:Card>

<TextBlock
Text="{Binding SliderValue, StringFormat={}{0:F0}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:PopupDisplayInfoView}}}"
FontSize="14"
Grid.Column="2"
VerticalAlignment="Center"
TextAlignment="Center"
Width="32"
/>

</Grid>

</UserControl>
40 changes: 40 additions & 0 deletions NightGlow/Views/Controls/PopupDisplayInfoView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Windows;
using System.Windows.Controls;

namespace NightGlow.Views.Controls;

public partial class PopupDisplayInfoView : UserControl
{

public static readonly DependencyProperty SliderValueProperty = DependencyProperty.Register(nameof(SliderValue), typeof(double), typeof(PopupDisplayInfoView), null);

public double SliderValue
{
get => (double)GetValue(SliderValueProperty);
set => SetValue(SliderValueProperty, value);
}

public static readonly DependencyProperty SliderValueMinProperty = DependencyProperty.Register(nameof(SliderValueMin), typeof(double), typeof(PopupDisplayInfoView), null);

public double SliderValueMin
{
get => (double)GetValue(SliderValueMinProperty);
set => SetValue(SliderValueMinProperty, value);
}

public static readonly DependencyProperty SliderValueMaxProperty = DependencyProperty.Register(nameof(SliderValueMax), typeof(double), typeof(PopupDisplayInfoView), null);

public double SliderValueMax
{
get => (double)GetValue(SliderValueMaxProperty);
set => SetValue(SliderValueMaxProperty, value);
}

public string Icon { get; set; }

public PopupDisplayInfoView()
{
InitializeComponent();
}

}
73 changes: 73 additions & 0 deletions NightGlow/Views/PopupWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<Window
x:Class="NightGlow.Views.PopupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NightGlow.Views"
xmlns:uc="clr-namespace:NightGlow.Views.Controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:conv="clr-namespace:NightGlow.Views.Converters"
mc:Ignorable="d"
Width="200"
WindowStyle="None"
AllowsTransparency="True"
Topmost="True"
ResizeMode="NoResize"
ShowInTaskbar="False"
Background="Transparent"
SizeToContent="Height"
Focusable="False"
TextElement.Foreground="{DynamicResource WinVolPopupDarkForeColor}"
>

<Window.Resources>
<conv:DecToPctConverter x:Key="DecToPctConverter"/>
</Window.Resources>

<!-- View to animate in the window. Larger bottom padding so view isnt immediately cut off when starting to animate -->
<Border
x:Name="AnimatedContainer"
Padding="4,4,4,16"
>

<Border.RenderTransform>
<TranslateTransform x:Name="AnimatedContainerTransform" />
</Border.RenderTransform>

<materialDesign:Card
Style="{StaticResource MaterialDesignElevatedCard}"
Background="{DynamicResource WinVolPopupDarkBackColor}"
UniformCornerRadius="10"
>

<Border
BorderBrush="{DynamicResource WinVolPopupDarkBorderColor}"
BorderThickness="1"
CornerRadius="10"
Padding="0,2"
>

<StackPanel
Orientation="Vertical"
>

<uc:PopupDisplayInfoView
Icon="/Assets/popup-brightness.svg"
SliderValue="{Binding NightGlowService.Brightness, Converter={StaticResource DecToPctConverter}}"
SliderValueMin="{Binding SettingsService.BrightnessMin, Converter={StaticResource DecToPctConverter}}"
SliderValueMax="{Binding SettingsService.BrightnessMax, Converter={StaticResource DecToPctConverter}}"
/>

<uc:PopupDisplayInfoView
Icon="/Assets/popup-temperature.svg"
SliderValue="{Binding NightGlowService.Temperature}"
SliderValueMin="{Binding SettingsService.TemperatureMin}"
SliderValueMax="{Binding SettingsService.TemperatureMax}"
/>

</StackPanel>
</Border>
</materialDesign:Card>
</Border>
</Window>
Loading

0 comments on commit 02c991b

Please sign in to comment.