Panda3D
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 
29 typedef struct _XcursorFile XcursorFile;
30 typedef struct _XcursorImage XcursorImage;
31 typedef struct _XcursorImages XcursorImages;
32 
33 typedef unsigned short Rotation;
34 typedef unsigned short SizeID;
35 typedef struct _XRRScreenConfiguration XRRScreenConfiguration;
36 typedef struct {
37  int width, height;
38  int mwidth, mheight;
40 
42 
43 /**
44  * This graphics pipe represents the interface for creating graphics windows
45  * on an X-based client.
46  */
47 class x11GraphicsPipe : public GraphicsPipe {
48 public:
49  x11GraphicsPipe(const std::string &display = std::string());
50  virtual ~x11GraphicsPipe();
51 
52  INLINE X11_Display *get_display() const;
53  INLINE int get_screen() const;
54  INLINE X11_Window get_root() const;
55  INLINE XIM get_im() const;
56 
57  INLINE X11_Cursor get_hidden_cursor();
58 
59  INLINE bool supports_relative_mouse() const;
60  INLINE bool enable_relative_mouse();
61  INLINE void disable_relative_mouse();
62 
63  static INLINE int disable_x_error_messages();
64  static INLINE int enable_x_error_messages();
65  static INLINE int get_x_error_count();
66 
67 public:
68  virtual PreferredWindowThread get_preferred_window_thread() const;
69 
70 public:
71  // Atom specifications.
72  Atom _wm_delete_window;
73  Atom _net_wm_pid;
74  Atom _net_wm_window_type;
75  Atom _net_wm_window_type_splash;
76  Atom _net_wm_window_type_fullscreen;
77  Atom _net_wm_state;
78  Atom _net_wm_state_fullscreen;
79  Atom _net_wm_state_above;
80  Atom _net_wm_state_below;
81  Atom _net_wm_state_add;
82  Atom _net_wm_state_remove;
83  Atom _net_wm_bypass_compositor;
84 
85  // Extension functions.
86  typedef int (*pfn_XcursorGetDefaultSize)(X11_Display *);
87  typedef XcursorImages *(*pfn_XcursorXcFileLoadImages)(XcursorFile *, int);
88  typedef X11_Cursor (*pfn_XcursorImagesLoadCursor)(X11_Display *, const XcursorImages *);
89  typedef void (*pfn_XcursorImagesDestroy)(XcursorImages *);
90  typedef XcursorImage *(*pfn_XcursorImageCreate)(int, int);
91  typedef X11_Cursor (*pfn_XcursorImageLoadCursor)(X11_Display *, const XcursorImage *);
92  typedef void (*pfn_XcursorImageDestroy)(XcursorImage *);
93 
94  int _xcursor_size;
95  pfn_XcursorXcFileLoadImages _XcursorXcFileLoadImages;
96  pfn_XcursorImagesLoadCursor _XcursorImagesLoadCursor;
97  pfn_XcursorImagesDestroy _XcursorImagesDestroy;
98  pfn_XcursorImageCreate _XcursorImageCreate;
99  pfn_XcursorImageLoadCursor _XcursorImageLoadCursor;
100  pfn_XcursorImageDestroy _XcursorImageDestroy;
101 
102  typedef Bool (*pfn_XRRQueryExtension)(X11_Display *, int*, int*);
103  typedef XRRScreenSize *(*pfn_XRRSizes)(X11_Display*, int, int*);
104  typedef short *(*pfn_XRRRates)(X11_Display*, int, int, int*);
105  typedef XRRScreenConfiguration *(*pfn_XRRGetScreenInfo)(X11_Display*, X11_Window);
106  typedef SizeID (*pfn_XRRConfigCurrentConfiguration)(XRRScreenConfiguration*, Rotation*);
107  typedef Status (*pfn_XRRSetScreenConfig)(X11_Display*, XRRScreenConfiguration *,
108  Drawable, int, Rotation, Time);
109 
110  bool _have_xrandr;
111  pfn_XRRSizes _XRRSizes;
112  pfn_XRRRates _XRRRates;
113  pfn_XRRGetScreenInfo _XRRGetScreenInfo;
114  pfn_XRRConfigCurrentConfiguration _XRRConfigCurrentConfiguration;
115  pfn_XRRSetScreenConfig _XRRSetScreenConfig;
116 
117 protected:
118  X11_Display *_display;
119  int _screen;
120  X11_Window _root;
121  XIM _im;
122 
123  X11_Cursor _hidden_cursor;
124 
125  typedef Bool (*pfn_XF86DGAQueryVersion)(X11_Display *, int*, int*);
126  typedef Status (*pfn_XF86DGADirectVideo)(X11_Display *, int, int);
127  pfn_XF86DGADirectVideo _XF86DGADirectVideo;
128 
129 private:
130  void make_hidden_cursor();
131  void release_hidden_cursor();
132 
133  static void install_error_handlers();
134  static int error_handler(X11_Display *display, XErrorEvent *error);
135  static int io_error_handler(X11_Display *display);
136 
137  typedef int ErrorHandlerFunc(X11_Display *, XErrorEvent *);
138  typedef int IOErrorHandlerFunc(X11_Display *);
139  static bool _error_handlers_installed;
140  static ErrorHandlerFunc *_prev_error_handler;
141  static IOErrorHandlerFunc *_prev_io_error_handler;
142 
143  static bool _x_error_messages_enabled;
144  static int _x_error_count;
145 
146 public:
147  // This Mutex protects any X library calls, which all have to be single-
148  // threaded. In particular, it protects glXMakeCurrent().
149  static LightReMutex _x_mutex;
150 
151 public:
152  static TypeHandle get_class_type() {
153  return _type_handle;
154  }
155  static void init_type() {
156  GraphicsPipe::init_type();
157  register_type(_type_handle, "x11GraphicsPipe",
158  GraphicsPipe::get_class_type());
159  }
160  virtual TypeHandle get_type() const {
161  return get_class_type();
162  }
163  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
164 
165 private:
166  static TypeHandle _type_handle;
167 };
168 
169 #include "x11GraphicsPipe.I"
170 
171 #endif
XIM get_im() const
Returns the input method opened for the pipe, or NULL if the input method could not be opened for som...
This graphics pipe represents the interface for creating graphics windows on an X-based client.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static int disable_x_error_messages()
Globally disables the printing of error messages that are raised by the X11 system,...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight reentrant mutex.
Definition: lightReMutex.h:30
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
X11_Window get_root() const
Returns the handle to the root window on the pipe's display.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static int enable_x_error_messages()
Reenables the printing of error messages after a previous call to disable_x_error_messages().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void disable_relative_mouse()
Disables relative mouse mode for this display.
int get_screen() const
Returns the X screen number associated with the pipe.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:52
X11_Cursor get_hidden_cursor()
Returns an invisible Cursor suitable for assigning to windows that have the cursor_hidden property se...
X11_Display * get_display() const
Returns a pointer to the X display associated with the pipe: the display on which to create the windo...
virtual PreferredWindowThread get_preferred_window_thread() const
Returns an indication of the thread in which this GraphicsPipe requires its window processing to be p...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static int get_x_error_count()
Returns the number of times an error indication has been raised by the X11 system since application s...