diff --git a/samples/VirtualDesktop.Showcase/MainWindow.xaml b/samples/VirtualDesktop.Showcase/MainWindow.xaml
index fdda1f6..049e03f 100644
--- a/samples/VirtualDesktop.Showcase/MainWindow.xaml
+++ b/samples/VirtualDesktop.Showcase/MainWindow.xaml
@@ -22,6 +22,16 @@
+
+
+
+
+
+
+
diff --git a/samples/VirtualDesktop.Showcase/MainWindow.xaml.cs b/samples/VirtualDesktop.Showcase/MainWindow.xaml.cs
index 720cf14..b10c7ae 100644
--- a/samples/VirtualDesktop.Showcase/MainWindow.xaml.cs
+++ b/samples/VirtualDesktop.Showcase/MainWindow.xaml.cs
@@ -30,6 +30,8 @@ private static async void InitializeComObjects()
}
VirtualDesktop.CurrentChanged += (sender, args) => System.Diagnostics.Debug.WriteLine($"Desktop changed: {args.NewDesktop.Id}");
+ VirtualDesktop.Moved += (sender, args) => System.Diagnostics.Debug.WriteLine($"Desktop moved: {args.OldIndex} -> {args.NewIndex} ({args.Source.Id})");
+ VirtualDesktop.Renamed += (sender, args) => System.Diagnostics.Debug.WriteLine($"Desktop renamed: {args.OldName} -> {args.NewName} ({args.Source.Id})");
}
private void CreateNew(object sender, RoutedEventArgs e)
@@ -141,6 +143,79 @@ private async void Remove(object sender, RoutedEventArgs e)
}
}
+ private async void GetName(object sender, RoutedEventArgs e)
+ {
+ if (this.ThisWindowMenu.IsChecked ?? false)
+ {
+ var name = this.GetCurrentDesktop().Name;
+ MessageBox.Show(name, "Current desktop name");
+ }
+ else
+ {
+ await Task.Delay(_delay);
+ var name = this.GetCurrentDesktop().Name;
+ MessageBox.Show(name, "Current desktop name");
+ }
+ }
+
+ private async void SetName(object sender, RoutedEventArgs e)
+ {
+ if (this.ThisWindowMenu.IsChecked ?? false)
+ {
+ try
+ {
+ this.GetCurrentDesktop().Name = this.NameTextBlock.Text;
+ }
+ catch (PlatformNotSupportedException ex)
+ {
+ MessageBox.Show(ex.Message, "Error");
+ }
+ }
+ else
+ {
+ await Task.Delay(_delay);
+ try
+ {
+ this.GetCurrentDesktop().Name = this.NameTextBlock.Text;
+ }
+ catch (PlatformNotSupportedException ex)
+ {
+ MessageBox.Show(ex.Message, "Error");
+ }
+ }
+ }
+
+ private async void GetWallpaperPath(object sender, RoutedEventArgs e)
+ {
+ if (this.ThisWindowMenu.IsChecked ?? false)
+ {
+ var name = this.GetCurrentDesktop().WallpaperPath;
+ MessageBox.Show(name, "Current wallpaper path");
+ }
+ else
+ {
+ await Task.Delay(_delay);
+ var name = this.GetCurrentDesktop().WallpaperPath;
+ MessageBox.Show(name, "Current wallpaper path");
+ }
+ }
+
+ private void MovePrevious(object sender, RoutedEventArgs e)
+ {
+ var desktop = this.GetCurrentDesktop();
+ if (desktop == null) return;
+
+ desktop.Move(desktop.Index - 1);
+ }
+
+ private void MoveNext(object sender, RoutedEventArgs e)
+ {
+ var desktop = this.GetCurrentDesktop();
+ if (desktop == null) return;
+
+ desktop.Move(desktop.Index + 1);
+ }
+
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
diff --git a/source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktop.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktop.cs
similarity index 91%
rename from source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktop.cs
rename to source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktop.cs
index 373e315..a5df4d1 100644
--- a/source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktop.cs
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktop.cs
@@ -9,7 +9,8 @@ namespace WindowsDesktop.Interop
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IVirtualDesktop
{
- bool IsViewVisible(object pView);
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool IsViewVisible(IApplicationView pView);
Guid GetID();
}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktop2.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktop2.cs
new file mode 100644
index 0000000..9f63eb1
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktop2.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Concurrent;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktop2
+ {
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool IsViewVisible(IApplicationView pView);
+
+ Guid GetID();
+
+ [return: MarshalAs(UnmanagedType.HString)]
+ string GetName();
+ }
+
+ // see also:
+ // https://github.com/MScholtes/VirtualDesktop/blob/f7c0018069f5500bce3b170a53fb71edee44ebec/VirtualDesktop.cs#L156-L173
+
+ public class VirtualDesktopCacheImpl2 : IVirtualDesktopCache
+ {
+ private readonly ConcurrentDictionary _wrappers = new ConcurrentDictionary();
+
+ public Func Factory { get; set; }
+
+ public VirtualDesktop GetOrCreate(object comObject)
+ {
+ if (comObject is IVirtualDesktop2)
+ {
+ return this._wrappers.GetOrAdd(((IVirtualDesktop)comObject).GetID(), id => this.Factory(id, comObject));
+ }
+
+ throw new ArgumentException();
+ }
+
+ public void Clear()
+ {
+ this._wrappers.Clear();
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktopManagerInternal.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal.cs
similarity index 79%
rename from source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktopManagerInternal.cs
rename to source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal.cs
index dfdde1f..5b9de67 100644
--- a/source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktopManagerInternal.cs
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal.cs
@@ -10,8 +10,9 @@ internal interface IVirtualDesktopManagerInternal
{
int GetCount();
- void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop desktop);
+ void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop pDesktop);
+ [return: MarshalAs(UnmanagedType.Bool)]
bool CanViewMoveDesktops(IApplicationView pView);
IVirtualDesktop GetCurrentDesktop();
@@ -20,12 +21,12 @@ internal interface IVirtualDesktopManagerInternal
IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
- void SwitchDesktop(IVirtualDesktop desktop);
+ void SwitchDesktop(IVirtualDesktop pDesktop);
IVirtualDesktop CreateDesktopW();
void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
- IVirtualDesktop FindDesktop(ref Guid desktopId);
+ IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);
}
}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal2.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal2.cs
new file mode 100644
index 0000000..e27bbca
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal2.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ internal interface IVirtualDesktopManagerInternal2
+ {
+ int GetCount();
+
+ void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop pDesktop);
+
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool CanViewMoveDesktops(IApplicationView pView);
+
+ IVirtualDesktop GetCurrentDesktop();
+
+ IObjectArray GetDesktops();
+
+ IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
+
+ void SwitchDesktop(IVirtualDesktop pDesktop);
+
+ IVirtualDesktop CreateDesktopW();
+
+ void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
+
+ IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);
+
+ void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
+
+ void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+ }
+
+ // see also:
+ // https://github.com/MScholtes/VirtualDesktop/blob/f7c0018069f5500bce3b170a53fb71edee44ebec/VirtualDesktop.cs#L193-L211
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal3.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal3.cs
new file mode 100644
index 0000000..ced94a5
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopManagerInternal3.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ internal interface IVirtualDesktopManagerInternal3
+ {
+ int GetCount();
+
+ void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop pDesktop);
+
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool CanViewMoveDesktops(IApplicationView pView);
+
+ IVirtualDesktop GetCurrentDesktop();
+
+ IObjectArray GetDesktops();
+
+ IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
+
+ void SwitchDesktop(IVirtualDesktop pDesktop);
+
+ IVirtualDesktop CreateDesktopW();
+
+ void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
+
+ IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);
+
+ void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
+
+ void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void Unknown2(IApplicationView pUnknown0, IApplicationView pUnknown1);
+ }
+
+ // see also:
+ // https://github.com/MScholtes/VirtualDesktop/blob/f7c0018069f5500bce3b170a53fb71edee44ebec/VirtualDesktop.cs#L193-L211
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktopNotification.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopNotification.cs
similarity index 93%
rename from source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktopNotification.cs
rename to source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopNotification.cs
index 3baeab6..00362f1 100644
--- a/source/VirtualDesktop/Interop/(interfaces)/IVirtualDesktopNotification.cs
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopNotification.cs
@@ -16,7 +16,7 @@ public interface IVirtualDesktopNotification
void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
- void ViewVirtualDesktopChanged(IntPtr pView);
+ void ViewVirtualDesktopChanged(IApplicationView pView);
void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
}
@@ -43,7 +43,7 @@ public void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualD
this.VirtualDesktopDestroyedCore(pDesktopDestroyed, pDesktopFallback);
}
- public void ViewVirtualDesktopChanged(IntPtr pView)
+ public void ViewVirtualDesktopChanged(IApplicationView pView)
{
this.ViewVirtualDesktopChangedCore(pView);
}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopNotification2.cs b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopNotification2.cs
new file mode 100644
index 0000000..d17d54d
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/10240/IVirtualDesktopNotification2.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktopNotification2
+ {
+ void VirtualDesktopCreated(IVirtualDesktop pDesktop);
+
+ void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void ViewVirtualDesktopChanged(IApplicationView pView);
+
+ void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
+
+ void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+ }
+
+ public class VirtualDesktopNotificationListener2 : VirtualDesktopNotification, IVirtualDesktopNotification, IVirtualDesktopNotification2
+ {
+ public void VirtualDesktopCreated(IVirtualDesktop pDesktop)
+ {
+ this.VirtualDesktopCreatedCore(pDesktop);
+ }
+
+ public void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyBeginCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyFailedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void ViewVirtualDesktopChanged(IApplicationView pView)
+ {
+ this.ViewVirtualDesktopChangedCore(pView);
+ }
+
+ public void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew)
+ {
+ this.CurrentVirtualDesktopChangedCore(pDesktopOld, pDesktopNew);
+ }
+
+ public void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName)
+ {
+ this.VirtualDesktopRenamedCore(pDesktop, chName);
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktop.cs b/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktop.cs
new file mode 100644
index 0000000..e9967de
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktop.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Concurrent;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktop
+ {
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool IsViewVisible(IApplicationView pView);
+
+ Guid GetID();
+
+ IntPtr Unknown1();
+
+ [return: MarshalAs(UnmanagedType.HString)]
+ string GetName();
+ }
+
+ // see also:
+ // https://github.com/MScholtes/VirtualDesktop/blob/f7c0018069f5500bce3b170a53fb71edee44ebec/VirtualDesktop.cs#L156-L173
+
+ public class VirtualDesktopCacheImpl : IVirtualDesktopCache
+ {
+ private readonly ConcurrentDictionary _wrappers = new ConcurrentDictionary();
+
+ public Func Factory { get; set; }
+
+ public VirtualDesktop GetOrCreate(object comObject)
+ {
+ if (comObject is IVirtualDesktop)
+ {
+ return this._wrappers.GetOrAdd(((IVirtualDesktop)comObject).GetID(), id => this.Factory(id, comObject));
+ }
+
+ throw new ArgumentException();
+ }
+
+ public void Clear()
+ {
+ this._wrappers.Clear();
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktopManagerInternal.cs b/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktopManagerInternal.cs
new file mode 100644
index 0000000..19427d3
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktopManagerInternal.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ internal interface IVirtualDesktopManagerInternal
+ {
+ int GetCount(IntPtr hWndOrMon);
+
+ void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop pDesktop);
+
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool CanViewMoveDesktops(IApplicationView pView);
+
+ IVirtualDesktop GetCurrentDesktop(IntPtr hWndOrMon);
+
+ IObjectArray GetDesktops(IntPtr hWndOrMon);
+
+ IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
+
+ void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop pDesktop);
+
+ IVirtualDesktop CreateDesktopW(IntPtr hWndOrMon);
+
+ void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
+
+ IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);
+
+ void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
+
+ void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void Unknown2(IApplicationView pUnknown0, IApplicationView pUnknown1);
+
+ int Unknown3();
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktopNotification.cs b/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktopNotification.cs
new file mode 100644
index 0000000..e443f31
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/20231/IVirtualDesktopNotification.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktopNotification
+ {
+ void VirtualDesktopCreated(IVirtualDesktop pDesktop);
+
+ void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void Unknown1(int nNumber);
+
+ void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void ViewVirtualDesktopChanged(IApplicationView pView);
+
+ void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
+ }
+
+ public class VirtualDesktopNotificationListener : VirtualDesktopNotification, IVirtualDesktopNotification
+ {
+ public void VirtualDesktopCreated(IVirtualDesktop pDesktop)
+ {
+ this.VirtualDesktopCreatedCore(pDesktop);
+ }
+
+ public void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyBeginCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyFailedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void Unknown1(int nNumber)
+ {
+ }
+
+ public void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName)
+ {
+ this.VirtualDesktopRenamedCore(pDesktop, chName);
+ }
+
+ public void ViewVirtualDesktopChanged(IApplicationView pView)
+ {
+ this.ViewVirtualDesktopChangedCore(pView);
+ }
+
+ public void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew)
+ {
+ this.CurrentVirtualDesktopChangedCore(pDesktopOld, pDesktopNew);
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktop.cs b/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktop.cs
new file mode 100644
index 0000000..86e89a7
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktop.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Concurrent;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktop
+ {
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool IsViewVisible(IApplicationView pView);
+
+ Guid GetID();
+
+ IntPtr Unknown1();
+
+ [return: MarshalAs(UnmanagedType.HString)]
+ string GetName();
+
+ [return: MarshalAs(UnmanagedType.HString)]
+ string GetWallpaperPath();
+ }
+
+ // see also:
+ // https://github.com/MScholtes/VirtualDesktop/blob/f7c0018069f5500bce3b170a53fb71edee44ebec/VirtualDesktop.cs#L156-L173
+
+ public class VirtualDesktopCacheImpl : IVirtualDesktopCache
+ {
+ private readonly ConcurrentDictionary _wrappers = new ConcurrentDictionary();
+
+ public Func Factory { get; set; }
+
+ public VirtualDesktop GetOrCreate(object comObject)
+ {
+ if (comObject is IVirtualDesktop)
+ {
+ return this._wrappers.GetOrAdd(((IVirtualDesktop)comObject).GetID(), id => this.Factory(id, comObject));
+ }
+
+ throw new ArgumentException();
+ }
+
+ public void Clear()
+ {
+ this._wrappers.Clear();
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktopManagerInternal.cs b/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktopManagerInternal.cs
new file mode 100644
index 0000000..f31db41
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktopManagerInternal.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ internal interface IVirtualDesktopManagerInternal
+ {
+ int GetCount(IntPtr hWndOrMon);
+
+ void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop pDesktop);
+
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool CanViewMoveDesktops(IApplicationView pView);
+
+ IVirtualDesktop GetCurrentDesktop(IntPtr hWndOrMon);
+
+ IObjectArray GetDesktops(IntPtr hWndOrMon);
+
+ IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
+
+ void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop pDesktop);
+
+ IVirtualDesktop CreateDesktopW(IntPtr hWndOrMon);
+
+ IVirtualDesktop MoveDesktop(IVirtualDesktop pDesktopReference, IntPtr hWndOrMon, int nIndex);
+
+ void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
+
+ IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);
+
+ void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
+
+ void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void SetWallpaperPath(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);
+
+ void Unknown2([MarshalAs(UnmanagedType.HString)] string chText);
+
+ void Unknown3(IApplicationView pUnknown0, IApplicationView pUnknown1);
+
+ int Unknown4();
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktopNotification.cs b/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktopNotification.cs
new file mode 100644
index 0000000..d75f5c4
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/21313/IVirtualDesktopNotification.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktopNotification
+ {
+ void VirtualDesktopCreated(IVirtualDesktop pDesktop);
+
+ void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void Unknown1(int nNumber);
+
+ void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nFromIndex, int nToIndex);
+
+ void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void ViewVirtualDesktopChanged(IApplicationView pView);
+
+ void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
+
+ void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);
+ }
+
+ public class VirtualDesktopNotificationListener : VirtualDesktopNotification, IVirtualDesktopNotification
+ {
+ public void VirtualDesktopCreated(IVirtualDesktop pDesktop)
+ {
+ this.VirtualDesktopCreatedCore(pDesktop);
+ }
+
+ public void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyBeginCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyFailedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void Unknown1(int nNumber)
+ {
+ }
+
+ public void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nFromIndex, int nToIndex)
+ {
+ this.VirtualDesktopMovedCore(pDesktop, nFromIndex, nToIndex);
+ }
+
+ public void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName)
+ {
+ this.VirtualDesktopRenamedCore(pDesktop, chName);
+ }
+
+ public void ViewVirtualDesktopChanged(IApplicationView pView)
+ {
+ this.ViewVirtualDesktopChangedCore(pView);
+ }
+
+ public void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew)
+ {
+ this.CurrentVirtualDesktopChangedCore(pDesktopOld, pDesktopNew);
+ }
+
+ public void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName)
+ {
+ this.VirtualDesktopWallpaperChangedCore(pDesktop, chName);
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktop.cs b/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktop.cs
new file mode 100644
index 0000000..a866cc8
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktop.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Concurrent;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktop
+ {
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool IsViewVisible(IApplicationView pView);
+
+ Guid GetID();
+
+ IntPtr Unknown1();
+
+ [return: MarshalAs(UnmanagedType.HString)]
+ string GetName();
+
+ [return: MarshalAs(UnmanagedType.HString)]
+ string GetWallpaperPath();
+ }
+
+ public class VirtualDesktopCacheImpl : IVirtualDesktopCache
+ {
+ private readonly ConcurrentDictionary _wrappers = new ConcurrentDictionary();
+
+ public Func Factory { get; set; }
+
+ public VirtualDesktop GetOrCreate(object comObject)
+ {
+ if (comObject is IVirtualDesktop)
+ {
+ return this._wrappers.GetOrAdd(((IVirtualDesktop)comObject).GetID(), id => this.Factory(id, comObject));
+ }
+
+ throw new ArgumentException();
+ }
+
+ public void Clear()
+ {
+ this._wrappers.Clear();
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktopManagerInternal.cs b/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktopManagerInternal.cs
new file mode 100644
index 0000000..dc744ec
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktopManagerInternal.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ internal interface IVirtualDesktopManagerInternal
+ {
+ int GetCount(IntPtr hWndOrMon);
+
+ void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop pDesktop);
+
+ [return: MarshalAs(UnmanagedType.Bool)]
+ bool CanViewMoveDesktops(IApplicationView pView);
+
+ IVirtualDesktop GetCurrentDesktop(IntPtr hWndOrMon);
+
+ IObjectArray GetDesktops(IntPtr hWndOrMon);
+
+ IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
+
+ void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop pDesktop);
+
+ IVirtualDesktop CreateDesktopW(IntPtr hWndOrMon);
+
+ IVirtualDesktop MoveDesktop(IVirtualDesktop pDesktopReference, IntPtr hWndOrMon, int nIndex);
+
+ void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop);
+
+ IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);
+
+ void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
+
+ void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void SetWallpaperPath(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);
+
+ void Unknown2([MarshalAs(UnmanagedType.HString)] string chText);
+
+ void Unknown3(IApplicationView pUnknown0, IApplicationView pUnknown1);
+
+ int Unknown4();
+
+ void Unknown5(int nNum);
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktopNotification.cs b/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktopNotification.cs
new file mode 100644
index 0000000..e563877
--- /dev/null
+++ b/source/VirtualDesktop/Interop/(interfaces)/21359/IVirtualDesktopNotification.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace WindowsDesktop.Interop
+{
+ [ComImport]
+ [Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */]
+ [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IVirtualDesktopNotification
+ {
+ void VirtualDesktopCreated(IObjectArray p0, IVirtualDesktop pDesktop);
+
+ void VirtualDesktopDestroyBegin(IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyFailed(IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void VirtualDesktopDestroyed(IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback);
+
+ void Unknown1(int nNumber);
+
+ void VirtualDesktopMoved(IObjectArray p0, IVirtualDesktop pDesktop, int nFromIndex, int nToIndex);
+
+ void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
+
+ void ViewVirtualDesktopChanged(IApplicationView pView);
+
+ void CurrentVirtualDesktopChanged(IObjectArray p0, IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew);
+
+ void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);
+ }
+
+ public class VirtualDesktopNotificationListener : VirtualDesktopNotification, IVirtualDesktopNotification
+ {
+ public void VirtualDesktopCreated(IObjectArray p0, IVirtualDesktop pDesktop)
+ {
+ this.VirtualDesktopCreatedCore(pDesktop);
+ }
+
+ public void VirtualDesktopDestroyBegin(IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyBeginCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyFailed(IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyFailedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void VirtualDesktopDestroyed(IObjectArray p0, IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback)
+ {
+ this.VirtualDesktopDestroyedCore(pDesktopDestroyed, pDesktopFallback);
+ }
+
+ public void Unknown1(int nNumber)
+ {
+ }
+
+ public void VirtualDesktopMoved(IObjectArray p0, IVirtualDesktop pDesktop, int nFromIndex, int nToIndex)
+ {
+ this.VirtualDesktopMovedCore(pDesktop, nFromIndex, nToIndex);
+ }
+
+ public void VirtualDesktopRenamed(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName)
+ {
+ this.VirtualDesktopRenamedCore(pDesktop, chName);
+ }
+
+ public void ViewVirtualDesktopChanged(IApplicationView pView)
+ {
+ this.ViewVirtualDesktopChangedCore(pView);
+ }
+
+ public void CurrentVirtualDesktopChanged(IObjectArray p0, IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew)
+ {
+ this.CurrentVirtualDesktopChangedCore(pDesktopOld, pDesktopNew);
+ }
+
+ public void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName)
+ {
+ this.VirtualDesktopWallpaperChangedCore(pDesktop, chName);
+ }
+ }
+}
diff --git a/source/VirtualDesktop/Interop/(interfaces)/AssemblyInfo.cs b/source/VirtualDesktop/Interop/(interfaces)/AssemblyInfo.cs
index f3079b5..cd46768 100644
--- a/source/VirtualDesktop/Interop/(interfaces)/AssemblyInfo.cs
+++ b/source/VirtualDesktop/Interop/(interfaces)/AssemblyInfo.cs
@@ -7,4 +7,4 @@
[assembly: AssemblyDescription("COM interface definitions for virtual desktop on Windows 10 build {VERSION}.")]
[assembly: AssemblyCopyright("Copyright © 2018 Manato KAMEYA")]
-[assembly: AssemblyVersion("1.0.0")]
+[assembly: AssemblyVersion("1.0.0.{BUILD}")]
diff --git a/source/VirtualDesktop/Interop/(wrappers)/VirtualDesktopManagerInternal.cs b/source/VirtualDesktop/Interop/(wrappers)/VirtualDesktopManagerInternal.cs
index ca6d145..875e739 100644
--- a/source/VirtualDesktop/Interop/(wrappers)/VirtualDesktopManagerInternal.cs
+++ b/source/VirtualDesktop/Interop/(wrappers)/VirtualDesktopManagerInternal.cs
@@ -1,66 +1,35 @@
using System;
using System.Collections.Generic;
-using System.Runtime.CompilerServices;
namespace WindowsDesktop.Interop
{
- [ComInterfaceWrapper]
- internal class VirtualDesktopManagerInternal : ComInterfaceWrapperBase
+ internal abstract class VirtualDesktopManagerInternal : ComInterfaceWrapperBase
{
- public VirtualDesktopManagerInternal(ComInterfaceAssembly assembly)
- : base(assembly, service: CLSID.VirtualDesktopAPIUnknown)
+ public VirtualDesktopManagerInternal(ComInterfaceAssembly assembly, uint latestVersion = 1)
+ : base(assembly, "IVirtualDesktopManagerInternal", latestVersion, service: CLSID.VirtualDesktopAPIUnknown)
{
}
- public void MoveViewToDesktop(ApplicationView pView, VirtualDesktop desktop)
- {
- this.Invoke(Args(pView.ComObject, desktop.ComObject));
- }
+ public abstract void MoveViewToDesktop(ApplicationView pView, VirtualDesktop desktop);
- public VirtualDesktop GetCurrentDesktop()
- {
- return this.GetDesktop();
- }
+ public abstract VirtualDesktop GetCurrentDesktop();
- public IEnumerable GetDesktops()
- {
- var array = this.Invoke();
- var count = array.GetCount();
- var vdType = this.ComInterfaceAssembly.GetType("IVirtualDesktop");
+ public abstract IEnumerable GetDesktops();
- for (var i = 0u; i < count; i++)
- {
- array.GetAt(i, vdType.GUID, out var ppvObject);
- yield return VirtualDesktopCache.GetOrCreate(ppvObject);
- }
- }
+ public abstract VirtualDesktop GetAdjacentDesktop(VirtualDesktop pDesktopReference, AdjacentDesktop uDirection);
- public VirtualDesktop GetAdjacentDesktop(VirtualDesktop pDesktopReference, AdjacentDesktop uDirection)
- {
- return this.GetDesktop(Args(pDesktopReference.ComObject, uDirection));
- }
+ public abstract void SwitchDesktop(VirtualDesktop desktop);
- public void SwitchDesktop(VirtualDesktop desktop)
- {
- this.Invoke(Args(desktop.ComObject));
- }
+ public abstract VirtualDesktop CreateDesktopW();
- public VirtualDesktop CreateDesktopW()
- {
- return this.GetDesktop();
- }
+ public abstract void MoveDesktop(VirtualDesktop desktop, int index);
- public void RemoveDesktop(VirtualDesktop pRemove, VirtualDesktop pFallbackDesktop)
- {
- this.Invoke(Args(pRemove.ComObject, pFallbackDesktop.ComObject));
- }
+ public abstract void RemoveDesktop(VirtualDesktop pRemove, VirtualDesktop pFallbackDesktop);
- public VirtualDesktop FindDesktop(ref Guid desktopId)
- {
- return this.GetDesktop(Args(desktopId));
- }
+ public abstract VirtualDesktop FindDesktop(Guid desktopId);
+
+ public abstract void SetName(VirtualDesktop desktop, string name);
- private VirtualDesktop GetDesktop(object[] parameters = null, [CallerMemberName] string methodName = "")
- => VirtualDesktopCache.GetOrCreate(this.Invoke