2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include "DSWindowPrivate.h"
26 #include "DSWaylandSurface.h"
27 #include "IDSBuffer.h"
29 namespace display_server
32 DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr)
33 : DSObjectPrivate(p_ptr),
45 __waylandSurface(nullptr),
47 __allowUserGeometry(false),
49 __vkbd_floating(false),
50 __renderView(nullptr),
51 __displayDeviceHWCWindow(nullptr)
55 DSWindowPrivate::~DSWindowPrivate()
59 bool DSWindowPrivate::create(std::shared_ptr<DSWaylandSurface> waylandSurface)
61 __waylandSurface = waylandSurface;
64 __waylandSurface->registerCallbackSurfaceCommitted(this, std::bind(&DSWindowPrivate::__onSurfaceCommitted, this, std::placeholders::_1));
69 void DSWindowPrivate::destroy(void)
73 void DSWindowPrivate::setParent(DSWindow *parent)
78 DSWindow *DSWindowPrivate::getParent(void)
83 bool DSWindowPrivate::show(void)
88 bool DSWindowPrivate::hide(bool autoFocus)
93 int DSWindowPrivate::showState(void)
98 bool DSWindowPrivate::setTitle(const std::string &title)
100 __title.replace(__title.begin(), __title.end(), title);
104 const std::string DSWindowPrivate::getTitle(void)
109 bool DSWindowPrivate::setSkipFocus(bool set)
111 __acceptsFocus = !set;
115 bool DSWindowPrivate::getSkipFocus(void)
123 void DSWindowPrivate::allowUserGeometry(bool set)
125 __allowUserGeometry = set;
128 bool DSWindowPrivate::isAllowUserGeometry(void)
130 return __allowUserGeometry;
133 bool DSWindowPrivate::setLayer(int layer)
138 bool DSWindowPrivate::raise(void)
143 bool DSWindowPrivate::lower(void)
148 bool DSWindowPrivate::raiseToTop()
151 __renderView->raiseToTop();
153 // TODO: set raiseToTop to hwc window ???
154 // if (__displayDeviceHWCWindow)
155 // __displayDeviceHWCWindow->raiseToTop();
160 bool DSWindowPrivate::lowerToBottom()
163 __renderView->lowerToBottom();
165 // TODO: set lowerToBottom to hwc window ???
166 // if (__displayDeviceHWCWindow)
167 // __displayDeviceHWCWindow->lowerToBottom();
172 bool DSWindowPrivate::unsetFocus(void)
178 bool DSWindowPrivate::setFocus(void)
184 bool DSWindowPrivate::isCreated()
189 void DSWindowPrivate::setPosition(int x, int y)
195 __renderView->setPosition(x, y);
197 // TODO: set lowerToBottom to hwc window ???
198 // if (__displayDeviceHWCWindow)
199 // __displayDeviceHWCWindow->lowerToBottom();
202 bool DSWindowPrivate::setVkbdFloating(bool set)
204 __vkbd_floating = set;
208 bool DSWindowPrivate::getVkbdFloating()
210 return __vkbd_floating;
213 void DSWindowPrivate::setRenderView(std::shared_ptr<DSRenderView> &renderView)
215 __renderView = renderView;
218 void DSWindowPrivate::setDisplayDeviceHWCWindow(std::shared_ptr<IDSDisplayDeviceHWCWindow> &displayDeviceHWCWindow)
220 __displayDeviceHWCWindow = displayDeviceHWCWindow;
223 void DSWindowPrivate::__onSurfaceCommitted(std::shared_ptr<DSWaylandSurfaceCommitInfo> waylandSurfaceCommitInfo)
225 DS_GET_PUB(DSWindow);
227 if (waylandSurfaceCommitInfo->bufferChanged()) {
228 std::shared_ptr<IDSBuffer> buffer = waylandSurfaceCommitInfo->getBuffer();
230 // emit a signal of the buffer changed
231 pub->__bufferChangedSignal.emit(buffer);
234 // TODO: get more information from waylandSurfaceCommitInfo. ex) damageSurface, damageBuffer, transform, scale and so on
238 : DS_INIT_PRIVATE_PTR(DSWindow)
241 DSWindow::DSWindow(std::shared_ptr<DSWaylandSurface> waylandSurface)
242 : DS_INIT_PRIVATE_PTR(DSWindow)
244 create(waylandSurface);
247 DSWindow::~DSWindow()
251 bool DSWindow::create(std::shared_ptr<DSWaylandSurface> waylandSurface)
253 DS_GET_PRIV(DSWindow);
255 if (!priv->isCreated())
257 return priv->create(waylandSurface);
263 void DSWindow::destroy(void)
265 DS_GET_PRIV(DSWindow);
270 void DSWindow::setParent(DSWindow *parent)
272 if (parent == this) return;
274 DS_GET_PRIV(DSWindow);
275 priv->setParent(parent);
278 DSWindow *DSWindow::getParent(void)
280 DS_GET_PRIV(DSWindow);
281 return priv->getParent();
284 bool DSWindow::show(void)
286 DS_GET_PRIV(DSWindow);
291 bool DSWindow::hide(bool autoFocus)
293 DS_GET_PRIV(DSWindow);
295 return priv->hide(autoFocus);
298 int DSWindow::showState(void)
300 DS_GET_PRIV(DSWindow);
302 return priv->showState();
305 bool DSWindow::setTitle(const std::string &title)
307 DSLOG_DBG("DSWindow", "title:%s", title.c_str());
309 DS_GET_PRIV(DSWindow);
310 return priv->setTitle(title);
313 const std::string DSWindow::getTitle(void)
315 DS_GET_PRIV(DSWindow);
316 return priv->getTitle();
319 bool DSWindow::setSkipFocus(bool set)
321 DS_GET_PRIV(DSWindow);
322 return priv->setSkipFocus(set);
325 bool DSWindow::getSkipFocus(void)
327 DS_GET_PRIV(DSWindow);
328 return priv->getSkipFocus();
331 void DSWindow::allowUserGeometry(bool set)
333 DS_GET_PRIV(DSWindow);
334 priv->allowUserGeometry(set);
337 bool DSWindow::isAllowUserGeometry(void)
339 DS_GET_PRIV(DSWindow);
340 return priv->isAllowUserGeometry();
343 bool DSWindow::setLayer(int layer)
345 DS_GET_PRIV(DSWindow);
347 return priv->setLayer(layer);
350 bool DSWindow::raise(void)
352 DS_GET_PRIV(DSWindow);
355 return priv->raise();
358 bool DSWindow::lower(void)
360 DS_GET_PRIV(DSWindow);
363 return priv->lower();
366 bool DSWindow::raiseToTop()
372 bool DSWindow::lowerToBottom()
378 bool DSWindow::unsetFocus(void)
380 DS_GET_PRIV(DSWindow);
382 return priv->unsetFocus();
385 bool DSWindow::setFocus(void)
387 DS_GET_PRIV(DSWindow);
389 return priv->setFocus();
392 bool DSWindow::hasFocus(void)
394 DS_GET_PRIV(DSWindow);
396 return priv->__hasFocus;
399 void DSWindow::setPosition(int x, int y)
401 DS_GET_PRIV(DSWindow);
407 stPosition DSWindow::getPosition(void)
409 DS_GET_PRIV(DSWindow);
418 stSize DSWindow::getSize()
420 DS_GET_PRIV(DSWindow);
429 void DSWindow::setSize(unsigned int w, unsigned int h)
431 DS_GET_PRIV(DSWindow);
437 void DSWindow::setSize(stSize size)
439 DS_GET_PRIV(DSWindow);
445 void DSWindow::setZOrder(unsigned int zOrder)
447 DS_GET_PRIV(DSWindow);
449 priv->__zOrder = zOrder;
452 unsigned int DSWindow::getZOrder()
454 DS_GET_PRIV(DSWindow);
456 return priv->__zOrder;
459 bool DSWindow::setVkbdFloating(bool set)
461 DS_GET_PRIV(DSWindow);
463 return priv->setVkbdFloating(set);
466 bool DSWindow::getVkbdFloating()
468 DS_GET_PRIV(DSWindow);
470 return priv->getVkbdFloating();
473 DSWaylandSurface *DSWindow::surface()
475 DS_GET_PRIV(DSWindow);
477 return priv->__waylandSurface.get();
480 void DSWindow::setRenderView(std::shared_ptr<DSRenderView> &renderView)
482 DS_GET_PRIV(DSWindow);
484 priv->setRenderView(renderView);
487 void DSWindow::setDisplayDeviceHWCWindow(std::shared_ptr<IDSDisplayDeviceHWCWindow> &displayDeviceHWCWindow)
489 DS_GET_PRIV(DSWindow);
491 priv->setDisplayDeviceHWCWindow(displayDeviceHWCWindow);
494 void DSWindow::registerCallbackBufferChanged(DSObject *slot, std::function<void(std::shared_ptr<IDSBuffer>)> func)
496 __bufferChangedSignal.connect(slot, func);
499 } // namespace display_server