Panda3D
Loading...
Searching...
No Matches
x11GraphicsPipe.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file x11GraphicsPipe.h
10 * @author rdb
11 * @date 2009-07-07
12 */
13
14#ifndef X11GRAPHICSPIPE_H
15#define X11GRAPHICSPIPE_H
16
17#include "pandabase.h"
18#include "graphicsWindow.h"
19#include "graphicsPipe.h"
20#include "lightMutex.h"
21#include "lightReMutex.h"
22#include "windowHandle.h"
23#include "get_x11.h"
24#include "config_x11display.h"
25
26// Excerpt the few definitions we need for the extensions.
27#define XF86DGADirectMouse 0x0004
28
29typedef struct _XcursorFile XcursorFile;
30typedef struct _XcursorImage XcursorImage;
31typedef struct _XcursorImages XcursorImages;
32
33typedef unsigned short Rotation;
34typedef unsigned short SizeID;
35typedef unsigned long XRRModeFlags;
36typedef XID RROutput;
37typedef XID RRCrtc;
38typedef XID RRMode;
39
40typedef struct _XRRScreenConfiguration XRRScreenConfiguration;
41typedef struct {
42 int width, height;
43 int mwidth, mheight;
45
46typedef struct _XRRModeInfo {
47 RRMode id;
48 unsigned int width;
49 unsigned int height;
50 unsigned long dotClock;
51 unsigned int hSyncStart;
52 unsigned int hSyncEnd;
53 unsigned int hTotal;
54 unsigned int hSkew;
55 unsigned int vSyncStart;
56 unsigned int vSyncEnd;
57 unsigned int vTotal;
58 char *name;
59 unsigned int nameLength;
60 XRRModeFlags modeFlags;
62
63typedef struct _XRRScreenResources {
64 Time timestamp;
65 Time configTimestamp;
66 int ncrtc;
67 RRCrtc *crtcs;
68 int noutput;
69 RROutput *outputs;
70 int nmode;
71 XRRModeInfo *modes;
73
74typedef struct _XRRCrtcInfo {
75 Time timestamp;
76 int x, y;
77 unsigned int width, height;
78 RRMode mode;
79 Rotation rotation;
80 int noutput;
81 RROutput *outputs;
82 Rotation rotations;
83 int npossible;
84 RROutput *possible;
86
87typedef void (*pfn_XRRFreeScreenResources)(XRRScreenResources *resources);
88typedef void (*pfn_XRRFreeCrtcInfo)(XRRCrtcInfo *crtcInfo);
89
91
92/**
93 * This graphics pipe represents the interface for creating graphics windows
94 * on an X-based client.
95 */
97public:
98 x11GraphicsPipe(const std::string &display = std::string());
99 virtual ~x11GraphicsPipe();
100
101 INLINE X11_Display *get_display() const;
102 INLINE int get_screen() const;
103 INLINE X11_Window get_root() const;
104 INLINE XIM get_im() const;
105
106 INLINE X11_Cursor get_hidden_cursor();
107
108 INLINE bool supports_relative_mouse() const;
109 INLINE bool enable_relative_mouse();
110 INLINE void disable_relative_mouse();
111
112 static INLINE int disable_x_error_messages();
113 static INLINE int enable_x_error_messages();
114 static INLINE int get_x_error_count();
115
116 std::unique_ptr<XRRScreenResources, pfn_XRRFreeScreenResources> get_screen_resources() const;
117 std::unique_ptr<XRRCrtcInfo, pfn_XRRFreeCrtcInfo> get_crtc_info(XRRScreenResources *res, RRCrtc crtc) const;
118
119 RRCrtc find_fullscreen_crtc(const LPoint2i &point,
120 int &x, int &y, int &width, int &height);
121
122public:
123 virtual PreferredWindowThread get_preferred_window_thread() const;
124
125public:
126 // Atom specifications.
127 Atom _wm_delete_window;
128 Atom _net_wm_name;
129 Atom _net_wm_pid;
130 Atom _net_wm_window_type;
131 Atom _net_wm_window_type_splash;
132 Atom _net_wm_window_type_fullscreen;
133 Atom _net_wm_state;
134 Atom _net_wm_state_fullscreen;
135 Atom _net_wm_state_above;
136 Atom _net_wm_state_below;
137 Atom _net_wm_state_add;
138 Atom _net_wm_state_remove;
139 Atom _net_wm_bypass_compositor;
140
141 // Extension functions.
142 typedef int (*pfn_XcursorGetDefaultSize)(X11_Display *);
143 typedef XcursorImages *(*pfn_XcursorXcFileLoadImages)(XcursorFile *, int);
144 typedef X11_Cursor (*pfn_XcursorImagesLoadCursor)(X11_Display *, const XcursorImages *);
145 typedef void (*pfn_XcursorImagesDestroy)(XcursorImages *);
146 typedef XcursorImage *(*pfn_XcursorImageCreate)(int, int);
147 typedef X11_Cursor (*pfn_XcursorImageLoadCursor)(X11_Display *, const XcursorImage *);
148 typedef void (*pfn_XcursorImageDestroy)(XcursorImage *);
149
150 int _xcursor_size;
151 pfn_XcursorXcFileLoadImages _XcursorXcFileLoadImages;
152 pfn_XcursorImagesLoadCursor _XcursorImagesLoadCursor;
153 pfn_XcursorImagesDestroy _XcursorImagesDestroy;
154 pfn_XcursorImageCreate _XcursorImageCreate;
155 pfn_XcursorImageLoadCursor _XcursorImageLoadCursor;
156 pfn_XcursorImageDestroy _XcursorImageDestroy;
157
158 typedef Bool (*pfn_XRRQueryExtension)(X11_Display *, int*, int*);
159 typedef Status (*pfn_XRRQueryVersion)(X11_Display *, int*, int*);
160 typedef XRRScreenSize *(*pfn_XRRSizes)(X11_Display*, int, int*);
161 typedef short *(*pfn_XRRRates)(X11_Display*, int, int, int*);
162 typedef XRRScreenConfiguration *(*pfn_XRRGetScreenInfo)(X11_Display*, X11_Window);
163 typedef SizeID (*pfn_XRRConfigCurrentConfiguration)(XRRScreenConfiguration*, Rotation*);
164 typedef Status (*pfn_XRRSetScreenConfig)(X11_Display*, XRRScreenConfiguration *,
165 Drawable, int, Rotation, Time);
166
167 bool _have_xrandr;
168 pfn_XRRSizes _XRRSizes;
169 pfn_XRRRates _XRRRates;
170 pfn_XRRGetScreenInfo _XRRGetScreenInfo;
171 pfn_XRRConfigCurrentConfiguration _XRRConfigCurrentConfiguration;
172 pfn_XRRSetScreenConfig _XRRSetScreenConfig;
173
174protected:
175 X11_Display *_display;
176 int _screen;
177 X11_Window _root;
178 XIM _im;
179
180 X11_Cursor _hidden_cursor;
181
182 typedef Bool (*pfn_XF86DGAQueryVersion)(X11_Display *, int*, int*);
183 typedef Status (*pfn_XF86DGADirectVideo)(X11_Display *, int, int);
184 pfn_XF86DGADirectVideo _XF86DGADirectVideo;
185
186 typedef XRRScreenResources *(*pfn_XRRGetScreenResources)(X11_Display*, X11_Window);
187 typedef XRRCrtcInfo *(*pfn_XRRGetCrtcInfo)(X11_Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
188
189 pfn_XRRGetScreenResources _XRRGetScreenResourcesCurrent;
190 pfn_XRRFreeScreenResources _XRRFreeScreenResources;
191 pfn_XRRGetCrtcInfo _XRRGetCrtcInfo;
192 pfn_XRRFreeCrtcInfo _XRRFreeCrtcInfo;
193
194private:
195 void make_hidden_cursor();
196 void release_hidden_cursor();
197
198 static void install_error_handlers();
199 static int error_handler(X11_Display *display, XErrorEvent *error);
200 static int io_error_handler(X11_Display *display);
201
202 typedef int ErrorHandlerFunc(X11_Display *, XErrorEvent *);
203 typedef int IOErrorHandlerFunc(X11_Display *);
204 static bool _error_handlers_installed;
205 static ErrorHandlerFunc *_prev_error_handler;
206 static IOErrorHandlerFunc *_prev_io_error_handler;
207
208 static bool _x_error_messages_enabled;
209 static int _x_error_count;
210
211public:
212 // This Mutex protects any X library calls, which all have to be single-
213 // threaded. In particular, it protects glXMakeCurrent().
214 static LightReMutex _x_mutex;
215
216public:
217 static TypeHandle get_class_type() {
218 return _type_handle;
219 }
220 static void init_type() {
221 GraphicsPipe::init_type();
222 register_type(_type_handle, "x11GraphicsPipe",
223 GraphicsPipe::get_class_type());
224 }
225 virtual TypeHandle get_type() const {
226 return get_class_type();
227 }
228 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
229
230private:
231 static TypeHandle _type_handle;
232};
233
234#include "x11GraphicsPipe.I"
235
236#endif
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
An object to create GraphicsOutputs that share a particular 3-D API.
A lightweight reentrant mutex.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This graphics pipe represents the interface for creating graphics windows on an X-based client.
X11_Window get_root() const
Returns the handle to the root window on the pipe's display.
static int enable_x_error_messages()
Reenables the printing of error messages after a previous call to disable_x_error_messages().
X11_Display * get_display() const
Returns a pointer to the X display associated with the pipe: the display on which to create the windo...
std::unique_ptr< XRRScreenResources, pfn_XRRFreeScreenResources > get_screen_resources() const
Returns an XRRScreenResources object, or null if RandR 1.2 is not supported.
std::unique_ptr< XRRCrtcInfo, pfn_XRRFreeCrtcInfo > get_crtc_info(XRRScreenResources *res, RRCrtc crtc) const
Returns an XRRCrtcInfo object, or null if RandR 1.2 is not supported.
RRCrtc find_fullscreen_crtc(const LPoint2i &point, int &x, int &y, int &width, int &height)
Finds a CRTC for going fullscreen to, at the given origin.
int get_screen() const
Returns the X screen number associated with the pipe.
XIM get_im() const
Returns the input method opened for the pipe, or NULL if the input method could not be opened for som...
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
bool supports_relative_mouse() const
Returns true if relative mouse mode is supported on this display.
bool enable_relative_mouse()
Enables relative mouse mode for this display.
static int disable_x_error_messages()
Globally disables the printing of error messages that are raised by the X11 system,...
static int get_x_error_count()
Returns the number of times an error indication has been raised by the X11 system since application s...
X11_Cursor get_hidden_cursor()
Returns an invisible Cursor suitable for assigning to windows that have the cursor_hidden property se...
void disable_relative_mouse()
Disables relative mouse mode for this display.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.