MScholtes/VirtualDesktop

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

AkazaRenn opened this issue · 8 comments

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.

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

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!

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!

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!

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:

  • a new command for virtualdesktop that returns a list of handle numbers of all windows of a given desktop separated by space or carriage returns as text
  • two new commands: one of them sends a Close signal to all windows on a given desktop, the other moving all windows of a given desktop to another given desktop. Similiar commands already exist with /SwapDesktop, /InsertDesktop (Win10) oder /MoveDesktop (Win11).

What do you think?

Greetings

Markus

@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!

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

Thank you so much!