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

Fix for 22631.3155 #22

Merged
merged 1 commit into from
Feb 17, 2024
Merged
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
47 changes: 47 additions & 0 deletions src/VirtualDesktop/Interop/Build22631_3155/.Provider.cs
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);
}

}
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();


}
}
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();
}
}
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);
}

}
}
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 src/VirtualDesktop/Interop/Build22631_3155/VirtualDesktop.cs
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>();
}
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."));
}
Loading
Loading