fix screen count alignment
REVIEW: 110119
This commit is contained in:
parent
4ec1a9bb3a
commit
c380acca3f
2 changed files with 50 additions and 7 deletions
25
screens.cpp
25
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
|
||||
|
|
32
screens.h
32
screens.h
|
@ -27,14 +27,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// Qt includes
|
||||
#include <QObject>
|
||||
#include <QRect>
|
||||
#include <QTimer>
|
||||
|
||||
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<ScreenCountTimer*>(m_changedTimer)->finish();
|
||||
}
|
||||
|
||||
inline
|
||||
bool Screens::isCurrentFollowsMouse() const
|
||||
{
|
||||
return m_currentFollowsMouse;
|
||||
}
|
||||
|
||||
inline
|
||||
void Screens::startChangedTimer()
|
||||
{
|
||||
m_changedTimer->start();
|
||||
}
|
||||
|
||||
inline
|
||||
Screens *screens()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue