[3.0] Add native source render surface for wayland
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / x-events / x-event-manager.cpp
1 // CLASS HEADER
2 #include "x-event-manager.h"
3
4 // EXTERNAL INCLUDES
5 #include <stdio.h>
6 #include <cstring>
7 #include <dali/integration-api/debug.h>
8 #include <dali/public-api/signals/callback.h>
9
10 namespace Dali
11 {
12
13 namespace Internal
14 {
15
16 namespace Adaptor
17 {
18
19 namespace
20 {
21
22 #if defined(DEBUG_ENABLED)
23 //Dali::Integration::Log::Filter* gInputDeviceLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_X_EVENT");
24 #endif
25
26 }
27
28 XEventManager::XEventManager( XID window, Display* display, WindowEventInterface* eventInterface )
29 : mXInput2( window, display, eventInterface ),
30   mFileDescriptorMonitor( NULL ),
31   mDisplay( display ),
32   mWindow( window ),
33   mInitialized( false )
34 {
35
36 }
37 XEventManager::~XEventManager()
38 {
39   delete mFileDescriptorMonitor;
40 }
41
42 void XEventManager::Initialize()
43 {
44   if( mInitialized )
45   {
46     return;
47   }
48
49   XSelectInput( mDisplay, mWindow, StructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask );
50
51   mXInput2.Initialize();
52
53   // Start monitoring for X events on a file descriptor return via ConnectionNumber.
54   int fileDescriptor = ConnectionNumber( mDisplay );
55
56   CallbackBase* callback =  MakeCallback( this, &XEventManager::XEventReceived);
57
58   mFileDescriptorMonitor = new FileDescriptorMonitor( fileDescriptor, callback, FileDescriptorMonitor::FD_READABLE );
59
60   mInitialized = true;
61 }
62
63
64 void XEventManager::XEventReceived( FileDescriptorMonitor::EventType eventMask )
65 {
66   if( ! ( eventMask & FileDescriptorMonitor::FD_READABLE ) )
67   {
68     DALI_ASSERT_ALWAYS( 0 && "X File descriptor error");
69     return;
70   }
71
72   while( XPending( mDisplay) )
73   {
74     XEvent xEvent;
75     XNextEvent( mDisplay, &xEvent );
76
77     // cookie data pointer is undefined until XGetEventData is called.
78     XGenericEventCookie* cookie = &xEvent.xcookie;
79
80     // Tizen 2.4 TV current uses client messages for key presses instead of KeyPress type
81     if( xEvent.type == ClientMessage)
82     {
83       // Process Client Message
84       mXInput2.ProcessClientMessage( &xEvent );
85     }
86     else if( xEvent.type == KeyPress )
87     {
88       mXInput2.ProcessKeyEvent( (XKeyEvent*)&xEvent );
89     }
90     else if( xEvent.type == GenericEvent )
91     {
92       if( XGetEventData( mDisplay, cookie ) )
93       {
94         if( cookie->extension == mXInput2.GetExtensionId() )
95         {
96           mXInput2.ProcessGenericEvent( cookie );
97         }
98         XFreeEventData( mDisplay, cookie );
99       }
100     }
101   }
102 }
103
104
105 } // namespace internal
106 } // namespace adaptor
107 } // namespace dali