~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/presentwindows/presentwindows.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
 
6
Copyright (C) 2008 Lucas Murray <lmurray@undefinedfire.com>
 
7
 
 
8
This program is free software; you can redistribute it and/or modify
 
9
it under the terms of the GNU General Public License as published by
 
10
the Free Software Foundation; either version 2 of the License, or
 
11
(at your option) any later version.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*********************************************************************/
 
21
 
 
22
#ifndef KWIN_PRESENTWINDOWS_H
 
23
#define KWIN_PRESENTWINDOWS_H
 
24
 
 
25
#include "presentwindows_proxy.h"
 
26
 
 
27
#include <kwineffects.h>
 
28
#include <kshortcut.h>
 
29
#include <QtGui/QGraphicsView>
 
30
 
 
31
class QTimer;
 
32
namespace Plasma
 
33
{
 
34
class PushButton;
 
35
class FrameSvg;
 
36
}
 
37
 
 
38
namespace KWin
 
39
{
 
40
 
 
41
class CloseWindowView : public QGraphicsView
 
42
{
 
43
    Q_OBJECT
 
44
public:
 
45
    CloseWindowView(QWidget* parent = 0);
 
46
    void windowInputMouseEvent(QMouseEvent* e);
 
47
    virtual void drawBackground(QPainter* painter, const QRectF& rect);
 
48
 
 
49
    void delayedShow();
 
50
    void hide();
 
51
 
 
52
Q_SIGNALS:
 
53
    void close();
 
54
 
 
55
private:
 
56
    Plasma::PushButton* m_closeButton;
 
57
    Plasma::FrameSvg* m_frame;
 
58
    QTimer* m_delayedShowTimer;
 
59
};
 
60
 
 
61
/**
 
62
 * Expose-like effect which shows all windows on current desktop side-by-side,
 
63
 *  letting the user select active window.
 
64
 **/
 
65
class PresentWindowsEffect
 
66
    : public Effect
 
67
{
 
68
    Q_OBJECT
 
69
private:
 
70
    // Structures
 
71
    struct WindowData {
 
72
        bool visible;
 
73
        bool deleted;
 
74
        bool referenced;
 
75
        double opacity;
 
76
        double highlight;
 
77
        EffectFrame* textFrame;
 
78
        EffectFrame* iconFrame;
 
79
    };
 
80
    typedef QHash<EffectWindow*, WindowData> DataHash;
 
81
    struct GridSize {
 
82
        int columns;
 
83
        int rows;
 
84
    };
 
85
 
 
86
public:
 
87
    PresentWindowsEffect();
 
88
    virtual ~PresentWindowsEffect();
 
89
 
 
90
    virtual void reconfigure(ReconfigureFlags);
 
91
    virtual void* proxy();
 
92
 
 
93
    // Screen painting
 
94
    virtual void prePaintScreen(ScreenPrePaintData &data, int time);
 
95
    virtual void paintScreen(int mask, QRegion region, ScreenPaintData &data);
 
96
    virtual void postPaintScreen();
 
97
 
 
98
    // Window painting
 
99
    virtual void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time);
 
100
    virtual void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data);
 
101
 
 
102
    // User interaction
 
103
    virtual bool borderActivated(ElectricBorder border);
 
104
    virtual void windowInputMouseEvent(Window w, QEvent *e);
 
105
    virtual void grabbedKeyboardEvent(QKeyEvent *e);
 
106
 
 
107
    enum { LayoutNatural, LayoutRegularGrid, LayoutFlexibleGrid }; // Layout modes
 
108
    enum PresentWindowsMode {
 
109
        ModeAllDesktops, // Shows windows of all desktops
 
110
        ModeCurrentDesktop, // Shows windows on current desktop
 
111
        ModeSelectedDesktop, // Shows windows of selected desktop via property (m_desktop)
 
112
        ModeWindowGroup, // Shows windows selected via property
 
113
        ModeWindowClass // Shows all windows of same class as selected class
 
114
    };
 
