summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/screen_gtk.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/gfx/screen_gtk.cc')
-rw-r--r--chromium/ui/gfx/screen_gtk.cc84
1 files changed, 53 insertions, 31 deletions
diff --git a/chromium/ui/gfx/screen_gtk.cc b/chromium/ui/gfx/screen_gtk.cc
index 8ef803dca1f..ac2464bbbd7 100644
--- a/chromium/ui/gfx/screen_gtk.cc
+++ b/chromium/ui/gfx/screen_gtk.cc
@@ -47,14 +47,20 @@ bool GetScreenWorkArea(gfx::Rect* out_rect) {
return true;
}
-gfx::Rect NativePrimaryMonitorBounds() {
- GdkScreen* screen = gdk_screen_get_default();
- GdkRectangle rect;
- gdk_screen_get_monitor_geometry(screen, 0, &rect);
- return gfx::Rect(rect);
+gfx::Display GetDisplayForMonitorNum(GdkScreen* screen, gint monitor_num) {
+ GdkRectangle bounds;
+ gdk_screen_get_monitor_geometry(screen, monitor_num, &bounds);
+ // Use |monitor_num| as display id.
+ gfx::Display display(monitor_num, gfx::Rect(bounds));
+ if (gdk_screen_get_primary_monitor(screen) == monitor_num) {
+ gfx::Rect rect;
+ if (GetScreenWorkArea(&rect))
+ display.set_work_area(gfx::IntersectRects(rect, display.bounds()));
+ }
+ return display;
}
-gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view) {
+gfx::Display GetMonitorAreaNearestWindow(gfx::NativeView view) {
GdkScreen* screen = gdk_screen_get_default();
gint monitor_num = 0;
if (view && GTK_IS_WINDOW(view)) {
@@ -66,9 +72,7 @@ gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view) {
screen,
gtk_widget_get_window(top_level));
}
- GdkRectangle bounds;
- gdk_screen_get_monitor_geometry(screen, monitor_num, &bounds);
- return gfx::Rect(bounds);
+ return GetDisplayForMonitorNum(screen, monitor_num);
}
class ScreenGtk : public gfx::Screen {
@@ -90,7 +94,7 @@ class ScreenGtk : public gfx::Screen {
}
// Returns the window under the cursor.
- virtual gfx::NativeWindow GetWindowAtCursorScreenPoint() OVERRIDE {
+ virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE {
GdkWindow* window = gdk_window_at_pointer(NULL, NULL);
if (!window)
return NULL;
@@ -104,20 +108,34 @@ class ScreenGtk : public gfx::Screen {
return GTK_IS_WINDOW(widget) ? GTK_WINDOW(widget) : NULL;
}
+ virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
+ OVERRIDE {
+ NOTIMPLEMENTED();
+ return NULL;
+ }
+
// Returns the number of displays.
// Mirrored displays are excluded; this method is intended to return the
// number of distinct, usable displays.
- virtual int GetNumDisplays() OVERRIDE {
+ virtual int GetNumDisplays() const OVERRIDE {
// This query is kinda bogus for Linux -- do we want number of X screens?
// The number of monitors Xinerama has? We'll just use whatever GDK uses.
GdkScreen* screen = gdk_screen_get_default();
return gdk_screen_get_n_monitors(screen);
}
+ virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
+ GdkScreen* screen = gdk_screen_get_default();
+ gint num_of_displays = gdk_screen_get_n_monitors(screen);
+ std::vector<gfx::Display> all_displays;
+ for (gint i = 0; i < num_of_displays; ++i)
+ all_displays.push_back(GetDisplayForMonitorNum(screen, i));
+ return all_displays;
+ }
+
// Returns the display nearest the specified window.
virtual gfx::Display GetDisplayNearestWindow(
gfx::NativeView view) const OVERRIDE {
- gfx::Rect bounds = GetMonitorAreaNearestWindow(view);
// Do not use the _NET_WORKAREA here, this is supposed to be an area on a
// specific monitor, and _NET_WORKAREA is a hint from the WM that
// generally spans across all monitors. This would make the work area
@@ -127,8 +145,8 @@ class ScreenGtk : public gfx::Screen {
// means to compute this rect would be to watch all windows with
// _NET_WM_STRUT(_PARTIAL) hints, and subtract their space from the
// physical area of the display to construct a work area.
- // TODO(oshima): Implement ID and Observer.
- return gfx::Display(0, bounds);
+ // TODO(oshima): Implement Observer.
+ return GetMonitorAreaNearestWindow(view);
}
// Returns the the display nearest the specified point.
@@ -137,32 +155,36 @@ class ScreenGtk : public gfx::Screen {
GdkScreen* screen = gdk_screen_get_default();
gint monitor = gdk_screen_get_monitor_at_point(
screen, point.x(), point.y());
- GdkRectangle bounds;
- gdk_screen_get_monitor_geometry(screen, monitor, &bounds);
- // TODO(oshima): Implement ID and Observer.
- return gfx::Display(0, gfx::Rect(bounds));
+ // TODO(oshima): Implement Observer.
+ return GetDisplayForMonitorNum(screen, monitor);
}
// Returns the display that most closely intersects the provided bounds.
virtual gfx::Display GetDisplayMatching(
const gfx::Rect& match_rect) const OVERRIDE {
- // TODO(thestig) Implement multi-monitor support.
- return GetPrimaryDisplay();
+ std::vector<gfx::Display> displays = GetAllDisplays();
+ gfx::Display maxIntersectDisplay;
+ gfx::Rect maxIntersection;
+ for (std::vector<gfx::Display>::iterator it = displays.begin();
+ it != displays.end(); ++it) {
+ gfx::Rect displayIntersection = it->bounds();
+ displayIntersection.Intersect(match_rect);
+ if (displayIntersection.size().GetArea() >
+ maxIntersection.size().GetArea()) {
+ maxIntersectDisplay = *it;
+ maxIntersection = displayIntersection;
+ }
+ }
+ return maxIntersectDisplay.is_valid() ?
+ maxIntersectDisplay : GetPrimaryDisplay();
}
// Returns the primary display.
virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
- gfx::Rect bounds = NativePrimaryMonitorBounds();
- // TODO(oshima): Implement ID and Observer.
- gfx::Display display(0, bounds);
- gfx::Rect rect;
- if (GetScreenWorkArea(&rect)) {
- display.set_work_area(gfx::IntersectRects(rect, bounds));
- } else {
- // Return the best we've got.
- display.set_work_area(bounds);
- }
- return display;
+ GdkScreen* screen = gdk_screen_get_default();
+ gint primary_monitor_index = gdk_screen_get_primary_monitor(screen);
+ // TODO(oshima): Implement Observer.
+ return GetDisplayForMonitorNum(screen, primary_monitor_index);
}
virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {