1/********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*********************************************************************/
20#ifndef KWIN_SCREENS_H
21#define KWIN_SCREENS_H
22
23// KWin includes
24#include <kwinglobals.h>
25// KDE includes
26#include <KDE/KConfig>
27// Qt includes
28#include <QObject>
29#include <QRect>
30#include <QTimer>
31
32class QDesktopWidget;
33
34namespace KWin
35{
36class Client;
37
38class Screens : public QObject
39{
40 Q_OBJECT
41 Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
42 Q_PROPERTY(int current READ current WRITE setCurrent)
43 Q_PROPERTY(bool currentFollowsMouse READ isCurrentFollowsMouse WRITE setCurrentFollowsMouse)
44
45public:
46 virtual ~Screens();
47 /**
48 * @internal
49 **/
50 void setConfig(KSharedConfig::Ptr config);
51 int count() const;
52 int current() const;
53 void setCurrent(int current);
54 /**
55 * Called e.g. when a user clicks on a window, set current screen to be the screen
56 * where the click occurred
57 */
58 void setCurrent(const QPoint &pos);
59 /**
60 * Check whether a client moved completely out of what's considered the current screen,
61 * if yes, set a new active screen.
62 */
63 void setCurrent(const Client *c);
64 bool isCurrentFollowsMouse() const;
65 void setCurrentFollowsMouse(bool follows);
66 virtual QRect geometry(int screen) const = 0;
67 virtual int number(const QPoint &pos) const = 0;
68
69 inline bool isChanging() { return m_changedTimer->isActive(); }
70
71 int intersecting(const QRect &r) const;
72
73public Q_SLOTS:
74 void reconfigure();
75
76Q_SIGNALS:
77 void countChanged(int previousCount, int newCount);
78 /**
79 * Emitted whenever the screens are changed either count or geometry.
80 **/
81 void changed();
82
83protected Q_SLOTS:
84 void setCount(int count);
85 void startChangedTimer();
86 virtual void updateCount() = 0;
87
88private:
89 int m_count;
90 int m_current;
91 bool m_currentFollowsMouse;
92 QTimer *m_changedTimer;
93 KSharedConfig::Ptr m_config;
94
95 KWIN_SINGLETON(Screens)
96};
97
98class DesktopWidgetScreens : public Screens
99{
100 Q_OBJECT
101public:
102 DesktopWidgetScreens(QObject *parent);
103 virtual ~DesktopWidgetScreens();
104 virtual QRect geometry(int screen) const;
105 virtual int number(const QPoint &pos) const;
106protected Q_SLOTS:
107 void updateCount();
108
109private:
110 QDesktopWidget *m_desktop;
111};
112
113inline
114void Screens::setConfig(KSharedConfig::Ptr config)
115{
116 m_config = config;
117}
118
119inline
120int Screens::count() const
121{
122 return m_count;
123}
124
125inline
126bool Screens::isCurrentFollowsMouse() const
127{
128 return m_currentFollowsMouse;
129}
130
131inline
132void Screens::startChangedTimer()
133{
134 m_changedTimer->start();
135}
136
137inline
138Screens *screens()
139{
140 return Screens::self();
141}
142
143}
144
145#endif // KWIN_SCREENS_H
146