X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=6867d060d879fd670f153118616202d351dcdc28;hp=2b758d50e6feeba65fcfa9b098b59208473de140;hb=6f442c275cc5a2d5f1084ac2ceca5f1ffce1d024;hpb=308e090392713b0fa2e402156fbae2fa74cab96a diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 2b758d50..6867d060 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -28,6 +28,10 @@ # include #endif +#ifdef Q_WS_X11 +# include +#endif + #include "aboutdlg.h" #include "awaylogfilter.h" #include "awaylogview.h" @@ -108,6 +112,10 @@ MainWin::MainWin(QWidget *parent) _titleSetter(this), _awayLog(0) { +#ifdef Q_WS_WIN + dwTickCount = 0; +#endif + QtUiSettings uiSettings; QString style = uiSettings.value("Style", QString()).toString(); if(!style.isEmpty()) { @@ -516,11 +524,6 @@ void MainWin::saveStatusBarStatus(bool enabled) { void MainWin::setupSystray() { _systemTray = new SystemTray(this); - -#ifndef Q_WS_MAC - connect(systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason))); -#endif - } void MainWin::setupToolBars() { @@ -548,18 +551,6 @@ void MainWin::setupToolBars() { #endif } -void MainWin::changeEvent(QEvent *event) { - if(event->type() == QEvent::WindowStateChange) { - if(windowState() & Qt::WindowMinimized) { - QtUiSettings s; - if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) { - hideToTray(); - event->accept(); - } - } - } -} - void MainWin::connectedToCore() { Q_CHECK_PTR(Client::bufferViewManager()); connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int))); @@ -761,10 +752,30 @@ void MainWin::closeEvent(QCloseEvent *event) { } } -void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) { - if(activationReason == QSystemTrayIcon::Trigger) { - toggleMinimizedToTray(); +bool MainWin::event(QEvent *event) { + if(event->type() == QEvent::WindowActivate) + QtUi::closeNotifications(); + return QMainWindow::event(event); +} + +void MainWin::changeEvent(QEvent *event) { + if(event->type() == QEvent::WindowStateChange) { + if(windowState() & Qt::WindowMinimized) { + QtUiSettings s; + if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) { + hideToTray(); + event->accept(); + return; + } + } } + +#ifdef Q_WS_WIN + else if(event->type() == QEvent::ActivationChange) + dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray() +#endif + + event->ignore(); } void MainWin::hideToTray() { @@ -772,22 +783,48 @@ void MainWin::hideToTray() { qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!"; return; } - clearFocus(); hide(); systemTray()->setIconVisible(); } void MainWin::toggleMinimizedToTray() { +#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 + if(windowState() & Qt::WindowMinimized) { // restore setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); - show(); - activateWindow(); - raise(); - } else { - setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); - hideToTray(); } + + move(frameGeometry().topLeft()); // avoid placement policies + show(); + raise(); + activateWindow(); } void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { @@ -819,12 +856,6 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { } } -bool MainWin::event(QEvent *event) { - if(event->type() == QEvent::WindowActivate) - QtUi::closeNotifications(); - return QMainWindow::event(event); -} - void MainWin::clientNetworkCreated(NetworkId id) { const Network *net = Client::network(id); QAction *act = new QAction(net->networkName(), this);