Re: 6/6 - the desktop needs to be in the processes session. Checking for NULL after inheriting the winstation won't change if the parent process is a valid winstation, but not in the user's session.
But I agree that forced switching should probably come as a last fallback; if no winstation is found or nothing could be intherited or the inherited winstation lives in a different session, then we should reset to the default. Maybe it is a wise idea to test what windows does here, but I am still not entirely sure how to code such a test within the WINE conformance tests - WTSQueryUserToken is basically only callable from within a service context, and I still understand winetest way to little to implement this into the wtsapi tests.
It might not be possible to do in an automated way, but it's probably worth testing at least manually whether you can create a process with a different session *and* a non-default window station that was previously created that matches that session, and other things of that ilk. I don't know if you can even do that from a service, can you? Maybe it needs RDP or multi-user to properly work, in which case it's definitely not something we can automate, and that's fine.
Regarding the switch, yeah, I thought that this conveys a bit clearer than an if/else that the two cases are session 0 and 1 (with 1 adopting the default). But I can surely change that and explain the case in a comment.
Well, even if we had other sessions, wouldn't they also use WinSta0?
Re: 1-5/6: I'll implement this in the next iteration. Sorry for the noise in review; I am still getting acquainted to the WINE code base and "how things are usually done". Thank you for taking the time to point out the little things!
Thanks. I do hate nitpicking style anyway. One of the odd things with Wine especially is that we don't want people to touch more code than they have to, and generally tell people to match the surrounding style, but then if existing code is stylistically ugly we'd prefer that to be fixed if you're touching it... -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9843#note_127475