Chromium Code Reviews| 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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
| 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
| 7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
| 8 | 8 |
| 9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
| 10 | 10 |
| 11 #include <ctype.h> | 11 #include <ctype.h> |
| 12 #include <sys/ipc.h> | 12 #include <sys/ipc.h> |
| 13 #include <sys/shm.h> | 13 #include <sys/shm.h> |
| 14 | 14 |
| 15 #include <list> | 15 #include <list> |
| 16 #include <map> | 16 #include <map> |
| 17 #include <utility> | 17 #include <utility> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include <X11/extensions/Xrandr.h> | 20 #include <X11/extensions/Xrandr.h> |
| 21 #include <X11/extensions/randr.h> | 21 #include <X11/extensions/randr.h> |
| 22 #include <X11/extensions/shape.h> | |
| 22 | 23 |
| 23 #include "base/bind.h" | 24 #include "base/bind.h" |
| 24 #include "base/command_line.h" | 25 #include "base/command_line.h" |
| 25 #include "base/logging.h" | 26 #include "base/logging.h" |
| 26 #include "base/memory/scoped_ptr.h" | 27 #include "base/memory/scoped_ptr.h" |
| 27 #include "base/memory/singleton.h" | 28 #include "base/memory/singleton.h" |
| 28 #include "base/message_loop.h" | 29 #include "base/message_loop.h" |
| 29 #include "base/string_number_conversions.h" | 30 #include "base/string_number_conversions.h" |
| 30 #include "base/string_util.h" | 31 #include "base/string_util.h" |
| 31 #include "base/stringprintf.h" | 32 #include "base/stringprintf.h" |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 return false; | 606 return false; |
| 606 | 607 |
| 607 if (!XTranslateCoordinates(GetXDisplay(), window, root, | 608 if (!XTranslateCoordinates(GetXDisplay(), window, root, |
| 608 0, 0, &x, &y, &child)) | 609 0, 0, &x, &y, &child)) |
| 609 return false; | 610 return false; |
| 610 | 611 |
| 611 *rect = gfx::Rect(x, y, width, height); | 612 *rect = gfx::Rect(x, y, width, height); |
| 612 return true; | 613 return true; |
| 613 } | 614 } |
| 614 | 615 |
| 616 | |
| 617 bool WindowContainsPoint(XID window, gfx::Point screen_loc) { | |
| 618 gfx::Rect window_rect; | |
| 619 if (!GetWindowRect(window, &window_rect)) | |
| 620 return false; | |
| 621 | |
| 622 if (!window_rect.Contains(screen_loc)) | |
| 623 return false; | |
| 624 | |
| 625 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, | |
| 626 // if an X display supports the shape extension the bounds of a window are | |
| 627 // defined as the intersection of the window bounds and the interior | |
| 628 // rectangles. This means to determine if a point is inside a window for the | |
| 629 // purpose of input handling we have to check the rectangles in the ShapeInput | |
| 630 // list. | |
| 631 int dummy; | |
| 632 if (XShapeQueryExtension(ui::GetXDisplay(), &dummy, &dummy)) { | |
|
sadrul
2012/09/24 23:39:24
It would make sense to cache the return value of X
| |
| 633 int input_rects_size = 0; | |
| 634 XRectangle* input_rects = XShapeGetRectangles( | |
| 635 ui::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy); | |
| 636 bool is_in_input_rects = false; | |
| 637 for (int i = 0; i < input_rects_size; ++i) { | |
| 638 gfx::Rect input_rect = | |
| 639 gfx::Rect(input_rects[i].x, input_rects[i].y, | |
| 640 input_rects[i].width, input_rects[i].height); | |
| 641 if (input_rect.Contains(screen_loc)) { | |
| 642 is_in_input_rects = true; | |
| 643 break; | |
| 644 } | |
| 645 } | |
|
Elliot Glaysher
2012/09/24 23:35:05
You'll need an XFree(input_rects); here.
| |
| 646 if (!is_in_input_rects) | |
| 647 return false; | |
| 648 } | |
| 649 | |
| 650 return true; | |
| 651 } | |
| 652 | |
| 653 | |
| 615 bool PropertyExists(XID window, const std::string& property_name) { | 654 bool PropertyExists(XID window, const std::string& property_name) { |
| 616 Atom type = None; | 655 Atom type = None; |
| 617 int format = 0; // size in bits of each item in 'property' | 656 int format = 0; // size in bits of each item in 'property' |
| 618 unsigned long num_items = 0; | 657 unsigned long num_items = 0; |
| 619 unsigned char* property = NULL; | 658 unsigned char* property = NULL; |
| 620 | 659 |
| 621 int result = GetProperty(window, property_name, 1, | 660 int result = GetProperty(window, property_name, 1, |
| 622 &type, &format, &num_items, &property); | 661 &type, &format, &num_items, &property); |
| 623 if (result != Success) | 662 if (result != Success) |
| 624 return false; | 663 return false; |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1620 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
| 1582 << "minor_code " << static_cast<int>(error_event.minor_code) | 1621 << "minor_code " << static_cast<int>(error_event.minor_code) |
| 1583 << " (" << request_str << ")"; | 1622 << " (" << request_str << ")"; |
| 1584 } | 1623 } |
| 1585 | 1624 |
| 1586 // ---------------------------------------------------------------------------- | 1625 // ---------------------------------------------------------------------------- |
| 1587 // End of x11_util_internal.h | 1626 // End of x11_util_internal.h |
| 1588 | 1627 |
| 1589 | 1628 |
| 1590 } // namespace ui | 1629 } // namespace ui |
| OLD | NEW |