summaryrefslogtreecommitdiff
path: root/src/mcompositemanager.h
blob: 765bce73094f7ba54ed46f9f5b919f6f7e4073aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of mcompositor.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef DUICOMPOSITEMANAGER_H
#define DUICOMPOSITEMANAGER_H

#include <QApplication>
#include <QGLWidget>
#include "mwindowpropertycache.h"

class QGraphicsScene;
class MCompositeManagerPrivate;
class MCompAtoms;

/*!
 * MCompositeManager is responsible for managing window events.
 *
 * It catches and redirects appropriate windows to offscreen pixmaps and
 * creates a MTexturePixmapItem object from these windows and adds them
 * to a QGraphicsScene. The manager also ensures the items are updated
 * when their contents change and removes them from its control when they are
 * destroyed.
 *
 */
class MCompositeManager: public QApplication
{
    Q_OBJECT
public:

    /*!
     * Initializes the compositing manager
     *
     * \param argc number of arguments passed from the command line
     * \param argv argument of strings passed from the command line
     */
    MCompositeManager(int &argc, char **argv);

    /*!
     * Cleans up resources
     */
    ~MCompositeManager();

    /*! Prepare and start composite management. This function should get called
     * after the window of this compositor is created and mapped to the screen
     */
    void prepareEvents();

    /*! Specify the QGLWidget used by the QGraphicsView to draw the items on
     * the screen.
     *
     * \param glw The QGLWidget widget used in used by the scene's
     * QGraphicsView viewport
     */
    void setGLWidget(QGLWidget *glw);

    /*! QGLWidget accessor for static initialisations. */
    QGLWidget *glWidget() const;

    /*!
     * Reimplemented from QApplication::x11EventFilter() to catch X11 events
     */
    virtual bool x11EventFilter(XEvent *event);

    /*!
     * Returns the scene where the items are rendered
     */
    QGraphicsScene *scene();

    /*!
     * Specifies the toplevel window where the items are rendered. This window
     * will reparented to the composite overlay window to ensure the compositor
     * stays on top of all windows.
     *
     * \param window Window id of the toplevel window where the items are
     * rendered. Typically, this will be the window id of a toplevel
     * QGraphicsView widget where the items are drawn
     */
    void setSurfaceWindow(Qt::HANDLE window);

    /*!
     * Redirects and manages existing windows as composited items
     */
    void redirectWindows();

    void loadPlugins();

    /*!
     * Returns whether a Window is redirected or not
     *
     * \param w Window id of a window
     */
    bool isRedirected(Qt::HANDLE window);
    
    /*
     * Returns the current state of windows whether it is being composited
     * or not
     */
    bool isCompositing();

    /*!
     * Try to direct-render the topmost window
     */
    bool possiblyUnredirectTopmostWindow();
    
    /*!
     * Returns if the display is off
     */
    bool displayOff();

    void debug(const QString& d);
    const QHash<Window, MWindowPropertyCache*>& propCaches() const;

    enum StackPosition {
        STACK_BOTTOM = 0,
        STACK_TOP
    };
    void positionWindow(Window w, StackPosition pos);
    void setWindowState(Window, int);
    const QList<Window> &stackingList() const;

#ifdef WINDOW_DEBUG
    // Dump the current state of MCompositeManager and MCompositeWindow:s
    // to qDebug().  Only available if compiled with TESTABILITY=on
    // (-DWINDOW_DEBUG).
    void dumpState(const char *heading = 0);

    // "Print" @msg in xtrace, to show you where your program's control was
    // between the various X requests, responses and events.
    // Synopsis:
    // [1] MCompositeManager::xtrace();
    // [2] MCompositeManager::xtrace("HEI");
    // [3] MCompositeManager::xtrace(__PRETTY_FUNCTION__, "HEI");
    //
    // xtracef() is the same, except that it sends a formatted message.
    // You can leave @fun NULL if you want.
    static void xtrace (const char *fun = NULL, const char *msg = NULL,
                        int lmsg = -1);
    static void xtracef(const char *fun, const char *fmt, ...)
        __attribute__((format(printf, 2, 3)));
#endif

public slots:
    void enableCompositing(bool forced = false);
    void disableCompositing();
    // called with the answer to mdecorator's dialog
    void queryDialogAnswer(unsigned int window, bool yes_answer);

    /*! Invoked remotely by MRmiClient to show a launch indicator
     *
     * \param timeout seconds elapsed to hide the launch indicator in case
     * window does not yet appear.
     */
    void showLaunchIndicator(int timeout);
    void hideLaunchIndicator();

    /*!
     * Invoke to show the desktop window, possibly with switcher contents
     */
    void exposeSwitcher();

    /*!
     * Area that is free after the area that decorator occupies.
     */
    const QRect &availableRect() const;

#ifdef WINDOW_DEBUG
    void remoteControl(int fd);
#endif
     
signals:
    void decoratorRectChanged(const QRect& rect);

private:
    MCompositeManagerPrivate *d;

    friend class MCompositeWindow;
    friend class MCompWindowAnimator;
    friend class MCompositeManagerExtension;
    friend class MTexturePixmapPrivate;
    friend class MWindowPropertyCache;
    friend class MCompositeWindowGroup;
};

#endif