From d85e59fe92be758bd79dcf32e6b5d9f5ceadb38d Mon Sep 17 00:00:00 2001 From: Felix Rohrbach Date: Mon, 4 Apr 2011 23:40:14 +0200 Subject: 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 --- src/application.cpp | 30 ++++++++++++++++++++++++++++++ src/application.h | 4 ++++ 2 files changed, 34 insertions(+) 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 #include #include +#include #include #include @@ -293,6 +294,11 @@ MainWindow *Application::mainWindow() if(m_mainWindows.isEmpty()) return 0; + Q_FOREACH (const QWeakPointer &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(watched); + if (window) + { + if (m_mainWindows.at(0).data() != window) + { + int index = m_mainWindows.indexOf(QWeakPointer(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 -- cgit v1.2.1