Added X11 window manager resize handling
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / x11 / window-system-x.h
1 #ifndef DALI_INTERNAL_WINDOW_SYSTEM_X11_WINDOW_SYSTEM_H
2 #define DALI_INTERNAL_WINDOW_SYSTEM_X11_WINDOW_SYSTEM_H
3
4 /*
5  * COPYRIGHT (c) 2023 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 #include <X11/Xlib.h>
21 #include <dali/internal/window-system/common/window-system.h>
22 #include <climits>
23 #include <cstdint>
24 #include <string>
25 #include <vector>
26
27 namespace Dali::Internal::Adaptor::WindowSystem
28 {
29 /**
30  * Class to encapsulate the actual window system calls to X11
31  */
32 class WindowSystemX : public WindowSystemBase
33 {
34 public:
35   static Atom ATOM_WM_PROTOCOLS;
36   static Atom ATOM_WM_DELETE_WINDOW;
37   static Atom ATOM_WM_STATE;
38   static Atom ATOM_WM_TRANSIENT_FOR;
39   static Atom ATOM_NET_ACTIVE_WINDOW;
40   static Atom ATOM_NET_STARTUP_ID;
41   static Atom ATOM_NET_WM_PID;
42   static Atom ATOM_NET_WM_WINDOW_TYPE;
43   static Atom ATOM_NET_WM_WINDOW_TYPE_NORMAL;
44   static Atom ATOM_NET_WM_NAME;
45   static Atom ATOM_UTF8_STRING;
46
47   enum class WindowState
48   {
49     WITHDRAWN,
50     NORMAL,
51     ICONIC
52   };
53
54 public:
55   /**
56    * constructor
57    */
58   WindowSystemX();
59
60   /**
61    * destructor
62    */
63   virtual ~WindowSystemX();
64
65   /**
66    * Get the screen size
67    */
68   void GetScreenSize(int& width, int& height) override;
69
70   /**
71    * Get the connected display
72    */
73   Dali::Any GetDisplay() override;
74
75   /**
76    * Get the display for this specific implementation
77    */
78   ::Display* GetXDisplay();
79
80   /**
81    * Synchronize with the display server if needed
82    */
83   void Sync();
84
85   /**
86    * Struct that describes a generic X11 event
87    */
88   struct X11Event : public EventBase
89   {
90     ::Window      window;
91     const XEvent* event;
92   };
93
94   /**
95    * Event struct that is sent when a window is moved/resized/lowered/raised
96    */
97   struct X11ConfigureNotifyEvent : public X11Event
98   {
99     int      x; // Relative to parent window's origin.
100     int      y;
101     int      width;
102     int      height;
103     ::Window above; // The window that this is now above.
104   };
105
106   /**
107    * Event struct that is sent when a window property is changed.
108    */
109   struct X11PropertyNotifyEvent : public X11Event
110   {
111     unsigned long timestamp;
112     Atom          atom;
113     int           state;
114   };
115
116   /**
117    * Event struct that is sent when the window needs to be redrawn
118    */
119   struct X11ExposeEvent : public X11Event
120   {
121     int x;
122     int y;
123     int width;
124     int height;
125   };
126
127   /**
128    * Event struct that is sent when mouse movement/button press occurs
129    */
130   struct X11MouseEvent : public X11Event
131   {
132     unsigned long timestamp; ///< time in milliseconds
133     int           x;
134     int           y;
135     int           buttons;
136     int           device;
137
138     struct Multi
139     {
140       float pressure;
141       float angle;
142       int   radius;
143       int   radiusX;
144       int   radiusY;
145     } multi;
146   };
147
148   /**
149    * Event struct that is sent when the mouse wheel is scrolled or pressed
150    */
151   struct X11MouseWheelEvent : public X11Event
152   {
153     unsigned long timestamp; ///< time in milliseconds
154     int           direction;
155     int           x;
156     int           y;
157     int           z;
158     unsigned int  modifiers;
159   };
160
161   /**
162    * Event struct that is sent when a keypress or keyrelease occurs
163    */
164   struct X11KeyEvent : public X11Event
165   {
166     unsigned long timestamp; ///< time in milliseconds
167     std::string   compose;
168     std::string   keyname;
169     std::string   key;
170     int           keyCode;
171     unsigned int  modifiers;
172   };
173
174   /**
175    * Event struct that is sent when a selection is cleared
176    */
177   struct X11SelectionClearEvent : public X11Event
178   {
179     enum class SelectionType
180     {
181       PRIMARY,
182       SECONDARY,
183       XDND,
184       CLIPBOARD,
185       OTHER
186     } selection;
187   };
188
189   /**
190    * @copydoc WindowSystemBase::AddEventHandler()
191    */
192   EventHandler* AddEventHandler(WindowSystemBase::Event                event,
193                                 WindowSystemBase::EventHandlerCallback callback,
194                                 void*                                  data) override;
195   /**
196    * @copydoc WindowSystemBase::DeleteEventHandler()
197    */
198   void DeleteEventHandler(EventHandler* eventHandler) override;
199
200   /**
201    * Create a window
202    * @param depth The color depth (24/32)
203    * @param x Horizontal position of the window
204    * @param y Vertical position of the window
205    * @param width Width of the new window
206    * @param height Height of the new window
207    * @return An X11 handle to the new window
208    */
209   ::Window CreateWindow(int depth, int x, int y, int width, int height);
210
211   /**
212    * Set window default parameters (client machine name, PID and window type)
213    * @param window The window to set the default parameters for
214    */
215   void SetWindowDefaults(::Window window);
216
217   /**
218    * Tells the window manager if the window is transient (e.g. a dialog) for another window
219    * @param window The window to set the hints on
220    * @param forWindow The window that this is transient for
221    */
222   void SetTransientForHint(::Window window, ::Window forWindow);
223
224   /**
225    * Removes the WM hint that the window is transient for another
226    * @param window The window to remove the hints on
227    */
228   void UnsetTransientFor(::Window window);
229
230   /**
231    * Set/clear the given Window manager protocol on the given window
232    * @param window The window to modify
233    * @param protocol The protocol to add/modify/remove
234    * @param value True if the protocol should be added, false if it should be removed
235    */
236   void SetProtocol(::Window window, Atom protocol, bool value);
237
238   /**
239    * Add a hint to the window that it accepts focus
240    * @param window The window to modify
241    * @param acceptsFocus True if the window should accept focus, or false if not
242    */
243   void SetWindowHints(::Window window, bool acceptsFocus);
244
245   /**
246    * Get the window's current state
247    * @param window The window to check
248    * @return The window state (withdrawn, normal or iconic)
249    */
250   WindowState GetWindowState(::Window window);
251
252   /**
253    * Show the window
254    * @param window The window to show
255    */
256   void Show(::Window window);
257
258   /**
259    * Hide the window
260    * @param window The window to hide
261    */
262   void Hide(::Window window);
263
264   /**
265    * Activate the window
266    * @param window The window to activate
267    */
268   void Activate(::Window window);
269
270   /**
271    * Raise the window to the top
272    * @param window The window to raise
273    */
274   void Raise(::Window window);
275
276   /**
277    * Lower the window to the bottom
278    * @param window The window to lower
279    */
280   void Lower(::Window window);
281
282   /**
283    * Enables the X window event handlers to trigger listeners
284    * @param eventType The window event type
285    * @param event The window event
286    */
287   void TriggerEventHandler(WindowSystemBase::Event eventType, X11Event& event);
288
289   /**
290    * Get the DPI of the screen
291    * @param dpiHorizontal
292    * @param dpiVertical
293    */
294   void GetDPI(unsigned int& dpiHorizontal, unsigned int& dpiVertical);
295
296   /**
297    * Move the window to the new screen coordinates
298    * @param window The window to move
299    * @param x The horizontal position
300    * @param y The vertical position
301    */
302   void Move(::Window window, int x, int y);
303
304   /**
305    * Resize the window to the given width and height
306    * @param window The window to resize
307    * @param width The new window width
308    * @param height  The new window height
309    */
310   void Resize(::Window window, int width, int height);
311
312   /**
313    * Move and resize the window in one operation
314    * @param window The window to resize and move
315    * @param x The horizontal position
316    * @param y The vertical position
317    * @param width The new window width
318    * @param height The new window height
319    */
320   void MoveResize(::Window window, int x, int y, int width, int height);
321
322   /**
323    * Set the value of a string property
324    * @param window The window to set the property on
325    * @param atom The property to modify
326    * @param string The new string to set on the property
327    */
328   void SetStringProperty(::Window window, Atom atom, const std::string& string);
329
330   /**
331    * Set the class of the window
332    * @param window The window to modify
333    * @param name The name (title) of the window
334    * @param className The class of the window
335    */
336   void SetClass(::Window window, const std::string& name, const std::string& className);
337
338   /**
339    * Initialize multiselection input on the window
340    * @Note NOT IMPLEMENTED
341    * @param window The window to initialize
342    */
343   void InputMultiSelect(::Window window);
344
345   /**
346    * Initialize drag and drop on the window
347    * @Note NOT IMPLEMENTED
348    * @param window The window to initialize
349    * @param enable True if drag and drop should be enabled, false otherwise
350    */
351   void EnableDragAndDrop(::Window window, bool enable);
352
353 private:
354   struct Impl;
355   Impl* mImpl;
356 };
357
358 /**
359  * Get the platform implementation of the window system
360  * @return the platform implementation of the window system
361  */
362 WindowSystemX& GetImplementation();
363
364 } // namespace Dali::Internal::Adaptor::WindowSystem
365
366 #endif // DALI_INTERNAL_WINDOW_SYSTEM_X11_WINDOW_SYSTEM_H