Closed pasha-zzz closed 3 months ago
Sounds good, thanks for the suggestion. I will try both and see what works.
So it turns out I already do this:
HWND console = GetConsoleWindow();
if (IsIconic(console))
ShowWindow(console, SW_SHOW);
BringWindowToTop(console) && SetForegroundWindow(console);
However, I can confirm that this does not work at all. I'll have to figure out to do it properly.
Looks like just calling ShowWindow
without any condition works fine. That said, I am having an issue with the entire restoration logic when FAR runs inside Windows Terminal now that I have to take care of.
Alright, I figured out how to do it. Works in all my tests now.
Fixed in V2.3. I will release this on the plugring ASAP.
Alright, I figured out how to do it. Works in all my tests now.
Not working if ConEmu is used. Stays minimized.
Dang. I only tested with Windows Terminal, I will test with ConEmu.
I can reproduce this with ConEmu, but I do not know how to solve it.
GetConsoleWindow
, but some parent window of it. In FRC, I currently solve this by calling GetForegroundWindow
during SetStartupInfoW
so that I have a handle to whatever the foreground window is at that time.0x403FC
in the below screenshot, when really I need 0x60402
.
GetForegroundWindow
is hWnd
. Then:
GetWindow(hWnd, GW_OWNER)
returns NULL
.GetParent(hWnd)
returns NULL
as well.GetAncestor(hWnd, GA_PARENT)
returns the taskbar window #32769
.Heureka! Enumerating them top-down does actually work for some reason. When calling the following GetRootwindow
on hWnd
, I get the correct window and restoring the terminal works in ConEmu:
typedef struct {
HWND leaf;
HWND root;
BOOL done;
} __GPWDATA;
BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam) {
__GPWDATA* gpw = (__GPWDATA*)lParam;
if (hWnd == gpw->leaf) {
gpw->done = TRUE;
return FALSE;
} else {
EnumChildWindows(hWnd, EnumChildProc, lParam);
return !gpw->done;
}
}
BOOL CALLBACK EnumRootsProc(HWND hWnd, LPARAM lParam) {
__GPWDATA* gpw = (__GPWDATA*)lParam;
if (hWnd == gpw->leaf) {
gpw->done = TRUE;
} else {
EnumChildWindows(hWnd, EnumChildProc, lParam);
}
if (gpw->done) {
gpw->root = hWnd;
return FALSE;
} else {
return TRUE;
}
}
HWND GetRootWindow(HWND hWnd) {
__GPWDATA gpw = { hWnd, NULL, FALSE };
EnumWindows(EnumRootsProc, (LPARAM) &gpw);
if (!gpw.done || !gpw.root)
return hWnd;
return gpw.root;
}
I will do a bit more testing and then likely release 2.4 with the fix.
- I simply do not know a good way to get a handle to ConEmu's actual window so that I can restore it or bring it to the top.
In 2.4 all works fine with ConEmu. But too complex method is used to find ConEmu window I think. In Far plugin try to get ConEmuHWND env variable.
I know many people use ConEmu with FAR, but I would prefer not to hard-code any magic values for a specific terminal emulator. I think doing a top-down search of all windows is fine, and it works with all terminal emulators I have tested: Windows Terminal, CMDer, ConEmu, PowerShell, and the default console.
When Far is minimized after command it stays in minimized state. Now there is BringWindowToTop call but maybe replace it with ShowWindow with SW_SHOW argument or SetForegroundWindow?