1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qdirectfbwindow.h"
41 #include "qdirectfbbackingstore.h"
42 #include "qdirectfbinput.h"
43 #include "qdirectfbscreen.h"
44
45 #include <qpa/qwindowsysteminterface.h>
46
47 #include <directfb.h>
48
49 QT_BEGIN_NAMESPACE
50
QDirectFbWindow(QWindow * tlw,QDirectFbInput * inputhandler)51 QDirectFbWindow::QDirectFbWindow(QWindow *tlw, QDirectFbInput *inputhandler)
52 : QPlatformWindow(tlw), m_inputHandler(inputhandler)
53 {
54 }
55
createDirectFBWindow()56 void QDirectFbWindow::createDirectFBWindow()
57 {
58 Q_ASSERT(!m_dfbWindow.data());
59
60 DFBDisplayLayerConfig layerConfig;
61 IDirectFBDisplayLayer *layer;
62
63 layer = toDfbScreen(window())->dfbLayer();
64 layer->GetConfiguration(layer, &layerConfig);
65
66 DFBWindowDescription description;
67 memset(&description,0,sizeof(DFBWindowDescription));
68
69 if (window()->type() == Qt::Desktop) {
70 QRect fullscreenRect(QPoint(), screen()->availableGeometry().size());
71 window()->setGeometry(fullscreenRect);
72
73 DFBResult result = layer->CreateWindow(layer, &description, m_dfbWindow.outPtr());
74 if (result != DFB_OK)
75 DirectFBError("QDirectFbWindow: failed to create window", result);
76
77 } else {
78 description.flags = DFBWindowDescriptionFlags(DWDESC_WIDTH|DWDESC_HEIGHT|DWDESC_POSX|DWDESC_POSY|DWDESC_SURFACE_CAPS
79 |DWDESC_OPTIONS
80 |DWDESC_CAPS);
81 description.width = qMax(1, window()->width());
82 description.height = qMax(1, window()->height());
83 description.posx = window()->x();
84 description.posy = window()->y();
85
86 if (layerConfig.surface_caps & DSCAPS_PREMULTIPLIED)
87 description.surface_caps = DSCAPS_PREMULTIPLIED;
88 description.pixelformat = layerConfig.pixelformat;
89
90 description.options = DFBWindowOptions(DWOP_ALPHACHANNEL);
91 description.caps = DFBWindowCapabilities(DWCAPS_DOUBLEBUFFER|DWCAPS_ALPHACHANNEL);
92
93
94 DFBResult result = layer->CreateWindow(layer, &description, m_dfbWindow.outPtr());
95 if (result != DFB_OK)
96 DirectFBError("QDirectFbWindow: failed to create window", result);
97
98 m_dfbWindow->SetOpacity(m_dfbWindow.data(), 0xff);
99 m_inputHandler->addWindow(m_dfbWindow.data(), window());
100 }
101 }
102
~QDirectFbWindow()103 QDirectFbWindow::~QDirectFbWindow()
104 {
105 m_inputHandler->removeWindow(m_dfbWindow.data());
106 m_dfbWindow->Destroy(m_dfbWindow.data());
107 }
108
setGeometry(const QRect & rect)109 void QDirectFbWindow::setGeometry(const QRect &rect)
110 {
111 QPlatformWindow::setGeometry(rect);
112 m_dfbWindow->SetBounds(m_dfbWindow.data(), rect.x(),rect.y(),
113 rect.width(), rect.height());
114 }
115
setOpacity(qreal level)116 void QDirectFbWindow::setOpacity(qreal level)
117 {
118 const quint8 windowOpacity = quint8(level * 0xff);
119 m_dfbWindow->SetOpacity(m_dfbWindow.data(), windowOpacity);
120 }
121
setVisible(bool visible)122 void QDirectFbWindow::setVisible(bool visible)
123 {
124 if (window()->type() != Qt::Desktop) {
125 if (visible) {
126 int x = geometry().x();
127 int y = geometry().y();
128 m_dfbWindow->MoveTo(m_dfbWindow.data(), x, y);
129 } else {
130 QDirectFBPointer<IDirectFBDisplayLayer> displayLayer;
131 QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(), DLID_PRIMARY, displayLayer.outPtr());
132
133 DFBDisplayLayerConfig config;
134 displayLayer->GetConfiguration(displayLayer.data(), &config);
135 m_dfbWindow->MoveTo(m_dfbWindow.data(), config. width + 1, config.height + 1);
136 }
137
138 if (window()->isTopLevel() && visible)
139 QPlatformWindow::setVisible(visible);
140 }
141 }
142
setWindowFlags(Qt::WindowFlags flags)143 void QDirectFbWindow::setWindowFlags(Qt::WindowFlags flags)
144 {
145 switch (flags & Qt::WindowType_Mask) {
146 case Qt::ToolTip: {
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);
151 break; }
152 default:
153 break;
154 }
155
156 m_dfbWindow->SetStackingClass(m_dfbWindow.data(), flags & Qt::WindowStaysOnTopHint ? DWSC_UPPER : DWSC_MIDDLE);
157 }
158
raise()159 void QDirectFbWindow::raise()
160 {
161 if (window()->type() != Qt::Desktop)
162 m_dfbWindow->RaiseToTop(m_dfbWindow.data());
163 }
164
lower()165 void QDirectFbWindow::lower()
166 {
167 if (window()->type() != Qt::Desktop)
168 m_dfbWindow->LowerToBottom(m_dfbWindow.data());
169 }
170
winId() const171 WId QDirectFbWindow::winId() const
172 {
173 DFBWindowID id;
174 m_dfbWindow->GetID(m_dfbWindow.data(), &id);
175 return WId(id);
176 }
177
setKeyboardGrabEnabled(bool grab)178 bool QDirectFbWindow::setKeyboardGrabEnabled(bool grab)
179 {
180 DFBResult res;
181
182 if (grab)
183 res = m_dfbWindow->GrabKeyboard(m_dfbWindow.data());
184 else
185 res = m_dfbWindow->UngrabKeyboard(m_dfbWindow.data());
186
187 return res == DFB_OK;
188 }
189
setMouseGrabEnabled(bool grab)190 bool QDirectFbWindow::setMouseGrabEnabled(bool grab)
191 {
192 DFBResult res;
193
194 if (grab)
195 res = m_dfbWindow->GrabPointer(m_dfbWindow.data());
196 else
197 res = m_dfbWindow->UngrabPointer(m_dfbWindow.data());
198
199 return res == DFB_OK;
200 }
201
dfbWindow() const202 IDirectFBWindow *QDirectFbWindow::dfbWindow() const
203 {
204 return m_dfbWindow.data();
205 }
206
dfbSurface()207 IDirectFBSurface *QDirectFbWindow::dfbSurface()
208 {
209 if (!m_dfbSurface) {
210 DFBResult res = m_dfbWindow->GetSurface(m_dfbWindow.data(), m_dfbSurface.outPtr());
211 if (res != DFB_OK)
212 DirectFBError(QDFB_PRETTY, res);
213 }
214
215 return m_dfbSurface.data();
216 }
217
218 QT_END_NAMESPACE
219