1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along 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 | |
32 | class QDesktopWidget; |
33 | |
34 | namespace KWin |
35 | { |
36 | class Client; |
37 | |
38 | class 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 | |
45 | public: |
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 | |
73 | public Q_SLOTS: |
74 | void reconfigure(); |
75 | |
76 | Q_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 | |
83 | protected Q_SLOTS: |
84 | void setCount(int count); |
85 | void startChangedTimer(); |
86 | virtual void updateCount() = 0; |
87 | |
88 | private: |
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 | |
98 | class DesktopWidgetScreens : public Screens |
99 | { |
100 | Q_OBJECT |
101 | public: |
102 | DesktopWidgetScreens(QObject *parent); |
103 | virtual ~DesktopWidgetScreens(); |
104 | virtual QRect geometry(int screen) const; |
105 | virtual int number(const QPoint &pos) const; |
106 | protected Q_SLOTS: |
107 | void updateCount(); |
108 | |
109 | private: |
110 | QDesktopWidget *m_desktop; |
111 | }; |
112 | |
113 | inline |
114 | void Screens::setConfig(KSharedConfig::Ptr config) |
115 | { |
116 | m_config = config; |
117 | } |
118 | |
119 | inline |
120 | int Screens::count() const |
121 | { |
122 | return m_count; |
123 | } |
124 | |
125 | inline |
126 | bool Screens::isCurrentFollowsMouse() const |
127 | { |
128 | return m_currentFollowsMouse; |
129 | } |
130 | |
131 | inline |
132 | void Screens::startChangedTimer() |
133 | { |
134 | m_changedTimer->start(); |
135 | } |
136 | |
137 | inline |
138 | Screens *screens() |
139 | { |
140 | return Screens::self(); |
141 | } |
142 | |
143 | } |
144 | |
145 | #endif // KWIN_SCREENS_H |
146 | |