Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Switched from saying register/unregister to add/remove #160

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Whim.FocusIndicator/FocusIndicatorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void PreInitialize()

_configContext.WindowManager.WindowFocused += WindowManager_WindowFocused;

_configContext.WindowManager.WindowRegistered += WindowManager_EventSink;
_configContext.WindowManager.WindowUnregistered += WindowManager_EventSink;
_configContext.WindowManager.WindowAdded += WindowManager_EventSink;
_configContext.WindowManager.WindowRemoved += WindowManager_EventSink;
_configContext.WindowManager.WindowMoveStart += WindowManager_EventSink;
_configContext.WindowManager.WindowMoved += WindowManager_EventSink;
_configContext.WindowManager.WindowMinimizeStart += WindowManager_EventSink;
Expand Down Expand Up @@ -141,8 +141,8 @@ protected virtual void Dispose(bool disposing)
{
// dispose managed state (managed objects)
_configContext.WindowManager.WindowFocused -= WindowManager_WindowFocused;
_configContext.WindowManager.WindowRegistered -= WindowManager_EventSink;
_configContext.WindowManager.WindowUnregistered -= WindowManager_EventSink;
_configContext.WindowManager.WindowAdded -= WindowManager_EventSink;
_configContext.WindowManager.WindowRemoved -= WindowManager_EventSink;
_configContext.WindowManager.WindowMoveStart -= WindowManager_EventSink;
_configContext.WindowManager.WindowMoved -= WindowManager_EventSink;
_configContext.WindowManager.WindowMinimizeStart -= WindowManager_EventSink;
Expand Down
2 changes: 1 addition & 1 deletion src/Whim.Tests/WorkspaceManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void GetMonitorForWorkspaceNull()

using WorkspaceManager workspaceManager = new(configContextMock.Object);

// Register the monitor in _monitorWorkspaceMap
// Add the monitor in _monitorWorkspaceMap
workspaceManager.Activate(new Mock<IWorkspace>().Object, monitorMock.Object);
workspaceManager.Activate(new Mock<IWorkspace>().Object, secondMonitorMock.Object);

Expand Down
6 changes: 3 additions & 3 deletions src/Whim.TreeLayout/TreeLayoutEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void ReplacePhantomNode(SplitNode parent, PhantomNode phantomNode, Windo
parent.Replace(phantomNode, windowNode);
phantomNode.Close();
_phantomWindows.Remove(phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.UnregisterPhantomWindow(this, phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.RemovePhantomWindow(this, phantomNode.Window);
}

/// <summary>
Expand All @@ -233,7 +233,7 @@ public bool Remove(IWindow window)
if (removingNode is PhantomNode phantomNode)
{
_phantomWindows.Remove(phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.UnregisterPhantomWindow(this, phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.RemovePhantomWindow(this, phantomNode.Window);
}

// Remove the node from the tree.
Expand Down Expand Up @@ -607,7 +607,7 @@ protected void SplitFocusedWindow(IWindow? focusedWindow = null, PhantomNode? ph
}

_phantomWindows.Add(phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.RegisterPhantomWindow(this, phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.AddPhantomWindow(this, phantomNode.Window);
_configContext.WorkspaceManager.ActiveWorkspace.DoLayout();
phantomNode.Focus();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Whim/Plugin/IPluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public interface IPluginManager : IDisposable
public void PostInitialize();

/// <summary>
/// Registers a plugin.
/// Adds a plugin.
/// There's no guarantee that <see cref="PreInitialize"/> will be called before Whim is
/// initialized. However, <see cref="PostInitialize"/> will still be called after
/// <see cref="PreInitialize"/>.
/// </summary>
/// <param name="plugin">The plugin to register.</param>
/// <returns>The plugin that was registered.</returns>
public T RegisterPlugin<T>(T plugin) where T : IPlugin;
/// <param name="plugin">The plugin to add.</param>
/// <returns>The plugin that was added.</returns>
public T AddPlugin<T>(T plugin) where T : IPlugin;
}
2 changes: 1 addition & 1 deletion src/Whim/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void PostInitialize()
}
}

public T RegisterPlugin<T>(T plugin) where T : IPlugin
public T AddPlugin<T>(T plugin) where T : IPlugin
{
_plugins.Add(plugin);
return plugin;
Expand Down
8 changes: 4 additions & 4 deletions src/Whim/Template/whim.config.csx
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ void DoConfig(IConfigContext configContext)

BarConfig barConfig = new(leftComponents, centerComponents, rightComponents);
BarPlugin barPlugin = new(configContext, barConfig);
configContext.PluginManager.RegisterPlugin(barPlugin);
configContext.PluginManager.AddPlugin(barPlugin);

// Floating window plugin.
FloatingLayoutPlugin floatingLayoutPlugin = new(configContext);
configContext.PluginManager.RegisterPlugin(floatingLayoutPlugin);
configContext.PluginManager.AddPlugin(floatingLayoutPlugin);

// Gap plugin.
GapsConfig gapsConfig = new(outerGap: 0, innerGap: 10);
GapsPlugin gapsPlugin = new(configContext, gapsConfig);
configContext.PluginManager.RegisterPlugin(gapsPlugin);
configContext.PluginManager.AddPlugin(gapsPlugin);

// Focus indicator.
FocusIndicatorConfig focusIndicatorConfig = new() { FadeEnabled = true };
FocusIndicatorPlugin focusIndicatorPlugin = new(configContext, focusIndicatorConfig);
configContext.PluginManager.RegisterPlugin(focusIndicatorPlugin);
configContext.PluginManager.AddPlugin(focusIndicatorPlugin);

// Load the commands and keybindings.
configContext.CommandManager.LoadCommands(DefaultCommands.GetCommands(configContext));
Expand Down
2 changes: 1 addition & 1 deletion src/Whim/Window/IWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public interface IWindow
/// <param name="configContext">The configuration context.</param>
public static IWindow? CreateWindow(HWND hwnd, IConfigContext configContext)
{
Logger.Debug($"Registering window {hwnd.Value}");
Logger.Debug($"Adding window {hwnd.Value}");

try
{
Expand Down
10 changes: 5 additions & 5 deletions src/Whim/Window/IWindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ public interface IWindowManager : IDisposable
public void Initialize();

/// <summary>
/// Register the top-level windows.
/// Add the top-level windows.
/// </summary>
public void PostInitialize();

/// <summary>
/// Event for when a window is registered by the <see cref="IWindowManager"/>.
/// Event for when a window is added by the <see cref="IWindowManager"/>.
/// </summary>
public event EventHandler<WindowEventArgs>? WindowRegistered;
public event EventHandler<WindowEventArgs>? WindowAdded;

/// <summary>
/// Event for when a window is focused.
/// </summary>
public event EventHandler<WindowEventArgs>? WindowFocused;

/// <summary>
/// Event for when a window is unregistered from Whim.
/// Event for when a window is removed from Whim.
/// </summary>
public event EventHandler<WindowEventArgs>? WindowUnregistered;
public event EventHandler<WindowEventArgs>? WindowRemoved;

/// <summary>
/// Event for when a window is being moved or resized.
Expand Down
66 changes: 33 additions & 33 deletions src/Whim/Window/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ internal class WindowManager : IWindowManager
{
private readonly IConfigContext _configContext;

public event EventHandler<WindowEventArgs>? WindowRegistered;
public event EventHandler<WindowEventArgs>? WindowAdded;
public event EventHandler<WindowEventArgs>? WindowFocused;
public event EventHandler<WindowEventArgs>? WindowUnregistered;
public event EventHandler<WindowEventArgs>? WindowRemoved;
public event EventHandler<WindowEventArgs>? WindowMoveStart;
public event EventHandler<WindowEventArgs>? WindowMoved;
public event EventHandler<WindowEventArgs>? WindowMinimizeStart;
Expand All @@ -25,9 +25,9 @@ internal class WindowManager : IWindowManager
private readonly Dictionary<HWND, IWindow> _windows = new();

/// <summary>
/// All the hooks registered with <see cref="PInvoke.SetWinEventHook(uint, uint, System.Runtime.InteropServices.SafeHandle, WINEVENTPROC, uint, uint, uint)"/>.
/// All the hooks added with <see cref="PInvoke.SetWinEventHook(uint, uint, System.Runtime.InteropServices.SafeHandle, WINEVENTPROC, uint, uint, uint)"/>.
/// </summary>
private readonly UnhookWinEventSafeHandle[] _registeredHooks = new UnhookWinEventSafeHandle[6];
private readonly UnhookWinEventSafeHandle[] _addedHooks = new UnhookWinEventSafeHandle[6];

/// <summary>
/// The delegate for handling all events triggered by <see cref="PInvoke.SetWinEventHook(uint, uint, System.Runtime.InteropServices.SafeHandle, WINEVENTPROC, uint, uint, uint)"/>.
Expand All @@ -54,21 +54,21 @@ public void Initialize()
{
Logger.Debug("Initializing window manager...");

// Each of the following hooks register just one or two event constants from https://docs.microsoft.com/en-us/windows/win32/winauto/event-constants
_registeredHooks[0] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_OBJECT_DESTROY, PInvoke.EVENT_OBJECT_SHOW, _hookDelegate);
_registeredHooks[1] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_OBJECT_CLOAKED, PInvoke.EVENT_OBJECT_UNCLOAKED, _hookDelegate);
_registeredHooks[2] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_SYSTEM_MOVESIZESTART, PInvoke.EVENT_SYSTEM_MOVESIZEEND, _hookDelegate);
_registeredHooks[3] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_SYSTEM_FOREGROUND, PInvoke.EVENT_SYSTEM_FOREGROUND, _hookDelegate);
_registeredHooks[4] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_OBJECT_LOCATIONCHANGE, PInvoke.EVENT_OBJECT_LOCATIONCHANGE, _hookDelegate);
_registeredHooks[5] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_SYSTEM_MINIMIZESTART, PInvoke.EVENT_SYSTEM_MINIMIZEEND, _hookDelegate);
// Each of the following hooks add just one or two event constants from https://docs.microsoft.com/en-us/windows/win32/winauto/event-constants
_addedHooks[0] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_OBJECT_DESTROY, PInvoke.EVENT_OBJECT_SHOW, _hookDelegate);
_addedHooks[1] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_OBJECT_CLOAKED, PInvoke.EVENT_OBJECT_UNCLOAKED, _hookDelegate);
_addedHooks[2] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_SYSTEM_MOVESIZESTART, PInvoke.EVENT_SYSTEM_MOVESIZEEND, _hookDelegate);
_addedHooks[3] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_SYSTEM_FOREGROUND, PInvoke.EVENT_SYSTEM_FOREGROUND, _hookDelegate);
_addedHooks[4] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_OBJECT_LOCATIONCHANGE, PInvoke.EVENT_OBJECT_LOCATIONCHANGE, _hookDelegate);
_addedHooks[5] = Win32Helper.SetWindowsEventHook(PInvoke.EVENT_SYSTEM_MINIMIZESTART, PInvoke.EVENT_SYSTEM_MINIMIZEEND, _hookDelegate);

