r/PowerShell • • 5d ago

Script Sharing A dock, desktop widget and falling snow for Windows, all in one PowerShell script (WPF + a bit of C#)

MacDesk is a macOS-style dock and desktop widget written in Windows PowerShell 5.1 with WPF. This winter it also got snow that settles on your windows.

Things that were fun or painful to get right:

- The snow overlay can't be a WPF window. WPF removes WS_EX_LAYERED from GPU-rendered windows, so a "transparent" overlay ends up eating every click on the desktop (I found out the hard way). It's now raw Win32 layered windows painted by hand with UpdateLayeredWindowIndirect, updating only the rectangles that changed.

- It runs on its own thread and paces frames with DwmFlush, which gave a steady 60 fps. A DispatcherTimer gave uneven 20-40 fps.

- Window tops come from EnumWindows plus DWMWA_EXTENDED_FRAME_BOUNDS, with z-order occlusion so snow only lands on visible edges.

- The C# is compiled at startup with Add-Type, so it's limited to C# 5.

- If the overlay ever loses click-through, a watchdog turns the snow off.

Repo: https://github.com/b33nthere/MacDesk

Feedback on the code is welcome, especially the WPF / Win32 parts.

2 Upvotes

1 comment sorted by

2

u/BlackV 3d ago

Things that were fun or painful to get right:

Have you seen the updated Sub rules

Rule 11 - AI Disclosure
If you’ve used AI or any other generative model or LLMs to write your script, tool, or whatever, it must be disclosed.

https://www.reddit.com/r/PowerShell/comments/1x6aq6v/new_rule_ai_disclosure/