| 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/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" | |
| 16 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 17 #include "ui/aura/dispatcher_linux.h" | 16 #include "ui/aura/dispatcher_linux.h" |
| 18 #include "ui/aura/monitor.h" | |
| 19 #include "ui/aura/monitor_manager.h" | 17 #include "ui/aura/monitor_manager.h" |
| 18 #include "ui/gfx/monitor.h" |
| 20 | 19 |
| 21 namespace aura { | 20 namespace aura { |
| 22 namespace internal { | 21 namespace internal { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { | 24 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { |
| 26 for (int m = 0; m < screen_resources->nmode; m++) { | 25 for (int m = 0; m < screen_resources->nmode; m++) { |
| 27 XRRModeInfo *mode = &screen_resources->modes[m]; | 26 XRRModeInfo *mode = &screen_resources->modes[m]; |
| 28 if (mode->id == current_mode) | 27 if (mode->id == current_mode) |
| 29 return mode; | 28 return mode; |
| 30 } | 29 } |
| 31 return NULL; | 30 return NULL; |
| 32 } | 31 } |
| 33 | 32 |
| 34 bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) { | 33 bool CompareMonitorY(gfx::Monitor lhs, gfx::Monitor rhs) { |
| 35 return lhs->bounds().y() < rhs->bounds().y(); | 34 return lhs.bounds().y() < rhs.bounds().y(); |
| 36 } | 35 } |
| 37 | 36 |
| 38 } // namespace | 37 } // namespace |
| 39 | 38 |
| 40 MonitorChangeObserverX11::MonitorChangeObserverX11() | 39 MonitorChangeObserverX11::MonitorChangeObserverX11() |
| 41 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), | 40 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), |
| 42 x_root_window_(DefaultRootWindow(xdisplay_)), | 41 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 43 xrandr_event_base_(0) { | 42 xrandr_event_base_(0) { |
| 44 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask); | 43 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask); |
| 45 int error_base_ignored; | 44 int error_base_ignored; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 70 XRRGetScreenResources(xdisplay_, x_root_window_); | 69 XRRGetScreenResources(xdisplay_, x_root_window_); |
| 71 std::map<XID, XRRCrtcInfo*> crtc_info_map; | 70 std::map<XID, XRRCrtcInfo*> crtc_info_map; |
| 72 | 71 |
| 73 for (int c = 0; c < screen_resources->ncrtc; c++) { | 72 for (int c = 0; c < screen_resources->ncrtc; c++) { |
| 74 XID crtc_id = screen_resources->crtcs[c]; | 73 XID crtc_id = screen_resources->crtcs[c]; |
| 75 XRRCrtcInfo *crtc_info = | 74 XRRCrtcInfo *crtc_info = |
| 76 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); | 75 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); |
| 77 crtc_info_map[crtc_id] = crtc_info; | 76 crtc_info_map[crtc_id] = crtc_info; |
| 78 } | 77 } |
| 79 | 78 |
| 80 std::vector<const Monitor*> monitors; | 79 std::vector<gfx::Monitor> monitors; |
| 81 std::set<int> y_coords; | 80 std::set<int> y_coords; |
| 82 for (int o = 0; o < screen_resources->noutput; o++) { | 81 for (int o = 0; o < screen_resources->noutput; o++) { |
| 83 XRROutputInfo *output_info = | 82 XRROutputInfo *output_info = |
| 84 XRRGetOutputInfo(xdisplay_, | 83 XRRGetOutputInfo(xdisplay_, |
| 85 screen_resources, | 84 screen_resources, |
| 86 screen_resources->outputs[o]); | 85 screen_resources->outputs[o]); |
| 87 if (output_info->connection != RR_Connected) { | 86 if (output_info->connection != RR_Connected) { |
| 88 XRRFreeOutputInfo(output_info); | 87 XRRFreeOutputInfo(output_info); |
| 89 continue; | 88 continue; |
| 90 } | 89 } |
| 91 XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; | 90 XRRCrtcInfo* crtc_info = crtc_info_map[output_info->crtc]; |
| 92 if (!crtc_info) { | 91 if (!crtc_info) { |
| 93 LOG(WARNING) << "Crtc not found for output"; | 92 LOG(WARNING) << "Crtc not found for output"; |
| 94 continue; | 93 continue; |
| 95 } | 94 } |
| 96 XRRModeInfo* mode = FindMode(screen_resources, crtc_info->mode); | 95 XRRModeInfo* mode = FindMode(screen_resources, crtc_info->mode); |
| 97 CHECK(mode); | 96 CHECK(mode); |
| 98 // Mirrored monitors have the same y coordinates. | 97 // Mirrored monitors have the same y coordinates. |
| 99 if (y_coords.find(crtc_info->y) != y_coords.end()) | 98 if (y_coords.find(crtc_info->y) != y_coords.end()) |
| 100 continue; | 99 continue; |
| 101 Monitor* monitor = new Monitor; | 100 // TODO(oshima): Create unique ID for the monitor. |
| 102 monitor->set_bounds(gfx::Rect(crtc_info->x, crtc_info->y, | 101 monitors.push_back(gfx::Monitor( |
| 103 mode->width, mode->height)); | 102 0, |
| 104 monitors.push_back(monitor); | 103 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); |
| 105 y_coords.insert(crtc_info->y); | 104 y_coords.insert(crtc_info->y); |
| 106 XRRFreeOutputInfo(output_info); | 105 XRRFreeOutputInfo(output_info); |
| 107 } | 106 } |
| 108 | 107 |
| 109 // Free all allocated resources. | 108 // Free all allocated resources. |
| 110 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); | 109 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); |
| 111 iter != crtc_info_map.end(); ++iter) { | 110 iter != crtc_info_map.end(); ++iter) { |
| 112 XRRFreeCrtcInfo(iter->second); | 111 XRRFreeCrtcInfo(iter->second); |
| 113 } | 112 } |
| 114 XRRFreeScreenResources(screen_resources); | 113 XRRFreeScreenResources(screen_resources); |
| 115 | 114 |
| 116 // PowerManager lays out the outputs vertically. Sort them by Y | 115 // PowerManager lays out the outputs vertically. Sort them by Y |
| 117 // coordinates. | 116 // coordinates. |
| 118 std::sort(monitors.begin(), monitors.end(), CompareMonitorY); | 117 std::sort(monitors.begin(), monitors.end(), CompareMonitorY); |
| 118 // TODO(oshima): Assisgn index as ID for now. Use unique ID. |
| 119 int id = 0; |
| 120 for (std::vector<gfx::Monitor>::iterator iter = monitors.begin(); |
| 121 iter != monitors.end(); ++iter, ++id) |
| 122 (*iter).set_id(id); |
| 123 |
| 119 Env::GetInstance()->monitor_manager() | 124 Env::GetInstance()->monitor_manager() |
| 120 ->OnNativeMonitorsChanged(monitors); | 125 ->OnNativeMonitorsChanged(monitors); |
| 121 STLDeleteContainerPointers(monitors.begin(), monitors.end()); | |
| 122 } | 126 } |
| 123 | 127 |
| 124 } // namespace internal | 128 } // namespace internal |
| 125 } // namespace aura | 129 } // namespace aura |
| OLD | NEW |