~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to src/mimxserverlogic.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* * This file is part of Maliit framework *
2
 
 *
3
 
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
 
 * All rights reserved.
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * This library is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU Lesser General Public
10
 
 * License version 2.1 as published by the Free Software Foundation
11
 
 * and appearing in the file LICENSE.LGPL included in the packaging
12
 
 * of this file.
13
 
 */
14
 
 
15
 
#include "mimxserverlogic.h"
16
 
 
17
 
#include "mpassthruwindow.h"
18
 
#include "mimremotewindow.h"
19
 
#include "mimxextension.h"
20
 
#include "mimrotationanimation.h"
21
 
 
22
 
#include "mimxapplication.h"
23
 
#include "mimpluginsproxywidget.h"
24
 
#include "mimrotationanimation.h"
25
 
#include "mimserveroptions.h"
26
 
 
27
 
#include "windowedsurfacegroup.h"
28
 
 
29
 
#include <QDebug>
30
 
 
31
 
#include <X11/Xlib.h>
32
 
 
33
 
namespace
34
 
{
35
 
    class ConfigureForCompositing {
36
 
 
37
 
    public:
38
 
        ConfigureForCompositing(const MImServerXOptions &newOptions)
39
 
            : options(newOptions)
40
 
        {
41
 
        }
42
 
 
43
 
        bool operator()(QWidget *w)
44
 
        {
45
 
            if (not w) {
46
 
                return false;
47
 
            }
48
 
 
49
 
            w->setAttribute(Qt::WA_OpaquePaintEvent);
50
 
            w->setAttribute(Qt::WA_NoSystemBackground);
51
 
            w->setAutoFillBackground(false);
52
 
            // Be aware that one cannot verify whether the background role *is*
53
 
            // QPalette::NoRole - see QTBUG-17924.
54
 
            w->setBackgroundRole(QPalette::NoRole);
55
 
 
56
 
            if (!options.selfComposited) {
57
 
                // Careful: This flag can trigger a call to
58
 
                // qt_x11_recreateNativeWidgetsRecursive
59
 
                // - which will crash when it tries to get the effective WId
60
 
                // (as none of widgets have been mapped yet).
61
 
                w->setAttribute(Qt::WA_TranslucentBackground);
62
 
            }
63
 
 
64
 
            return true;
65
 
        }
66
 
 
67
 
    private:
68
 
        const MImServerXOptions &options;
69
 
 
70
 
    };
71
 
 
72
 
 
73
 
}
74
 
 
75
 
MImXServerLogic::MImXServerLogic(const MImServerXOptions &options, QObject *parent) :
76
 
    MImAbstractServerLogic(parent),
77
 
    xOptions(options),
78
 
    mBackgroundSuppressed(false),
79
 
    mCompositeExtension(),
80
 
    mDamageExtension(),
81
 
    mPassThruWindow(),
82
 
    mRemoteWindow(),
83
 
    mSurfaceGroupFactory(new Maliit::Server::WindowedSurfaceGroupFactory)
84
 
{
85
 
    mPassThruWindow.reset(new MPassThruWindow(this, xOptions));
86
 
    mPluginsProxyWidget.reset(new MImPluginsProxyWidget(mPassThruWindow.data()));
87
 
    mRotationAnimation = new MImRotationAnimation(mPluginsProxyWidget.data(), passThruWindow(),
88
 
                                                  this, xOptions);
89
 
 
90
 
    configureWidgetsForCompositing();
91
 
}
92
 
 
93
 
MImXServerLogic::~MImXServerLogic()
94
 
{
95
 
}
96
 
 
97
 
void MImXServerLogic::finalize()
98
 
{
99
 
    // Cannot destroy QWidgets or QPixmaps during MIMApplication destruction.
100
 
    // Hence the finalize handler that runs before the d'tor.
101
 
    mPluginsProxyWidget.reset();
102
 
    mPassThruWindow.reset();
103
 
    mRemoteWindow.reset();
104
 
}
105
 
 
106
 
bool MImXServerLogic::selfCompositionSupported()
107
 
{
108
 
    return mCompositeExtension.supported(0, 2) && mDamageExtension.supported();
109
 
}
110
 
 
111
 
void MImXServerLogic::x11EventFilter(XEvent *ev)
112
 
{
113
 
    handleTransientEvents(ev);
114
 
    handleRemoteWindowEvents(ev);
115
 
    handlePassThruMapEvent(ev);
116
 
}
117
 
 
118
 
void MImXServerLogic::handleTransientEvents(XEvent *ev)
119
 
{
120
 
    if (not mRemoteWindow.data()) {
121
 
        return;
122
 
    }
123
 
 
124
 
    if (mRemoteWindow->wasIconified(ev) || mRemoteWindow->wasUnmapped(ev)) {
125
 
        qDebug() << "MImX11ServerLogic" << __PRETTY_FUNCTION__
126
 
                 << "Remote window was destroyed or iconified - hiding.";
127
 
 
128
 
        Q_EMIT remoteWindowChanged(0);
129
 
        Q_EMIT applicationWindowGone();
130
 
        mRemoteWindow.reset();
131
 
    }
132
 
}
133
 
 
134
 
void MImXServerLogic::handleRemoteWindowEvents(XEvent *event)
135
 
