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 "ui/aura/desktop_host.h" | 5 #include "ui/aura/desktop_host.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
11 #undef RootWindow | 11 #undef RootWindow |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/message_pump_observer.h" | |
16 #include "base/message_pump_x.h" | 17 #include "base/message_pump_x.h" |
17 #include "ui/aura/cursor.h" | 18 #include "ui/aura/cursor.h" |
18 #include "ui/aura/desktop.h" | 19 #include "ui/aura/desktop.h" |
19 #include "ui/aura/event.h" | 20 #include "ui/aura/event.h" |
20 #include "ui/base/keycodes/keyboard_codes.h" | 21 #include "ui/base/keycodes/keyboard_codes.h" |
21 #include "ui/base/touch/touch_factory.h" | 22 #include "ui/base/touch/touch_factory.h" |
22 #include "ui/base/x/x11_util.h" | 23 #include "ui/base/x/x11_util.h" |
23 #include "ui/gfx/compositor/layer.h" | 24 #include "ui/gfx/compositor/layer.h" |
24 | 25 |
25 #include <X11/cursorfont.h> | 26 #include <X11/cursorfont.h> |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 case ui::VKEY_OEM_PLUS: | 216 case ui::VKEY_OEM_PLUS: |
216 case ui::VKEY_OEM_COMMA: | 217 case ui::VKEY_OEM_COMMA: |
217 case ui::VKEY_OEM_MINUS: | 218 case ui::VKEY_OEM_MINUS: |
218 case ui::VKEY_OEM_PERIOD: | 219 case ui::VKEY_OEM_PERIOD: |
219 return true; | 220 return true; |
220 default: | 221 default: |
221 return false; | 222 return false; |
222 } | 223 } |
223 } | 224 } |
224 | 225 |
225 class DesktopHostLinux : public DesktopHost { | 226 class DesktopHostLinux : public DesktopHost, |
227 public base::MessagePumpObserver { | |
226 public: | 228 public: |
227 explicit DesktopHostLinux(const gfx::Rect& bounds); | 229 explicit DesktopHostLinux(const gfx::Rect& bounds); |
228 virtual ~DesktopHostLinux(); | 230 virtual ~DesktopHostLinux(); |
229 | 231 |
230 private: | 232 private: |
231 // base::MessageLoop::Dispatcher Override. | 233 // base::MessageLoop::Dispatcher Override. |
232 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; | 234 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; |
233 | 235 |
234 // DesktopHost Overrides. | 236 // DesktopHost Overrides. |
235 virtual void SetDesktop(Desktop* desktop) OVERRIDE; | 237 virtual void SetDesktop(Desktop* desktop) OVERRIDE; |
236 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | 238 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; |
237 virtual void Show() OVERRIDE; | 239 virtual void Show() OVERRIDE; |
238 virtual void ToggleFullScreen() OVERRIDE; | 240 virtual void ToggleFullScreen() OVERRIDE; |
239 virtual gfx::Size GetSize() const OVERRIDE; | 241 virtual gfx::Size GetSize() const OVERRIDE; |
240 virtual void SetSize(const gfx::Size& size) OVERRIDE; | 242 virtual void SetSize(const gfx::Size& size) OVERRIDE; |
241 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; | 243 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; |
242 virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; | 244 virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; |
243 virtual gfx::Point QueryMouseLocation() OVERRIDE; | 245 virtual gfx::Point QueryMouseLocation() OVERRIDE; |
244 virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; | 246 virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; |
245 | 247 |
248 // base::MessagePumpObserver Overrides. | |
249 virtual base::EventStatus WillProcessEvent( | |
250 const base::NativeEvent& event) OVERRIDE; | |
251 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | |
252 virtual void DestroyMessagePump() OVERRIDE; | |
253 | |
246 // Returns true if there's an X window manager present... in most cases. Some | 254 // Returns true if there's an X window manager present... in most cases. Some |
247 // window managers (notably, ion3) don't implement enough of ICCCM for us to | 255 // window managers (notably, ion3) don't implement enough of ICCCM for us to |
248 // detect that they're there. | 256 // detect that they're there. |
249 bool IsWindowManagerPresent(); | 257 bool IsWindowManagerPresent(); |
250 | 258 |
251 Desktop* desktop_; | 259 Desktop* desktop_; |
252 | 260 |
253 // The display and the native X window hosting the desktop. | 261 // The display and the native X window hosting the desktop. |
254 Display* xdisplay_; | 262 Display* xdisplay_; |
255 ::Window xwindow_; | 263 ::Window xwindow_; |
(...skipping 24 matching lines...) Expand all Loading... | |
280 StructureNotifyMask | PropertyChangeMask | | 288 StructureNotifyMask | PropertyChangeMask | |
281 PointerMotionMask; | 289 PointerMotionMask; |
282 XSelectInput(xdisplay_, xwindow_, event_mask); | 290 XSelectInput(xdisplay_, xwindow_, event_mask); |
283 XFlush(xdisplay_); | 291 XFlush(xdisplay_); |
284 | 292 |
285 // TODO(sadrul): reenable once 103981 is fixed. | 293 // TODO(sadrul): reenable once 103981 is fixed. |
286 #if defined(TOUCH_UI) | 294 #if defined(TOUCH_UI) |
287 if (base::MessagePumpForUI::HasXInput2()) | 295 if (base::MessagePumpForUI::HasXInput2()) |
288 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); | 296 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); |
289 #endif | 297 #endif |
298 | |
299 base::MessagePumpX::SetDefaultDispatcher(this); | |
300 MessageLoopForUI::current()->AddObserver(this); | |
290 } | 301 } |
291 | 302 |
292 DesktopHostLinux::~DesktopHostLinux() { | 303 DesktopHostLinux::~DesktopHostLinux() { |
293 XDestroyWindow(xdisplay_, xwindow_); | 304 XDestroyWindow(xdisplay_, xwindow_); |
294 | 305 |
295 // Clears XCursorCache. | 306 // Clears XCursorCache. |
296 ui::GetXCursor(ui::kCursorClearXCursorCache); | 307 ui::GetXCursor(ui::kCursorClearXCursorCache); |
308 | |
309 base::MessagePumpX::SetDefaultDispatcher(NULL); | |
310 if (MessageLoop::current()) | |
311 MessageLoopForUI::current()->RemoveObserver(this); | |
oshima
2011/11/30 00:04:16
nit: it may be better to put them in reverse order
sadrul
2011/11/30 13:54:58
Done.
| |
297 } | 312 } |
298 | 313 |
299 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( | 314 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( |
300 XEvent* xev) { | 315 XEvent* xev) { |
301 bool handled = false; | 316 bool handled = false; |
302 switch (xev->type) { | 317 switch (xev->type) { |
303 case Expose: | 318 case Expose: |
304 desktop_->Draw(); | 319 desktop_->Draw(); |
305 handled = true; | 320 handled = true; |
306 break; | 321 break; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 desktop_->ConvertPointToNativeScreen(&point); | 528 desktop_->ConvertPointToNativeScreen(&point); |
514 xevent.xmotion.x_root = point.x(); | 529 xevent.xmotion.x_root = point.x(); |
515 xevent.xmotion.y_root = point.y(); | 530 xevent.xmotion.y_root = point.y(); |
516 } | 531 } |
517 default: | 532 default: |
518 break; | 533 break; |
519 } | 534 } |
520 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 535 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
521 } | 536 } |
522 | 537 |
538 base::EventStatus DesktopHostLinux::WillProcessEvent( | |
539 const base::NativeEvent& event) { | |
540 return base::EVENT_CONTINUE; | |
541 } | |
542 | |
543 void DesktopHostLinux::DidProcessEvent(const base::NativeEvent& event) { | |
544 } | |
545 | |
546 void DesktopHostLinux::DestroyMessagePump() { | |
547 desktop_->DeleteInstance(); | |
548 } | |
549 | |
523 bool DesktopHostLinux::IsWindowManagerPresent() { | 550 bool DesktopHostLinux::IsWindowManagerPresent() { |
524 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 551 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
525 // of WM_Sn selections (where n is a screen number). | 552 // of WM_Sn selections (where n is a screen number). |
526 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); | 553 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); |
527 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; | 554 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; |
528 } | 555 } |
529 | 556 |
530 } // namespace | 557 } // namespace |
531 | 558 |
532 // static | 559 // static |
533 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | 560 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { |
534 return new DesktopHostLinux(bounds); | 561 return new DesktopHostLinux(bounds); |
535 } | 562 } |
536 | 563 |
537 // static | 564 // static |
538 gfx::Size DesktopHost::GetNativeDisplaySize() { | 565 gfx::Size DesktopHost::GetNativeDisplaySize() { |
539 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 566 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
540 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 567 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
541 } | 568 } |
542 | 569 |
543 } // namespace aura | 570 } // namespace aura |
OLD | NEW |