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

Unified Diff: ui/gfx/screen_gtk.cc

Issue 8549008: Extract MonitorInfoProvider from WindowSizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add docs Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/screen_aura.cc ('k') | ui/gfx/screen_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « ui/gfx/screen_aura.cc ('k') | ui/gfx/screen_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698