GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
chore: update to .NET 6 and fix common Roslynator rule violations (#42)
neon-sunset121f23733d9c
diff --git a/.editorconfig b/.editorconfigindex cd22754c..890061ff 100644--- a/.editorconfig+++ b/.editorconfig@@ -43,7 +43,7 @@ dotnet_style_prefer_inferred_tuple_names = true:suggestiondotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestiondotnet_style_prefer_auto_properties = true:silentdotnet_style_prefer_conditional_expression_over_assignment = true:silent-dotnet_style_prefer_conditional_expression_over_return = true:silent+dotnet_style_prefer_conditional_expression_over_return = false:silent################################ Naming Conventions ################################@@ -85,6 +85,7 @@ csharp_style_deconstructed_variable_declaration = true:suggestioncsharp_prefer_simple_default_expression = true:suggestioncsharp_style_pattern_local_over_anonymous_function = true:suggestioncsharp_style_inlined_variable_declaration = true:suggestion+csharp_style_unused_value_expression_statement_preference = discard_variable:none################################ C# Formatting Rules ################################@@ -116,8 +117,41 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = falsecsharp_preserve_single_line_statements = truecsharp_preserve_single_line_blocks = true###############################-# VB Coding Conventions #+# Analyzer Rules ################################-[*.vb]-# Modifier preferences-visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion+roslynator_refactorings.enabled = false+roslynator_compiler_diagnostic_fixes.enabled = true+# Disable rule "Add braces (when expression spans over multiple lines)".+dotnet_diagnostic.IDE0011.severity = none+dotnet_diagnostic.RCS1001.severity = none+dotnet_diagnostic.RCS1003.severity = none+# Disable rule "Use bit shift operator".+dotnet_diagnostic.RCS1237.severity = none+# Disable rule "Add 'param' element to documentation comment".+dotnet_diagnostic.RCS1141.severity = none+# Disable rule "Add 'typeparam' element to documentation comment".+dotnet_diagnostic.RCS1142.severity = none+# Disable rule "Use pattern matching to avoid 'as' followed by a 'null' check".+dotnet_diagnostic.IDE0019.severity = none+dotnet_diagnostic.RCS1221.severity = none+# Disable rule "Declare enum member with zero value (when enum has FlagsAttribute)"+dotnet_diagnostic.RCS1135.severity = none+# Disable rule "Avoid NullReferenceException". Undecided whether to enable, since it can reduce+# clarity when a variable is guaranteed to be defined.+dotnet_diagnostic.RCS1202.severity = none+# TODO: Temporarily disabled rules until upcoming refactors:+# Disable rule "P/Invoke methods should not be visible".+dotnet_diagnostic.CA1401.severity = none+# Disable rule "Duplicate enum value".+dotnet_diagnostic.RCS1234.severity = none+dotnet_diagnostic.CA1069.severity = none+# Disable rule "Identifiers should not contain underscores".+dotnet_diagnostic.CA1707.severity = none+# Disable rule "Enum should declare explicit values".+dotnet_diagnostic.RCS1161.severity = none+# Add rule exception "Types that own disposable fields should be disposable".+[**/Bus.cs]+dotnet_diagnostic.CA1001.severity = none+# Add rule exception "Fix formatting".+[**/AssemblyInfo.cs]+dotnet_diagnostic.IDE0055.severity = nonediff --git a/.vscode/launch.json b/.vscode/launch.jsonindex 3b291537..87fb71bd 100644--- a/.vscode/launch.json+++ b/.vscode/launch.json@@ -10,7 +10,7 @@"request": "launch","preLaunchTask": "build",// If you have changed target frameworks, make sure to update the program path.- "program": "${workspaceFolder}/GlazeWM.Bootstrapper/bin/Debug/netcoreapp3.1/GlazeWM.dll",+ "program": "${workspaceFolder}/GlazeWM.Bootstrapper/bin/Debug/net6.0-windows/GlazeWM.dll","args": [],"cwd": "${workspaceFolder}/GlazeWM.Bootstrapper",// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Consolediff --git a/GlazeWM.Bar/AssemblyInfo.cs b/GlazeWM.Bar/AssemblyInfo.csindex 8b5504ec..90d553f3 100644--- a/GlazeWM.Bar/AssemblyInfo.cs+++ b/GlazeWM.Bar/AssemblyInfo.cs@@ -1,10 +1,10 @@using System.Windows;[assembly: ThemeInfo(- ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located- //(used if a resource is not found in the page,- // or application resource dictionaries)- ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located- //(used if a resource is not found in the page,- // app, or any theme specific resource dictionaries)-)]+ // Where theme specific resource dictionaries are located (used if a resource is not found in the+ // page, or application resource dictionaries).+ ResourceDictionaryLocation.None,+ // Where the generic resource dictionary is located (used if a resource is not found in the page,+ // app, or any theme specific resource dictionaries).+ ResourceDictionaryLocation.SourceAssembly)+]diff --git a/GlazeWM.Bar/BarService.cs b/GlazeWM.Bar/BarService.csindex 627ea602..424c7adc 100644--- a/GlazeWM.Bar/BarService.cs+++ b/GlazeWM.Bar/BarService.cs@@ -12,10 +12,9 @@ namespace GlazeWM.Bar{public class BarService{- private Bus _bus;+ private readonly Bus _bus;private Application _application;- private Dictionary<string, MainWindow> _activeWindowsByDeviceName- = new Dictionary<string, MainWindow>();+ private readonly Dictionary<string, MainWindow> _activeWindowsByDeviceName = new();public BarService(Bus bus){@@ -68,9 +67,10 @@ namespace GlazeWM.Bar});_application.Run();- });-- thread.Name = "GlazeWMBar";+ })+ {+ Name = "GlazeWMBar"+ };thread.SetApartmentState(ApartmentState.STA);thread.Start();}@@ -85,17 +85,18 @@ namespace GlazeWM.Bar/// to be compatible with their equivalent XAML properties (ie. `Padding`, `Margin`, and/// `BorderThickness`). Shorthand properties follow the 1-to-4 value syntax used in CSS./// </summary>- public string ShorthandToXamlProperty(string shorthand)+ /// <exception cref="ArgumentException"></exception>+ public static string ShorthandToXamlProperty(string shorthand){var shorthandParts = shorthand.Split(" ");- return shorthandParts.Count() switch+ return shorthandParts.Length switch{1 => shorthand,2 => $"{shorthandParts[1]},{shorthandParts[0]},{shorthandParts[1]},{shorthandParts[0]}",3 => $"{shorthandParts[1]},{shorthandParts[0]},{shorthandParts[1]},{shorthandParts[2]}",4 => $"{shorthandParts[3]},{shorthandParts[0]},{shorthandParts[1]},{shorthandParts[2]}",- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(shorthand)),};}}diff --git a/GlazeWM.Bar/BarViewModel.cs b/GlazeWM.Bar/BarViewModel.csindex 6028f077..94233da0 100644--- a/GlazeWM.Bar/BarViewModel.cs+++ b/GlazeWM.Bar/BarViewModel.cs@@ -1,7 +1,5 @@-using System;+using System;using System.Collections.Generic;-using System.Linq;-using System.Reactive.Linq;using System.Windows.Threading;using GlazeWM.Bar.Common;using GlazeWM.Bar.Components;@@ -17,8 +15,7 @@ namespace GlazeWM.Barpublic Dispatcher Dispatcher { get; set; }public Monitor Monitor { get; set; }- private BarService _barService = ServiceLocator.Provider.GetRequiredService<BarService>();- private UserConfigService _userConfigService = ServiceLocator.Provider.GetRequiredService<UserConfigService>();+ private readonly UserConfigService _userConfigService = ServiceLocator.Provider.GetRequiredService<UserConfigService>();private BarConfig _barConfig => _userConfigService.UserConfig.Bar;public BarPosition Position => _barConfig.Position;@@ -27,8 +24,8 @@ namespace GlazeWM.Barpublic string FontFamily => _barConfig.FontFamily;public string FontSize => _barConfig.FontSize;public string BorderColor => _barConfig.BorderColor;- public string BorderWidth => _barService.ShorthandToXamlProperty(_barConfig.BorderWidth);- public string Padding => _barService.ShorthandToXamlProperty(_barConfig.Padding);+ public string BorderWidth => BarService.ShorthandToXamlProperty(_barConfig.BorderWidth);+ public string Padding => BarService.ShorthandToXamlProperty(_barConfig.Padding);public double Opacity => _barConfig.Opacity;public List<ComponentViewModel> ComponentsLeft =>@@ -40,24 +37,14 @@ namespace GlazeWM.Barpublic List<ComponentViewModel> ComponentsRight =>CreateComponentViewModels(_barConfig.ComponentsRight);- public BarViewModel()- {- }-private List<ComponentViewModel> CreateComponentViewModels(List<BarComponentConfig> componentConfigs){- return componentConfigs.Select(config =>+ return componentConfigs.ConvertAll<ComponentViewModel>(config => config switch{- // TODO: Use pattern matching syntax with types once updated to C# 9.- ComponentViewModel viewModel = config.Type switch- {- "workspaces" => new WorkspacesComponentViewModel(this, config as WorkspacesComponentConfig),- "clock" => new ClockComponentViewModel(this, config as ClockComponentConfig),- _ => throw new ArgumentException(),- };-- return viewModel;- }).ToList();+ WorkspacesComponentConfig wcc => new WorkspacesComponentViewModel(this, wcc),+ ClockComponentConfig ccc => new ClockComponentViewModel(this, ccc),+ _ => throw new ArgumentOutOfRangeException(nameof(config)),+ });}}}diff --git a/GlazeWM.Bar/Common/RelayCommand.cs b/GlazeWM.Bar/Common/RelayCommand.csindex 53e2ba7a..627bdab9 100644--- a/GlazeWM.Bar/Common/RelayCommand.cs+++ b/GlazeWM.Bar/Common/RelayCommand.cs@@ -5,13 +5,13 @@ namespace GlazeWM.Bar.Common{public class RelayCommand : ICommand{- private readonly Action _methodToExecute = null;- private readonly Func<bool> _canExecutePredicate = null;+ private readonly Action _methodToExecute;+ private readonly Func<bool> _canExecutePredicate;public event EventHandler CanExecuteChanged{- add { CommandManager.RequerySuggested += value; }- remove { CommandManager.RequerySuggested -= value; }+ add => CommandManager.RequerySuggested += value;+ remove => CommandManager.RequerySuggested -= value;}public RelayCommand(Action methodToExecute)@@ -29,7 +29,7 @@ namespace GlazeWM.Bar.Commonpublic bool CanExecute(object parameter){- return _canExecutePredicate == null ? true : _canExecutePredicate.Invoke();+ return _canExecutePredicate?.Invoke() != false;}public void Execute(object parameter)@@ -40,13 +40,13 @@ namespace GlazeWM.Bar.Commonpublic class RelayCommand<T> : ICommand{- private readonly Action<T> _methodToExecute = null;- private readonly Predicate<T> _canExecutePredicate = null;+ private readonly Action<T> _methodToExecute;+ private readonly Predicate<T> _canExecutePredicate;public event EventHandler CanExecuteChanged{- add { CommandManager.RequerySuggested += value; }- remove { CommandManager.RequerySuggested -= value; }+ add => CommandManager.RequerySuggested += value;+ remove => CommandManager.RequerySuggested -= value;}public RelayCommand(Action<T> methodToExecute)@@ -64,7 +64,7 @@ namespace GlazeWM.Bar.Commonpublic bool CanExecute(object parameter){- return _canExecutePredicate == null ? true : _canExecutePredicate.Invoke((T)parameter);+ return _canExecutePredicate?.Invoke((T)parameter) != false;}public void Execute(object parameter)diff --git a/GlazeWM.Bar/Components/ClockComponent.xaml.cs b/GlazeWM.Bar/Components/ClockComponent.xaml.csindex b76ce8dd..1c4b3c59 100644--- a/GlazeWM.Bar/Components/ClockComponent.xaml.cs+++ b/GlazeWM.Bar/Components/ClockComponent.xaml.cs@@ -1,16 +1,4 @@-using System;-using System.Collections;-using System.Collections.Generic;-using System.Text;-using System.Windows;using System.Windows.Controls;-using System.Windows.Data;-using System.Windows.Documents;-using System.Windows.Input;-using System.Windows.Media;-using System.Windows.Media.Imaging;-using System.Windows.Navigation;-using System.Windows.Shapes;namespace GlazeWM.Bar.Components{@@ -25,4 +13,3 @@ namespace GlazeWM.Bar.Components}}}-diff --git a/GlazeWM.Bar/Components/ComponentPortal.xaml.cs b/GlazeWM.Bar/Components/ComponentPortal.xaml.csindex b629f48b..134e515c 100644--- a/GlazeWM.Bar/Components/ComponentPortal.xaml.cs+++ b/GlazeWM.Bar/Components/ComponentPortal.xaml.cs@@ -1,17 +1,4 @@-using System;-using System.Collections;-using System.Collections.Generic;-using System.Text;-using System.Windows;using System.Windows.Controls;-using System.Windows.Data;-using System.Windows.Documents;-using System.Windows.Input;-using System.Windows.Media;-using System.Windows.Media.Imaging;-using System.Windows.Navigation;-using System.Windows.Shapes;-using GlazeWM.Domain.UserConfigs;namespace GlazeWM.Bar.Components{@@ -26,4 +13,3 @@ namespace GlazeWM.Bar.Components}}}-diff --git a/GlazeWM.Bar/Components/ComponentViewModel.cs b/GlazeWM.Bar/Components/ComponentViewModel.csindex fc4e8c58..0e5173c2 100644--- a/GlazeWM.Bar/Components/ComponentViewModel.cs+++ b/GlazeWM.Bar/Components/ComponentViewModel.cs@@ -16,9 +16,9 @@ namespace GlazeWM.Bar.Componentspublic string FontFamily => _componentConfig.FontFamily ?? _parentViewModel.FontFamily;public string FontSize => _componentConfig.FontSize ?? _parentViewModel.FontSize;public string BorderColor => _componentConfig.BorderColor;- public string BorderWidth => _barService.ShorthandToXamlProperty(_componentConfig.BorderWidth);- public string Padding => _barService.ShorthandToXamlProperty(_componentConfig.Padding);- public string Margin => _barService.ShorthandToXamlProperty(_componentConfig.Margin);+ public string BorderWidth => BarService.ShorthandToXamlProperty(_componentConfig.BorderWidth);+ public string Padding => BarService.ShorthandToXamlProperty(_componentConfig.Padding);+ public string Margin => BarService.ShorthandToXamlProperty(_componentConfig.Margin);public ComponentViewModel(BarViewModel parentViewModel, BarComponentConfig baseConfig){diff --git a/GlazeWM.Bar/Components/WorkspacesComponent.xaml.cs b/GlazeWM.Bar/Components/WorkspacesComponent.xaml.csindex b0b1d2e2..67d06cde 100644--- a/GlazeWM.Bar/Components/WorkspacesComponent.xaml.cs+++ b/GlazeWM.Bar/Components/WorkspacesComponent.xaml.cs@@ -1,16 +1,4 @@-using System;-using System.Collections;-using System.Collections.Generic;-using System.Text;-using System.Windows;using System.Windows.Controls;-using System.Windows.Data;-using System.Windows.Documents;-using System.Windows.Input;-using System.Windows.Media;-using System.Windows.Media.Imaging;-using System.Windows.Navigation;-using System.Windows.Shapes;namespace GlazeWM.Bar.Components{@@ -25,4 +13,3 @@ namespace GlazeWM.Bar.Components}}}-diff --git a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.csindex f610a83a..97985745 100644--- a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs+++ b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs@@ -27,8 +27,7 @@ namespace GlazeWM.Bar.Componentsprivate readonly UserConfigService _userConfigService =ServiceLocator.Provider.GetRequiredService<UserConfigService>();- public ObservableCollection<Workspace> Workspaces =>- new ObservableCollection<Workspace>(_orderedWorkspaces);+ public ObservableCollection<Workspace> Workspaces => new(_orderedWorkspaces);/// <summary>/// Get workspaces of the current monitor sorted in the order they appear in the user's config.@@ -45,19 +44,19 @@ namespace GlazeWM.Bar.Componentspublic string FocusedWorkspaceForeground => _config.FocusedWorkspaceForeground ?? Foreground;public string FocusedWorkspaceBorderColor => _config.FocusedWorkspaceBorderColor;public string FocusedWorkspaceBorderWidth =>- _barService.ShorthandToXamlProperty(_config.FocusedWorkspaceBorderWidth);+ BarService.ShorthandToXamlProperty(_config.FocusedWorkspaceBorderWidth);public string DisplayedWorkspaceBackground => _config.DisplayedWorkspaceBackground;public string DisplayedWorkspaceForeground => _config.DisplayedWorkspaceForeground ?? Foreground;public string DisplayedWorkspaceBorderColor => _config.DisplayedWorkspaceBorderColor;public string DisplayedWorkspaceBorderWidth =>- _barService.ShorthandToXamlProperty(_config.DisplayedWorkspaceBorderWidth);+ BarService.ShorthandToXamlProperty(_config.DisplayedWorkspaceBorderWidth);public string DefaultWorkspaceBackground => _config.DefaultWorkspaceBackground ?? Background;public string DefaultWorkspaceForeground => _config.DefaultWorkspaceForeground ?? Foreground;public string DefaultWorkspaceBorderColor => _config.DefaultWorkspaceBorderColor;public string DefaultWorkspaceBorderWidth =>- _barService.ShorthandToXamlProperty(_config.DefaultWorkspaceBorderWidth);+ BarService.ShorthandToXamlProperty(_config.DefaultWorkspaceBorderWidth);public ICommand FocusWorkspaceCommand => new RelayCommand<string>(FocusWorkspace);@@ -65,16 +64,11 @@ namespace GlazeWM.Bar.Components: base(parentViewModel, config){var workspacesChangedEvent = _bus.Events.Where((@event) =>- @event is WorkspaceActivatedEvent ||- @event is WorkspaceDeactivatedEvent ||- @event is FocusChangedEvent+ @event is WorkspaceActivatedEvent or WorkspaceDeactivatedEvent or FocusChangedEvent);// Refresh contents of workspaces collection.- workspacesChangedEvent.Subscribe((_observer) =>- {- _dispatcher.Invoke(() => OnPropertyChanged(nameof(Workspaces)));- });+ workspacesChangedEvent.Subscribe(_ => _dispatcher.Invoke(() => OnPropertyChanged(nameof(Workspaces))));}public void FocusWorkspace(string workspaceName)diff --git a/GlazeWM.Bar/GlazeWM.Bar.csproj b/GlazeWM.Bar/GlazeWM.Bar.csprojindex c8b7e347..49f32a9c 100644--- a/GlazeWM.Bar/GlazeWM.Bar.csproj+++ b/GlazeWM.Bar/GlazeWM.Bar.csproj@@ -1,9 +1,8 @@-<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">+<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Library</OutputType>- <TargetFramework>netcoreapp3.1</TargetFramework>- <RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>+ <TargetFramework>net6.0-windows</TargetFramework><UseWPF>true</UseWPF><DebugType>embedded</DebugType></PropertyGroup>diff --git a/GlazeWM.Bar/MainWindow.xaml.cs b/GlazeWM.Bar/MainWindow.xaml.csindex 74110c6f..b9a9c769 100644--- a/GlazeWM.Bar/MainWindow.xaml.cs+++ b/GlazeWM.Bar/MainWindow.xaml.cs@@ -18,8 +18,8 @@ namespace GlazeWM.Bar/// </summary>public partial class MainWindow : Window{- private Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();- private UserConfigService _userConfigService =+ private readonly Bus _bus = ServiceLocator.Provider.GetRequiredService<Bus>();+ private readonly UserConfigService _userConfigService =ServiceLocator.Provider.GetRequiredService<UserConfigService>();private BarViewModel _barViewModel { get; }@@ -44,19 +44,16 @@ namespace GlazeWM.Bar// Reposition window on changes to the monitor's working area._bus.Events.Where(@event => @event is WorkingAreaResizedEvent)- .Subscribe((@event) =>- {- _dispatcher.Invoke(() => PositionWindow(windowHandle));- });+ .Subscribe(_ => _dispatcher.Invoke(() => PositionWindow(windowHandle)));}/// <summary>/// Hide the WPF window from task switcher (alt+tab menu)./// </summary>- private void HideFromTaskSwitcher(IntPtr windowHandle)+ private static void HideFromTaskSwitcher(IntPtr windowHandle){var exstyle = (int)GetWindowLongPtr(windowHandle, GWL_EXSTYLE);- exstyle |= (int)(WS_EX.WS_EX_TOOLWINDOW);+ exstyle |= (int)WS_EX.WS_EX_TOOLWINDOW;SetWindowLongPtr(windowHandle, GWL_EXSTYLE, (IntPtr)exstyle);}diff --git a/GlazeWM.Bootstrapper/GlazeWM.Bootstrapper.csproj b/GlazeWM.Bootstrapper/GlazeWM.Bootstrapper.csprojindex f6c9f5b7..ac74e84d 100644--- a/GlazeWM.Bootstrapper/GlazeWM.Bootstrapper.csproj+++ b/GlazeWM.Bootstrapper/GlazeWM.Bootstrapper.csproj@@ -1,9 +1,8 @@-<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">+<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>WinExe</OutputType>- <TargetFramework>netcoreapp3.1</TargetFramework>- <RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>+ <TargetFramework>net6.0-windows</TargetFramework><UseWindowsForms>true</UseWindowsForms><DebugType>embedded</DebugType><ApplicationIcon>icon.ico</ApplicationIcon>diff --git a/GlazeWM.Bootstrapper/Program.cs b/GlazeWM.Bootstrapper/Program.csindex 8eb459b7..3f82d56e 100644--- a/GlazeWM.Bootstrapper/Program.cs+++ b/GlazeWM.Bootstrapper/Program.cs@@ -9,35 +9,33 @@ using System.Windows.Forms;namespace GlazeWM.Bootstrapper{- static class Program+ internal static class Program{- private static string appGuid = "325d0ed7-7f60-4925-8d1b-aa287b26b218";+ private const string APP_GUID = "325d0ed7-7f60-4925-8d1b-aa287b26b218";/// <summary>/// The main entry point for the application./// </summary>[STAThread]- static void Main()+ private static void Main(){Debug.WriteLine("Application started.");// Prevent multiple app instances using a global UUID mutex.- using (Mutex mutex = new Mutex(false, "Global\\" + appGuid))+ using var mutex = new Mutex(false, "Global\\" + APP_GUID);+ if (!mutex.WaitOne(0, false)){- if (!mutex.WaitOne(0, false))- {- Debug.Write(- "Application is already running. Only one instance of this application is allowed."- );- return;- }+ Debug.Write(+ "Application is already running. Only one instance of this application is allowed."+ );+ return;+ }- ServiceLocator.Provider = BuildServiceProvider();+ ServiceLocator.Provider = BuildServiceProvider();- var startup = ServiceLocator.Provider.GetRequiredService<Startup>();- startup.Run();- Application.Run();- }+ var startup = ServiceLocator.Provider.GetRequiredService<Startup>();+ startup.Run();+ Application.Run();}private static ServiceProvider BuildServiceProvider()diff --git a/GlazeWM.Bootstrapper/Startup.cs b/GlazeWM.Bootstrapper/Startup.csindex 4eeb63d0..bfc5f672 100644--- a/GlazeWM.Bootstrapper/Startup.cs+++ b/GlazeWM.Bootstrapper/Startup.cs@@ -20,17 +20,17 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Bootstrapper{- class Startup+ internal class Startup{- private Bus _bus;- private MonitorService _monitorService;- private KeybindingService _keybindingService;- private WindowEventService _windowEventService;- private WindowService _windowService;- private BarService _barService;- private WorkspaceService _workspaceService;- private SystemTrayService _systemTrayService;- private SystemEventService _systemEventService;+ private readonly Bus _bus;+ private readonly MonitorService _monitorService;+ private readonly KeybindingService _keybindingService;+ private readonly WindowEventService _windowEventService;+ private readonly WindowService _windowService;+ private readonly BarService _barService;+ private readonly WorkspaceService _workspaceService;+ private readonly SystemTrayService _systemTrayService;+ private readonly SystemEventService _systemEventService;public Startup(Bus bus,@@ -58,7 +58,7 @@ namespace GlazeWM.Bootstrapperpublic void Run(){// Set the process-default DPI awareness.- SetProcessDpiAwarenessContext(DpiAwarenessContext.Context_PerMonitorAwareV2);+ _ = SetProcessDpiAwarenessContext(DpiAwarenessContext.Context_PerMonitorAwareV2);// Launch bar WPF application. Spawns bar window when monitors are added, so the service needs// to be initialized before populating initial state.@@ -80,7 +80,7 @@ namespace GlazeWM.Bootstrapper_systemTrayService.AddToSystemTray();_bus.Events.Where(@event => @event is ApplicationExitingEvent)- .Subscribe((@event) => OnApplicationExit());+ .Subscribe(_ => OnApplicationExit());}/// <summary>@@ -97,7 +97,7 @@ namespace GlazeWM.Bootstrapper_bus.Invoke(new AddMonitorCommand(screen));// Add initial windows to the tree.- foreach (var windowHandle in _windowService.GetAllWindowHandles())+ foreach (var windowHandle in WindowService.GetAllWindowHandles()){// Register appbar windows.if (_windowService.IsHandleAppBar(windowHandle))@@ -129,13 +129,12 @@ namespace GlazeWM.Bootstrapper// `GetForegroundWindow` might return a handle that is not in the tree. In that case, set// focus to an arbitrary window. If there are no manageable windows in the tree, set focus to// an arbitrary workspace.- Container containerToFocus =+ var containerToFocus =_windowService.GetWindows().FirstOrDefault() as Container- ?? _workspaceService.GetActiveWorkspaces().FirstOrDefault() as Container;+ ?? _workspaceService.GetActiveWorkspaces().FirstOrDefault();if (containerToFocus is Window)_bus.Invoke(new FocusWindowCommand(containerToFocus as Window));-else if (containerToFocus is Workspace)_bus.Invoke(new FocusWorkspaceCommand((containerToFocus as Workspace).Name));}diff --git a/GlazeWM.Domain/Common/CommandHandlers/ExitApplicationHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/ExitApplicationHandler.csindex 66fb10c6..e84ac2bb 100644--- a/GlazeWM.Domain/Common/CommandHandlers/ExitApplicationHandler.cs+++ b/GlazeWM.Domain/Common/CommandHandlers/ExitApplicationHandler.cs@@ -4,9 +4,9 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Common.CommandHandlers{- class ExitApplicationHandler : ICommandHandler<ExitApplicationCommand>+ internal class ExitApplicationHandler : ICommandHandler<ExitApplicationCommand>{- private Bus _bus;+ private readonly Bus _bus;public ExitApplicationHandler(Bus bus){diff --git a/GlazeWM.Domain/Common/Enums/Direction.cs b/GlazeWM.Domain/Common/Enums/Direction.csindex 16997870..ee1c4b03 100644--- a/GlazeWM.Domain/Common/Enums/Direction.cs+++ b/GlazeWM.Domain/Common/Enums/Direction.cs@@ -15,20 +15,17 @@ namespace GlazeWM.Domain.Common.Enums/// <summary>/// Get the inverse of a given direction (eg. `Direction.UP` is the inverse of `Direction.DOWN`)./// </summary>+ /// <exception cref="ArgumentOutOfRangeException"></exception>public static Direction Inverse(this Direction direction){- switch (direction)+ return direction switch{- case Direction.UP:- return Direction.DOWN;- case Direction.DOWN:- return Direction.UP;- case Direction.LEFT:- return Direction.RIGHT;- case Direction.RIGHT:- return Direction.LEFT;- default: throw new ArgumentOutOfRangeException();- }+ Direction.UP => Direction.DOWN,+ Direction.DOWN => Direction.UP,+ Direction.LEFT => Direction.RIGHT,+ Direction.RIGHT => Direction.LEFT,+ _ => throw new ArgumentOutOfRangeException(nameof(direction)),+ };}/// <summary>@@ -37,7 +34,7 @@ namespace GlazeWM.Domain.Common.Enums/// </summary>public static Layout GetCorrespondingLayout(this Direction direction){- return (direction == Direction.LEFT || direction == Direction.RIGHT)+ return (direction is Direction.LEFT or Direction.RIGHT)? Layout.HORIZONTAL : Layout.VERTICAL;}}diff --git a/GlazeWM.Domain/Containers/CommandHandlers/AttachAndResizeContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/AttachAndResizeContainerHandler.csindex 17339a8c..e290288b 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/AttachAndResizeContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/AttachAndResizeContainerHandler.cs@@ -5,9 +5,9 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class AttachAndResizeContainerHandler : ICommandHandler<AttachAndResizeContainerCommand>+ internal class AttachAndResizeContainerHandler : ICommandHandler<AttachAndResizeContainerCommand>{- private Bus _bus;+ private readonly Bus _bus;public AttachAndResizeContainerHandler(Bus bus){@@ -20,22 +20,21 @@ namespace GlazeWM.Domain.Containers.CommandHandlersvar targetParent = command.TargetParent;var targetIndex = command.TargetIndex;- if (!(childToAdd is IResizable))+ if (childToAdd is not IResizable)throw new Exception("Cannot resize a non-resizable container. This is a bug.");_bus.Invoke(new AttachContainerCommand(childToAdd, targetParent, targetIndex));var resizableSiblings = childToAdd.Siblings.Where(container => container is IResizable);- double defaultPercent = 1.0 / (resizableSiblings.Count() + 1);+ var defaultPercent = 1.0 / (resizableSiblings.Count() + 1);(childToAdd as IResizable).SizePercentage = defaultPercent;var sizePercentageDecrement = defaultPercent / resizableSiblings.Count();// Adjust `SizePercentage` of the added container's siblings.foreach (var sibling in resizableSiblings)- (sibling as IResizable).SizePercentage =- (sibling as IResizable).SizePercentage - sizePercentageDecrement;+ (sibling as IResizable).SizePercentage -= sizePercentageDecrement;return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.csindex 868a2944..8f7cea79 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/AttachContainerHandler.cs@@ -4,9 +4,9 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class AttachContainerHandler : ICommandHandler<AttachContainerCommand>+ internal class AttachContainerHandler : ICommandHandler<AttachContainerCommand>{- private ContainerService _containerService;+ private readonly ContainerService _containerService;public AttachContainerHandler(ContainerService containerService){diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.csindex 4b871266..2e9041b4 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs@@ -7,21 +7,15 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class ChangeContainerLayoutHandler : ICommandHandler<ChangeContainerLayoutCommand>+ internal class ChangeContainerLayoutHandler : ICommandHandler<ChangeContainerLayoutCommand>{- private Bus _bus;- private ContainerService _containerService;- private WindowService _windowService;-- public ChangeContainerLayoutHandler(- Bus bus,- ContainerService containerService,- WindowService windowService- )+ private readonly Bus _bus;+ private readonly ContainerService _containerService;++ public ChangeContainerLayoutHandler(Bus bus, ContainerService containerService){_bus = bus;_containerService = containerService;- _windowService = windowService;}public CommandResponse Handle(ChangeContainerLayoutCommand command)@@ -31,7 +25,6 @@ namespace GlazeWM.Domain.Containers.CommandHandlersif (container is TilingWindow)ChangeWindowLayout(container as Window, newLayout);-else if (container is Workspace)ChangeWorkspaceLayout(container as Workspace, newLayout);@@ -90,7 +83,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers{var childSplitContainer = child as SplitContainer;- if (childSplitContainer == null || childSplitContainer.Layout != newLayout)+ if (childSplitContainer?.Layout != newLayout)continue;_bus.Invoke(new FlattenSplitContainerCommand(childSplitContainer));diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.csindex 6cf056a0..25eb9df5 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ChangeFocusedContainerLayoutHandler.cs@@ -3,10 +3,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class ChangeFocusedContainerLayoutHandler : ICommandHandler<ChangeFocusedContainerLayoutCommand>+ internal class ChangeFocusedContainerLayoutHandler : ICommandHandler<ChangeFocusedContainerLayoutCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public ChangeFocusedContainerLayoutHandler(Bus bus, ContainerService containerService){diff --git a/GlazeWM.Domain/Containers/CommandHandlers/DetachAndResizeContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/DetachAndResizeContainerHandler.csindex 64d976ee..59b6c252 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/DetachAndResizeContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/DetachAndResizeContainerHandler.cs@@ -6,9 +6,9 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class DetachAndResizeContainerHandler : ICommandHandler<DetachAndResizeContainerCommand>+ internal class DetachAndResizeContainerHandler : ICommandHandler<DetachAndResizeContainerCommand>{- private Bus _bus;+ private readonly Bus _bus;public DetachAndResizeContainerHandler(Bus bus){@@ -21,11 +21,11 @@ namespace GlazeWM.Domain.Containers.CommandHandlersvar parent = childToRemove.Parent;var grandparent = parent.Parent;- if (!(childToRemove is IResizable))+ if (childToRemove is not IResizable)throw new Exception("Cannot resize a non-resizable container. This is a bug.");- var isEmptySplitContainer = parent is SplitContainer && parent.Children.Count() == 1- && !(parent is Workspace);+ var isEmptySplitContainer = parent is SplitContainer && parent.Children.Count == 1+ && parent is not Workspace;// Get the freed up space after container is detached.var availableSizePercentage = isEmptySplitContainer@@ -43,8 +43,9 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// Adjust `SizePercentage` of the siblings of the removed container.foreach (var containerToResize in containersToResize)- (containerToResize as IResizable).SizePercentage =- (containerToResize as IResizable).SizePercentage + sizePercentageIncrement;+ {+ ((IResizable)containerToResize).SizePercentage += sizePercentageIncrement;+ }return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.csindex 40d710ad..b14e34bb 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/DetachContainerHandler.cs@@ -5,10 +5,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class DetachContainerHandler : ICommandHandler<DetachContainerCommand>+ internal class DetachContainerHandler : ICommandHandler<DetachContainerCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public DetachContainerHandler(Bus bus, ContainerService containerService){@@ -29,7 +29,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlersparent.ChildFocusOrder.Remove(childToRemove);var isEmptySplitContainer = parent is SplitContainer && !parent.HasChildren()- && !(parent is Workspace);+ && parent is not Workspace;// If the parent of the removed child is an empty split container, detach the split container// as well.diff --git a/GlazeWM.Domain/Containers/CommandHandlers/FlattenSplitContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/FlattenSplitContainerHandler.csindex 68bea860..42f7cf04 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/FlattenSplitContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/FlattenSplitContainerHandler.cs@@ -5,10 +5,10 @@ using GlazeWM.Infrastructure.Utils;namespace GlazeWM.Domain.Containers.CommandHandlers{- class FlattenSplitContainerHandler : ICommandHandler<FlattenSplitContainerCommand>+ internal class FlattenSplitContainerHandler : ICommandHandler<FlattenSplitContainerCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public FlattenSplitContainerHandler(Bus bus, ContainerService containerService){diff --git a/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.csindex 6e448bd2..587b8ce0 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.cs@@ -10,11 +10,11 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class FocusInDirectionHandler : ICommandHandler<FocusInDirectionCommand>+ internal class FocusInDirectionHandler : ICommandHandler<FocusInDirectionCommand>{- private Bus _bus;- private ContainerService _containerService;- private MonitorService _monitorService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;+ private readonly MonitorService _monitorService;public FocusInDirectionHandler(Bus bus, ContainerService containerService, MonitorService monitorService){@@ -30,7 +30,6 @@ namespace GlazeWM.Domain.Containers.CommandHandlersif (focusedContainer is FloatingWindow)FocusFromFloatingWindow(focusedContainer, direction);-elseFocusFromTilingContainer(focusedContainer, direction);@@ -40,7 +39,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlersprivate void FocusFromFloatingWindow(Container focusedContainer, Direction direction){// Cannot focus vertically from a floating window.- if (direction == Direction.UP || direction == Direction.DOWN)+ if (direction is Direction.UP or Direction.DOWN)return;var focusTarget = direction == Direction.RIGHT@@ -65,7 +64,6 @@ namespace GlazeWM.Domain.Containers.CommandHandlersif (focusTarget is Window)_bus.Invoke(new FocusWindowCommand(focusTarget as Window));-else if (focusTarget is Workspace)_bus.Invoke(new FocusWorkspaceCommand((focusTarget as Workspace).Name));}@@ -79,7 +77,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// If a suitable focus target isn't found in the current workspace, attempt to find// a workspace in the given direction.- return GetFocusTargetOutsideWorkspace(focusedContainer, direction);+ return GetFocusTargetOutsideWorkspace(direction);}/// <summary>@@ -93,7 +91,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// Traverse upwards from the focused container. Stop searching when a workspace is// encountered.- while (!(focusReference is Workspace))+ while (focusReference is not Workspace){var parent = focusReference.Parent as SplitContainer;@@ -103,7 +101,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlerscontinue;}- var focusTarget = direction == Direction.UP || direction == Direction.LEFT+ var focusTarget = direction is Direction.UP or Direction.LEFT? focusReference.GetPreviousSiblingOfType(typeof(IResizable)): focusReference.GetNextSiblingOfType(typeof(IResizable));@@ -122,7 +120,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers/// <summary>/// Attempt to find a focus target in a different workspace than the focused workspace./// </summary>- private Container GetFocusTargetOutsideWorkspace(Container focusedContainer, Direction direction)+ private Container GetFocusTargetOutsideWorkspace(Direction direction){var focusedMonitor = _monitorService.GetFocusedMonitor();diff --git a/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.csindex 94250dbe..feffa4f2 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/MoveContainerWithinTreeHandler.cs@@ -6,15 +6,13 @@ using GlazeWM.Infrastructure.Utils;namespace GlazeWM.Domain.Containers.CommandHandlers{- class MoveContainerWithinTreeHandler : ICommandHandler<MoveContainerWithinTreeCommand>+ internal class MoveContainerWithinTreeHandler : ICommandHandler<MoveContainerWithinTreeCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;- public MoveContainerWithinTreeHandler(Bus bus, ContainerService containerService)+ public MoveContainerWithinTreeHandler(Bus bus){_bus = bus;- _containerService = containerService;}public CommandResponse Handle(MoveContainerWithinTreeCommand command)@@ -24,12 +22,12 @@ namespace GlazeWM.Domain.Containers.CommandHandlersvar targetIndex = command.TargetIndex;var shouldAdjustSize = command.ShouldAdjustSize;- if (shouldAdjustSize && !(containerToMove is IResizable))+ if (shouldAdjustSize && containerToMove is not IResizable)throw new Exception("Cannot resize a non-resizable container. This is a bug.");// Get lowest common ancestor (LCA) between `containerToMove` and `targetParent`. This could// be the `targetParent` itself.- var lowestCommonAncestor = _containerService.GetLowestCommonAncestor(+ var lowestCommonAncestor = ContainerService.GetLowestCommonAncestor(containerToMove,targetParent);@@ -49,7 +47,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// Get whether the container is the focused descendant in its original subtree.var isFocusedDescendant = containerToMove == containerToMoveAncestor- ? true : containerToMoveAncestor.LastFocusedDescendant == containerToMove;+ || containerToMoveAncestor.LastFocusedDescendant == containerToMove;var targetParentAncestor = targetParent.SelfAndAncestors.First(ancestor => ancestor.Parent == lowestCommonAncestor);diff --git a/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.csindex 310d1438..e1adc742 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs@@ -7,9 +7,9 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Containers.CommandHandlers{- class RedrawContainersHandler : ICommandHandler<RedrawContainersCommand>+ internal class RedrawContainersHandler : ICommandHandler<RedrawContainersCommand>{- private ContainerService _containerService;+ private readonly ContainerService _containerService;public RedrawContainersHandler(ContainerService containerService){@@ -28,7 +28,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// Get windows that are minimized/maximized and shouldn't be.var windowsToRestore = windowsToRedraw.Where(- window => !(window is MinimizedWindow) && window.HasWindowStyle(WS.WS_MAXIMIZE | WS.WS_MINIMIZE)+ window => window is not MinimizedWindow && window.HasWindowStyle(WS.WS_MAXIMIZE | WS.WS_MINIMIZE)).ToList();@@ -63,7 +63,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlersreturn CommandResponse.Ok;}- private void SetWindowPosition(Window window, SWP flags)+ private static void SetWindowPosition(Window window, SWP flags){if (window is TilingWindow){diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.csindex 02922585..a4816bf4 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs@@ -6,9 +6,9 @@ using GlazeWM.Infrastructure.Utils;namespace GlazeWM.Domain.Containers.CommandHandlers{- class ReplaceContainerHandler : ICommandHandler<ReplaceContainerCommand>+ internal class ReplaceContainerHandler : ICommandHandler<ReplaceContainerCommand>{- private ContainerService _containerService;+ private readonly ContainerService _containerService;public ReplaceContainerHandler(ContainerService containerService){@@ -33,7 +33,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers(containerToReplace as IResizable).SizePercentage;// Adjust `SizePercentage` of siblings.- if (containerToReplace is IResizable && !(replacementContainer is IResizable))+ if (containerToReplace is IResizable && replacementContainer is not IResizable){// Get the freed up space after container is detached.var availableSizePercentage = (containerToReplace as IResizable).SizePercentage;@@ -45,8 +45,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// Adjust `SizePercentage` of the siblings of the removed container.foreach (var sibling in resizableSiblings)- (sibling as IResizable).SizePercentage =- (sibling as IResizable).SizePercentage + sizePercentageIncrement;+ (sibling as IResizable).SizePercentage += sizePercentageIncrement;}// Replace the container at the given index.diff --git a/GlazeWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.csindex e1e476ec..356eea61 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/SetFocusedDescendantHandler.cs@@ -4,12 +4,8 @@ using GlazeWM.Infrastructure.Utils;namespace GlazeWM.Domain.Containers.CommandHandlers{- class SetFocusedDescendantHandler : ICommandHandler<SetFocusedDescendantCommand>+ internal class SetFocusedDescendantHandler : ICommandHandler<SetFocusedDescendantCommand>{- public SetFocusedDescendantHandler()- {- }-public CommandResponse Handle(SetFocusedDescendantCommand command){var focusedDescendant = command.FocusedDescendant;diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.csindex f61ed915..28610e56 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs@@ -7,11 +7,11 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.CommandHandlers{- class ToggleFocusModeHandler : ICommandHandler<ToggleFocusModeCommand>+ internal class ToggleFocusModeHandler : ICommandHandler<ToggleFocusModeCommand>{- private Bus _bus;- private ContainerService _containerService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;+ private readonly WorkspaceService _workspaceService;public ToggleFocusModeHandler(Bus bus, ContainerService containerService, WorkspaceService workspaceService){@@ -28,13 +28,12 @@ namespace GlazeWM.Domain.Containers.CommandHandlersvar focusedWorkspace = _workspaceService.GetFocusedWorkspace();- Window windowToFocus = null;+ Window windowToFocus;if (targetFocusMode == FocusMode.FLOATING)// Get the last focused tiling window within the workspace.windowToFocus = focusedWorkspace.LastFocusedDescendantOfType(typeof(FloatingWindow))as Window;-else// Get the last focused floating window within the workspace.windowToFocus = focusedWorkspace.LastFocusedDescendantOfType(typeof(TilingWindow))diff --git a/GlazeWM.Domain/Containers/Commands/AttachAndResizeContainerCommand.cs b/GlazeWM.Domain/Containers/Commands/AttachAndResizeContainerCommand.csindex ab8ca6dd..155fec1f 100644--- a/GlazeWM.Domain/Containers/Commands/AttachAndResizeContainerCommand.cs+++ b/GlazeWM.Domain/Containers/Commands/AttachAndResizeContainerCommand.cs@@ -8,7 +8,9 @@ namespace GlazeWM.Domain.Containers.Commandspublic Container TargetParent { get; }public int TargetIndex { get; }- // Insert child as end element if `targetIndex` is not provided.+ /// <summary>+ /// Insert child as end element if `targetIndex` is not provided.+ /// </summary>public AttachAndResizeContainerCommand(Container childToAdd, Container targetParent){ChildToAdd = childToAdd;diff --git a/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs b/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.csindex e17e83de..a4f3ac0a 100644--- a/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs+++ b/GlazeWM.Domain/Containers/Commands/AttachContainerCommand.cs@@ -8,7 +8,9 @@ namespace GlazeWM.Domain.Containers.Commandspublic Container TargetParent { get; }public int TargetIndex { get; }- // Insert child as end element if `targetIndex` is not provided.+ /// <summary>+ /// Insert child as end element if `targetIndex` is not provided.+ /// </summary>public AttachContainerCommand(Container childToAdd, Container targetParent){ChildToAdd = childToAdd;diff --git a/GlazeWM.Domain/Containers/Commands/MoveContainerWithinTreeCommand.cs b/GlazeWM.Domain/Containers/Commands/MoveContainerWithinTreeCommand.csindex d48ba463..c1e15d10 100644--- a/GlazeWM.Domain/Containers/Commands/MoveContainerWithinTreeCommand.cs+++ b/GlazeWM.Domain/Containers/Commands/MoveContainerWithinTreeCommand.cs@@ -9,7 +9,9 @@ namespace GlazeWM.Domain.Containers.Commandspublic int TargetIndex { get; }public bool ShouldAdjustSize { get; }- // Insert child as end element if `targetIndex` is not provided.+ /// <summary>+ /// Insert child as end element if `targetIndex` is not provided.+ /// </summary>public MoveContainerWithinTreeCommand(Container containerToMove, Container targetParent, bool shouldAdjustSize){ContainerToMove = containerToMove;diff --git a/GlazeWM.Domain/Containers/Commands/RedrawContainersCommand.cs b/GlazeWM.Domain/Containers/Commands/RedrawContainersCommand.csindex dc543964..2a70c3dc 100644--- a/GlazeWM.Domain/Containers/Commands/RedrawContainersCommand.cs+++ b/GlazeWM.Domain/Containers/Commands/RedrawContainersCommand.cs@@ -4,8 +4,5 @@ namespace GlazeWM.Domain.Containers.Commands{public class RedrawContainersCommand : Command{- public RedrawContainersCommand()- {- }}}diff --git a/GlazeWM.Domain/Containers/Commands/ToggleFocusModeCommand.cs b/GlazeWM.Domain/Containers/Commands/ToggleFocusModeCommand.csindex 32323fe1..e7206c1c 100644--- a/GlazeWM.Domain/Containers/Commands/ToggleFocusModeCommand.cs+++ b/GlazeWM.Domain/Containers/Commands/ToggleFocusModeCommand.cs@@ -4,8 +4,5 @@ namespace GlazeWM.Domain.Containers.Commands{public class ToggleFocusModeCommand : Command{- public ToggleFocusModeCommand()- {- }}}diff --git a/GlazeWM.Domain/Containers/Container.cs b/GlazeWM.Domain/Containers/Container.csindex ddc0caf4..a7ec23ee 100644--- a/GlazeWM.Domain/Containers/Container.cs+++ b/GlazeWM.Domain/Containers/Container.cs@@ -11,7 +11,7 @@ namespace GlazeWM.Domain.Containerspublic virtual int Width { get; set; }public virtual int X { get; set; }public virtual int Y { get; set; }- public Container Parent { get; set; } = null;+ public Container Parent { get; set; }public List<Container> Children { get; set; } = new List<Container>();/// <summary>@@ -110,9 +110,15 @@ namespace GlazeWM.Domain.Containers}}- public bool HasChildren() => Children.Count > 0;+ public bool HasChildren()+ {+ return Children.Count > 0;+ }- public bool HasSiblings() => Siblings.Count() > 0;+ public bool HasSiblings()+ {+ return Siblings.Any();+ }public WindowRect ToRectangle(){@@ -155,7 +161,7 @@ namespace GlazeWM.Domain.Containers/// </summary>public Container LastFocusedChildOfType(Type type){- return ChildFocusOrder.FirstOrDefault(+ return ChildFocusOrder.Find(container => type.IsAssignableFrom(container.GetType()));}@@ -189,7 +195,7 @@ namespace GlazeWM.Domain.Containersstack.Push(this);// Do a depth-first search using child focus order.- while (stack.Any())+ while (stack.Count > 0){var current = stack.Pop();diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.csindex ea0267fc..a01aedcf 100644--- a/GlazeWM.Domain/Containers/ContainerService.cs+++ b/GlazeWM.Domain/Containers/ContainerService.cs@@ -14,13 +14,13 @@ namespace GlazeWM.Domain.Containers/// The root node of the container tree. Monitors are the children of the root node, followed/// by workspaces, then split containers/windows./// </summary>- public Container ContainerTree = new Container();+ public Container ContainerTree = new();/// <summary>/// Containers (and their descendants) to redraw on the next invocation of/// `RedrawContainersCommand`./// </summary>- public List<Container> ContainersToRedraw = new List<Container>();+ public List<Container> ContainersToRedraw = new();/// <summary>/// The currently focused container. This can either be a `Window` or a@@ -38,7 +38,7 @@ namespace GlazeWM.Domain.Containers/// If set, this container overrides the target container to set focus to on the next/// focus window event (ie. `EVENT_SYSTEM_FOREGROUND`)./// </summary>- public Container PendingFocusContainer = null;+ public Container PendingFocusContainer;/// <summary>/// Whether the focused container of the WM is in sync with the OS. Mismatches between the@@ -55,12 +55,11 @@ namespace GlazeWM.Domain.Containersif (focusedContainer is Window)return (focusedContainer as Window).Hwnd == foregroundHandle;- else- return IntPtr.Zero == foregroundHandle;+ return IntPtr.Zero == foregroundHandle;}}- private UserConfigService _userConfigService;+ private readonly UserConfigService _userConfigService;public ContainerService(UserConfigService userConfigService){@@ -81,7 +80,8 @@ namespace GlazeWM.Domain.Containersvar innerGap = _userConfigService.UserConfig.Gaps.InnerGap;var resizableSiblings = container.SelfAndSiblingsOfType(typeof(IResizable));- return (int)((container as IResizable).SizePercentage * (parent.Width - (innerGap * (resizableSiblings.Count() - 1))));+ return (int)((container as IResizable).SizePercentage+ * (parent.Width - (innerGap * (resizableSiblings.Count() - 1))));}/// <summary>@@ -98,7 +98,8 @@ namespace GlazeWM.Domain.Containersvar innerGap = _userConfigService.UserConfig.Gaps.InnerGap;var resizableSiblings = container.SelfAndSiblingsOfType(typeof(IResizable));- return (int)((container as IResizable).SizePercentage * (parent.Height - (innerGap * (resizableSiblings.Count() - 1))));+ return (int)((container as IResizable).SizePercentage+ * (parent.Height - (innerGap * (resizableSiblings.Count() - 1))));}/// <summary>@@ -149,7 +150,7 @@ namespace GlazeWM.Domain.Containerspublic Container GetDescendantInDirection(Container originContainer, Direction direction){var isDescendable = originContainer is SplitContainer- && originContainer.ChildrenOfType(typeof(IResizable)).Count() > 0;+ && originContainer.ChildrenOfType(typeof(IResizable)).Any();if (!isDescendable)return originContainer;@@ -161,13 +162,11 @@ namespace GlazeWM.Domain.ContainersoriginContainer.LastFocusedChildOfType(typeof(IResizable)),direction);-- if (direction == Direction.UP || direction == Direction.LEFT)+ else if (direction is Direction.UP or Direction.LEFT)return GetDescendantInDirection(originContainer.ChildrenOfType(typeof(IResizable)).First(),direction);-elsereturn GetDescendantInDirection(originContainer.ChildrenOfType(typeof(IResizable)).Last(),@@ -179,7 +178,7 @@ namespace GlazeWM.Domain.Containers/// Get the lowest container in the tree that has both `containerA` and `containerB` as/// descendants./// </summary>- public Container GetLowestCommonAncestor(Container containerA, Container containerB)+ public static Container GetLowestCommonAncestor(Container containerA, Container containerB){var ancestorA = containerA;diff --git a/GlazeWM.Domain/Containers/SplitContainer.cs b/GlazeWM.Domain/Containers/SplitContainer.csindex 17fb46d4..b028d208 100644--- a/GlazeWM.Domain/Containers/SplitContainer.cs+++ b/GlazeWM.Domain/Containers/SplitContainer.cs@@ -10,7 +10,7 @@ namespace GlazeWM.Domain.Containerspublic double SizePercentage { get; set; } = 1;- private ContainerService _containerService = ServiceLocator.Provider.GetRequiredService<ContainerService>();+ private readonly ContainerService _containerService = ServiceLocator.Provider.GetRequiredService<ContainerService>();public override int Width => _containerService.CalculateWidthOfResizableContainer(this);diff --git a/GlazeWM.Domain/GlazeWM.Domain.csproj b/GlazeWM.Domain/GlazeWM.Domain.csprojindex ada138ab..0a18b56a 100644--- a/GlazeWM.Domain/GlazeWM.Domain.csproj+++ b/GlazeWM.Domain/GlazeWM.Domain.csproj@@ -1,9 +1,8 @@-<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">+<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Library</OutputType>- <TargetFramework>netcoreapp3.1</TargetFramework>- <RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>+ <TargetFramework>net6.0-windows</TargetFramework><UseWindowsForms>true</UseWindowsForms><ApplicationIcon /><StartupObject />@@ -13,13 +12,13 @@<ItemGroup><PackageReferenceInclude="Microsoft.Extensions.DependencyInjection"- Version="3.1.1" />+ Version="6.0.0" /><PackageReferenceInclude="Newtonsoft.Json"Version="13.0.1" /><PackageReferenceInclude="System.Reactive"- Version="4.3.2" />+ Version="5.0.0" /><PackageReferenceInclude="YamlDotNet"Version="8.1.0" />diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.csindex 463218bc..2395a815 100644--- a/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs+++ b/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs@@ -6,14 +6,15 @@ using GlazeWM.Domain.Monitors.Events;using GlazeWM.Domain.Workspaces;using GlazeWM.Domain.Workspaces.Commands;using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.Exceptions;namespace GlazeWM.Domain.Monitors.CommandHandlers{- class AddMonitorHandler : ICommandHandler<AddMonitorCommand>+ internal class AddMonitorHandler : ICommandHandler<AddMonitorCommand>{- private Bus _bus;- private ContainerService _containerService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;+ private readonly WorkspaceService _workspaceService;public AddMonitorHandler(Bus bus, ContainerService containerService, WorkspaceService workspaceService){diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.csindex 69beaf38..1affc75b 100644--- a/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs+++ b/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs@@ -10,27 +10,24 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Monitors.CommandHandlers{- class RefreshMonitorStateHandler : ICommandHandler<RefreshMonitorStateCommand>+ internal class RefreshMonitorStateHandler : ICommandHandler<RefreshMonitorStateCommand>{- private Bus _bus;- private MonitorService _monitorService;- private ContainerService _containerService;- private WindowService _windowService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly MonitorService _monitorService;+ private readonly ContainerService _containerService;+ private readonly WindowService _windowService;public RefreshMonitorStateHandler(Bus bus,MonitorService monitorService,ContainerService containerService,- WindowService windowService,- WorkspaceService workspaceService+ WindowService windowService){_bus = bus;_monitorService = monitorService;_containerService = containerService;_windowService = windowService;- _workspaceService = workspaceService;}public CommandResponse Handle(RefreshMonitorStateCommand command)@@ -66,7 +63,9 @@ namespace GlazeWM.Domain.Monitors.CommandHandlers// Remove any monitors that no longer exist and move their workspaces to other monitors.// TODO: Verify that this works with "Duplicate these displays" or "Show only X" settings.foreach (var monitor in monitorsToRemove.ToList())+ {_bus.Invoke(new RemoveMonitorCommand(monitor));+ }foreach (var window in _windowService.GetWindows()){@@ -76,7 +75,7 @@ namespace GlazeWM.Domain.Monitors.CommandHandlers// Need to update floating position of moved windows when a monitor is disconnected or if// the primary display is changed. The primary display dictates the position of 0,0.- var parentWorkspace = _workspaceService.GetWorkspaceFromChildContainer(window);+ var parentWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(window);window.FloatingPlacement =window.FloatingPlacement.TranslateToCenter(parentWorkspace.ToRectangle());}@@ -88,7 +87,7 @@ namespace GlazeWM.Domain.Monitors.CommandHandlersreturn CommandResponse.Ok;}- private bool IsMonitorActive(Monitor monitor)+ private static bool IsMonitorActive(Monitor monitor){return Screen.AllScreens.Any(screen => screen.DeviceName == monitor.DeviceName);}diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.csindex cc93feb8..bc30083a 100644--- a/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.cs+++ b/GlazeWM.Domain/Monitors/CommandHandlers/RemoveMonitorHandler.cs@@ -10,10 +10,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Monitors.CommandHandlers{- class RemoveMonitorHandler : ICommandHandler<RemoveMonitorCommand>+ internal class RemoveMonitorHandler : ICommandHandler<RemoveMonitorCommand>{- private Bus _bus;- private MonitorService _monitorService;+ private readonly Bus _bus;+ private readonly MonitorService _monitorService;public RemoveMonitorHandler(Bus bus, MonitorService monitorService){@@ -42,9 +42,7 @@ namespace GlazeWM.Domain.Monitors.CommandHandlers_bus.Invoke(new MoveContainerWithinTreeCommand(workspace, targetMonitor, false));// Get windows of the moved workspace.- var windows = workspace.Descendants- .Where(descendant => descendant is Window)- .Cast<Window>();+ var windows = workspace.Descendants.OfType<Window>();// Update workspaces displayed in bar window.// TODO: Consider creating separate event `WorkspaceMovedEvent`.diff --git a/GlazeWM.Domain/Monitors/Commands/RefreshMonitorStateCommand.cs b/GlazeWM.Domain/Monitors/Commands/RefreshMonitorStateCommand.csindex 730a0b61..e94f48fe 100644--- a/GlazeWM.Domain/Monitors/Commands/RefreshMonitorStateCommand.cs+++ b/GlazeWM.Domain/Monitors/Commands/RefreshMonitorStateCommand.cs@@ -4,8 +4,5 @@ namespace GlazeWM.Domain.Monitors.Commands{public class RefreshMonitorStateCommand : Command{- public RefreshMonitorStateCommand()- {- }}}diff --git a/GlazeWM.Domain/Monitors/EventHandlers/DisplaySettingsChangedHandler.cs b/GlazeWM.Domain/Monitors/EventHandlers/DisplaySettingsChangedHandler.csindex f20c7d8f..c801a8f1 100644--- a/GlazeWM.Domain/Monitors/EventHandlers/DisplaySettingsChangedHandler.cs+++ b/GlazeWM.Domain/Monitors/EventHandlers/DisplaySettingsChangedHandler.cs@@ -4,9 +4,9 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Monitors.EventHandlers{- class DisplaySettingsChangedHandler : IEventHandler<DisplaySettingsChangedEvent>+ internal class DisplaySettingsChangedHandler : IEventHandler<DisplaySettingsChangedEvent>{- private Bus _bus;+ private readonly Bus _bus;public DisplaySettingsChangedHandler(Bus bus){diff --git a/GlazeWM.Domain/Monitors/Events/MonitorAddedEvent.cs b/GlazeWM.Domain/Monitors/Events/MonitorAddedEvent.csindex 5c389bf4..3c4c2397 100644--- a/GlazeWM.Domain/Monitors/Events/MonitorAddedEvent.cs+++ b/GlazeWM.Domain/Monitors/Events/MonitorAddedEvent.cs@@ -1,5 +1,4 @@using GlazeWM.Infrastructure.Bussing;-using System;namespace GlazeWM.Domain.Monitors.Events{diff --git a/GlazeWM.Domain/Monitors/Monitor.cs b/GlazeWM.Domain/Monitors/Monitor.csindex ee986b50..539ba82d 100644--- a/GlazeWM.Domain/Monitors/Monitor.cs+++ b/GlazeWM.Domain/Monitors/Monitor.cs@@ -1,7 +1,5 @@using GlazeWM.Domain.Containers;using GlazeWM.Domain.Workspaces;-using GlazeWM.Infrastructure;-using Microsoft.Extensions.DependencyInjection;namespace GlazeWM.Domain.Monitors{@@ -15,9 +13,7 @@ namespace GlazeWM.Domain.Monitorspublic bool IsPrimary { get; set; }public Workspace DisplayedWorkspace { get; set; }- private MonitorService _monitorService =- ServiceLocator.Provider.GetRequiredService<MonitorService>();- public uint Dpi => _monitorService.GetMonitorDpi(this);+ public uint Dpi => MonitorService.GetMonitorDpi(this);public decimal ScaleFactor => decimal.Divide(Dpi, 96);public Monitor(diff --git a/GlazeWM.Domain/Monitors/MonitorService.cs b/GlazeWM.Domain/Monitors/MonitorService.csindex 2eae2f69..31406847 100644--- a/GlazeWM.Domain/Monitors/MonitorService.cs+++ b/GlazeWM.Domain/Monitors/MonitorService.cs@@ -11,7 +11,7 @@ namespace GlazeWM.Domain.Monitors{public class MonitorService{- private ContainerService _containerService;+ private readonly ContainerService _containerService;public MonitorService(ContainerService containerService){@@ -26,7 +26,7 @@ namespace GlazeWM.Domain.Monitorsreturn _containerService.ContainerTree.Children.Cast<Monitor>();}- public Monitor GetMonitorFromChildContainer(Container container)+ public static Monitor GetMonitorFromChildContainer(Container container){return container.SelfAndAncestors.OfType<Monitor>().First();}@@ -47,7 +47,7 @@ namespace GlazeWM.Domain.Monitorsreturn GetMonitorFromChildContainer(_containerService.FocusedContainer);}- public uint GetMonitorDpi(Monitor monitor)+ public static uint GetMonitorDpi(Monitor monitor){// Create a point within the monitor's dimensions.var point = new Point@@ -59,9 +59,7 @@ namespace GlazeWM.Domain.Monitors// Get a handle to the monitor.// TODO: Consider adding a `Monitor` getter for a monitor's handle.var monitorHandle = MonitorFromPoint(point, MonitorFromPointFlags.MONITOR_DEFAULTTONEAREST);-- uint dpiX, dpiY;- GetDpiForMonitor(monitorHandle, DpiType.Effective, out dpiX, out dpiY);+ _ = GetDpiForMonitor(monitorHandle, DpiType.Effective, out var dpiX, out _);// DPI X and Y should be equivalent, so it's arbitrary which to return.return dpiX;@@ -70,7 +68,7 @@ namespace GlazeWM.Domain.Monitors/// <summary>/// Whether there is a difference in DPI between two containers./// </summary>- public bool HasDpiDifference(Container firstContainer, Container secondContainer)+ public static bool HasDpiDifference(Container firstContainer, Container secondContainer){var firstMonitor = firstContainer is Monitor ?firstContainer as Monitor : GetMonitorFromChildContainer(firstContainer);@@ -86,7 +84,6 @@ namespace GlazeWM.Domain.Monitors/// </summary>/// <param name="direction">Direction to search in.</param>/// <param name="originMonitor">The monitor to search from.</param>- /// <returns></returns>public Monitor GetMonitorInDirection(Direction direction, Monitor originMonitor){Monitor monitorInDirection = null;diff --git a/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs b/GlazeWM.Domain/UserConfigs/BarComponentConfig.csindex 171a1efc..4d1626f8 100644--- a/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs+++ b/GlazeWM.Domain/UserConfigs/BarComponentConfig.cs@@ -12,22 +12,22 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Fallback to bar background config if unset./// </summary>- public string Background { get; set; } = null;+ public string Background { get; set; }/// <summary>/// Fallback to bar foreground config if unset./// </summary>- public string Foreground { get; set; } = null;+ public string Foreground { get; set; }/// <summary>/// Fallback to bar font family config if unset./// </summary>- public string FontFamily { get; set; } = null;+ public string FontFamily { get; set; }/// <summary>/// Fallback to bar font size config if unset./// </summary>- public string FontSize { get; set; } = null;+ public string FontSize { get; set; }public string BorderColor { get; set; } = "blue";diff --git a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.csindex 69457e0e..895b1831 100644--- a/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs+++ b/GlazeWM.Domain/UserConfigs/BarComponentConfigConverter.cs@@ -6,7 +6,10 @@ namespace GlazeWM.Domain.UserConfigs{public class BarComponentConfigConverter : JsonConverter{- public override bool CanConvert(Type type) => type.IsAssignableFrom(typeof(BarComponentConfig));+ public override bool CanConvert(Type objectType)+ {+ return objectType.IsAssignableFrom(typeof(BarComponentConfig));+ }public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer){@@ -30,6 +33,7 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Serializing is not needed, so it's fine to leave it unimplemented./// </summary>+ /// <exception cref="NotImplementedException"></exception>public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer){throw new NotImplementedException();diff --git a/GlazeWM.Domain/UserConfigs/BarConfig.cs b/GlazeWM.Domain/UserConfigs/BarConfig.csindex f7c36f26..83c508ef 100644--- a/GlazeWM.Domain/UserConfigs/BarConfig.cs+++ b/GlazeWM.Domain/UserConfigs/BarConfig.cs@@ -6,7 +6,7 @@ namespace GlazeWM.Domain.UserConfigspublic class BarConfig{public uint Height { get; set; } = 30;-+public BarPosition Position { get; set; } = BarPosition.Top;public double Opacity { get; set; } = 1.0;diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.csindex 62b2d15d..6c9a6fe9 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/EvaluateUserConfigHandler.cs@@ -1,6 +1,6 @@using GlazeWM.Domain.UserConfigs.Commands;using GlazeWM.Infrastructure.Bussing;-using GlazeWM.Infrastructure.WindowsApi;+using GlazeWM.Infrastructure.Exceptions;using GlazeWM.Infrastructure.Yaml;using Newtonsoft.Json;using System;@@ -11,24 +11,26 @@ using System.Windows.Forms;namespace GlazeWM.Domain.UserConfigs.CommandHandlers{- class EvaluateUserConfigHandler : ICommandHandler<EvaluateUserConfigCommand>+ internal class EvaluateUserConfigHandler : ICommandHandler<EvaluateUserConfigCommand>{- private Bus _bus;- private UserConfigService _userConfigService;- private KeybindingService _keybindingService;- private YamlDeserializationService _yamlDeserializationService;-- public EvaluateUserConfigHandler(Bus bus, UserConfigService userConfigService, KeybindingService keybindingService, YamlDeserializationService yamlDeserializationService)+ private readonly Bus _bus;+ private readonly UserConfigService _userConfigService;+ private readonly YamlDeserializationService _yamlDeserializationService;++ public EvaluateUserConfigHandler(+ Bus bus,+ UserConfigService userConfigService,+ YamlDeserializationService yamlDeserializationService+ ){_bus = bus;_userConfigService = userConfigService;- _keybindingService = keybindingService;_yamlDeserializationService = yamlDeserializationService;}public CommandResponse Handle(EvaluateUserConfigCommand command){- UserConfig deserializedConfig = null;+ UserConfig deserializedConfig;try{@@ -57,7 +59,7 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlersreturn CommandResponse.Ok;}- private void InitializeSampleUserConfig(string userConfigPath)+ private static void InitializeSampleUserConfig(string userConfigPath){// Fix any inconsistencies in directory delimiters.var normalizedUserConfigPath = Path.GetFullPath(new Uri(userConfigPath).LocalPath);@@ -72,20 +74,17 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlersthrow new FatalUserException("Cannot start the app without a configuration file.");var assembly = Assembly.GetEntryAssembly();- var sampleConfigResourceName = "GlazeWM.Bootstrapper.sample-config.yaml";+ const string sampleConfigResourceName = "GlazeWM.Bootstrapper.sample-config.yaml";// Create containing directory. Needs to be created before writing to the file.Directory.CreateDirectory(Path.GetDirectoryName(userConfigPath));// Get the embedded sample user config from the entry assembly.- using (Stream stream = assembly.GetManifestResourceStream(sampleConfigResourceName))- {- // Write the sample user config to the appropriate destination.- using (var fileStream = new FileStream(userConfigPath, FileMode.Create, FileAccess.Write))- {- stream.CopyTo(fileStream);- }- }+ using var stream = assembly.GetManifestResourceStream(sampleConfigResourceName);++ // Write the sample user config to the appropriate destination.+ using var fileStream = new FileStream(userConfigPath, FileMode.Create, FileAccess.Write);+ stream.CopyTo(fileStream);}private UserConfig DeserializeUserConfig(string userConfigPath)@@ -96,11 +95,11 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlersreturn _yamlDeserializationService.Deserialize<UserConfig>(input);}- private string FormatErrorMessage(Exception exception)+ private static string FormatErrorMessage(Exception exception){var errorMessage = "Failed to parse user config. ";- var unknownPropertyRegex = new Regex(@"Could not find member '(?<property>.*?)' on object");+ var unknownPropertyRegex = new Regex("Could not find member '(?<property>.*?)' on object");var unknownPropertyMatch = unknownPropertyRegex.Match(exception.Message);// Improve error message in case of unknown property errors.@@ -110,7 +109,6 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers// Improve error message of generic deserialization errors.else if (exception is JsonReaderException)errorMessage += $"Invalid value at property: '{(exception as JsonReaderException).Path}'.";-elseerrorMessage += exception.Message;diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.csindex 9bc8699a..e9c772e8 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs@@ -1,15 +1,14 @@-using System.Linq;using GlazeWM.Domain.UserConfigs.Commands;using GlazeWM.Infrastructure.Bussing;using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.UserConfigs.CommandHandlers{- class RegisterKeybindingsHandler : ICommandHandler<RegisterKeybindingsCommand>+ internal class RegisterKeybindingsHandler : ICommandHandler<RegisterKeybindingsCommand>{- private Bus _bus;- private KeybindingService _keybindingService;- private CommandParsingService _commandParsingService;+ private readonly Bus _bus;+ private readonly KeybindingService _keybindingService;+ private readonly CommandParsingService _commandParsingService;public RegisterKeybindingsHandler(Bus bus, KeybindingService keybindingService, CommandParsingService commandParsingService){@@ -24,12 +23,11 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers{// Parse command strings defined in keybinding config. Calling `ToList()` is necessary here,// otherwise parsing errors get delayed until keybinding is invoked instead of at startup.- var parsedCommands = keybindingConfig.CommandList.Select(commandString =>+ var parsedCommands = keybindingConfig.CommandList.ConvertAll(commandString =>{- commandString = _commandParsingService.FormatCommand(commandString);+ commandString = CommandParsingService.FormatCommand(commandString);return _commandParsingService.ParseCommand(commandString);- })- .ToList();+ });// Register all keybindings for a command sequence.foreach (var binding in keybindingConfig.BindingList)diff --git a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs b/GlazeWM.Domain/UserConfigs/CommandParsingService.csindex 97aee2bd..407f8dfc 100644--- a/GlazeWM.Domain/UserConfigs/CommandParsingService.cs+++ b/GlazeWM.Domain/UserConfigs/CommandParsingService.cs@@ -7,6 +7,7 @@ using GlazeWM.Domain.Containers.Commands;using GlazeWM.Domain.Windows.Commands;using GlazeWM.Domain.Workspaces.Commands;using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.Exceptions;using GlazeWM.Infrastructure.Utils;using GlazeWM.Infrastructure.WindowsApi;@@ -14,17 +15,18 @@ namespace GlazeWM.Domain.UserConfigs{public class CommandParsingService{- private UserConfigService _userConfigService;+ private readonly UserConfigService _userConfigService;public CommandParsingService(UserConfigService userConfigService){_userConfigService = userConfigService;}- public string FormatCommand(string commandString)+ public static string FormatCommand(string commandString){var formattedCommandString = commandString.Trim().ToLowerInvariant();- return Regex.Replace(formattedCommandString, @"\s+", " ");+ var multipleSpacesRegex = new Regex(@"\s+");+ return multipleSpacesRegex.Replace(formattedCommandString, " ");}public Command ParseCommand(string commandString)@@ -43,7 +45,7 @@ namespace GlazeWM.Domain.UserConfigs"toggle" => ParseToggleCommand(commandParts),"exit" => ParseExitCommand(commandParts),"close" => new CloseFocusedWindowCommand(),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandString)),};}catch@@ -52,13 +54,13 @@ namespace GlazeWM.Domain.UserConfigs}}- private Command ParseLayoutCommand(string[] commandParts)+ private static Command ParseLayoutCommand(string[] commandParts){return commandParts[1] switch{"vertical" => new ChangeFocusedContainerLayoutCommand(Layout.VERTICAL),"horizontal" => new ChangeFocusedContainerLayoutCommand(Layout.HORIZONTAL),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}@@ -71,7 +73,7 @@ namespace GlazeWM.Domain.UserConfigs"up" => new FocusInDirectionCommand(Direction.UP),"down" => new FocusInDirectionCommand(Direction.DOWN),"workspace" => new FocusWorkspaceCommand(ValidateWorkspaceName(commandParts[2])),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}@@ -84,11 +86,11 @@ namespace GlazeWM.Domain.UserConfigs"up" => new MoveFocusedWindowCommand(Direction.UP),"down" => new MoveFocusedWindowCommand(Direction.DOWN),"to" => new MoveFocusedWindowToWorkspaceCommand(ValidateWorkspaceName(commandParts[3])),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}- private Command ParseResizeCommand(string[] commandParts)+ private static Command ParseResizeCommand(string[] commandParts){return commandParts[1] switch{@@ -97,20 +99,20 @@ namespace GlazeWM.Domain.UserConfigs"borders" => new ResizeFocusedWindowBordersCommand(ShorthandToRectDelta(string.Join(" ", commandParts[2..]))),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}- private Command ParseSetCommand(string[] commandParts)+ private static Command ParseSetCommand(string[] commandParts){return commandParts[1] switch{"floating" => new SetFocusedWindowFloatingCommand(),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}- private Command ParseToggleCommand(string[] commandParts)+ private static Command ParseToggleCommand(string[] commandParts){return commandParts[1] switch{@@ -118,18 +120,18 @@ namespace GlazeWM.Domain.UserConfigs"focus" => commandParts[2] switch{"mode" => new ToggleFocusModeCommand(),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),},- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}- private Command ParseExitCommand(string[] commandParts)+ private static Command ParseExitCommand(string[] commandParts){return commandParts[1] switch{"wm" => new ExitApplicationCommand(),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(commandParts)),};}@@ -137,29 +139,30 @@ namespace GlazeWM.Domain.UserConfigs/// Checks whether a workspace exists with the given name./// </summary>/// <returns>The workspace name if valid.</returns>+ /// <exception cref="ArgumentException"></exception>private string ValidateWorkspaceName(string workspaceName){var workspaceConfig = _userConfigService.GetWorkspaceConfigByName(workspaceName);if (workspaceConfig == null)- throw new ArgumentException();+ throw new ArgumentException(null, nameof(workspaceName));return workspaceName;}- private RectDelta ShorthandToRectDelta(string shorthand)+ private static RectDelta ShorthandToRectDelta(string shorthand){var shorthandParts = shorthand.Split(" ").Select(shorthandPart => UnitsHelper.TrimUnits(shorthandPart)).ToList();- return shorthandParts.Count() switch+ return shorthandParts.Count switch{1 => new RectDelta(shorthandParts[0], shorthandParts[0], shorthandParts[0], shorthandParts[0]),2 => new RectDelta(shorthandParts[1], shorthandParts[0], shorthandParts[1], shorthandParts[0]),3 => new RectDelta(shorthandParts[1], shorthandParts[0], shorthandParts[1], shorthandParts[2]),4 => new RectDelta(shorthandParts[3], shorthandParts[0], shorthandParts[1], shorthandParts[2]),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(shorthand)),};}}diff --git a/GlazeWM.Domain/UserConfigs/UserConfig.cs b/GlazeWM.Domain/UserConfigs/UserConfig.csindex a8435efd..8ec84a0e 100644--- a/GlazeWM.Domain/UserConfigs/UserConfig.cs+++ b/GlazeWM.Domain/UserConfigs/UserConfig.cs@@ -8,10 +8,10 @@ namespace GlazeWM.Domain.UserConfigspublic BarConfig Bar { get; set; } = new BarConfig();- public List<WorkspaceConfig> Workspaces = new List<WorkspaceConfig>();+ public List<WorkspaceConfig> Workspaces = new();- public List<WindowRuleConfig> WindowRules = new List<WindowRuleConfig>();+ public List<WindowRuleConfig> WindowRules = new();- public List<KeybindingConfig> Keybindings = new List<KeybindingConfig>();+ public List<KeybindingConfig> Keybindings = new();}}diff --git a/GlazeWM.Domain/UserConfigs/UserConfigService.cs b/GlazeWM.Domain/UserConfigs/UserConfigService.csindex 9cc52a90..332cf898 100644--- a/GlazeWM.Domain/UserConfigs/UserConfigService.cs+++ b/GlazeWM.Domain/UserConfigs/UserConfigService.cs@@ -8,7 +8,7 @@ namespace GlazeWM.Domain.UserConfigs{public class UserConfigService{- public UserConfig UserConfig { get; set; } = null;+ public UserConfig UserConfig { get; set; }/// <summary>/// Path to the user's config file.@@ -124,7 +124,7 @@ namespace GlazeWM.Domain.UserConfigspublic WorkspaceConfig GetWorkspaceConfigByName(string workspaceName){- return UserConfig.Workspaces.FirstOrDefault(+ return UserConfig.Workspaces.Find((workspaceConfig) => workspaceConfig.Name == workspaceName);}@@ -133,16 +133,9 @@ namespace GlazeWM.Domain.UserConfigs{return UserConfig.WindowRules.Where(rule =>{- if (rule.ProcessNameRegex?.IsMatch(window.ProcessName) == false)- return false;-- if (rule.ClassNameRegex?.IsMatch(window.ClassName) == false)- return false;-- if (rule.TitleRegex?.IsMatch(window.Title) == false)- return false;-- return true;+ return rule.ProcessNameRegex?.IsMatch(window.ProcessName) != false+ && rule.ClassNameRegex?.IsMatch(window.ClassName) != false+ && (rule.TitleRegex?.IsMatch(window.Title)) != false;});}}diff --git a/GlazeWM.Domain/UserConfigs/WindowRuleConfig.cs b/GlazeWM.Domain/UserConfigs/WindowRuleConfig.csindex 8355b67d..aaaaa4c9 100644--- a/GlazeWM.Domain/UserConfigs/WindowRuleConfig.cs+++ b/GlazeWM.Domain/UserConfigs/WindowRuleConfig.cs@@ -1,4 +1,3 @@-using System;using System.Collections.Generic;using System.Text.RegularExpressions;@@ -6,19 +5,19 @@ namespace GlazeWM.Domain.UserConfigs{public class WindowRuleConfig{- public string MatchProcessName { get; set; } = null;+ public string MatchProcessName { get; set; }public Regex ProcessNameRegex => CreateRegex(MatchProcessName);- public string MatchClassName { get; set; } = null;+ public string MatchClassName { get; set; }public Regex ClassNameRegex => CreateRegex(MatchClassName);- public string MatchTitle { get; set; } = null;+ public string MatchTitle { get; set; }public Regex TitleRegex => CreateRegex(MatchTitle);- public string Command { get; set; } = null;+ public string Command { get; set; }public List<string> Commands { get; set; } = new List<string>();@@ -29,16 +28,16 @@ namespace GlazeWM.Domain.UserConfigs/// Creates an exact match regex for the given string./// </summary>/// <returns>The corresponding regex, or null if input is invalid.</returns>- private Regex CreateRegex(string input)+ private static Regex CreateRegex(string input){- if (String.IsNullOrWhiteSpace(input))+ if (string.IsNullOrWhiteSpace(input))return null;var isRegexLiteral = input.StartsWith("/") && input.EndsWith("/");// Allow user to pass a string that should be interpreted as regex (eg. "/steam/").if (isRegexLiteral)- return new Regex(input.Substring(1, input.Length - 2));+ return new Regex(input[1..^1]);// Otherwise, create an exact match regex.return new Regex($"^{input}$");diff --git a/GlazeWM.Domain/UserConfigs/WorkspaceConfig.cs b/GlazeWM.Domain/UserConfigs/WorkspaceConfig.csindex 89922499..76f2491a 100644--- a/GlazeWM.Domain/UserConfigs/WorkspaceConfig.cs+++ b/GlazeWM.Domain/UserConfigs/WorkspaceConfig.cs@@ -6,8 +6,8 @@ namespace GlazeWM.Domain.UserConfigs{[Required]public string Name { get; set; }- public string BindToMonitor { get; set; } = null;- public string DisplayName { get; set; } = null;- public bool KeepAlive { get; set; } = false;+ public string BindToMonitor { get; set; }+ public string DisplayName { get; set; }+ public bool KeepAlive { get; set; }}}diff --git a/GlazeWM.Domain/UserConfigs/WorkspacesComponentConfig.cs b/GlazeWM.Domain/UserConfigs/WorkspacesComponentConfig.csindex cd04ab95..c4595257 100644--- a/GlazeWM.Domain/UserConfigs/WorkspacesComponentConfig.cs+++ b/GlazeWM.Domain/UserConfigs/WorkspacesComponentConfig.cs@@ -9,7 +9,7 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Fallback to component foreground config if unset./// </summary>- public string FocusedWorkspaceForeground { get; set; } = null;+ public string FocusedWorkspaceForeground { get; set; }public string DisplayedWorkspaceBorderWidth { get; set; } = "0";public string DisplayedWorkspaceBorderColor { get; set; } = "blue";@@ -18,7 +18,7 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Fallback to component foreground config if unset./// </summary>- public string DisplayedWorkspaceForeground { get; set; } = null;+ public string DisplayedWorkspaceForeground { get; set; }public string DefaultWorkspaceBorderWidth { get; set; } = "0";public string DefaultWorkspaceBorderColor { get; set; } = "blue";@@ -26,11 +26,11 @@ namespace GlazeWM.Domain.UserConfigs/// <summary>/// Fallback to component background config if unset./// </summary>- public string DefaultWorkspaceBackground { get; set; } = null;+ public string DefaultWorkspaceBackground { get; set; }/// <summary>/// Fallback to component foreground config if unset./// </summary>- public string DefaultWorkspaceForeground { get; set; } = null;+ public string DefaultWorkspaceForeground { get; set; }}}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.csindex 77e830fa..7f200b43 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs@@ -12,15 +12,15 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Windows.CommandHandlers{- class AddWindowHandler : ICommandHandler<AddWindowCommand>+ internal class AddWindowHandler : ICommandHandler<AddWindowCommand>{- private Bus _bus;- private ContainerService _containerService;- private UserConfigService _userConfigService;- private CommandParsingService _commandParsingService;- private WindowService _windowService;- private MonitorService _monitorService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;+ private readonly UserConfigService _userConfigService;+ private readonly CommandParsingService _commandParsingService;+ private readonly WindowService _windowService;+ private readonly MonitorService _monitorService;+ private readonly WorkspaceService _workspaceService;public AddWindowHandler(Bus bus,@@ -46,7 +46,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar windowHandle = command.WindowHandle;var shouldRedraw = command.ShouldRedraw;- if (!_windowService.IsHandleManageable(windowHandle))+ if (!WindowService.IsHandleManageable(windowHandle))return CommandResponse.Ok;// Attach the new window as first child of the target parent (if provided), otherwise, add as@@ -56,14 +56,14 @@ namespace GlazeWM.Domain.Windows.CommandHandlers: GetInsertionTarget();// Create the window instance.- var targetWorkspace = _workspaceService.GetWorkspaceFromChildContainer(targetParent);+ var targetWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(targetParent);var window = CreateWindow(windowHandle, targetWorkspace);var matchingWindowRules = _userConfigService.GetMatchingWindowRules(window);var commandStrings = matchingWindowRules.SelectMany(rule => rule.CommandList)- .Select(commandString => _commandParsingService.FormatCommand(commandString));+ .Select(commandString => CommandParsingService.FormatCommand(commandString));// Avoid managing a window if a window rule uses 'ignore' command.if (commandStrings.Contains("ignore"))@@ -77,7 +77,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// The OS might spawn the window on a different monitor to the target parent, so adjustments// might need to be made because of DPI.var monitor = _monitorService.GetMonitorFromHandleLocation(windowHandle);- if (_monitorService.HasDpiDifference(monitor, window.Parent))+ if (MonitorService.HasDpiDifference(monitor, window.Parent))window.HasPendingDpiAdjustment = true;// Set the newly added window as focus descendant. This is necessary because@@ -104,17 +104,17 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;}- private Window CreateWindow(IntPtr windowHandle, Workspace targetWorkspace)+ private static Window CreateWindow(IntPtr windowHandle, Workspace targetWorkspace){// Calculate where window should be placed when floating is enabled. Use the original// width/height of the window, but position it in the center of the workspace.- var originalPlacement = _windowService.GetPlacementOfHandle(windowHandle).NormalPosition;+ var originalPlacement = WindowService.GetPlacementOfHandle(windowHandle).NormalPosition;var floatingPlacement = originalPlacement.TranslateToCenter(targetWorkspace.ToRectangle());var defaultBorderDelta = new RectDelta(7, 0, 7, 7);var windowType = GetWindowTypeToCreate(windowHandle);- var isResizable = _windowService.HandleHasWindowStyle(windowHandle, WS.WS_THICKFRAME);+ var isResizable = WindowService.HandleHasWindowStyle(windowHandle, WS.WS_THICKFRAME);// TODO: Handle initialization of maximized and fullscreen windows.return windowType switch@@ -135,17 +135,19 @@ namespace GlazeWM.Domain.Windows.CommandHandlersfloatingPlacement,defaultBorderDelta),- _ => throw new ArgumentException(),+ WindowType.MAXIMIZED => throw new ArgumentException(null, nameof(windowHandle)),+ WindowType.FULLSCREEN => throw new ArgumentException(null, nameof(windowHandle)),+ _ => throw new ArgumentException(null, nameof(windowHandle)),};}- private WindowType GetWindowTypeToCreate(IntPtr windowHandle)+ private static WindowType GetWindowTypeToCreate(IntPtr windowHandle){- if (_windowService.HandleHasWindowStyle(windowHandle, WS.WS_MINIMIZE))+ if (WindowService.HandleHasWindowStyle(windowHandle, WS.WS_MINIMIZE))return WindowType.MINIMIZED;// Initialize windows that can't be resized as floating.- if (!_windowService.HandleHasWindowStyle(windowHandle, WS.WS_THICKFRAME))+ if (!WindowService.HandleHasWindowStyle(windowHandle, WS.WS_THICKFRAME))return WindowType.FLOATING;return WindowType.TILING;diff --git a/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.csindex 98e3e275..8290d6b1 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/CloseFocusedWindowHandler.cs@@ -6,9 +6,9 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Windows.CommandHandlers{- class CloseFocusedWindowHandler : ICommandHandler<CloseFocusedWindowCommand>+ internal class CloseFocusedWindowHandler : ICommandHandler<CloseFocusedWindowCommand>{- private ContainerService _containerService;+ private readonly ContainerService _containerService;public CloseFocusedWindowHandler(ContainerService containerService){@@ -20,7 +20,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar focusedWindow = _containerService.FocusedContainer as Window;// Ignore cases where focused container is not a window or not in foreground.- if (focusedWindow == null || !_containerService.IsFocusSynced)+ if (focusedWindow is null || !_containerService.IsFocusSynced)return CommandResponse.Ok;SendMessage(focusedWindow.Hwnd, SendMessageType.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);diff --git a/GlazeWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/FocusWindowHandler.csindex 9f9b26cc..4e5dc1c8 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/FocusWindowHandler.cs@@ -4,12 +4,8 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Windows.CommandHandlers{- class FocusWindowHandler : ICommandHandler<FocusWindowCommand>+ internal class FocusWindowHandler : ICommandHandler<FocusWindowCommand>{- public FocusWindowHandler()- {- }-public CommandResponse Handle(FocusWindowCommand command){var window = command.Window;diff --git a/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.csindex d205d111..93de62d5 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/MoveFocusedWindowHandler.cs@@ -10,18 +10,20 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- class MoveFocusedWindowHandler : ICommandHandler<MoveFocusedWindowCommand>+ internal class MoveFocusedWindowHandler : ICommandHandler<MoveFocusedWindowCommand>{- private Bus _bus;- private ContainerService _containerService;- private WorkspaceService _workspaceService;- private MonitorService _monitorService;-- public MoveFocusedWindowHandler(Bus bus, ContainerService containerService, WorkspaceService workspaceService, MonitorService monitorService)+ private readonly Bus _bus;+ private readonly ContainerService _containerService;+ private readonly MonitorService _monitorService;++ public MoveFocusedWindowHandler(+ Bus bus,+ ContainerService containerService,+ MonitorService monitorService+ ){_bus = bus;_containerService = containerService;- _workspaceService = workspaceService;_monitorService = monitorService;}@@ -30,7 +32,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar focusedWindow = _containerService.FocusedContainer as TilingWindow;// Ignore cases where focused container is not a tiling window.- if (focusedWindow == null)+ if (focusedWindow is null)return CommandResponse.Ok;var direction = command.Direction;@@ -52,9 +54,9 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// The focused window cannot be moved within the parent container, so traverse upwards to find// a suitable ancestor to move to.- var ancestorWithLayout = focusedWindow.Parent.Ancestors- .Where(container => (container as SplitContainer)?.Layout == layoutForDirection)- .FirstOrDefault() as SplitContainer;+ var ancestorWithLayout = focusedWindow.Parent.Ancestors.FirstOrDefault(+ container => (container as SplitContainer)?.Layout == layoutForDirection+ ) as SplitContainer;// Change the layout of the workspace to layout for direction.if (ancestorWithLayout == null)@@ -71,24 +73,24 @@ namespace GlazeWM.Domain.Windows.CommandHandlers/// <summary>/// Whether the focused window has a tiling sibling in the given direction./// </summary>- private bool HasSiblingInDirection(Window focusedWindow, Direction direction)+ private static bool HasSiblingInDirection(Window focusedWindow, Direction direction){- if (direction == Direction.UP || direction == Direction.LEFT)+ if (direction is Direction.UP or Direction.LEFT)return focusedWindow != focusedWindow.SelfAndSiblingsOfType(typeof(IResizable)).First();- else- return focusedWindow != focusedWindow.SelfAndSiblingsOfType(typeof(IResizable)).Last();++ return focusedWindow != focusedWindow.SelfAndSiblingsOfType(typeof(IResizable)).Last();}private void SwapSiblingContainers(Window focusedWindow, Direction direction){- var siblingInDirection = direction == Direction.UP || direction == Direction.LEFT+ var siblingInDirection = direction is Direction.UP or Direction.LEFT? focusedWindow.GetPreviousSiblingOfType(typeof(IResizable)): focusedWindow.GetNextSiblingOfType(typeof(IResizable));// Swap the focused window with sibling in given direction.if (siblingInDirection is Window){- var targetIndex = direction == Direction.UP || direction == Direction.LEFT ?+ var targetIndex = direction is Direction.UP or Direction.LEFT ?siblingInDirection.Index : siblingInDirection.Index + 1;_bus.Invoke(@@ -126,7 +128,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn;// Since window is crossing monitors, adjustments might need to be made because of DPI.- if (_monitorService.HasDpiDifference(focusedWindow, workspaceInDirection))+ if (MonitorService.HasDpiDifference(focusedWindow, workspaceInDirection))focusedWindow.HasPendingDpiAdjustment = true;// Update floating placement since the window has to cross monitors.@@ -134,7 +136,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersfocusedWindow.FloatingPlacement.TranslateToCenter(workspaceInDirection.ToRectangle());// TODO: Descend into container if possible.- if (direction == Direction.UP || direction == Direction.LEFT)+ if (direction is Direction.UP or Direction.LEFT)_bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, workspaceInDirection, true));else_bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, workspaceInDirection, 0, true));@@ -147,7 +149,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersprivate void ChangeWorkspaceLayout(Window focusedWindow, Direction direction){- var workspace = _workspaceService.GetWorkspaceFromChildContainer(focusedWindow);+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(focusedWindow);var layoutForDirection = direction.GetCorrespondingLayout();_bus.Invoke(new ChangeContainerLayoutCommand(workspace, layoutForDirection));@@ -166,7 +168,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar insertionReference = focusedWindow.Ancestors.FirstOrDefault(container => container.Parent == ancestorWithLayout);- var insertionReferenceSibling = direction == Direction.UP || direction == Direction.LEFT+ var insertionReferenceSibling = direction is Direction.UP or Direction.LEFT? insertionReference.GetPreviousSiblingOfType(typeof(IResizable)): insertionReference.GetNextSiblingOfType(typeof(IResizable));@@ -185,7 +187,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlerselse{// Move the focused window into the container above.- var insertionIndex = (direction == Direction.UP || direction == Direction.LEFT) ?+ var insertionIndex = (direction is Direction.UP or Direction.LEFT) ?insertionReference.Index : insertionReference.Index + 1;_bus.Invoke(new MoveContainerWithinTreeCommand(focusedWindow, ancestorWithLayout, insertionIndex, true));diff --git a/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.csindex 4f0d28f0..e6358c61 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/RemoveWindowHandler.cs@@ -5,10 +5,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- class RemoveWindowHandler : ICommandHandler<RemoveWindowCommand>+ internal class RemoveWindowHandler : ICommandHandler<RemoveWindowCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public RemoveWindowHandler(Bus bus, ContainerService containerService){@@ -32,8 +32,8 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// Get container to switch focus to after the window has been removed. The OS automatically// switches focus to a different window after closing, so by setting `PendingFocusContainer`// this behavior is overridden.- var containerToFocus = parent.LastFocusedDescendant ?? grandparent.LastFocusedDescendant;- _containerService.PendingFocusContainer = containerToFocus;+ _containerService.PendingFocusContainer = parent.LastFocusedDescendant+ ?? grandparent.LastFocusedDescendant;return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.csindex e2da2b69..d5e2e958 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowBordersHandler.cs@@ -6,7 +6,7 @@ using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Windows.CommandHandlers{- class ResizeFocusedWindowBordersHandler : ICommandHandler<ResizeFocusedWindowBordersCommand>+ internal class ResizeFocusedWindowBordersHandler : ICommandHandler<ResizeFocusedWindowBordersCommand>{private readonly Bus _bus;private readonly ContainerService _containerService;@@ -34,7 +34,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersfocusedWindow.BorderDelta.DeltaBottom + borderDelta.DeltaBottom);- if (!(focusedWindow is TilingWindow))+ if (focusedWindow is not TilingWindow)return CommandResponse.Ok;// Only redraw the window if it's tiling.diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.csindex 03abd77c..1b741464 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeFocusedWindowHandler.cs@@ -1,5 +1,4 @@using System;-using System.Collections.Generic;using System.Globalization;using System.Linq;using System.Text.RegularExpressions;@@ -9,13 +8,14 @@ using GlazeWM.Domain.Containers.Commands;using GlazeWM.Domain.Windows.Commands;using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.Exceptions;namespace GlazeWM.Domain.Windows.CommandHandlers{- class ResizeFocusedWindowHandler : ICommandHandler<ResizeFocusedWindowCommand>+ internal class ResizeFocusedWindowHandler : ICommandHandler<ResizeFocusedWindowCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public ResizeFocusedWindowHandler(Bus bus, ContainerService containerService){@@ -30,7 +30,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar focusedWindow = _containerService.FocusedContainer as TilingWindow;// Ignore cases where focused container is not a tiling window.- if (focusedWindow == null)+ if (focusedWindow is null)return CommandResponse.Ok;var layout = (focusedWindow.Parent as SplitContainer).Layout;@@ -47,7 +47,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar resizableSiblings = containerToResize.Siblings.Where(container => container is IResizable);// Ignore cases where the container to resize is a workspace or is only child.- if (resizableSiblings.Count() == 0 || containerToResize is Workspace)+ if (!resizableSiblings.Any() || containerToResize is Workspace)return CommandResponse.Ok;// Convert `resizeAmount` to a percentage to increase/decrease the window size by.@@ -65,11 +65,11 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;}- private double ConvertToResizePercentage(string resizeAmount)+ private static double ConvertToResizePercentage(string resizeAmount){try{- var matchedResizeAmount = new Regex(@"(.*)(%|ppt)").Match(resizeAmount);+ var matchedResizeAmount = new Regex("(.*)(%|ppt)").Match(resizeAmount);var amount = matchedResizeAmount.Groups[1].Value;var unit = matchedResizeAmount.Groups[2].Value;@@ -78,7 +78,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlers{"%" => Convert.ToDouble(amount, CultureInfo.InvariantCulture),"ppt" => Convert.ToDouble(amount, CultureInfo.InvariantCulture),- _ => throw new ArgumentException(),+ _ => throw new ArgumentException(null, nameof(resizeAmount)),};}catchdiff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.csindex 6d70ace9..885193a6 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs@@ -6,15 +6,13 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- class SetFloatingHandler : ICommandHandler<SetFloatingCommand>+ internal class SetFloatingHandler : ICommandHandler<SetFloatingCommand>{private readonly Bus _bus;- private readonly WorkspaceService _workspaceService;- public SetFloatingHandler(Bus bus, WorkspaceService workspaceService)+ public SetFloatingHandler(Bus bus){_bus = bus;- _workspaceService = workspaceService;}public CommandResponse Handle(SetFloatingCommand command)@@ -25,7 +23,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersreturn CommandResponse.Ok;// Keep reference to the window's ancestor workspace prior to detaching.- var workspace = _workspaceService.GetWorkspaceFromChildContainer(window);+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window);if (window is IResizable)_bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true));diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.csindex a8b6b6a4..dbacac4b 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetFocusedWindowFloatingHandler.cs@@ -4,10 +4,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- class SetFocusedWindowFloatingHandler : ICommandHandler<SetFocusedWindowFloatingCommand>+ internal class SetFocusedWindowFloatingHandler : ICommandHandler<SetFocusedWindowFloatingCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public SetFocusedWindowFloatingHandler(Bus bus, ContainerService containerService){diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ShowAllWindowsHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ShowAllWindowsHandler.csindex e2c59dd4..71c1b7fe 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ShowAllWindowsHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ShowAllWindowsHandler.cs@@ -5,9 +5,9 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Windows.CommandHandlers{- class ShowAllWindowsHandler : ICommandHandler<ShowAllWindowsCommand>+ internal class ShowAllWindowsHandler : ICommandHandler<ShowAllWindowsCommand>{- private WindowService _windowService;+ private readonly WindowService _windowService;public ShowAllWindowsHandler(WindowService windowService){@@ -19,7 +19,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// Show all windows regardless of whether their workspace is displayed.foreach (var window in _windowService.GetWindows()){- var flags = SWP.SWP_FRAMECHANGED | SWP.SWP_NOACTIVATE | SWP.SWP_NOCOPYBITS |+ const SWP flags = SWP.SWP_FRAMECHANGED | SWP.SWP_NOACTIVATE | SWP.SWP_NOCOPYBITS |SWP.SWP_NOZORDER | SWP.SWP_NOOWNERZORDER | SWP.SWP_NOSENDCHANGING | SWP.SWP_SHOWWINDOW;SetWindowPos(diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.csindex 43403f0f..c7b05815 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFloatingHandler.cs@@ -6,15 +6,13 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- class ToggleFloatingHandler : ICommandHandler<ToggleFloatingCommand>+ internal class ToggleFloatingHandler : ICommandHandler<ToggleFloatingCommand>{private readonly Bus _bus;- private readonly WorkspaceService _workspaceService;- public ToggleFloatingHandler(Bus bus, WorkspaceService workspaceService)+ public ToggleFloatingHandler(Bus bus){_bus = bus;- _workspaceService = workspaceService;}public CommandResponse Handle(ToggleFloatingCommand command)@@ -23,7 +21,6 @@ namespace GlazeWM.Domain.Windows.CommandHandlersif (window is FloatingWindow)UnsetFloating(window as FloatingWindow);-else_bus.Invoke(new SetFloatingCommand(window));@@ -33,7 +30,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersprivate void UnsetFloating(FloatingWindow floatingWindow){// Keep reference to the window's ancestor workspace prior to detaching.- var workspace = _workspaceService.GetWorkspaceFromChildContainer(floatingWindow);+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(floatingWindow);var insertionTarget = workspace.LastFocusedDescendantOfType(typeof(IResizable));diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.csindex 76503e65..0f4c0dbc 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ToggleFocusedWindowFloatingHandler.cs@@ -4,10 +4,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Windows.CommandHandlers{- class ToggleFocusedWindowFloatingHandler : ICommandHandler<ToggleFocusedWindowFloatingCommand>+ internal class ToggleFocusedWindowFloatingHandler : ICommandHandler<ToggleFocusedWindowFloatingCommand>{- private Bus _bus;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;public ToggleFocusedWindowFloatingHandler(Bus bus, ContainerService containerService){@@ -20,7 +20,7 @@ namespace GlazeWM.Domain.Windows.CommandHandlersvar focusedWindow = _containerService.FocusedContainer as Window;// Ignore cases where focused container is not a window or not in foreground.- if (focusedWindow == null || !_containerService.IsFocusSynced)+ if (focusedWindow is null || !_containerService.IsFocusSynced)return CommandResponse.Ok;_bus.Invoke(new ToggleFloatingCommand(focusedWindow));diff --git a/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs b/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.csindex d275f7be..41650b45 100644--- a/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs+++ b/GlazeWM.Domain/Windows/Commands/SetFocusedWindowFloatingCommand.cs@@ -4,8 +4,5 @@ namespace GlazeWM.Domain.Windows.Commands{public class SetFocusedWindowFloatingCommand : Command{- public SetFocusedWindowFloatingCommand()- {- }}}diff --git a/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.cs b/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.csindex 71ae031b..b5c1c8f0 100644--- a/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.cs+++ b/GlazeWM.Domain/Windows/Commands/ToggleFocusedWindowFloatingCommand.cs@@ -4,8 +4,5 @@ namespace GlazeWM.Domain.Windows.Commands{public class ToggleFocusedWindowFloatingCommand : Command{- public ToggleFocusedWindowFloatingCommand()- {- }}}diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.csindex fc8aabae..2b9d3561 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs@@ -7,10 +7,10 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowDestroyedHandler : IEventHandler<WindowDestroyedEvent>+ internal class WindowDestroyedHandler : IEventHandler<WindowDestroyedEvent>{- private Bus _bus;- private WindowService _windowService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;public WindowDestroyedHandler(Bus bus, WindowService windowService){diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.csindex 4d43304b..d8f163a5 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs@@ -10,11 +10,11 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowFocusedHandler : IEventHandler<WindowFocusedEvent>+ internal class WindowFocusedHandler : IEventHandler<WindowFocusedEvent>{- private Bus _bus;- private WindowService _windowService;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;+ private readonly ContainerService _containerService;public WindowFocusedHandler(Bus bus, WindowService windowService, ContainerService containerService){@@ -32,7 +32,6 @@ namespace GlazeWM.Domain.Windows.EventHandlers{if (pendingFocusContainer is Window)_bus.Invoke(new FocusWindowCommand(pendingFocusContainer as Window));-else if (pendingFocusContainer is Workspace)_bus.Invoke(new FocusWorkspaceCommand((pendingFocusContainer as Workspace).Name));diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.csindex fe9ac3fb..daba8388 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs@@ -7,10 +7,10 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowHiddenHandler : IEventHandler<WindowHiddenEvent>+ internal class WindowHiddenHandler : IEventHandler<WindowHiddenEvent>{- private Bus _bus;- private WindowService _windowService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;public WindowHiddenHandler(Bus bus, WindowService windowService){@@ -35,7 +35,7 @@ namespace GlazeWM.Domain.Windows.EventHandlers// Ignore events where the window isn't managed or is actually supposed to be hidden. Since// window events are processed in a sequence, also handle case where the window is not// actually hidden anymore when the event is processed.- if (window == null || window.IsHidden == true || _windowService.IsHandleVisible(window.Hwnd))+ if (window?.IsHidden != false || WindowService.IsHandleVisible(window.Hwnd))return;// Detach the hidden window from its parent.diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.csindex eaa0f16d..faa30879 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs@@ -4,10 +4,10 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowLocationChangedHandler : IEventHandler<WindowLocationChangedEvent>+ internal class WindowLocationChangedHandler : IEventHandler<WindowLocationChangedEvent>{- private Bus _bus;- private WindowService _windowService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;public WindowLocationChangedHandler(Bus bus, WindowService windowService){diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.csindex f4ca09df..85f8fe06 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs@@ -8,24 +8,21 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowMinimizeEndedHandler : IEventHandler<WindowMinimizeEndedEvent>+ internal class WindowMinimizeEndedHandler : IEventHandler<WindowMinimizeEndedEvent>{- private Bus _bus;- private WindowService _windowService;- private ContainerService _containerService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;+ private readonly ContainerService _containerService;public WindowMinimizeEndedHandler(Bus bus,WindowService windowService,- ContainerService containerService,- WorkspaceService workspaceService+ ContainerService containerService){_bus = bus;_windowService = windowService;_containerService = containerService;- _workspaceService = workspaceService;}public void Handle(WindowMinimizeEndedEvent @event)@@ -40,10 +37,10 @@ namespace GlazeWM.Domain.Windows.EventHandlers_bus.Invoke(new ReplaceContainerCommand(restoredWindow, window.Parent, window.Index));- if (!(restoredWindow is TilingWindow))+ if (restoredWindow is not TilingWindow)return;- var workspace = _workspaceService.GetWorkspaceFromChildContainer(window);+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window);var insertionTarget = workspace.LastFocusedDescendantOfType(typeof(IResizable));// Insert the created tiling window after the last focused descendant of the workspace.@@ -63,7 +60,7 @@ namespace GlazeWM.Domain.Windows.EventHandlers_bus.Invoke(new RedrawContainersCommand());}- private Window CreateWindowFromPreviousState(MinimizedWindow window)+ private static Window CreateWindowFromPreviousState(MinimizedWindow window){return window.PreviousState switch{@@ -89,7 +86,8 @@ namespace GlazeWM.Domain.Windows.EventHandlerswindow.BorderDelta,0),- _ => throw new ArgumentException(),+ WindowType.MINIMIZED => throw new ArgumentException(null, nameof(window)),+ _ => throw new ArgumentException(null, nameof(window)),};}}diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.csindex 35f04c22..1c7c7d50 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs@@ -1,4 +1,3 @@-using System;using System.Linq;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;@@ -10,24 +9,21 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowMinimizedHandler : IEventHandler<WindowMinimizedEvent>+ internal class WindowMinimizedHandler : IEventHandler<WindowMinimizedEvent>{- private Bus _bus;- private WindowService _windowService;- private ContainerService _containerService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;+ private readonly ContainerService _containerService;public WindowMinimizedHandler(Bus bus,WindowService windowService,- ContainerService containerService,- WorkspaceService workspaceService+ ContainerService containerService){_bus = bus;_windowService = windowService;_containerService = containerService;- _workspaceService = workspaceService;}public void Handle(WindowMinimizedEvent @event)@@ -35,24 +31,16 @@ namespace GlazeWM.Domain.Windows.EventHandlersvar window = _windowService.GetWindows().FirstOrDefault(window => window.Hwnd == @event.WindowHandle);- if (window == null || window is MinimizedWindow)+ if (window is null or MinimizedWindow)return;- var workspace = _workspaceService.GetWorkspaceFromChildContainer(window);+ var workspace = WorkspaceService.GetWorkspaceFromChildContainer(window);// Move tiling windows to be direct children of workspace (in case they aren't already).if (window is TilingWindow)_bus.Invoke(new MoveContainerWithinTreeCommand(window, workspace, true));- var previousState = window switch- {- TilingWindow _ => WindowType.TILING,- FloatingWindow _ => WindowType.FLOATING,- MaximizedWindow _ => WindowType.MAXIMIZED,- FullscreenWindow _ => WindowType.FULLSCREEN,- _ => throw new ArgumentException(),- };-+ var previousState = WindowService.GetWindowType(window);var minimizedWindow = new MinimizedWindow(window.Hwnd,window.FloatingPlacement,@@ -66,7 +54,6 @@ namespace GlazeWM.Domain.Windows.EventHandlersif (focusTarget is Window)_bus.Invoke(new FocusWindowCommand(focusTarget as Window));-else if (focusTarget is Workspace)_bus.Invoke(new FocusWorkspaceCommand((focusTarget as Workspace).Name));diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.csindex bc0f976b..e7783527 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs@@ -8,19 +8,21 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowMovedOrResizedHandler : IEventHandler<WindowMovedOrResizedEvent>+ internal class WindowMovedOrResizedHandler : IEventHandler<WindowMovedOrResizedEvent>{- private Bus _bus;- private WindowService _windowService;- private MonitorService _monitorService;- private WorkspaceService _workspaceService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;+ private readonly MonitorService _monitorService;- public WindowMovedOrResizedHandler(Bus bus, WindowService windowService, MonitorService monitorService, WorkspaceService workspaceService)+ public WindowMovedOrResizedHandler(+ Bus bus,+ WindowService windowService,+ MonitorService monitorService+ ){_bus = bus;_windowService = windowService;_monitorService = monitorService;- _workspaceService = workspaceService;}public void Handle(WindowMovedOrResizedEvent @event)@@ -28,7 +30,7 @@ namespace GlazeWM.Domain.Windows.EventHandlersvar window = _windowService.GetWindows().FirstOrDefault(window => window.Hwnd == @event.WindowHandle);- if (window == null || !(window is FloatingWindow))+ if (window is null or not FloatingWindow)return;// Update state with new location of the floating window.@@ -38,15 +40,14 @@ namespace GlazeWM.Domain.Windows.EventHandlersUpdateParentWorkspace(window);}- private void UpdateWindowPlacement(Window window)+ private static void UpdateWindowPlacement(Window window){- var updatedPlacement = _windowService.GetPlacementOfHandle(window.Hwnd).NormalPosition;- window.FloatingPlacement = updatedPlacement;+ window.FloatingPlacement = WindowService.GetPlacementOfHandle(window.Hwnd).NormalPosition;}private void UpdateParentWorkspace(Window window){- var currentWorkspace = _workspaceService.GetWorkspaceFromChildContainer(window);+ var currentWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(window);// Get workspace that encompasses most of the window.var targetMonitor = _monitorService.GetMonitorFromHandleLocation(window.Hwnd);diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.csindex 7962be8a..19d657d4 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs@@ -6,10 +6,10 @@ using GlazeWM.Infrastructure.WindowsApi.Events;namespace GlazeWM.Domain.Windows.EventHandlers{- class WindowShownHandler : IEventHandler<WindowShownEvent>+ internal class WindowShownHandler : IEventHandler<WindowShownEvent>{- private Bus _bus;- private WindowService _windowService;+ private readonly Bus _bus;+ private readonly WindowService _windowService;public WindowShownHandler(Bus bus, WindowService windowService){diff --git a/GlazeWM.Domain/Windows/Events/FocusedWindowMovedEvent.cs b/GlazeWM.Domain/Windows/Events/FocusedWindowMovedEvent.csindex e9159603..f0d31cc7 100644--- a/GlazeWM.Domain/Windows/Events/FocusedWindowMovedEvent.cs+++ b/GlazeWM.Domain/Windows/Events/FocusedWindowMovedEvent.cs@@ -1,7 +1,7 @@-using GlazeWM.Domain.Windows;+using GlazeWM.Domain.Containers;using GlazeWM.Infrastructure.Bussing;-namespace GlazeWM.Domain.Containers.Events+namespace GlazeWM.Domain.Windows.Events{public class FocusedWindowMovedEvent : Event{diff --git a/GlazeWM.Domain/Windows/TilingWindow.cs b/GlazeWM.Domain/Windows/TilingWindow.csindex 8f2d9ca5..71f9c6c6 100644--- a/GlazeWM.Domain/Windows/TilingWindow.cs+++ b/GlazeWM.Domain/Windows/TilingWindow.cs@@ -10,7 +10,7 @@ namespace GlazeWM.Domain.Windows{public double SizePercentage { get; set; } = 1;- private ContainerService _containerService =+ private readonly ContainerService _containerService =ServiceLocator.Provider.GetRequiredService<ContainerService>();public override int Width => _containerService.CalculateWidthOfResizableContainer(this);diff --git a/GlazeWM.Domain/Windows/Window.cs b/GlazeWM.Domain/Windows/Window.csindex 5a80bcac..a4134936 100644--- a/GlazeWM.Domain/Windows/Window.cs+++ b/GlazeWM.Domain/Windows/Window.cs@@ -1,9 +1,7 @@using System;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Workspaces;-using GlazeWM.Infrastructure;using GlazeWM.Infrastructure.WindowsApi;-using Microsoft.Extensions.DependencyInjection;using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Windows@@ -28,10 +26,7 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Whether adjustments need to be made because of DPI (eg. when moving between monitors)./// </summary>- public bool HasPendingDpiAdjustment { get; set; } = false;-- private WindowService _windowService = ServiceLocator.Provider.GetRequiredService<WindowService>();- private WorkspaceService _workspaceService = ServiceLocator.Provider.GetRequiredService<WorkspaceService>();+ public bool HasPendingDpiAdjustment { get; set; }public Window(IntPtr hwnd, WindowRect floatingPlacement, RectDelta borderDelta){@@ -43,30 +38,30 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Windows are hidden if their parent workspace is not displayed./// </summary>- public bool IsHidden => !_workspaceService.GetWorkspaceFromChildContainer(this).IsDisplayed;+ public bool IsHidden => !WorkspaceService.GetWorkspaceFromChildContainer(this).IsDisplayed;- public string ProcessName => _windowService.GetProcessOfHandle(Hwnd).ProcessName;+ public string ProcessName => WindowService.GetProcessOfHandle(Hwnd).ProcessName;- public string ClassName => _windowService.GetClassNameOfHandle(Hwnd);+ public string ClassName => WindowService.GetClassNameOfHandle(Hwnd);- public WindowRect Location => _windowService.GetLocationOfHandle(Hwnd);+ public WindowRect Location => WindowService.GetLocationOfHandle(Hwnd);- public string Title => _windowService.GetTitleOfHandle(Hwnd);+ public string Title => WindowService.GetTitleOfHandle(Hwnd);- public bool IsManageable => _windowService.IsHandleManageable(Hwnd);+ public bool IsManageable => WindowService.IsHandleManageable(Hwnd);- public WS WindowStyles => _windowService.GetWindowStyles(Hwnd);+ public WS WindowStyles => WindowService.GetWindowStyles(Hwnd);- public WS_EX WindowStylesEx => _windowService.GetWindowStylesEx(Hwnd);+ public WS_EX WindowStylesEx => WindowService.GetWindowStylesEx(Hwnd);public bool HasWindowStyle(WS style){- return _windowService.HandleHasWindowStyle(Hwnd, style);+ return WindowService.HandleHasWindowStyle(Hwnd, style);}public bool HasWindowExStyle(WS_EX style){- return _windowService.HandleHasWindowExStyle(Hwnd, style);+ return WindowService.HandleHasWindowExStyle(Hwnd, style);}}}diff --git a/GlazeWM.Domain/Windows/WindowService.cs b/GlazeWM.Domain/Windows/WindowService.csindex 1e74b4de..875de90c 100644--- a/GlazeWM.Domain/Windows/WindowService.cs+++ b/GlazeWM.Domain/Windows/WindowService.cs@@ -19,8 +19,8 @@ namespace GlazeWM.Domain.Windows/// </summary>public List<IntPtr> AppBarHandles { get; set; } = new List<IntPtr>();- private ContainerService _containerService;- private MonitorService _monitorService;+ private readonly ContainerService _containerService;+ private readonly MonitorService _monitorService;public WindowService(ContainerService containerService, MonitorService monitorService){@@ -39,28 +39,27 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Get the id of the process that created the window./// </summary>- public Process GetProcessOfHandle(IntPtr handle)+ public static Process GetProcessOfHandle(IntPtr handle){- uint processId;- GetWindowThreadProcessId(handle, out processId);- return Process.GetProcesses().FirstOrDefault(process => process.Id == (int)processId);+ _ = GetWindowThreadProcessId(handle, out var processId);+ return Array.Find(Process.GetProcesses(), process => process.Id == (int)processId);}/// <summary>/// Get the class name of the specified window./// </summary>- public string GetClassNameOfHandle(IntPtr handle)+ public static string GetClassNameOfHandle(IntPtr handle){// Class name is limited to 256 characters, so it's fine to use a fixed size buffer.var buffer = new StringBuilder(256);- GetClassName(handle, buffer, buffer.Capacity);+ _ = GetClassName(handle, buffer, buffer.Capacity);return buffer.ToString();}/// <summary>/// Get dimensions of the bounding rectangle of the specified window./// </summary>- public WindowRect GetLocationOfHandle(IntPtr handle)+ public static WindowRect GetLocationOfHandle(IntPtr handle){var rect = new WindowRect();GetWindowRect(handle, ref rect);@@ -70,7 +69,7 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Get info about the placement of the specified window./// </summary>- public WindowPlacement GetPlacementOfHandle(IntPtr handle)+ public static WindowPlacement GetPlacementOfHandle(IntPtr handle){var windowPlacement = new WindowPlacement();GetWindowPlacement(handle, ref windowPlacement);@@ -80,23 +79,23 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Get title bar text of the specified window./// </summary>- public string GetTitleOfHandle(IntPtr handle)+ public static string GetTitleOfHandle(IntPtr handle){var titleLength = GetWindowTextLength(handle);if (titleLength == 0)- return String.Empty;+ return string.Empty;var buffer = new StringBuilder(titleLength + 1);- GetWindowText(handle, buffer, buffer.Capacity);+ _ = GetWindowText(handle, buffer, buffer.Capacity);return buffer.ToString();}- public List<IntPtr> GetAllWindowHandles()+ public static List<IntPtr> GetAllWindowHandles(){var windowHandles = new List<IntPtr>();- EnumWindows((IntPtr hwnd, int lParam) =>+ EnumWindows((IntPtr hwnd, int _) =>{windowHandles.Add(hwnd);return true;@@ -105,22 +104,22 @@ namespace GlazeWM.Domain.Windowsreturn windowHandles;}- public WS_EX GetWindowStylesEx(IntPtr handle)+ public static WS_EX GetWindowStylesEx(IntPtr handle){- return unchecked((WS_EX)GetWindowLongPtr(handle, (int)(GWL_EXSTYLE)).ToInt64());+ return unchecked((WS_EX)GetWindowLongPtr(handle, GWL_EXSTYLE).ToInt64());}- public WS GetWindowStyles(IntPtr handle)+ public static WS GetWindowStyles(IntPtr handle){- return unchecked((WS)GetWindowLongPtr(handle, (int)(GWL_STYLE)).ToInt64());+ return unchecked((WS)GetWindowLongPtr(handle, GWL_STYLE).ToInt64());}- public bool HandleHasWindowStyle(IntPtr handle, WS style)+ public static bool HandleHasWindowStyle(IntPtr handle, WS style){return (GetWindowStyles(handle) & style) != 0;}- public bool HandleHasWindowExStyle(IntPtr handle, WS_EX style)+ public static bool HandleHasWindowExStyle(IntPtr handle, WS_EX style){return (GetWindowStylesEx(handle) & style) != 0;}@@ -130,22 +129,21 @@ namespace GlazeWM.Domain.Windows/// the window isn't actually visible. The `DWMWA_CLOAKED` attribute is used to check whether/// these apps are visible./// </summary>- public bool IsHandleCloaked(IntPtr handle)+ public static bool IsHandleCloaked(IntPtr handle){- bool isCloaked;- DwmGetWindowAttribute(handle, DwmWindowAttribute.DWMWA_CLOAKED, out isCloaked, Marshal.SizeOf(typeof(bool)));+ _ = DwmGetWindowAttribute(handle, DwmWindowAttribute.DWMWA_CLOAKED, out var isCloaked, Marshal.SizeOf(typeof(bool)));return isCloaked;}/// <summary>/// Whether the given handle is actually visible./// </summary>- public bool IsHandleVisible(IntPtr handle)+ public static bool IsHandleVisible(IntPtr handle){return IsWindowVisible(handle) && !IsHandleCloaked(handle);}- public bool IsHandleManageable(IntPtr handle)+ public static bool IsHandleManageable(IntPtr handle){// Ignore windows that are hidden.if (!IsHandleVisible(handle))@@ -165,10 +163,7 @@ namespace GlazeWM.Domain.Windowsvar isMenuWindow = GetWindow(handle, GW.GW_OWNER) != IntPtr.Zero&& !HandleHasWindowStyle(handle, WS.WS_CAPTION);- if (isMenuWindow)- return false;-- return true;+ return !isMenuWindow;}/// <summary>@@ -199,5 +194,17 @@ namespace GlazeWM.Domain.Windowsreturn isHorizontalBar || isVerticalBar;}++ public static WindowType GetWindowType(Window window)+ {+ return window switch+ {+ TilingWindow => WindowType.TILING,+ FloatingWindow => WindowType.FLOATING,+ MaximizedWindow => WindowType.MAXIMIZED,+ FullscreenWindow => WindowType.FULLSCREEN,+ _ => throw new ArgumentException(null, nameof(window)),+ };+ }}}diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/ActivateWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/ActivateWorkspaceHandler.csindex ef739cb8..c75fae76 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/ActivateWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/ActivateWorkspaceHandler.cs@@ -5,9 +5,9 @@ using GlazeWM.Domain.Workspaces.Events;namespace GlazeWM.Domain.Workspaces.CommandHandlers{- class ActivateWorkspaceHandler : ICommandHandler<ActivateWorkspaceCommand>+ internal class ActivateWorkspaceHandler : ICommandHandler<ActivateWorkspaceCommand>{- private Bus _bus;+ private readonly Bus _bus;public ActivateWorkspaceHandler(Bus bus){diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/DeactivateWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/DeactivateWorkspaceHandler.csindex 92985608..1b14a15e 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/DeactivateWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/DeactivateWorkspaceHandler.cs@@ -5,7 +5,7 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Workspaces.CommandHandlers{- class DeactivateWorkspaceHandler : ICommandHandler<DeactivateWorkspaceCommand>+ internal class DeactivateWorkspaceHandler : ICommandHandler<DeactivateWorkspaceCommand>{public Bus _bus { get; }diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.csindex 2289796e..85e7e5f9 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs@@ -6,16 +6,14 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Workspaces.CommandHandlers{- class DisplayWorkspaceHandler : ICommandHandler<DisplayWorkspaceCommand>+ internal class DisplayWorkspaceHandler : ICommandHandler<DisplayWorkspaceCommand>{- private Bus _bus;- private MonitorService _monitorService;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly ContainerService _containerService;- public DisplayWorkspaceHandler(Bus bus, MonitorService monitorService, ContainerService containerService)+ public DisplayWorkspaceHandler(Bus bus, ContainerService containerService){_bus = bus;- _monitorService = monitorService;_containerService = containerService;}@@ -23,7 +21,7 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers{var workspaceToDisplay = command.Workspace;- var monitor = _monitorService.GetMonitorFromChildContainer(command.Workspace);+ var monitor = MonitorService.GetMonitorFromChildContainer(command.Workspace);var currentWorkspace = monitor.DisplayedWorkspace;// If `DisplayedWorkspace` is unassigned (ie. on startup), there is no need to show/hidediff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.csindex 0229573c..f568928b 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs@@ -11,12 +11,12 @@ using System.Linq;namespace GlazeWM.Domain.Workspaces.CommandHandlers{- class FocusWorkspaceHandler : ICommandHandler<FocusWorkspaceCommand>+ internal class FocusWorkspaceHandler : ICommandHandler<FocusWorkspaceCommand>{- private Bus _bus;- private WorkspaceService _workspaceService;- private MonitorService _monitorService;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly WorkspaceService _workspaceService;+ private readonly MonitorService _monitorService;+ private readonly ContainerService _containerService;public FocusWorkspaceHandler(Bus bus,diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.csindex 76715bb5..b8dcf2f7 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs@@ -7,12 +7,12 @@ using GlazeWM.Domain.Containers.Commands;namespace GlazeWM.Domain.Workspaces.CommandHandlers{- class MoveFocusedWindowToWorkspaceHandler : ICommandHandler<MoveFocusedWindowToWorkspaceCommand>+ internal class MoveFocusedWindowToWorkspaceHandler : ICommandHandler<MoveFocusedWindowToWorkspaceCommand>{- private Bus _bus;- private WorkspaceService _workspaceService;- private MonitorService _monitorService;- private ContainerService _containerService;+ private readonly Bus _bus;+ private readonly WorkspaceService _workspaceService;+ private readonly MonitorService _monitorService;+ private readonly ContainerService _containerService;public MoveFocusedWindowToWorkspaceHandler(Bus bus,@@ -42,7 +42,7 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers// Since target workspace could be on a different monitor, adjustments might need to be made// because of DPI.- if (_monitorService.HasDpiDifference(currentWorkspace, targetWorkspace))+ if (MonitorService.HasDpiDifference(currentWorkspace, targetWorkspace))focusedWindow.HasPendingDpiAdjustment = true;// Update floating placement if the window has to cross monitors.diff --git a/GlazeWM.Domain/Workspaces/Commands/ActivateWorkspaceCommand.cs b/GlazeWM.Domain/Workspaces/Commands/ActivateWorkspaceCommand.csindex a844a617..533d7ea9 100644--- a/GlazeWM.Domain/Workspaces/Commands/ActivateWorkspaceCommand.cs+++ b/GlazeWM.Domain/Workspaces/Commands/ActivateWorkspaceCommand.cs@@ -3,10 +3,10 @@ using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Workspaces.Commands{- class ActivateWorkspaceCommand : Command+ internal class ActivateWorkspaceCommand : Command{- public string WorkspaceName { get; private set; }- public Monitor TargetMonitor { get; private set; }+ public string WorkspaceName { get; }+ public Monitor TargetMonitor { get; }public ActivateWorkspaceCommand(string workspaceName, Monitor targetMonitor){diff --git a/GlazeWM.Domain/Workspaces/Commands/DeactivateWorkspaceCommand.cs b/GlazeWM.Domain/Workspaces/Commands/DeactivateWorkspaceCommand.csindex 66a9816a..8812ac3a 100644--- a/GlazeWM.Domain/Workspaces/Commands/DeactivateWorkspaceCommand.cs+++ b/GlazeWM.Domain/Workspaces/Commands/DeactivateWorkspaceCommand.cs@@ -2,7 +2,7 @@namespace GlazeWM.Domain.Workspaces.Commands{- class DeactivateWorkspaceCommand : Command+ internal class DeactivateWorkspaceCommand : Command{public Workspace Workspace { get; }diff --git a/GlazeWM.Domain/Workspaces/Commands/DisplayWorkspaceCommand.cs b/GlazeWM.Domain/Workspaces/Commands/DisplayWorkspaceCommand.csindex 4c8dd1db..14e293fc 100644--- a/GlazeWM.Domain/Workspaces/Commands/DisplayWorkspaceCommand.cs+++ b/GlazeWM.Domain/Workspaces/Commands/DisplayWorkspaceCommand.cs@@ -2,7 +2,7 @@namespace GlazeWM.Domain.Workspaces.Commands{- class DisplayWorkspaceCommand : Command+ internal class DisplayWorkspaceCommand : Command{public Workspace Workspace { get; }diff --git a/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.cs b/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.csindex 522cad0e..94775f05 100644--- a/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.cs+++ b/GlazeWM.Domain/Workspaces/Commands/MoveFocusedWindowToWorkspaceCommand.cs@@ -2,7 +2,7 @@namespace GlazeWM.Domain.Workspaces.Commands{- class MoveFocusedWindowToWorkspaceCommand : Command+ internal class MoveFocusedWindowToWorkspaceCommand : Command{public string WorkspaceName { get; }diff --git a/GlazeWM.Domain/Workspaces/Workspace.cs b/GlazeWM.Domain/Workspaces/Workspace.csindex 9faf4123..ad47a71d 100644--- a/GlazeWM.Domain/Workspaces/Workspace.cs+++ b/GlazeWM.Domain/Workspaces/Workspace.cs@@ -11,21 +11,19 @@ namespace GlazeWM.Domain.Workspaces{public string Name { get; set; }- private UserConfigService _userConfigService =+ private readonly UserConfigService _userConfigService =ServiceLocator.Provider.GetRequiredService<UserConfigService>();- private WorkspaceService _workspaceService =+ private readonly WorkspaceService _workspaceService =ServiceLocator.Provider.GetRequiredService<WorkspaceService>();public string DisplayName =>_userConfigService.GetWorkspaceConfigByName(Name).DisplayName ?? Name;- private int OuterGap => _userConfigService.UserConfig.Gaps.OuterGap;-/// <summary>/// Get height of bar after it's been automatically adjusted by DPI scaling./// </summary>- private int LogicalBarHeight+ private int _logicalBarHeight{get{@@ -34,10 +32,21 @@ namespace GlazeWM.Domain.Workspaces}}- public override int Height => Parent.Height - (OuterGap * 2) - LogicalBarHeight;- public override int Width => Parent.Width - (OuterGap * 2);- public override int X => Parent.X + OuterGap;- public override int Y => Parent.Y + OuterGap + (_userConfigService.UserConfig.Bar.Position == BarPosition.Top ? LogicalBarHeight : 0);+ private int _yOffset+ {+ get+ {+ var barPosition = _userConfigService.UserConfig.Bar.Position;+ return barPosition == BarPosition.Top ? _logicalBarHeight : 0;+ }+ }++ private int _outerGap => _userConfigService.UserConfig.Gaps.OuterGap;++ public override int Height => Parent.Height - (_outerGap * 2) - _logicalBarHeight;+ public override int Width => Parent.Width - (_outerGap * 2);+ public override int X => Parent.X + _outerGap;+ public override int Y => Parent.Y + _outerGap + _yOffset;/// <summary>/// Whether the workspace itself or a descendant container has focus.diff --git a/GlazeWM.Domain/Workspaces/WorkspaceService.cs b/GlazeWM.Domain/Workspaces/WorkspaceService.csindex 1428673a..3ba48df5 100644--- a/GlazeWM.Domain/Workspaces/WorkspaceService.cs+++ b/GlazeWM.Domain/Workspaces/WorkspaceService.cs@@ -7,8 +7,8 @@ namespace GlazeWM.Domain.Workspaces{public class WorkspaceService{- private ContainerService _containerService;- private UserConfigService _userConfigService;+ private readonly ContainerService _containerService;+ private readonly UserConfigService _userConfigService;public WorkspaceService(ContainerService containerService, UserConfigService userConfigService){@@ -42,7 +42,7 @@ namespace GlazeWM.Domain.Workspacesreturn inactiveWorkspaceConfigs.Select(config => config.Name);}- public Workspace GetWorkspaceFromChildContainer(Container container)+ public static Workspace GetWorkspaceFromChildContainer(Container container){return container.SelfAndAncestors.OfType<Workspace>().FirstOrDefault();}diff --git a/GlazeWM.Infrastructure/Bussing/Bus.cs b/GlazeWM.Infrastructure/Bussing/Bus.csindex 403b2c39..fbb610c4 100644--- a/GlazeWM.Infrastructure/Bussing/Bus.cs+++ b/GlazeWM.Infrastructure/Bussing/Bus.cs@@ -1,4 +1,5 @@-using GlazeWM.Infrastructure.WindowsApi.Events;+using GlazeWM.Infrastructure.Exceptions;+using GlazeWM.Infrastructure.WindowsApi.Events;using Microsoft.Extensions.DependencyInjection;using System;using System.Collections.Generic;@@ -14,8 +15,8 @@ namespace GlazeWM.Infrastructure.Bussing/// </summary>public sealed class Bus{- public readonly Subject<Event> Events = new Subject<Event>();- private static readonly Object _lockObj = new Object();+ public readonly Subject<Event> Events = new();+ private readonly object _lockObj = new();/// <summary>/// Sends command to appropriate command handler.@@ -40,7 +41,7 @@ namespace GlazeWM.Infrastructure.Bussingcatch (Exception error){HandleError(error);- throw error;+ throw;}}@@ -73,7 +74,7 @@ namespace GlazeWM.Infrastructure.Bussingcatch (Exception error){HandleError(error);- throw error;+ throw;}}@@ -88,7 +89,7 @@ namespace GlazeWM.Infrastructure.Bussing}// TODO: Move to dedicated logging service.- private void WriteToErrorLog(Exception error)+ private static void WriteToErrorLog(Exception error){var errorLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),diff --git a/GlazeWM.Infrastructure/Bussing/CommandResponse.cs b/GlazeWM.Infrastructure/Bussing/CommandResponse.csindex f9f68015..8d1d6f28 100644--- a/GlazeWM.Infrastructure/Bussing/CommandResponse.cs+++ b/GlazeWM.Infrastructure/Bussing/CommandResponse.cs@@ -1,14 +1,12 @@-using System;--namespace GlazeWM.Infrastructure.Bussing+namespace GlazeWM.Infrastructure.Bussing{public class CommandResponse{- public Boolean Success { get; private set; }- public static CommandResponse Ok = new CommandResponse { Success = true };- public static CommandResponse Fail = new CommandResponse { Success = false };+ public bool Success { get; private set; }+ public static readonly CommandResponse Ok = new() { Success = true };+ public static readonly CommandResponse Fail = new() { Success = false };- public CommandResponse(Boolean success = false)+ public CommandResponse(bool success = false){Success = success;}diff --git a/GlazeWM.Infrastructure/Exceptions/FatalUserException.cs b/GlazeWM.Infrastructure/Exceptions/FatalUserException.csindex 358265fa..cccc22fb 100644--- a/GlazeWM.Infrastructure/Exceptions/FatalUserException.cs+++ b/GlazeWM.Infrastructure/Exceptions/FatalUserException.cs@@ -1,8 +1,19 @@using System;-public class FatalUserException : Exception+namespace GlazeWM.Infrastructure.Exceptions{- public FatalUserException(string message) : base(message)+ public class FatalUserException : Exception{+ public FatalUserException()+ {+ }++ public FatalUserException(string message) : base(message)+ {+ }++ public FatalUserException(string message, Exception innerException) : base(message, innerException)+ {+ }}}diff --git a/GlazeWM.Infrastructure/GlazeWM.Infrastructure.csproj b/GlazeWM.Infrastructure/GlazeWM.Infrastructure.csprojindex 95b4e625..d5b487c9 100644--- a/GlazeWM.Infrastructure/GlazeWM.Infrastructure.csproj+++ b/GlazeWM.Infrastructure/GlazeWM.Infrastructure.csproj@@ -1,8 +1,7 @@-<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">+<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>- <TargetFramework>netcoreapp3.1</TargetFramework>- <RuntimeFrameworkVersion>3.1.0</RuntimeFrameworkVersion>+ <TargetFramework>net6.0-windows</TargetFramework><UseWindowsForms>true</UseWindowsForms><DebugType>embedded</DebugType></PropertyGroup>@@ -10,13 +9,13 @@<ItemGroup><PackageReferenceInclude="Microsoft.Extensions.DependencyInjection"- Version="3.1.1" />+ Version="6.0.0" /><PackageReferenceInclude="Newtonsoft.Json"Version="13.0.1" /><PackageReferenceInclude="System.Reactive"- Version="4.3.2" />+ Version="5.0.0" /><PackageReferenceInclude="YamlDotNet"Version="8.1.0" />diff --git a/GlazeWM.Infrastructure/ServiceLocator.cs b/GlazeWM.Infrastructure/ServiceLocator.csindex ea05ab28..49e1d0f8 100644--- a/GlazeWM.Infrastructure/ServiceLocator.cs+++ b/GlazeWM.Infrastructure/ServiceLocator.cs@@ -1,10 +1,8 @@using System;-using System.Collections.Generic;-using System.Text;namespace GlazeWM.Infrastructure{- public class ServiceLocator+ public static class ServiceLocator{public static IServiceProvider Provider { get; set; }}diff --git a/GlazeWM.Infrastructure/Utils/UnitsHelper.cs b/GlazeWM.Infrastructure/Utils/UnitsHelper.csindex 064de90f..a5f31e7a 100644--- a/GlazeWM.Infrastructure/Utils/UnitsHelper.cs+++ b/GlazeWM.Infrastructure/Utils/UnitsHelper.cs@@ -8,7 +8,7 @@ namespace GlazeWM.Infrastructure.Utils{public static int TrimUnits(string amountWithUnits){- var unitsRegex = new Regex(@"(%|ppt|px)");+ var unitsRegex = new Regex("(%|ppt|px)");var amount = unitsRegex.Replace(amountWithUnits, "").Trim();return Convert.ToInt32(amount, CultureInfo.InvariantCulture);}diff --git a/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.cs b/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.csindex bf1d6c6a..24d5383b 100644--- a/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.cs+++ b/GlazeWM.Infrastructure/WindowsApi/Enums/EventConstant.cs@@ -5,15 +5,13 @@/// </summary>public enum EventConstant : uint{- EVENT_OBJECT_LOCATIONCHANGE = 0x800B,EVENT_SYSTEM_FOREGROUND = 0x0003,+ EVENT_SYSTEM_MOVESIZEEND = 0x000B,EVENT_SYSTEM_MINIMIZESTART = 0x0016,EVENT_SYSTEM_MINIMIZEEND = 0x0017,- EVENT_SYSTEM_MOVESIZEEND = 0x000B,EVENT_OBJECT_DESTROY = 0x8001,EVENT_OBJECT_SHOW = 0x8002,EVENT_OBJECT_HIDE = 0x8003,- EVENT_OBJECT_CLOAKED = 0x8017,- EVENT_OBJECT_UNCLOAKED = 0x8018,+ EVENT_OBJECT_LOCATIONCHANGE = 0x800B,}}diff --git a/GlazeWM.Infrastructure/WindowsApi/Enums/ObjectIdentifier.cs b/GlazeWM.Infrastructure/WindowsApi/Enums/ObjectIdentifier.csindex 3a4a57f7..1f797f42 100644--- a/GlazeWM.Infrastructure/WindowsApi/Enums/ObjectIdentifier.cs+++ b/GlazeWM.Infrastructure/WindowsApi/Enums/ObjectIdentifier.cs@@ -1,8 +1,4 @@-using System;-using System.Collections.Generic;-using System.Text;--namespace GlazeWM.Infrastructure.WindowsApi.Enums+namespace GlazeWM.Infrastructure.WindowsApi.Enums{/// <summary>/// Identifies categories of accessible objects within a window (including the window object itself).diff --git a/GlazeWM.Infrastructure/WindowsApi/KeybindingService.cs b/GlazeWM.Infrastructure/WindowsApi/KeybindingService.csindex 4f242e1b..8edd074a 100644--- a/GlazeWM.Infrastructure/WindowsApi/KeybindingService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/KeybindingService.cs@@ -5,7 +5,6 @@ using System.Linq;using System.Runtime.InteropServices;using System.Threading;using System.Windows.Forms;-using GlazeWM.Infrastructure.Bussing;using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Infrastructure.WindowsApi@@ -24,19 +23,20 @@ namespace GlazeWM.Infrastructure.WindowsApipublic class KeybindingService{- private static readonly uint WM_KEYDOWN = 0x100;- private static readonly uint WM_SYSKEYDOWN = 0x104;+ private const uint WM_KEYDOWN = 0x100;+ private const uint WM_SYSKEYDOWN = 0x104;/// <summary>/// Registered keybindings grouped by trigger key (ie. the final key in a key combination)./// </summary>- private Dictionary<Keys, List<Keybinding>> _keybindingsByTriggerKey- = new Dictionary<Keys, List<Keybinding>>();+ private readonly Dictionary<Keys, List<Keybinding>> _keybindingsByTriggerKey = new();public void Start(){- var thread = new Thread(() => CreateKeybindingHook());- thread.Name = "GlazeWMKeybindingService";+ var thread = new Thread(() => CreateKeybindingHook())+ {+ Name = "GlazeWMKeybindingService"+ };thread.Start();}@@ -61,19 +61,16 @@ namespace GlazeWM.Infrastructure.WindowsApi_keybindingsByTriggerKey.Add(triggerKey, new List<Keybinding>() { keybinding });}- private string FormatKeybinding(string key)+ private static string FormatKeybinding(string key){- var isNumeric = int.TryParse(key, out int _);-- if (isNumeric)- return $"D{key}";+ var isNumeric = int.TryParse(key, out var _);- return key;+ return isNumeric ? $"D{key}" : key;}private void CreateKeybindingHook(){- SetWindowsHookEx(HookType.WH_KEYBOARD_LL, KeybindingHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);+ _ = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, KeybindingHookProc, Process.GetCurrentProcess().MainModule.BaseAddress, 0);// `SetWindowsHookEx` requires a message loop within the thread that is executing the code.Application.Run();@@ -99,7 +96,7 @@ namespace GlazeWM.Infrastructure.WindowsApiif (registeredKeybindings == null)return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);- Dictionary<Keys, bool> cachedKeyStates = new Dictionary<Keys, bool>();+ var cachedKeyStates = new Dictionary<Keys, bool>();var matchedKeybindings = registeredKeybindings.Where(keybinding =>{@@ -117,7 +114,7 @@ namespace GlazeWM.Infrastructure.WindowsApi// If multiple keybindings match the user input, call the longest key combination.var longestKeybinding = matchedKeybindings- .OrderByDescending(keybinding => keybinding.KeyCombination.Count())+ .OrderByDescending(keybinding => keybinding.KeyCombination.Count).FirstOrDefault();if (longestKeybinding == null)@@ -133,24 +130,21 @@ namespace GlazeWM.Infrastructure.WindowsApi/// <summary>/// Get whether the given key is down. Check alternate versions of modifier keys./// </summary>- private bool IsKeyDown(Keys key)+ private static bool IsKeyDown(Keys key){- if (key == Keys.Alt)- return IsKeyDownRaw(Keys.LMenu) || IsKeyDownRaw(Keys.RMenu);-- if (key == Keys.Shift)- return IsKeyDownRaw(Keys.LShiftKey) || IsKeyDownRaw(Keys.RShiftKey);-- if (key == Keys.Control)- return IsKeyDownRaw(Keys.LControlKey) || IsKeyDownRaw(Keys.RControlKey);-- return IsKeyDownRaw(key);+ return key switch+ {+ Keys.Alt => IsKeyDownRaw(Keys.LMenu) || IsKeyDownRaw(Keys.RMenu),+ Keys.Shift => IsKeyDownRaw(Keys.LShiftKey) || IsKeyDownRaw(Keys.RShiftKey),+ Keys.Control => IsKeyDownRaw(Keys.LControlKey) || IsKeyDownRaw(Keys.RControlKey),+ _ => IsKeyDownRaw(key),+ };}/// <summary>/// Get whether the given key is down. If the high-order bit is 1, the key is down; otherwise, it is up./// </summary>- private bool IsKeyDownRaw(Keys key)+ private static bool IsKeyDownRaw(Keys key){return (GetKeyState(key) & 0x8000) == 0x8000;}diff --git a/GlazeWM.Infrastructure/WindowsApi/SetWindowPosFlags.cs b/GlazeWM.Infrastructure/WindowsApi/SetWindowPosFlags.csindex c998d13e..b9eae4d7 100644--- a/GlazeWM.Infrastructure/WindowsApi/SetWindowPosFlags.cs+++ b/GlazeWM.Infrastructure/WindowsApi/SetWindowPosFlags.cs@@ -8,14 +8,26 @@ namespace GlazeWM.Infrastructure.WindowsApi[Flags]public enum SetWindowPosFlags : uint{- /// <summary>If the calling thread and the thread that owns the window are attached to different input queues,- /// the system posts the request to the thread that owns the window. This prevents the calling thread from- /// blocking its execution while other threads process the request.</summary>- /// <remarks>SWP_ASYNCWINDOWPOS</remarks>- AsynchronousWindowPosition = 0x4000,- /// <summary>Prevents generation of the WM_SYNCPAINT message.</summary>- /// <remarks>SWP_DEFERERASE</remarks>- DeferErase = 0x2000,+ /// <summary>Retains the current size (ignores the cx and cy parameters).</summary>+ /// <remarks>SWP_NOSIZE</remarks>+ IgnoreResize = 0x0001,+ /// <summary>Retains the current position (ignores X and Y parameters).</summary>+ /// <remarks>SWP_NOMOVE</remarks>+ IgnoreMove = 0x0002,+ /// <summary>Retains the current Z order (ignores the hWndInsertAfter parameter).</summary>+ /// <remarks>SWP_NOZORDER</remarks>+ IgnoreZOrder = 0x0004,+ /// <summary>Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to+ /// the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent+ /// window uncovered as a result of the window being moved. When this flag is set, the application must+ /// explicitly invalidate or redraw any parts of the window and parent window that need redrawing.</summary>+ /// <remarks>SWP_NOREDRAW</remarks>+ DoNotRedraw = 0x0008,+ /// <summary>Does not activate the window. If this flag is not set, the window is activated and moved to the+ /// top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter+ /// parameter).</summary>+ /// <remarks>SWP_NOACTIVATE</remarks>+ DoNotActivate = 0x0010,/// <summary>Draws a frame (defined in the window's class description) around the window.</summary>/// <remarks>SWP_DRAWFRAME</remarks>DrawFrame = 0x0020,@@ -24,45 +36,33 @@ namespace GlazeWM.Infrastructure.WindowsApi/// is sent only when the window's size is being changed.</summary>/// <remarks>SWP_FRAMECHANGED</remarks>FrameChanged = 0x0020,+ /// <summary>Displays the window.</summary>+ /// <remarks>SWP_SHOWWINDOW</remarks>+ ShowWindow = 0x0040,/// <summary>Hides the window.</summary>/// <remarks>SWP_HIDEWINDOW</remarks>HideWindow = 0x0080,- /// <summary>Does not activate the window. If this flag is not set, the window is activated and moved to the- /// top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter- /// parameter).</summary>- /// <remarks>SWP_NOACTIVATE</remarks>- DoNotActivate = 0x0010,/// <summary>Discards the entire contents of the client area. If this flag is not specified, the valid/// contents of the client area are saved and copied back into the client area after the window is sized or/// repositioned.</summary>/// <remarks>SWP_NOCOPYBITS</remarks>DoNotCopyBits = 0x0100,- /// <summary>Retains the current position (ignores X and Y parameters).</summary>- /// <remarks>SWP_NOMOVE</remarks>- IgnoreMove = 0x0002,/// <summary>Does not change the owner window's position in the Z order.</summary>/// <remarks>SWP_NOOWNERZORDER</remarks>DoNotChangeOwnerZOrder = 0x0200,- /// <summary>Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to- /// the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent- /// window uncovered as a result of the window being moved. When this flag is set, the application must- /// explicitly invalidate or redraw any parts of the window and parent window that need redrawing.</summary>- /// <remarks>SWP_NOREDRAW</remarks>- DoNotRedraw = 0x0008,/// <summary>Same as the SWP_NOOWNERZORDER flag.</summary>/// <remarks>SWP_NOREPOSITION</remarks>DoNotReposition = 0x0200,/// <summary>Prevents the window from receiving the WM_WINDOWPOSCHANGING message.</summary>/// <remarks>SWP_NOSENDCHANGING</remarks>DoNotSendChangingEvent = 0x0400,- /// <summary>Retains the current size (ignores the cx and cy parameters).</summary>- /// <remarks>SWP_NOSIZE</remarks>- IgnoreResize = 0x0001,- /// <summary>Retains the current Z order (ignores the hWndInsertAfter parameter).</summary>- /// <remarks>SWP_NOZORDER</remarks>- IgnoreZOrder = 0x0004,- /// <summary>Displays the window.</summary>- /// <remarks>SWP_SHOWWINDOW</remarks>- ShowWindow = 0x0040,+ /// <summary>Prevents generation of the WM_SYNCPAINT message.</summary>+ /// <remarks>SWP_DEFERERASE</remarks>+ DeferErase = 0x2000,+ /// <summary>If the calling thread and the thread that owns the window are attached to different input queues,+ /// the system posts the request to the thread that owns the window. This prevents the calling thread from+ /// blocking its execution while other threads process the request.</summary>+ /// <remarks>SWP_ASYNCWINDOWPOS</remarks>+ AsynchronousWindowPosition = 0x4000,}}diff --git a/GlazeWM.Infrastructure/WindowsApi/SystemEventService.cs b/GlazeWM.Infrastructure/WindowsApi/SystemEventService.csindex f4b131c0..254e5ce3 100644--- a/GlazeWM.Infrastructure/WindowsApi/SystemEventService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/SystemEventService.cs@@ -7,7 +7,7 @@ namespace GlazeWM.Infrastructure.WindowsApi{public class SystemEventService{- private Bus _bus;+ private readonly Bus _bus;public SystemEventService(Bus bus){@@ -17,7 +17,7 @@ namespace GlazeWM.Infrastructure.WindowsApipublic void Start(){// TODO: Unsubscribe on application exit.- SystemEvents.DisplaySettingsChanged += new EventHandler(OnDisplaySettingsChanged);+ SystemEvents.DisplaySettingsChanged += OnDisplaySettingsChanged;}private void OnDisplaySettingsChanged(object sender, EventArgs e)diff --git a/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs b/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.csindex e5d25fc0..3104d444 100644--- a/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/SystemTrayService.cs@@ -5,13 +5,12 @@ using System.Windows.Forms;using System.Threading;using GlazeWM.Infrastructure.WindowsApi.Events;using System.Reflection;-using System.IO;namespace GlazeWM.Infrastructure.WindowsApi{public class SystemTrayService{- private Bus _bus;+ private readonly Bus _bus;public SystemTrayService(Bus bus){@@ -20,8 +19,10 @@ namespace GlazeWM.Infrastructure.WindowsApipublic void AddToSystemTray(){- var thread = new Thread(() => PopulateSystemTray());- thread.Name = "GlazeWMSystemTray";+ var thread = new Thread(() => PopulateSystemTray())+ {+ Name = "GlazeWMSystemTray"+ };thread.Start();}@@ -32,26 +33,25 @@ namespace GlazeWM.Infrastructure.WindowsApicontextMenuStrip.Items.Add("Exit", null, SignalApplicationExit);var assembly = Assembly.GetEntryAssembly();- var iconResourceName = "GlazeWM.Bootstrapper.icon.ico";+ const string iconResourceName = "GlazeWM.Bootstrapper.icon.ico";// Get the embedded icon resource from the entry assembly.- using (Stream stream = assembly.GetManifestResourceStream(iconResourceName))+ using (var stream = assembly.GetManifestResourceStream(iconResourceName)){- var notificationIcon = new NotifyIcon()+ var notificationIcon = new NotifyIcon{Icon = new Icon(stream),ContextMenuStrip = contextMenuStrip,- Text = "GlazeWM"+ Text = "GlazeWM",+ Visible = true};-- notificationIcon.Visible = true;}// System tray requires a message loop within the thread that is executing the code.Application.Run();}- void SignalApplicationExit(object sender, EventArgs e)+ private void SignalApplicationExit(object sender, EventArgs e){// TODO: Call `Dispose()` on `notificationIcon`._bus.RaiseEvent(new ApplicationExitingEvent());diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowEventService.cs b/GlazeWM.Infrastructure/WindowsApi/WindowEventService.csindex bea181c2..d70e38cd 100644--- a/GlazeWM.Infrastructure/WindowsApi/WindowEventService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/WindowEventService.cs@@ -10,8 +10,8 @@ namespace GlazeWM.Infrastructure.WindowsApi{public class WindowEventService{- private Bus _bus;- private static readonly int CHILDID_SELF = 0;+ private readonly Bus _bus;+ private const int CHILDID_SELF = 0;public WindowEventService(Bus bus){@@ -20,8 +20,10 @@ namespace GlazeWM.Infrastructure.WindowsApipublic void Start(){- var thread = new Thread(() => CreateWindowEventHook());- thread.Name = "GlazeWMWindowHooks";+ var thread = new Thread(() => CreateWindowEventHook())+ {+ Name = "GlazeWMWindowHooks"+ };thread.Start();}@@ -46,33 +48,21 @@ namespace GlazeWM.Infrastructure.WindowsApiif (!isWindowEvent)return;- switch (eventType)+ Event eventToRaise = eventType switch{- case EventConstant.EVENT_OBJECT_LOCATIONCHANGE:- _bus.RaiseEvent(new WindowLocationChangedEvent(hwnd));- break;- case EventConstant.EVENT_SYSTEM_FOREGROUND:- _bus.RaiseEvent(new WindowFocusedEvent(hwnd));- break;- case EventConstant.EVENT_SYSTEM_MINIMIZESTART:- _bus.RaiseEvent(new WindowMinimizedEvent(hwnd));- break;- case EventConstant.EVENT_SYSTEM_MINIMIZEEND:- _bus.RaiseEvent(new WindowMinimizeEndedEvent(hwnd));- break;- case EventConstant.EVENT_SYSTEM_MOVESIZEEND:- _bus.RaiseEvent(new WindowMovedOrResizedEvent(hwnd));- break;- case EventConstant.EVENT_OBJECT_DESTROY:- _bus.RaiseEvent(new WindowDestroyedEvent(hwnd));- break;- case EventConstant.EVENT_OBJECT_SHOW:- _bus.RaiseEvent(new WindowShownEvent(hwnd));- break;- case EventConstant.EVENT_OBJECT_HIDE:- _bus.RaiseEvent(new WindowHiddenEvent(hwnd));- break;- }+ EventConstant.EVENT_OBJECT_LOCATIONCHANGE => new WindowLocationChangedEvent(hwnd),+ EventConstant.EVENT_SYSTEM_FOREGROUND => new WindowFocusedEvent(hwnd),+ EventConstant.EVENT_SYSTEM_MINIMIZESTART => new WindowMinimizedEvent(hwnd),+ EventConstant.EVENT_SYSTEM_MINIMIZEEND => new WindowMinimizeEndedEvent(hwnd),+ EventConstant.EVENT_SYSTEM_MOVESIZEEND => new WindowMovedOrResizedEvent(hwnd),+ EventConstant.EVENT_OBJECT_DESTROY => new WindowDestroyedEvent(hwnd),+ EventConstant.EVENT_OBJECT_SHOW => new WindowShownEvent(hwnd),+ EventConstant.EVENT_OBJECT_HIDE => new WindowHiddenEvent(hwnd),+ _ => null,+ };++ if (eventToRaise is not null)+ _bus.RaiseEvent((dynamic)eventToRaise);}}}diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.csindex f60c0e79..adcfea3a 100644--- a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs@@ -6,22 +6,23 @@ using System.Windows.Forms;namespace GlazeWM.Infrastructure.WindowsApi{- public class WindowsApiService+ public static class WindowsApiService{+ [Flags]public enum SWP : uint{- SWP_SHOWWINDOW = 0x0040,- SWP_HIDEWINDOW = 0x0080,+ SWP_NOSIZE = 0x0001,+ SWP_NOMOVE = 0x0002,SWP_NOZORDER = 0x0004,SWP_NOREDRAW = 0x0008,SWP_NOACTIVATE = 0x0010,- SWP_NOMOVE = 0x0002,- SWP_NOSIZE = 0x0001,SWP_FRAMECHANGED = 0x0020,+ SWP_SHOWWINDOW = 0x0040,+ SWP_HIDEWINDOW = 0x0080,SWP_NOCOPYBITS = 0x0100,SWP_NOOWNERZORDER = 0x0200,- SWP_DEFERERASE = 0x2000,SWP_NOSENDCHANGING = 0x0400,+ SWP_DEFERERASE = 0x2000,SWP_ASYNCWINDOWPOS = 0x4000}@@ -32,32 +33,32 @@ namespace GlazeWM.Infrastructure.WindowsApipublic enum WS : uint{WS_OVERLAPPED = 0x00000000,- WS_POPUP = 0x80000000,- WS_CHILD = 0x40000000,- WS_MINIMIZE = 0x20000000,- WS_VISIBLE = 0x10000000,- WS_DISABLED = 0x08000000,- WS_CLIPSIBLINGS = 0x04000000,- WS_CLIPCHILDREN = 0x02000000,- WS_MAXIMIZE = 0x01000000,- WS_BORDER = 0x00800000,- WS_DLGFRAME = 0x00400000,- WS_VSCROLL = 0x00200000,- WS_HSCROLL = 0x00100000,- WS_SYSMENU = 0x00080000,- WS_THICKFRAME = 0x00040000,- WS_GROUP = 0x00020000,+ WS_TILED = WS_OVERLAPPED,WS_TABSTOP = 0x00010000,- WS_MINIMIZEBOX = 0x00020000,WS_MAXIMIZEBOX = 0x00010000,- WS_CAPTION = WS_BORDER | WS_DLGFRAME,- WS_TILED = WS_OVERLAPPED,- WS_ICONIC = WS_MINIMIZE,+ WS_GROUP = 0x00020000,+ WS_MINIMIZEBOX = 0x00020000,+ WS_THICKFRAME = 0x00040000,WS_SIZEBOX = WS_THICKFRAME,+ WS_SYSMENU = 0x00080000,+ WS_HSCROLL = 0x00100000,+ WS_VSCROLL = 0x00200000,+ WS_DLGFRAME = 0x00400000,+ WS_BORDER = 0x00800000,+ WS_CAPTION = WS_BORDER | WS_DLGFRAME,WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,- WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU,- WS_CHILDWINDOW = WS_CHILD+ WS_MAXIMIZE = 0x01000000,+ WS_CLIPCHILDREN = 0x02000000,+ WS_CLIPSIBLINGS = 0x04000000,+ WS_DISABLED = 0x08000000,+ WS_VISIBLE = 0x10000000,+ WS_MINIMIZE = 0x20000000,+ WS_ICONIC = WS_MINIMIZE,+ WS_CHILD = 0x40000000,+ WS_CHILDWINDOW = WS_CHILD,+ WS_POPUP = 0x80000000,+ WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU}/// <summary>@@ -66,6 +67,9 @@ namespace GlazeWM.Infrastructure.WindowsApi[Flags]public enum WS_EX : uint{+ WS_EX_LEFT = 0x0000,+ WS_EX_LTRREADING = 0x0000,+ WS_EX_RIGHTSCROLLBAR = 0x0000,WS_EX_DLGMODALFRAME = 0x0001,WS_EX_NOPARENTNOTIFY = 0x0004,WS_EX_TOPMOST = 0x0008,@@ -74,19 +78,16 @@ namespace GlazeWM.Infrastructure.WindowsApiWS_EX_MDICHILD = 0x0040,WS_EX_TOOLWINDOW = 0x0080,WS_EX_WINDOWEDGE = 0x0100,+ WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST,WS_EX_CLIENTEDGE = 0x0200,+ WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE,WS_EX_CONTEXTHELP = 0x0400,WS_EX_RIGHT = 0x1000,- WS_EX_LEFT = 0x0000,WS_EX_RTLREADING = 0x2000,- WS_EX_LTRREADING = 0x0000,WS_EX_LEFTSCROLLBAR = 0x4000,- WS_EX_RIGHTSCROLLBAR = 0x0000,WS_EX_CONTROLPARENT = 0x10000,WS_EX_STATICEDGE = 0x20000,WS_EX_APPWINDOW = 0x40000,- WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),- WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST),WS_EX_LAYERED = 0x00080000,WS_EX_NOINHERITLAYOUT = 0x00100000,WS_EX_LAYOUTRTL = 0x00400000,@@ -115,8 +116,8 @@ namespace GlazeWM.Infrastructure.WindowsApiDWMWA_LAST}- public static int GWL_STYLE = -16;- public static int GWL_EXSTYLE = -20;+ public const int GWL_STYLE = -16;+ public const int GWL_EXSTYLE = -20;public enum GW : uint{@@ -139,7 +140,9 @@ namespace GlazeWM.Infrastructure.WindowsApiprivate static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int index);public static IntPtr GetWindowLongPtr(IntPtr hWnd, int index)- => Environment.Is64BitProcess ? GetWindowLongPtr64(hWnd, index) : GetWindowLongPtr32(hWnd, index);+ {+ return Environment.Is64BitProcess ? GetWindowLongPtr64(hWnd, index) : GetWindowLongPtr32(hWnd, index);+ }[DllImport("user32.dll", EntryPoint = "SetWindowLong")]private static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int index, IntPtr newLong);@@ -148,7 +151,9 @@ namespace GlazeWM.Infrastructure.WindowsApiprivate static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int index, IntPtr newLong);public static IntPtr SetWindowLongPtr(IntPtr hWnd, int index, IntPtr newLong)- => Environment.Is64BitProcess ? SetWindowLongPtr64(hWnd, index, newLong) : SetWindowLongPtr32(hWnd, index, newLong);+ {+ return Environment.Is64BitProcess ? SetWindowLongPtr64(hWnd, index, newLong) : SetWindowLongPtr32(hWnd, index, newLong);+ }[DllImport("user32.dll", SetLastError = true)]public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SWP uFlags);@@ -195,13 +200,13 @@ namespace GlazeWM.Infrastructure.WindowsApi[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]public static extern int GetWindowTextLength(IntPtr hWnd);- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]public static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString, int nMaxCount);[DllImport("user32.dll", SetLastError = true)]public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);[DllImport("user32.dll")]@@ -259,7 +264,7 @@ namespace GlazeWM.Infrastructure.WindowsApipublic delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);- public enum HookType : int+ public enum HookType{WH_KEYBOARD_LL = 13,WH_MOUSE_LL = 14@@ -292,7 +297,7 @@ namespace GlazeWM.Infrastructure.WindowsApipublic int Flags;/// <summary>- /// The time stamp stamp for this message, equivalent to what GetMessageTime would return for this message.+ /// The time stamp for this message, equivalent to what GetMessageTime would return for this message./// </summary>public int TimeStamp;@@ -342,12 +347,12 @@ namespace GlazeWM.Infrastructure.WindowsApipublic enum DpiAwarenessContext{- Context_Undefined = 0,- Context_Unaware = -1,- Context_SystemAware = -2,- Context_PerMonitorAware = -3,+ Context_UnawareGdiScaled = -5,Context_PerMonitorAwareV2 = -4,- Context_UnawareGdiScaled = -5+ Context_PerMonitorAware = -3,+ Context_SystemAware = -2,+ Context_Unaware = -1,+ Context_Undefined = 0}[DllImport("user32.dll", SetLastError = true)]diff --git a/GlazeWM.Infrastructure/Yaml/ValidatingDeserializer.cs b/GlazeWM.Infrastructure/Yaml/ValidatingDeserializer.csindex 999bc961..3a417448 100644--- a/GlazeWM.Infrastructure/Yaml/ValidatingDeserializer.cs+++ b/GlazeWM.Infrastructure/Yaml/ValidatingDeserializer.cs@@ -14,10 +14,10 @@ namespace GlazeWM.Infrastructure.Yaml_nodeDeserializer = nodeDeserializer;}- public bool Deserialize(IParser parser, Type expectedType,+ public bool Deserialize(IParser reader, Type expectedType,Func<IParser, Type, object> nestedObjectDeserializer, out object value){- if (!_nodeDeserializer.Deserialize(parser, expectedType, nestedObjectDeserializer, out value))+ if (!_nodeDeserializer.Deserialize(reader, expectedType, nestedObjectDeserializer, out value))return false;// Validate using the provided data annotations (eg. `[Required]`).diff --git a/GlazeWM.Infrastructure/Yaml/YamlDeserializationService.cs b/GlazeWM.Infrastructure/Yaml/YamlDeserializationService.csindex 485112d2..95e6a7c7 100644--- a/GlazeWM.Infrastructure/Yaml/YamlDeserializationService.cs+++ b/GlazeWM.Infrastructure/Yaml/YamlDeserializationService.cs@@ -8,15 +8,15 @@ namespace GlazeWM.Infrastructure.Yaml{public class YamlDeserializationService{- IDeserializer _yamlDeserializer = new DeserializerBuilder()+ private readonly IDeserializer _yamlDeserializer = new DeserializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance).Build();- ISerializer _jsonSerializer = new SerializerBuilder()+ private readonly ISerializer _jsonSerializer = new SerializerBuilder().JsonCompatible().Build();- JsonSerializerSettings _jsonDeserializerSettings = new JsonSerializerSettings+ private readonly JsonSerializerSettings _jsonDeserializerSettings = new(){MissingMemberHandling = MissingMemberHandling.Error,ContractResolver = new DefaultContractResolver@@ -38,4 +38,3 @@ namespace GlazeWM.Infrastructure.Yaml}}}-