extend bring to front

This commit is contained in:
Patrick von Reth 2015-04-13 20:14:34 +02:00
parent 5e4838467a
commit a36bfead69
3 changed files with 10 additions and 11 deletions

View File

@ -27,20 +27,19 @@
using namespace Snore; using namespace Snore;
void Utils::bringWindowToFront(qlonglong _wid) void Utils::bringWindowToFront(qlonglong _wid, bool focus)
{ {
snoreDebug(SNORE_DEBUG) << _wid; snoreDebug(SNORE_DEBUG) << _wid;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
HWND wid = (HWND)_wid; HWND wid = (HWND)_wid;
HWND hwndActiveWin = GetForegroundWindow(); int idActive = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL); bool attetched = AttachThreadInput(GetCurrentThreadId(), idActive, TRUE);
if (AttachThreadInput(GetCurrentThreadId(), idActive, TRUE)) {
SetForegroundWindow(wid); SetForegroundWindow(wid);
if (focus) {
SetFocus(wid);
}
if (attetched) {
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE); AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
} else {
// try it anyhow
SetForegroundWindow(wid);
} }
#endif #endif
} }

View File

@ -30,7 +30,7 @@ public:
~Utils(); ~Utils();
//TODO: make Wid usable with the meta system and change signature. //TODO: make Wid usable with the meta system and change signature.
Q_INVOKABLE void bringWindowToFront(qlonglong wid); Q_INVOKABLE void bringWindowToFront(qlonglong wid, bool focus);
}; };

View File

@ -45,7 +45,7 @@ Rectangle {
animation.start() animation.start()
window.visible = true window.visible = true
utils.bringWindowToFront(window.wid) utils.bringWindowToFront(window.wid, false)
} }
} }