Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / events / platform / x11 / x11_event_source.cc
index e074bc8..9268c42 100644 (file)
 #include <X11/XKBlib.h>
 
 #include "base/logging.h"
+#include "ui/events/devices/x11/device_data_manager_x11.h"
 #include "ui/events/event_utils.h"
 #include "ui/events/platform/platform_event_dispatcher.h"
+#include "ui/events/platform/x11/x11_hotplug_event_handler.h"
 #include "ui/gfx/x/x11_types.h"
 
 namespace ui {
@@ -80,10 +82,17 @@ bool InitializeXkb(XDisplay* display) {
 }  // namespace
 
 X11EventSource::X11EventSource(XDisplay* display)
-    : display_(display) {
+    : display_(display),
+      continue_stream_(true) {
   CHECK(display_);
+  DeviceDataManagerX11::CreateInstance();
+  hotplug_event_handler_.reset(
+      new X11HotplugEventHandler(DeviceDataManager::GetInstance()));
   InitializeXInput2(display_);
   InitializeXkb(display_);
+
+  // Force the initial device query to have an update list of active devices.
+  hotplug_event_handler_->OnHotplugEvent();
 }
 
 X11EventSource::~X11EventSource() {
@@ -102,12 +111,11 @@ void X11EventSource::DispatchXEvents() {
   // Handle all pending events.
   // It may be useful to eventually align this event dispatch with vsync, but
   // not yet.
-  while (XPending(display_)) {
+  continue_stream_ = true;
+  while (XPending(display_) && continue_stream_) {
     XEvent xevent;
     XNextEvent(display_, &xevent);
-    uint32_t action = DispatchEvent(&xevent);
-    if (action & POST_DISPATCH_QUIT_LOOP)
-      break;
+    DispatchEvent(&xevent);
   }
 }
 
@@ -135,6 +143,7 @@ uint32_t X11EventSource::DispatchEvent(XEvent* xevent) {
   if (xevent->type == GenericEvent &&
       xevent->xgeneric.evtype == XI_HierarchyChanged) {
     ui::UpdateDeviceList();
+    hotplug_event_handler_->OnHotplugEvent();
   }
 
   if (have_cookie)
@@ -142,4 +151,8 @@ uint32_t X11EventSource::DispatchEvent(XEvent* xevent) {
   return action;
 }
 
+void X11EventSource::StopCurrentEventStream() {
+  continue_stream_ = false;
+}
+
 }  // namespace ui