2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "ecore-x-window-interface.h"
22 #include <X11/Xatom.h>
24 #include <X11/Xutil.h>
26 #include <dali/integration-api/debug.h>
29 #include <ecore-x-types.h>
43 namespace WindowInterface
46 const char* const CBHM_WINDOW = "CBHM_XWIN";
48 Ecore_X_Window GetWindow()
50 Ecore_X_Atom xAtomCbhm = ecore_x_atom_get( CBHM_WINDOW );
52 Ecore_X_Window xCbhmWin = 0;
53 unsigned char *buf = NULL;
55 int ret = ecore_x_window_prop_property_get( 0, xAtomCbhm, XA_WINDOW, 0, &buf, &num );
59 memcpy( &xCbhmWin, buf, sizeof( Ecore_X_Window ) );
69 std::string GetWindowProperty( Ecore_X_Atom property, Ecore_X_Atom *xDataType, unsigned int num )
80 long unsigned int numRet = 0, bytes = 0;
83 unsigned char *propRet;
86 // X11 Function to get window property
87 ret = XGetWindowProperty( static_cast<Display*>(ecore_x_display_get()), // Display* X Server Connection
88 GetWindow(), // Window window in question
89 property, // Atom name of property
90 num, // long offset where required data is stored
91 LONG_MAX, // long length of data to retrieve
92 False, // Bool flag to delete data
93 ecore_x_window_prop_any_type(), // Atom atom id associated to property type
94 (Atom *)&typeRet, // Atom actual_type_return, atom id property type
95 &sizeRet, // int* format of property
96 &numRet, // unsigned long* number of items being returned in prop_return
97 &bytes, // unsigned long* remaining bytes if partial retrieval
98 &propRet ); // unsigned char** return data
110 numRet--; // As propRet in XGetWindowProperty gets an extra 0 added for compatibility reasons.
112 switch ( sizeRet ) // Format returned by XGetWindowProperty int, short, long
116 for ( i = 0; i < numRet; i++ )
125 for ( i = 0; i < numRet; i++ )
127 data += ( ( unsigned short * )propRet )[i];
134 for ( i = 0; i < numRet; i++ )
136 data += ( ( unsigned long * )propRet )[i];
146 *xDataType = typeRet;
152 void SendXEvent(Ecore_X_Display* display, Ecore_X_Window window, bool propagate,
153 long int eventMask, Ecore_X_Atom messageType, int messageFormat, const char *msg )
155 XClientMessageEvent message;
156 memset(&message, 0, sizeof( message ) );
157 message.type = ClientMessage;
158 message.display = static_cast<Display*>( display );
159 message.message_type = messageType;
160 message.format = messageFormat;
161 message.window = window;
162 snprintf(message.data.b, 20, "%s", msg);
164 XSendEvent( static_cast<Display*>( display ), window, propagate, eventMask,( XEvent* )&message );
168 } // namespace WindowInterface
173 } // namespace Adaptor
175 } // namespace Internal