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/gfx/screen.h" | 5 #include "ui/gfx/screen.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "ui/gfx/monitor.h" | 11 #include "ui/gfx/display.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 bool GetScreenWorkArea(gfx::Rect* out_rect) { | 15 bool GetScreenWorkArea(gfx::Rect* out_rect) { |
16 gboolean ok; | 16 gboolean ok; |
17 guchar* raw_data = NULL; | 17 guchar* raw_data = NULL; |
18 gint data_len = 0; | 18 gint data_len = 0; |
19 ok = gdk_property_get(gdk_get_default_root_window(), // a gdk window | 19 ok = gdk_property_get(gdk_get_default_root_window(), // a gdk window |
20 gdk_atom_intern("_NET_WORKAREA", FALSE), // property | 20 gdk_atom_intern("_NET_WORKAREA", FALSE), // property |
21 gdk_atom_intern("CARDINAL", FALSE), // property type | 21 gdk_atom_intern("CARDINAL", FALSE), // property type |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 gpointer data = NULL; | 96 gpointer data = NULL; |
97 gdk_window_get_user_data(window, &data); | 97 gdk_window_get_user_data(window, &data); |
98 GtkWidget* widget = reinterpret_cast<GtkWidget*>(data); | 98 GtkWidget* widget = reinterpret_cast<GtkWidget*>(data); |
99 if (!widget) | 99 if (!widget) |
100 return NULL; | 100 return NULL; |
101 widget = gtk_widget_get_toplevel(widget); | 101 widget = gtk_widget_get_toplevel(widget); |
102 return GTK_IS_WINDOW(widget) ? GTK_WINDOW(widget) : NULL; | 102 return GTK_IS_WINDOW(widget) ? GTK_WINDOW(widget) : NULL; |
103 } | 103 } |
104 | 104 |
105 // static | 105 // static |
106 gfx::Monitor Screen::GetMonitorNearestWindow(gfx::NativeView view) { | 106 gfx::Display Screen::GetMonitorNearestWindow(gfx::NativeView view) { |
107 gfx::Rect bounds = GetMonitorAreaNearestWindow(view); | 107 gfx::Rect bounds = GetMonitorAreaNearestWindow(view); |
108 // Do not use the _NET_WORKAREA here, this is supposed to be an area on a | 108 // Do not use the _NET_WORKAREA here, this is supposed to be an area on a |
109 // specific monitor, and _NET_WORKAREA is a hint from the WM that generally | 109 // specific monitor, and _NET_WORKAREA is a hint from the WM that generally |
110 // spans across all monitors. This would make the work area larger than the | 110 // spans across all monitors. This would make the work area larger than the |
111 // monitor. | 111 // monitor. |
112 // TODO(danakj) This is a work-around as there is no standard way to get this | 112 // TODO(danakj) This is a work-around as there is no standard way to get this |
113 // area, but it is a rect that we should be computing. The standard means | 113 // area, but it is a rect that we should be computing. The standard means |
114 // to compute this rect would be to watch all windows with | 114 // to compute this rect would be to watch all windows with |
115 // _NET_WM_STRUT(_PARTIAL) hints, and subtract their space from the physical | 115 // _NET_WM_STRUT(_PARTIAL) hints, and subtract their space from the physical |
116 // area of the monitor to construct a work area. | 116 // area of the display to construct a work area. |
117 // TODO(oshima): Implement ID and Observer. | 117 // TODO(oshima): Implement ID and Observer. |
118 return gfx::Monitor(0, bounds); | 118 return gfx::Display(0, bounds); |
119 } | 119 } |
120 | 120 |
121 // static | 121 // static |
122 gfx::Monitor Screen::GetMonitorNearestPoint(const gfx::Point& point) { | 122 gfx::Display Screen::GetMonitorNearestPoint(const gfx::Point& point) { |
123 GdkScreen* screen = gdk_screen_get_default(); | 123 GdkScreen* screen = gdk_screen_get_default(); |
124 gint monitor = gdk_screen_get_monitor_at_point(screen, point.x(), point.y()); | 124 gint monitor = gdk_screen_get_monitor_at_point(screen, point.x(), point.y()); |
125 GdkRectangle bounds; | 125 GdkRectangle bounds; |
126 gdk_screen_get_monitor_geometry(screen, monitor, &bounds); | 126 gdk_screen_get_monitor_geometry(screen, monitor, &bounds); |
127 // TODO(oshima): Implement ID and Observer. | 127 // TODO(oshima): Implement ID and Observer. |
128 return gfx::Monitor(0, gfx::Rect(bounds)); | 128 return gfx::Display(0, gfx::Rect(bounds)); |
129 } | 129 } |
130 | 130 |
131 // static | 131 // static |
132 gfx::Monitor Screen::GetPrimaryMonitor() { | 132 gfx::Display Screen::GetPrimaryMonitor() { |
133 gfx::Rect bounds = NativePrimaryMonitorBounds(); | 133 gfx::Rect bounds = NativePrimaryMonitorBounds(); |
134 // TODO(oshima): Implement ID and Observer. | 134 // TODO(oshima): Implement ID and Observer. |
135 gfx::Monitor monitor(0, bounds); | 135 gfx::Display display(0, bounds); |
136 gfx::Rect rect; | 136 gfx::Rect rect; |
137 if (GetScreenWorkArea(&rect)) { | 137 if (GetScreenWorkArea(&rect)) { |
138 monitor.set_work_area(rect.Intersect(bounds)); | 138 display.set_work_area(rect.Intersect(bounds)); |
139 } else { | 139 } else { |
140 // Return the best we've got. | 140 // Return the best we've got. |
141 monitor.set_work_area(bounds); | 141 display.set_work_area(bounds); |
142 } | 142 } |
143 return monitor; | 143 return display; |
144 } | 144 } |
145 | 145 |
146 // static | 146 // static |
147 gfx::Monitor Screen::GetMonitorMatching(const gfx::Rect& match_rect) { | 147 gfx::Display Screen::GetMonitorMatching(const gfx::Rect& match_rect) { |
148 // TODO(thestig) Implement multi-monitor support. | 148 // TODO(thestig) Implement multi-monitor support. |
149 return GetPrimaryMonitor(); | 149 return GetPrimaryMonitor(); |
150 } | 150 } |
151 | 151 |
152 // static | 152 // static |
153 int Screen::GetNumMonitors() { | 153 int Screen::GetNumMonitors() { |
154 // This query is kinda bogus for Linux -- do we want number of X screens? | 154 // This query is kinda bogus for Linux -- do we want number of X screens? |
155 // The number of monitors Xinerama has? We'll just use whatever GDK uses. | 155 // The number of monitors Xinerama has? We'll just use whatever GDK uses. |
156 GdkScreen* screen = gdk_screen_get_default(); | 156 GdkScreen* screen = gdk_screen_get_default(); |
157 return gdk_screen_get_n_monitors(screen); | 157 return gdk_screen_get_n_monitors(screen); |
158 } | 158 } |
159 | 159 |
160 } // namespace gfx | 160 } // namespace gfx |
OLD | NEW |