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

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

Issue 232653002: x11_util: Added GetInnerWindowBounds and GetWindowExtents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test compile. Created 6 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
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
(...skipping 25 matching lines...) Expand all
36 #include "skia/ext/image_operations.h" 36 #include "skia/ext/image_operations.h"
37 #include "third_party/skia/include/core/SkBitmap.h" 37 #include "third_party/skia/include/core/SkBitmap.h"
38 #include "third_party/skia/include/core/SkPostConfig.h" 38 #include "third_party/skia/include/core/SkPostConfig.h"
39 #include "ui/base/x/x11_menu_list.h" 39 #include "ui/base/x/x11_menu_list.h"
40 #include "ui/base/x/x11_util_internal.h" 40 #include "ui/base/x/x11_util_internal.h"
41 #include "ui/events/event_utils.h" 41 #include "ui/events/event_utils.h"
42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 42 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
43 #include "ui/events/x/device_data_manager_x11.h" 43 #include "ui/events/x/device_data_manager_x11.h"
44 #include "ui/events/x/touch_factory_x11.h" 44 #include "ui/events/x/touch_factory_x11.h"
45 #include "ui/gfx/canvas.h" 45 #include "ui/gfx/canvas.h"
46 #include "ui/gfx/geometry/insets.h"
47 #include "ui/gfx/geometry/point.h"
48 #include "ui/gfx/geometry/point_conversions.h"
49 #include "ui/gfx/geometry/rect.h"
50 #include "ui/gfx/geometry/size.h"
46 #include "ui/gfx/image/image_skia.h" 51 #include "ui/gfx/image/image_skia.h"
47 #include "ui/gfx/image/image_skia_rep.h" 52 #include "ui/gfx/image/image_skia_rep.h"
48 #include "ui/gfx/point.h"
49 #include "ui/gfx/point_conversions.h"
50 #include "ui/gfx/rect.h"
51 #include "ui/gfx/size.h"
52 #include "ui/gfx/skia_util.h" 53 #include "ui/gfx/skia_util.h"
53 #include "ui/gfx/x/x11_error_tracker.h" 54 #include "ui/gfx/x/x11_error_tracker.h"
54 55
55 #if defined(OS_FREEBSD) 56 #if defined(OS_FREEBSD)
56 #include <sys/sysctl.h> 57 #include <sys/sysctl.h>
57 #include <sys/types.h> 58 #include <sys/types.h>
58 #endif 59 #endif
59 60
60 namespace ui { 61 namespace ui {
61 62
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 32, // size in bits 574 32, // size in bits
574 PropModeReplace, 575 PropModeReplace,
575 reinterpret_cast<unsigned char*>(&hide), 576 reinterpret_cast<unsigned char*>(&hide),
576 1); 577 1);
577 } 578 }
578 579
579 void ClearX11DefaultRootWindow() { 580 void ClearX11DefaultRootWindow() {
580 XDisplay* display = gfx::GetXDisplay(); 581 XDisplay* display = gfx::GetXDisplay();
581 XID root_window = GetX11RootWindow(); 582 XID root_window = GetX11RootWindow();
582 gfx::Rect root_bounds; 583 gfx::Rect root_bounds;
583 if (!GetWindowRect(root_window, &root_bounds)) { 584 if (!GetOuterWindowBounds(root_window, &root_bounds)) {
584 LOG(ERROR) << "Failed to get the bounds of the X11 root window"; 585 LOG(ERROR) << "Failed to get the bounds of the X11 root window";
585 return; 586 return;
586 } 587 }
587 588
588 XGCValues gc_values = {0}; 589 XGCValues gc_values = {0};
589 gc_values.foreground = BlackPixel(display, DefaultScreen(display)); 590 gc_values.foreground = BlackPixel(display, DefaultScreen(display));
590 GC gc = XCreateGC(display, root_window, GCForeground, &gc_values); 591 GC gc = XCreateGC(display, root_window, GCForeground, &gc_values);
591 XFillRectangle(display, root_window, gc, 592 XFillRectangle(display, root_window, gc,
592 root_bounds.x(), 593 root_bounds.x(),
593 root_bounds.y(), 594 root_bounds.y(),
(...skipping 23 matching lines...) Expand all
617 618
618 // Some compositing window managers (notably kwin) do not actually unmap 619 // Some compositing window managers (notably kwin) do not actually unmap
619 // windows on desktop switch, so we also must check the current desktop. 620 // windows on desktop switch, so we also must check the current desktop.
620 int window_desktop, current_desktop; 621 int window_desktop, current_desktop;
621 return (!GetWindowDesktop(window, &window_desktop) || 622 return (!GetWindowDesktop(window, &window_desktop) ||
622 !GetCurrentDesktop(&current_desktop) || 623 !GetCurrentDesktop(&current_desktop) ||
623 window_desktop == kAllDesktops || 624 window_desktop == kAllDesktops ||
624 window_desktop == current_desktop); 625 window_desktop == current_desktop);
625 } 626 }
626 627
627 bool GetWindowRect(XID window, gfx::Rect* rect) { 628 bool GetInnerWindowBounds(XID window, gfx::Rect* rect) {
628 Window root, child; 629 Window root, child;
629 int x, y; 630 int x, y;
630 unsigned int width, height; 631 unsigned int width, height;
631 unsigned int border_width, depth; 632 unsigned int border_width, depth;
632 633
633 if (!XGetGeometry(gfx::GetXDisplay(), window, &root, &x, &y, 634 if (!XGetGeometry(gfx::GetXDisplay(), window, &root, &x, &y,
634 &width, &height, &border_width, &depth)) 635 &width, &height, &border_width, &depth))
635 return false; 636 return false;
636 637
637 if (!XTranslateCoordinates(gfx::GetXDisplay(), window, root, 638 if (!XTranslateCoordinates(gfx::GetXDisplay(), window, root,
638 0, 0, &x, &y, &child)) 639 0, 0, &x, &y, &child))
639 return false; 640 return false;
640 641
641 *rect = gfx::Rect(x, y, width, height); 642 *rect = gfx::Rect(x, y, width, height);
642 643
644 return true;
645 }
646
647 bool GetWindowExtents(XID window, gfx::Insets* extents) {
643 std::vector<int> insets; 648 std::vector<int> insets;
644 if (GetIntArrayProperty(window, "_NET_FRAME_EXTENTS", &insets) && 649 if (!GetIntArrayProperty(window, "_NET_FRAME_EXTENTS", &insets))
645 insets.size() == 4) { 650 return false;
646 rect->Inset(-insets[0], -insets[2], -insets[1], -insets[3]); 651 if (insets.size() != 4)
647 } 652 return false;
653
654 int left = insets[0];
655 int right = insets[1];
656 int top = insets[2];
657 int bottom = insets[3];
658 extents->Set(-top, -left, -bottom, -right);
659 return true;
660 }
661
662 bool GetOuterWindowBounds(XID window, gfx::Rect* rect) {
663 if (!GetInnerWindowBounds(window, rect))
664 return false;
665
666 gfx::Insets extents;
667 if (GetWindowExtents(window, &extents))
668 rect->Inset(extents);
648 // Not all window managers support _NET_FRAME_EXTENTS so return true even if 669 // Not all window managers support _NET_FRAME_EXTENTS so return true even if
649 // requesting the property fails. 670 // requesting the property fails.
650 671
651 return true; 672 return true;
652 } 673 }
653 674
654 675
655 bool WindowContainsPoint(XID window, gfx::Point screen_loc) { 676 bool WindowContainsPoint(XID window, gfx::Point screen_loc) {
656 TRACE_EVENT0("ui", "WindowContainsPoint"); 677 TRACE_EVENT0("ui", "WindowContainsPoint");
657 678
658 gfx::Rect window_rect; 679 gfx::Rect window_rect;
659 if (!GetWindowRect(window, &window_rect)) 680 if (!GetOuterWindowBounds(window, &window_rect))
660 return false; 681 return false;
661 682
662 if (!window_rect.Contains(screen_loc)) 683 if (!window_rect.Contains(screen_loc))
663 return false; 684 return false;
664 685
665 if (!IsShapeExtensionAvailable()) 686 if (!IsShapeExtensionAvailable())
666 return true; 687 return true;
667 688
668 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, 689 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html,
669 // if an X display supports the shape extension the bounds of a window are 690 // if an X display supports the shape extension the bounds of a window are
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 "_NET_WM_STATE", 1311 "_NET_WM_STATE",
1291 &atom_properties)) { 1312 &atom_properties)) {
1292 return std::find(atom_properties.begin(), 1313 return std::find(atom_properties.begin(),
1293 atom_properties.end(), 1314 atom_properties.end(),
1294 fullscreen_atom) != 1315 fullscreen_atom) !=
1295 atom_properties.end(); 1316 atom_properties.end();
1296 } 1317 }
1297 } 1318 }
1298 1319
1299 gfx::Rect window_rect; 1320 gfx::Rect window_rect;
1300 if (!ui::GetWindowRect(window, &window_rect)) 1321 if (!ui::GetOuterWindowBounds(window, &window_rect))
1301 return false; 1322 return false;
1302 1323
1303 // We can't use gfx::Screen here because we don't have an aura::Window. So 1324 // We can't use gfx::Screen here because we don't have an aura::Window. So
1304 // instead just look at the size of the default display. 1325 // instead just look at the size of the default display.
1305 // 1326 //
1306 // TODO(erg): Actually doing this correctly would require pulling out xrandr, 1327 // TODO(erg): Actually doing this correctly would require pulling out xrandr,
1307 // which we don't even do in the desktop screen yet. 1328 // which we don't even do in the desktop screen yet.
1308 ::XDisplay* display = gfx::GetXDisplay(); 1329 ::XDisplay* display = gfx::GetXDisplay();
1309 ::Screen* screen = DefaultScreenOfDisplay(display); 1330 ::Screen* screen = DefaultScreenOfDisplay(display);
1310 int width = WidthOfScreen(screen); 1331 int width = WidthOfScreen(screen);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1493 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1473 << "minor_code " << static_cast<int>(error_event.minor_code) 1494 << "minor_code " << static_cast<int>(error_event.minor_code)
1474 << " (" << request_str << ")"; 1495 << " (" << request_str << ")";
1475 } 1496 }
1476 1497
1477 // ---------------------------------------------------------------------------- 1498 // ----------------------------------------------------------------------------
1478 // End of x11_util_internal.h 1499 // End of x11_util_internal.h
1479 1500
1480 1501
1481 } // namespace ui 1502 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698