Clementine icon indicating copy to clipboard operation
Clementine copied to clipboard

Windows: If I click on the tray icon, Clementine window is not brought to front (with possible fix)

Open HappySeaFox opened this issue 7 years ago • 4 comments

Using Clementine 1.3.1 and Windows 7. Actually I see this issue in all version of Clementine.

Steps to reproduce:

  1. run Clementine
  2. click on a window close button to hide it
  3. open some application, say Firefox
  4. click on Clementine's tray icon

Result: Clementine is shown, but not brought to front. Clementine's icon is flashing in the Windows taskbar.

I am aware of Windows SetForegroundWindow() limitations and I use the following hack to bring my Qt application to front from tray:

DWORD foregroundProcessId;

const HWND foregroundWindow = GetForegroundWindow();
const DWORD foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, &foregroundProcessId);

// foreground process is not ours: attach to it and set focus to us
if(GetCurrentProcessId() != foregroundProcessId)
{
    const DWORD currentThreadId = GetCurrentThreadId();

    // attach to the foreground process and activate our window
    if(!AttachThreadInput(foregroundThreadId, currentThreadId, TRUE))
    {
        qWarning("Cannot attach to the thread %ld (%ld)", foregroundThreadId, GetLastError());
        return;
    }

    activate();
    SetForegroundWindow(reinterpret_cast<HWND>(winId())); // Qt4! Qt5 needs fixing this

    AttachThreadInput(foregroundThreadId, currentThreadId, FALSE);
}
else
    activate();

However this approach may need to run Clementine under administrator, because if a foreground process runs under administrator, we won't be able to attach to it.

HappySeaFox avatar Apr 05 '17 14:04 HappySeaFox

I have the same problem on Linux Mint 17.3

zablotski avatar Jun 24 '17 07:06 zablotski

Same issue not really an issue with fuctionality just an annoying issue when the behaviour expected is it to be brough to the foreground.

Windows 10 version 1803

BigDeeZKnutz avatar Aug 02 '19 21:08 BigDeeZKnutz

Same issue Ubuntu Mate 20.04

nimch avatar May 29 '20 13:05 nimch

same. have to delete the config to be able to see the window.

manjaro linux / gnome

pppest avatar Jun 21 '22 20:06 pppest