| 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" | 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/monitor.h" | 18 #include "ui/aura/monitor.h" |
| 18 #include "ui/aura/monitor_manager.h" | 19 #include "ui/aura/monitor_manager.h" |
| 19 | 20 |
| 20 namespace aura { | 21 namespace aura { |
| 22 namespace internal { |
| 23 |
| 21 namespace { | 24 namespace { |
| 22 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { | 25 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { |
| 23 for (int m = 0; m < screen_resources->nmode; m++) { | 26 for (int m = 0; m < screen_resources->nmode; m++) { |
| 24 XRRModeInfo *mode = &screen_resources->modes[m]; | 27 XRRModeInfo *mode = &screen_resources->modes[m]; |
| 25 if (mode->id == current_mode) | 28 if (mode->id == current_mode) |
| 26 return mode; | 29 return mode; |
| 27 } | 30 } |
| 28 return NULL; | 31 return NULL; |
| 29 } | 32 } |
| 30 | 33 |
| 31 bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) { | 34 bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) { |
| 32 return lhs->bounds().y() < rhs->bounds().y(); | 35 return lhs->bounds().y() < rhs->bounds().y(); |
| 33 } | 36 } |
| 34 | 37 |
| 35 } // namespace internal | 38 } // namespace |
| 36 | 39 |
| 37 MonitorChangeObserverX11::MonitorChangeObserverX11() | 40 MonitorChangeObserverX11::MonitorChangeObserverX11() |
| 38 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), | 41 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), |
| 39 x_root_window_(DefaultRootWindow(xdisplay_)), | 42 x_root_window_(DefaultRootWindow(xdisplay_)), |
| 40 xrandr_event_base_(0) { | 43 xrandr_event_base_(0) { |
| 41 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask); | 44 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask); |
| 42 int error_base_ignored; | 45 int error_base_ignored; |
| 43 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); | 46 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); |
| 47 static_cast<DispatcherLinux*>( |
| 48 Env::GetInstance()->GetDispatcher())-> |
| 49 WindowDispatcherCreated(x_root_window_, this); |
| 44 } | 50 } |
| 45 | 51 |
| 46 MonitorChangeObserverX11::~MonitorChangeObserverX11() { | 52 MonitorChangeObserverX11::~MonitorChangeObserverX11() { |
| 53 static_cast<DispatcherLinux*>( |
| 54 Env::GetInstance()->GetDispatcher())-> |
| 55 WindowDispatcherDestroying(x_root_window_); |
| 47 } | 56 } |
| 48 | 57 |
| 49 bool MonitorChangeObserverX11::Dispatch(const XEvent* event) { | 58 base::MessagePumpDispatcher::DispatchStatus |
| 59 MonitorChangeObserverX11::Dispatch(XEvent* event) { |
| 50 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { | 60 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { |
| 51 NotifyMonitorChange(); | 61 NotifyMonitorChange(); |
| 52 return true; | 62 return base::MessagePumpDispatcher::EVENT_PROCESSED; |
| 53 } | 63 } |
| 54 return false; | 64 return base::MessagePumpDispatcher::EVENT_IGNORED; |
| 55 } | 65 } |
| 56 | 66 |
| 57 void MonitorChangeObserverX11::NotifyMonitorChange() { | 67 void MonitorChangeObserverX11::NotifyMonitorChange() { |
| 58 if (!MonitorManager::use_fullscreen_host_window()) | 68 if (!MonitorManager::use_fullscreen_host_window()) |
| 59 return; // Use the default monitor that monitor manager determined. | 69 return; // Use the default monitor that monitor manager determined. |
| 60 | 70 |
| 61 XRRScreenResources* screen_resources = | 71 XRRScreenResources* screen_resources = |
| 62 XRRGetScreenResources(xdisplay_, x_root_window_); | 72 XRRGetScreenResources(xdisplay_, x_root_window_); |
| 63 std::map<XID, XRRCrtcInfo*> crtc_info_map; | 73 std::map<XID, XRRCrtcInfo*> crtc_info_map; |
| 64 | 74 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // Free all allocated resources. | 111 // Free all allocated resources. |
| 102 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); | 112 for (std::map<XID, XRRCrtcInfo*>::const_iterator iter = crtc_info_map.begin(); |
| 103 iter != crtc_info_map.end(); ++iter) { | 113 iter != crtc_info_map.end(); ++iter) { |
| 104 XRRFreeCrtcInfo(iter->second); | 114 XRRFreeCrtcInfo(iter->second); |
| 105 } | 115 } |
| 106 XRRFreeScreenResources(screen_resources); | 116 XRRFreeScreenResources(screen_resources); |
| 107 | 117 |
| 108 // PowerManager lays out the outputs vertically. Sort them by Y | 118 // PowerManager lays out the outputs vertically. Sort them by Y |
| 109 // coordinates. | 119 // coordinates. |
| 110 std::sort(monitors.begin(), monitors.end(), CompareMonitorY); | 120 std::sort(monitors.begin(), monitors.end(), CompareMonitorY); |
| 111 aura::Env::GetInstance()->monitor_manager() | 121 Env::GetInstance()->monitor_manager() |
| 112 ->OnNativeMonitorsChanged(monitors); | 122 ->OnNativeMonitorsChanged(monitors); |
| 113 STLDeleteContainerPointers(monitors.begin(), monitors.end()); | 123 STLDeleteContainerPointers(monitors.begin(), monitors.end()); |
| 114 } | 124 } |
| 115 | 125 |
| 126 } // namespace internal |
| 116 } // namespace aura | 127 } // namespace aura |
| OLD | NEW |