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 |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 | 648 |
649 if (!IsShapeAvailable()) | 649 if (!IsShapeAvailable()) |
650 return true; | 650 return true; |
651 | 651 |
652 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, | 652 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, |
653 // if an X display supports the shape extension the bounds of a window are | 653 // if an X display supports the shape extension the bounds of a window are |
654 // defined as the intersection of the window bounds and the interior | 654 // defined as the intersection of the window bounds and the interior |
655 // rectangles. This means to determine if a point is inside a window for the | 655 // rectangles. This means to determine if a point is inside a window for the |
656 // purpose of input handling we have to check the rectangles in the ShapeInput | 656 // purpose of input handling we have to check the rectangles in the ShapeInput |
657 // list. | 657 // list. |
658 int dummy; | 658 // According to http://www.x.org/releases/current/doc/xextproto/shape.html, |
659 int input_rects_size = 0; | 659 // we need to also respect the ShapeBounding rectangles. |
660 XRectangle* input_rects = XShapeGetRectangles( | 660 // The effective input region of a window is defined to be the intersection |
661 gfx::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy); | 661 // of the client input region with both the default input region and the |
662 if (!input_rects) | 662 // client bounding region. Any portion of the client input region that is not |
663 return true; | 663 // included in both the default input region and the client bounding region |
664 bool is_in_input_rects = false; | 664 // will not be included in the effective input region on the screen. |
665 for (int i = 0; i < input_rects_size; ++i) { | 665 bool is_in_shape_rects = false; |
666 // The ShapeInput rects appear to be in window space, so we have to | 666 int rectangle_kind[] = {ShapeInput, ShapeBounding}; |
667 // translate by the window_rect's offset to map to screen space. | 667 for (size_t kind_index = 0 ; |
668 gfx::Rect input_rect = | 668 kind_index < sizeof(rectangle_kind)/sizeof(*rectangle_kind) ; |
sadrul
2014/02/04 23:12:18
You can use the arraysize macro here instead.
varkha
2014/02/05 03:52:31
Done.
| |
669 gfx::Rect(input_rects[i].x + window_rect.x(), | 669 kind_index++) { |
670 input_rects[i].y + window_rect.y(), | 670 int dummy; |
671 input_rects[i].width, input_rects[i].height); | 671 int shape_rects_size = 0; |
672 if (input_rect.Contains(screen_loc)) { | 672 XRectangle* shape_rects = XShapeGetRectangles(gfx::GetXDisplay(), |
673 is_in_input_rects = true; | 673 window, |
674 break; | 674 rectangle_kind[kind_index], |
675 &shape_rects_size, | |
676 &dummy); | |
677 if (!shape_rects) { | |
678 is_in_shape_rects = true; | |
679 continue; | |
675 } | 680 } |
681 is_in_shape_rects = false; | |
682 for (int i = 0; i < shape_rects_size; ++i) { | |
683 // The ShapeInput and ShapeBounding rects are to be in window space, so we | |
684 // have to translate by the window_rect's offset to map to screen space. | |
685 gfx::Rect shape_rect = | |
686 gfx::Rect(shape_rects[i].x + window_rect.x(), | |
687 shape_rects[i].y + window_rect.y(), | |
688 shape_rects[i].width, shape_rects[i].height); | |
689 if (shape_rect.Contains(screen_loc)) { | |
690 is_in_shape_rects = true; | |
691 break; | |
692 } | |
693 } | |
694 XFree(shape_rects); | |
695 if (!is_in_shape_rects) | |
696 return false; | |
676 } | 697 } |
677 XFree(input_rects); | 698 return is_in_shape_rects; |
sadrul
2014/02/04 23:12:18
I think you can move is_in_shape_rects inside the
varkha
2014/02/05 03:52:31
Done.
| |
678 return is_in_input_rects; | |
679 } | 699 } |
680 | 700 |
681 | 701 |
682 bool PropertyExists(XID window, const std::string& property_name) { | 702 bool PropertyExists(XID window, const std::string& property_name) { |
683 Atom type = None; | 703 Atom type = None; |
684 int format = 0; // size in bits of each item in 'property' | 704 int format = 0; // size in bits of each item in 'property' |
685 unsigned long num_items = 0; | 705 unsigned long num_items = 0; |
686 unsigned char* property = NULL; | 706 unsigned char* property = NULL; |
687 | 707 |
688 int result = GetProperty(window, property_name, 1, | 708 int result = GetProperty(window, property_name, 1, |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1533 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1553 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1534 << "minor_code " << static_cast<int>(error_event.minor_code) | 1554 << "minor_code " << static_cast<int>(error_event.minor_code) |
1535 << " (" << request_str << ")"; | 1555 << " (" << request_str << ")"; |
1536 } | 1556 } |
1537 | 1557 |
1538 // ---------------------------------------------------------------------------- | 1558 // ---------------------------------------------------------------------------- |
1539 // End of x11_util_internal.h | 1559 // End of x11_util_internal.h |
1540 | 1560 |
1541 | 1561 |
1542 } // namespace ui | 1562 } // namespace ui |
OLD | NEW |