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

Add support for 22449 & correct naming #1

Open
wants to merge 1 commit into
base: develop
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal interface IVirtualDesktopManagerInternal2

void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);

void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
void SetDesktopName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
}

// see also:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal interface IVirtualDesktopManagerInternal3

void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);

void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
void SetDesktopName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);

void Unknown2(IApplicationView pUnknown0, IApplicationView pUnknown1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ internal interface IVirtualDesktopManagerInternal

IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);

void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);

void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
void SetDesktopName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);

void Unknown2(IApplicationView pUnknown0, IApplicationView pUnknown1);
void CopyDesktopState(IApplicationView pUnknown0, IApplicationView pUnknown1);

int Unknown3();
int GetDesktopIsPerMonitor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ internal interface IVirtualDesktopManagerInternal

IVirtualDesktop FindDesktop([In, MarshalAs(UnmanagedType.LPStruct)] Guid desktopId);

void Unknown1(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);
void GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop pDesktop, out IObjectArray pUnknown1, out IObjectArray pUnknown2);

void SetName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);
void SetDesktopName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);

void SetWallpaperPath(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);
void SetDesktopWallpaper(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);

void Unknown2([MarshalAs(UnmanagedType.HString)] string chText);
void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string chText);

void Unknown3(IApplicationView pUnknown0, IApplicationView pUnknown1);
void CopyDesktopState(IApplicationView pUnknown0, IApplicationView pUnknown1);

int Unknown4();
int GetDesktopIsPerMonitor();
}
}
Original file line number Diff line number Diff line change
@@ -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<Guid, VirtualDesktop> _wrappers = new ConcurrentDictionary<Guid, VirtualDesktop>();

public Func<Guid, object, VirtualDesktop> 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 GetAllCurrentDesktops();//7

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 GetDesktopSwitchIncludeExcludeViews(IVirtualDesktop desktop, out IObjectArray unknown1, out IObjectArray unknown2);//15

void SetDesktopName(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chName);

void SetDesktopWallpaper(IVirtualDesktop pDesktop, [MarshalAs(UnmanagedType.HString)] string chPath);

void UpdateWallpaperPathForAllDesktops([MarshalAs(UnmanagedType.HString)] string wallpaper);//18

void CopyDesktopState(IApplicationView pView0, IApplicationView pView1);//19

int GetDesktopIsPerMonitor();//20