{
136
 
    if (not mRemoteWindow.data()) {
137
 
        return;
138
 
    }
139
 
 
140
 
    mRemoteWindow->handleEvent(event);
141
 
}
142
 
 
143
 
void MImXServerLogic::handlePassThruMapEvent(XEvent *ev)
144
 
{
145
 
    if (ev->type != MapNotify)
146
 
        return;
147
 
 
148
 
    if (ev->xmap.window != mPassThruWindow->effectiveWinId())
149
 
        return;
150
 
 
151
 
    if (not mRemoteWindow.data()) {
152
 
        qWarning() << __PRETTY_FUNCTION__
153
 
                   << "No remote window found, but passthru window was mapped.";
154
 
        return;
155
 
    }
156
 
 
157
 
    mRemoteWindow->resetPixmap();
158
 
}
159
 
 
160
 
void MImXServerLogic::applicationFocusChanged(WId newRemoteWinId)
161
 
{
162
 
    if (0 == newRemoteWinId) {
163
 
        return;
164
 
    }
165
 
 
166
 
    if (mRemoteWindow.data() && mRemoteWindow->id() == newRemoteWinId) {
167
 
        return;
168
 
    }
169
 
 
170
 
    const bool wasRedirected(mRemoteWindow.data() && mRemoteWindow->isRedirected());
171
 
 
172
 
    mRemoteWindow.reset(new MImRemoteWindow(newRemoteWinId, this, xOptions));
173
 
 
174
 
    QSharedPointer<Maliit::Server::WindowedSurfaceGroupFactory> windowedSurfaceGroupFactory
175
 
            = qSharedPointerDynamicCast<Maliit::Server::WindowedSurfaceGroupFactory>(mSurfaceGroupFactory);
176
 
    if (windowedSurfaceGroupFactory)
177
 
        windowedSurfaceGroupFactory->applicationFocusChanged(newRemoteWinId);
178
 
 
179
 
    connect(mRemoteWindow.data(), SIGNAL(contentUpdated(QRegion)),
180
 
            this,                SLOT(updatePassThruWindow(QRegion)));
181
 
 
182
 
    if (wasRedirected) {
183
 
        mRemoteWindow->redirect();
184
 
    }
185
 
 
186
 
    Q_EMIT remoteWindowChanged(mRemoteWindow.data());
187
 
}
188
 
 
189
 
void MImXServerLogic::setSuppressBackground(bool suppress)
190
 
{
191
 
    mBackgroundSuppressed = suppress;
192
 
}
193
 
 
194
 
QWidget *MImXServerLogic::passThruWindow() const
195
 
{
196
 
    return mPassThruWindow.data();
197
 
}
198
 
 
199
 
QSharedPointer<Maliit::Server::AbstractSurfaceGroupFactory> MImXServerLogic::surfaceGroupFactory() const
200
 
{
201
 
    return mSurfaceGroupFactory;
202
 
}
203
 
 
204
 
const QPixmap &MImXServerLogic::remoteWindowPixmap()
205
 
{
206
 
    if (not mRemoteWindow.data()
207
 
            || mBackgroundSuppressed
208
 
            || not xOptions.selfComposited) {
209
 
        static const QPixmap empty;
210
 
        return empty;
211
 
    }
212
 
 
213
 
    return mRemoteWindow->windowPixmap();
214
 
}
215
 
 
216
 
void MImXServerLogic::updatePassThruWindow(const QRegion &region)
217
 
{
218
 
    if (region.isEmpty() || remoteWindowPixmap().isNull()) {
219
 
        qDebug() << "Skipping update request for passthru window.";
220
 
        return;
221
 
    }
222
 
 
223
 
    mPassThruWindow->updateFromRemoteWindow(region);
224
 
}
225
 
 
226
 
void MImXServerLogic::pluginLoaded()
227
 
{
228
 
    configureWidgetsForCompositing();
229
 
}
230
 
 
231
 
void MImXServerLogic::configureWidgetsForCompositing()
232
 
{
233
 
    ConfigureForCompositing visitor(xOptions);
234
 
    visitWidgetHierarchy(visitor, mPassThruWindow.data());
235
 
}
236
 
 
237
 
void MImXServerLogic::appOrientationAboutToChange(int toAngle) {
238
 
    mRotationAnimation->appOrientationAboutToChange(toAngle);
239
 
}
240
 
 
241
 
void MImXServerLogic::appOrientationChangeFinished(int toAngle) {
242
 
    mRotationAnimation->appOrientationChangeFinished(toAngle);
243
 
}
244
 
 
245
 
MImRemoteWindow *MImXServerLogic::remoteWindow() const
246
 
{
247
 
    return mRemoteWindow.data();
248
 
}
249
 
 
250
 
void MImXServerLogic::inputPassthrough(const QRegion &region)
251
 
{
252
 
    mPassThruWindow->inputPassthrough(region);
253
 
}
254
 
 
255
 
const MImXCompositeExtension& MImXServerLogic::compositeExtension()
256
 
{
257
 
    return mCompositeExtension;
258
 
}
259
 
 
260
 
const MImXDamageExtension& MImXServerLogic::damageExtension()
261
 
{
262
 
    return mDamageExtension;
263
 
}