Commit 4ba07b25 authored by aa@chromium.org's avatar aa@chromium.org

Hook up platform events in Mojo shell on Linux desktop.

Review URL: https://codereview.chromium.org/293033003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272360 0039d316-1c4b-4281-b951-d872f2087c98
parent 33963436
...@@ -25,6 +25,7 @@ class BackgroundServiceLoader::BackgroundLoader { ...@@ -25,6 +25,7 @@ class BackgroundServiceLoader::BackgroundLoader {
} }
private: private:
base::MessageLoop::Type message_loop_type_;
ServiceLoader* loader_; // Owned by BackgroundServiceLoader ServiceLoader* loader_; // Owned by BackgroundServiceLoader
DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); DISALLOW_COPY_AND_ASSIGN(BackgroundLoader);
...@@ -32,9 +33,11 @@ class BackgroundServiceLoader::BackgroundLoader { ...@@ -32,9 +33,11 @@ class BackgroundServiceLoader::BackgroundLoader {
BackgroundServiceLoader::BackgroundServiceLoader( BackgroundServiceLoader::BackgroundServiceLoader(
scoped_ptr<ServiceLoader> real_loader, scoped_ptr<ServiceLoader> real_loader,
const char* thread_name) const char* thread_name,
base::MessageLoop::Type message_loop_type)
: loader_(real_loader.Pass()), : loader_(real_loader.Pass()),
thread_(thread_name), thread_(thread_name),
message_loop_type_(message_loop_type),
background_loader_(NULL) { background_loader_(NULL) {
} }
...@@ -52,8 +55,10 @@ void BackgroundServiceLoader::LoadService( ...@@ -52,8 +55,10 @@ void BackgroundServiceLoader::LoadService(
ServiceManager* manager, ServiceManager* manager,
const GURL& url, const GURL& url,
ScopedMessagePipeHandle service_handle) { ScopedMessagePipeHandle service_handle) {
const int kDefaultStackSize = 0;
if (!thread_.IsRunning()) if (!thread_.IsRunning())
thread_.Start(); thread_.StartWithOptions(
base::Thread::Options(message_loop_type_, kDefaultStackSize));
thread_.message_loop()->PostTask( thread_.message_loop()->PostTask(
FROM_HERE, FROM_HERE,
base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread, base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ #define MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "mojo/service_manager/service_loader.h" #include "mojo/service_manager/service_loader.h"
...@@ -19,7 +20,8 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader ...@@ -19,7 +20,8 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader
: public ServiceLoader { : public ServiceLoader {
public: public:
BackgroundServiceLoader(scoped_ptr<ServiceLoader> real_loader, BackgroundServiceLoader(scoped_ptr<ServiceLoader> real_loader,
const char* thread_name); const char* thread_name,
base::MessageLoop::Type message_loop_type);
virtual ~BackgroundServiceLoader(); virtual ~BackgroundServiceLoader();
// ServiceLoader overrides: // ServiceLoader overrides:
...@@ -45,6 +47,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader ...@@ -45,6 +47,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader
scoped_ptr<ServiceLoader> loader_; scoped_ptr<ServiceLoader> loader_;
base::Thread thread_; base::Thread thread_;
base::MessageLoop::Type message_loop_type_;
// Lives on |thread_|. Trivial interface that calls through to |loader_|. // Lives on |thread_|. Trivial interface that calls through to |loader_|.
BackgroundLoader* background_loader_; BackgroundLoader* background_loader_;
......
...@@ -192,4 +192,3 @@ MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* ...@@ -192,4 +192,3 @@ MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
app->AddService<mojo::services::NativeViewportImpl>(context); app->AddService<mojo::services::NativeViewportImpl>(context);
return app; return app;
} }
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
#include "mojo/services/native_viewport/native_viewport.h" #include "mojo/services/native_viewport/native_viewport.h"
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "base/message_loop/message_loop.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_dispatcher.h"
#include "ui/events/platform/platform_event_source.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/rect.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
...@@ -23,7 +26,7 @@ class NativeViewportX11 : public NativeViewport, ...@@ -23,7 +26,7 @@ class NativeViewportX11 : public NativeViewport,
} }
virtual ~NativeViewportX11() { virtual ~NativeViewportX11() {
ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); event_source_->RemovePlatformEventDispatcher(this);
XDestroyWindow(gfx::GetXDisplay(), window_); XDestroyWindow(gfx::GetXDisplay(), window_);
} }
...@@ -53,10 +56,21 @@ class NativeViewportX11 : public NativeViewport, ...@@ -53,10 +56,21 @@ class NativeViewportX11 : public NativeViewport,
atom_wm_delete_window_ = XInternAtom(display, "WM_DELETE_WINDOW", 1); atom_wm_delete_window_ = XInternAtom(display, "WM_DELETE_WINDOW", 1);
XSetWMProtocols(display, window_, &atom_wm_delete_window_, 1); XSetWMProtocols(display, window_, &atom_wm_delete_window_, 1);
event_source_.reset(ui::PlatformEventSource::GetInstance()); event_source_ = ui::PlatformEventSource::CreateDefault();
if (!event_source_.get()) event_source_->AddPlatformEventDispatcher(this);
event_source_ = ui::PlatformEventSource::CreateDefault();
ui::PlatformEventSource::GetInstance()->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_); delegate_->OnAcceleratedWidgetAvailable(window_);
} }
...@@ -64,6 +78,8 @@ class NativeViewportX11 : public NativeViewport, ...@@ -64,6 +78,8 @@ class NativeViewportX11 : public NativeViewport,
virtual void Show() OVERRIDE { virtual void Show() OVERRIDE {
XDisplay* display = gfx::GetXDisplay(); XDisplay* display = gfx::GetXDisplay();
XMapWindow(display, window_); XMapWindow(display, window_);
static_cast<ui::X11EventSource*>(
event_source_.get())->BlockUntilWindowMapped(window_);
XFlush(display); XFlush(display);
} }
...@@ -94,14 +110,35 @@ class NativeViewportX11 : public NativeViewport, ...@@ -94,14 +110,35 @@ class NativeViewportX11 : public NativeViewport,
// ui::PlatformEventDispatcher: // ui::PlatformEventDispatcher:
virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
return event->type == ClientMessage && // TODO(aa): This is going to have to be thought through more carefully.
event->xclient.message_type == atom_wm_protocols_; // 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 { virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); if (event->type == ClientMessage) {
if (protocol == atom_wm_delete_window_) Atom protocol = static_cast<Atom>(event->xclient.data.l[0]);
delegate_->OnDestroyed(); 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; return ui::POST_DISPATCH_NONE;
} }
......
...@@ -100,7 +100,8 @@ Context::Context() ...@@ -100,7 +100,8 @@ Context::Context()
scoped_ptr<ServiceLoader>( scoped_ptr<ServiceLoader>(
new BackgroundServiceLoader( new BackgroundServiceLoader(
scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)), scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)),
"native_viewport")), "native_viewport",
base::MessageLoop::TYPE_UI)),
GURL("mojo:mojo_native_viewport_service")); GURL("mojo:mojo_native_viewport_service"));
#if defined(USE_AURA) #if defined(USE_AURA)
// TODO(sky): need a better way to find this. It shouldn't be linked in. // TODO(sky): need a better way to find this. It shouldn't be linked in.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment