Skip to content

Commit

Permalink
Change core classes to be internal where possible (#102)
Browse files Browse the repository at this point in the history
As part of #100, decreased the number of classes from the `Whim` namespace exposed to other projects. The static method `Window.CreateWindow` had to be moved to `IWindow` to provide external access.
  • Loading branch information
dalyIsaac authored Jul 2, 2022
1 parent af5bff6 commit 768798d
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/Whim.Bar/BarWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;

namespace Whim.Bar;

Expand All @@ -20,7 +20,7 @@ public BarWindow(IConfigContext configContext, BarConfig barConfig, IMonitor mon

UIElementExtensions.InitializeComponent(this, "Whim.Bar", "BarWindow");

IWindow? window = Window.CreateWindow(this.GetHandle(), _configContext);
IWindow? window = IWindow.CreateWindow(this.GetHandle(), _configContext);
if (window == null)
{
throw new BarException("Window was unexpectedly null");
Expand Down
2 changes: 1 addition & 1 deletion src/Whim.Runner/Whim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class Whim
internal static void Start()
{
// Create an empty Whim config context.
IConfigContext configContext = new ConfigContext();
IConfigContext configContext = Engine.CreateConfigContext();
Exception? startupException = null;

try
Expand Down
2 changes: 1 addition & 1 deletion src/Whim.TreeLayout/PhantomNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected PhantomNode(IWindow windowModel, Microsoft.UI.Xaml.Window? phantomWind
{
PhantomWindow phantomWindow = new();

IWindow? windowModel = Whim.Window.CreateWindow(phantomWindow.GetHandle(), configContext);
IWindow? windowModel = Whim.IWindow.CreateWindow(phantomWindow.GetHandle(), configContext);

if (windowModel == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Whim/Commands/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Whim;

public class CommandManager : ICommandManager
internal class CommandManager : ICommandManager
{
private readonly ICommandItems _commandItems;
private readonly IKeybindManager _keybindManager;
Expand Down
2 changes: 1 addition & 1 deletion src/Whim/ConfigContext/ConfigContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Whim;
/// <c>ConfigContext</c> also contains other associated state and functionality, like the
/// <see cref="Logger"/>.
/// </summary>
public class ConfigContext : IConfigContext
internal class ConfigContext : IConfigContext
{
public Logger Logger { get; set; }
public IWorkspaceManager WorkspaceManager { get; set; }
Expand Down
21 changes: 21 additions & 0 deletions src/Whim/Engine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Whim;

/// <summary>
/// Exposes the Whim <see cref="IConfigContext"/>.
/// </summary>
public static class Engine
{
private static IConfigContext? _configContext;

/// <summary>
/// Get the <see cref="IConfigContext"/>.
/// </summary>
public static IConfigContext CreateConfigContext()
{
if (_configContext == null)
{
_configContext = new ConfigContext();
}
return _configContext;
}
}
4 changes: 2 additions & 2 deletions src/Whim/Monitor/Monitor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Whim;
namespace Whim;

/// <summary>
/// Implementation of <see cref="IMonitor"/>.
/// </summary>
public class Monitor : IMonitor
internal class Monitor : IMonitor
{
/// <summary>
/// Internal representation of a screen, based on the WinForms Screen class.
Expand Down
2 changes: 1 addition & 1 deletion src/Whim/Monitor/MonitorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Whim;
/// <summary>
/// Implementation of <see cref="IMonitorManager"/>.
/// </summary>
public class MonitorManager : IMonitorManager
internal class MonitorManager : IMonitorManager
{
private readonly IConfigContext _configContext;

Expand Down
2 changes: 1 addition & 1 deletion src/Whim/Native/WindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ IConfigContext configContext
UIElementExtensions.InitializeComponent(uiWindow, componentNamespace, componentPath);

HWND hwnd = new(WinRT.Interop.WindowNative.GetWindowHandle(uiWindow));
IWindow? window = Window.CreateWindow(GetHandle(uiWindow), configContext);
IWindow? window = IWindow.CreateWindow(GetHandle(uiWindow), configContext);
if (window == null)
{
throw new InitializeWindowException("Window was unexpectedly null");
Expand Down
2 changes: 1 addition & 1 deletion src/Whim/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Whim;

public class PluginManager : IPluginManager
internal class PluginManager : IPluginManager
{
private readonly List<IPlugin> _plugins = new();
private bool disposedValue;
Expand Down
2 changes: 1 addition & 1 deletion src/Whim/Router/FilterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Whim;

public class FilterManager : IFilterManager
internal class FilterManager : IFilterManager
{

#region Filters for specific properties
Expand Down
4 changes: 2 additions & 2 deletions src/Whim/Router/RouterManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Whim;

public class RouterManager : IRouterManager
internal class RouterManager : IRouterManager
{
private readonly IConfigContext _configContext;
private readonly List<Router> _routers = new();
Expand Down
21 changes: 21 additions & 0 deletions src/Whim/Window/IWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Windows.Win32.Foundation;

namespace Whim;
Expand Down Expand Up @@ -110,4 +111,24 @@ public interface IWindow
/// Quits the window.
/// </summary>
public void Close();

/// <summary>
/// Create a new window. If the window cannot be created, <c>null</c> is returned.
/// </summary>
/// <param name="hwnd">The handle of the window.</param>
/// <param name="configContext">The configuration context.</param>
public static IWindow? CreateWindow(HWND hwnd, IConfigContext configContext)
{
Logger.Debug($"Registering window {hwnd.Value}");

try
{
return new Window(hwnd, configContext);
}
catch (Exception e)
{
Logger.Error($"Could not create a Window instance for {hwnd.Value}, {e.Message}");
return null;
}
}
}
19 changes: 2 additions & 17 deletions src/Whim/Window/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Whim;

public class Window : IWindow
internal class Window : IWindow
{
private readonly IConfigContext _configContext;

Expand Down Expand Up @@ -126,7 +126,7 @@ public void ShowNormal()
/// <param name="hwnd"></param>
/// <param name="configContext"></param>
/// <exception cref="Win32Exception"></exception>
private Window(HWND hwnd, IConfigContext configContext)
internal Window(HWND hwnd, IConfigContext configContext)
{
_configContext = configContext;
Handle = hwnd;
Expand Down Expand Up @@ -159,21 +159,6 @@ private Window(HWND hwnd, IConfigContext configContext)
};
}

public static Window? CreateWindow(HWND hwnd, IConfigContext configContext)
{
Logger.Debug($"Registering window {hwnd.Value}");

try
{
return new Window(hwnd, configContext);
}
catch (Exception e)
{
Logger.Error($"Could not create a Window instance for {hwnd.Value}, {e.Message}");
return null;
}
}

public override bool Equals(object? obj)
{
if (obj == null || GetType() != obj.GetType())
Expand Down
4 changes: 2 additions & 2 deletions src/Whim/Window/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Whim;

public class WindowManager : IWindowManager
internal class WindowManager : IWindowManager
{
private readonly IConfigContext _configContext;

Expand Down Expand Up @@ -209,7 +209,7 @@ private void WindowsEventHook(HWINEVENTHOOK hWinEventHook, uint eventType, HWND

Logger.Debug($"Registering window {hwnd.Value}");

Window? window = Window.CreateWindow(hwnd, _configContext);
IWindow? window = IWindow.CreateWindow(hwnd, _configContext);

if (window == null || _configContext.FilterManager.ShouldBeIgnored(window))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Whim/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Whim;

public class Workspace : IWorkspace
internal class Workspace : IWorkspace
{
private readonly IConfigContext _configContext;

Expand Down
4 changes: 2 additions & 2 deletions src/Whim/Workspace/WorkspaceManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -8,7 +8,7 @@ namespace Whim;
/// <summary>
/// Implementation of <see cref="IWorkspaceManager"/>.
/// </summary>
public class WorkspaceManager : IWorkspaceManager
internal class WorkspaceManager : IWorkspaceManager
{
private readonly IConfigContext _configContext;

Expand Down

0 comments on commit 768798d

Please sign in to comment.