diff options
-rw-r--r-- | mojo/service_manager/background_service_loader.cc | 9 | ||||
-rw-r--r-- | mojo/service_manager/background_service_loader.h | 5 | ||||
-rw-r--r-- | mojo/services/native_viewport/native_viewport_service.cc | 1 | ||||
-rw-r--r-- | mojo/services/native_viewport/native_viewport_x11.cc | 57 | ||||
-rw-r--r-- | mojo/shell/context.cc | 3 |
5 files changed, 60 insertions, 15 deletions
diff --git a/mojo/service_manager/background_service_loader.cc b/mojo/service_manager/background_service_loader.cc index e780767..16004ca 100644 --- a/mojo/service_manager/background_service_loader.cc +++ b/mojo/service_manager/background_service_loader.cc @@ -25,6 +25,7 @@ class BackgroundServiceLoader::BackgroundLoader { } private: + base::MessageLoop::Type message_loop_type_; ServiceLoader* loader_; // Owned by BackgroundServiceLoader DISALLOW_COPY_AND_ASSIGN(BackgroundLoader); @@ -32,9 +33,11 @@ class BackgroundServiceLoader::BackgroundLoader { BackgroundServiceLoader::BackgroundServiceLoader( scoped_ptr<ServiceLoader> real_loader, - const char* thread_name) + const char* thread_name, + base::MessageLoop::Type message_loop_type) : loader_(real_loader.Pass()), thread_(thread_name), + message_loop_type_(message_loop_type), background_loader_(NULL) { } @@ -52,8 +55,10 @@ void BackgroundServiceLoader::LoadService( ServiceManager* manager, const GURL& url, ScopedMessagePipeHandle service_handle) { + const int kDefaultStackSize = 0; if (!thread_.IsRunning()) - thread_.Start(); + thread_.StartWithOptions( + base::Thread::Options(message_loop_type_, kDefaultStackSize)); thread_.message_loop()->PostTask( FROM_HERE, base::Bind(&BackgroundServiceLoader::LoadServiceOnBackgroundThread, diff --git a/mojo/service_manager/background_service_loader.h b/mojo/service_manager/background_service_loader.h index bdfae0c..9b4d757 100644 --- a/mojo/service_manager/background_service_loader.h +++ b/mojo/service_manager/background_service_loader.h @@ -6,6 +6,7 @@ #define MOJO_SERVICE_MANAGER_BACKGROUND_SERVICE_LOADER_H_ #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" #include "base/threading/thread.h" #include "mojo/service_manager/service_loader.h" @@ -19,7 +20,8 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader : public ServiceLoader { public: BackgroundServiceLoader(scoped_ptr<ServiceLoader> real_loader, - const char* thread_name); + const char* thread_name, + base::MessageLoop::Type message_loop_type); virtual ~BackgroundServiceLoader(); // ServiceLoader overrides: @@ -45,6 +47,7 @@ class MOJO_SERVICE_MANAGER_EXPORT BackgroundServiceLoader scoped_ptr<ServiceLoader> loader_; base::Thread thread_; + base::MessageLoop::Type message_loop_type_; // Lives on |thread_|. Trivial interface that calls through to |loader_|. BackgroundLoader* background_loader_; diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc index 4e339bf..30e37b7 100644 --- a/mojo/services/native_viewport/native_viewport_service.cc +++ b/mojo/services/native_viewport/native_viewport_service.cc @@ -192,4 +192,3 @@ MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* app->AddService<mojo::services::NativeViewportImpl>(context); return app; } - diff --git a/mojo/services/native_viewport/native_viewport_x11.cc b/mojo/services/native_viewport/native_viewport_x11.cc index 50397b8..9903523 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; } diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc index 960fcfe..4435f4c 100644 --- a/mojo/shell/context.cc +++ b/mojo/shell/context.cc @@ -100,7 +100,8 @@ Context::Context() scoped_ptr<ServiceLoader>( new BackgroundServiceLoader( scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader(this)), - "native_viewport")), + "native_viewport", + base::MessageLoop::TYPE_UI)), GURL("mojo:mojo_native_viewport_service")); #if defined(USE_AURA) // TODO(sky): need a better way to find this. It shouldn't be linked in. |