void GetDesktopIsPerMonitor(int state);//21
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public VirtualDesktopManagerInternal(ComInterfaceAssembly assembly, uint latestV

public abstract VirtualDesktop FindDesktop(Guid desktopId);

public abstract void SetName(VirtualDesktop desktop, string name);
public abstract void SetDesktopName(VirtualDesktop desktop, string name);

public abstract void SetWallpaperPath(VirtualDesktop desktop, string path);
public abstract void SetDesktopWallpaper(VirtualDesktop desktop, string path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public override VirtualDesktop FindDesktop(Guid desktopId)
private VirtualDesktop GetDesktop(object[] parameters = null, [CallerMemberName] string methodName = "")
=> VirtualDesktopCache.GetOrCreate(this.Invoke<object>(parameters, methodName));

public override void SetName(VirtualDesktop desktop, string name)
public override void SetDesktopName(VirtualDesktop desktop, string name)
{
if (this.ComVersion < 2) throw new PlatformNotSupportedException("This Windows 10 version is not supported.");

this.Invoke(Args(desktop.ComObject, name));
}

public override void SetWallpaperPath(VirtualDesktop desktop, string path)
public override void SetDesktopWallpaper(VirtualDesktop desktop, string path)
{
throw new PlatformNotSupportedException("This Windows 10 version is not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public override VirtualDesktop FindDesktop(Guid desktopId)
private VirtualDesktop GetDesktop(object[] parameters = null, [CallerMemberName] string methodName = "")
=> VirtualDesktopCache.GetOrCreate(this.Invoke<object>(parameters, methodName));

public override void SetName(VirtualDesktop desktop, string name)
public override void SetDesktopName(VirtualDesktop desktop, string name)
{
this.Invoke(Args(desktop.ComObject, name));
}

public override void SetWallpaperPath(VirtualDesktop desktop, string path)
public override void SetDesktopWallpaper(VirtualDesktop desktop, string path)
{
throw new PlatformNotSupportedException("This Windows 10 version is not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public override VirtualDesktop FindDesktop(Guid desktopId)
private VirtualDesktop GetDesktop(object[] parameters = null, [CallerMemberName] string methodName = "")
=> VirtualDesktopCache.GetOrCreate(this.Invoke<object>(parameters, methodName));

public override void SetName(VirtualDesktop desktop, string name)
public override void SetDesktopName(VirtualDesktop desktop, string name)
{
this.Invoke(Args(desktop.ComObject, name));
}

public override void SetWallpaperPath(VirtualDesktop desktop, string path)
public override void SetDesktopWallpaper(VirtualDesktop desktop, string path)
{
this.Invoke(Args(desktop.ComObject, path));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace WindowsDesktop.Interop
{
[ComInterfaceWrapper("IVirtualDesktopManagerInternal", 22449)]
internal sealed class VirtualDesktopManagerInternal22449 : VirtualDesktopManagerInternal
{
public VirtualDesktopManagerInternal22449(ComInterfaceAssembly assembly)
: base(assembly)
{
}

public override void MoveViewToDesktop(ApplicationView pView, VirtualDesktop desktop)
{
this.Invoke(Args(pView.ComObject, desktop.ComObject));
}

public override VirtualDesktop GetCurrentDesktop()
{
return this.GetDesktop(Args(IntPtr.Zero));
}

public override IEnumerable<VirtualDesktop> GetDesktops()
{
var array = this.Invoke<IObjectArray>(Args(IntPtr.Zero));
var count = array.GetCount();
var vdType = this.ComInterfaceAssembly.GetType("IVirtualDesktop");

for (var i = 0u; i < count; i++)
{
array.GetAt(i, vdType.GUID, out var ppvObject);
yield return VirtualDesktopCache.GetOrCreate(ppvObject);
}
}

public override VirtualDesktop GetAdjacentDesktop(VirtualDesktop pDesktopReference, AdjacentDesktop uDirection)
{
return this.GetDesktop(Args(pDesktopReference.ComObject, uDirection));
}

public override void SwitchDesktop(VirtualDesktop desktop)
{
this.Invoke(Args(IntPtr.Zero, desktop.ComObject));
}

public override VirtualDesktop CreateDesktopW()
{
return this.GetDesktop(Args(IntPtr.Zero));
}

public override void MoveDesktop(VirtualDesktop desktop, int index)
{
this.Invoke(Args(desktop.ComObject, IntPtr.Zero, index));
}

public override void RemoveDesktop(VirtualDesktop pRemove, VirtualDesktop pFallbackDesktop)
{
this.Invoke(Args(pRemove.ComObject, pFallbackDesktop.ComObject));
}

public override VirtualDesktop FindDesktop(Guid desktopId)
{
return this.GetDesktop(Args(desktopId));
}

private VirtualDesktop GetDesktop(object[] parameters = null, [CallerMemberName] string methodName = "")
=> VirtualDesktopCache.GetOrCreate(this.Invoke<object>(parameters, methodName));

public override void SetDesktopName(VirtualDesktop desktop, string name)
{
this.Invoke(Args(desktop.ComObject, name));
}

public override void SetDesktopWallpaper(VirtualDesktop desktop, string path)
{
this.Invoke(Args(desktop.ComObject, path));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class ComInterfaceAssemblyProvider
private static readonly Regex _assemblyRegex = new Regex(@"VirtualDesktop\.(?<build>\d{5}?)(\.\w*|)\.dll");
private static readonly string _defaultAssemblyDirectoryPath = Path.Combine(ProductInfo.LocalAppData.FullName, "assemblies");
private static readonly Version _requireVersion = new Version("1.0");
private static readonly int[] _interfaceVersions = new[] { 10240, 20231, 21313 };
private static readonly int[] _interfaceVersions = new[] { 10240, 20231, 21313, 22449 };

private readonly string _assemblyDirectoryPath;

Expand Down
Loading