OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "aura/desktop_host.h" | 5 #include "aura/desktop_host.h" |
6 | 6 |
7 #include "aura/desktop.h" | 7 #include "aura/desktop.h" |
| 8 #include "aura/event.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/message_pump_x.h" | 10 #include "base/message_pump_x.h" |
10 | 11 |
11 #include <X11/Xlib.h> | 12 #include <X11/Xlib.h> |
12 | 13 |
13 namespace aura { | 14 namespace aura { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 class DesktopHostLinux : public DesktopHost { | 18 class DesktopHostLinux : public DesktopHost { |
18 public: | 19 public: |
19 explicit DesktopHostLinux(const gfx::Rect& bounds); | 20 explicit DesktopHostLinux(const gfx::Rect& bounds); |
20 virtual ~DesktopHostLinux(); | 21 virtual ~DesktopHostLinux(); |
21 | 22 |
22 private: | 23 private: |
23 // base::MessageLoop::Dispatcher Override. | 24 // base::MessageLoop::Dispatcher Override. |
24 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; | 25 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; |
25 | 26 |
26 // DesktopHost Overrides. | 27 // DesktopHost Overrides. |
27 virtual void SetDesktop(Desktop* desktop) OVERRIDE; | 28 virtual void SetDesktop(Desktop* desktop) OVERRIDE; |
28 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | 29 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; |
29 virtual void Show() OVERRIDE; | 30 virtual void Show() OVERRIDE; |
30 virtual gfx::Size GetSize() OVERRIDE; | 31 virtual gfx::Size GetSize() OVERRIDE; |
| 32 virtual void SetSize(const gfx::Size& size) OVERRIDE; |
31 | 33 |
32 Desktop* desktop_; | 34 Desktop* desktop_; |
33 | 35 |
34 // The display and the native X window hosting the desktop. | 36 // The display and the native X window hosting the desktop. |
35 Display* xdisplay_; | 37 Display* xdisplay_; |
36 ::Window xwindow_; | 38 ::Window xwindow_; |
37 | 39 |
38 // The size of |xwindow_|. | 40 // The size of |xwindow_|. |
39 gfx::Rect bounds_; | 41 gfx::Rect bounds_; |
40 | 42 |
(...skipping 20 matching lines...) Expand all Loading... |
61 XSelectInput(xdisplay_, xwindow_, event_mask); | 63 XSelectInput(xdisplay_, xwindow_, event_mask); |
62 XFlush(xdisplay_); | 64 XFlush(xdisplay_); |
63 } | 65 } |
64 | 66 |
65 DesktopHostLinux::~DesktopHostLinux() { | 67 DesktopHostLinux::~DesktopHostLinux() { |
66 XDestroyWindow(xdisplay_, xwindow_); | 68 XDestroyWindow(xdisplay_, xwindow_); |
67 } | 69 } |
68 | 70 |
69 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( | 71 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( |
70 XEvent* xev) { | 72 XEvent* xev) { |
71 // TODO(sad): Create events and dispatch to the appropriate window. | 73 bool handled = false; |
72 switch (xev->type) { | 74 switch (xev->type) { |
73 case Expose: | 75 case Expose: |
74 desktop_->Draw(); | 76 desktop_->Draw(); |
| 77 handled = true; |
75 break; | 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 } |
76 } | 92 } |
77 return EVENT_IGNORED; | 93 return handled ? EVENT_PROCESSED : EVENT_IGNORED; |
78 } | 94 } |
79 | 95 |
80 void DesktopHostLinux::SetDesktop(Desktop* desktop) { | 96 void DesktopHostLinux::SetDesktop(Desktop* desktop) { |
81 desktop_ = desktop; | 97 desktop_ = desktop; |
82 } | 98 } |
83 | 99 |
84 gfx::AcceleratedWidget DesktopHostLinux::GetAcceleratedWidget() { | 100 gfx::AcceleratedWidget DesktopHostLinux::GetAcceleratedWidget() { |
85 return xwindow_; | 101 return xwindow_; |
86 } | 102 } |
87 | 103 |
88 void DesktopHostLinux::Show() { | 104 void DesktopHostLinux::Show() { |
89 } | 105 } |
90 | 106 |
91 gfx::Size DesktopHostLinux::GetSize() { | 107 gfx::Size DesktopHostLinux::GetSize() { |
92 return bounds_.size(); | 108 return bounds_.size(); |
93 } | 109 } |
94 | 110 |
| 111 void DesktopHostLinux::SetSize(const gfx::Size& size) { |
| 112 XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); |
| 113 } |
| 114 |
95 } // namespace | 115 } // namespace |
96 | 116 |
97 // static | 117 // static |
98 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | 118 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { |
99 return new DesktopHostLinux(bounds); | 119 return new DesktopHostLinux(bounds); |
100 } | 120 } |
101 | 121 |
102 } // namespace aura | 122 } // namespace aura |
OLD | NEW |