Skip to content

Commit

Permalink
Add visual indicator that the dial is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
C1rdec committed Jun 17, 2022
1 parent 3f3583e commit ea8190b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# CA1416: Validate platform compatibility
dotnet_diagnostic.CA1416.severity = none

# IDE0022: Use block body for methods
dotnet_diagnostic.IDE0022.severity = none
24 changes: 18 additions & 6 deletions src/GitLurker.UI/Services/SurfaceDialService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class SurfaceDialService : IDisposable

public event EventHandler RotatedRight;

public event EventHandler ControlAcquired;

public event EventHandler ControlLost;

#endregion

#region Methods
Expand All @@ -51,10 +55,18 @@ public async Task Initialize(Window window)
_controller.RotationChanged += Controller_RotationChanged;
_controller.ButtonHolding += Controller_ButtonHolding;
_controller.ButtonReleased += Controller_ButtonReleased;
_controller.ControlAcquired += Controller_ControlAcquired;
_controller.ControlLost += Controller_ControlLost;

RemoveSystemItems(handle);
ApplyConfigurations(handle);
}

private void Controller_ControlLost(RadialController sender, object args)
=> ControlLost?.Invoke(this, EventArgs.Empty);

private void Controller_ControlAcquired(RadialController sender, RadialControllerControlAcquiredEventArgs args)
=> ControlAcquired?.Invoke(this, EventArgs.Empty);

private void Controller_ButtonReleased(RadialController sender, RadialControllerButtonReleasedEventArgs args)
{
if (_holding)
Expand Down Expand Up @@ -91,15 +103,15 @@ private void Controller_ButtonClicked(RadialController sender, RadialControllerB
ButtonClicked?.Invoke(this, EventArgs.Empty);
}

private void RemoveSystemItems(IntPtr hwnd)
private void ApplyConfigurations(IntPtr hwnd)
{
RadialControllerConfiguration config;
var radialControllerConfigInterop = (IRadialControllerConfigurationInterop)System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.GetActivationFactory(typeof(RadialControllerConfiguration));
var guid = typeof(RadialControllerConfiguration).GetInterface("IRadialControllerConfiguration").GUID;

config = radialControllerConfigInterop.GetForWindow(hwnd, ref guid);
config.IsMenuSuppressed = true;
config.SetDefaultMenuItems(Enumerable.Empty<RadialControllerSystemMenuItemKind>());
var configuration = radialControllerConfigInterop.GetForWindow(hwnd, ref guid);
var t = RadialControllerConfiguration.IsAppControllerEnabled;
configuration.IsMenuSuppressed = true;
configuration.SetDefaultMenuItems(Enumerable.Empty<RadialControllerSystemMenuItemKind>());
}

public void Dispose()
Expand Down
17 changes: 17 additions & 0 deletions src/GitLurker.UI/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ShellViewModel : Screen, IHandle<CloseMessage>, IHandle<string>
private string _version;
private double _dpiX = 1;
private double _dpiY = 1;
private bool _hasSurfaceDial;

#endregion

Expand Down Expand Up @@ -102,6 +103,16 @@ public string SearchTerm
}
}

public bool HasSurfaceDial
{
get => _hasSurfaceDial;
set
{
_hasSurfaceDial = value;
NotifyOfPropertyChange();
}
}

public string SearchWatermark
{
get => _searchWatermark;
Expand Down Expand Up @@ -243,6 +254,8 @@ protected override async void OnViewLoaded(object view)
_surfaceDialService.RotatedRight += SurfaceDialService_RotatedRight;
_surfaceDialService.RotatedLeft += SurfaceDialService_RotatedLeft;
_surfaceDialService.ButtonHolding += SurfaceDialService_ButtonHolding;
_surfaceDialService.ControlAcquired += SurfaceDialService_ControlAcquired;
_surfaceDialService.ControlLost += SurfaceDialService_ControlLost;

var source = PresentationSource.FromVisual(this.View);
if (source != null)
Expand All @@ -259,6 +272,10 @@ protected override async void OnViewLoaded(object view)
HideFromAltTab(View);
}

private void SurfaceDialService_ControlLost(object sender, EventArgs e) => HasSurfaceDial = false;

private void SurfaceDialService_ControlAcquired(object sender, EventArgs e) => HasSurfaceDial = true;

private void SurfaceDialService_ButtonHolding(object sender, EventArgs e) => WorkspaceViewModel.OpenPullRequest();

private void SurfaceDialService_RotatedLeft(object sender, EventArgs e) => WorkspaceViewModel.MoveUp();
Expand Down
18 changes: 17 additions & 1 deletion src/GitLurker.UI/Views/ShellView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
<Border Background="{DynamicResource MahApps.Brushes.Gray10}"
CornerRadius="10"
BorderThickness="0,0,0,1.6">
<TextBox x:Name="SearchTerm"
<Grid>
<TextBox x:Name="SearchTerm"
Margin="10,5,0,5"
Grid.Column="1"
Background="Transparent"
Expand All @@ -69,6 +70,21 @@
Controls:TextBoxHelper.SelectAllOnFocus="True"
Controls:TextBoxHelper.Watermark="{Binding SearchWatermark}"
BorderBrush="{DynamicResource MahApps.Brushes.Accent}"/>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Visibility="{Binding HasSurfaceDial, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="0,0,10,5">

<iconPacks:PackIconMaterial Kind="HockeyPuck"
Height="18"
Width="18"
Foreground="{DynamicResource MahApps.Brushes.Accent2}"/>
<TextBlock VerticalAlignment="Center"
Margin="10,0,0,0"
Foreground="{DynamicResource MahApps.Brushes.Accent2}">Connected</TextBlock>
</StackPanel>
</Grid>
</Border>

<Grid VerticalAlignment="Top"
Expand Down

0 comments on commit ea8190b

Please sign in to comment.