Fix broken handling of inactive transient surfaces
[profile/ivi/qtwayland.git] / src / compositor / wayland_wrapper / wlsurface.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the Qt Compositor.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
10 **
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
13 ** met:
14 **   * Redistributions of source code must retain the above copyright
15 **     notice, this list of conditions and the following disclaimer.
16 **   * Redistributions in binary form must reproduce the above copyright
17 **     notice, this list of conditions and the following disclaimer in
18 **     the documentation and/or other materials provided with the
19 **     distribution.
20 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 **     the names of its contributors may be used to endorse or promote
22 **     products derived from this software without specific prior written
23 **     permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #ifndef WL_SURFACE_H
42 #define WL_SURFACE_H
43
44 #include "waylandexport.h"
45
46 #include "wlsurfacebuffer.h"
47 #include "waylandsurface.h"
48
49 #include "waylandobject.h"
50
51 #include <QtCore/QRect>
52 #include <QtGui/QImage>
53
54 #include <QtCore/QTextStream>
55 #include <QtCore/QMetaType>
56
57 #ifdef QT_COMPOSITOR_WAYLAND_GL
58 #include <QtGui/QOpenGLContext>
59 #include <QtGui/qopengl.h>
60 #endif
61
62 #include <wayland-util.h>
63
64 class QTouchEvent;
65
66 namespace Wayland {
67
68 class Compositor;
69 class Buffer;
70 class ExtendedSurface;
71 class SubSurface;
72 class ShellSurface;
73
74 class Q_COMPOSITOR_EXPORT Surface : public Object<struct wl_surface>
75 {
76 public:
77     Surface(struct wl_client *client, uint32_t id, Compositor *compositor);
78     ~Surface();
79
80     WaylandSurface::Type type() const;
81     bool isYInverted() const;
82
83     bool visible() const;
84
85     uint id() const { return base()->resource.object.id; }
86
87     QPointF pos() const;
88     QPointF nonAdjustedPos() const;
89     void setPos(const QPointF  &pos);
90
91     QSize size() const;
92     void setSize(const QSize &size);
93
94     QRegion inputRegion() const;
95     QRegion opaqueRegion() const;
96
97     QImage image() const;
98
99 #ifdef QT_COMPOSITOR_WAYLAND_GL
100     GLuint textureId(QOpenGLContext *context) const;
101 #endif
102
103     void sendFrameCallback();
104
105     void frameFinished();
106
107     WaylandSurface *waylandSurface() const;
108
109     QPoint lastMousePos() const;
110
111     void setExtendedSurface(ExtendedSurface *extendedSurface);
112     ExtendedSurface *extendedSurface() const;
113
114     void setSubSurface(SubSurface *subSurface);
115     SubSurface *subSurface() const;
116
117     void setShellSurface(ShellSurface *shellSurface);
118     ShellSurface *shellSurface() const;
119
120     Compositor *compositor() const;
121
122     void damage(const QRect &rect);
123
124     static const struct wl_surface_interface surface_interface;
125
126     QString title() const { return m_title; }
127     void setTitle(const QString &title);
128
129     bool transientInactive() const { return m_transientInactive; }
130     void setTransientInactive(bool v) { m_transientInactive = v; }
131
132 private:
133     Q_DISABLE_COPY(Surface)
134
135     Compositor *m_compositor;
136     WaylandSurface *m_waylandSurface;
137
138     SurfaceBuffer *m_backBuffer;
139     SurfaceBuffer *m_frontBuffer;
140     QList<SurfaceBuffer *> m_bufferQueue;
141     bool m_surfaceMapped;
142
143     QPoint m_lastLocalMousePos;
144     QPoint m_lastGlobalMousePos;
145
146     struct wl_list m_frame_callback_list;
147
148     ExtendedSurface *m_extendedSurface;
149     SubSurface *m_subSurface;
150     ShellSurface *m_shellSurface;
151
152     QRegion m_inputRegion;
153     QRegion m_opaqueRegion;
154
155     static const int buffer_pool_size = 3;
156     SurfaceBuffer *m_bufferPool[buffer_pool_size];
157
158     QPointF m_position;
159     QSize m_size;
160     QString m_title;
161     bool m_transientInactive;
162
163     inline SurfaceBuffer *currentSurfaceBuffer() const;
164     bool advanceBufferQueue();
165     void doUpdate();
166     SurfaceBuffer *createSurfaceBuffer(struct wl_buffer *buffer);
167     void frameFinishedInternal();
168     bool postBuffer();
169
170     void attach(struct wl_buffer *buffer);
171
172     static void surface_destroy(struct wl_client *client, struct wl_resource *_surface);
173     static void surface_attach(struct wl_client *client, struct wl_resource *surface,
174                         struct wl_resource *buffer, int x, int y);
175     static void surface_damage(struct wl_client *client, struct wl_resource *_surface,
176                         int32_t x, int32_t y, int32_t width, int32_t height);
177     static void surface_frame(struct wl_client *client, struct wl_resource *resource,
178                        uint32_t callback);
179     static void surface_set_opaque_region(struct wl_client *client, struct wl_resource *resource,
180                                           struct wl_resource *region);
181     static void surface_set_input_region(struct wl_client *client, struct wl_resource *resource,
182                                          struct wl_resource *region);
183
184 };
185
186 inline SurfaceBuffer *Surface::currentSurfaceBuffer() const {
187     return m_backBuffer? m_backBuffer : m_frontBuffer;
188 }
189
190 }
191
192 #endif //WL_SURFACE_H