OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/x11_property_change_waiter.h" | 5 #include "ui/views/test/x11_property_change_waiter.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "ui/base/x/x11_window_event_manager.h" |
10 #include "ui/events/platform/platform_event_source.h" | 11 #include "ui/events/platform/platform_event_source.h" |
11 #include "ui/events/platform/scoped_event_dispatcher.h" | 12 #include "ui/events/platform/scoped_event_dispatcher.h" |
12 #include "ui/gfx/x/x11_atom_cache.h" | 13 #include "ui/gfx/x/x11_atom_cache.h" |
13 | 14 |
14 namespace views { | 15 namespace views { |
15 | 16 |
16 X11PropertyChangeWaiter::X11PropertyChangeWaiter(XID window, | 17 X11PropertyChangeWaiter::X11PropertyChangeWaiter(XID window, |
17 const char* property) | 18 const char* property) |
18 : x_window_(window), | 19 : x_window_(window), property_(property), wait_(true) { |
19 property_(property), | |
20 wait_(true), | |
21 old_event_mask_(0) { | |
22 Display* display = gfx::GetXDisplay(); | 20 Display* display = gfx::GetXDisplay(); |
23 | 21 |
24 // Ensure that we are listening to PropertyNotify events for |window|. This | 22 // Ensure that we are listening to PropertyNotify events for |window|. This |
25 // is not the case for windows which were not created by | 23 // is not the case for windows which were not created by |
26 // DesktopWindowTreeHostX11. | 24 // DesktopWindowTreeHostX11. |
27 XWindowAttributes attributes; | 25 x_window_events_.reset( |
28 XGetWindowAttributes(display, x_window_, &attributes); | 26 new ui::XScopedEventSelector(x_window_, PropertyChangeMask)); |
29 old_event_mask_ = attributes.your_event_mask; | |
30 XSelectInput(display, x_window_, old_event_mask_ | PropertyChangeMask); | |
31 | 27 |
32 const char* kAtomsToCache[] = { property, NULL }; | 28 const char* kAtomsToCache[] = { property, NULL }; |
33 atom_cache_.reset(new ui::X11AtomCache(display, kAtomsToCache)); | 29 atom_cache_.reset(new ui::X11AtomCache(display, kAtomsToCache)); |
34 | 30 |
35 // Override the dispatcher so that we get events before | 31 // Override the dispatcher so that we get events before |
36 // DesktopWindowTreeHostX11 does. We must do this because | 32 // DesktopWindowTreeHostX11 does. We must do this because |
37 // DesktopWindowTreeHostX11 stops propagation. | 33 // DesktopWindowTreeHostX11 stops propagation. |
38 dispatcher_ = | 34 dispatcher_ = |
39 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(this); | 35 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(this); |
40 } | 36 } |
41 | 37 |
42 X11PropertyChangeWaiter::~X11PropertyChangeWaiter() { | 38 X11PropertyChangeWaiter::~X11PropertyChangeWaiter() {} |
43 XSelectInput(gfx::GetXDisplay(), x_window_, old_event_mask_); | |
44 } | |
45 | 39 |
46 void X11PropertyChangeWaiter::Wait() { | 40 void X11PropertyChangeWaiter::Wait() { |
47 if (!wait_) | 41 if (!wait_) |
48 return; | 42 return; |
49 | 43 |
50 base::RunLoop run_loop; | 44 base::RunLoop run_loop; |
51 quit_closure_ = run_loop.QuitClosure(); | 45 quit_closure_ = run_loop.QuitClosure(); |
52 run_loop.Run(); | 46 run_loop.Run(); |
53 | 47 |
54 dispatcher_.reset(); | 48 dispatcher_.reset(); |
(...skipping 20 matching lines...) Expand all Loading... |
75 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 69 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
76 } | 70 } |
77 | 71 |
78 wait_ = false; | 72 wait_ = false; |
79 if (!quit_closure_.is_null()) | 73 if (!quit_closure_.is_null()) |
80 quit_closure_.Run(); | 74 quit_closure_.Run(); |
81 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 75 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
82 } | 76 } |
83 | 77 |
84 } // namespace views | 78 } // namespace views |
OLD | NEW |