| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "aura/desktop_host.h" | |
| 6 | |
| 7 #include "aura/desktop.h" | |
| 8 #include "aura/event.h" | |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/message_pump_x.h" | |
| 11 | |
| 12 #include <X11/Xlib.h> | |
| 13 | |
| 14 namespace aura { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class DesktopHostLinux : public DesktopHost { | |
| 19 public: | |
| 20 explicit DesktopHostLinux(const gfx::Rect& bounds); | |
| 21 virtual ~DesktopHostLinux(); | |
| 22 | |
| 23 private: | |
| 24 // base::MessageLoop::Dispatcher Override. | |
| 25 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; | |
| 26 | |
| 27 // DesktopHost Overrides. | |
| 28 virtual void SetDesktop(Desktop* desktop) OVERRIDE; | |
| 29 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | |
| 30 virtual void Show() OVERRIDE; | |
| 31 virtual gfx::Size GetSize() OVERRIDE; | |
| 32 virtual void SetSize(const gfx::Size& size) OVERRIDE; | |
| 33 | |
| 34 Desktop* desktop_; | |
| 35 | |
| 36 // The display and the native X window hosting the desktop. | |
| 37 Display* xdisplay_; | |
| 38 ::Window xwindow_; | |
| 39 | |
| 40 // The size of |xwindow_|. | |
| 41 gfx::Rect bounds_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(DesktopHostLinux); | |
| 44 }; | |
| 45 | |
| 46 DesktopHostLinux::DesktopHostLinux(const gfx::Rect& bounds) | |
| 47 : desktop_(NULL), | |
| 48 xdisplay_(NULL), | |
| 49 xwindow_(0), | |
| 50 bounds_(bounds) { | |
| 51 // This assumes that the message-pump creates and owns the display. | |
| 52 xdisplay_ = base::MessagePumpX::GetDefaultXDisplay(); | |
| 53 xwindow_ = XCreateSimpleWindow(xdisplay_, DefaultRootWindow(xdisplay_), | |
| 54 bounds.x(), bounds.y(), | |
| 55 bounds.width(), bounds.height(), | |
| 56 0, 0, 0); | |
| 57 XMapWindow(xdisplay_, xwindow_); | |
| 58 | |
| 59 long event_mask = ButtonPressMask | ButtonReleaseMask | | |
| 60 KeyPressMask | KeyReleaseMask | | |
| 61 ExposureMask | VisibilityChangeMask | | |
| 62 StructureNotifyMask | PropertyChangeMask; | |
| 63 XSelectInput(xdisplay_, xwindow_, event_mask); | |
| 64 XFlush(xdisplay_); | |
| 65 } | |
| 66 | |
| 67 DesktopHostLinux::~DesktopHostLinux() { | |
| 68 XDestroyWindow(xdisplay_, xwindow_); | |
| 69 } | |
| 70 | |
| 71 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( | |
| 72 XEvent* xev) { | |
| 73 bool handled = false; | |
| 74 switch (xev->type) { | |
| 75 case Expose: | |
| 76 desktop_->Draw(); | |
| 77 handled = true; | |
| 78 break; | |
| 79 case KeyPress: | |
| 80 case KeyRelease: { | |
| 81 KeyEvent keyev(xev); | |
| 82 handled = desktop_->OnKeyEvent(keyev); | |
| 83 break; | |
| 84 } | |
| 85 case ButtonPress: | |
| 86 case ButtonRelease: | |
| 87 case MotionNotify: { | |
| 88 MouseEvent mouseev(xev); | |
| 89 handled = desktop_->OnMouseEvent(mouseev); | |
| 90 break; | |
| 91 } | |
| 92 } | |
| 93 return handled ? EVENT_PROCESSED : EVENT_IGNORED; | |
| 94 } | |
| 95 | |
| 96 void DesktopHostLinux::SetDesktop(Desktop* desktop) { | |
| 97 desktop_ = desktop; | |
| 98 } | |
| 99 | |
| 100 gfx::AcceleratedWidget DesktopHostLinux::GetAcceleratedWidget() { | |
| 101 return xwindow_; | |
| 102 } | |
| 103 | |
| 104 void DesktopHostLinux::Show() { | |
| 105 } | |
| 106 | |
| 107 gfx::Size DesktopHostLinux::GetSize() { | |
| 108 return bounds_.size(); | |
| 109 } | |
| 110 | |
| 111 void DesktopHostLinux::SetSize(const gfx::Size& size) { | |
| 112 XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); | |
| 113 } | |
| 114 | |
| 115 } // namespace | |
| 116 | |
| 117 // static | |
| 118 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | |
| 119 return new DesktopHostLinux(bounds); | |
| 120 } | |
| 121 | |
| 122 } // namespace aura | |
| OLD | NEW |