Index: mojo/services/native_viewport/native_viewport_x11.cc |
diff --git a/mojo/services/native_viewport/native_viewport_x11.cc b/mojo/services/native_viewport/native_viewport_x11.cc |
index 50397b87d23ecabdc329254940b4e65e7a61da33..9903523525880d58a95adae67aae95044edf1517 100644 |
--- a/mojo/services/native_viewport/native_viewport_x11.cc |
+++ b/mojo/services/native_viewport/native_viewport_x11.cc |
@@ -5,10 +5,13 @@ |
#include "mojo/services/native_viewport/native_viewport.h" |
#include <X11/Xlib.h> |
+#include <X11/Xutil.h> |
#include "base/message_loop/message_loop.h" |
+#include "ui/events/event.h" |
#include "ui/events/platform/platform_event_dispatcher.h" |
#include "ui/events/platform/platform_event_source.h" |
+#include "ui/events/platform/x11/x11_event_source.h" |
#include "ui/gfx/rect.h" |
#include "ui/gfx/x/x11_types.h" |
@@ -23,7 +26,7 @@ class NativeViewportX11 : public NativeViewport, |
} |
virtual ~NativeViewportX11() { |
- ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
+ event_source_->RemovePlatformEventDispatcher(this); |
XDestroyWindow(gfx::GetXDisplay(), window_); |
} |
@@ -53,10 +56,21 @@ class NativeViewportX11 : public NativeViewport, |
atom_wm_delete_window_ = XInternAtom(display, "WM_DELETE_WINDOW", 1); |
XSetWMProtocols(display, window_, &atom_wm_delete_window_, 1); |
- event_source_.reset(ui::PlatformEventSource::GetInstance()); |
- if (!event_source_.get()) |
- event_source_ = ui::PlatformEventSource::CreateDefault(); |
- ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
+ event_source_ = ui::PlatformEventSource::CreateDefault(); |
+ event_source_->AddPlatformEventDispatcher(this); |
+ |
+ long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | |
+ KeyPressMask | KeyReleaseMask | EnterWindowMask | LeaveWindowMask | |
+ ExposureMask | VisibilityChangeMask | StructureNotifyMask | |
+ PropertyChangeMask | PointerMotionMask; |
+ XSelectInput(display, window_, event_mask); |
+ |
+ // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with |
+ // the desktop environment. |
+ XSetWMProperties(display, window_, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
+ |
+ // TODO(aa): Setup xinput2 events. |
+ // See desktop_aura/desktop_window_tree_host_x11.cc. |
delegate_->OnAcceleratedWidgetAvailable(window_); |
} |
@@ -64,6 +78,8 @@ class NativeViewportX11 : public NativeViewport, |
virtual void Show() OVERRIDE { |
XDisplay* display = gfx::GetXDisplay(); |
XMapWindow(display, window_); |
+ static_cast<ui::X11EventSource*>( |
+ event_source_.get())->BlockUntilWindowMapped(window_); |
XFlush(display); |
} |
@@ -94,14 +110,35 @@ class NativeViewportX11 : public NativeViewport, |
// ui::PlatformEventDispatcher: |
virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
- return event->type == ClientMessage && |
- event->xclient.message_type == atom_wm_protocols_; |
+ // TODO(aa): This is going to have to be thought through more carefully. |
+ // Which events are appropriate to pass to clients? |
+ switch (event->type) { |
+ case KeyPress: |
+ case KeyRelease: |
+ case ButtonPress: |
+ case ButtonRelease: |
+ case MotionNotify: |
+ return true; |
+ case ClientMessage: |
+ return event->xclient.message_type != atom_wm_protocols_; |
+ default: |
+ return false; |
+ } |
} |
virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
- Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); |
- if (protocol == atom_wm_delete_window_) |
- delegate_->OnDestroyed(); |
+ if (event->type == ClientMessage) { |
+ Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); |
+ if (protocol == atom_wm_delete_window_) |
+ delegate_->OnDestroyed(); |
+ } else if (event->type == KeyPress || event->type == KeyRelease) { |
+ ui::KeyEvent key_event(event, true); |
+ delegate_->OnEvent(&key_event); |
+ } else if (event->type == ButtonPress || event->type == ButtonRelease || |
+ event->type == MotionNotify) { |
+ ui::MouseEvent mouse_event(event); |
+ delegate_->OnEvent(&mouse_event); |
+ } |
return ui::POST_DISPATCH_NONE; |
} |