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

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

Issue 264713007: Add unittests for X11TopmostWindowFinder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 XCustomCursorCache() {} 210 XCustomCursorCache() {}
211 ~XCustomCursorCache() { 211 ~XCustomCursorCache() {
212 Clear(); 212 Clear();
213 } 213 }
214 214
215 std::map< ::Cursor, XCustomCursor*> cache_; 215 std::map< ::Cursor, XCustomCursor*> cache_;
216 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache); 216 DISALLOW_COPY_AND_ASSIGN(XCustomCursorCache);
217 }; 217 };
218 218
219 bool IsShapeAvailable() {
220 int dummy;
221 static bool is_shape_available =
222 XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy);
223 return is_shape_available;
224
225 }
226
227 } // namespace 219 } // namespace
228 220
229 bool IsXInput2Available() { 221 bool IsXInput2Available() {
230 return DeviceDataManager::GetInstance()->IsXInput2Available(); 222 return DeviceDataManager::GetInstance()->IsXInput2Available();
231 } 223 }
232 224
233 static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) { 225 static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) {
234 int dummy; 226 int dummy;
235 Bool pixmaps_supported; 227 Bool pixmaps_supported;
236 // Query the server's support for XSHM. 228 // Query the server's support for XSHM.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 black.red = black.green = black.blue = 0; 444 black.red = black.green = black.blue = 0;
453 Pixmap blank = XCreateBitmapFromData(xdisplay, 445 Pixmap blank = XCreateBitmapFromData(xdisplay,
454 DefaultRootWindow(xdisplay), 446 DefaultRootWindow(xdisplay),
455 nodata, 8, 8); 447 nodata, 8, 8);
456 invisible_cursor = XCreatePixmapCursor(xdisplay, blank, blank, 448 invisible_cursor = XCreatePixmapCursor(xdisplay, blank, blank,
457 &black, &black, 0, 0); 449 &black, &black, 0, 0);
458 XFreePixmap(xdisplay, blank); 450 XFreePixmap(xdisplay, blank);
459 return invisible_cursor; 451 return invisible_cursor;
460 } 452 }
461 453
454 void SetUseOSWindowFrame(XID window, bool use_os_window_frame) {
455 // This data structure represents additional hints that we send to the window
456 // manager and has a direct lineage back to Motif, which defined this de facto
457 // standard. This struct doesn't seem 64-bit safe though, but it's what GDK
458 // does.
459 typedef struct {
460 unsigned long flags;
461 unsigned long functions;
462 unsigned long decorations;
463 long input_mode;
464 unsigned long status;
465 } MotifWmHints;
466
467 MotifWmHints motif_hints;
468 memset(&motif_hints, 0, sizeof(motif_hints));
469 // Signals that the reader of the _MOTIF_WM_HINTS property should pay
470 // attention to the value of |decorations|.
471 motif_hints.flags = (1L << 1);
472 motif_hints.decorations = use_os_window_frame ? 1 : 0;
473
474 ::Atom hint_atom = GetAtom("_MOTIF_WM_HINTS");
475 XChangeProperty(gfx::GetXDisplay(),
476 window,
477 hint_atom,
478 hint_atom,
479 32,
480 PropModeReplace,
481 reinterpret_cast<unsigned char*>(&motif_hints),
482 sizeof(MotifWmHints)/sizeof(long));
483 }
484
485 bool IsShapeExtensionAvailable() {
486 int dummy;
487 static bool is_shape_available =
488 XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy);
489 return is_shape_available;
490 }
491
462 XID GetX11RootWindow() { 492 XID GetX11RootWindow() {
463 return DefaultRootWindow(gfx::GetXDisplay()); 493 return DefaultRootWindow(gfx::GetXDisplay());
464 } 494 }
465 495
466 bool GetCurrentDesktop(int* desktop) { 496 bool GetCurrentDesktop(int* desktop) {
467 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop); 497 return GetIntProperty(GetX11RootWindow(), "_NET_CURRENT_DESKTOP", desktop);
468 } 498 }
469 499
470 void SetHideTitlebarWhenMaximizedProperty(XID window, 500 void SetHideTitlebarWhenMaximizedProperty(XID window,
471 HideTitlebarWhenMaximized property) { 501 HideTitlebarWhenMaximized property) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 bool WindowContainsPoint(XID window, gfx::Point screen_loc) { 590 bool WindowContainsPoint(XID window, gfx::Point screen_loc) {
561 TRACE_EVENT0("ui", "WindowContainsPoint"); 591 TRACE_EVENT0("ui", "WindowContainsPoint");
562 592
563 gfx::Rect window_rect; 593 gfx::Rect window_rect;
564 if (!GetWindowRect(window, &window_rect)) 594 if (!GetWindowRect(window, &window_rect))
565 return false; 595 return false;
566 596
567 if (!window_rect.Contains(screen_loc)) 597 if (!window_rect.Contains(screen_loc))
568 return false; 598 return false;
569 599
570 if (!IsShapeAvailable()) 600 if (!IsShapeExtensionAvailable())
571 return true; 601 return true;
572 602
573 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html, 603 // According to http://www.x.org/releases/X11R7.6/doc/libXext/shapelib.html,
574 // if an X display supports the shape extension the bounds of a window are 604 // if an X display supports the shape extension the bounds of a window are
575 // defined as the intersection of the window bounds and the interior 605 // defined as the intersection of the window bounds and the interior
576 // rectangles. This means to determine if a point is inside a window for the 606 // rectangles. This means to determine if a point is inside a window for the
577 // purpose of input handling we have to check the rectangles in the ShapeInput 607 // purpose of input handling we have to check the rectangles in the ShapeInput
578 // list. 608 // list.
579 // According to http://www.x.org/releases/current/doc/xextproto/shape.html, 609 // According to http://www.x.org/releases/current/doc/xextproto/shape.html,
580 // we need to also respect the ShapeBounding rectangles. 610 // we need to also respect the ShapeBounding rectangles.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 window, 867 window,
838 name_atom, 868 name_atom,
839 type_atom, 869 type_atom,
840 32, // size in bits of items in 'value' 870 32, // size in bits of items in 'value'
841 PropModeReplace, 871 PropModeReplace,
842 reinterpret_cast<const unsigned char*>(data.get()), 872 reinterpret_cast<const unsigned char*>(data.get()),
843 value.size()); // num items 873 value.size()); // num items
844 return !err_tracker.FoundNewError(); 874 return !err_tracker.FoundNewError();
845 } 875 }
846 876
877 bool SetAtomProperty(XID window,
878 const std::string& name,
879 const std::string& type,
880 Atom value) {
881 std::vector<Atom> values(1, value);
882 return SetAtomArrayProperty(window, name, type, values);
883 }
884
847 bool SetAtomArrayProperty(XID window, 885 bool SetAtomArrayProperty(XID window,
848 const std::string& name, 886 const std::string& name,
849 const std::string& type, 887 const std::string& type,
850 const std::vector<Atom>& value) { 888 const std::vector<Atom>& value) {
851 DCHECK(!value.empty()); 889 DCHECK(!value.empty());
852 Atom name_atom = GetAtom(name.c_str()); 890 Atom name_atom = GetAtom(name.c_str());
853 Atom type_atom = GetAtom(type.c_str()); 891 Atom type_atom = GetAtom(type.c_str());
854 892
855 // XChangeProperty() expects values of type 32 to be longs. 893 // XChangeProperty() expects values of type 32 to be longs.
856 scoped_ptr<Atom[]> data(new Atom[value.size()]); 894 scoped_ptr<Atom[]> data(new Atom[value.size()]);
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 << "request_code " << static_cast<int>(error_event.request_code) << ", " 1386 << "request_code " << static_cast<int>(error_event.request_code) << ", "
1349 << "minor_code " << static_cast<int>(error_event.minor_code) 1387 << "minor_code " << static_cast<int>(error_event.minor_code)
1350 << " (" << request_str << ")"; 1388 << " (" << request_str << ")";
1351 } 1389 }
1352 1390
1353 // ---------------------------------------------------------------------------- 1391 // ----------------------------------------------------------------------------
1354 // End of x11_util_internal.h 1392 // End of x11_util_internal.h
1355 1393
1356 1394
1357 } // namespace ui 1395 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | ui/gfx/x/x11_atom_cache.h » ('j') | ui/gfx/x/x11_atom_cache.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698