forked from Grabacr07/VirtualDesktop
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e08e63b
commit d8d49a8
Showing
13 changed files
with
482 additions
and
1 deletion.
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,47 @@ | ||
using WindowsDesktop.Interop.Build10240; | ||
using WindowsDesktop.Interop.Proxy; | ||
|
||
namespace WindowsDesktop.Interop.Build22631; | ||
|
||
internal class VirtualDesktopProvider22631 : VirtualDesktopProvider | ||
{ | ||
private IVirtualDesktopManager? _virtualDesktopManager; | ||
private ApplicationViewCollection? _applicationViewCollection; | ||
private VirtualDesktopManagerInternal? _virtualDesktopManagerInternal; | ||
private VirtualDesktopPinnedApps? _virtualDesktopPinnedApps; | ||
private VirtualDesktopNotificationService? _virtualDesktopNotificationService; | ||
|
||
public override IApplicationViewCollection ApplicationViewCollection | ||
=> this._applicationViewCollection ?? throw InitializationIsRequired; | ||
|
||
public override IVirtualDesktopManager VirtualDesktopManager | ||
=> this._virtualDesktopManager ?? throw InitializationIsRequired; | ||
|
||
public override IVirtualDesktopManagerInternal VirtualDesktopManagerInternal | ||
=> this._virtualDesktopManagerInternal ?? throw InitializationIsRequired; | ||
|
||
public override IVirtualDesktopPinnedApps VirtualDesktopPinnedApps | ||
=> this._virtualDesktopPinnedApps ?? throw InitializationIsRequired; | ||
|
||
public override IVirtualDesktopNotificationService VirtualDesktopNotificationService | ||
=> this._virtualDesktopNotificationService ?? throw InitializationIsRequired; | ||
|
||
private protected override void InitializeCore(ComInterfaceAssembly assembly) | ||
{ | ||
var type = Type.GetTypeFromCLSID(CLSID.VirtualDesktopManager) | ||
?? throw new Exception($"No type found for CLSID '{CLSID.VirtualDesktopManager}'."); | ||
this._virtualDesktopManager = Activator.CreateInstance(type) is IVirtualDesktopManager manager | ||
? manager | ||
: throw new Exception($"Failed to create instance of Type '{typeof(IVirtualDesktopManager)}'."); | ||
|
||
this._applicationViewCollection = new ApplicationViewCollection(assembly); | ||
var factory = new ComWrapperFactory( | ||
x => new ApplicationView(assembly, x), | ||
x => this._applicationViewCollection.GetViewForHwnd(x), | ||
x => new VirtualDesktop(assembly, x)); | ||
this._virtualDesktopPinnedApps = new VirtualDesktopPinnedApps(assembly, factory); | ||
this._virtualDesktopManagerInternal = new VirtualDesktopManagerInternal(assembly, factory); | ||
this._virtualDesktopNotificationService = new VirtualDesktopNotificationService(assembly, factory); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/VirtualDesktop/Interop/Build22631_3155/.interfaces/IVirtualDesktop.cs
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,24 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using WindowsDesktop.Interop.Build10240; | ||
|
||
namespace WindowsDesktop.Interop.Build22631 | ||
{ | ||
[ComImport] | ||
[Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
public interface IVirtualDesktop | ||
{ | ||
bool IsViewVisible(IApplicationView view); | ||
|
||
Guid GetID(); | ||
|
||
HString GetName(); | ||
|
||
HString GetWallpaperPath(); | ||
|
||
bool IsRemote(); | ||
|
||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/VirtualDesktop/Interop/Build22631_3155/.interfaces/IVirtualDesktopManagerInternal.cs
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,54 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using WindowsDesktop.Interop.Build10240; | ||
|
||
namespace WindowsDesktop.Interop.Build22631 | ||
{ | ||
[ComImport] | ||
[Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
public interface IVirtualDesktopManagerInternal | ||
{ | ||
int GetCount(); | ||
|
||
void MoveViewToDesktop(IApplicationView pView, IVirtualDesktop desktop); | ||
|
||
bool CanViewMoveDesktops(IApplicationView pView); | ||
|
||
IVirtualDesktop GetCurrentDesktop(); | ||
|
||
IObjectArray GetDesktops(); | ||
|
||
IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, int uDirection); | ||
|
||
void SwitchDesktop(IVirtualDesktop desktop); | ||
|
||
IVirtualDesktop CreateDesktop(); | ||
|
||
void MoveDesktop(IVirtualDesktop desktop, int nIndex); | ||
|
||
void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop); | ||
|
||
IVirtualDesktop FindDesktop(in Guid desktopId); | ||
|
||
void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray o1, out IObjectArray o2); | ||
|
||
void SetDesktopName(IVirtualDesktop desktop, HString name); | ||
|
||
void SetDesktopWallpaper(IVirtualDesktop desktop, HString path); | ||
|
||
void UpdateWallpaperPathForAllDesktops(HString path); | ||
|
||
void CopyDesktopState(IApplicationView pView0, IApplicationView pView1); | ||
|
||
IVirtualDesktop CreateRemoteDesktop(HString name); | ||
|
||
void SwitchRemoteDesktop(IVirtualDesktop desktop); | ||
|
||
void SwitchDesktopWithAnimation(IVirtualDesktop desktop); | ||
|
||
IVirtualDesktop GetLastActiveDesktop(); | ||
|
||
void WaitForAnimationToComplete(); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/VirtualDesktop/Interop/Build22631_3155/.interfaces/IVirtualDesktopNotification.cs
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,93 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using WindowsDesktop.Interop.Build10240; | ||
|
||
namespace WindowsDesktop.Interop.Build22631 | ||
{ | ||
[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 VirtualDesktopMoved(IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo); | ||
|
||
void VirtualDesktopNameChanged(IVirtualDesktop pDesktop, HString chName); | ||
|
||
void ViewVirtualDesktopChanged(IApplicationView pView); | ||
|
||
void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew); | ||
|
||
void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, HString chPath); | ||
|
||
void VirtualDesktopSwitched(IVirtualDesktop pDesktop); | ||
|
||
void RemoteVirtualDesktopConnected(IVirtualDesktop pDesktop); | ||
} | ||
|
||
internal class VirtualDesktopNotification : VirtualDesktopNotificationService.EventListenerBase, IVirtualDesktopNotification | ||
{ | ||
public void VirtualDesktopCreated(IVirtualDesktop pDesktop) | ||
{ | ||
this.CreatedCore(pDesktop); | ||
} | ||
|
||
public void VirtualDesktopDestroyBegin(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback) | ||
{ | ||
this.DestroyBeginCore(pDesktopDestroyed, pDesktopFallback); | ||
} | ||
|
||
public void VirtualDesktopDestroyFailed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback) | ||
{ | ||
this.DestroyFailedCore(pDesktopDestroyed, pDesktopFallback); | ||
} | ||
|
||
public void VirtualDesktopDestroyed(IVirtualDesktop pDesktopDestroyed, IVirtualDesktop pDesktopFallback) | ||
{ | ||
this.DestroyedCore(pDesktopDestroyed, pDesktopFallback); | ||
} | ||
|
||
public void VirtualDesktopMoved(IVirtualDesktop pDesktop, int nIndexFrom, int nIndexTo) | ||
{ | ||
this.MovedCore(pDesktop, nIndexFrom, nIndexTo); | ||
} | ||
|
||
public void VirtualDesktopNameChanged(IVirtualDesktop pDesktop, HString chName) | ||
{ | ||
this.RenamedCore(pDesktop, chName); | ||
} | ||
|
||
public void ViewVirtualDesktopChanged(IApplicationView pView) | ||
{ | ||
this.ViewChangedCore(pView); | ||
} | ||
|
||
public void CurrentVirtualDesktopChanged(IVirtualDesktop pDesktopOld, IVirtualDesktop pDesktopNew) | ||
{ | ||
this.CurrentChangedCore(pDesktopOld, pDesktopNew); | ||
} | ||
|
||
public void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, HString chPath) | ||
{ | ||
this.WallpaperChangedCore(pDesktop, chPath); | ||
} | ||
|
||
public void VirtualDesktopSwitched(IVirtualDesktop pDesktop) | ||
{ | ||
this.SwitchedCore(pDesktop); | ||
} | ||
|
||
public void RemoteVirtualDesktopConnected(IVirtualDesktop pDesktop) | ||
{ | ||
this.RemoteConnectedCore(pDesktop); | ||
} | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/VirtualDesktop/Interop/Build22631_3155/.interfaces/IVirtualDesktopNotificationService.cs
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,15 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace WindowsDesktop.Interop.Build22631 | ||
{ | ||
[ComImport] | ||
[Guid("00000000-0000-0000-0000-000000000000") /* replace at runtime */] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
public interface IVirtualDesktopNotificationService | ||
{ | ||
uint Register(IVirtualDesktopNotification pNotification); | ||
|
||
void Unregister(uint dwCookie); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/VirtualDesktop/Interop/Build22631_3155/VirtualDesktop.cs
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,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using WindowsDesktop.Interop.Proxy; | ||
|
||
namespace WindowsDesktop.Interop.Build22631; | ||
|
||
internal class VirtualDesktop : ComWrapperBase<IVirtualDesktop>, IVirtualDesktop | ||
{ | ||
private Guid? _id; | ||
|
||
public VirtualDesktop(ComInterfaceAssembly assembly, object comObject) | ||
: base(assembly, comObject) | ||
{ | ||
} | ||
|
||
public bool IsViewVisible(IntPtr hWnd) | ||
=> this.InvokeMethod<bool>(Args(hWnd)); | ||
|
||
public Guid GetID() | ||
=> this._id ?? (Guid)(this._id = this.InvokeMethod<Guid>()); | ||
|
||
public string GetName() | ||
=> this.InvokeMethod<HString>(); | ||
|
||
public string GetWallpaperPath() | ||
=> this.InvokeMethod<HString>(); | ||
|
||
public bool IsRemote() | ||
=> this.InvokeMethod<bool>(); | ||
} |
68 changes: 68 additions & 0 deletions
68
src/VirtualDesktop/Interop/Build22631_3155/VirtualDesktopManagerInternal.cs
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,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using WindowsDesktop.Interop.Proxy; | ||
|
||
namespace WindowsDesktop.Interop.Build22631; | ||
|
||
internal class VirtualDesktopManagerInternal : ComWrapperBase<IVirtualDesktopManagerInternal>, IVirtualDesktopManagerInternal | ||
{ | ||
private readonly ComWrapperFactory _factory; | ||
|
||
public VirtualDesktopManagerInternal(ComInterfaceAssembly assembly, ComWrapperFactory factory) | ||
: base(assembly, CLSID.VirtualDesktopManagerInternal) | ||
{ | ||
this._factory = factory; | ||
} | ||
|
||
public IEnumerable<IVirtualDesktop> GetDesktops() | ||
{ | ||
var array = this.InvokeMethod<IObjectArray>(); | ||
if (array == null) yield break; | ||
|
||
var count = array.GetCount(); | ||
var vdType = this.ComInterfaceAssembly.GetType(nameof(IVirtualDesktop)); | ||
|
||
for (var i = 0u; i < count; i++) | ||
{ | ||
var ppvObject = array.GetAt(i, vdType.GUID); | ||
yield return new VirtualDesktop(this.ComInterfaceAssembly, ppvObject); | ||
} | ||
} | ||
|
||
public IVirtualDesktop GetCurrentDesktop() | ||
=> this.InvokeMethodAndWrap(); | ||
|
||
public IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, AdjacentDesktop uDirection) | ||
=> this.InvokeMethodAndWrap(Args(((VirtualDesktop)pDesktopReference).ComObject, uDirection)); | ||
|
||
public IVirtualDesktop FindDesktop(Guid desktopId) | ||
=> this.InvokeMethodAndWrap(Args(desktopId)); | ||
|
||
public IVirtualDesktop CreateDesktop() | ||
=> this.InvokeMethodAndWrap(); | ||
|
||
public void SwitchDesktop(IVirtualDesktop desktop) | ||
=> this.InvokeMethod(Args(((VirtualDesktop)desktop).ComObject)); | ||
|
||
public void MoveDesktop(IVirtualDesktop pMove, int nIndex) | ||
=> this.InvokeMethod(Args(((VirtualDesktop)pMove).ComObject, nIndex)); | ||
|
||
public void RemoveDesktop(IVirtualDesktop pRemove, IVirtualDesktop pFallbackDesktop) | ||
=> this.InvokeMethod(Args(((VirtualDesktop)pRemove).ComObject, ((VirtualDesktop)pFallbackDesktop).ComObject)); | ||
|
||
public void MoveViewToDesktop(IntPtr hWnd, IVirtualDesktop desktop) | ||
=> this.InvokeMethod(Args(this._factory.ApplicationViewFromHwnd(hWnd).ComObject, ((VirtualDesktop)desktop).ComObject)); | ||
|
||
public void SetDesktopName(IVirtualDesktop desktop, string name) | ||
=> this.InvokeMethod(Args(((VirtualDesktop)desktop).ComObject, new HString(name))); | ||
|
||
public void SetDesktopWallpaper(IVirtualDesktop desktop, string path) | ||
=> this.InvokeMethod(Args(((VirtualDesktop)desktop).ComObject, new HString(path))); | ||
|
||
public void UpdateWallpaperPathForAllDesktops(string path) | ||
=> this.InvokeMethod(Args(new HString(path))); | ||
|
||
private VirtualDesktop InvokeMethodAndWrap(object?[]? parameters = null, [CallerMemberName] string methodName = "") | ||
=> new(this.ComInterfaceAssembly, this.InvokeMethod<object>(parameters, methodName) ?? throw new Exception("Failed to get IVirtualDesktop instance.")); | ||
} |
Oops, something went wrong.