huettenhain / frc

A FAR Manager Plugin for Integration with Everything File Search
12 stars 1 forks source link

Minimized Far #4

Closed pasha-zzz closed 3 months ago

pasha-zzz commented 3 months ago

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?

huettenhain commented 3 months ago

Sounds good, thanks for the suggestion. I will try both and see what works.

huettenhain commented 3 months ago

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.

huettenhain commented 3 months ago

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.

huettenhain commented 3 months ago

Alright, I figured out how to do it. Works in all my tests now.

huettenhain commented 3 months ago

Fixed in V2.3. I will release this on the plugring ASAP.

pasha-zzz commented 3 months ago

Alright, I figured out how to do it. Works in all my tests now.

Not working if ConEmu is used. Stays minimized.

huettenhain commented 3 months ago

Dang. I only tested with Windows Terminal, I will test with ConEmu.

huettenhain commented 3 months ago

I can reproduce this with ConEmu, but I do not know how to solve it.

huettenhain commented 3 months ago

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.

pasha-zzz commented 3 months ago
  • 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.

huettenhain commented 3 months ago

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.