Skip to content

Commit

Permalink
Merge pull request #321 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored May 9, 2022
2 parents 093ca58 + 1031dbc commit 3bc1dd0
Show file tree
Hide file tree
Showing 23 changed files with 320 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Source/Installer/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.10.1"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.11.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
11 changes: 11 additions & 0 deletions Source/Monitorian.Core/AppControllerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ protected virtual void ShowMenuWindow(Point pivot)

protected virtual async void OnSettingsInitiated()
{
if (Settings.UsesAccentColor)
WindowPainter.AttachAccentColors();

if (Settings.MakesOperationLog)
await Recorder.EnableAsync("Initiated");
}
Expand All @@ -163,6 +166,14 @@ protected virtual async void OnSettingsChanged(object sender, PropertyChangedEve
{
switch (e.PropertyName)
{
case nameof(Settings.UsesAccentColor):
if (Settings.UsesAccentColor)
WindowPainter.AttachAccentColors();
else
WindowPainter.DetachAccentColors();

break;

case nameof(Settings.EnablesUnison) when !Settings.EnablesUnison:
foreach (var m in Monitors)
m.IsUnison = false;
Expand Down
11 changes: 11 additions & 0 deletions Source/Monitorian.Core/Models/SettingsCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public bool UsesLargeElements
}
private bool _usesLargeElements = true; // Default

/// <summary>
/// Whether to use accent color for brightness
/// </summary>
[DataMember]
public bool UsesAccentColor
{
get => _usesAccentColor;
set => SetPropertyValue(ref _usesAccentColor, value);
}
private bool _usesAccentColor;

/// <summary>
/// Whether to show adjusted brightness
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions Source/Monitorian.Core/Models/Watcher/BrightnessWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -68,11 +69,11 @@ protected virtual void Dispose(bool disposing)
if (_watcher is not null)
{
_watcher.EventArrived -= OnEventArrived;
_watcher.Stop(); // This may throw InvalidCastException.
_watcher.Stop(); // This may throw InvalidCastException or COMException.
_watcher.Dispose();
}
}
catch (InvalidCastException)
catch (Exception ex) when (ex is InvalidCastException or COMException)
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.10.1.0")]
[assembly: AssemblyFileVersion("3.10.1.0")]
[assembly: AssemblyVersion("3.11.0.0")]
[assembly: AssemblyFileVersion("3.11.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]

// For unit test
Expand Down
18 changes: 18 additions & 0 deletions Source/Monitorian.Core/Properties/Resources.Designer.cs

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

6 changes: 6 additions & 0 deletions Source/Monitorian.Core/Properties/Resources.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
<data name="Rescan" xml:space="preserve">
<value>モニターを再探索する</value>
</data>
<data name="RestoreReconnection" xml:space="preserve">
<value>再接続時に明るさを復元する</value>
</data>
<data name="Settings" xml:space="preserve">
<value>設定</value>
</data>
Expand All @@ -192,6 +195,9 @@
<data name="StatusReasonDdcNotEnabled" xml:space="preserve">
<value>DDC/CIがサポートされていないか有効になっていません。</value>
</data>
<data name="UseAccentColor" xml:space="preserve">
<value>明るさにアクセントカラーを使う</value>
</data>
<data name="UseLargeElements" xml:space="preserve">
<value>大きいスライダーを使う</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions Source/Monitorian.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
<data name="Rescan" xml:space="preserve">
<value>Rescan monitors</value>
</data>
<data name="RestoreReconnection" xml:space="preserve">
<value>Restore brightness on reconnection</value>
</data>
<data name="Settings" xml:space="preserve">
<value>Settings</value>
</data>
Expand All @@ -192,6 +195,9 @@
<data name="StatusReasonDdcNotEnabled" xml:space="preserve">
<value>DDC/CI is not supported or enabled.</value>
</data>
<data name="UseAccentColor" xml:space="preserve">
<value>Use accent color for brightness</value>
</data>
<data name="UseLargeElements" xml:space="preserve">
<value>Use large sliders</value>
</data>
Expand Down
5 changes: 4 additions & 1 deletion Source/Monitorian.Core/Views/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<Color x:Key="App.TargetColor">LightGray</Color>
<Color x:Key="App.OverlayColor">#48000000</Color>

<Color x:Key="App.Background.Accent.StaticColor">#FF2982CC</Color>
<Color x:Key="App.Background.Accent.MouseOverColor">#FF5CA4DE</Color>
<Color x:Key="App.Background.Accent.PressedColor">#FF5CA4DE</Color>

<SolidColorBrush x:Key="App.Foreground" Color="{DynamicResource App.ForegroundColor}"/>
<SolidColorBrush x:Key="App.Foreground.Shadow" Color="{DynamicResource App.ShadowColor}"/>
<SolidColorBrush x:Key="App.Foreground.Dusk" Color="#FFACACAC"/>
Expand All @@ -18,7 +22,6 @@
<SolidColorBrush x:Key="App.Border.Outline" Color="{DynamicResource App.LineColor}"/>
<SolidColorBrush x:Key="App.Background.Plain" Color="#FF1F1F1F"/>
<SolidColorBrush x:Key="App.Background.Translucent" Color="#D3161616"/>
<SolidColorBrush x:Key="App.Background.Accent" Color="#FF2982CC"/>

<Color x:Key="Icon.Foreground.NormalColor">#FF808080</Color>
<Color x:Key="Icon.Background.MouseOverColor">#33FFFFFF</Color>
Expand Down
11 changes: 4 additions & 7 deletions Source/Monitorian.Core/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource ToolTipStyle}"/>

<!-- Slider -->
<Color x:Key="Slider.Background.Main.StaticColor">#FF2982CC</Color>
<Color x:Key="Slider.Background.Main.MouseOverColor">#FF5CA4DE</Color>
<Color x:Key="Slider.Background.Main.PressedColor">#FF5CA4DE</Color>
<Color x:Key="Slider.Background.Range.StaticColor">#FFFFA500</Color>
<Color x:Key="Slider.Background.Range.MouseOverColor">#FFFFC400</Color>
<Color x:Key="Slider.Background.Range.PressedColor">#FFFFC400</Color>
Expand All @@ -51,9 +48,9 @@
<Color x:Key="Slider.Background.DisabledColor">#FFF0F0F0</Color>
<Color x:Key="Slider.Background.VacantColor">#FF999999</Color>

<SolidColorBrush x:Key="Slider.Background.Main.Static" Color="{StaticResource Slider.Background.Main.StaticColor}"/>
<SolidColorBrush x:Key="Slider.Background.Main.MouseOver" Color="{StaticResource Slider.Background.Main.MouseOverColor}"/>
<SolidColorBrush x:Key="Slider.Background.Main.Pressed" Color="{StaticResource Slider.Background.Main.PressedColor}"/>
<SolidColorBrush x:Key="Slider.Background.Main.Static" Color="{DynamicResource App.Background.Accent.StaticColor}"/>
<SolidColorBrush x:Key="Slider.Background.Main.MouseOver" Color="{DynamicResource App.Background.Accent.MouseOverColor}"/>
<SolidColorBrush x:Key="Slider.Background.Main.Pressed" Color="{DynamicResource App.Background.Accent.PressedColor}"/>
<SolidColorBrush x:Key="Slider.Background.Range.Static" Color="{StaticResource Slider.Background.Range.StaticColor}"/>
<SolidColorBrush x:Key="Slider.Background.Range.MouseOver" Color="{StaticResource Slider.Background.Range.MouseOverColor}"/>
<SolidColorBrush x:Key="Slider.Background.Range.Pressed" Color="{StaticResource Slider.Background.Range.PressedColor}"/>
Expand Down Expand Up @@ -667,7 +664,7 @@
</Grid.ColumnDefinitions>

<Rectangle Grid.Column="0"
Fill="{StaticResource App.Background.Accent}"
Fill="{StaticResource Slider.Background.Main.Static}"
Visibility="{Binding IsSelectedByKey, Converter={StaticResource BooleanToVisibilityConverterKey}}"/>

<!-- Brightness -->
Expand Down
7 changes: 5 additions & 2 deletions Source/Monitorian.Core/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public MainWindow(AppControllerCore controller)
{
ViewModel.MonitorsView.Refresh();
};
//controller.WindowPainter.AccentColorChanged += (_, _) =>
//{
//};

_tracker = new TouchpadTracker(this);
_tracker.ManipulationDelta += (_, delta) =>
Expand Down Expand Up @@ -113,7 +116,7 @@ public bool UsesLargeElements
true,
(d, e) =>
{
// Setting the same value will not trigger calling this method.
// Setting the same value will not trigger calling this method.
var window = (MainWindow)d;
if (window._defaultHeights is null)
Expand Down Expand Up @@ -205,7 +208,7 @@ protected override void OnDeactivated(EventArgs e)

ViewModel.Deactivate();

// Set time to prevent this window from being shown unintentionally.
// Set time to prevent this window from being shown unintentionally.
_preventionTime = DateTimeOffset.Now + TimeSpan.FromSeconds(0.2);

ClearHide();
Expand Down
8 changes: 8 additions & 0 deletions Source/Monitorian.Core/Views/MenuWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
IsChecked="{Binding Settings.UsesLargeElements}"/>
</ContentControl>

<ContentControl Style="{StaticResource MenuItemStyle}">
<ToggleButton Padding="8,4"
Style="{StaticResource CheckButtonItemStyle}"
FontSize="13"
Content="{x:Static properties:Resources.UseAccentColor}"
IsChecked="{Binding Settings.UsesAccentColor}"/>
</ContentControl>

<ContentControl Style="{StaticResource MenuItemStyle}">
<ToggleButton Padding="8,4"
Style="{StaticResource CheckButtonItemStyle}"
Expand Down
65 changes: 62 additions & 3 deletions Source/Monitorian.Core/Views/WindowPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Media;

using Monitorian.Core.Helper;
using Monitorian.Supplement;
using ScreenFrame.Painter;

namespace Monitorian.Core.Views
Expand All @@ -19,7 +20,7 @@ public WindowPainter() : base(AppKeeper.StandardArguments)
public static new IReadOnlyCollection<string> Options => ScreenFrame.Painter.WindowPainter.Options.Concat(ColorPairs.Keys).ToArray();

/// <summary>
/// Color changeable elements of window
/// Color changeable background/border
/// </summary>
private enum ColorElement
{
Expand Down Expand Up @@ -77,15 +78,17 @@ bool TryParse(string source, out Brush brush)
_colors = colors.Any() ? colors : null;
}

#region Theme or background/border colors

protected override void PaintBackground(Window window)
{
if (ChangeColors(window))
if (ChangeBackgroundColors(window))
return;

base.PaintBackground(window);
}

private bool ChangeColors(Window window)
private bool ChangeBackgroundColors(Window window)
{
if (_colors is not { Count: > 0 })
return false;
Expand Down Expand Up @@ -135,5 +138,61 @@ protected override void ChangeThemes(ColorTheme oldTheme, ColorTheme newTheme)
break;
}
}

#endregion

#region Accent color

private static readonly Lazy<ResourceDictionary> _generic = new(() =>
Application.Current.Resources.MergedDictionaries.Single(x => x.Source.OriginalString.EndsWith("Generic.xaml")));

private class ColorContainer
{
private readonly string _key;
private readonly Color _color;

public ColorContainer(string key)
{
this._key = key;
this._color = Color;
}

public Color Color
{
get => (Color)_generic.Value[_key];
set => _generic.Value[_key] = value;
}

public void Revert() => Color = _color;
}

private readonly Lazy<ColorContainer> _staticColorContaier = new(() => new("App.Background.Accent.StaticColor"));
private readonly Lazy<ColorContainer> _mouseOverColorContainer = new(() => new("App.Background.Accent.MouseOverColor"));
private readonly Lazy<ColorContainer> _pressedColorContainer = new(() => new("App.Background.Accent.PressedColor"));

public void AttachAccentColors()
{
ChangeAccentColors();

RespondsAccentColorChanged = true;
}

public void DetachAccentColors()
{
RespondsAccentColorChanged = false;

_staticColorContaier.Value.Revert();
_mouseOverColorContainer.Value.Revert();
_pressedColorContainer.Value.Revert();
}

protected override void ChangeAccentColors()
{
_staticColorContaier.Value.Color = UIInformation.GetAccentColor();
_mouseOverColorContainer.Value.Color = UIInformation.GetAccentLightColor();
_pressedColorContainer.Value.Color = _mouseOverColorContainer.Value.Color;
}

#endregion
}
}
4 changes: 2 additions & 2 deletions Source/Monitorian.Supplement/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.10.0.0")]
[assembly: AssemblyFileVersion("3.10.0.0")]
[assembly: AssemblyVersion("3.11.0.0")]
[assembly: AssemblyFileVersion("3.11.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]
12 changes: 12 additions & 0 deletions Source/Monitorian.Supplement/UIInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ public class UIInformation
/// <returns></returns>
public static Color GetAccentColor() => GetUIColor(UIColorType.Accent);

/// <summary>
/// Gets the system accent light color.
/// </summary>
/// <returns></returns>
public static Color GetAccentLightColor() => GetUIColor(UIColorType.AccentLight1);

/// <summary>
/// Gets the system accent dark color.
/// </summary>
/// <returns></returns>
public static Color GetAccentDarkColor() => GetUIColor(UIColorType.AccentDark1);

/// <summary>
/// Gets the system background color.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.10.1.0")]
[assembly: AssemblyFileVersion("3.10.1.0")]
[assembly: AssemblyVersion("3.11.0.0")]
[assembly: AssemblyFileVersion("3.11.0.0")]
[assembly: Guid("a4cc5362-9b08-465b-ad64-5cfabc72a4c7")]
[assembly: NeutralResourcesLanguage("en-US")]
Loading

0 comments on commit 3bc1dd0

Please sign in to comment.