microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
109.18k stars 6.44k forks source link

PowerShell integration for FancyZones #6653

Open dossen opened 3 years ago

dossen commented 3 years ago

It would be really practical to be able to move windows to a desired zone using a PowerShell cmdlet. Likewise for switching between FancyZones layouts.

When changing between different screen-setups, I'd like to be able to just run a script that checks which setup I'm on and which programs are running to then move them to their designated zone on the right screen. While there is not yet support for multiple monitors in FancyZones, it works decently enough. And using a 3rd party tool like MultiMonitorTool.exe I can manipulate the setup and move programs to the right screen. What I cannot do (without this enhancement to PowerToys) is make sure the windows snap to their zones. It works sometimes, if the windows happen to have already been snapped and thus appear in the right position.

This enhancement would in the ideal case go together with the one about multi monitor support :-)

Aaron-Junker commented 3 years ago

Can you tell me a useful case you need this?

ghost commented 3 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 5 days. It will be closed if no further activity occurs within 5 days of this comment.

dossen commented 3 years ago

In my case, I switch between different desktop setups.

What I'm imagining would be a simple commandlet that takes a process and/or a specific window (by name-filtering or whatever is practical) and the identity of a specific zone in the current FancyZones layout and behaves exactly like the window was dragged to that zone. Then I could have a script that made sure my usual programs (Visual Studio, Remote Desktops, Outlook, Teams, browsers, etc.) were running and moved all of them to my preferred zone.

As I said in the initial entry, this would complement multimonitor support quite nicely (I'm currently running a laptop docked to four monitors for my usual workstation and another docking setup with three monitors as well as taking the laptop out of its dock), and even better if it was also possible to switch the currently active layout to another from PowerShell.

As far as editing the layouts, I don't think that needs to be exposed to PowerShell (though it would be nice - imagine rolling out FancyZones layouts to a fleet of servers and having well thought out zones available when remoting in - since remote desktop with multiple monitors is not really a "done" thing ;-)). But if there were to be some kind of support, I'd suggest that saving, restoring (with the option to overwrite), listing, and deleting the layouts in some serialized format (JSON or XML springs to mind) would be a low weight solution that would allow a lot to be done.

I know it's a niche desire, but I also think a lot of the really interesting uses for something like FancyZones show up when some flexible programmatic interface becomes available. I'd love to have a Windows desktop experience where everything I could tweak with the mouse through dialogs could also be adjusted easily from PowerShell, so I could quickly get new installs of Windows adjusted to the way I like them.

psychuil commented 2 years ago

This would be amazing, being able to change where everything is when moving setups would be very useful

ImaBadCoder commented 2 years ago

I would love to see this as well. I have one configuration for leading Teams meetings and another for my daily work. Would be great to use PowerShell for this automation between configurations.

codingHippo commented 2 years ago

I have PowerShell scripts that open a set of different applications based on what my workflow is. Development/Photography/Writing and so on.

I would very much like to pick a layout, and then populate it with applications. There would be a 1:1 relationship between windows and zones in my case.

Currently I am solving this by manually placing each window. To do this is a lot more complicated that it ought to be.

It would make it much easier and flexible to ask the script to put the window in a fancy zone in a layout.

An added benefit would be that I could adjust the layout without having to alter my script and that would be fantastic.

PaulHoving commented 2 years ago

Can you tell me a useful case you need this?

For a kiosk-alike videowall that starts every morning. I now use WASP.DLL and put windows on window coordinates. Would be nice to have a powershell function like this: Set-WindowFancyZone -window $window.handle -display 1 -zone 2 to put a window to a certain zone. :-)

Appa-lw commented 2 years ago

This would be a great feature!

I imagen starting up my device and everything starts up in the desired zone. Even over multiple virtual Desktops for different working enviorments. For e.g. if i work on a script in VS Code and i have to switch to my "Helpdesk"-Enviorment, i don't need to prepare all the different enviorments after start up. Instead i can start right away and everything is at it's place. .

bpluly commented 1 year ago

I have 6 virtual desktops, I use FancyZone differently in different desktops. One of the desktops is an array of 3x3 Powershell windows. On start up I have a script which starts the nine consoles, I then have to drag each one manually to its zone. I would like to add the move to the script.

