mskyaxl / wsl-terminal

Terminal emulator for Windows Subsystem for Linux (WSL)
MIT License
3.12k stars 158 forks source link

open-wsl.exe activates existing terminal window if terminal title not changed #92

Closed cuihaoleo closed 6 years ago

cuihaoleo commented 6 years ago

When I called open-wsl.exe to open a new terminal, an existing mintty window (if any) would also get activated for a moment before new window showing up, which was really annoying. But the "bug" failed to be reproduced on another machine of my friend.

After investigation of the source code and my personal config, it turns out that my custom shell prompt (PS1 variable) didn't set terminal title so the default title in wsl-terminal.conf was inherited.

Last part of open-wsl.ahk finds new terminal window by its title and activate it, which causes the buggy behaviour I mentioned:

; Activate window {{{1
Loop, 5 {
    WinActivate, %title%
    if (WinActive(title)) {
        break
    }

    Sleep, 50
}

I know little about Windows and AutoHotkey programming, but window title doesn't seem to be a reliable way to identify window uniquely. Also, I wonder why open-wsl.exe have to activate new mintty window itself. Should not the new window get focused automatically?

goreliu commented 6 years ago

I think I fixed it here (https://github.com/goreliu/wsl-terminal/commit/a89ea7bc15fdd65bd0d8fcb779521231e166dc8a), v0.8.11.