Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_screen_x11.cc

Issue 341983008: Listen to Display reconfiguration and notify DisplayObservers on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mac_display
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/desktop_screen_x11.h" 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
6 6
7 #include <X11/extensions/Xrandr.h> 7 #include <X11/extensions/Xrandr.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 // It clashes with out RootWindow. 10 // It clashes with out RootWindow.
11 #undef RootWindow 11 #undef RootWindow
12 12
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
19 #include "ui/display/util/display_util.h" 19 #include "ui/display/util/display_util.h"
20 #include "ui/display/util/x11/edid_parser_x11.h" 20 #include "ui/display/util/x11/edid_parser_x11.h"
21 #include "ui/events/platform/platform_event_source.h" 21 #include "ui/events/platform/platform_event_source.h"
22 #include "ui/gfx/display.h" 22 #include "ui/gfx/display.h"
23 #include "ui/gfx/display_observer.h"
24 #include "ui/gfx/native_widget_types.h" 23 #include "ui/gfx/native_widget_types.h"
25 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
26 #include "ui/gfx/x/x11_types.h" 25 #include "ui/gfx/x/x11_types.h"
27 #include "ui/views/widget/desktop_aura/desktop_screen.h" 26 #include "ui/views/widget/desktop_aura/desktop_screen.h"
28 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" 27 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
29 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h" 28 #include "ui/views/widget/desktop_aura/x11_topmost_window_finder.h"
30 29
31 namespace { 30 namespace {
32 31
33 // The delay to perform configuration after RRNotify. See the comment 32 // The delay to perform configuration after RRNotify. See the comment
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } else { 102 } else {
104 displays_ = GetFallbackDisplayList(); 103 displays_ = GetFallbackDisplayList();
105 } 104 }
106 } 105 }
107 106
108 DesktopScreenX11::~DesktopScreenX11() { 107 DesktopScreenX11::~DesktopScreenX11() {
109 if (has_xrandr_ && ui::PlatformEventSource::GetInstance()) 108 if (has_xrandr_ && ui::PlatformEventSource::GetInstance())
110 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 109 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
111 } 110 }
112 111
113 void DesktopScreenX11::ProcessDisplayChange(
114 const std::vector<gfx::Display>& incoming) {
115 std::vector<gfx::Display> old_displays = displays_;
116 displays_ = incoming;
117
118 typedef std::vector<gfx::Display>::const_iterator DisplayIt;
119 std::vector<gfx::Display>::const_iterator old_it = old_displays.begin();
120 for (; old_it != old_displays.end(); ++old_it) {
121 bool found = false;
122 for (std::vector<gfx::Display>::const_iterator new_it =
123 displays_.begin(); new_it != displays_.end(); ++new_it) {
124 if (old_it->id() == new_it->id()) {
125 found = true;
126 break;
127 }
128 }
129
130 if (!found) {
131 FOR_EACH_OBSERVER(gfx::DisplayObserver, observer_list_,
132 OnDisplayRemoved(*old_it));
133 }
134 }
135
136 std::vector<gfx::Display>::const_iterator new_it = displays_.begin();
137 for (; new_it != displays_.end(); ++new_it) {
138 bool found = false;
139 for (std::vector<gfx::Display>::const_iterator old_it =
140 old_displays.begin(); old_it != old_displays.end(); ++old_it) {
141 if (new_it->id() != old_it->id())
142 continue;
143
144 uint32_t metrics = gfx::DisplayObserver::DISPLAY_METRIC_NONE;
145
146 if (new_it->bounds() != old_it->bounds())
147 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS;
148
149 if (new_it->rotation() != old_it->rotation())
150 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_ROTATION;
151
152 if (new_it->work_area() != old_it->work_area())
153 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
154
155 if (new_it->device_scale_factor() != old_it->device_scale_factor())
156 metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
157
158 if (metrics != gfx::DisplayObserver::DISPLAY_METRIC_NONE) {
159 FOR_EACH_OBSERVER(gfx::DisplayObserver,
160 observer_list_,
161 OnDisplayMetricsChanged(*new_it, metrics));
162 }
163
164 found = true;
165 break;
166 }
167
168 if (!found) {
169 FOR_EACH_OBSERVER(gfx::DisplayObserver, observer_list_,
170 OnDisplayAdded(*new_it));
171 }
172 }
173 }
174
175 //////////////////////////////////////////////////////////////////////////////// 112 ////////////////////////////////////////////////////////////////////////////////
176 // DesktopScreenX11, gfx::Screen implementation: 113 // DesktopScreenX11, gfx::Screen implementation:
177 114
178 bool DesktopScreenX11::IsDIPEnabled() { 115 bool DesktopScreenX11::IsDIPEnabled() {
179 return true; 116 return true;
180 } 117 }
181 118
182 gfx::Point DesktopScreenX11::GetCursorScreenPoint() { 119 gfx::Point DesktopScreenX11::GetCursorScreenPoint() {
183 TRACE_EVENT0("views", "DesktopScreenX11::GetCursorScreenPoint()"); 120 TRACE_EVENT0("views", "DesktopScreenX11::GetCursorScreenPoint()");
184 121
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 203 }
267 // Fallback to the primary display if there is no matching display. 204 // Fallback to the primary display if there is no matching display.
268 return matching ? *matching : GetPrimaryDisplay(); 205 return matching ? *matching : GetPrimaryDisplay();
269 } 206 }
270 207
271 gfx::Display DesktopScreenX11::GetPrimaryDisplay() const { 208 gfx::Display DesktopScreenX11::GetPrimaryDisplay() const {
272 return displays_.front(); 209 return displays_.front();
273 } 210 }
274 211
275 void DesktopScreenX11::AddObserver(gfx::DisplayObserver* observer) { 212 void DesktopScreenX11::AddObserver(gfx::DisplayObserver* observer) {
276 observer_list_.AddObserver(observer); 213 change_notifier_.AddObserver(observer);
277 } 214 }
278 215
279 void DesktopScreenX11::RemoveObserver(gfx::DisplayObserver* observer) { 216 void DesktopScreenX11::RemoveObserver(gfx::DisplayObserver* observer) {
280 observer_list_.RemoveObserver(observer); 217 change_notifier_.RemoveObserver(observer);
281 } 218 }
282 219
283 bool DesktopScreenX11::CanDispatchEvent(const ui::PlatformEvent& event) { 220 bool DesktopScreenX11::CanDispatchEvent(const ui::PlatformEvent& event) {
284 return event->type - xrandr_event_base_ == RRScreenChangeNotify || 221 return event->type - xrandr_event_base_ == RRScreenChangeNotify ||
285 event->type - xrandr_event_base_ == RRNotify; 222 event->type - xrandr_event_base_ == RRNotify;
286 } 223 }
287 224
288 uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) { 225 uint32_t DesktopScreenX11::DispatchEvent(const ui::PlatformEvent& event) {
289 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { 226 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) {
290 // Pass the event through to xlib. 227 // Pass the event through to xlib.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 346
410 XRRFreeScreenResources(resources); 347 XRRFreeScreenResources(resources);
411 348
412 if (displays.empty()) 349 if (displays.empty())
413 return GetFallbackDisplayList(); 350 return GetFallbackDisplayList();
414 351
415 return displays; 352 return displays;
416 } 353 }
417 354
418 void DesktopScreenX11::ConfigureTimerFired() { 355 void DesktopScreenX11::ConfigureTimerFired() {
419 std::vector<gfx::Display> new_displays = BuildDisplaysFromXRandRInfo(); 356 std::vector<gfx::Display> old_displays = displays_;
420 ProcessDisplayChange(new_displays); 357 displays_ = BuildDisplaysFromXRandRInfo();
358
359 change_notifier_.NotifyDisplaysChanged(old_displays, displays_);
421 } 360 }
422 361
423 //////////////////////////////////////////////////////////////////////////////// 362 ////////////////////////////////////////////////////////////////////////////////
424 363
425 gfx::Screen* CreateDesktopScreen() { 364 gfx::Screen* CreateDesktopScreen() {
426 return new DesktopScreenX11; 365 return new DesktopScreenX11;
427 } 366 }
428 367
429 } // namespace views 368 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_screen_x11.h ('k') | ui/views/widget/desktop_aura/desktop_screen_x11_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698