Skip to content

Commit da2db47

Browse files
AkazaRennSlion
authored andcommitted
Support desktop move
Desktops can now be moved to specified index. Close #16.
1 parent 4f7e4d0 commit da2db47

File tree

9 files changed

+63
-7
lines changed

9 files changed

+63
-7
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ bld/
2525
# Visual Studo 2015 cache/options directory
2626
.vs/
2727

28+
# Visual Studo Code cache/options directory
29+
.vscode/
30+
2831
# MSTest test Results
2932
[Tt]est[Rr]esult*/
3033
[Bb]uild[Ll]og.*
@@ -129,7 +132,7 @@ publish/
129132
# Publish Web Output
130133
*.[Pp]ublish.xml
131134
*.azurePubxml
132-
# TODO: Comment the next line if you want to checkin your web deploy settings
135+
# TODO: Comment the next line if you want to checkin your web deploy settings
133136
# but database connection strings (with potential passwords) will be unencrypted
134137
*.pubxml
135138
*.publishproj

samples/VirtualDesktop.Showcase/MainWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
Click="SwitchRight" />
3939
<Button Content="Remove"
4040
Click="Remove" />
41+
<Button Content="Move left"
42+
Click="MoveLeft" />
43+
<Button Content="Move right"
44+
Click="MoveRight" />
4145
</StackPanel>
4246
</GroupBox>
4347

samples/VirtualDesktop.Showcase/MainWindow.xaml.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.ComponentModel;
@@ -224,6 +224,30 @@ private void Remove(object sender, RoutedEventArgs e)
224224
VirtualDesktop.Current.Remove();
225225
}
226226

227+
private void MoveLeft(object sender, RoutedEventArgs e)
228+
{
229+
foreach (var it in this.Desktops.Select((x, i) => new { Desktop = x, Index = i }))
230+
{
231+
if (it.Desktop.IsCurrent && it.Index > 0)
232+
{
233+
Debug.WriteLine($"Moved: {it.Index} -> {it.Index - 1}");
234+
VirtualDesktop.Current.Move(it.Index - 1);
235+
}
236+
}
237+
}
238+
239+
private void MoveRight(object sender, RoutedEventArgs e)
240+
{
241+
foreach (var it in this.Desktops.Select((x, i) => new { Desktop = x, Index = i }))
242+
{
243+
if (it.Desktop.IsCurrent && (it.Index < (this.Desktops.Count - 1)))
244+
{
245+
Debug.WriteLine($"Moved: {it.Index} -> {it.Index + 1}");
246+
VirtualDesktop.Current.Move(it.Index + 1);
247+
}
248+
}
249+
}
250+
227251
private void SwitchDesktop(object sender, RoutedEventArgs e)
228252
{
229253
if (sender is Button { DataContext: VirtualDesktopViewModel vm })

src/VirtualDesktop/Interop/Build10240_0000/VirtualDesktopManagerInternal.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.CompilerServices;
44
using WindowsDesktop.Interop.Proxy;
@@ -45,6 +45,9 @@ public IVirtualDesktop CreateDesktop()
4545
public void SwitchDesktop(IVirtualDesktop desktop)
4646
=> this.InvokeMethod(Args(((VirtualDesktop)desktop).ComObject));
4747

48+
public void MoveDesktop(IVirtualDesktop pMove, int nIndex)
49+
=> throw new NotSupportedException();
50+
4851
public void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop)
4952
=> this.InvokeMethod(Args(((VirtualDesktop)pRemove).ComObject, ((VirtualDesktop)pFallbackDesktop).ComObject));
5053

src/VirtualDesktop/Interop/Build20348_0000/VirtualDesktopManagerInternal.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.CompilerServices;
44
using WindowsDesktop.Interop.Proxy;
@@ -45,6 +45,10 @@ public IVirtualDesktop CreateDesktop()
4545
public void SwitchDesktop(IVirtualDesktop desktop)
4646
=> this.InvokeMethod(Args(IntPtr.Zero, ((VirtualDesktop)desktop).ComObject));
4747

48+
49+
public void MoveDesktop(IVirtualDesktop pMove, int nIndex)
50+
=> throw new NotSupportedException();
51+
4852
public void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop)
4953
=> this.InvokeMethod(Args(((VirtualDesktop)pRemove).ComObject, ((VirtualDesktop)pFallbackDesktop).ComObject));
5054

src/VirtualDesktop/Interop/Build22000_0000/VirtualDesktopManagerInternal.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.CompilerServices;
44
using WindowsDesktop.Interop.Proxy;
@@ -45,6 +45,9 @@ public IVirtualDesktop CreateDesktop()
4545
public void SwitchDesktop(IVirtualDesktop desktop)
4646
=> this.InvokeMethod(Args(IntPtr.Zero, ((VirtualDesktop)desktop).ComObject));
4747

48+
public void MoveDesktop(IVirtualDesktop pMove, int nIndex)
49+
=> this.InvokeMethod(Args(((VirtualDesktop)pMove).ComObject, IntPtr.Zero, nIndex));
50+
4851
public void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop)
4952
=> this.InvokeMethod(Args(((VirtualDesktop)pRemove).ComObject, ((VirtualDesktop)pFallbackDesktop).ComObject));
5053

src/VirtualDesktop/Interop/Build22621_2215/VirtualDesktopManagerInternal.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.CompilerServices;
44
using WindowsDesktop.Interop.Proxy;
@@ -45,6 +45,9 @@ public IVirtualDesktop CreateDesktop()
4545
public void SwitchDesktop(IVirtualDesktop desktop)
4646
=> this.InvokeMethod(Args(((VirtualDesktop)desktop).ComObject));
4747

48+
public void MoveDesktop(IVirtualDesktop pMove, int nIndex)
49+
=> this.InvokeMethod(Args(((VirtualDesktop)pMove).ComObject, nIndex));
50+
4851
public void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop)
4952
=> this.InvokeMethod(Args(((VirtualDesktop)pRemove).ComObject, ((VirtualDesktop)pFallbackDesktop).ComObject));
5053

src/VirtualDesktop/Interop/Proxy/IVirtualDesktopManagerInternal.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface IVirtualDesktopManagerInternal
2020

2121
IVirtualDesktop CreateDesktop();
2222

23+
void MoveDesktop(IVirtualDesktop pMove, int nIndex);
24+
2325
void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
2426

2527
void SwitchDesktop(IVirtualDesktop desktop);

src/VirtualDesktop/VirtualDesktop.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ public static VirtualDesktop Create()
149149
.ToVirtualDesktop();
150150
}
151151

152+
/// <summary>
153+
/// Move the given desktop to another posision.
154+
/// </summary>
155+
public void Move(int index)
156+
{
157+
if (index < 0 || index >= GetDesktops().Count()) throw new Exception($"Invalid index: {index}");
158+
159+
_provider.VirtualDesktopManagerInternal.MoveDesktop(this._source, index);
160+
}
161+
152162
/// <summary>
153163
/// Returns a virtual desktop matching the specified identifier.
154164
/// </summary>
@@ -344,4 +354,4 @@ public static bool TryGetAppUserModelId(IntPtr hWnd, out string appUserModelId)
344354
}
345355

346356
#endregion
347-
}
357+
}

0 commit comments

Comments
 (0)