Add Window::SetLayout method
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-base-ecore-wl2.h
1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_WINDOW_BASE_ECORE_WL2_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_WINDOW_BASE_ECORE_WL2_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/window-system/common/window-base.h>
23
24 // EXTERNAL HEADERS
25 #include <Ecore.h>
26 #include <Ecore_Wl2.h>
27 #include <input-method-client-protocol.h>
28 #include <tizen-extension-client-protocol.h>
29 #include <wayland-egl.h>
30 #include <xkbcommon/xkbcommon.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38 class WindowRenderSurface;
39 class WindowRenderSurfaceEcoreWl2;
40
41 /**
42  * WindowBaseEcoreWl2 class provides an WindowBase Ecore-Wayland2 implementation.
43  */
44 class WindowBaseEcoreWl2 : public WindowBase
45 {
46 public:
47   /**
48    * @brief Constructor
49    */
50   WindowBaseEcoreWl2(PositionSize positionSize, Any surface, bool isTransparent);
51
52   /**
53    * @brief Destructor
54    */
55   virtual ~WindowBaseEcoreWl2();
56
57 public:
58   /**
59    * @brief Called when the window iconify state is changed.
60    */
61   Eina_Bool OnIconifyStateChanged(void* data, int type, void* event);
62
63   /**
64    * @brief Called when the window gains focus.
65    */
66   Eina_Bool OnFocusIn(void* data, int type, void* event);
67
68   /**
69    * @brief Called when the window loses focus.
70    */
71   Eina_Bool OnFocusOut(void* data, int type, void* event);
72
73   /**
74    * @brief Called when the output is transformed.
75    */
76   Eina_Bool OnOutputTransform(void* data, int type, void* event);
77
78   /**
79    * @brief Called when the output transform should be ignored.
80    */
81   Eina_Bool OnIgnoreOutputTransform(void* data, int type, void* event);
82
83   /**
84    * @brief Called when a rotation event is recevied.
85    */
86   void OnRotation(void* data, int type, void* event);
87
88   /**
89    * @brief Called when a configure event is recevied.
90    */
91   void OnConfiguration(void* data, int type, void* event);
92
93   /**
94    * @brief Called when a touch down is received.
95    */
96   void OnMouseButtonDown(void* data, int type, void* event);
97
98   /**
99    * @brief Called when a touch up is received.
100    */
101   void OnMouseButtonUp(void* data, int type, void* event);
102
103   /**
104    * @brief Called when a touch motion is received.
105    */
106   void OnMouseButtonMove(void* data, int type, void* event);
107
108   /**
109    * @brief Called when a touch is canceled.
110    */
111   void OnMouseButtonCancel(void* data, int type, void* event);
112
113   /**
114    * @brief Called when a mouse wheel is received.
115    */
116   void OnMouseWheel(void* data, int type, void* event);
117
118   /**
119    * @brief Called when a detent rotation event is recevied.
120    */
121   void OnDetentRotation(void* data, int type, void* event);
122
123   /**
124    * @brief Called when a key down is received.
125    */
126   void OnKeyDown(void* data, int type, void* event);
127
128   /**
129    * @brief Called when a key up is received.
130    */
131   void OnKeyUp(void* data, int type, void* event);
132
133   /**
134    * @brief Called when the source window notifies us the content in clipboard is selected.
135    */
136   void OnDataSend(void* data, int type, void* event);
137
138   /**
139    * @brief Called when the source window sends us about the selected content.
140    */
141   void OnDataReceive(void* data, int type, void* event);
142
143   /**
144    * @brief Called when a font name is changed.
145    */
146   void OnFontNameChanged();
147
148   /**
149    * @brief Called when a font size is changed.
150    */
151   void OnFontSizeChanged();
152
153   /**
154    * @brief Called when a transition effect-start/end event is received.
155    */
156   void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
157
158   /**
159    * @brief Called when a keyboard repeat event is changed.
160    */
161   void OnKeyboardRepeatSettingsChanged();
162
163   /**
164    * @brief Called when a window redraw is requested.
165    */
166   void OnEcoreEventWindowRedrawRequest();
167
168   /**
169    * @brief Called when window's auxiliary is changed then display server send the changed message.
170    *
171    * @param[in] auxiliary's message data. It has key, value and integer list data.
172    */
173   void OnEcoreEventWindowAuxiliaryMessage(void* event);
174
175   /**
176    * @brief Called when a keymap is changed.
177    */
178   void KeymapChanged(void* data, int type, void* event);
179
180   /**
181    * @brief RegistryGlobalCallback
182    */
183   void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
184
185   /**
186    * @brief RegistryGlobalCallbackRemove
187    */
188   void RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id);
189
190   /**
191    * @brief TizenPolicyNotificationChangeDone
192    */
193   void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state);
194
195   /**
196    * @brief TizenPolicyScreenModeChangeDone
197    */
198   void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state);
199
200   /**
201    * @brief DisplayPolicyBrightnessChangeDone
202    */
203   void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state);
204
205   /**
206    * @brief Gets the key code by keyName.
207    */
208   void GetKeyCode(std::string keyName, int32_t& keyCode);
209
210 public:
211   /**
212    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNativeWindow()
213    */
214   Any GetNativeWindow() override;
215
216   /**
217    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNativeWindowId()
218    */
219   int GetNativeWindowId() override;
220
221   /**
222    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNativeWindowResourceId()
223    */
224   std::string GetNativeWindowResourceId() override;
225
226   /**
227    * @copydoc Dali::Internal::Adaptor::WindowBase::CreateEglWindow()
228    */
229   EGLNativeWindowType CreateEglWindow(int width, int height) override;
230
231   /**
232    * @copydoc Dali::Internal::Adaptor::WindowBase::DestroyEglWindow()
233    */
234   void DestroyEglWindow() override;
235
236   /**
237    * @copydoc Dali::Internal::Adaptor::WindowBase::SetEglWindowRotation()
238    */
239   void SetEglWindowRotation(int angle) override;
240
241   /**
242    * @copydoc Dali::Internal::Adaptor::WindowBase::SetEglWindowBufferTransform()
243    */
244   void SetEglWindowBufferTransform(int angle) override;
245
246   /**
247    * @copydoc Dali::Internal::Adaptor::WindowBase::SetEglWindowTransform()
248    */
249   void SetEglWindowTransform(int angle) override;
250
251   /**
252    * @copydoc Dali::Internal::Adaptor::WindowBase::ResizeEglWindow()
253    */
254   void ResizeEglWindow(PositionSize positionSize) override;
255
256   /**
257    * @copydoc Dali::Internal::Adaptor::WindowBase::IsEglWindowRotationSupported()
258    */
259   bool IsEglWindowRotationSupported() override;
260
261   /**
262    * @copydoc Dali::Internal::Adaptor::WindowBase::Move()
263    */
264   void Move(PositionSize positionSize) override;
265
266   /**
267    * @copydoc Dali::Internal::Adaptor::WindowBase::Resize()
268    */
269   void Resize(PositionSize positionSize) override;
270
271   /**
272    * @copydoc Dali::Internal::Adaptor::WindowBase::MoveResize()
273    */
274   void MoveResize(PositionSize positionSize) override;
275
276  /**
277    * @copydoc Dali::Internal::Adaptor::WindowBase::SetLayout()
278    */
279   void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan) override;
280
281   /**
282    * @copydoc Dali::Internal::Adaptor::WindowBase::SetClass()
283    */
284   void SetClass(const std::string& name, const std::string& className) override;
285
286   /**
287    * @copydoc Dali::Internal::Adaptor::WindowBase::Raise()
288    */
289   void Raise() override;
290
291   /**
292    * @copydoc Dali::Internal::Adaptor::WindowBase::Lower()
293    */
294   void Lower() override;
295
296   /**
297    * @copydoc Dali::Internal::Adaptor::WindowBase::Activate()
298    */
299   void Activate() override;
300
301   /**
302    * @copydoc Dali::Internal::Adaptor::WindowBase::Maximize()
303    */
304   void Maximize(bool maximize) override;
305
306   /**
307    * @copydoc Dali::Internal::Adaptor::WindowBase::IsMaximized()
308    */
309   bool IsMaximized() const override;
310
311   /**
312    * @copydoc Dali::Internal::Adaptor::WindowBase::SetMaximumSize()
313    */
314   void SetMaximumSize(Dali::Window::WindowSize size) override;
315
316   /**
317    * @copydoc Dali::Internal::Adaptor::WindowBase::Minimize()
318    */
319   void Minimize(bool minimize) override;
320
321   /**
322    * @copydoc Dali::Internal::Adaptor::WindowBase::IsMinimized()
323    */
324   bool IsMinimized() const override;
325
326   /**
327    * @copydoc Dali::Internal::Adaptor::WindowBase::SetMimimumSize()
328    */
329   void SetMimimumSize(Dali::Window::WindowSize size) override;
330
331   /**
332    * @copydoc Dali::Internal::Adaptor::WindowBase::SetAvailableAnlges()
333    */
334   void SetAvailableAnlges(const std::vector<int>& angles) override;
335
336   /**
337    * @copydoc Dali::Internal::Adaptor::WindowBase::SetPreferredAngle()
338    */
339   void SetPreferredAngle(int angle) override;
340
341   /**
342    * @copydoc Dali::Internal::Adaptor::WindowBase::SetAcceptFocus()
343    */
344   void SetAcceptFocus(bool accept) override;
345
346   /**
347    * @copydoc Dali::Internal::Adaptor::WindowBase::Show()
348    */
349   void Show() override;
350
351   /**
352    * @copydoc Dali::Internal::Adaptor::WindowBase::Hide()
353    */
354   void Hide() override;
355
356   /**
357    * @copydoc Dali::Internal::Adaptor::WindowBase::GetSupportedAuxiliaryHintCount()
358    */
359   unsigned int GetSupportedAuxiliaryHintCount() const override;
360
361   /**
362    * @copydoc Dali::Internal::Adaptor::WindowBase::GetSupportedAuxiliaryHint()
363    */
364   std::string GetSupportedAuxiliaryHint(unsigned int index) const override;
365
366   /**
367    * @copydoc Dali::Internal::Adaptor::WindowBase::AddAuxiliaryHint()
368    */
369   unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value) override;
370
371   /**
372    * @copydoc Dali::Internal::Adaptor::WindowBase::RemoveAuxiliaryHint()
373    */
374   bool RemoveAuxiliaryHint(unsigned int id) override;
375
376   /**
377    * @copydoc Dali::Internal::Adaptor::WindowBase::SetAuxiliaryHintValue()
378    */
379   bool SetAuxiliaryHintValue(unsigned int id, const std::string& value) override;
380
381   /**
382    * @copydoc Dali::Internal::Adaptor::WindowBase::GetAuxiliaryHintValue()
383    */
384   std::string GetAuxiliaryHintValue(unsigned int id) const override;
385
386   /**
387    * @copydoc Dali::Internal::Adaptor::WindowBase::GetAuxiliaryHintId()
388    */
389   unsigned int GetAuxiliaryHintId(const std::string& hint) const override;
390
391   /**
392    * @copydoc Dali::Internal::Adaptor::WindowBase::SetInputRegion()
393    */
394   void SetInputRegion(const Rect<int>& inputRegion) override;
395
396   /**
397    * @copydoc Dali::Internal::Adaptor::WindowBase::SetType()
398    */
399   void SetType(Dali::WindowType type) override;
400
401   /**
402    * @copydoc Dali::Internal::Adaptor::WindowBase::GetType()
403    */
404   Dali::WindowType GetType() const override;
405
406   /**
407    * @copydoc Dali::Internal::Adaptor::WindowBase::SetNotificationLevel()
408    */
409   Dali::WindowOperationResult SetNotificationLevel(Dali::WindowNotificationLevel level) override;
410
411   /**
412    * @copydoc Dali::Internal::Adaptor::WindowBase::GetNotificationLevel()
413    */
414   Dali::WindowNotificationLevel GetNotificationLevel() const override;
415
416   /**
417    * @copydoc Dali::Internal::Adaptor::WindowBase::SetOpaqueState()
418    */
419   void SetOpaqueState(bool opaque) override;
420
421   /**
422    * @copydoc Dali::Internal::Adaptor::WindowBase::SetScreenOffMode()
423    */
424   Dali::WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode) override;
425
426   /**
427    * @copydoc Dali::Internal::Adaptor::WindowBase::GetScreenOffMode()
428    */
429   WindowScreenOffMode GetScreenOffMode() const override;
430
431   /**
432    * @copydoc Dali::Internal::Adaptor::WindowBase::SetBrightness()
433    */
434   Dali::WindowOperationResult SetBrightness(int brightness) override;
435
436   /**
437    * @copydoc Dali::Internal::Adaptor::WindowBase::GetBrightness()
438    */
439   int GetBrightness() const override;
440
441   /**
442    * @copydoc Dali::Internal::Adaptor::WindowBase::GrabKey()
443    */
444   bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode) override;
445
446   /**
447    * @copydoc Dali::Internal::Adaptor::WindowBase::UngrabKey()
448    */
449   bool UngrabKey(Dali::KEY key) override;
450
451   /**
452    * @copydoc Dali::Internal::Adaptor::WindowBase::GrabKeyList()
453    */
454   bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result) override;
455
456   /**
457    * @copydoc Dali::Internal::Adaptor::WindowBase::UngrabKeyList()
458    */
459   bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result) override;
460
461   /**
462    * @copydoc Dali::Internal::Adaptor::WindowBase::GetDpi()
463    */
464   void GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical) override;
465
466   /**
467    * @copydoc Dali::Internal::Adaptor::WindowBase::GetWindowRotationAngle()
468    */
469   int GetWindowRotationAngle() const override;
470
471   /**
472    * @copydoc Dali::Internal::Adaptor::WindowBase::GetScreenRotationAngle()
473    */
474   int GetScreenRotationAngle() override;
475
476   /**
477    * @copydoc Dali::Internal::Adaptor::WindowBase::SetWindowRotationAngle()
478    */
479   void SetWindowRotationAngle(int degree) override;
480
481   /**
482    * @copydoc Dali::Internal::Adaptor::WindowBase::WindowRotationCompleted()
483    */
484   void WindowRotationCompleted(int degree, int width, int height) override;
485
486   /**
487    * @copydoc Dali::Internal::Adaptor::WindowBase::SetTransparency()
488    */
489   void SetTransparency(bool transparent) override;
490
491   /**
492    * @copydoc Dali::Internal::Adaptor::WindowBase::SetParent()
493    */
494   void SetParent(WindowBase* parentWinBase, bool belowParent) override;
495
496   /**
497    * @copydoc  Dali::Internal::Adaptor::WindowBase::CreateFrameRenderedSyncFence()
498    */
499   int CreateFrameRenderedSyncFence() override;
500
501   /**
502    * @copydoc  Dali::Internal::Adaptor::WindowBase::CreateFramePresentedSyncFence()
503    */
504   int CreateFramePresentedSyncFence() override;
505
506   /**
507    * @copydoc Dali::Internal::Adaptor::WindowBase::SetPositionSizeWithAngle()
508    */
509   void SetPositionSizeWithAngle(PositionSize positionSize, int angle) override;
510
511   /**
512    * @copydoc Dali::Internal::Adaptor::WindowBase::InitializeIme()
513    */
514   void InitializeIme() override;
515
516   /**
517    * @copydoc Dali::Internal::Adaptor::WindowBase::ImeWindowReadyToRender()
518    */
519   void ImeWindowReadyToRender() override;
520
521   /**
522    * @copydoc Dali::Internal::Adaptor::WindowBase::RequestMoveToServer()
523    */
524   void RequestMoveToServer() override;
525
526   /**
527    * @copydoc Dali::Internal::Adaptor::WindowBase::RequestResizeToServer()
528    */
529   void RequestResizeToServer(WindowResizeDirection direction) override;
530
531   /**
532    * @copydoc Dali::Internal::Adaptor::WindowBase::EnableFloatingMode()
533    */
534   void EnableFloatingMode(bool enable) override;
535
536   /**
537    * @copydoc Dali::Internal::Adaptor::WindowBase::IsFloatingModeEnabled()
538    */
539   bool IsFloatingModeEnabled() const override;
540
541   /**
542    * @copydoc Dali::Internal::Adaptor::WindowBase::IncludeInputRegion()
543    */
544   void IncludeInputRegion(const Rect<int>& inputRegion) override;
545
546   /**
547    * @copydoc Dali::Internal::Adaptor::WindowBase::ExcludeInputRegion()
548    */
549   void ExcludeInputRegion(const Rect<int>& inputRegion) override;
550
551 private:
552   /**
553    * Second stage initialization
554    */
555   void Initialize(PositionSize positionSize, Any surface, bool isTransparent);
556
557   /**
558    * @brief Create window
559    */
560   void CreateWindow(PositionSize positionSize);
561
562   /**
563    * @brief Return the window's position and size to recalulate with the default system coordinates.
564    * It is used when window is moved or resized for native ecore wayland window system.
565    *
566    * @param[in] positionSize the window's current position and size with current oriented window's coordinates.
567    * @return the re-calculated window's position and size on the default system coordinates.
568    */
569   PositionSize RecalculatePositionSizeToSystem(PositionSize positionSize);
570
571   /**
572    * @brief Return the window's position and size to recalulate with current oriented window's coordinates.
573    * It is used when window is moved or resized for dali and uppler layer framework.
574    *
575    * @param[in] positionSize the window's current position and size with the default system coordinates.
576    * @return the re-calculated window's position and size on current oriented window's coordinates.
577    */
578   PositionSize RecalculatePositionSizeToCurrentOrientation(PositionSize positionSize);
579
580 protected:
581   // Undefined
582   WindowBaseEcoreWl2(const WindowBaseEcoreWl2&) = delete;
583
584   // Undefined
585   WindowBaseEcoreWl2& operator=(const WindowBaseEcoreWl2& rhs) = delete;
586
587 private:
588   typedef std::vector<std::pair<std::string, std::string> > AuxiliaryHints;
589   Dali::Vector<Ecore_Event_Handler*>                        mEcoreEventHandler;
590   Ecore_Wl2_Window*                                         mEcoreWindow;
591
592   wl_surface* mWlSurface;
593 #ifdef OVER_TIZEN_VERSION_7
594   zwp_input_panel_v1* mWlInputPanel;
595 #else
596   wl_input_panel*         mWlInputPanel;
597 #endif
598   wl_output* mWlOutput;
599 #ifdef OVER_TIZEN_VERSION_7
600   zwp_input_panel_surface_v1* mWlInputPanelSurface;
601 #else
602   wl_input_panel_surface* mWlInputPanelSurface;
603 #endif
604
605   wl_egl_window*        mEglWindow;
606   wl_display*           mDisplay;
607   wl_event_queue*       mEventQueue;
608   tizen_policy*         mTizenPolicy;
609   tizen_display_policy* mTizenDisplayPolicy;
610   xkb_keymap*           mKeyMap;
611
612   std::vector<std::string> mSupportedAuxiliaryHints;
613
614   // It is based on the default system coordinates.
615   Dali::PositionSize mWindowPositionSize;
616
617   AuxiliaryHints mAuxiliaryHints;
618
619   WindowType mType;
620   int        mNotificationLevel;
621   int        mScreenOffMode;
622   int        mBrightness;
623   int        mWindowRotationAngle;
624   int        mScreenRotationAngle;
625   int        mSupportedPreProtation;
626
627   uint32_t          mNotificationChangeState;
628   uint32_t          mScreenOffModeChangeState;
629   uint32_t          mBrightnessChangeState;
630   uint32_t          mLastSubmittedMoveResizeSerial;
631   volatile uint32_t mMoveResizeSerial;
632
633   bool mNotificationLevelChangeDone;
634   bool mScreenOffModeChangeDone;
635   bool mVisible : 1;
636   bool mOwnSurface;
637   bool mBrightnessChangeDone;
638 };
639
640 } // namespace Adaptor
641
642 } // namespace Internal
643
644 } // namespace Dali
645
646 #endif // DALI_INTERNAL_WINDOWSYSTEM_TIZENWAYLAND_WINDOW_BASE_ECORE_WL2_H