I've messed a little with SendWait but not with any success..

MickFly commented 1 year ago

Would love a cmdlet to send windows to specific fancy zones! For daily work startup or for videowall purposes

shodanx2 commented 1 year ago

Hello, I found this issue while searching for a way to make a script that will send all my correct pre-determined windows to their respective fancyzones.

I have 5 monitors and sometimes something will change and scramble all my windows all over the place, so I'm trying to make one script to put everything back in its place with one click.

DiegoSpinola commented 1 year ago

This would be really useful for me too , I've been searching for a way to automate the startup of my development environments but no luck... if anyone knows of a way to programmatically place windows into a given fancy zones let me know too...

mircboe commented 1 year ago

Can you tell me a useful case you need this?

What kind of question is this? Isn't PowerToys for POWER users? This is one of those features you don't know you need until you have it. Like the iPhone in 2008. So I guess the answer to my question is "certainly not a visionary's, but that of a jaded BDFL's."

Since they're not gonna implement it, I guess one idea would be to parse the JSON "C:\Users\$UserName\AppData\Local\Microsoft\PowerToys\FancyZones\custom-layouts.json" and get the zones from jsonData["custom-layouts"][0]["zones"] (because of course they used a dash in the key names so we can't access it in a sane manner - jsonData.cusomLayouts[0].zones for example). Then you can use your favorite UI manipulation method to move the windows there.

As an added bonus, now you also know how to do pixel accurate editing of the zones. Which is another issue they dismissed without even telling us we could edit this very JSON file. I had to find it on stackoverflow or serverfault or something. I guess it's too hard to make the size information (under the zone number) editable textboxes instead of text.

FROM:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                   ┃
┃                                   ┃
┃                                   ┃
┃                                   ┃
┃                (1)                ┃
┃             800 x 600             ┃
┃                                   ┃
┃                                   ┃
┃                                   ┃
┃                                   ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

TO:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                   ┃
┃                                   ┃
┃                                   ┃
┃                                   ┃
┃                (1)                ┃
┃           [800] x [600]           ┃
┃                                   ┃
┃                                   ┃
┃                                   ┃
┃                                   ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Nocture commented 1 year ago

Came across this, while googling how to do a script to attach windows to the FancyZones layouts.

Any plans on implementing this?

angelhdzmultimedia commented 9 months ago

Hello everyone and props to the PowerToys team for the great work!

My vote for this feature! +1 👍

I need this feature because I'm developer and was finding having to open 2 Windows Terminal windows for client and server, then snap each to the left one above the other, then open VSCode, and snap it to the left, so I started using Power Automate for all these tasks, even typing the Current Working Directory of my project and it opens the terminals at that path, and also apply a different color to the active tab of each window (green for Client - Nuxt, and red for Server - NestJS) and adds the title for them.

So my only missing piece of this puzzle is being able to send these windows to their places in the layout I created.

image

image

shodanx2 commented 8 months ago

Just a heads up, if you just want your window to go back to their zones after docking or any monitor change.

https://github.com/manutalcual/winredock

Winredock monitor windows and put them back in their place.

Fancyzone has an option to put windows in their previous zone. But that's only for new window, and it doesn't work if you have many similar window (example firefox or terminal) and it doesn't have an exception list.

wolfhoundjesse commented 8 months ago

I've been asking about this for a few years, thinking this was a unique request. Looks like I'm not the only one!

My use case is similar to @angelhdzmultimedia. I have a 43" monitor and use various tiled layouts, some for Picture in Picture, streaming, development, etc. Switching layouts is nice, but the windows don't always end up where I'd expect. For development, I have four terminal windows with specific positions, each named and generated with a PowerShell script. I'm just looking for a way to not have to drag them where they go every time I run the script. It's not a real issue, but like everyone else, I just want to be in control. lol

Baleine82 commented 1 month ago

I’d love to see that too. I’m testing an UWQHD screen for development purposes on which we’re using an application using a FHD app designed to be full screen. It would be quite useful for us to have the window to force going into a defined zone when we’re debugging it.