OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/root_window_host_linux.h" | 5 #include "ui/aura/root_window_host_linux.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/Xcursor/Xcursor.h> | 8 #include <X11/Xcursor/Xcursor.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/cursorfont.h> | 10 #include <X11/cursorfont.h> |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 DISALLOW_COPY_AND_ASSIGN(ImageCursors); | 466 DISALLOW_COPY_AND_ASSIGN(ImageCursors); |
467 }; | 467 }; |
468 | 468 |
469 RootWindowHostLinux::RootWindowHostLinux(RootWindowHostDelegate* delegate, | 469 RootWindowHostLinux::RootWindowHostLinux(RootWindowHostDelegate* delegate, |
470 const gfx::Rect& bounds) | 470 const gfx::Rect& bounds) |
471 : delegate_(delegate), | 471 : delegate_(delegate), |
472 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), | 472 xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
473 xwindow_(0), | 473 xwindow_(0), |
474 x_root_window_(DefaultRootWindow(xdisplay_)), | 474 x_root_window_(DefaultRootWindow(xdisplay_)), |
475 current_cursor_(ui::kCursorNull), | 475 current_cursor_(ui::kCursorNull), |
476 window_mapped_(false), | |
476 cursor_shown_(true), | 477 cursor_shown_(true), |
477 bounds_(bounds), | 478 bounds_(bounds), |
478 focus_when_shown_(false), | 479 focus_when_shown_(false), |
479 pointer_barriers_(NULL), | 480 pointer_barriers_(NULL), |
480 image_cursors_(new ImageCursors), | 481 image_cursors_(new ImageCursors), |
481 atom_cache_(xdisplay_, kAtomsToCache) { | 482 atom_cache_(xdisplay_, kAtomsToCache) { |
482 XSetWindowAttributes swa; | 483 XSetWindowAttributes swa; |
483 memset(&swa, 0, sizeof(swa)); | 484 memset(&swa, 0, sizeof(swa)); |
484 swa.background_pixmap = None; | 485 swa.background_pixmap = None; |
485 xwindow_ = XCreateWindow( | 486 xwindow_ = XCreateWindow( |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 break; | 613 break; |
613 case ConfigureNotify: { | 614 case ConfigureNotify: { |
614 DCHECK_EQ(xwindow_, xev->xconfigure.window); | 615 DCHECK_EQ(xwindow_, xev->xconfigure.window); |
615 DCHECK_EQ(xwindow_, xev->xconfigure.event); | 616 DCHECK_EQ(xwindow_, xev->xconfigure.event); |
616 // It's possible that the X window may be resized by some other means than | 617 // It's possible that the X window may be resized by some other means than |
617 // from within aura (e.g. the X window manager can change the size). Make | 618 // from within aura (e.g. the X window manager can change the size). Make |
618 // sure the root window size is maintained properly. | 619 // sure the root window size is maintained properly. |
619 gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y, | 620 gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y, |
620 xev->xconfigure.width, xev->xconfigure.height); | 621 xev->xconfigure.width, xev->xconfigure.height); |
621 bool size_changed = bounds_.size() != bounds.size(); | 622 bool size_changed = bounds_.size() != bounds.size(); |
623 bool origin_changed = bounds_.origin() != bounds.origin(); | |
622 bounds_ = bounds; | 624 bounds_ = bounds; |
623 // Update barrier and mouse location when the root window has | 625 // Update barrier and mouse location when the root window has |
624 // moved/resized. | 626 // moved/resized. |
625 if (pointer_barriers_.get()) { | 627 if (pointer_barriers_.get()) { |
626 UnConfineCursor(); | 628 UnConfineCursor(); |
627 gfx::Point p = gfx::Screen::GetCursorScreenPoint(); | 629 gfx::Point p = gfx::Screen::GetCursorScreenPoint(); |
628 XWarpPointer(xdisplay_, None, xwindow_, 0, 0, 0, 0, p.x(), p.y()); | 630 XWarpPointer(xdisplay_, None, xwindow_, 0, 0, 0, 0, p.x(), p.y()); |
629 ConfineCursorToRootWindow(); | 631 ConfineCursorToRootWindow(); |
630 } | 632 } |
631 if (size_changed) | 633 if (size_changed) |
632 delegate_->OnHostResized(bounds.size()); | 634 delegate_->OnHostResized(bounds.size()); |
635 if (origin_changed) | |
636 delegate_->OnHostMoved(bounds_.origin()); | |
633 break; | 637 break; |
634 } | 638 } |
635 case GenericEvent: { | 639 case GenericEvent: { |
636 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 640 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
637 if (!factory->ShouldProcessXI2Event(xev)) | 641 if (!factory->ShouldProcessXI2Event(xev)) |
638 break; | 642 break; |
639 | 643 |
640 ui::EventType type = ui::EventTypeFromNative(xev); | 644 ui::EventType type = ui::EventTypeFromNative(xev); |
641 XEvent last_event; | 645 XEvent last_event; |
642 int num_coalesced = 0; | 646 int num_coalesced = 0; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 } | 778 } |
775 | 779 |
776 gfx::AcceleratedWidget RootWindowHostLinux::GetAcceleratedWidget() { | 780 gfx::AcceleratedWidget RootWindowHostLinux::GetAcceleratedWidget() { |
777 return xwindow_; | 781 return xwindow_; |
778 } | 782 } |
779 | 783 |
780 void RootWindowHostLinux::Show() { | 784 void RootWindowHostLinux::Show() { |
781 // The device scale factor is now accessible, so load cursors now. | 785 // The device scale factor is now accessible, so load cursors now. |
782 image_cursors_->Reload(delegate_->GetDeviceScaleFactor()); | 786 image_cursors_->Reload(delegate_->GetDeviceScaleFactor()); |
783 | 787 |
784 // Before we map the window, set size hints. Otherwise, some window managers | 788 if (!window_mapped_) { |
785 // will ignore toplevel XMoveWindow commands. | 789 // Before we map the window, set size hints. Otherwise, some window managers |
786 XSizeHints size_hints; | 790 // will ignore toplevel XMoveWindow commands. |
787 size_hints.flags = PPosition; | 791 XSizeHints size_hints; |
788 size_hints.x = bounds_.x(); | 792 size_hints.flags = PPosition; |
789 size_hints.y = bounds_.y(); | 793 size_hints.x = bounds_.x(); |
790 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); | 794 size_hints.y = bounds_.y(); |
795 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); | |
791 | 796 |
792 XMapWindow(xdisplay_, xwindow_); | 797 XMapWindow(xdisplay_, xwindow_); |
798 | |
799 // We now block until our window is mapped. Some X11 APIs will crash and | |
800 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | |
801 // asynchronous. | |
802 base::MessagePumpAuraX11::Current()->BlockUntilWindowMapped(xwindow_); | |
803 window_mapped_ = true; | |
804 } | |
805 } | |
806 | |
807 void RootWindowHostLinux::Hide() { | |
808 if (window_mapped_) { | |
809 XWithdrawWindow(xdisplay_, xwindow_, 0); | |
810 XUnmapWindow(xdisplay_, xwindow_); | |
Daniel Erat
2012/08/15 20:30:57
do you need this XUnmapWindow() call? the man pag
Elliot Glaysher
2012/08/15 20:55:59
I called both because GTK called both. If I remove
| |
811 window_mapped_ = false; | |
812 } | |
793 } | 813 } |
794 | 814 |
795 void RootWindowHostLinux::ToggleFullScreen() { | 815 void RootWindowHostLinux::ToggleFullScreen() { |
796 NOTIMPLEMENTED(); | 816 NOTIMPLEMENTED(); |
797 } | 817 } |
798 | 818 |
799 gfx::Rect RootWindowHostLinux::GetBounds() const { | 819 gfx::Rect RootWindowHostLinux::GetBounds() const { |
800 return bounds_; | 820 return bounds_; |
801 } | 821 } |
802 | 822 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1054 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); | 1074 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); |
1055 } | 1075 } |
1056 | 1076 |
1057 // static | 1077 // static |
1058 gfx::Size RootWindowHost::GetNativeScreenSize() { | 1078 gfx::Size RootWindowHost::GetNativeScreenSize() { |
1059 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); | 1079 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); |
1060 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 1080 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
1061 } | 1081 } |
1062 | 1082 |
1063 } // namespace aura | 1083 } // namespace aura |
OLD | NEW |