blob: e7e09f93fad4e61fc55e0460fd17c8799f8f7ee3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
|