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

Side by Side Diff: ui/aura/monitor_change_observer_x11.cc

Issue 9960042: Refactor screen/monitor so that gfx::Screen returns monitor object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix command line Created 8 years, 8 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 | Annotate | Revision Log
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/aura/monitor_change_observer_x11.h" 5 #include "ui/aura/monitor_change_observer_x11.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include <X11/extensions/Xrandr.h> 12 #include <X11/extensions/Xrandr.h>
13 13
14 #include "base/message_pump_x.h" 14 #include "base/message_pump_x.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
17 #include "ui/aura/dispatcher_linux.h" 17 #include "ui/aura/dispatcher_linux.h"
18 #include "ui/aura/monitor.h" 18 #include "ui/aura/monitor_aura.h"
19 #include "ui/aura/monitor_manager.h" 19 #include "ui/aura/monitor_manager.h"
20 20
21 namespace aura { 21 namespace aura {
22 namespace internal { 22 namespace internal {
23 23
24 namespace { 24 namespace {
25 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { 25 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) {
26 for (int m = 0; m < screen_resources->nmode; m++) { 26 for (int m = 0; m < screen_resources->nmode; m++) {
27 XRRModeInfo *mode = &screen_resources->modes[m]; 27 XRRModeInfo *mode = &screen_resources->modes[m];
28 if (mode->id == current_mode) 28 if (mode->id == current_mode)
29 return mode; 29 return mode;
30 } 30 }
31 return NULL; 31 return NULL;
32 } 32 }
33 33
34 bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) { 34 bool CompareMonitorY(const MonitorAura* lhs, const MonitorAura* rhs) {
35 return lhs->bounds().y() < rhs->bounds().y(); 35 return lhs->bounds().y() < rhs->bounds().y();
36 } 36 }
37 37
38 } // namespace 38 } // namespace
39 39
40 MonitorChangeObserverX11::MonitorChangeObserverX11() 40 MonitorChangeObserverX11::MonitorChangeObserverX11()
41 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), 41 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()),
42 x_root_window_(DefaultRootWindow(xdisplay_)), 42 x_root_window_(DefaultRootWindow(xdisplay_)),
43 xrandr_event_base_(0) { 43 xrandr_event_base_(0) {
44 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask); 44 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask);
(...skipping 25 matching lines...) Expand all
70 XRRGetScreenResources(xdisplay_, x_root_window_); 70 XRRGetScreenResources(xdisplay_, x_root_window_);
71 std::map<XID, XRRCrtcInfo*> crtc_info_map; 71 std::map<XID, XRRCrtcInfo*> crtc_info_map;
72 72
73 for (int c = 0; c < screen_resources->ncrtc; c++) { 73 for (int c = 0; c < screen_resources->ncrtc; c++) {
74 XID crtc_id = screen_resources->crtcs[c]; 74 XID crtc_id = screen_resources->crtcs[c];
75 XRRCrtcInfo *crtc_info = 75 XRRCrtcInfo *crtc_info =
76 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); 76 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id);
77 crtc_info_map[crtc_id] = crtc_info; 77 crtc_info_map[crtc_id] = crtc_info;
78 } 78 }
79 79
80 std::vector<const Monitor*> monitors; 80 std::vector<const MonitorAura*> monitors;
81 std::set<int> y_coords; 81 std::set<int> y_coords;
82 for (int o = 0; o < screen_resources->noutput; o++) { 82 for (int o = 0; o < screen_resources->noutput; o++) {
83 XRROutputInfo *output_info = 83 XRROutputInfo *output_info =
84 XRRGetOutputInfo(xdisplay_, 84 XRRGetOutputInfo(xdisplay_,
85 screen_resources, 85 screen_resources,
86 screen_resources->outputs[o]); 86 screen_resources->outputs[o]);
87 if (output_info->connection != RR_Connected) { 87 if (output_info->connection != RR_Connected) {
88 XRRFreeOutputInfo(output_info); 88 XRRFreeOutputInfo(output_info);
89 continue; 89 continue;
90 } 90 }
91 XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; 91 XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc];
92 if (!crtc_info) { 92 if (!crtc_info) {
93 LOG(WARNING) << "Crtc not found for output"; 93 LOG(WARNING) << "Crtc not found for output";
94 continue; 94 continue;
95 } 95 }
96 XRRModeInfo* mode = FindMode(screen_resources, crtc_info->mode); 96 XRRModeInfo* mode = FindMode(screen_resources, crtc_info->mode);
97 CHECK(mode); 97 CHECK(mode);
98 // Mirrored monitors have the same y coordinates. 98 // Mirrored monitors have the same y coordinates.
99 if (y_coords.find(crtc_info->y) != y_coords.end()) 99 if (y_coords.find(crtc_info->y) != y_coords.end())
100 continue; 100 continue;
101 Monitor* monitor = new Monitor; 101 MonitorAura* monitor = new MonitorAura;
102 monitor->set_bounds(gfx::Rect(crtc_info->x, crtc_info->y, 102 monitor->set_bounds(gfx::Rect(crtc_info->x, crtc_info->y,
103 mode->width, mode->height)); 103 mode->width, mode->height));
104 monitors.push_back(monitor); 104 monitors.push_back(monitor);
105 y_coords.insert(crtc_info->y); 105 y_coords.insert(crtc_info->y);
106 XRRFreeOutputInfo(output_info); 106 XRRFreeOutputInfo(output_info);
107 } 107 }
108 108
109 // Free all allocated resources. 109 // Free all allocated resources.
110 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); 110 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin();
111 iter != crtc_info_map.end(); ++iter) { 111 iter != crtc_info_map.end(); ++iter) {
112 XRRFreeCrtcInfo(iter->second); 112 XRRFreeCrtcInfo(iter->second);
113 } 113 }
114 XRRFreeScreenResources(screen_resources); 114 XRRFreeScreenResources(screen_resources);
115 115
116 // PowerManager lays out the outputs vertically. Sort them by Y 116 // PowerManager lays out the outputs vertically. Sort them by Y
117 // coordinates. 117 // coordinates.
118 std::sort(monitors.begin(), monitors.end(), CompareMonitorY); 118 std::sort(monitors.begin(), monitors.end(), CompareMonitorY);
119 Env::GetInstance()->monitor_manager() 119 Env::GetInstance()->monitor_manager()
120 ->OnNativeMonitorsChanged(monitors); 120 ->OnNativeMonitorsChanged(monitors);
121 STLDeleteContainerPointers(monitors.begin(), monitors.end()); 121 STLDeleteContainerPointers(monitors.begin(), monitors.end());
122 } 122 }
123 123
124 } // namespace internal 124 } // namespace internal
125 } // namespace aura 125 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698