| 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. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 case ui::VKEY_OEM_PLUS: | 215 case ui::VKEY_OEM_PLUS: |
| 216 case ui::VKEY_OEM_COMMA: | 216 case ui::VKEY_OEM_COMMA: |
| 217 case ui::VKEY_OEM_MINUS: | 217 case ui::VKEY_OEM_MINUS: |
| 218 case ui::VKEY_OEM_PERIOD: | 218 case ui::VKEY_OEM_PERIOD: |
| 219 return true; | 219 return true; |
| 220 default: | 220 default: |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 class DesktopHostLinux : public DesktopHost { | 225 class DesktopHostLinux : public DesktopHost, |
| 226 public MessageLoop::DestructionObserver { |
| 226 public: | 227 public: |
| 227 explicit DesktopHostLinux(const gfx::Rect& bounds); | 228 explicit DesktopHostLinux(const gfx::Rect& bounds); |
| 228 virtual ~DesktopHostLinux(); | 229 virtual ~DesktopHostLinux(); |
| 229 | 230 |
| 230 private: | 231 private: |
| 231 // base::MessageLoop::Dispatcher Override. | 232 // MessageLoop::Dispatcher Override. |
| 232 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; | 233 virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE; |
| 233 | 234 |
| 234 // DesktopHost Overrides. | 235 // DesktopHost Overrides. |
| 235 virtual void SetDesktop(Desktop* desktop) OVERRIDE; | 236 virtual void SetDesktop(Desktop* desktop) OVERRIDE; |
| 236 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | 237 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; |
| 237 virtual void Show() OVERRIDE; | 238 virtual void Show() OVERRIDE; |
| 238 virtual void ToggleFullScreen() OVERRIDE; | 239 virtual void ToggleFullScreen() OVERRIDE; |
| 239 virtual gfx::Size GetSize() const OVERRIDE; | 240 virtual gfx::Size GetSize() const OVERRIDE; |
| 240 virtual void SetSize(const gfx::Size& size) OVERRIDE; | 241 virtual void SetSize(const gfx::Size& size) OVERRIDE; |
| 241 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; | 242 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; |
| 242 virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; | 243 virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; |
| 243 virtual gfx::Point QueryMouseLocation() OVERRIDE; | 244 virtual gfx::Point QueryMouseLocation() OVERRIDE; |
| 244 virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; | 245 virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; |
| 245 | 246 |
| 247 // MessageLoop::DestructionObserver Overrides. |
| 248 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 249 |
| 246 // Returns true if there's an X window manager present... in most cases. Some | 250 // 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 | 251 // window managers (notably, ion3) don't implement enough of ICCCM for us to |
| 248 // detect that they're there. | 252 // detect that they're there. |
| 249 bool IsWindowManagerPresent(); | 253 bool IsWindowManagerPresent(); |
| 250 | 254 |
| 251 Desktop* desktop_; | 255 Desktop* desktop_; |
| 252 | 256 |
| 253 // The display and the native X window hosting the desktop. | 257 // The display and the native X window hosting the desktop. |
| 254 Display* xdisplay_; | 258 Display* xdisplay_; |
| 255 ::Window xwindow_; | 259 ::Window xwindow_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 285 PointerMotionMask; | 289 PointerMotionMask; |
| 286 XSelectInput(xdisplay_, xwindow_, event_mask); | 290 XSelectInput(xdisplay_, xwindow_, event_mask); |
| 287 XSelectInput(xdisplay_, root_window_, StructureNotifyMask); | 291 XSelectInput(xdisplay_, root_window_, StructureNotifyMask); |
| 288 XFlush(xdisplay_); | 292 XFlush(xdisplay_); |
| 289 | 293 |
| 290 // TODO(sadrul): reenable once 103981 is fixed. | 294 // TODO(sadrul): reenable once 103981 is fixed. |
| 291 #if defined(TOUCH_UI) | 295 #if defined(TOUCH_UI) |
| 292 if (base::MessagePumpForUI::HasXInput2()) | 296 if (base::MessagePumpForUI::HasXInput2()) |
| 293 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); | 297 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); |
| 294 #endif | 298 #endif |
| 299 |
| 300 base::MessagePumpX::SetDefaultDispatcher(this); |
| 301 MessageLoopForUI::current()->AddDestructionObserver(this); |
| 295 } | 302 } |
| 296 | 303 |
| 297 DesktopHostLinux::~DesktopHostLinux() { | 304 DesktopHostLinux::~DesktopHostLinux() { |
| 298 XDestroyWindow(xdisplay_, xwindow_); | 305 XDestroyWindow(xdisplay_, xwindow_); |
| 299 | 306 |
| 300 // Clears XCursorCache. | 307 // Clears XCursorCache. |
| 301 ui::GetXCursor(ui::kCursorClearXCursorCache); | 308 ui::GetXCursor(ui::kCursorClearXCursorCache); |
| 309 |
| 310 MessageLoopForUI::current()->RemoveDestructionObserver(this); |
| 311 base::MessagePumpX::SetDefaultDispatcher(NULL); |
| 302 } | 312 } |
| 303 | 313 |
| 304 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( | 314 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( |
| 305 XEvent* xev) { | 315 XEvent* xev) { |
| 306 DLOG(WARNING) << "DispatchEvent:" << xev->type; | 316 DLOG(WARNING) << "DispatchEvent:" << xev->type; |
| 307 | 317 |
| 308 bool handled = false; | 318 bool handled = false; |
| 309 switch (xev->type) { | 319 switch (xev->type) { |
| 310 case Expose: | 320 case Expose: |
| 311 desktop_->Draw(); | 321 desktop_->Draw(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 xevent.xmotion.x_root = point.x(); | 537 xevent.xmotion.x_root = point.x(); |
| 528 xevent.xmotion.y_root = point.y(); | 538 xevent.xmotion.y_root = point.y(); |
| 529 } | 539 } |
| 530 default: | 540 default: |
| 531 break; | 541 break; |
| 532 } | 542 } |
| 533 Status status = XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 543 Status status = XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
| 534 DLOG(WARNING) << "PostEvent:" << xevent.type << ", status=" << status; | 544 DLOG(WARNING) << "PostEvent:" << xevent.type << ", status=" << status; |
| 535 } | 545 } |
| 536 | 546 |
| 547 void DesktopHostLinux::WillDestroyCurrentMessageLoop() { |
| 548 desktop_->DeleteInstance(); |
| 549 } |
| 550 |
| 537 bool DesktopHostLinux::IsWindowManagerPresent() { | 551 bool DesktopHostLinux::IsWindowManagerPresent() { |
| 538 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 552 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
| 539 // of WM_Sn selections (where n is a screen number). | 553 // of WM_Sn selections (where n is a screen number). |
| 540 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); | 554 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); |
| 541 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; | 555 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; |
| 542 } | 556 } |
| 543 | 557 |
| 544 } // namespace | 558 } // namespace |
| 545 | 559 |
| 546 // static | 560 // static |
| 547 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | 561 DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { |
| 548 return new DesktopHostLinux(bounds); | 562 return new DesktopHostLinux(bounds); |
| 549 } | 563 } |
| 550 | 564 |
| 551 // static | 565 // static |
| 552 gfx::Size DesktopHost::GetNativeScreenSize() { | 566 gfx::Size DesktopHost::GetNativeScreenSize() { |
| 553 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 567 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
| 554 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 568 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 555 } | 569 } |
| 556 | 570 |
| 557 } // namespace aura | 571 } // namespace aura |
| OLD | NEW |