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

Side by Side Diff: ash/monitor/monitor_change_observer_x11.cc

Issue 9808010: Keep the mouse cursor within desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 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 "ash/monitor/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 ash {
22 namespace internal {
23
24 using aura::Monitor;
25
21 namespace { 26 namespace {
22 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) { 27 XRRModeInfo* FindMode(XRRScreenResources* screen_resources, XID current_mode) {
23 for (int m = 0; m < screen_resources->nmode; m++) { 28 for (int m = 0; m < screen_resources->nmode; m++) {
24 XRRModeInfo *mode = &screen_resources->modes[m]; 29 XRRModeInfo *mode = &screen_resources->modes[m];
25 if (mode->id == current_mode) 30 if (mode->id == current_mode)
26 return mode; 31 return mode;
27 } 32 }
28 return NULL; 33 return NULL;
29 } 34 }
30 35
31 bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) { 36 bool CompareMonitorY(const Monitor* lhs, const Monitor* rhs) {
32 return lhs->bounds().y() < rhs->bounds().y(); 37 return lhs->bounds().y() < rhs->bounds().y();
33 } 38 }
34 39
35 } // namespace internal 40 } // namespace
36 41
37 MonitorChangeObserverX11::MonitorChangeObserverX11() 42 MonitorChangeObserverX11::MonitorChangeObserverX11()
38 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), 43 : xdisplay_(base::MessagePumpX::GetDefaultXDisplay()),
39 x_root_window_(DefaultRootWindow(xdisplay_)), 44 x_root_window_(DefaultRootWindow(xdisplay_)),
40 xrandr_event_base_(0) { 45 xrandr_event_base_(0) {
41 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask); 46 XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask);
42 int error_base_ignored; 47 int error_base_ignored;
43 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored); 48 XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored);
44 NotifyMonitorChange(); 49 NotifyMonitorChange();
50
51 static_cast<aura::DispatcherLinux*>(
52 aura::Env::GetInstance()->GetDispatcher())->
53 WindowDispatcherCreated(x_root_window_, this);
45 } 54 }
46 55
47 MonitorChangeObserverX11::~MonitorChangeObserverX11() { 56 MonitorChangeObserverX11::~MonitorChangeObserverX11() {
57 static_cast<aura::DispatcherLinux*>(
58 aura::Env::GetInstance()->GetDispatcher())->
59 WindowDispatcherDestroying(x_root_window_);
48 } 60 }
49 61
50 bool MonitorChangeObserverX11::Dispatch(const XEvent* event) { 62 base::MessagePumpDispatcher::DispatchStatus
63 MonitorChangeObserverX11::Dispatch(XEvent* event) {
51 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) { 64 if (event->type - xrandr_event_base_ == RRScreenChangeNotify) {
52 NotifyMonitorChange(); 65 NotifyMonitorChange();
53 return true; 66 return base::MessagePumpDispatcher::EVENT_PROCESSED;
54 } 67 }
55 return false; 68 return base::MessagePumpDispatcher::EVENT_IGNORED;
56 } 69 }
57 70
58 void MonitorChangeObserverX11::NotifyMonitorChange() { 71 void MonitorChangeObserverX11::NotifyMonitorChange() {
59 if (!MonitorManager::use_fullscreen_host_window()) 72 if (!aura::MonitorManager::use_fullscreen_host_window())
60 return; // Use the default monitor that monitor manager determined. 73 return; // Use the default monitor that monitor manager determined.
61 74
62 XRRScreenResources* screen_resources = 75 XRRScreenResources* screen_resources =
63 XRRGetScreenResources(xdisplay_, x_root_window_); 76 XRRGetScreenResources(xdisplay_, x_root_window_);
64 std::map<XID, XRRCrtcInfo*> crtc_info_map; 77 std::map<XID, XRRCrtcInfo*> crtc_info_map;
65 78
66 for (int c = 0; c < screen_resources->ncrtc; c++) { 79 for (int c = 0; c < screen_resources->ncrtc; c++) {
67 XID crtc_id = screen_resources->crtcs[c]; 80 XID crtc_id = screen_resources->crtcs[c];
68 XRRCrtcInfo *crtc_info = 81 XRRCrtcInfo *crtc_info =
69 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id); 82 XRRGetCrtcInfo(xdisplay_, screen_resources, crtc_id);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 XRRFreeScreenResources(screen_resources); 120 XRRFreeScreenResources(screen_resources);
108 121
109 // PowerManager lays out the outputs vertically. Sort them by Y 122 // PowerManager lays out the outputs vertically. Sort them by Y
110 // coordinates. 123 // coordinates.
111 std::sort(monitors.begin(), monitors.end(), CompareMonitorY); 124 std::sort(monitors.begin(), monitors.end(), CompareMonitorY);
112 aura::Env::GetInstance()->monitor_manager() 125 aura::Env::GetInstance()->monitor_manager()
113 ->OnNativeMonitorsChanged(monitors); 126 ->OnNativeMonitorsChanged(monitors);
114 STLDeleteContainerPointers(monitors.begin(), monitors.end()); 127 STLDeleteContainerPointers(monitors.begin(), monitors.end());
115 } 128 }
116 129
130 } // namespace internal
117 } // namespace aura 131 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698