How to Position Windows Terminal Similar to Cygwin’s Mintty?

0
5
Asked By TechieGamer99 On

I've been using Cygwin for years and I'm finally making the switch to WSL2 for improved security among other reasons. Cygwin's terminal app, mintty, allows me to easily position terminal windows using simple command-line arguments, such as specifying their positions on the screen with options like "top", "bottom", "left", and "right". I have a batch script that launches eight Cygwin terminals in each corner of two monitors, which has become my routine workflow.

While Windows Terminal does offer some positioning options, it doesn't allow the same relative positioning commands as mintty. I even tried using "GenXdev.Windows Set-WindowPosition", but it seems like all the Windows Terminal instances share the same PID, which confuses me regarding Windows processes and handles.

Does anyone have tips on how to achieve this kind of window positioning in Windows Terminal?

2 Answers

Answered By WindowWizard123 On

You might want to check out the command line arguments for Windows Terminal. That page can give you an overview of what options you can use. However, I believe it doesn't quite support those relative placements like "top left" from mintty, so you're likely out of luck there.

CodeExplorer88 -

Yeah, I noticed the same thing. It seems like Windows Terminal lacks those direct positioning capabilities that mintty offers.

Answered By PowerProGuy On

I know it’s a bit complicated, but you can use Win32 functions in your script to manually adjust window positions. You'll need unique window titles to differentiate between the terminal instances. Here’s a basic example of how to do this using PowerShell, which you might find helpful:

`````
# Launch Notepad and wait for its main window
$proc = Start-Process notepad -PassThru
$null = $proc.WaitForInputIdle()

# Add Win32 functions once per session
if (-not ("Win32" -as [type])) {
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
using System;
using System.Runtime.InteropServices;

public class NativeMethods {
[DllImport("user32.dll", SetLastError=true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int X, int Y, int cx, int cy, uint uFlags);

public static readonly IntPtr HWND_TOP = IntPtr.Zero;
public const UInt32 SWP_NOSIZE = 0x0001;
public const UInt32 SWP_NOMOVE = 0x0002;
public const UInt32 SWP_NOZORDER = 0x0004;
public const UInt32 SWP_NOACTIVATE = 0x0010;
}
"@
}

# Move & resize
[Win32.NativeMethods]::SetWindowPos($proc.MainWindowHandle,
[Win32.NativeMethods]::HWND_TOP,
100, 100, 1200, 800, 0) | Out-Null
`````

CuriousCoder07 -

Thanks for this! I think making use of unique titles is crucial to managing window handles, and your sample code is super helpful.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.