Blender  V3.3
GHOST_SystemX11.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
9 #pragma once
10 
11 #include <X11/XKBlib.h> /* Allow detectable auto-repeat. */
12 #include <X11/Xlib.h>
13 
14 #include "../GHOST_Types.h"
15 #include "GHOST_System.h"
16 
17 // For tablets
18 #ifdef WITH_X11_XINPUT
19 # include <X11/extensions/XInput.h>
20 
21 /* Disable XINPUT warp, currently not implemented by Xorg for multi-head display.
22  * (see comment in XSERVER `Xi/xiwarppointer.c` -> `FIXME: panoramix stuff is missing` ~ v1.13.4)
23  * If this is supported we can add back XINPUT for warping (fixing T48901).
24  * For now disable (see T50383). */
25 // # define USE_X11_XINPUT_WARP
26 #endif
27 
28 #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
29 # define GHOST_X11_RES_NAME "Blender" /* res_name */
30 # define GHOST_X11_RES_CLASS "Blender" /* res_class */
31 #endif
32 
33 /* generic error handlers */
34 int GHOST_X11_ApplicationErrorHandler(Display *display, XErrorEvent *theEvent);
35 int GHOST_X11_ApplicationIOErrorHandler(Display *display);
36 
37 #define GHOST_X11_ERROR_HANDLERS_OVERRIDE(var) \
38  struct { \
39  XErrorHandler handler; \
40  XIOErrorHandler handler_io; \
41  } var = { \
42  XSetErrorHandler(GHOST_X11_ApplicationErrorHandler), \
43  XSetIOErrorHandler(GHOST_X11_ApplicationIOErrorHandler), \
44  }
45 
46 #define GHOST_X11_ERROR_HANDLERS_RESTORE(var) \
47  { \
48  (void)XSetErrorHandler(var.handler); \
49  (void)XSetIOErrorHandler(var.handler_io); \
50  } \
51  ((void)0)
52 
53 class GHOST_WindowX11;
54 
60 class GHOST_SystemX11 : public GHOST_System {
61  public:
68 
73 
75 
85  uint64_t getMilliSeconds() const;
86 
91  uint8_t getNumDisplays() const;
92 
98 
104 
122  GHOST_IWindow *createWindow(const char *title,
123  int32_t left,
124  int32_t top,
125  uint32_t width,
129  GHOST_GLSettings glSettings,
130  const bool exclusive = false,
131  const bool is_dialog = false,
132  const GHOST_IWindow *parentWindow = 0);
133 
140 
147 
153  bool processEvents(bool waitForEvent);
154 
156 
158 
165 
171  GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const;
172 
178  void addDirtyWindow(GHOST_WindowX11 *bad_wind);
179 
184  Display *getXDisplay()
185  {
186  return m_display;
187  }
188 
189 #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
190  XIM getX11_XIM()
191  {
192  return m_xim;
193  }
194 #endif
195 
197  void getClipboard_xcout(const XEvent *evt,
198  Atom sel,
199  Atom target,
200  unsigned char **txt,
201  unsigned long *len,
202  unsigned int *context) const;
203 
209  char *getClipboard(bool selection) const;
210 
216  void putClipboard(const char *buffer, bool selection) const;
217 
227  GHOST_TSuccess showMessageBox(const char *title,
228  const char *message,
229  const char *help_label,
230  const char *continue_label,
231  const char *link,
232  GHOST_DialogOptions dialog_options) const;
233 #ifdef WITH_XDND
245  static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType,
246  GHOST_TDragnDropTypes draggedObjectType,
247  GHOST_IWindow *window,
248  int mouseX,
249  int mouseY,
250  void *data);
251 #endif
252 
257  {
258  return 0;
259  }
260 
261 #ifdef WITH_X11_XINPUT
262  typedef struct GHOST_TabletX11 {
263  GHOST_TTabletMode mode;
264  XDevice *Device;
265  XID ID;
266 
267  int MotionEvent;
268  int ProxInEvent;
269  int ProxOutEvent;
270  int PressEvent;
271 
272  int PressureLevels;
273  int XtiltLevels, YtiltLevels;
274  } GHOST_TabletX11;
275 
276  std::vector<GHOST_TabletX11> &GetXTablets()
277  {
278  return m_xtablets;
279  }
280 #endif // WITH_X11_XINPUT
281 
282  struct {
289  Atom WM_STATE;
299 
300  /* Atoms for Selection, copy & paste. */
301  Atom TARGETS;
302  Atom STRING;
304  Atom TEXT;
305  Atom CLIPBOARD;
306  Atom PRIMARY;
307  Atom XCLIP_OUT;
308  Atom INCR;
310 #ifdef WITH_X11_XINPUT
311  Atom TABLET;
312 #endif
314 
315 #ifdef WITH_X11_XINPUT
316  XExtensionVersion m_xinput_version;
317 #endif
318 
319  private:
320  Display *m_display;
321 
323  XkbDescRec *m_xkb_descr;
324 
325 #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
326  XIM m_xim;
327 #endif
328 
329 #ifdef WITH_X11_XINPUT
330  /* Tablet devices */
331  std::vector<GHOST_TabletX11> m_xtablets;
332 #endif
333 
335  std::vector<GHOST_WindowX11 *> m_dirty_windows;
336 
338  uint64_t m_start_time;
339 
341  char m_keyboard_vector[32];
342 
347  Time m_last_warp_x;
348  Time m_last_warp_y;
349 
350  /* Detect auto-repeat glitch. */
351  unsigned int m_last_release_keycode;
352  Time m_last_release_time;
353 
354  uint m_keycode_last_repeat_key;
355 
361 #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING)
362  bool openX11_IM();
363 #endif
364 
365 #ifdef WITH_X11_XINPUT
366  void clearXInputDevices();
367  void refreshXInputDevices();
368 #endif
369 
370  GHOST_WindowX11 *findGhostWindow(Window xwind) const;
371 
372  void processEvent(XEvent *xe);
373 
374  Time lastEventTime(Time default_time);
375 
376  bool generateWindowExposeEvents();
377 };
unsigned int uint
Definition: BLI_sys_types.h:67
struct ID ID
int GHOST_X11_ApplicationIOErrorHandler(Display *display)
int GHOST_X11_ApplicationErrorHandler(Display *display, XErrorEvent *theEvent)
GHOST_TWindowState
Definition: GHOST_Types.h:129
GHOST_TEventType
Definition: GHOST_Types.h:169
GHOST_TTabletMode
Definition: GHOST_Types.h:83
GHOST_TDrawingContextType
Definition: GHOST_Types.h:148
GHOST_TSuccess
Definition: GHOST_Types.h:74
GHOST_TDragnDropTypes
Definition: GHOST_Types.h:474
GHOST_TConsoleWindowState
Definition: GHOST_Types.h:139
GHOST_DialogOptions
Definition: GHOST_Types.h:67
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble top
int setConsoleWindowState(GHOST_TConsoleWindowState)
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type, GHOST_GLSettings glSettings, const bool exclusive=false, const bool is_dialog=false, const GHOST_IWindow *parentWindow=0)
GHOST_TSuccess disposeContext(GHOST_IContext *context)
void getClipboard_xcout(const XEvent *evt, Atom sel, Atom target, unsigned char **txt, unsigned long *len, unsigned int *context) const
GHOST_IContext * createOffscreenContext(GHOST_GLSettings glSettings)
void addDirtyWindow(GHOST_WindowX11 *bad_wind)
GHOST_TSuccess init()
char * getClipboard(bool selection) const
Atom _NET_WM_STATE_MAXIMIZED_VERT
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const
void putClipboard(const char *buffer, bool selection) const
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y)
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const
Display * getXDisplay()
uint64_t getMilliSeconds() const
uint8_t getNumDisplays() const
bool processEvents(bool waitForEvent)
struct GHOST_SystemX11::@1294 m_atom
GHOST_TSuccess showMessageBox(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options) const
Atom _NET_WM_STATE_MAXIMIZED_HORZ
int len
Definition: draw_manager.c:108
ccl_global float * buffer
const int state
static int left
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78
unsigned __int64 uint64_t
Definition: stdint.h:90