Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / gfx / src / X11Util.h
blobe7e09f93fad4e61fc55e0460fd17c8799f8f7ee3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_X11Util_h
8 #define mozilla_X11Util_h
10 // Utilities common to all X clients, regardless of UI toolkit.
12 #if defined(MOZ_WIDGET_GTK)
13 # include <gdk/gdk.h>
14 # include <gdk/gdkx.h>
15 # include "mozilla/WidgetUtilsGtk.h"
16 # include "X11UndefineNone.h"
17 #else
18 # error Unknown toolkit
19 #endif
21 #include <string.h> // for memset
22 #include "mozilla/Scoped.h" // for SCOPED_TEMPLATE
24 namespace mozilla {
26 /**
27 * Return the default X Display created and used by the UI toolkit.
29 inline Display* DefaultXDisplay() {
30 #if defined(MOZ_WIDGET_GTK)
31 GdkDisplay* gdkDisplay = gdk_display_get_default();
32 if (mozilla::widget::GdkIsX11Display(gdkDisplay)) {
33 return GDK_DISPLAY_XDISPLAY(gdkDisplay);
35 #endif
36 return nullptr;
39 /**
40 * Sets *aVisual to point to aDisplay's Visual struct corresponding to
41 * aVisualID, and *aDepth to its depth. When aVisualID is None, these are set
42 * to nullptr and 0 respectively. Both out-parameter pointers are assumed
43 * non-nullptr.
45 void FindVisualAndDepth(Display* aDisplay, VisualID aVisualID, Visual** aVisual,
46 int* aDepth);
48 /**
49 * Ensure that all X requests have been processed.
51 * This is similar to XSync, but doesn't need a round trip if the previous
52 * request was synchronous or if events have been received since the last
53 * request. Subsequent FinishX calls will be noops if there have been no
54 * intermediate requests.
57 void FinishX(Display* aDisplay);
59 /**
60 * Invoke XFree() on a pointer to memory allocated by Xlib (if the
61 * pointer is nonnull) when this class goes out of scope.
63 template <typename T>
64 struct ScopedXFreePtrTraits {
65 typedef T* type;
66 static T* empty() { return nullptr; }
67 static void release(T* ptr) {
68 if (ptr != nullptr) XFree(ptr);
71 SCOPED_TEMPLATE(ScopedXFree, ScopedXFreePtrTraits)
73 } // namespace mozilla
75 #endif // mozilla_X11Util_h