1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qdirectfbwindow.h"
43 #include "qdirectfbbackingstore.h"
44 #include "qdirectfbinput.h"
45 #include "qdirectfbscreen.h"
47 #include <QtGui/qwindowsysteminterface.h>
53 QDirectFbWindow::QDirectFbWindow(QWindow *tlw, QDirectFbInput *inputhandler)
54 : QPlatformWindow(tlw), m_inputHandler(inputhandler)
58 void QDirectFbWindow::createDirectFBWindow()
60 Q_ASSERT(!m_dfbWindow.data());
62 DFBDisplayLayerConfig layerConfig;
63 IDirectFBDisplayLayer *layer;
65 layer = toDfbScreen(window())->dfbLayer();
66 layer->GetConfiguration(layer, &layerConfig);
68 DFBWindowDescription description;
69 memset(&description,0,sizeof(DFBWindowDescription));
70 description.flags = DFBWindowDescriptionFlags(DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_POSX|DWDESC_POSY|DWDESC_SURFACE_CAPS
73 description.width = qMax(1, window()->width());
74 description.height = qMax(1, window()->height());
75 description.posx = window()->x();
76 description.posy = window()->y();
78 if (layerConfig.surface_caps & DSCAPS_PREMULTIPLIED)
79 description.surface_caps = DSCAPS_PREMULTIPLIED;
80 description.pixelformat = layerConfig.pixelformat;
82 description.options = DFBWindowOptions(DWOP_ALPHACHANNEL);
83 description.caps = DFBWindowCapabilities(DWCAPS_DOUBLEBUFFER|DWCAPS_ALPHACHANNEL);
85 DFBResult result = layer->CreateWindow(layer, &description, m_dfbWindow.outPtr());
87 DirectFBError("QDirectFbWindow: failed to create window", result);
89 m_dfbWindow->SetOpacity(m_dfbWindow.data(), 0xff);
90 m_inputHandler->addWindow(m_dfbWindow.data(), window());
93 QDirectFbWindow::~QDirectFbWindow()
95 m_inputHandler->removeWindow(m_dfbWindow.data());
96 m_dfbWindow->Destroy(m_dfbWindow.data());
99 void QDirectFbWindow::setGeometry(const QRect &rect)
101 // bool isMoveOnly = (rect.topLeft() != geometry().topLeft()) && (rect.size() == geometry().size());
103 QPlatformWindow::setGeometry(rect);
104 if (window()->isVisible()) {
105 m_dfbWindow->SetBounds(m_dfbWindow.data(), rect.x(),rect.y(),
106 rect.width(), rect.height());
107 // ### TODO port, verify if this is needed
109 //Hack. When moving since the WindowSurface of a window becomes invalid when moved
110 if (isMoveOnly) { //if resize then windowsurface is updated.
111 widget()->windowSurface()->resize(rect.size());
118 void QDirectFbWindow::setOpacity(qreal level)
120 const quint8 windowOpacity = quint8(level * 0xff);
121 m_dfbWindow->SetOpacity(m_dfbWindow.data(), windowOpacity);
124 void QDirectFbWindow::setVisible(bool visible)
127 int x = geometry().x();
128 int y = geometry().y();
129 m_dfbWindow->MoveTo(m_dfbWindow.data(), x, y);
131 QDirectFBPointer<IDirectFBDisplayLayer> displayLayer;
132 QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(), DLID_PRIMARY, displayLayer.outPtr());
134 DFBDisplayLayerConfig config;
135 displayLayer->GetConfiguration(displayLayer.data(), &config);
136 m_dfbWindow->MoveTo(m_dfbWindow.data(), config. width + 1, config.height + 1);
139 if (window()->isTopLevel() && visible)
140 QWindowSystemInterface::handleExposeEvent(window(), window()->geometry());
143 Qt::WindowFlags QDirectFbWindow::setWindowFlags(Qt::WindowFlags flags)
145 switch (flags & Qt::WindowType_Mask) {
147 DFBWindowOptions options;
148 m_dfbWindow->GetOptions(m_dfbWindow.data(), &options);
149 options = DFBWindowOptions(options | DWOP_GHOST);
150 m_dfbWindow->SetOptions(m_dfbWindow.data(), options);
156 m_dfbWindow->SetStackingClass(m_dfbWindow.data(), flags & Qt::WindowStaysOnTopHint ? DWSC_UPPER : DWSC_MIDDLE);
160 void QDirectFbWindow::raise()
162 m_dfbWindow->RaiseToTop(m_dfbWindow.data());
165 void QDirectFbWindow::lower()
167 m_dfbWindow->LowerToBottom(m_dfbWindow.data());
170 WId QDirectFbWindow::winId() const
173 m_dfbWindow->GetID(m_dfbWindow.data(), &id);
177 bool QDirectFbWindow::setKeyboardGrabEnabled(bool grab)
182 res = m_dfbWindow->GrabKeyboard(m_dfbWindow.data());
184 res = m_dfbWindow->UngrabKeyboard(m_dfbWindow.data());
186 return res == DFB_OK;
189 bool QDirectFbWindow::setMouseGrabEnabled(bool grab)
194 res = m_dfbWindow->GrabPointer(m_dfbWindow.data());
196 res = m_dfbWindow->UngrabPointer(m_dfbWindow.data());
198 return res == DFB_OK;
201 IDirectFBWindow *QDirectFbWindow::dfbWindow() const
203 return m_dfbWindow.data();
206 IDirectFBSurface *QDirectFbWindow::dfbSurface()
209 DFBResult res = m_dfbWindow->GetSurface(m_dfbWindow.data(), m_dfbSurface.outPtr());
211 DirectFBError(QDFB_PRETTY, res);
214 return m_dfbSurface.data();