| 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/display_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_aurax11.h" | 14 #include "base/message_pump_aurax11.h" |
| 15 #include "ui/aura/dispatcher_linux.h" | 15 #include "ui/aura/dispatcher_linux.h" |
| 16 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 17 #include "ui/aura/monitor_manager.h" | 17 #include "ui/aura/display_manager.h" |
| 18 #include "ui/compositor/dip_util.h" | 18 #include "ui/compositor/dip_util.h" |
| 19 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
| 20 | 20 |
| 21 namespace aura { | 21 namespace aura { |
| 22 namespace internal { | 22 namespace internal { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // The DPI threshold to detect high density screen. | 26 // The DPI threshold to detect high density screen. |
| 27 // Higher DPI than this will use device_scale_factor=2. | 27 // Higher DPI than this will use device_scale_factor=2. |
| 28 // Note: This value has to be kept in sync with the mouse/touchpad driver | 28 // Note: This value has to be kept in sync with the mouse/touchpad driver |
| 29 // which controls mouse pointer acceleration. If you need to update this value, | 29 // which controls mouse pointer acceleration. If you need to update this value, |
| 30 // please update the bug (crosbug.com/31628) first and make sure that the | 30 // please update the bug (crosbug.com/31628) first and make sure that the |
| 31 // driver will use the same value. | 31 // driver will use the same value. |
| 32 // This value also has to be kept in sync with the value in | 32 // This value also has to be kept in sync with the value in |
| 33 // chromeos/monitor/output_configurator.cc. See crbug.com/130188 | 33 // chromeos/display/output_configurator.cc. See crbug.com/130188 |
| 34 const unsigned int kHighDensityDIPThreshold = 160; | 34 const unsigned int kHighDensityDIPThreshold = 160; |
| 35 | 35 |
| 36 // 1 inch in mm. | 36 // 1 inch in mm. |
| 37 const float kInchInMm = 25.4f; | 37 const float kInchInMm = 25.4f; |
| 38 | 38 |
| 39 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { | 39 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { |
| 40 for (int m = 0; m < screen_resources->nmode; m++) { | 40 for (int m = 0; m < screen_resources->nmode; m++) { |
| 41 XRRModeInfo *mode = &screen_resources->modes[m]; | 41 XRRModeInfo *mode = &screen_resources->modes[m]; |
| 42 if (mode->id == current_mode) | 42 if (mode->id == current_mode) |
| 43 return mode; | 43 return mode; |
| 44 } | 44 } |
| 45 return NULL; | 45 return NULL; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool CompareDisplayY(const gfx::Display& lhs, const gfx::Display& rhs) { | 48 bool CompareDisplayY(const gfx::Display& lhs, const gfx::Display& rhs) { |
| 49 return lhs.bounds_in_pixel().y() < rhs.bounds_in_pixel().y(); | 49 return lhs.bounds_in_pixel().y() < rhs.bounds_in_pixel().y(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 MonitorChangeObserverX11::MonitorChangeObserverX11() | 54 DisplayChangeObserverX11::DisplayChangeObserverX11() |
| 55 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), | 55 : xdisplay_(base::MessagePumpAuraX11::GetDefaultXDisplay()), |
| 56 x_root_window_(DefaultRootWindow(xdisplay_)), | 56 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 57 xrandr_event_base_(0) { | 57 xrandr_event_base_(0) { |
| 58 int error_base_ignored; | 58 int error_base_ignored; |
| 59 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); | 59 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); |
| 60 static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())-> | 60 static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())-> |
| 61 AddDispatcherForRootWindow(this); | 61 AddDispatcherForRootWindow(this); |
| 62 } | 62 } |
| 63 | 63 |
| 64 MonitorChangeObserverX11::~MonitorChangeObserverX11() { | 64 DisplayChangeObserverX11::~DisplayChangeObserverX11() { |
| 65 static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())-> | 65 static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())-> |
| 66 RemoveDispatcherForRootWindow(this); | 66 RemoveDispatcherForRootWindow(this); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool MonitorChangeObserverX11::Dispatch(const base::NativeEvent& event) { | 69 bool DisplayChangeObserverX11::Dispatch(const base::NativeEvent& event) { |
| 70 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { | 70 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { |
| 71 NotifyDisplayChange(); | 71 NotifyDisplayChange(); |
| 72 } | 72 } |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void MonitorChangeObserverX11::NotifyDisplayChange() { | 76 void DisplayChangeObserverX11::NotifyDisplayChange() { |
| 77 if (!MonitorManager::use_fullscreen_host_window()) | 77 if (!DisplayManager::use_fullscreen_host_window()) |
| 78 return; // Use the default monitor that monitor manager determined. | 78 return; // Use the default display that display manager determined. |
| 79 | 79 |
| 80 XRRScreenResources* screen_resources = | 80 XRRScreenResources* screen_resources = |
| 81 XRRGetScreenResources(xdisplay_, x_root_window_); | 81 XRRGetScreenResources(xdisplay_, x_root_window_); |
| 82 std::map<XID, XRRCrtcInfo*> crtc_info_map; | 82 std::map<XID, XRRCrtcInfo*> crtc_info_map; |
| 83 | 83 |
| 84 for (int c = 0; c < screen_resources->ncrtc; c++) { | 84 for (int c = 0; c < screen_resources->ncrtc; c++) { |
| 85 XID crtc_id = screen_resources->crtcs[c]; | 85 XID crtc_id = screen_resources->crtcs[c]; |
| 86 XRRCrtcInfo *crtc_info = | 86 XRRCrtcInfo *crtc_info = |
| 87 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); | 87 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); |
| 88 crtc_info_map[crtc_id] = crtc_info; | 88 crtc_info_map[crtc_id] = crtc_info; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 105 continue; | 105 continue; |
| 106 } | 106 } |
| 107 XRRModeInfo* mode = FindMode(screen_resources, crtc_info->mode); | 107 XRRModeInfo* mode = FindMode(screen_resources, crtc_info->mode); |
| 108 if (!mode) { | 108 if (!mode) { |
| 109 LOG(WARNING) << "Could not find a mode for the output: output=" << o; | 109 LOG(WARNING) << "Could not find a mode for the output: output=" << o; |
| 110 continue; | 110 continue; |
| 111 } | 111 } |
| 112 // Mirrored monitors have the same y coordinates. | 112 // Mirrored monitors have the same y coordinates. |
| 113 if (y_coords.find(crtc_info->y) != y_coords.end()) | 113 if (y_coords.find(crtc_info->y) != y_coords.end()) |
| 114 continue; | 114 continue; |
| 115 // TODO(oshima): Create unique ID for the monitor. | 115 // TODO(oshima): Create unique ID for the display. |
| 116 displays.push_back(gfx::Display( | 116 displays.push_back(gfx::Display( |
| 117 0, | 117 0, |
| 118 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); | 118 gfx::Rect(crtc_info->x, crtc_info->y, mode->width, mode->height))); |
| 119 | 119 |
| 120 float device_scale_factor = 1.0f; | 120 float device_scale_factor = 1.0f; |
| 121 if (output_info->mm_width > 0 && | 121 if (output_info->mm_width > 0 && |
| 122 (kInchInMm * mode->width / output_info->mm_width) > | 122 (kInchInMm * mode->width / output_info->mm_width) > |
| 123 kHighDensityDIPThreshold) { | 123 kHighDensityDIPThreshold) { |
| 124 device_scale_factor = 2.0f; | 124 device_scale_factor = 2.0f; |
| 125 } | 125 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 137 | 137 |
| 138 // PowerManager lays out the outputs vertically. Sort them by Y | 138 // PowerManager lays out the outputs vertically. Sort them by Y |
| 139 // coordinates. | 139 // coordinates. |
| 140 std::sort(displays.begin(), displays.end(), CompareDisplayY); | 140 std::sort(displays.begin(), displays.end(), CompareDisplayY); |
| 141 // TODO(oshima): Assisgn index as ID for now. Use unique ID. | 141 // TODO(oshima): Assisgn index as ID for now. Use unique ID. |
| 142 int id = 0; | 142 int id = 0; |
| 143 for (std::vector<gfx::Display>::iterator iter = displays.begin(); | 143 for (std::vector<gfx::Display>::iterator iter = displays.begin(); |
| 144 iter != displays.end(); ++iter, ++id) | 144 iter != displays.end(); ++iter, ++id) |
| 145 (*iter).set_id(id); | 145 (*iter).set_id(id); |
| 146 | 146 |
| 147 Env::GetInstance()->monitor_manager()->OnNativeMonitorsChanged(displays); | 147 Env::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace internal | 150 } // namespace internal |
| 151 } // namespace aura | 151 } // namespace aura |
| OLD | NEW |