diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-27 20:53:51 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-27 20:53:51 +0000 |
commit | 4e62b3d0ac881be70f5dca51ffc249522d0db7ab (patch) | |
tree | 224012928bb69005c305040190b209cf3faf9376 /ui/base/x | |
parent | 40b38c935a5272aee9cb0924366a9aa4cad32e7b (diff) | |
download | chromium_src-4e62b3d0ac881be70f5dca51ffc249522d0db7ab.zip chromium_src-4e62b3d0ac881be70f5dca51ffc249522d0db7ab.tar.gz chromium_src-4e62b3d0ac881be70f5dca51ffc249522d0db7ab.tar.bz2 |
Fix tab dragging in unity2d
Unity 2d creates non-rectangled or 'shaped' X11 windows. These windows have a
big bounding box according to XGetGeometry but should actually only interact
with part of the screen, which confuses the tab strip dragging code. This
checks if a point is actually inside the ShapeInput list when this extension
is supported by the X display
BUG=114985
Review URL: https://chromiumcodereview.appspot.com/10990010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159111 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/x')
-rw-r--r-- | ui/base/x/x11_util.cc | 56 | ||||
-rw-r--r-- | ui/base/x/x11_util.h | 3 |
2 files changed, 52 insertions, 7 deletions
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc index 8a1d5e6..4cc5dc3 100644 --- a/ui/base/x/x11_util.cc +++ b/ui/base/x/x11_util.cc @@ -19,6 +19,7 @@ #include <X11/extensions/Xrandr.h> #include <X11/extensions/randr.h> +#include <X11/extensions/shape.h> #include "base/bind.h" #include "base/command_line.h" @@ -310,19 +311,21 @@ class XButtonMap { }; bool IsRandRAvailable() { - static bool is_randr_available = false; - static bool is_randr_availability_cached = false; - if (is_randr_availability_cached) - return is_randr_available; - int randr_version_major = 0; int randr_version_minor = 0; - is_randr_available = XRRQueryVersion( + static bool is_randr_available = XRRQueryVersion( GetXDisplay(), &randr_version_major, &randr_version_minor); - is_randr_availability_cached = true; return is_randr_available; } +bool IsShapeAvailable() { + int dummy; + static bool is_shape_available = + XShapeQueryExtension(ui::GetXDisplay(), &dummy, &dummy); + return is_shape_available; + +} + } // namespace bool XDisplayExists() { @@ -612,6 +615,45 @@ bool GetWindowRect(XID window, gfx::Rect* rect) { return true; } + +bool WindowContainsPoint(XID window, gfx::Point screen_loc) { + gfx::Rect window_rect; + if (!GetWindowRect(window, &window_rect)) + return false; + + if (!window_rect.Contains(screen_loc)) + return false; + + if (!IsShapeAvailable()) + return true; + + // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, + // if an X display supports the shape extension the bounds of a window are + // defined as the intersection of the window bounds and the interior + // rectangles. This means to determine if a point is inside a window for the + // purpose of input handling we have to check the rectangles in the ShapeInput + // list. + int dummy; + int input_rects_size = 0; + XRectangle* input_rects = XShapeGetRectangles( + ui::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy); + if (!input_rects) + return true; + bool is_in_input_rects = false; + for (int i = 0; i < input_rects_size; ++i) { + gfx::Rect input_rect = + gfx::Rect(input_rects[i].x, input_rects[i].y, + input_rects[i].width, input_rects[i].height); + if (input_rect.Contains(screen_loc)) { + is_in_input_rects = true; + break; + } + } + XFree(input_rects); + return is_in_input_rects; +} + + bool PropertyExists(XID window, const std::string& property_name) { Atom type = None; int format = 0; // size in bits of each item in 'property' diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h index 053008f..b1a6e4d 100644 --- a/ui/base/x/x11_util.h +++ b/ui/base/x/x11_util.h @@ -145,6 +145,9 @@ UI_EXPORT bool IsWindowVisible(XID window); // Returns the bounds of |window|. UI_EXPORT bool GetWindowRect(XID window, gfx::Rect* rect); +// Returns true if |window| contains the point |screen_loc|. +UI_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); + // Return true if |window| has any property with |property_name|. UI_EXPORT bool PropertyExists(XID window, const std::string& property_name); |