// If any of the above hooks are invalid, we dispose the WindowManager instance and return false.
for (int i = 0; i < _registeredHooks.Length; i++)
for (int i = 0; i < _addedHooks.Length; i++)
{
if (_registeredHooks[i].IsInvalid)
if (_addedHooks[i].IsInvalid)
{
// Disposing is handled by the caller.
throw new InvalidOperationException($"Failed to register hook {i}");
throw new InvalidOperationException($"Failed to add hook {i}");
}
}
}
Expand All @@ -77,7 +77,7 @@ public void PostInitialize()
{
foreach (HWND hwnd in Win32Helper.GetAllWindows())
{
RegisterWindow(hwnd);
AddWindow(hwnd);
}
}

Expand All @@ -89,7 +89,7 @@ protected virtual void Dispose(bool disposing)
{
Logger.Debug("Disposing window manager");

foreach (UnhookWinEventSafeHandle? hook in _registeredHooks)
foreach (UnhookWinEventSafeHandle? hook in _addedHooks)
{
if (hook == null || hook.IsClosed || hook.IsInvalid)
{
Expand Down Expand Up @@ -161,8 +161,8 @@ private void WindowsEventHook(HWINEVENTHOOK hWinEventHook, uint eventType, HWND
// Try get the window
if (!_windows.TryGetValue(hwnd, out IWindow? window) || window == null)
{
Logger.Verbose($"Window {hwnd.Value} is not registered, event type {eventType}");
window = RegisterWindow(hwnd);
Logger.Verbose($"Window {hwnd.Value} is not added, event type {eventType}");
window = AddWindow(hwnd);
if (window == null)
{
return;
Expand All @@ -178,7 +178,7 @@ private void WindowsEventHook(HWINEVENTHOOK hWinEventHook, uint eventType, HWND
break;
case PInvoke.EVENT_OBJECT_DESTROY:
case PInvoke.EVENT_OBJECT_CLOAKED:
OnWindowUnregistered(window);
OnWindowRemoved(window);
break;
case PInvoke.EVENT_SYSTEM_MOVESIZESTART:
OnWindowMoveStart(window);
Expand All @@ -202,12 +202,12 @@ private void WindowsEventHook(HWINEVENTHOOK hWinEventHook, uint eventType, HWND
}

/// <summary>
/// Register the given <see cref="HWND"/> as an <see cref="IWindow"/> inside this
/// Add the given <see cref="HWND"/> as an <see cref="IWindow"/> inside this
/// <see cref="IWindowManager"/>.
/// </summary>
/// <param name="hwnd"></param>
/// <returns></returns>
private IWindow? RegisterWindow(HWND hwnd)
private IWindow? AddWindow(HWND hwnd)
{
if (Win32Helper.IsSplashScreen(hwnd)
|| Win32Helper.IsCloakedWindow(hwnd)
Expand All @@ -217,7 +217,7 @@ private void WindowsEventHook(HWINEVENTHOOK hWinEventHook, uint eventType, HWND
return null;
}

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

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

Expand All @@ -240,21 +240,21 @@ private void WindowsEventHook(HWINEVENTHOOK hWinEventHook, uint eventType, HWND
// Try add the window to the dictionary.
if (!_windows.TryAdd(hwnd, window))
{
Logger.Debug($"Failed to register {window}");
Logger.Debug($"Failed to add {window}");
return null;
}

Logger.Debug($"Registered {window}");
Logger.Debug($"Added {window}");

OnWindowRegistered(window);
OnWindowAdded(window);
return window;
}

private void OnWindowRegistered(IWindow window)
private void OnWindowAdded(IWindow window)
{
Logger.Debug($"Window registered: {window}");
(_configContext.WorkspaceManager as WorkspaceManager)?.WindowRegistered(window);
WindowRegistered?.Invoke(this, new WindowEventArgs(window));
Logger.Debug($"Window added: {window}");
(_configContext.WorkspaceManager as WorkspaceManager)?.WindowAdded(window);
WindowAdded?.Invoke(this, new WindowEventArgs(window));
}

/// <summary>
Expand All @@ -270,12 +270,12 @@ internal void OnWindowFocused(IWindow window)
WindowFocused?.Invoke(this, new WindowEventArgs(window));
}

private void OnWindowUnregistered(IWindow window)
private void OnWindowRemoved(IWindow window)
{
Logger.Debug($"Window unregistered: {window}");
Logger.Debug($"Window removed: {window}");
_windows.Remove(window.Handle);
(_configContext.WorkspaceManager as WorkspaceManager)?.WindowUnregistered(window);
WindowUnregistered?.Invoke(this, new WindowEventArgs(window));
(_configContext.WorkspaceManager as WorkspaceManager)?.WindowRemoved(window);
WindowRemoved?.Invoke(this, new WindowEventArgs(window));
}

private void OnWindowMoveStart(IWindow window)
Expand Down
20 changes: 10 additions & 10 deletions src/Whim/Workspace/IWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,20 @@ public interface IWorkspace : IDisposable

#region Phantom Windows
/// <summary>
/// Register a phantom window. This can only be done by the active layout engine.
/// Add a phantom window. This can only be done by the active layout engine.
/// </summary>
/// <param name="engine">The layout engine to register the phantom window to.</param>
/// <param name="window">The phantom window to register.</param>
public void RegisterPhantomWindow(ILayoutEngine engine, IWindow window);
/// <param name="engine">The layout engine to add the phantom window to.</param>
/// <param name="window">The phantom window to add.</param>
public void AddPhantomWindow(ILayoutEngine engine, IWindow window);

/// <summary>
/// Unregister a phantom window. This can only be done by the active layout engine,
/// and the phantom window must be registered to the same layout engine.
/// Remove a phantom window. This can only be done by the active layout engine,
/// and the phantom window must have been added to the same layout engine.
/// </summary>
/// <param name="engine">The layout engine to unregister the phantom window from.</param>
/// <param name="window">The phantom window to unregister.</param>
/// <param name="doLayout">Indicates whether to do a layout after unregistering the phantom window.</param>
public void UnregisterPhantomWindow(ILayoutEngine engine, IWindow window, bool doLayout = false);
/// <param name="engine">The layout engine to remove the phantom window from.</param>
/// <param name="window">The phantom window to remove.</param>
/// <param name="doLayout">Indicates whether to do a layout after removing the phantom window.</param>
public void RemovePhantomWindow(ILayoutEngine engine, IWindow window, bool doLayout = false);
#endregion

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/Whim/Workspace/IWorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ public interface IWorkspaceManager : IEnumerable<IWorkspace>, IDisposable

#region Phantom Windows
/// <summary>
/// Register a phantom window for the given <paramref name="workspace"/>.
/// Add a phantom window for the given <paramref name="workspace"/>.
/// </summary>
/// <param name="window">The phantom window to register.</param>
/// <param name="workspace">The workspace to register the window for.</param>
public void RegisterPhantomWindow(IWorkspace workspace, IWindow window);
/// <param name="window">The phantom window to add.</param>
/// <param name="workspace">The workspace to add the window for.</param>
public void AddPhantomWindow(IWorkspace workspace, IWindow window);

/// <summary>
/// Unregister the given phantom window.
/// Remove the given phantom window.
/// </summary>
public void UnregisterPhantomWindow(IWindow window);
public void RemovePhantomWindow(IWindow window);
#endregion
}
4 changes: 2 additions & 2 deletions src/Whim/Workspace/RouteEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class RouteEventArgs : EventArgs

/// <summary>
/// The workspace that the window was routed from. If the window has just
/// been registered, this will be null.
/// been added, this will be null.
/// </summary>
public IWorkspace? PreviousWorkspace { get; }

/// <summary>
/// The workspace that the window was routed to. If the window has just
/// been unregistered, this will be null.
/// been removed, this will be null.
/// </summary>
public IWorkspace? CurrentWorkspace { get; }

Expand Down
Loading