Index: ui/gfx/screen_gtk.cc |
diff --git a/ui/gfx/screen_gtk.cc b/ui/gfx/screen_gtk.cc |
index 42799b70d5dcbff0323e1f344ef838eb3f021cff..579ad1a2852413d5f81e38da35bb6a1dd95ef4b0 100644 |
--- a/ui/gfx/screen_gtk.cc |
+++ b/ui/gfx/screen_gtk.cc |
@@ -9,6 +9,45 @@ |
#include "base/logging.h" |
+namespace { |
+ |
+bool GetScreenWorkArea(gfx::Rect* out_rect) { |
+ gboolean ok; |
+ guchar* raw_data = NULL; |
+ gint data_len = 0; |
+ ok = gdk_property_get(gdk_get_default_root_window(), // a gdk window |
+ gdk_atom_intern("_NET_WORKAREA", FALSE), // property |
+ gdk_atom_intern("CARDINAL", FALSE), // property type |
+ 0, // byte offset into property |
+ 0xff, // property length to retrieve |
+ false, // delete property after retrieval? |
+ NULL, // returned property type |
+ NULL, // returned data format |
+ &data_len, // returned data len |
+ &raw_data); // returned data |
+ if (!ok) |
+ return false; |
+ |
+ // We expect to get four longs back: x, y, width, height. |
+ if (data_len < static_cast<gint>(4 * sizeof(glong))) { |
+ NOTREACHED(); |
+ g_free(raw_data); |
+ return false; |
+ } |
+ |
+ glong* data = reinterpret_cast<glong*>(raw_data); |
+ gint x = data[0]; |
+ gint y = data[1]; |
+ gint width = data[2]; |
+ gint height = data[3]; |
+ g_free(raw_data); |
+ |
+ out_rect->SetRect(x, y, width, height); |
+ return true; |
+} |
+ |
+} // namespace |
+ |
namespace gfx { |
// static |
@@ -64,6 +103,30 @@ gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) { |
} |
// static |
+gfx::Rect Screen::GetPrimaryMonitorWorkArea() { |
+ gfx::Rect rect; |
+ if (GetScreenWorkArea(&rect)) |
+ return rect.Intersect(GetPrimaryMonitorBounds()); |
+ |
+ // Return the best we've got. |
+ return GetPrimaryMonitorBounds(); |
+} |
+ |
+// static |
+gfx::Rect Screen::GetPrimaryMonitorBounds() { |
+ GdkScreen* screen = gdk_screen_get_default(); |
+ GdkRectangle rect; |
+ gdk_screen_get_monitor_geometry(screen, 0, &rect); |
+ return gfx::Rect(rect); |
+} |
+ |
+// static |
+gfx::Rect Screen::GetMonitorWorkAreaMatching(const gfx::Rect& match_rect) { |
+ // TODO(thestig) Implement multi-monitor support. |
+ return GetPrimaryMonitorWorkArea(); |
+} |
+ |
+// static |
gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() { |
GdkWindow* window = gdk_window_at_pointer(NULL, NULL); |
if (!window) |