diff --git a/screens.cpp b/screens.cpp
index 9cff4e7cc7..cf819839b1 100644
--- a/screens.cpp
+++ b/screens.cpp
@@ -36,10 +36,11 @@ Screens::Screens(QObject *parent)
, m_count(0)
, m_current(0)
, m_currentFollowsMouse(false)
- , m_changedTimer(new QTimer(this))
+ , m_changedTimer(new ScreenCountTimer(this))
{
m_changedTimer->setSingleShot(true);
m_changedTimer->setInterval(100);
+ connect(m_changedTimer, SIGNAL(timeout()), SLOT(updateCount()));
connect(m_changedTimer, SIGNAL(timeout()), SIGNAL(changed()));
Settings settings;
@@ -115,19 +116,26 @@ int Screens::current() const
return m_current;
}
-void Screens::startChangedTimer()
+ScreenCountTimer::ScreenCountTimer(QObject * parent) : QTimer(parent)
{
- m_changedTimer->start();
+}
+
+void ScreenCountTimer::finish()
+{
+ if (isActive()) {
+ stop();
+ Screens::self()->updateCount();
+ QMetaObject::invokeMethod(Screens::self(), "changed", Qt::QueuedConnection);
+ }
}
DesktopWidgetScreens::DesktopWidgetScreens(QObject *parent)
: Screens(parent)
, m_desktop(QApplication::desktop())
{
- connect(m_desktop, SIGNAL(screenCountChanged(int)), SLOT(setCount(int)));
connect(m_desktop, SIGNAL(screenCountChanged(int)), SLOT(startChangedTimer()));
connect(m_desktop, SIGNAL(resized(int)), SLOT(startChangedTimer()));
- setCount(m_desktop->screenCount());
+ updateCount();
}
DesktopWidgetScreens::~DesktopWidgetScreens()
@@ -136,12 +144,19 @@ DesktopWidgetScreens::~DesktopWidgetScreens()
QRect DesktopWidgetScreens::geometry(int screen) const
{
+ finishChangedTimer();
return m_desktop->screenGeometry(screen);
}
int DesktopWidgetScreens::number(const QPoint &pos) const
{
+ finishChangedTimer();
return m_desktop->screenNumber(pos);
}
+void DesktopWidgetScreens::updateCount()
+{
+ setCount(m_desktop->screenCount());
+}
+
} // namespace
diff --git a/screens.h b/screens.h
index 66770cafd2..6bdc9689b3 100644
--- a/screens.h
+++ b/screens.h
@@ -27,14 +27,23 @@ along with this program. If not, see .
// Qt includes
#include
#include
+#include
class QDesktopWidget;
-class QTimer;
namespace KWin
{
class Client;
+class ScreenCountTimer : public QTimer {
+ public:
+ ScreenCountTimer(QObject * parent = 0);
+ /**
+ * if isActive, stop AND emit timeout()
+ */
+ void finish();
+};
+
class Screens : public QObject
{
Q_OBJECT
@@ -76,15 +85,20 @@ Q_SIGNALS:
**/
void changed();
+protected:
+ void finishChangedTimer() const;
+
protected Q_SLOTS:
+ friend class ScreenCountTimer;
void setCount(int count);
void startChangedTimer();
+ virtual void updateCount() = 0;
private:
int m_count;
int m_current;
bool m_currentFollowsMouse;
- QTimer *m_changedTimer;
+ ScreenCountTimer *m_changedTimer;
KSharedConfig::Ptr m_config;
KWIN_SINGLETON(Screens)
@@ -98,6 +112,8 @@ public:
virtual ~DesktopWidgetScreens();
virtual QRect geometry(int screen) const;
virtual int number(const QPoint &pos) const;
+protected Q_SLOTS:
+ void updateCount();
private:
QDesktopWidget *m_desktop;
@@ -115,12 +131,24 @@ int Screens::count() const
return m_count;
}
+inline
+void Screens::finishChangedTimer() const
+{
+ const_cast(m_changedTimer)->finish();
+}
+
inline
bool Screens::isCurrentFollowsMouse() const
{
return m_currentFollowsMouse;
}
+inline
+void Screens::startChangedTimer()
+{
+ m_changedTimer->start();
+}
+
inline
Screens *screens()
{