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

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: blindly patches dock_info_aurax11.cc and simplifies query cache 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 304
304 ~XButtonMap() {} 305 ~XButtonMap() {}
305 306
306 unsigned char map_[256]; 307 unsigned char map_[256];
307 int count_; 308 int count_;
308 309
309 DISALLOW_COPY_AND_ASSIGN(XButtonMap); 310 DISALLOW_COPY_AND_ASSIGN(XButtonMap);
310 }; 311 };
311 312
312 bool IsRandRAvailable() { 313 bool IsRandRAvailable() {
313 static bool is_randr_available = false;
314 static bool is_randr_availability_cached = false;
315 if (is_randr_availability_cached)
316 return is_randr_available;
317
318 int randr_version_major = 0; 314 int randr_version_major = 0;
319 int randr_version_minor = 0; 315 int randr_version_minor = 0;
320 is_randr_available = XRRQueryVersion( 316 static bool is_randr_available = XRRQueryVersion(
321 GetXDisplay(), &randr_version_major, &randr_version_minor); 317 GetXDisplay(), &randr_version_major, &randr_version_minor);
322 is_randr_availability_cached = true;
323 return is_randr_available; 318 return is_randr_available;
324 } 319 }
325 320
321 bool IsShapeAvailable() {
322 int dummy;
323 static bool is_shape_available =
324 XShapeQueryExtension(ui::GetXDisplay(), &dummy, &dummy);
325 return is_shape_available;
326
327 }
328
326 } // namespace 329 } // namespace
327 330
328 bool XDisplayExists() { 331 bool XDisplayExists() {
329 return (GetXDisplay() != NULL); 332 return (GetXDisplay() != NULL);
330 } 333 }
331 334
332 Display* GetXDisplay() { 335 Display* GetXDisplay() {
333 return base::MessagePumpForUI::GetDefaultXDisplay(); 336 return base::MessagePumpForUI::GetDefaultXDisplay();
334 } 337 }
335 338
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 return false; 608 return false;
606 609
607 if (!XTranslateCoordinates(GetXDisplay(), window, root, 610 if (!XTranslateCoordinates(GetXDisplay(), window, root,
608 0, 0, &x, &y, &child)) 611 0, 0, &x, &y, &child))
609 return false; 612 return false;
610 613
611 *rect = gfx::Rect(x, y, width, height); 614 *rect = gfx::Rect(x, y, width, height);
612 return true; 615 return true;
613 } 616 }
614 617
618
619 bool WindowContainsPoint(XID window, gfx::Point screen_loc) {
620 gfx::Rect window_rect;
621 if (!GetWindowRect(window, &window_rect))
622 return false;
623
624 if (!window_rect.Contains(screen_loc))
625 return false;
626
627 if (!IsShapeAvailable())
628 return true;
629
630 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html,
631 // if an X display supports the shape extension the bounds of a window are
632 // defined as the intersection of the window bounds and the interior
633 // rectangles. This means to determine if a point is inside a window for the
634 // purpose of input handling we have to check the rectangles in the ShapeInput
635 // list.
636 int dummy;
637 int input_rects_size = 0;
638 XRectangle* input_rects = XShapeGetRectangles(
639 ui::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy);
640 if (!input_rects)
641 return true;
642 bool is_in_input_rects = false;
643 for (int i = 0; i < input_rects_size; ++i) {
644 gfx::Rect input_rect =
645 gfx::Rect(input_rects[i].x, input_rects[i].y,
646 input_rects[i].width, input_rects[i].height);
647 if (input_rect.Contains(screen_loc)) {
648 is_in_input_rects = true;
649 break;
650 }
651 }
652 XFree(input_rects);
653 return is_in_input_rects;
654 }
655
656
615 bool PropertyExists(XID window, const std::string& property_name) { 657 bool PropertyExists(XID window, const std::string& property_name) {
616 Atom type = None; 658 Atom type = None;
617 int format = 0; // size in bits of each item in 'property' 659 int format = 0; // size in bits of each item in 'property'
618 unsigned long num_items = 0; 660 unsigned long num_items = 0;
619 unsigned char* property = NULL; 661 unsigned char* property = NULL;
620 662
621 int result = GetProperty(window, property_name, 1, 663 int result = GetProperty(window, property_name, 1,
622 &type, &format, &num_items, &property); 664 &type, &format, &num_items, &property);
623 if (result != Success) 665 if (result != Success)
624 return false; 666 return false;
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1623 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1582 << "minor_code " << static_cast<int>(error_event.minor_code) 1624 << "minor_code " << static_cast<int>(error_event.minor_code)
1583 << " (" << request_str << ")"; 1625 << " (" << request_str << ")";
1584 } 1626 }
1585 1627
1586 // ---------------------------------------------------------------------------- 1628 // ----------------------------------------------------------------------------
1587 // End of x11_util_internal.h 1629 // End of x11_util_internal.h
1588 1630
1589 1631
1590 } // namespace ui 1632 } // 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