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

Switching feature #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions source/SylphyHorn/Models/HookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ private void KeyHookOnPressed(object sender, ShortcutKeyPressedEventArgs args)
VisualHelper.InvokeOnUIDispatcher(() => this.MoveToNew()?.Switch());
args.Handled = true;
}

if (ShortcutSettings.SwitchLeft.Value != null &&
ShortcutSettings.SwitchLeft.Value == args.ShortcutKey)
{
VisualHelper.InvokeOnUIDispatcher(() => this.GetLeftDesktop()?.Switch());
args.Handled = true;
}

if (ShortcutSettings.SwitchRight.Value != null &&
ShortcutSettings.SwitchRight.Value == args.ShortcutKey)
{
VisualHelper.InvokeOnUIDispatcher(() => this.GetRightDesktop()?.Switch());
args.Handled = true;
}
}

private VirtualDesktop MoveToLeft()
Expand Down Expand Up @@ -186,6 +200,38 @@ private VirtualDesktop MoveToNew()
return null;
}

private VirtualDesktop GetLeftDesktop()
{
var current = VirtualDesktop.Current;
if (current != null)
{
var left = current.GetLeft();
if (left == null && GeneralSettings.LoopDesktop)
{
var desktops = VirtualDesktop.GetDesktops();
if (desktops.Length >= 2) left = desktops.Last();
}
return left;
}
return null;
}

private VirtualDesktop GetRightDesktop()
{
var current = VirtualDesktop.Current;
if (current != null)
{
var right = current.GetRight();
if (right == null && GeneralSettings.LoopDesktop)
{
var desktops = VirtualDesktop.GetDesktops();
if (desktops.Length >= 2) right = desktops.First();
}
return right;
}
return null;
}

public void Dispose()
{
this.detector.Stop();
Expand Down
6 changes: 6 additions & 0 deletions source/SylphyHorn/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public static class ShortcutSettings
public static SerializableProperty<ShortcutKey?> MoveNewAndSwitch { get; }
= new SerializableProperty<ShortcutKey?>(GetKey(), Providers.Local, new ShortcutKey(Key.D, Key.LeftCtrl, Key.LeftAlt, Key.LWin));

public static SerializableProperty<ShortcutKey?> SwitchLeft { get; }
= new SerializableProperty<ShortcutKey?>(GetKey(), Providers.Local);

public static SerializableProperty<ShortcutKey?> SwitchRight { get; }
= new SerializableProperty<ShortcutKey?>(GetKey(), Providers.Local);


private static string GetKey([CallerMemberName] string caller = "")
{
Expand Down
24 changes: 24 additions & 0 deletions source/SylphyHorn/Views/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,30 @@
<controls:ShortcutKeyBox Current="{Binding Source={x:Static models:ShortcutSettings.MoveNewAndSwitch}, Path=Value, Mode=TwoWay}" />
</UniformGrid>
</Grid>

<TextBlock Text="Switch virtual desktop"
Style="{DynamicResource HeaderStyleKey}" />
<Grid Margin="8,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"
SharedSizeGroup="KeyHeader" />
<ColumnDefinition Width="8" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<UniformGrid Columns="1">
<TextBlock Text="Switch to Right (Default)" />
<TextBlock Text="Switch to Left (Default)" />
<TextBlock Text="Switch to Right" />
<TextBlock Text="Switch to Left" />
</UniformGrid>
<UniformGrid Grid.Column="2"
Columns="1">
<TextBlock Text="Ctrl + Win + &lt;- (provided by Windows)" />
<TextBlock Text="Ctrl + Win + -&gt; (provided by Windows)" />
<controls:ShortcutKeyBox Current="{Binding Source={x:Static models:ShortcutSettings.SwitchLeft}, Path=Value, Mode=TwoWay}" />
<controls:ShortcutKeyBox Current="{Binding Source={x:Static models:ShortcutSettings.SwitchRight}, Path=Value, Mode=TwoWay}" />
</UniformGrid>
</Grid>
</StackPanel>
</ScrollViewer>
</TabItem>
Expand Down