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 const int kMaxWMAtoms = 64; | |
59 size_t atoms_count = 0; | |
60 Atom* atoms = NULL; | |
61 Atom type; | |
62 int format; | |
63 size_t bytes; | |
64 XGetWindowProperty(xdisplay_, x_root_window_, | |
65 atom_cache_.GetAtom("_NET_SUPPORTED"), | |
66 0, kMaxWMAtoms, | |
67 False, XA_ATOM, | |
68 &type, &format, &atoms_count, &bytes, | |
69 reinterpret_cast<unsigned char**>(&atoms)); | |
Elliot Glaysher
2013/11/14 18:37:38
ui::GetAtomArrayProperty()?
sadrul
2013/11/14 19:06:41
Done.
| |
70 if (type == XA_ATOM) { | |
71 Atom active_window = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); | |
72 for (size_t i = 0; i < atoms_count; ++i) { | |
73 if (atoms[i] == active_window) { | |
74 wm_supports_active_window_ = true; | |
75 break; | |
76 } | |
77 } | |
78 } | |
52 } | 79 } |
53 | 80 |
54 X11DesktopHandler::~X11DesktopHandler() { | 81 X11DesktopHandler::~X11DesktopHandler() { |
55 aura::Env::GetInstance()->RemoveObserver(this); | 82 aura::Env::GetInstance()->RemoveObserver(this); |
56 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 83 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); |
57 } | 84 } |
58 | 85 |
59 void X11DesktopHandler::ActivateWindow(::Window window) { | 86 void X11DesktopHandler::ActivateWindow(::Window window) { |
60 DCHECK_EQ(gfx::GetXDisplay(), xdisplay_); | 87 if (wm_supports_active_window_) { |
88 DCHECK_EQ(gfx::GetXDisplay(), xdisplay_); | |
61 | 89 |
62 XEvent xclient; | 90 XClientMessageEvent xclient; |
Elliot Glaysher
2013/11/14 18:37:38
piman would disprove. He's told me several times t
sadrul
2013/11/14 19:06:41
Reverted (I hadn't meant to include this in the CL
| |
63 memset(&xclient, 0, sizeof(xclient)); | 91 memset(&xclient, 0, sizeof(xclient)); |
64 xclient.type = ClientMessage; | 92 xclient.type = ClientMessage; |
65 xclient.xclient.window = window; | 93 xclient.window = window; |
66 xclient.xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); | 94 xclient.message_type = atom_cache_.GetAtom("_NET_ACTIVE_WINDOW"); |
67 xclient.xclient.format = 32; | 95 xclient.format = 32; |
68 xclient.xclient.data.l[0] = 1; // Specified we are an app. | 96 xclient.data.l[0] = 1; // Specified we are an app. |
69 xclient.xclient.data.l[1] = CurrentTime; | 97 xclient.data.l[1] = CurrentTime; |
70 xclient.xclient.data.l[2] = None; | 98 xclient.data.l[2] = None; |
71 xclient.xclient.data.l[3] = 0; | 99 xclient.data.l[3] = 0; |
72 xclient.xclient.data.l[4] = 0; | 100 xclient.data.l[4] = 0; |
73 | 101 |
74 XSendEvent(xdisplay_, x_root_window_, False, | 102 XSendEvent(xdisplay_, x_root_window_, False, |
75 SubstructureRedirectMask | SubstructureNotifyMask, | 103 SubstructureRedirectMask | SubstructureNotifyMask, |
76 &xclient); | 104 (XEvent*)&xclient); |
105 } else { | |
106 XRaiseWindow(xdisplay_, window); | |
107 OnActiveWindowChanged(window); | |
108 } | |
77 } | 109 } |
78 | 110 |
79 bool X11DesktopHandler::IsActiveWindow(::Window window) const { | 111 bool X11DesktopHandler::IsActiveWindow(::Window window) const { |
80 return window == current_window_; | 112 return window == current_window_; |
81 } | 113 } |
82 | 114 |
83 bool X11DesktopHandler::Dispatch(const base::NativeEvent& event) { | 115 bool X11DesktopHandler::Dispatch(const base::NativeEvent& event) { |
84 // Check for a change to the active window. | 116 // Check for a change to the active window. |
85 switch (event->type) { | 117 switch (event->type) { |
86 case PropertyNotify: { | 118 case PropertyNotify: { |
(...skipping 30 matching lines...) Expand all Loading... | |
117 | 149 |
118 DesktopRootWindowHostX11* new_host = | 150 DesktopRootWindowHostX11* new_host = |
119 views::DesktopRootWindowHostX11::GetHostForXID(xid); | 151 views::DesktopRootWindowHostX11::GetHostForXID(xid); |
120 if (new_host) | 152 if (new_host) |
121 new_host->HandleNativeWidgetActivationChanged(true); | 153 new_host->HandleNativeWidgetActivationChanged(true); |
122 | 154 |
123 current_window_ = xid; | 155 current_window_ = xid; |
124 } | 156 } |
125 | 157 |
126 } // namespace views | 158 } // namespace views |
OLD | NEW |