Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

197 Commits

Repository files navigation

VirtualDesktop

.NET library for Windows multiple desktop operations

Windows 11Windows 10

BuildPublishLicense

PlatformNuGetDownloads
CoreNuGet BadgeNuGet Downloads
FormsNuGet BadgeNuGet Downloads
WPFNuGet BadgeNuGet Downloads

Features

  • Switch, add, and remove a virtual desktop
  • Move any window to any virtual desktop
  • Pin any window or application for them to show on all desktops
  • Notifications when switching, deleting, or renaming virtual desktops
  • Change the wallpaper for each desktop

Sample app

samples/VirtualDesktop.Showcase

Requirements

<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
  • .NET 6.0
  • .NET 7.0
  • .NET 8.0
  • Windows 10 build 19041 (20H1) or later

Installation

Install NuGet package(s).

PM>Install-Package VirtualDesktop

How to use

Preparation

Because of the dependency on C#/WinRT, the target framework must be set to net6.0-windows10.0.19041.0 or later.

<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>

If it does not work, try creating an app.manifest file optimized to work on Windows 10.

<compatibilityxmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 / 11-->
<supportedOSId="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>

The namespace to use is WindowsDesktop.

usingWindowsDesktop;

Get instance of VirtualDesktop class

// Get all virtual desktopsvardesktops=VirtualDesktop.GetDesktops();// Get Virtual Desktop for specific windowvardesktop=VirtualDesktop.FromHwnd(hwnd);// Get the left/right desktopvarleft=desktop.GetLeft();varright=desktop.GetRight();

Manage virtual desktops

// Create newvardesktop=VirtualDesktop.Create();// Removedesktop.Remove();// Switchdesktop.GetLeft().Switch();

Subscribe virtual desktop events

// Notification of desktop switchingVirtualDesktop.CurrentChanged+=(_,args)=>Console.WriteLine($"Switched: {args.NewDesktop.Name}");// Notification of desktop creatingVirtualDesktop.Created+=(_,desktop)=>desktop.Switch();

for WPF window

// Need to install 'VirtualDesktop.WPF' package// Check whether a window is on the current desktop.varisCurrent=window.IsCurrentVirtualDesktop();// Get Virtual Desktop for WPF windowvardesktop=window.GetCurrentDesktop();// Move window to specific Virtual Desktopwindow.MoveToDesktop(desktop);// Pin windowwindow.Pin()

Windows version support

Since this library is using undocumented interfaces, you need to reverse engineer your Windows version to support it.

The class IDs of undocumented interfaces tend to change between different OS versions. If the demo application crashes on start-up, you will need to provide the interfaces' IDs matching your Windows version.

Here are the interfaces we need:

  • IApplicationView
  • IApplicationViewCollection
  • IObjectArray
  • IServiceProvider
  • IVirtualDesktop
  • IVirtualDesktopManager
  • IVirtualDesktopManagerInternal
  • IVirtualDesktopNotification
  • IVirtualDesktopNotificationService
  • IVirtualDesktopPinnedApps

Once you have those IDs, add them in a new setting element in app.config. Make sure to specify the correct 9 digits Windows build and cumulative update version. You can get it using one of those methods:

  • From the UI run: winver
  • From shell run: ver
  • From powershell run: cmd /c ver

Don't forget to contribute back your changes.

Publish

To publish a new release specify your version in Directory.Build.props and push the changes with a commit description such as: Release vx.y.z where x, y, z form your version number. That should publish it on NuGet providing that your secret NUGET_API_KEY is still valid.

Internals

This library is essentially a C# wrapper for IVirtualDesktopManager and related undocumented interfaces. In order to support breaking binary changes between Windows versions we perform runtime compilation of a DLL providing access to the COM interfaces matching your OS build version.

Resources

License

This library is under the MIT License.

Credits

  • Thanks @Grabacr07 for creating this great piece of software
  • All contributors for sharing your work with the community

About

.NET library for Windows multiple desktop operations

Topics

Resources

Stars

42 stars

Watchers

7 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages