OK, so rereading this patch in the morning when I'm feeling more awake, I can see a few mistakes that slipped past my review last night. To save people the hassle of point them out to me, here they are:
1) The whole of X11DRV_systray_dock_window should probably be protected with a TS lock, instead of just the middle section.
2) The line: X11DRV_systray_dock_window(display, undockedTrayIcons[0]) should use (undockedTrayIconsCount - 1) as the index, not 0.
3) Whitespace noise in the part that sets the KDE hints
4) Commented out line I used for debugging made its way into the patch.
5) This confuses me:
- ... create_desktop( Display *display, WND *wndPtr ) + ... create_desktop( Display *display, WND *wndPtr, CREATESTRUCTA *cs ) + SendMessageW( wndPtr->hwndSelf, WM_NCCREATE, 0, (LPARAM)cs );
as I don't remember writing that code.
Presumably the createstruct parameter was there when I first wrote the patch and removed later without me noticing, as I diffed the tree in a different location to where I wrote it, CVS thought I readded it. So I guess this is "old code" noise.
I'll try again tonight.