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

Side by Side Diff: ui/base/x/x11_util.cc

Issue 10990010: Fix tab dragging in unity2d (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add null check for return value of XShapeGetRectangles Created 8 years, 2 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return is_randr_available; 317 return is_randr_available;
317 318
318 int randr_version_major = 0; 319 int randr_version_major = 0;
319 int randr_version_minor = 0; 320 int randr_version_minor = 0;
320 is_randr_available = XRRQueryVersion( 321 is_randr_available = XRRQueryVersion(
321 GetXDisplay(), &randr_version_major, &randr_version_minor); 322 GetXDisplay(), &randr_version_major, &randr_version_minor);
322 is_randr_availability_cached = true; 323 is_randr_availability_cached = true;
323 return is_randr_available; 324 return is_randr_available;
324 } 325 }
325 326
327 bool IsShapeAvailable() {
328 static bool is_shape_available = false;
329 static bool is_shape_availability_cached = false;
sadrul 2012/09/25 16:37:20 I think you can just do: static bool is_shape_ava
330 if (is_shape_availability_cached)
331 return is_shape_available;
332
333 int dummy;
334 is_shape_available = XShapeQueryExtension(ui::GetXDisplay(), &dummy, &dummy);
335 is_shape_availability_cached = true;
336 return is_shape_available;
337
338 }
339
326 } // namespace 340 } // namespace
327 341
328 bool XDisplayExists() { 342 bool XDisplayExists() {
329 return (GetXDisplay() != NULL); 343 return (GetXDisplay() != NULL);
330 } 344 }
331 345
332 Display* GetXDisplay() { 346 Display* GetXDisplay() {
333 return base::MessagePumpForUI::GetDefaultXDisplay(); 347 return base::MessagePumpForUI::GetDefaultXDisplay();
334 } 348 }
335 349
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return false; 619 return false;
606 620
607 if (!XTranslateCoordinates(GetXDisplay(), window, root, 621 if (!XTranslateCoordinates(GetXDisplay(), window, root,
608 0, 0, &x, &y, &child)) 622 0, 0, &x, &y, &child))
609 return false; 623 return false;
610 624
611 *rect = gfx::Rect(x, y, width, height); 625 *rect = gfx::Rect(x, y, width, height);
612 return true; 626 return true;
613 } 627 }
614 628
629
630 bool WindowContainsPoint(XID window, gfx::Point screen_loc) {
631 gfx::Rect window_rect;
632 if (!GetWindowRect(window, &window_rect))
633 return false;
634
635 if (!window_rect.Contains(screen_loc))
636 return false;
637
638 if (!IsShapeAvailable())
639 return true;
640
641 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html,
642 // if an X display supports the shape extension the bounds of a window are
643 // defined as the intersection of the window bounds and the interior
644 // rectangles. This means to determine if a point is inside a window for the
645 // purpose of input handling we have to check the rectangles in the ShapeInput
646 // list.
647 int dummy;
648 int input_rects_size = 0;
649 XRectangle* input_rects = XShapeGetRectangles(
650 ui::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy);
651 if (!input_rects)
652 return true;
653 bool is_in_input_rects = false;
654 for (int i = 0; i < input_rects_size; ++i) {
655 gfx::Rect input_rect =
656 gfx::Rect(input_rects[i].x, input_rects[i].y,
657 input_rects[i].width, input_rects[i].height);
658 if (input_rect.Contains(screen_loc)) {
659 is_in_input_rects = true;
660 break;
661 }
662 }
663 XFree(input_rects);
664 return is_in_input_rects;
665 }
666
667
615 bool PropertyExists(XID window, const std::string& property_name) { 668 bool PropertyExists(XID window, const std::string& property_name) {
616 Atom type = None; 669 Atom type = None;
617 int format = 0; // size in bits of each item in 'property' 670 int format = 0; // size in bits of each item in 'property'
618 unsigned long num_items = 0; 671 unsigned long num_items = 0;
619 unsigned char* property = NULL; 672 unsigned char* property = NULL;
620 673
621 int result = GetProperty(window, property_name, 1, 674 int result = GetProperty(window, property_name, 1,
622 &type, &format, &num_items, &property); 675 &type, &format, &num_items, &property);
623 if (result != Success) 676 if (result != Success)
624 return false; 677 return false;
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1634 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1582 << "minor_code " << static_cast<int>(error_event.minor_code) 1635 << "minor_code " << static_cast<int>(error_event.minor_code)
1583 << " (" << request_str << ")"; 1636 << " (" << request_str << ")";
1584 } 1637 }
1585 1638
1586 // ---------------------------------------------------------------------------- 1639 // ----------------------------------------------------------------------------
1587 // End of x11_util_internal.h 1640 // End of x11_util_internal.h
1588 1641
1589 1642
1590 } // namespace ui 1643 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698