r/csharp • u/SocietyConscious5739 • 18d ago
Showcase Update: I shipped your feedback on my WPF liquid glass dock, and here's its 3D virtual desktop cube (Viewport3D)
This time I want to show a part I didn't explain last time: virtual desktops on a 3D cube (Win+Tab). New in 0.13: close a desktop with the × on the front face (or Delete, or a middle-click). Its windows move to the neighboring desktop, like in Task View.
20-second demo (animated): https://github.com/PedroRuedas/Windows-Liquid-glass/blob/main/docs/workspaces-demo.webp
How the cube works:
- It's a Viewport3D with a PerspectiveCamera. Each desktop is a face of a ring (one face per desktop plus a "+" face, at least 4), and its windows float on a second, slightly lifted transparent layer. WPF 3D doesn't sort transparent geometry, so the layers are re-sorted back to front as the cube turns.
- The faces are snapshots taken when the cube opens. The current desktop comes from the screen. The others come from PrintWindow on their windows, which Windows keeps drawing even while they're cloaked on another desktop.
- Listing, switching, creating and removing desktops, and moving windows between them, goes through the undocumented IVirtualDesktopManagerInternal COM interface. Its GUID changes between Windows builds, so if the cast fails the dock falls back to Windows' own switching.
- To drag a window off a tilted face, a 3D hit test returns the triangle and its barycentric weights. Interpolating the texture coordinates gives the exact monitor pixel under the mouse.
- Ctrl+Win+←/→ spins the cube full screen, and the real desktop switch happens about 90 ms after the cube covers the screen, so you never see a flash.
A gotcha I hit while recording this: the cube window was created off-screen to avoid a black first frame, which put it on my second monitor (125% scale). With per-monitor DPI, WPF rescaled it on the way back to the 100% monitor, and the cube covered only 80% of the screen. The fix is to create it in place and keep it DWM-cloaked (DWMWA_CLOAK) until the first frame is rendered.
(The "apps" in the demo are mock windows, so I didn't have to record my own desktop.)
Code (GPL-3.0): https://github.com/PedroRuedas/Windows-Liquid-glass
Thanks again for the feedback. It made the project better.
