DSWindowPrivate: add setPosition method
[platform/core/uifw/libds.git] / src / DSWindow / DSWindow.cpp
1 /*
2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23
24 #include "DSWindow.h"
25 #include "DSWindowPrivate.h"
26 #include "DSWaylandSurface.h"
27 #include "IDSBuffer.h"
28
29 namespace display_server
30 {
31
32 DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr)
33         : DSObjectPrivate(p_ptr),
34           __p_ptr(p_ptr),
35           __parent(nullptr),
36           __x(0),
37           __y(0),
38           __w(0),
39           __h(0),
40           __zOrder(0),
41           __committedW(0),
42           __committedH(0),
43           __created(false),
44           __hasFocus(false),
45           __waylandSurface(nullptr),
46           __acceptsFocus(true),
47           __allowUserGeometry(false),
48           __title(""),
49           __vkbd_floating(false),
50           __renderView(nullptr),
51           __displayDeviceHWCWindow(nullptr)
52 {
53 }
54
55 DSWindowPrivate::~DSWindowPrivate()
56 {
57 }
58
59 bool DSWindowPrivate::create(std::shared_ptr<DSWaylandSurface> waylandSurface)
60 {
61         __waylandSurface = waylandSurface;
62         __created = true;
63
64         __waylandSurface->registerCallbackSurfaceCommitted(this, std::bind(&DSWindowPrivate::__onSurfaceCommitted, this, std::placeholders::_1));
65
66         return true;
67 }
68
69 void DSWindowPrivate::destroy(void)
70 {
71 }
72
73 void DSWindowPrivate::setParent(DSWindow *parent)
74 {
75         __parent = parent;
76 }
77
78 DSWindow *DSWindowPrivate::getParent(void)
79 {
80         return __parent;
81 }
82
83 bool DSWindowPrivate::show(void)
84 {
85         return true;
86 }
87
88 bool DSWindowPrivate::hide(bool autoFocus)
89 {
90         return true;
91 }
92
93 int  DSWindowPrivate::showState(void)
94 {
95         return 0;
96 }
97
98 bool DSWindowPrivate::setTitle(const std::string &title)
99 {
100         __title.replace(__title.begin(), __title.end(), title);
101         return true;
102 }
103
104 const std::string DSWindowPrivate::getTitle(void)
105 {
106         return __title;
107 }
108
109 bool DSWindowPrivate::setSkipFocus(bool set)
110 {
111         __acceptsFocus = !set;
112         return true;
113 }
114
115 bool DSWindowPrivate::getSkipFocus(void)
116 {
117         if (__acceptsFocus)
118                 return false;
119         else
120                 return true;
121 }
122
123 void DSWindowPrivate::allowUserGeometry(bool set)
124 {
125         __allowUserGeometry = set;
126 }
127
128 bool DSWindowPrivate::isAllowUserGeometry(void)
129 {
130         return __allowUserGeometry;
131 }
132
133 bool DSWindowPrivate::setLayer(int layer)
134 {
135         return true;
136 }
137
138 bool DSWindowPrivate::raise(void)
139 {
140         return true;
141 }
142
143 bool DSWindowPrivate::lower(void)
144 {
145         return true;
146 }
147
148 bool DSWindowPrivate::raiseToTop()
149 {
150         if (__renderView)
151                 __renderView->raiseToTop();
152
153         // TODO: set raiseToTop to hwc window ???
154         // if (__displayDeviceHWCWindow)
155         //      __displayDeviceHWCWindow->raiseToTop();
156
157         return true;
158 }
159
160 bool DSWindowPrivate::lowerToBottom()
161 {
162         if (__renderView)
163                 __renderView->lowerToBottom();
164
165         // TODO: set lowerToBottom to hwc window ???
166         // if (__displayDeviceHWCWindow)
167         //      __displayDeviceHWCWindow->lowerToBottom();
168
169         return true;
170 }
171
172 bool DSWindowPrivate::unsetFocus(void)
173 {
174         __hasFocus = false;
175         return true;
176 }
177
178 bool DSWindowPrivate::setFocus(void)
179 {
180         __hasFocus = true;
181         return true;
182 }
183
184 bool DSWindowPrivate::isCreated()
185 {
186         return __created;
187 }
188
189 void DSWindowPrivate::setPosition(int x, int y)
190 {
191         __x = x;
192         __y = y;
193
194         if (__renderView)
195                 __renderView->setPosition(x, y);
196
197         // TODO: set lowerToBottom to hwc window ???
198         // if (__displayDeviceHWCWindow)
199         //      __displayDeviceHWCWindow->lowerToBottom();
200 }
201
202 bool DSWindowPrivate::setVkbdFloating(bool set)
203 {
204         __vkbd_floating = set;
205         return true;
206 }
207
208 bool DSWindowPrivate::getVkbdFloating()
209 {
210         return __vkbd_floating;
211 }
212
213 void DSWindowPrivate::setRenderView(std::shared_ptr<DSRenderView> &renderView)
214 {
215         __renderView = renderView;
216 }
217
218 void DSWindowPrivate::setDisplayDeviceHWCWindow(std::shared_ptr<IDSDisplayDeviceHWCWindow> &displayDeviceHWCWindow)
219 {
220         __displayDeviceHWCWindow = displayDeviceHWCWindow;
221 }
222
223 void DSWindowPrivate::__onSurfaceCommitted(std::shared_ptr<DSWaylandSurfaceCommitInfo> waylandSurfaceCommitInfo)
224 {
225         DS_GET_PUB(DSWindow);
226
227         if (waylandSurfaceCommitInfo->bufferChanged()) {
228                 std::shared_ptr<IDSBuffer> buffer = waylandSurfaceCommitInfo->getBuffer();
229
230                 // emit a signal of the buffer changed
231                 pub->__bufferChangedSignal.emit(buffer);
232         }
233
234         // TODO: get more information from waylandSurfaceCommitInfo. ex) damageSurface, damageBuffer, transform, scale and so on
235 }
236
237 DSWindow::DSWindow()
238         : DS_INIT_PRIVATE_PTR(DSWindow)
239 {}
240
241 DSWindow::DSWindow(std::shared_ptr<DSWaylandSurface> waylandSurface)
242         : DS_INIT_PRIVATE_PTR(DSWindow)
243 {
244         create(waylandSurface);
245 }
246
247 DSWindow::~DSWindow()
248 {
249 }
250
251 bool DSWindow::create(std::shared_ptr<DSWaylandSurface> waylandSurface)
252 {
253         DS_GET_PRIV(DSWindow);
254
255         if (!priv->isCreated())
256         {
257                 return priv->create(waylandSurface);
258         }
259
260         return true;
261 }
262
263 void DSWindow::destroy(void)
264 {
265         DS_GET_PRIV(DSWindow);
266
267         priv->destroy();
268 }
269
270 void DSWindow::setParent(DSWindow *parent)
271 {
272         if (parent == this) return;
273
274         DS_GET_PRIV(DSWindow);
275         priv->setParent(parent);
276 }
277
278 DSWindow *DSWindow::getParent(void)
279 {
280         DS_GET_PRIV(DSWindow);
281         return priv->getParent();
282 }
283
284 bool DSWindow::show(void)
285 {
286         DS_GET_PRIV(DSWindow);
287
288         return priv->show();
289 }
290
291 bool DSWindow::hide(bool autoFocus)
292 {
293         DS_GET_PRIV(DSWindow);
294
295         return priv->hide(autoFocus);
296 }
297
298 int  DSWindow::showState(void)
299 {
300         DS_GET_PRIV(DSWindow);
301
302         return priv->showState();
303 }
304
305 bool DSWindow::setTitle(const std::string &title)
306 {
307         DSLOG_DBG("DSWindow", "title:%s", title.c_str());
308
309         DS_GET_PRIV(DSWindow);
310         return priv->setTitle(title);
311 }
312
313 const std::string DSWindow::getTitle(void)
314 {
315         DS_GET_PRIV(DSWindow);
316         return priv->getTitle();
317 }
318
319 bool DSWindow::setSkipFocus(bool set)
320 {
321         DS_GET_PRIV(DSWindow);
322         return priv->setSkipFocus(set);
323 }
324
325 bool DSWindow::getSkipFocus(void)
326 {
327         DS_GET_PRIV(DSWindow);
328         return priv->getSkipFocus();
329 }
330
331 void DSWindow::allowUserGeometry(bool set)
332 {
333         DS_GET_PRIV(DSWindow);
334         priv->allowUserGeometry(set);
335 }
336
337 bool DSWindow::isAllowUserGeometry(void)
338 {
339         DS_GET_PRIV(DSWindow);
340         return priv->isAllowUserGeometry();
341 }
342
343 bool DSWindow::setLayer(int layer)
344 {
345         DS_GET_PRIV(DSWindow);
346
347         return priv->setLayer(layer);
348 }
349
350 bool DSWindow::raise(void)
351 {
352         DS_GET_PRIV(DSWindow);
353
354         raiseToTop();
355         return priv->raise();
356 }
357
358 bool DSWindow::lower(void)
359 {
360         DS_GET_PRIV(DSWindow);
361
362         lowerToBottom();
363         return priv->lower();
364 }
365
366 bool DSWindow::raiseToTop()
367 {
368
369         return true;
370 }
371
372 bool DSWindow::lowerToBottom()
373 {
374
375         return true;
376 }
377
378 bool DSWindow::unsetFocus(void)
379 {
380         DS_GET_PRIV(DSWindow);
381
382         return priv->unsetFocus();
383 }
384
385 bool DSWindow::setFocus(void)
386 {
387         DS_GET_PRIV(DSWindow);
388
389         return priv->setFocus();
390 }
391
392 bool DSWindow::hasFocus(void)
393 {
394         DS_GET_PRIV(DSWindow);
395
396         return priv->__hasFocus;
397 }
398
399 void DSWindow::setPosition(int x, int y)
400 {
401         DS_GET_PRIV(DSWindow);
402
403         priv->__x = x;
404         priv->__y = y;
405 }
406
407 stPosition DSWindow::getPosition(void)
408 {
409         DS_GET_PRIV(DSWindow);
410
411         stPosition pos;
412         pos.x = priv->__x;
413         pos.y = priv->__y;
414
415         return pos;
416 }
417
418 stSize DSWindow::getSize()
419 {
420         DS_GET_PRIV(DSWindow);
421
422         stSize size;
423         size.w = priv->__w;
424         size.h = priv->__h;
425
426         return size;
427 }
428
429 void DSWindow::setSize(unsigned int w, unsigned int h)
430 {
431         DS_GET_PRIV(DSWindow);
432
433         priv->__w = w;
434         priv->__h = h;
435 }
436
437 void DSWindow::setSize(stSize size)
438 {
439         DS_GET_PRIV(DSWindow);
440
441         priv->__w = size.w;
442         priv->__h = size.h;
443 }
444
445 void DSWindow::setZOrder(unsigned int zOrder)
446 {
447         DS_GET_PRIV(DSWindow);
448
449         priv->__zOrder = zOrder;
450 }
451
452 unsigned int DSWindow::getZOrder()
453 {
454         DS_GET_PRIV(DSWindow);
455
456         return priv->__zOrder;
457 }
458
459 bool DSWindow::setVkbdFloating(bool set)
460 {
461         DS_GET_PRIV(DSWindow);
462
463         return priv->setVkbdFloating(set);
464 }
465
466 bool DSWindow::getVkbdFloating()
467 {
468         DS_GET_PRIV(DSWindow);
469
470         return priv->getVkbdFloating();
471 }
472
473 DSWaylandSurface *DSWindow::surface()
474 {
475         DS_GET_PRIV(DSWindow);
476
477         return priv->__waylandSurface.get();
478 }
479
480 void DSWindow::setRenderView(std::shared_ptr<DSRenderView> &renderView)
481 {
482         DS_GET_PRIV(DSWindow);
483
484         priv->setRenderView(renderView);
485 }
486
487 void DSWindow::setDisplayDeviceHWCWindow(std::shared_ptr<IDSDisplayDeviceHWCWindow> &displayDeviceHWCWindow)
488 {
489         DS_GET_PRIV(DSWindow);
490
491         priv->setDisplayDeviceHWCWindow(displayDeviceHWCWindow);
492 }
493
494 void DSWindow::registerCallbackBufferChanged(DSObject *slot, std::function<void(std::shared_ptr<IDSBuffer>)> func)
495 {
496         __bufferChangedSignal.connect(slot, func);
497 }
498
499 } //  namespace display_server