diff options
author | Felix Rohrbach <fxrh@gmx.de> | 2011-04-04 23:40:14 +0200 |
---|---|---|
committer | Felix Rohrbach <fxrh@gmx.de> | 2011-04-10 14:06:55 +0200 |
commit | d85e59fe92be758bd79dcf32e6b5d9f5ceadb38d (patch) | |
tree | eeab0f737d7077b58aec2964cf40f4cf1a7d8212 /src | |
parent | AdBlock Improvements: (diff) | |
download | rekonq-d85e59fe92be758bd79dcf32e6b5d9f5ceadb38d.tar.xz |
Make rekonq desktop aware
If there is a rekonq window on the current virtual desktop and
another application opens a link, rekonq will prefer this window.
rekonq also prefers windows that were activated most recently.
CCBUG: 237732
REVIEW: 101033
Diffstat (limited to 'src')
-rw-r--r-- | src/application.cpp | 30 | ||||
-rw-r--r-- | src/application.h | 4 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/application.cpp b/src/application.cpp index eda588a0..830442f0 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -58,6 +58,7 @@ #include <ThreadWeaver/Weaver> #include <KAction> #include <KWindowSystem> +#include <KWindowInfo> #include <KGlobal> #include <KCharsets> @@ -293,6 +294,11 @@ MainWindow *Application::mainWindow() if(m_mainWindows.isEmpty()) return 0; + Q_FOREACH (const QWeakPointer<MainWindow> &pointer, m_mainWindows) + { + if (KWindowInfo(pointer.data()->effectiveWinId(),NET::WMDesktop,0).isOnCurrentDesktop()) + return pointer.data(); + } return m_mainWindows.at(0).data(); } return active; @@ -411,6 +417,8 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) MainWindow *Application::newMainWindow(bool withTab) { MainWindow *w = new MainWindow(); + // This is used to track which window was activated most recently + w->installEventFilter(this); if (withTab) w->mainView()->newWebTab(); // remember using newWebTab and NOT newTab here!! @@ -467,6 +475,28 @@ void Application::newWindow() } +bool Application::eventFilter( QObject* watched, QEvent* event ) +{ + // Track which window was activated most recently to prefer it on window choosing + // (e.g. when another application opens a link) + if (event->type() == QEvent::WindowActivate) + { + MainWindow *window = qobject_cast<MainWindow*>(watched); + if (window) + { + if (m_mainWindows.at(0).data() != window) + { + int index = m_mainWindows.indexOf(QWeakPointer<MainWindow>(window)); + Q_ASSERT(index != -1); + m_mainWindows.prepend(m_mainWindows.takeAt(index)); + } + } + } + + return QObject::eventFilter( watched, event ); +} + + void Application::updateConfiguration() { // ============== Tabs ================== diff --git a/src/application.h b/src/application.h index 3cd3c96b..d3757645 100644 --- a/src/application.h +++ b/src/application.h @@ -134,6 +134,10 @@ public slots: void newWindow(); void removeMainWindow(MainWindow *window); +protected: + // This is used to track which window was activated most recently + bool eventFilter(QObject *watched, QEvent *event); + private slots: /** * Any actions that can be delayed until the window is visible |