Revert "[Tizen] Added 'make clean' on each profile build."
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / ecore-x-window-interface.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "ecore-x-window-interface.h"
20
21 // EXTERNAL INCLUDES
22 #include <X11/Xatom.h>
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25
26 #include <dali/integration-api/debug.h>
27
28 // INTERNAL INCLUDES
29 #include <ecore-x-types.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 namespace ECore
41 {
42
43 namespace WindowInterface
44 {
45 // CONSTANTS
46 const char* const CBHM_WINDOW = "CBHM_XWIN";
47
48 Ecore_X_Window GetWindow()
49 {
50   Ecore_X_Atom xAtomCbhm = ecore_x_atom_get( CBHM_WINDOW );
51
52   Ecore_X_Window xCbhmWin = 0;
53   unsigned char *buf = NULL;
54   int num = 0;
55 // XA_WINDOW is a macro with C cast
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wold-style-cast"
58   int ret = ecore_x_window_prop_property_get( 0, xAtomCbhm, XA_WINDOW, 0, &buf, &num );
59 #pragma GCC diagnostic pop
60
61   if ( ret && num )
62   {
63     memcpy( &xCbhmWin, buf, sizeof( Ecore_X_Window ) );
64   }
65   if ( buf )
66   {
67     free( buf );
68   }
69
70   return xCbhmWin;
71 }
72
73 std::string GetWindowProperty( Ecore_X_Atom property, Ecore_X_Atom *xDataType, unsigned int num  )
74 {
75    std::string data("");
76
77    if ( !property )
78    {
79       return data;
80    }
81
82    ecore_x_sync();
83
84    long unsigned int numRet = 0, bytes = 0;
85    int ret = 0, sizeRet;
86    unsigned int i;
87    unsigned char *propRet;
88    Ecore_X_Atom typeRet;
89
90    // X11 Function to get window property
91    ret = XGetWindowProperty( static_cast<Display*>(ecore_x_display_get()), // Display* X Server Connection
92                              GetWindow(),                                  // Window  window in question
93                              property,                                     // Atom  name of property
94                              num,                                          // long offset where required data is stored
95                              LONG_MAX,                                     // long length of data to retrieve
96                              False,                                        // Bool flag to delete data
97                              ecore_x_window_prop_any_type(),               // Atom atom id associated to property type
98                              reinterpret_cast< Atom * >( &typeRet ),       // Atom actual_type_return, atom id property type
99                              &sizeRet,                                     // int* format of property
100                              &numRet,                                      // unsigned long*  number of items being returned in prop_return
101                              &bytes,                                       // unsigned long* remaining bytes if partial retrieval
102                              &propRet );                                   // unsigned char** return data
103    if ( ret != Success )
104    {
105      return data;
106    }
107
108    if ( !numRet )
109    {
110       XFree( propRet );
111       return data;
112    }
113
114    numRet--; // As propRet in XGetWindowProperty gets an extra 0 added for compatibility reasons.
115
116    switch ( sizeRet ) // Format returned by XGetWindowProperty int, short, long
117    {
118    case 8:
119    {
120      for ( i = 0; i < numRet; i++ )
121      {
122        data += propRet[i];
123      }
124    }
125    break;
126
127    case 16:
128    {
129      for ( i = 0; i < numRet; i++ )
130      {
131        data += ( propRet )[i];
132      }
133    }
134    break;
135
136    case 32:
137    {
138      for ( i = 0; i < numRet; i++ )
139      {
140        data += ( propRet )[i];
141      }
142    }
143    break;
144    }
145
146    XFree( propRet );
147
148    if ( xDataType )
149    {
150      *xDataType = typeRet;
151    }
152
153    return data;
154   }
155
156 void SendXEvent(Ecore_X_Display* display, Ecore_X_Window window, bool propagate,
157     long int eventMask, Ecore_X_Atom messageType, int messageFormat, const char *msg )
158 {
159   XClientMessageEvent message;
160   memset(&message, 0, sizeof( message ) );
161   message.type = ClientMessage;
162   message.display = static_cast<Display*>( display );
163   message.message_type = messageType;
164   message.format = messageFormat;
165   message.window = window;
166   snprintf(message.data.b, 20, "%s", msg);
167
168   XSendEvent( static_cast<Display*>( display ), window, propagate, eventMask, reinterpret_cast< XEvent* >( &message ) );
169 }
170
171
172 } // namespace WindowInterface
173
174
175 } // namespace ECore
176
177 } // namespace Adaptor
178
179 } // namespace Internal
180
181 } // namespace Dali