| 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/cursorfont.h> | 7 #include <X11/cursorfont.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/extensions/Xfixes.h> | 9 #include <X11/extensions/Xfixes.h> |
| 10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/message_pump_x.h" | 13 #include "base/message_pump_x.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "ui/aura/cursor.h" | |
| 17 #include "ui/aura/dispatcher_linux.h" | 16 #include "ui/aura/dispatcher_linux.h" |
| 18 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
| 19 #include "ui/aura/event.h" | 18 #include "ui/aura/event.h" |
| 20 #include "ui/aura/monitor.h" | 19 #include "ui/aura/monitor.h" |
| 21 #include "ui/aura/monitor_manager.h" | 20 #include "ui/aura/monitor_manager.h" |
| 22 #include "ui/aura/root_window.h" | 21 #include "ui/aura/root_window.h" |
| 22 #include "ui/base/cursor/cursor.h" |
| 23 #include "ui/base/keycodes/keyboard_codes.h" | 23 #include "ui/base/keycodes/keyboard_codes.h" |
| 24 #include "ui/base/touch/touch_factory.h" | 24 #include "ui/base/touch/touch_factory.h" |
| 25 #include "ui/base/x/x11_util.h" | 25 #include "ui/base/x/x11_util.h" |
| 26 #include "ui/gfx/compositor/layer.h" | 26 #include "ui/gfx/compositor/layer.h" |
| 27 | 27 |
| 28 using std::max; | 28 using std::max; |
| 29 using std::min; | 29 using std::min; |
| 30 | 30 |
| 31 namespace aura { | 31 namespace aura { |
| 32 | 32 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 CHECK_EQ(slave_event.valuators.mask_len, xievent->valuators.mask_len); | 76 CHECK_EQ(slave_event.valuators.mask_len, xievent->valuators.mask_len); |
| 77 CHECK_EQ(slave_event.mods.base, xievent->mods.base); | 77 CHECK_EQ(slave_event.mods.base, xievent->mods.base); |
| 78 CHECK_EQ(slave_event.mods.latched, xievent->mods.latched); | 78 CHECK_EQ(slave_event.mods.latched, xievent->mods.latched); |
| 79 CHECK_EQ(slave_event.mods.locked, xievent->mods.locked); | 79 CHECK_EQ(slave_event.mods.locked, xievent->mods.locked); |
| 80 CHECK_EQ(slave_event.mods.effective, xievent->mods.effective); | 80 CHECK_EQ(slave_event.mods.effective, xievent->mods.effective); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Returns X font cursor shape from an Aura cursor. | 84 // Returns X font cursor shape from an Aura cursor. |
| 85 int CursorShapeFromNative(gfx::NativeCursor native_cursor) { | 85 int CursorShapeFromNative(gfx::NativeCursor native_cursor) { |
| 86 switch (native_cursor) { | 86 switch (native_cursor.native_type()) { |
| 87 case aura::kCursorNull: | 87 case ui::kCursorNull: |
| 88 return XC_left_ptr; | 88 return XC_left_ptr; |
| 89 case aura::kCursorPointer: | 89 case ui::kCursorPointer: |
| 90 return XC_left_ptr; | 90 return XC_left_ptr; |
| 91 case aura::kCursorCross: | 91 case ui::kCursorCross: |
| 92 return XC_crosshair; | 92 return XC_crosshair; |
| 93 case aura::kCursorHand: | 93 case ui::kCursorHand: |
| 94 return XC_hand2; | 94 return XC_hand2; |
| 95 case aura::kCursorIBeam: | 95 case ui::kCursorIBeam: |
| 96 return XC_xterm; | 96 return XC_xterm; |
| 97 case aura::kCursorWait: | 97 case ui::kCursorWait: |
| 98 return XC_watch; | 98 return XC_watch; |
| 99 case aura::kCursorHelp: | 99 case ui::kCursorHelp: |
| 100 return XC_question_arrow; | 100 return XC_question_arrow; |
| 101 case aura::kCursorEastResize: | 101 case ui::kCursorEastResize: |
| 102 return XC_right_side; | 102 return XC_right_side; |
| 103 case aura::kCursorNorthResize: | 103 case ui::kCursorNorthResize: |
| 104 return XC_top_side; | 104 return XC_top_side; |
| 105 case aura::kCursorNorthEastResize: | 105 case ui::kCursorNorthEastResize: |
| 106 return XC_top_right_corner; | 106 return XC_top_right_corner; |
| 107 case aura::kCursorNorthWestResize: | 107 case ui::kCursorNorthWestResize: |
| 108 return XC_top_left_corner; | 108 return XC_top_left_corner; |
| 109 case aura::kCursorSouthResize: | 109 case ui::kCursorSouthResize: |
| 110 return XC_bottom_side; | 110 return XC_bottom_side; |
| 111 case aura::kCursorSouthEastResize: | 111 case ui::kCursorSouthEastResize: |
| 112 return XC_bottom_right_corner; | 112 return XC_bottom_right_corner; |
| 113 case aura::kCursorSouthWestResize: | 113 case ui::kCursorSouthWestResize: |
| 114 return XC_bottom_left_corner; | 114 return XC_bottom_left_corner; |
| 115 case aura::kCursorWestResize: | 115 case ui::kCursorWestResize: |
| 116 return XC_left_side; | 116 return XC_left_side; |
| 117 case aura::kCursorNorthSouthResize: | 117 case ui::kCursorNorthSouthResize: |
| 118 return XC_sb_v_double_arrow; | 118 return XC_sb_v_double_arrow; |
| 119 case aura::kCursorEastWestResize: | 119 case ui::kCursorEastWestResize: |
| 120 return XC_sb_h_double_arrow; | 120 return XC_sb_h_double_arrow; |
| 121 case aura::kCursorNorthEastSouthWestResize: | 121 case ui::kCursorNorthEastSouthWestResize: |
| 122 case aura::kCursorNorthWestSouthEastResize: | 122 case ui::kCursorNorthWestSouthEastResize: |
| 123 // There isn't really a useful cursor available for these. | 123 // There isn't really a useful cursor available for these. |
| 124 return XC_left_ptr; | 124 return XC_left_ptr; |
| 125 case aura::kCursorColumnResize: | 125 case ui::kCursorColumnResize: |
| 126 return XC_sb_h_double_arrow; | 126 return XC_sb_h_double_arrow; |
| 127 case aura::kCursorRowResize: | 127 case ui::kCursorRowResize: |
| 128 return XC_sb_v_double_arrow; | 128 return XC_sb_v_double_arrow; |
| 129 case aura::kCursorMiddlePanning: | 129 case ui::kCursorMiddlePanning: |
| 130 return XC_fleur; | 130 return XC_fleur; |
| 131 case aura::kCursorEastPanning: | 131 case ui::kCursorEastPanning: |
| 132 return XC_sb_right_arrow; | 132 return XC_sb_right_arrow; |
| 133 case aura::kCursorNorthPanning: | 133 case ui::kCursorNorthPanning: |
| 134 return XC_sb_up_arrow; | 134 return XC_sb_up_arrow; |
| 135 case aura::kCursorNorthEastPanning: | 135 case ui::kCursorNorthEastPanning: |
| 136 return XC_top_right_corner; | 136 return XC_top_right_corner; |
| 137 case aura::kCursorNorthWestPanning: | 137 case ui::kCursorNorthWestPanning: |
| 138 return XC_top_left_corner; | 138 return XC_top_left_corner; |
| 139 case aura::kCursorSouthPanning: | 139 case ui::kCursorSouthPanning: |
| 140 return XC_sb_down_arrow; | 140 return XC_sb_down_arrow; |
| 141 case aura::kCursorSouthEastPanning: | 141 case ui::kCursorSouthEastPanning: |
| 142 return XC_bottom_right_corner; | 142 return XC_bottom_right_corner; |
| 143 case aura::kCursorSouthWestPanning: | 143 case ui::kCursorSouthWestPanning: |
| 144 return XC_bottom_left_corner; | 144 return XC_bottom_left_corner; |
| 145 case aura::kCursorWestPanning: | 145 case ui::kCursorWestPanning: |
| 146 return XC_sb_left_arrow; | 146 return XC_sb_left_arrow; |
| 147 case aura::kCursorMove: | 147 case ui::kCursorMove: |
| 148 return XC_fleur; | 148 return XC_fleur; |
| 149 case aura::kCursorVerticalText: | 149 case ui::kCursorVerticalText: |
| 150 case aura::kCursorCell: | 150 case ui::kCursorCell: |
| 151 case aura::kCursorContextMenu: | 151 case ui::kCursorContextMenu: |
| 152 case aura::kCursorAlias: | 152 case ui::kCursorAlias: |
| 153 case aura::kCursorProgress: | 153 case ui::kCursorProgress: |
| 154 case aura::kCursorNoDrop: | 154 case ui::kCursorNoDrop: |
| 155 case aura::kCursorCopy: | 155 case ui::kCursorCopy: |
| 156 case aura::kCursorNone: | 156 case ui::kCursorNone: |
| 157 case aura::kCursorNotAllowed: | 157 case ui::kCursorNotAllowed: |
| 158 case aura::kCursorZoomIn: | 158 case ui::kCursorZoomIn: |
| 159 case aura::kCursorZoomOut: | 159 case ui::kCursorZoomOut: |
| 160 case aura::kCursorGrab: | 160 case ui::kCursorGrab: |
| 161 case aura::kCursorGrabbing: | 161 case ui::kCursorGrabbing: |
| 162 case aura::kCursorCustom: | |
| 163 // TODO(jamescook): Need cursors for these. crbug.com/111650 | 162 // TODO(jamescook): Need cursors for these. crbug.com/111650 |
| 164 return XC_left_ptr; | 163 return XC_left_ptr; |
| 164 case ui::kCursorCustom: |
| 165 NOTREACHED(); |
| 166 return XC_left_ptr; |
| 165 } | 167 } |
| 166 NOTREACHED(); | 168 NOTREACHED(); |
| 167 return XC_left_ptr; | 169 return XC_left_ptr; |
| 168 } | 170 } |
| 169 | 171 |
| 170 // Coalesce all pending motion events that are at the top of the queue, and | 172 // Coalesce all pending motion events that are at the top of the queue, and |
| 171 // return the number eliminated, storing the last one in |last_event|. | 173 // return the number eliminated, storing the last one in |last_event|. |
| 172 int CoalescePendingXIMotionEvents(const XEvent* xev, XEvent* last_event) { | 174 int CoalescePendingXIMotionEvents(const XEvent* xev, XEvent* last_event) { |
| 173 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 175 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 174 int num_coalesed = 0; | 176 int num_coalesed = 0; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 274 } |
| 273 } | 275 } |
| 274 | 276 |
| 275 } // namespace | 277 } // namespace |
| 276 | 278 |
| 277 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) | 279 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) |
| 278 : root_window_(NULL), | 280 : root_window_(NULL), |
| 279 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), | 281 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), |
| 280 xwindow_(0), | 282 xwindow_(0), |
| 281 x_root_window_(DefaultRootWindow(xdisplay_)), | 283 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 282 current_cursor_(aura::kCursorNull), | 284 current_cursor_(ui::kCursorNull), |
| 283 cursor_shown_(true), | 285 cursor_shown_(true), |
| 284 bounds_(bounds), | 286 bounds_(bounds), |
| 285 focus_when_shown_(false), | 287 focus_when_shown_(false), |
| 286 pointer_barriers_(NULL) { | 288 pointer_barriers_(NULL) { |
| 287 XSetWindowAttributes swa; | 289 XSetWindowAttributes swa; |
| 288 memset(&swa, 0, sizeof(swa)); | 290 memset(&swa, 0, sizeof(swa)); |
| 289 swa.background_pixmap = None; | 291 swa.background_pixmap = None; |
| 290 xwindow_ = XCreateWindow( | 292 xwindow_ = XCreateWindow( |
| 291 xdisplay_, x_root_window_, | 293 xdisplay_, x_root_window_, |
| 292 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), | 294 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 } | 558 } |
| 557 | 559 |
| 558 void RootWindowHostLinux::ReleaseCapture() { | 560 void RootWindowHostLinux::ReleaseCapture() { |
| 559 } | 561 } |
| 560 | 562 |
| 561 void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) { | 563 void RootWindowHostLinux::SetCursor(gfx::NativeCursor cursor) { |
| 562 if (cursor == current_cursor_) | 564 if (cursor == current_cursor_) |
| 563 return; | 565 return; |
| 564 current_cursor_ = cursor; | 566 current_cursor_ = cursor; |
| 565 | 567 |
| 566 // Custom web cursors are handled directly. | |
| 567 if (cursor == kCursorCustom) | |
| 568 return; | |
| 569 | |
| 570 if (cursor_shown_) | 568 if (cursor_shown_) |
| 571 SetCursorInternal(cursor); | 569 SetCursorInternal(cursor); |
| 572 } | 570 } |
| 573 | 571 |
| 574 void RootWindowHostLinux::ShowCursor(bool show) { | 572 void RootWindowHostLinux::ShowCursor(bool show) { |
| 575 if (show == cursor_shown_) | 573 if (show == cursor_shown_) |
| 576 return; | 574 return; |
| 577 cursor_shown_ = show; | 575 cursor_shown_ = show; |
| 578 SetCursorInternal(show ? current_cursor_ : kCursorNone); | 576 SetCursorInternal(show ? current_cursor_ : ui::kCursorNone); |
| 579 } | 577 } |
| 580 | 578 |
| 581 gfx::Point RootWindowHostLinux::QueryMouseLocation() { | 579 gfx::Point RootWindowHostLinux::QueryMouseLocation() { |
| 582 ::Window root_return, child_return; | 580 ::Window root_return, child_return; |
| 583 int root_x_return, root_y_return, win_x_return, win_y_return; | 581 int root_x_return, root_y_return, win_x_return, win_y_return; |
| 584 unsigned int mask_return; | 582 unsigned int mask_return; |
| 585 XQueryPointer(xdisplay_, | 583 XQueryPointer(xdisplay_, |
| 586 xwindow_, | 584 xwindow_, |
| 587 &root_return, | 585 &root_return, |
| 588 &child_return, | 586 &child_return, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 | 689 |
| 692 bool RootWindowHostLinux::IsWindowManagerPresent() { | 690 bool RootWindowHostLinux::IsWindowManagerPresent() { |
| 693 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 691 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
| 694 // of WM_Sn selections (where n is a screen number). | 692 // of WM_Sn selections (where n is a screen number). |
| 695 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); | 693 ::Atom wm_s0_atom = XInternAtom(xdisplay_, "WM_S0", False); |
| 696 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; | 694 return XGetSelectionOwner(xdisplay_, wm_s0_atom) != None; |
| 697 } | 695 } |
| 698 | 696 |
| 699 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { | 697 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { |
| 700 ::Cursor xcursor = | 698 ::Cursor xcursor = |
| 701 cursor == kCursorNone ? | 699 cursor == ui::kCursorNone ? |
| 702 invisible_cursor_ : | 700 invisible_cursor_ : |
| 701 cursor == ui::kCursorCustom ? |
| 702 cursor.platform() : |
| 703 ui::GetXCursor(CursorShapeFromNative(cursor)); | 703 ui::GetXCursor(CursorShapeFromNative(cursor)); |
| 704 XDefineCursor(xdisplay_, xwindow_, xcursor); | 704 XDefineCursor(xdisplay_, xwindow_, xcursor); |
| 705 } | 705 } |
| 706 | 706 |
| 707 // static | 707 // static |
| 708 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 708 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
| 709 return new RootWindowHostLinux(bounds); | 709 return new RootWindowHostLinux(bounds); |
| 710 } | 710 } |
| 711 | 711 |
| 712 // static | 712 // static |
| 713 gfx::Size RootWindowHost::GetNativeScreenSize() { | 713 gfx::Size RootWindowHost::GetNativeScreenSize() { |
| 714 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 714 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
| 715 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 715 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 716 } | 716 } |
| 717 | 717 |
| 718 } // namespace aura | 718 } // namespace aura |
| OLD | NEW |