115
    enum WindowMouseAction {
 
116
        WindowNoAction = 0, // Nothing
 
117
        WindowActivateAction = 1, // Activates the window and deactivates the effect
 
118
        WindowExitAction = 2, // Deactivates the effect without activating new window
 
119
        WindowToCurrentDesktopAction = 3, // Brings window to current desktop
 
120
        WindowToAllDesktopsAction = 4, // Brings window to all desktops
 
121
        WindowMinimizeAction = 5, // Minimize the window
 
122
        WindowCloseAction = 6 // Closes the window
 
123
    };
 
124
    enum DesktopMouseAction {
 
125
        DesktopNoAction = 0, // nothing
 
126
        DesktopActivateAction = 1, // Activates the window and deactivates the effect
 
127
        DesktopExitAction = 2, // Deactivates the effect without activating new window
 
128
        DesktopShowDesktopAction = 3 // Minimizes all windows
 
129
    };
 
130
 
 
131
public slots:
 
132
    void setActive(bool active, bool closingTab = false);   // HACK: closingTab shouldn't be needed
 
133
    void toggleActive()  {
 
134
        m_mode = ModeCurrentDesktop;
 
135
        setActive(!m_activated);
 
136
    }
 
137
    void toggleActiveAllDesktops()  {
 
138
        m_mode = ModeAllDesktops;
 
139
        setActive(!m_activated);
 
140
    }
 
141
    void toggleActiveClass();
 
142
 
 
143
    // slots for global shortcut changed
 
144
    // needed to toggle the effect
 
145
    void globalShortcutChanged(const QKeySequence& seq);
 
146
    void globalShortcutChangedAll(const QKeySequence& seq);
 
147
    void globalShortcutChangedClass(const QKeySequence& seq);
 
148
    // EffectsHandler
 
149
    void slotWindowAdded(EffectWindow *w);
 
150
    void slotWindowClosed(EffectWindow *w);
 
151
    void slotWindowDeleted(EffectWindow *w);
 
152
    void slotWindowGeometryShapeChanged(EffectWindow *w, const QRect &old);
 
153
    // Tab box
 
154
    void slotTabBoxAdded(int mode);
 
155
    void slotTabBoxClosed();
 
156
    void slotTabBoxUpdated();
 
157
    void slotTabBoxKeyEvent(QKeyEvent* event);
 
158
    // atoms
 
159
    void slotPropertyNotify(EffectWindow* w, long atom);
 
160
 
 
161
private slots:
 
162
    void closeWindow();
 
163
 
 
164
protected:
 
165
    // Window rearranging
 
166
    void rearrangeWindows();
 
167
    void calculateWindowTransformations(EffectWindowList windowlist, int screen,
 
168
                                        WindowMotionManager& motionManager, bool external = false);
 
169
    void calculateWindowTransformationsClosest(EffectWindowList windowlist, int screen,
 
170
            WindowMotionManager& motionManager);
 
171
    void calculateWindowTransformationsKompose(EffectWindowList windowlist, int screen,
 
172
            WindowMotionManager& motionManager);
 
173
    void calculateWindowTransformationsNatural(EffectWindowList windowlist, int screen,
 
174
            WindowMotionManager& motionManager);
 
175
 
 
176
    // Helper functions for window rearranging
 
177
    inline double aspectRatio(EffectWindow *w) {
 
178
        return w->width() / double(w->height());
 
179
    }
 
180
    inline int widthForHeight(EffectWindow *w, int height) {
 
181
        return int((height / double(w->height())) * w->width());
 
182
    }
 
183
    inline int heightForWidth(EffectWindow *w, int width) {
 
184
        return int((width / double(w->width())) * w->height());
 
185
    }
 
186
    bool isOverlappingAny(EffectWindow *w, const QHash<EffectWindow*, QRect> &targets, const QRegion &border);
 
