Slions.VirtualDesktop
6.6.0
dotnet add package Slions.VirtualDesktop --version 6.6.0
NuGet\Install-Package Slions.VirtualDesktop -Version 6.6.0
<PackageReference Include="Slions.VirtualDesktop" Version="6.6.0" />
paket add Slions.VirtualDesktop --version 6.6.0
#r "nuget: Slions.VirtualDesktop, 6.6.0"
// Install Slions.VirtualDesktop as a Cake Addin #addin nuget:?package=Slions.VirtualDesktop&version=6.6.0 // Install Slions.VirtualDesktop as a Cake Tool #tool nuget:?package=Slions.VirtualDesktop&version=6.6.0
VirtualDesktop
VirtualDesktop is C# wrapper for IVirtualDesktopManager on Windows 11 (and Windows 10).
Platform | NuGet |
---|---|
Core | |
Forms | |
WPF |
Features
- Switch, add, and remove a virtual desktop.
- Move the window in the same process to any virtual desktop.
- Move the window of another process to any virtual desktop (Support in version 2.0 or later).
- Pin any window or application; will be display on all desktops.
- Notification for switching, deletion, renaming, etc.
- Change the wallpaper for each desktop.
Sample app
samples/VirtualDesktop.Showcase
Requirements
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
- .NET 5, 6 or 7
- Windows 10 build 19041 (20H1) or later
Installation
Install NuGet package(s).
PM> Install-Package VirtualDesktop
- VirtualDesktop - Core classes for VirtualDesktop.
- VirtualDesktop.WPF - Provides extension methods for WPF Window class.
- VirtualDesktop.WinForms - Provides extension methods for Form class.
How to use
Preparation
Because of the dependency on C#/WinRT (repo), the target framework must be set to net5.0-windows10.0.19041.0
or later.
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
If it doesn't work, try creating an app.manifest
file and optimize to work on Windows 10.
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
The namespace to use is WindowsDesktop
.
using WindowsDesktop;
Get instance of VirtualDesktop class
// Get all virtual desktops
var desktops = VirtualDesktop.GetDesktops();
// Get Virtual Desktop for specific window
var desktop = VirtualDesktop.FromHwnd(hwnd);
// Get the left/right desktop
var left = desktop.GetLeft();
var right = desktop.GetRight();
Manage virtual desktops
// Create new
var desktop = VirtualDesktop.Create();
// Remove
desktop.Remove();
// Switch
desktop.GetLeft().Switch();
Subscribe virtual desktop events
// Notification of desktop switching
VirtualDesktop.CurrentChanged += (_, args) => Console.WriteLine($"Switched: {args.NewDesktop.Name}");
// Notification of desktop creating
VirtualDesktop.Created += (_, desktop) => desktop.Switch();
for WPF window
// Need to install 'VirtualDesktop.WPF' package
// Check whether a window is on the current desktop.
var isCurrent = window.IsCurrentVirtualDesktop();
// Get Virtual Desktop for WPF window
var desktop = window.GetCurrentDesktop();
// Move window to specific Virtual Desktop
window.MoveToDesktop(desktop);
// Pin window
window.Pin()
Windows version support
The class IDs of some of the undocumented interfaces we use tend to change a lot between different versions of Windows. If the demo application crashes on start-up chances are all you need to do is provide the proper IDs for the version of Windows you are running on.
Open regedit
and export this path into a file: \HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface
.
Open the resulting reg file and search it for matches against the whole word of each interface name we need:
IApplicationView
IApplicationViewCollection
IObjectArray
IServiceProvider
IVirtualDesktop
IVirtualDesktopManager
IVirtualDesktopManagerInternal
IVirtualDesktopNotification
IVirtualDesktopNotificationService
IVirtualDesktopPinnedApps
Once you have the IDs add them in a new setting
element in app.config.
Make sure to specify the correct 5 digits Windows build 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
Make sure 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.
Resources
License
This library is under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0-windows10.0.19041 is compatible. net6.0-windows was computed. net6.0-windows10.0.19041 is compatible. net7.0-windows was computed. net7.0-windows10.0.19041 is compatible. net8.0-windows was computed. net8.0-windows10.0.19041 is compatible. |
-
net5.0-windows10.0.19041
- Microsoft.CodeAnalysis.CSharp (>= 4.0.1)
-
net6.0-windows10.0.19041
- Microsoft.CodeAnalysis.CSharp (>= 4.0.1)
-
net7.0-windows10.0.19041
- Microsoft.CodeAnalysis.CSharp (>= 4.0.1)
-
net8.0-windows10.0.19041
- Microsoft.CodeAnalysis.CSharp (>= 4.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Slions.VirtualDesktop:
Package | Downloads |
---|---|
Slions.VirtualDesktop.WinForms
C# Wrapper for the Virtual Desktop API on Windows 11 (and Windows 10). |
|
Slions.VirtualDesktop.WPF
C# Wrapper for the Virtual Desktop API on Windows 11 (and Windows 10). |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
6.6.0 | 1,626 | 2/20/2024 |
6.5.0 | 128 | 2/4/2024 |
6.4.0 | 244 | 11/27/2023 |
6.3.0 | 158 | 11/21/2023 |
6.2.1 | 286 | 9/1/2023 |
6.2.0 | 135 | 9/1/2023 |
6.1.0 | 157 | 9/1/2023 |
6.0.0 | 144 | 8/31/2023 |
5.2.0 | 197 | 8/18/2023 |
5.1.2 | 164 | 8/16/2023 |
5.1.1 | 150 | 8/12/2023 |
5.1.0 | 165 | 8/12/2023 |
5.0.9 | 167 | 8/12/2023 |
5.0.7 | 155 | 8/12/2023 |
5.0.6 | 166 | 8/12/2023 |
v6.6.0
Support OS Build 22631.3155
Support OS Build 22621.3155
v6.5.0
Support for .NET 8.0
v6.4.0
Fix crash when changing desktop
v6.3.0
Desktop move support
v6.2.1
Add mzomparelli to list of authors
v6.2.0
Better OS version resolution
v6.1.0
Support OS Build 20348.1906
v6.0.0
Support OS Build 22621.2215
v5.2.0
Support for .NET 7.0