+#ifdef Q_WS_WIN
+ // the problem is that we lose focus when the systray icon is activated
+ // and we don't know the former active window
+ // therefore we watch for activation event and use our stopwatch :)
+ // courtesy: KSystemTrayIcon
+ if(GetTickCount() - dwTickCount >= 300)
+ // we weren't active in the last 300ms -> activate
+ forceActivated();
+ else
+ hideToTray();
+
+#else
+
+ if(!isVisible() || isMinimized())
+ // restore
+ forceActivated();
+ else
+ hideToTray();
+
+#endif
+}
+
+void MainWin::forceActivated() {
+#ifdef Q_WS_X11
+ // Bypass focus stealing prevention
+ QX11Info::setAppUserTime(QX11Info::appTime());
+#endif
+