MScholtes / VirtualDesktop

C# command line tool to manage virtual desktops in Windows 10
MIT License
606 stars 60 forks source link

[Feature Request] Option to list all windows running in current desktop #54

Closed AkazaRenn closed 1 year ago

AkazaRenn commented 1 year ago

I want to close them before switching to another one, otherwise they will be brought over when the this desktop is closed. Getting a list of all the windows only on the current desktop would be very helpful.

Not sure if it's an easy implementation but always thanks for the great job, it helped me a lot.

MScholtes commented 1 year ago

Hello @AkazaRenn,

this is a comprehensible suggestion, but I guess your feature request is something different: "Option to list all processes (or rather process ids) that have windows on the current (or chosen) desktop"

Reason: You cannot close windows of "foreign" processes (without probably crashing the associated program) and if you send a "WM_CLOSE" message, you never know whether it succeeds or you send this message to a child window.

Is this correct?

Greetings

Markus

AkazaRenn commented 1 year ago

Hello @AkazaRenn,

this is a comprehensible suggestion, but I guess your feature request is something different: "Option to list all processes (or rather process ids) that have windows on the current (or chosen) desktop"

Reason: You cannot close windows of "foreign" processes (without probably crashing the associated program) and if you send a "WM_CLOSE" message, you never know whether it succeeds or you send this message to a child window.

Is this correct?

Greetings

Markus

I think I would prefer a window handler which can be used to differentiate between windows in current desktop or not, instead of a process ID, so no accidental kills. However, it's fine to use process ID's if window handles are harder to acquire.

What I want ultimately is to simulate this behavior with scripting: before switching out (and kill) this desktop, for all windows presenting on the task bar, right-click on each one of them and select close.

Hope it clarifies!

ev-dev commented 1 year ago

This feature would be very interesting!

If implemented, it could provide a technique to do something I've always wanted to be able to do with this tool: "Move all the windows on desktop 1 to desktop 2"

Even without specifically implementing that sort of operation in the code here, the OP's requested feature would at least provide a potential for scripting what I mentioned as well.

PS. Thanks for updating this tool's compatability with newer insider builds even when Win11 releases made it break again so many times!

ev-dev commented 1 year ago

Wow actually I hadn't seen that you have updated the PSVirtualDesktop module recently as well, great work!

I was able to script exactly what I had mentioned above and even include a filter for matching against window titles so I can now: "Move all windows on desktop A (or -CurrentDesktop) that match [pattern] to desktop B"

Maybe I'll throw it in a gist or something if I/anyone find it useful. Thanks again!

MScholtes commented 1 year ago

Hello @AkazaRenn , hello @ev-dev,

the requests you're making are not very difficult to fulfill programmatically. But contrary to the Powershell environment of PSVirtualDesktop VirtualDesktop.exe acts in a cmd.exe environment. There is no possibility to return arrays of handles to the pipeline, cmd.exe only handles strings.

I see two options:

What do you think?

Greetings

Markus

AkazaRenn commented 1 year ago

@MScholtes Option 1 is perfect. I personally can handle the processing of the string by myself.

Aside from that, I feel like letting the app to kill those windows are a bit beyond the original purpose of itself.

Thank you!

MScholtes commented 1 year ago

Hello @AkazaRenn, hello @ev-dev,

I released the version 1.12 of VirtualDesktop tody that includes the new parameters /ListWindowsOnDesktop, /MoveWindowsToDesktop and /CloseWindowsOnDesktop.

They were so similiar to implement, that I decided to deliver all three ideas.

Greetings

Markus

AkazaRenn commented 1 year ago

Thank you so much!