| 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/cursorfont.h> | 9 #include <X11/cursorfont.h> |
| 9 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/extensions/Xfixes.h> | 11 #include <X11/extensions/Xfixes.h> |
| 11 #include <X11/extensions/Xrandr.h> | 12 #include <X11/extensions/Xrandr.h> |
| 12 #include <algorithm> | 13 #include <algorithm> |
| 13 | 14 |
| 14 #include "base/message_pump_x.h" | 15 #include "base/message_pump_x.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "grit/ui_resources_standard.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/aura/client/user_gesture_client.h" | 20 #include "ui/aura/client/user_gesture_client.h" |
| 18 #include "ui/aura/dispatcher_linux.h" | 21 #include "ui/aura/dispatcher_linux.h" |
| 19 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 20 #include "ui/aura/event.h" | 23 #include "ui/aura/event.h" |
| 21 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
| 22 #include "ui/base/cursor/cursor.h" | 25 #include "ui/base/cursor/cursor.h" |
| 23 #include "ui/base/keycodes/keyboard_codes.h" | 26 #include "ui/base/keycodes/keyboard_codes.h" |
| 27 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/base/touch/touch_factory.h" | 28 #include "ui/base/touch/touch_factory.h" |
| 25 #include "ui/base/x/x11_util.h" | 29 #include "ui/base/x/x11_util.h" |
| 26 #include "ui/base/view_prop.h" | 30 #include "ui/base/view_prop.h" |
| 27 #include "ui/gfx/compositor/layer.h" | 31 #include "ui/gfx/compositor/layer.h" |
| 32 #include "ui/gfx/image/image.h" |
| 28 | 33 |
| 29 using std::max; | 34 using std::max; |
| 30 using std::min; | 35 using std::min; |
| 31 | 36 |
| 32 namespace aura { | 37 namespace aura { |
| 33 | 38 |
| 34 namespace { | 39 namespace { |
| 35 | 40 |
| 36 // Standard Linux mouse buttons for going back and forward. | 41 // Standard Linux mouse buttons for going back and forward. |
| 37 const int kBackMouseButton = 8; | 42 const int kBackMouseButton = 8; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // X11 server. Must be kept in sync with RootWindowHostLinux::AtomList | 290 // X11 server. Must be kept in sync with RootWindowHostLinux::AtomList |
| 286 const char* kAtomList[] = { | 291 const char* kAtomList[] = { |
| 287 "WM_DELETE_WINDOW", | 292 "WM_DELETE_WINDOW", |
| 288 "_NET_WM_PING", | 293 "_NET_WM_PING", |
| 289 "_NET_WM_PID", | 294 "_NET_WM_PID", |
| 290 "WM_S0" | 295 "WM_S0" |
| 291 }; | 296 }; |
| 292 | 297 |
| 293 } // namespace | 298 } // namespace |
| 294 | 299 |
| 300 // A utility class that provides X Cursor for NativeCursors for which we have |
| 301 // image resources. |
| 302 class RootWindowHostLinux::ImageCursors { |
| 303 public: |
| 304 ImageCursors() { |
| 305 LoadImageCursor(ui::kCursorNoDrop, IDR_AURA_CURSOR_NO_DROP); |
| 306 LoadImageCursor(ui::kCursorCopy, IDR_AURA_CURSOR_COPY); |
| 307 // TODO (varunjain): add more cursors once we have assets. |
| 308 } |
| 309 |
| 310 ~ImageCursors() { |
| 311 std::map<int, Cursor>::const_iterator it; |
| 312 for (it = cursors_.begin(); it != cursors_.end(); ++it) |
| 313 ui::UnrefCustomXCursor(it->second); |
| 314 } |
| 315 |
| 316 // Returns true if we have an image resource loaded for the |native_cursor|. |
| 317 bool IsImageCursor(gfx::NativeCursor native_cursor) { |
| 318 return cursors_.find(native_cursor.native_type()) != cursors_.end(); |
| 319 } |
| 320 |
| 321 // Gets the X Cursor corresponding to the |native_cursor|. |
| 322 ::Cursor ImageCursorFromNative(gfx::NativeCursor native_cursor) { |
| 323 DCHECK(cursors_.find(native_cursor.native_type()) != cursors_.end()); |
| 324 return cursors_[native_cursor.native_type()]; |
| 325 } |
| 326 |
| 327 private: |
| 328 // Creates an X Cursor from an image resource and puts it in the cursor map. |
| 329 void LoadImageCursor(int id, int resource_id) { |
| 330 const SkBitmap* bitmap = |
| 331 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 332 resource_id).ToSkBitmap(); |
| 333 |
| 334 XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap, gfx::Point(0, 0)); |
| 335 cursors_[id] = ui::CreateReffedCustomXCursor(image); |
| 336 // |bitmap| is owned by the resource bundle. So we do not need to free it. |
| 337 } |
| 338 |
| 339 // A map to hold all image cursors. It maps the cursor ID to the X Cursor. |
| 340 std::map<int, Cursor> cursors_; |
| 341 |
| 342 DISALLOW_COPY_AND_ASSIGN(ImageCursors); |
| 343 }; |
| 344 |
| 295 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) | 345 RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds) |
| 296 : root_window_(NULL), | 346 : root_window_(NULL), |
| 297 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), | 347 xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), |
| 298 xwindow_(0), | 348 xwindow_(0), |
| 299 x_root_window_(DefaultRootWindow(xdisplay_)), | 349 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 300 current_cursor_(ui::kCursorNull), | 350 current_cursor_(ui::kCursorNull), |
| 301 cursor_shown_(true), | 351 cursor_shown_(true), |
| 302 bounds_(bounds), | 352 bounds_(bounds), |
| 303 focus_when_shown_(false), | 353 focus_when_shown_(false), |
| 304 pointer_barriers_(NULL) { | 354 pointer_barriers_(NULL), |
| 355 image_cursors_(new ImageCursors) { |
| 305 XSetWindowAttributes swa; | 356 XSetWindowAttributes swa; |
| 306 memset(&swa, 0, sizeof(swa)); | 357 memset(&swa, 0, sizeof(swa)); |
| 307 swa.background_pixmap = None; | 358 swa.background_pixmap = None; |
| 308 xwindow_ = XCreateWindow( | 359 xwindow_ = XCreateWindow( |
| 309 xdisplay_, x_root_window_, | 360 xdisplay_, x_root_window_, |
| 310 bounds.x(), bounds.y(), bounds.width(), bounds.height(), | 361 bounds.x(), bounds.y(), bounds.width(), bounds.height(), |
| 311 0, // border width | 362 0, // border width |
| 312 CopyFromParent, // depth | 363 CopyFromParent, // depth |
| 313 InputOutput, | 364 InputOutput, |
| 314 CopyFromParent, // visual | 365 CopyFromParent, // visual |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 838 } |
| 788 | 839 |
| 789 bool RootWindowHostLinux::IsWindowManagerPresent() { | 840 bool RootWindowHostLinux::IsWindowManagerPresent() { |
| 790 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 841 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
| 791 // of WM_Sn selections (where n is a screen number). | 842 // of WM_Sn selections (where n is a screen number). |
| 792 return XGetSelectionOwner(xdisplay_, cached_atoms_[ATOM_WM_S0]) != None; | 843 return XGetSelectionOwner(xdisplay_, cached_atoms_[ATOM_WM_S0]) != None; |
| 793 } | 844 } |
| 794 | 845 |
| 795 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { | 846 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { |
| 796 ::Cursor xcursor = | 847 ::Cursor xcursor = |
| 848 image_cursors_->IsImageCursor(cursor) ? |
| 849 image_cursors_->ImageCursorFromNative(cursor) : |
| 797 cursor == ui::kCursorNone ? | 850 cursor == ui::kCursorNone ? |
| 798 invisible_cursor_ : | 851 invisible_cursor_ : |
| 799 cursor == ui::kCursorCustom ? | 852 cursor == ui::kCursorCustom ? |
| 800 cursor.platform() : | 853 cursor.platform() : |
| 801 ui::GetXCursor(CursorShapeFromNative(cursor)); | 854 ui::GetXCursor(CursorShapeFromNative(cursor)); |
| 802 XDefineCursor(xdisplay_, xwindow_, xcursor); | 855 XDefineCursor(xdisplay_, xwindow_, xcursor); |
| 803 } | 856 } |
| 804 | 857 |
| 805 // static | 858 // static |
| 806 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { | 859 RootWindowHost* RootWindowHost::Create(const gfx::Rect& bounds) { |
| 807 return new RootWindowHostLinux(bounds); | 860 return new RootWindowHostLinux(bounds); |
| 808 } | 861 } |
| 809 | 862 |
| 810 // static | 863 // static |
| 811 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( | 864 RootWindowHost* RootWindowHost::GetForAcceleratedWidget( |
| 812 gfx::AcceleratedWidget accelerated_widget) { | 865 gfx::AcceleratedWidget accelerated_widget) { |
| 813 return reinterpret_cast<RootWindowHost*>( | 866 return reinterpret_cast<RootWindowHost*>( |
| 814 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); | 867 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); |
| 815 } | 868 } |
| 816 | 869 |
| 817 // static | 870 // static |
| 818 gfx::Size RootWindowHost::GetNativeScreenSize() { | 871 gfx::Size RootWindowHost::GetNativeScreenSize() { |
| 819 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 872 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
| 820 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 873 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 821 } | 874 } |
| 822 | 875 |
| 823 } // namespace aura | 876 } // namespace aura |
| OLD | NEW |