summaryrefslogtreecommitdiffstats
path: root/gfx/src/X11Util.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /gfx/src/X11Util.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/src/X11Util.h')
-rw-r--r--gfx/src/X11Util.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/gfx/src/X11Util.h b/gfx/src/X11Util.h
new file mode 100644
index 0000000000..e7e09f93fa
--- /dev/null
+++ b/gfx/src/X11Util.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_X11Util_h
+#define mozilla_X11Util_h
+
+// Utilities common to all X clients, regardless of UI toolkit.
+
+#if defined(MOZ_WIDGET_GTK)
+# include <gdk/gdk.h>
+# include <gdk/gdkx.h>
+# include "mozilla/WidgetUtilsGtk.h"
+# include "X11UndefineNone.h"
+#else
+# error Unknown toolkit
+#endif
+
+#include <string.h> // for memset
+#include "mozilla/Scoped.h" // for SCOPED_TEMPLATE
+
+namespace mozilla {
+
+/**
+ * Return the default X Display created and used by the UI toolkit.
+ */
+inline Display* DefaultXDisplay() {
+#if defined(MOZ_WIDGET_GTK)
+ GdkDisplay* gdkDisplay = gdk_display_get_default();
+ if (mozilla::widget::GdkIsX11Display(gdkDisplay)) {
+ return GDK_DISPLAY_XDISPLAY(gdkDisplay);
+ }
+#endif
+ return nullptr;
+}
+
+/**
+ * Sets *aVisual to point to aDisplay's Visual struct corresponding to
+ * aVisualID, and *aDepth to its depth. When aVisualID is None, these are set
+ * to nullptr and 0 respectively. Both out-parameter pointers are assumed
+ * non-nullptr.
+ */
+void FindVisualAndDepth(Display* aDisplay, VisualID aVisualID, Visual** aVisual,
+ int* aDepth);
+
+/**
+ * Ensure that all X requests have been processed.
+ *
+ * This is similar to XSync, but doesn't need a round trip if the previous
+ * request was synchronous or if events have been received since the last
+ * request. Subsequent FinishX calls will be noops if there have been no
+ * intermediate requests.
+ */
+
+void FinishX(Display* aDisplay);
+
+/**
+ * Invoke XFree() on a pointer to memory allocated by Xlib (if the
+ * pointer is nonnull) when this class goes out of scope.
+ */
+template <typename T>
+struct ScopedXFreePtrTraits {
+ typedef T* type;
+ static T* empty() { return nullptr; }
+ static void release(T* ptr) {
+ if (ptr != nullptr) XFree(ptr);
+ }
+};
+SCOPED_TEMPLATE(ScopedXFree, ScopedXFreePtrTraits)
+
+} // namespace mozilla
+
+#endif // mozilla_X11Util_h