-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #6 - Added a rudimentary Bar plugin. - Added the following widgets: - `TextWidget` - `WorkspaceWidget` - `DateTimeWidget` - `ProxyLayoutEngine` is now a delegate. - Added a `BaseProxyLayoutEngine` to inherit from. - Renamed `WorkspaceMonitorChangedEvent` to `MonitorWorkspaceChangedEvent`, as the event is responsible for notifying subscribers of the monitor's change of workspaces.
- Loading branch information
Showing
43 changed files
with
1,120 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.insertSpaces": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<UserControl x:Class="Whim.Bar.ActiveLayoutWidget" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Whim.Bar" | ||
mc:Ignorable="d" | ||
d:DataContext="{d:DesignInstance Type=local:ActiveLayoutViewModel}" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<Button Content="{Binding Path=ActiveLayoutEngine}" Command="{Binding Path=NextLayoutEngineCommand}" CommandParameter="{Binding}" /> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
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 Whim.Bar; | ||
|
||
/// <summary> | ||
/// Interaction logic for ActiveLayoutWidget.xaml | ||
/// </summary> | ||
public partial class ActiveLayoutWidget : UserControl | ||
{ | ||
public ActiveLayoutWidgetViewModel ViewModel { get; private set; } | ||
|
||
public ActiveLayoutWidget(IConfigContext config, IMonitor monitor) | ||
{ | ||
ViewModel = new ActiveLayoutWidgetViewModel(config, monitor); | ||
InitializeComponent(); | ||
DataContext = ViewModel; | ||
} | ||
|
||
public static BarComponent CreateComponent() | ||
{ | ||
return new BarComponent((configContext, monitor, window) => new ActiveLayoutWidget(configContext, monitor)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
|
||
namespace Whim.Bar; | ||
|
||
public class ActiveLayoutWidgetViewModel : INotifyPropertyChanged, IDisposable | ||
{ | ||
private readonly IConfigContext _configContext; | ||
public IMonitor Monitor { get; } | ||
private bool disposedValue; | ||
|
||
private readonly HashSet<IWorkspace> _workspaces = new(); | ||
public string ActiveLayoutEngine { get => _configContext.WorkspaceManager.GetWorkspaceForMonitor(Monitor)?.ActiveLayoutEngine.Name ?? ""; } | ||
|
||
public System.Windows.Input.ICommand NextLayoutEngineCommand { get; } | ||
|
||
public ActiveLayoutWidgetViewModel(IConfigContext configContext, IMonitor monitor) | ||
{ | ||
_configContext = configContext; | ||
Monitor = monitor; | ||
NextLayoutEngineCommand = new NextLayoutEngineCommand(configContext, this); | ||
|
||
_configContext.WorkspaceManager.WorkspaceAdded += WorkspaceAdded; | ||
_configContext.WorkspaceManager.WorkspaceRemoved += WorkspaceRemoved; | ||
|
||
foreach (IWorkspace workspace in _configContext.WorkspaceManager) | ||
{ | ||
workspace.ActiveLayoutEngineChanged += Workspace_ActiveLayoutEngineChanged; | ||
_workspaces.Add(workspace); | ||
} | ||
} | ||
|
||
private void WorkspaceManager_ActiveWorkspaceChanged(object? sender, EventArgs e) | ||
{ | ||
OnPropertyChanged(nameof(ActiveLayoutEngine)); | ||
} | ||
|
||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
protected virtual void OnPropertyChanged(string? propertyName) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
// dispose managed state (managed objects) | ||
_configContext.WorkspaceManager.WorkspaceAdded -= WorkspaceAdded; | ||
_configContext.WorkspaceManager.WorkspaceRemoved -= WorkspaceRemoved; | ||
|
||
foreach (IWorkspace workspace in _configContext.WorkspaceManager) | ||
{ | ||
workspace.ActiveLayoutEngineChanged -= Workspace_ActiveLayoutEngineChanged; | ||
} | ||
} | ||
|
||
// free unmanaged resources (unmanaged objects) and override finalizer | ||
// set large fields to null | ||
disposedValue = true; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private void WorkspaceAdded(object? sender, WorkspaceEventArgs e) | ||
{ | ||
_workspaces.Add(e.Workspace); | ||
} | ||
|
||
private void WorkspaceRemoved(object? sender, WorkspaceEventArgs e) | ||
{ | ||
_workspaces.Remove(e.Workspace); | ||
} | ||
|
||
private void Workspace_ActiveLayoutEngineChanged(object? sender, EventArgs e) | ||
{ | ||
OnPropertyChanged(nameof(ActiveLayoutEngine)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Windows.Input; | ||
|
||
namespace Whim.Bar; | ||
|
||
public class NextLayoutEngineCommand : System.Windows.Input.ICommand | ||
{ | ||
private readonly IConfigContext _configContext; | ||
private readonly ActiveLayoutWidgetViewModel _viewModel; | ||
|
||
public NextLayoutEngineCommand(IConfigContext configContext, ActiveLayoutWidgetViewModel viewModel) | ||
{ | ||
_configContext = configContext; | ||
_viewModel = viewModel; | ||
} | ||
|
||
public event EventHandler? CanExecuteChanged | ||
{ | ||
add => CommandManager.RequerySuggested += value; | ||
remove => CommandManager.RequerySuggested -= value; | ||
} | ||
|
||
public bool CanExecute(object? parameter) => true; | ||
|
||
public void Execute(object? parameter) | ||
{ | ||
Logger.Debug("Switching to next layout engine"); | ||
_configContext.WorkspaceManager.GetWorkspaceForMonitor(_viewModel.Monitor)?.NextLayoutEngine(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Windows.Controls; | ||
|
||
namespace Whim.Bar; | ||
|
||
/// <summary> | ||
/// Delegate for creating a component. | ||
/// A component will subscribe to <see cref="Window.Closed"/> if it has resources to dispose. | ||
/// </summary> | ||
public delegate UserControl BarComponent(IConfigContext configContext, IMonitor monitor, System.Windows.Window window); | ||
|
||
public class BarConfig : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
private List<BarComponent> _leftComponents; | ||
public IEnumerable<BarComponent> LeftComponents | ||
{ | ||
get => _leftComponents; | ||
set | ||
{ | ||
_leftComponents = value.ToList(); | ||
OnPropertyChanged(nameof(LeftComponents)); | ||
} | ||
} | ||
|
||
private List<BarComponent> _middleComponents; | ||
public IEnumerable<BarComponent> CenterComponents | ||
{ | ||
get => _middleComponents; | ||
set | ||
{ | ||
_middleComponents = value.ToList(); | ||
OnPropertyChanged(nameof(CenterComponents)); | ||
} | ||
} | ||
|
||
private List<BarComponent> _rightComponents; | ||
public IEnumerable<BarComponent> RightComponents | ||
{ | ||
get => _rightComponents; | ||
set | ||
{ | ||
_rightComponents = value.ToList(); | ||
OnPropertyChanged(nameof(RightComponents)); | ||
} | ||
} | ||
|
||
private int _height = 48; | ||
public int Height | ||
{ | ||
get => _height; | ||
set | ||
{ | ||
_height = value; | ||
OnPropertyChanged(nameof(Height)); | ||
} | ||
} | ||
|
||
protected virtual void OnPropertyChanged(string propertyName) | ||
{ | ||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
public BarConfig(IEnumerable<BarComponent>? leftComponents = null, IEnumerable<BarComponent>? middleComponents = null, IEnumerable<BarComponent>? rightComponents = null) | ||
{ | ||
_leftComponents = (leftComponents ?? Enumerable.Empty<BarComponent>()).ToList(); | ||
_middleComponents = (middleComponents ?? Enumerable.Empty<BarComponent>()).ToList(); | ||
_rightComponents = (rightComponents ?? Enumerable.Empty<BarComponent>()).ToList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Whim.Bar; | ||
|
||
public class BarLayoutEngine : BaseProxyLayoutEngine | ||
{ | ||
private readonly BarConfig _barConfig; | ||
|
||
public BarLayoutEngine(BarConfig barConfig, ILayoutEngine innerLayoutEngine) : base(innerLayoutEngine) | ||
{ | ||
_barConfig = barConfig; | ||
} | ||
|
||
public override void AddWindow(IWindow window) | ||
{ | ||
_innerLayoutEngine.AddWindow(window); | ||
} | ||
|
||
public override IEnumerable<IWindowLocation> DoLayout(ILocation location) | ||
{ | ||
Location proxiedLocation = new(location.X, location.Y + _barConfig.Height, location.Width, location.Height - _barConfig.Height); | ||
return _innerLayoutEngine.DoLayout(proxiedLocation); | ||
} | ||
|
||
public override bool RemoveWindow(IWindow window) | ||
{ | ||
return _innerLayoutEngine.RemoveWindow(window); | ||
} | ||
} |
Oops, something went wrong.