187
 
 
188
    // Filter box
 
189
    void updateFilterFrame();
 
190
 
 
191
    // Helper functions
 
192
    bool isSelectableWindow(EffectWindow *w);
 
193
    bool isVisibleWindow(EffectWindow *w);
 
194
    void setHighlightedWindow(EffectWindow *w);
 
195
    EffectWindow* relativeWindow(EffectWindow *w, int xdiff, int ydiff, bool wrap) const;
 
196
    EffectWindow* findFirstWindow() const;
 
197
    void updateCloseWindow();
 
198
 
 
199
    // Helper functions for mouse actions
 
200
    void mouseActionWindow(WindowMouseAction& action);
 
201
    void mouseActionDesktop(DesktopMouseAction& action);
 
202
 
 
203
private:
 
204
    PresentWindowsEffectProxy m_proxy;
 
205
    friend class PresentWindowsEffectProxy;
 
206
 
 
207
    // User configuration settings
 
208
    QList<ElectricBorder> m_borderActivate;
 
209
    QList<ElectricBorder> m_borderActivateAll;
 
210
    int m_layoutMode;
 
211
    bool m_showCaptions;
 
212
    bool m_showIcons;
 
213
    bool m_doNotCloseWindows;
 
214
    bool m_tabBoxAllowed;
 
215
    bool m_tabBoxAlternativeAllowed;
 
216
    int m_accuracy;
 
217
    bool m_fillGaps;
 
218
    double m_fadeDuration;
 
219
    bool m_showPanel;
 
220
 
 
221
    // Activation
 
222
    bool m_activated;
 
223
    bool m_ignoreMinimized;
 
224
    double m_decalOpacity;
 
225
    Window m_input;
 
226
    bool m_hasKeyboardGrab;
 
227
    bool m_tabBoxEnabled;
 
228
    PresentWindowsMode m_mode;
 
229
    int m_desktop;
 
230
    EffectWindowList m_selectedWindows;
 
231
    EffectWindow *m_managerWindow;
 
232
    QString m_class;
 
233
 
 
234
    // Window data
 
235
    WindowMotionManager m_motionManager;
 
236
    DataHash m_windowData;
 
237
    EffectWindow *m_highlightedWindow;
 
238
 
 
239
    // Grid layout info
 
240
    QList<GridSize> m_gridSizes;
 
241
 
 
242
    // Filter box
 
243
    EffectFrame* m_filterFrame;
 
244
    QString m_windowFilter;
 
245
 
 
246
    // Shortcut - needed to toggle the effect
 
247
    KShortcut shortcut;
 
248
    KShortcut shortcutAll;
 
249
    KShortcut shortcutClass;
 
250
 
 
251
    // Atoms
 
252
    // Present windows for all windows of given desktop
 
253
    // -1 for all desktops
 
254
    long m_atomDesktop;
 
255
    // Present windows for group of window ids
 
256
    long m_atomWindows;
 
257
 
 
258
    // Mouse Actions
 
259
    WindowMouseAction m_leftButtonWindow;
 
260
    WindowMouseAction m_middleButtonWindow;
 
261
    WindowMouseAction m_rightButtonWindow;
 
262
    DesktopMouseAction m_leftButtonDesktop;
 
263
    DesktopMouseAction m_middleButtonDesktop;
 
264
    DesktopMouseAction m_rightButtonDesktop;
 
265
 
 
266
    CloseWindowView* m_closeView;
 
267
    EffectWindow* m_closeWindow;
 
268
 
 
269
    // drag to close
 
270
    QPoint m_dragStart;
 
271
    bool m_dragInProgress;
 
272
    EffectWindow *m_dragWindow;
 
273
    QList<EffectFrame*> m_dropTargets;
 
274
    EffectFrame *m_highlightedDropTarget;
 
275
    bool m_dragToClose;
 
276
};
 
277
 
 
278
} // namespace
 
279
 
 
280
#endif