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/views/widget/desktop_aura/x11_desktop_handler.h" | 5 #include "ui/views/widget/desktop_aura/x11_desktop_handler.h" |
6 | 6 |
| 7 #include <X11/Xatom.h> |
| 8 #include <X11/Xlib.h> |
| 9 |
7 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
8 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
9 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
10 #include "ui/base/x/x11_util.h" | 13 #include "ui/base/x/x11_util.h" |
11 | 14 |
12 #if !defined(OS_CHROMEOS) | 15 #if !defined(OS_CHROMEOS) |
13 #include "ui/views/ime/input_method.h" | 16 #include "ui/views/ime/input_method.h" |
14 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" | 17 #include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" |
15 #endif | 18 #endif |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 const char* kAtomsToCache[] = { | 22 const char* kAtomsToCache[] = { |
20 "_NET_ACTIVE_WINDOW", | 23 "_NET_ACTIVE_WINDOW", |
| 24 "_NET_SUPPORTED", |
21 NULL | 25 NULL |
22 }; | 26 }; |
23 | 27 |
24 // Our global instance. Deleted when our Env() is deleted. | 28 // Our global instance. Deleted when our Env() is deleted. |
25 views::X11DesktopHandler* g_handler = NULL; | 29 views::X11DesktopHandler* g_handler = NULL; |
26 | 30 |
27 } // namespace | 31 } // namespace |
28 | 32 |
29 namespace views { | 33 namespace views { |
30 | 34 |
31 // static | 35 // static |
32 X11DesktopHandler* X11DesktopHandler::get() { | 36 X11DesktopHandler* X11DesktopHandler::get() { |
33 if (!g_handler) | 37 if (!g_handler) |
34 g_handler = new X11DesktopHandler; | 38 g_handler = new X11DesktopHandler; |
35 | 39 |
36 return g_handler; | 40 return g_handler; |
37 } | 41 } |
38 | 42 |
39 X11DesktopHandler::X11DesktopHandler() | 43 X11DesktopHandler::X11DesktopHandler() |
40 : xdisplay_(gfx::GetXDisplay()), | 44 : xdisplay_(gfx::GetXDisplay()), |
41 x_root_window_(DefaultRootWindow(xdisplay_)), | 45 x_root_window_(DefaultRootWindow(xdisplay_)), |
42 current_window_(None), | 46 current_window_(None), |
43 atom_cache_(xdisplay_, kAtomsToCache) { | 47 atom_cache_(xdisplay_, kAtomsToCache), |
| 48 wm_supports_active_window_(false) { |
44 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); | 49 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); |
45 aura::Env::GetInstance()->AddObserver(this); | 50 aura::Env::GetInstance()->AddObserver(this); |
46 | 51 |
47 XWindowAttributes attr; | 52 XWindowAttributes attr; |
48 XGetWindowAttributes(xdisplay_, x_root_window_, &attr); | 53 XGetWindowAttributes(xdisplay_, x_root_window_, &attr); |
49 XSelectInput(xdisplay_, x_root_window_, | 54 XSelectInput(xdisplay_, x_root_window_, |
50 attr.your_event_mask | PropertyChangeMask | | 55 attr.your_event_mask | PropertyChangeMask | |
51 StructureNotifyMask | SubstructureNotifyMask); | 56 StructureNotifyMask | SubstructureNotifyMask); |
| 57 |
| 58 std::vector<Atom> atoms; |
| 59 if (ui::GetAtomArrayProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &atoms)) { |
| 60 Atom active_window = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); |
| 61 for (std::vector<Atom>::iterator iter = atoms.begin(); iter != atoms.end(); |
| 62 ++iter) { |
| 63 if (*(iter) == active_window) { |
| 64 wm_supports_active_window_ = true; |
| 65 break; |
| 66 } |
| 67 } |
| 68 } |
52 } | 69 } |
53 | 70 |
54 X11DesktopHandler::~X11DesktopHandler() { | 71 X11DesktopHandler::~X11DesktopHandler() { |
55 aura::Env::GetInstance()->RemoveObserver(this); | 72 aura::Env::GetInstance()->RemoveObserver(this); |
56 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 73 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); |
57 } | 74 } |
58 | 75 |
59 void X11DesktopHandler::ActivateWindow(::Window window) { | 76 void X11DesktopHandler::ActivateWindow(::Window window) { |
60 DCHECK_EQ(gfx::GetXDisplay(), xdisplay_); | 77 if (wm_supports_active_window_) { |
| 78 DCHECK_EQ(gfx::GetXDisplay(), xdisplay_); |
61 | 79 |
62 XEvent xclient; | 80 XEvent xclient; |
63 memset(&xclient, 0, sizeof(xclient)); | 81 memset(&xclient, 0, sizeof(xclient)); |
64 xclient.type = ClientMessage; | 82 xclient.type = ClientMessage; |
65 xclient.xclient.window = window; | 83 xclient.xclient.window = window; |
66 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); | 84 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); |
67 xclient.xclient.format = 32; | 85 xclient.xclient.format = 32; |
68 xclient.xclient.data.l[0] = 1; // Specified we are an app. | 86 xclient.xclient.data.l[0] = 1; // Specified we are an app. |
69 xclient.xclient.data.l[1] = CurrentTime; | 87 xclient.xclient.data.l[1] = CurrentTime; |
70 xclient.xclient.data.l[2] = None; | 88 xclient.xclient.data.l[2] = None; |
71 xclient.xclient.data.l[3] = 0; | 89 xclient.xclient.data.l[3] = 0; |
72 xclient.xclient.data.l[4] = 0; | 90 xclient.xclient.data.l[4] = 0; |
73 | 91 |
74 XSendEvent(xdisplay_, x_root_window_, False, | 92 XSendEvent(xdisplay_, x_root_window_, False, |
75 SubstructureRedirectMask | SubstructureNotifyMask, | 93 SubstructureRedirectMask | SubstructureNotifyMask, |
76 &xclient); | 94 &xclient); |
| 95 } else { |
| 96 XRaiseWindow(xdisplay_, window); |
| 97 OnActiveWindowChanged(window); |
| 98 } |
77 } | 99 } |
78 | 100 |
79 bool X11DesktopHandler::IsActiveWindow(::Window window) const { | 101 bool X11DesktopHandler::IsActiveWindow(::Window window) const { |
80 return window == current_window_; | 102 return window == current_window_; |
81 } | 103 } |
82 | 104 |
83 bool X11DesktopHandler::Dispatch(const base::NativeEvent& event) { | 105 bool X11DesktopHandler::Dispatch(const base::NativeEvent& event) { |
84 // Check for a change to the active window. | 106 // Check for a change to the active window. |
85 switch (event->type) { | 107 switch (event->type) { |
86 case PropertyNotify: { | 108 case PropertyNotify: { |
(...skipping 30 matching lines...) Expand all Loading... |
117 | 139 |
118 DesktopRootWindowHostX11* new_host = | 140 DesktopRootWindowHostX11* new_host = |
119 views::DesktopRootWindowHostX11::GetHostForXID(xid); | 141 views::DesktopRootWindowHostX11::GetHostForXID(xid); |
120 if (new_host) | 142 if (new_host) |
121 new_host->HandleNativeWidgetActivationChanged(true); | 143 new_host->HandleNativeWidgetActivationChanged(true); |
122 | 144 |
123 current_window_ = xid; | 145 current_window_ = xid; |
124 } | 146 } |
125 | 147 |
126 } // namespace views | 148 } // namespace views |
OLD | NEW |