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> |
11 #include <X11/extensions/XInput2.h> | 11 #include <X11/extensions/XInput2.h> |
12 #include <X11/extensions/Xfixes.h> | 12 #include <X11/extensions/Xfixes.h> |
13 #include <X11/extensions/Xrandr.h> | 13 #include <X11/extensions/Xrandr.h> |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 #include "base/message_pump_x.h" | 16 #include "base/message_pump_x.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "grit/ui_resources_standard.h" | 19 #include "grit/ui_resources_standard.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/aura/client/user_gesture_client.h" | 21 #include "ui/aura/client/user_gesture_client.h" |
22 #include "ui/aura/dispatcher_linux.h" | 22 #include "ui/aura/dispatcher_linux.h" |
23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
24 #include "ui/aura/event.h" | 24 #include "ui/aura/event.h" |
25 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
| 26 #include "ui/aura/x11_atom_cache.h" |
26 #include "ui/base/cursor/cursor.h" | 27 #include "ui/base/cursor/cursor.h" |
27 #include "ui/base/keycodes/keyboard_codes.h" | 28 #include "ui/base/keycodes/keyboard_codes.h" |
28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/base/touch/touch_factory.h" | 30 #include "ui/base/touch/touch_factory.h" |
30 #include "ui/base/view_prop.h" | 31 #include "ui/base/view_prop.h" |
31 #include "ui/base/x/x11_atom_cache.h" | |
32 #include "ui/base/x/x11_util.h" | 32 #include "ui/base/x/x11_util.h" |
33 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
34 #include "ui/gfx/codec/png_codec.h" | 34 #include "ui/gfx/codec/png_codec.h" |
35 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
36 | 36 |
37 using ui::X11AtomCache; | |
38 using std::max; | 37 using std::max; |
39 using std::min; | 38 using std::min; |
40 | 39 |
41 namespace aura { | 40 namespace aura { |
42 | 41 |
43 namespace { | 42 namespace { |
44 | 43 |
45 // Standard Linux mouse buttons for going back and forward. | 44 // Standard Linux mouse buttons for going back and forward. |
46 const int kBackMouseButton = 8; | 45 const int kBackMouseButton = 8; |
47 const int kForwardMouseButton = 9; | 46 const int kForwardMouseButton = 9; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 invisible_cursor_ = XCreatePixmapCursor(xdisplay_, blank, blank, | 385 invisible_cursor_ = XCreatePixmapCursor(xdisplay_, blank, blank, |
387 &black, &black, 0, 0); | 386 &black, &black, 0, 0); |
388 XFreePixmap(xdisplay_, blank); | 387 XFreePixmap(xdisplay_, blank); |
389 | 388 |
390 if (RootWindow::hide_host_cursor()) | 389 if (RootWindow::hide_host_cursor()) |
391 XDefineCursor(xdisplay_, x_root_window_, invisible_cursor_); | 390 XDefineCursor(xdisplay_, x_root_window_, invisible_cursor_); |
392 | 391 |
393 // TODO(erg): We currently only request window deletion events. We also | 392 // TODO(erg): We currently only request window deletion events. We also |
394 // should listen for activation events and anything else that GTK+ listens | 393 // should listen for activation events and anything else that GTK+ listens |
395 // for, and do something useful. | 394 // for, and do something useful. |
396 X11AtomCache* cache = X11AtomCache::GetInstance(); | 395 X11AtomCache* cache = aura::Env::GetInstance()->atom_cache(); |
397 ::Atom protocols[2]; | 396 ::Atom protocols[2]; |
398 protocols[0] = cache->GetAtom(ui::ATOM_WM_DELETE_WINDOW); | 397 protocols[0] = cache->GetAtom(ATOM_WM_DELETE_WINDOW); |
399 protocols[1] = cache->GetAtom(ui::ATOM__NET_WM_PING); | 398 protocols[1] = cache->GetAtom(ATOM__NET_WM_PING); |
400 XSetWMProtocols(xdisplay_, xwindow_, protocols, 2); | 399 XSetWMProtocols(xdisplay_, xwindow_, protocols, 2); |
401 | 400 |
402 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with | 401 // We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with |
403 // the desktop environment. | 402 // the desktop environment. |
404 XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL); | 403 XSetWMProperties(xdisplay_, xwindow_, NULL, NULL, NULL, 0, NULL, NULL, NULL); |
405 | 404 |
406 // Likewise, the X server needs to know this window's pid so it knows which | 405 // Likewise, the X server needs to know this window's pid so it knows which |
407 // program to kill if the window hangs. | 406 // program to kill if the window hangs. |
408 pid_t pid = getpid(); | 407 pid_t pid = getpid(); |
409 XChangeProperty(xdisplay_, | 408 XChangeProperty(xdisplay_, |
410 xwindow_, | 409 xwindow_, |
411 cache->GetAtom(ui::ATOM__NET_WM_PID), | 410 cache->GetAtom(ATOM__NET_WM_PID), |
412 XA_CARDINAL, | 411 XA_CARDINAL, |
413 32, | 412 32, |
414 PropModeReplace, | 413 PropModeReplace, |
415 reinterpret_cast<unsigned char*>(&pid), 1); | 414 reinterpret_cast<unsigned char*>(&pid), 1); |
416 | 415 |
417 // crbug.com/120229 - set the window title so gtalk can find the primary root | 416 // crbug.com/120229 - set the window title so gtalk can find the primary root |
418 // window to broadcast. | 417 // window to broadcast. |
419 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. | 418 // TODO(jhorwich) Remove this once Chrome supports window-based broadcasting. |
420 static int root_window_number = 0; | 419 static int root_window_number = 0; |
421 std::string name = StringPrintf("aura_root_%d", root_window_number++); | 420 std::string name = StringPrintf("aura_root_%d", root_window_number++); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 } | 572 } |
574 case MapNotify: { | 573 case MapNotify: { |
575 // If there's no window manager running, we need to assign the X input | 574 // If there's no window manager running, we need to assign the X input |
576 // focus to our host window. | 575 // focus to our host window. |
577 if (!IsWindowManagerPresent() && focus_when_shown_) | 576 if (!IsWindowManagerPresent() && focus_when_shown_) |
578 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); | 577 XSetInputFocus(xdisplay_, xwindow_, RevertToNone, CurrentTime); |
579 break; | 578 break; |
580 } | 579 } |
581 case ClientMessage: { | 580 case ClientMessage: { |
582 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); | 581 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); |
583 X11AtomCache* cache = X11AtomCache::GetInstance(); | 582 X11AtomCache* cache = aura::Env::GetInstance()->atom_cache(); |
584 if (message_type == cache->GetAtom(ui::ATOM_WM_DELETE_WINDOW)) { | 583 if (message_type == cache->GetAtom(ATOM_WM_DELETE_WINDOW)) { |
585 // We have received a close message from the window manager. | 584 // We have received a close message from the window manager. |
586 root_window_->OnRootWindowHostClosed(); | 585 root_window_->OnRootWindowHostClosed(); |
587 } else if (message_type == cache->GetAtom(ui::ATOM__NET_WM_PING)) { | 586 } else if (message_type == cache->GetAtom(ATOM__NET_WM_PING)) { |
588 XEvent reply_event = *xev; | 587 XEvent reply_event = *xev; |
589 reply_event.xclient.window = x_root_window_; | 588 reply_event.xclient.window = x_root_window_; |
590 | 589 |
591 XSendEvent(xdisplay_, | 590 XSendEvent(xdisplay_, |
592 reply_event.xclient.window, | 591 reply_event.xclient.window, |
593 False, | 592 False, |
594 SubstructureRedirectMask | SubstructureNotifyMask, | 593 SubstructureRedirectMask | SubstructureNotifyMask, |
595 &reply_event); | 594 &reply_event); |
596 } | 595 } |
597 break; | 596 break; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 break; | 869 break; |
871 } | 870 } |
872 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); | 871 XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); |
873 } | 872 } |
874 | 873 |
875 bool RootWindowHostLinux::IsWindowManagerPresent() { | 874 bool RootWindowHostLinux::IsWindowManagerPresent() { |
876 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership | 875 // Per ICCCM 2.8, "Manager Selections", window managers should take ownership |
877 // of WM_Sn selections (where n is a screen number). | 876 // of WM_Sn selections (where n is a screen number). |
878 return XGetSelectionOwner( | 877 return XGetSelectionOwner( |
879 xdisplay_, | 878 xdisplay_, |
880 X11AtomCache::GetInstance()->GetAtom(ui::ATOM_WM_S0)) != None; | 879 aura::Env::GetInstance()->atom_cache()->GetAtom(ATOM_WM_S0)) != None; |
881 } | 880 } |
882 | 881 |
883 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { | 882 void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) { |
884 ::Cursor xcursor = | 883 ::Cursor xcursor = |
885 image_cursors_->IsImageCursor(cursor) ? | 884 image_cursors_->IsImageCursor(cursor) ? |
886 image_cursors_->ImageCursorFromNative(cursor) : | 885 image_cursors_->ImageCursorFromNative(cursor) : |
887 cursor == ui::kCursorNone ? | 886 cursor == ui::kCursorNone ? |
888 invisible_cursor_ : | 887 invisible_cursor_ : |
889 cursor == ui::kCursorCustom ? | 888 cursor == ui::kCursorCustom ? |
890 cursor.platform() : | 889 cursor.platform() : |
(...skipping 13 matching lines...) Expand all Loading... |
904 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); | 903 ui::ViewProp::GetValue(accelerated_widget, kRootWindowHostLinuxKey)); |
905 } | 904 } |
906 | 905 |
907 // static | 906 // static |
908 gfx::Size RootWindowHost::GetNativeScreenSize() { | 907 gfx::Size RootWindowHost::GetNativeScreenSize() { |
909 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 908 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
910 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 909 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
911 } | 910 } |
912 | 911 |
913 } // namespace aura | 912 } // namespace aura |
OLD | NEW |