X11OpenGLWindow.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. #include "X11OpenGLWindow.h"
  2. #include "OpenGLInclude.h"
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #ifdef GLEW_STATIC
  6. #include "CustomGL/glew.h"
  7. #else
  8. #include <GL/glew.h>
  9. #endif//GLEW_STATIC
  10. #ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
  11. #include "CustomGL/glxew.h"
  12. #else
  13. #include<GL/glx.h>
  14. #endif // GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
  15. #include <assert.h>
  16. //#define DYNAMIC_LOAD_X11_FUNCTIONS
  17. #ifdef DYNAMIC_LOAD_X11_FUNCTIONS
  18. #include <dlfcn.h>
  19. #endif //DYNAMIC_LOAD_X11_FUNCTIONS
  20. //#include<X11/X.h>
  21. //#include<X11/Xlib.h>
  22. //#include<GL/gl.h>
  23. //defined in GL/glxew.h
  24. //#include<GL/glu.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <pthread.h>
  30. GLint att[] = { GLX_RGBA,
  31. GLX_DEPTH_SIZE, 24,
  32. GLX_RED_SIZE , 8,
  33. GLX_GREEN_SIZE , 8,
  34. GLX_BLUE_SIZE , 8,
  35. GLX_ALPHA_SIZE , 8,
  36. GLX_STENCIL_SIZE , 8,
  37. GLX_DOUBLEBUFFER,
  38. None };
  39. /*
  40. static int att[] =
  41. {
  42. GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None
  43. GLX_X_RENDERABLE , True,
  44. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  45. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  46. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  47. GLX_RED_SIZE , 8,
  48. GLX_GREEN_SIZE , 8,
  49. GLX_BLUE_SIZE , 8,
  50. GLX_ALPHA_SIZE , 8,
  51. GLX_DEPTH_SIZE , 24,
  52. GLX_STENCIL_SIZE , 8,
  53. GLX_DOUBLEBUFFER , True,
  54. None
  55. };
  56. */
  57. static bool forceOpenGL3 = true;
  58. #ifdef DYNAMIC_LOAD_X11_FUNCTIONS
  59. ///our X11 function typedefs
  60. typedef int (*PFNXFREE)(void*);
  61. typedef XErrorHandler (* PFNXSETERRORHANDLER) (XErrorHandler);
  62. typedef int (* PFNXSYNC) (Display* a,Bool b);
  63. typedef Display* (* PFNXOPENDISPLAY) (_Xconst char* a);
  64. typedef Colormap (*PFNXCREATECOLORMAP) (Display* a,Window b,Visual* c,int d);
  65. typedef Window (*PFNXCREATEWINDOW) (Display* a,Window b,int c,int d,unsigned int e,unsigned int f,unsigned int g,int h,unsigned int i,Visual* j,unsigned long k,XSetWindowAttributes* l);
  66. typedef int (*PFNXMAPWINDOW) (Display*, Window);
  67. typedef int (*PFNXSTORENAME) (Display* a,Window b,_Xconst char* c);
  68. typedef int (*PFNXCLOSEDISPLAY) (Display* a);
  69. typedef int (*PFNXDESTROYWINDOW) (Display* a,Window b);
  70. typedef int (*PFNXRAISEWINDOW) (Display* a, Window b);
  71. #if NeedWidePrototypes
  72. typedef KeySym* (*PFNXGETKEYBOARDMAPPING) (Display*,unsigned int,int,int*);
  73. typedef KeySym (*PFNXKEYCODETOKEYSYM) (Display* a,unsigned int b,int c);
  74. #else
  75. typedef KeySym* (*PFNXGETKEYBOARDMAPPING) (Display*,KeyCode,int,int*);
  76. typedef KeySym (*PFNXKEYCODETOKEYSYM) (Display* a,KeyCode b,int c);
  77. #endif
  78. typedef void (*PFNXCONVERTCASE) (KeySym /* sym */,KeySym * /* lower */,KeySym * /* upper */);
  79. typedef int (*PFNXPENDING) (Display* a);
  80. typedef int (*PFNXNEXTEVENT) (Display* a,XEvent* b);
  81. typedef int (*PFNXEVENTSQUEUED) (Display* a,int b);
  82. typedef int (*PFNXPEEKEVENT) (Display* a,XEvent* b);
  83. typedef KeySym (*PFNXLOOKUPKEYSYM) (XKeyEvent* a,int b);
  84. typedef Status (*PFNXGETWINDOWATTRIBUTES) (Display* a,Window b,XWindowAttributes* c);
  85. #define X11_LIBRARY "libX11.so.6"
  86. #define MyXSync m_data->m_x11_XSync
  87. #define MyXGetKeyboardMapping m_data->m_x11_XGetKeyboardMapping
  88. #define MyXSetErrorHandler m_data->m_x11_XSetErrorHandler
  89. #define MyXOpenDisplay m_data->m_x11_XOpenDisplay
  90. #define MyXCreateColormap m_data->m_x11_XCreateColormap
  91. #define MyXCreateWindow m_data->m_x11_XCreateWindow
  92. #define MyXMapWindow m_data->m_x11_XMapWindow
  93. #define MyXStoreName m_data->m_x11_XStoreName
  94. #define MyXDestroyWindow m_data->m_x11_XDestroyWindow
  95. #define MyXRaiseWindow m_data->m_x11_XRaiseWindow
  96. #define MyXCloseDisplay m_data->m_x11_XCloseDisplay
  97. #define MyXKeycodeToKeysym m_data->m_x11_XKeycodeToKeysym
  98. #define MyXConvertCase m_data->m_x11_XConvertCase
  99. #define MyXPending m_data->m_x11_XPending
  100. #define MyXNextEvent m_data->m_x11_XNextEvent
  101. #define MyXEventsQueued m_data->m_x11_XEventsQueued
  102. #define MyXPeekEvent m_data->m_x11_XPeekEvent
  103. #define MyXNextEvent m_data->m_x11_XNextEvent
  104. #define MyXGetWindowAttributes m_data->m_x11_XGetWindowAttributes
  105. #define MyXStoreName m_data->m_x11_XStoreName
  106. #define MyXFree m_data->m_x11_XFree
  107. #define MyXMapWindow m_data->m_x11_XMapWindow
  108. #define MyXStoreName m_data->m_x11_XStoreName
  109. #define MyXLookupKeysym m_data->m_x11_XLookupKeysym
  110. #else
  111. #define MyXSync XSync
  112. #define MyXGetKeyboardMapping XGetKeyboardMapping
  113. #define MyXSetErrorHandler XSetErrorHandler
  114. #define MyXOpenDisplay XOpenDisplay
  115. #define MyXCreateColormap XCreateColormap
  116. #define MyXCreateWindow XCreateWindow
  117. #define MyXMapWindow XMapWindow
  118. #define MyXStoreName XStoreName
  119. #define MyXDestroyWindow XDestroyWindow
  120. #define MyXRaiseWindow XRaiseWindow
  121. #define MyXCloseDisplay XCloseDisplay
  122. #define MyXKeycodeToKeysym XKeycodeToKeysym
  123. #define MyXConvertCase XConvertCase
  124. #define MyXPending XPending
  125. #define MyXNextEvent XNextEvent
  126. #define MyXEventsQueued XEventsQueued
  127. #define MyXPeekEvent XPeekEvent
  128. #define MyXNextEvent XNextEvent
  129. #define MyXGetWindowAttributes XGetWindowAttributes
  130. #define MyXStoreName XStoreName
  131. #define MyXFree XFree
  132. #define MyXMapWindow XMapWindow
  133. #define MyXStoreName XStoreName
  134. #define MyXLookupKeysym XLookupKeysym
  135. #endif//DYNAMIC_LOAD_X11_FUNCTIONS
  136. enum
  137. {
  138. MY_X11_ALT_KEY = 1,
  139. MY_X11_SHIFT_KEY = 2,
  140. MY_X11_CONTROL_KEY = 4
  141. };
  142. struct InternalData2
  143. {
  144. Display* m_dpy;
  145. Window m_root;
  146. XVisualInfo* m_vi;
  147. Colormap m_cmap;
  148. XSetWindowAttributes m_swa;
  149. Window m_win;
  150. GLXContext m_glc;
  151. XWindowAttributes m_gwa;
  152. XEvent m_xev;
  153. GLXFBConfig m_bestFbc;
  154. int m_modifierFlags;
  155. #ifdef DYNAMIC_LOAD_X11_FUNCTIONS
  156. //dynamically load stuff
  157. void* m_x11_library;
  158. PFNXFREE m_x11_XFree;
  159. PFNXSETERRORHANDLER m_x11_XSetErrorHandler;
  160. PFNXSYNC m_x11_XSync;
  161. PFNXOPENDISPLAY m_x11_XOpenDisplay;
  162. PFNXCREATECOLORMAP m_x11_XCreateColormap;
  163. PFNXCREATEWINDOW m_x11_XCreateWindow;
  164. PFNXMAPWINDOW m_x11_XMapWindow;
  165. PFNXSTORENAME m_x11_XStoreName;
  166. PFNXCLOSEDISPLAY m_x11_XCloseDisplay;
  167. PFNXDESTROYWINDOW m_x11_XDestroyWindow;
  168. PFNXRAISEWINDOW m_x11_XRaiseWindow;
  169. PFNXKEYCODETOKEYSYM m_x11_XKeycodeToKeysym;
  170. PFNXGETKEYBOARDMAPPING m_x11_XGetKeyboardMapping;
  171. PFNXCONVERTCASE m_x11_XConvertCase;
  172. PFNXPENDING m_x11_XPending;
  173. PFNXNEXTEVENT m_x11_XNextEvent;
  174. PFNXEVENTSQUEUED m_x11_XEventsQueued;
  175. PFNXPEEKEVENT m_x11_XPeekEvent;
  176. PFNXLOOKUPKEYSYM m_x11_XLookupKeysym;
  177. PFNXGETWINDOWATTRIBUTES m_x11_XGetWindowAttributes;
  178. #endif //DYNAMIC_LOAD_X11_FUNCTIONS
  179. b3WheelCallback m_wheelCallback;
  180. b3MouseMoveCallback m_mouseMoveCallback;
  181. b3MouseButtonCallback m_mouseButtonCallback;
  182. b3ResizeCallback m_resizeCallback;
  183. b3KeyboardCallback m_keyboardCallback;
  184. InternalData2()
  185. :m_dpy(0),
  186. m_vi(0),
  187. m_wheelCallback(0),
  188. m_mouseMoveCallback(0),
  189. m_mouseButtonCallback(0),
  190. m_resizeCallback(0),
  191. m_keyboardCallback(0)
  192. {
  193. #ifdef DYNAMIC_LOAD_X11_FUNCTIONS
  194. m_x11_library = dlopen(X11_LIBRARY, RTLD_LOCAL | RTLD_NOW);
  195. if (!m_x11_library)
  196. {
  197. printf("Error opening X11 library %s\n", X11_LIBRARY);
  198. exit(0);
  199. }
  200. bool missingFunc = false;
  201. missingFunc = ((m_x11_XFree = (PFNXFREE) dlsym(m_x11_library, "XFree"))==NULL) | missingFunc;
  202. assert(!missingFunc);
  203. if (missingFunc) { printf("Error: missing func XFree in %s, exiting!\n", X11_LIBRARY); exit(0);}
  204. missingFunc = ((m_x11_XSetErrorHandler = (PFNXSETERRORHANDLER) dlsym(m_x11_library,"XSetErrorHandler"))==NULL) | missingFunc;
  205. if (missingFunc) { printf("Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(0);}
  206. missingFunc = ((m_x11_XSetErrorHandler = (PFNXSETERRORHANDLER) dlsym(m_x11_library,"XSetErrorHandler"))==NULL) | missingFunc;
  207. if (missingFunc) { printf("Error: missing func XSetErrorHandler in %s, exiting!\n", X11_LIBRARY); exit(0);}
  208. missingFunc = ((m_x11_XSync = (PFNXSYNC) dlsym(m_x11_library,"XSync"))==NULL) | missingFunc;
  209. if (missingFunc) { printf("Error: missing func XSync in %s, exiting!\n", X11_LIBRARY); exit(0);}
  210. missingFunc = ((m_x11_XOpenDisplay = (PFNXOPENDISPLAY) dlsym(m_x11_library,"XOpenDisplay"))==NULL) | missingFunc;
  211. if (missingFunc) { printf("Error: missing func XOpenDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
  212. missingFunc = ((m_x11_XCreateColormap = (PFNXCREATECOLORMAP) dlsym(m_x11_library,"XCreateColormap"))==NULL) | missingFunc;
  213. if (missingFunc) { printf("Error: missing func XCreateColormap in %s, exiting!\n", X11_LIBRARY); exit(0);}
  214. missingFunc = ((m_x11_XCreateWindow = (PFNXCREATEWINDOW) dlsym(m_x11_library,"XCreateWindow"))==NULL) | missingFunc;
  215. if (missingFunc) { printf("Error: missing func XCreateWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
  216. missingFunc = ((m_x11_XMapWindow = (PFNXMAPWINDOW) dlsym(m_x11_library,"XMapWindow"))==NULL) | missingFunc;
  217. if (missingFunc) { printf("Error: missing func XMapWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
  218. missingFunc = ((m_x11_XStoreName = (PFNXSTORENAME) dlsym(m_x11_library,"XStoreName"))==NULL) | missingFunc;
  219. if (missingFunc) { printf("Error: missing func XStoreName in %s, exiting!\n", X11_LIBRARY); exit(0);}
  220. missingFunc = ((m_x11_XCloseDisplay = (PFNXCLOSEDISPLAY) dlsym(m_x11_library,"XCloseDisplay"))==NULL) | missingFunc;
  221. if (missingFunc) { printf("Error: missing func XCloseDisplay in %s, exiting!\n", X11_LIBRARY); exit(0);}
  222. missingFunc = ((m_x11_XDestroyWindow = (PFNXDESTROYWINDOW) dlsym(m_x11_library,"XDestroyWindow"))==NULL) | missingFunc;
  223. if (missingFunc) { printf("Error: missing func XDestroyWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
  224. missingFunc = ((m_x11_XRaiseWindow = (PFNXRAISEWINDOW) dlsym(m_x11_library,"XRaiseWindow"))==NULL) | missingFunc;
  225. if (missingFunc) { printf("Error: missing func XRaiseWindow in %s, exiting!\n", X11_LIBRARY); exit(0);}
  226. missingFunc = ((m_x11_XGetKeyboardMapping = (PFNXGETKEYBOARDMAPPING) dlsym(m_x11_library,"XGetKeyboardMapping"))==NULL) | missingFunc;
  227. if (missingFunc) { printf("Error: missing func XGetKeyboardMapping in %s, exiting!\n", X11_LIBRARY); exit(0);}
  228. missingFunc = ((m_x11_XKeycodeToKeysym = (PFNXKEYCODETOKEYSYM) dlsym(m_x11_library,"XKeycodeToKeysym"))==NULL) | missingFunc;
  229. if (missingFunc) { printf("Error: missing func XKeycodeToKeysym in %s, exiting!\n", X11_LIBRARY); exit(0);}
  230. missingFunc = ((m_x11_XConvertCase = (PFNXCONVERTCASE) dlsym(m_x11_library,"XConvertCase"))==NULL) | missingFunc;
  231. if (missingFunc) { printf("Error: missing func XConvertCase in %s, exiting!\n", X11_LIBRARY); exit(0);}
  232. missingFunc = ((m_x11_XPending = (PFNXPENDING) dlsym(m_x11_library,"XPending"))==NULL) | missingFunc;
  233. if (missingFunc) { printf("Error: missing func XPending in %s, exiting!\n", X11_LIBRARY); exit(0);}
  234. missingFunc = ((m_x11_XNextEvent = (PFNXNEXTEVENT) dlsym(m_x11_library,"XNextEvent"))==NULL) | missingFunc;
  235. if (missingFunc) { printf("Error: missing func XNextEvent in %s, exiting!\n", X11_LIBRARY); exit(0);}
  236. missingFunc = ((m_x11_XEventsQueued = (PFNXEVENTSQUEUED) dlsym(m_x11_library,"XEventsQueued"))==NULL) | missingFunc;
  237. if (missingFunc) { printf("Error: missing func XEventsQueued in %s, exiting!\n", X11_LIBRARY); exit(0);}
  238. missingFunc = ((m_x11_XPeekEvent = (PFNXPEEKEVENT) dlsym(m_x11_library,"XPeekEvent"))==NULL) | missingFunc;
  239. if (missingFunc) { printf("Error: missing func XPeekEvent in %s, exiting!\n", X11_LIBRARY); exit(0);}
  240. missingFunc = ((m_x11_XLookupKeysym = (PFNXLOOKUPKEYSYM) dlsym(m_x11_library,"XLookupKeysym"))==NULL) | missingFunc;
  241. if (missingFunc) { printf("Error: missing func XLookupKeysym in %s, exiting!\n", X11_LIBRARY); exit(0);}
  242. missingFunc = ((m_x11_XGetWindowAttributes = (PFNXGETWINDOWATTRIBUTES) dlsym(m_x11_library,"XGetWindowAttributes"))==NULL) | missingFunc;
  243. if (missingFunc) { printf("Error: missing func XGetWindowAttributes in %s, exiting!\n", X11_LIBRARY); exit(0);}
  244. if (missingFunc)
  245. {
  246. printf("Error: a missing func in %s, exiting!\n", X11_LIBRARY);
  247. exit(0);
  248. } else
  249. {
  250. printf("X11 functions dynamically loaded using dlopen/dlsym OK!\n");
  251. }
  252. #endif //DYNAMIC_LOAD_X11_FUNCTIONS
  253. }
  254. };
  255. #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
  256. #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
  257. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
  258. // Helper to check for extension string presence. Adapted from:
  259. // http://www.opengl.org/resources/features/OGLextensions/
  260. static bool isExtensionSupported(const char *extList, const char *extension)
  261. {
  262. const char *start;
  263. const char *where, *terminator;
  264. /* Extension names should not have spaces. */
  265. where = strchr(extension, ' ');
  266. if (where || *extension == '\0')
  267. return false;
  268. /* It takes a bit of care to be fool-proof about parsing the
  269. OpenGL extensions string. Don't be fooled by sub-strings,
  270. etc. */
  271. for (start=extList;;) {
  272. where = strstr(start, extension);
  273. if (!where)
  274. break;
  275. terminator = where + strlen(extension);
  276. if ( where == start || *(where - 1) == ' ' )
  277. if ( *terminator == ' ' || *terminator == '\0' )
  278. return true;
  279. start = terminator;
  280. }
  281. return false;
  282. }
  283. static bool ctxErrorOccurred = false;
  284. static int ctxErrorHandler( Display *dpy, XErrorEvent *ev )
  285. {
  286. ctxErrorOccurred = true;
  287. return 0;
  288. }
  289. X11OpenGLWindow::X11OpenGLWindow()
  290. :m_OpenGLInitialized(false),
  291. m_requestedExit(false)
  292. {
  293. m_data = new InternalData2;
  294. }
  295. X11OpenGLWindow::~X11OpenGLWindow()
  296. {
  297. if (m_OpenGLInitialized)
  298. {
  299. disableOpenGL();
  300. }
  301. delete m_data;
  302. }
  303. void X11OpenGLWindow::enableOpenGL()
  304. {
  305. if (forceOpenGL3)
  306. {
  307. // Get the default screen's GLX extension list
  308. const char *glxExts = glXQueryExtensionsString( m_data->m_dpy,
  309. DefaultScreen( m_data->m_dpy ) );
  310. // NOTE: It is not necessary to create or make current to a context before
  311. // calling glXGetProcAddressARB, unless we dynamically load OpenGL/GLX/X11
  312. glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
  313. glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
  314. glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  315. GLXContext ctx = 0;
  316. // Install an X error handler so the application won't exit if GL 3.0
  317. // context allocation fails.
  318. //
  319. // Note this error handler is global. All display connections in all threads
  320. // of a process use the same error handler, so be sure to guard against other
  321. // threads issuing X commands while this code is running.
  322. ctxErrorOccurred = false;
  323. int (*oldHandler)(Display*, XErrorEvent*) =
  324. MyXSetErrorHandler(&ctxErrorHandler);
  325. // Check for the GLX_ARB_create_context extension string and the function.
  326. // If either is not present, use GLX 1.3 context creation method.
  327. if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) ||
  328. !glXCreateContextAttribsARB )
  329. {
  330. printf( "glXCreateContextAttribsARB() not found"
  331. " ... using old-style GLX context\n" );
  332. ctx = glXCreateNewContext( m_data->m_dpy, m_data->m_bestFbc, GLX_RGBA_TYPE, 0, True );
  333. }
  334. // If it does, try to get a GL 3.0 context!
  335. else
  336. {
  337. int context_attribs[] = {
  338. GLX_CONTEXT_MAJOR_VERSION_ARB ,3,
  339. GLX_CONTEXT_MINOR_VERSION_ARB, 2,
  340. GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
  341. GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,None
  342. };
  343. /*
  344. int context_attribs[] =
  345. {
  346. GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
  347. GLX_CONTEXT_MINOR_VERSION_ARB, 2,
  348. //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
  349. None
  350. };
  351. */
  352. printf( "Creating context\n" );
  353. ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0,
  354. True, context_attribs );
  355. // Sync to ensure any errors generated are processed.
  356. MyXSync( m_data->m_dpy, False );
  357. if ( !ctxErrorOccurred && ctx )
  358. printf( "Created GL 3.0 context\n" );
  359. else
  360. {
  361. // Couldn't create GL 3.0 context. Fall back to old-style 2.x context.
  362. // When a context version below 3.0 is requested, implementations will
  363. // return the newest context version compatible with OpenGL versions less
  364. // than version 3.0.
  365. // GLX_CONTEXT_MAJOR_VERSION_ARB = 1
  366. context_attribs[1] = 1;
  367. // GLX_CONTEXT_MINOR_VERSION_ARB = 0
  368. context_attribs[3] = 0;
  369. ctxErrorOccurred = false;
  370. printf( "Failed to create GL 3.0 context"
  371. " ... using old-style GLX context\n" );
  372. ctx = glXCreateContextAttribsARB( m_data->m_dpy, m_data->m_bestFbc, 0,
  373. True, context_attribs );
  374. }
  375. }
  376. // Sync to ensure any errors generated are processed.
  377. MyXSync( m_data->m_dpy, False );
  378. // Restore the original error handler
  379. MyXSetErrorHandler( oldHandler );
  380. if ( ctxErrorOccurred || !ctx )
  381. {
  382. printf( "Failed to create an OpenGL context\n" );
  383. exit(1);
  384. }
  385. // Verifying that context is a direct context
  386. if ( ! glXIsDirect ( m_data->m_dpy, ctx ) )
  387. {
  388. printf( "Indirect GLX rendering context obtained\n" );
  389. }
  390. else
  391. {
  392. printf( "Direct GLX rendering context obtained\n" );
  393. }
  394. printf( "Making context current\n" );
  395. glXMakeCurrent( m_data->m_dpy, m_data->m_win, ctx );
  396. } else
  397. {
  398. m_data->m_glc = glXCreateContext(m_data->m_dpy, m_data->m_vi, NULL, GL_TRUE);
  399. glXMakeCurrent(m_data->m_dpy, m_data->m_win, m_data->m_glc);
  400. }
  401. #ifdef GLEW_INIT_OPENGL11_FUNCTIONS
  402. {
  403. GLboolean res = glewOpenGL11Init();
  404. if (res==0)
  405. {
  406. printf("glewOpenGL11Init OK!\n");
  407. } else
  408. {
  409. printf("ERROR: glewOpenGL11Init failed, exiting!\n");
  410. exit(0);
  411. }
  412. }
  413. #endif //GLEW_INIT_OPENGL11_FUNCTIONS
  414. const GLubyte* ven = glGetString(GL_VENDOR);
  415. printf("GL_VENDOR=%s\n", ven);
  416. const GLubyte* ren = glGetString(GL_RENDERER);
  417. printf("GL_RENDERER=%s\n",ren);
  418. const GLubyte* ver = glGetString(GL_VERSION);
  419. printf("GL_VERSION=%s\n", ver);
  420. const GLubyte* sl = glGetString(GL_SHADING_LANGUAGE_VERSION);
  421. printf("GL_SHADING_LANGUAGE_VERSION=%s\n", sl);
  422. //Access pthreads as a workaround for a bug in Linux/Ubuntu
  423. //See https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642
  424. int i=pthread_getconcurrency();
  425. printf("pthread_getconcurrency()=%d\n",i);
  426. // const GLubyte* ext = glGetString(GL_EXTENSIONS);
  427. // printf("GL_EXTENSIONS=%s\n", ext);
  428. }
  429. void X11OpenGLWindow::disableOpenGL()
  430. {
  431. glXMakeCurrent(m_data->m_dpy, None, NULL);
  432. glXDestroyContext(m_data->m_dpy, m_data->m_glc);
  433. }
  434. void X11OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
  435. {
  436. m_data->m_dpy = MyXOpenDisplay(NULL);
  437. if(m_data->m_dpy == NULL) {
  438. printf("\n\tcannot connect to X server\n\n");
  439. exit(0);
  440. }
  441. m_data->m_root = DefaultRootWindow(m_data->m_dpy);
  442. #ifdef GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
  443. GLboolean res = glewXInit();
  444. if (res==0)
  445. {
  446. printf("glewXInit OK\n");
  447. } else
  448. {
  449. printf("glewXInit failed, exit\n");
  450. exit(0);
  451. }
  452. #endif //GLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS
  453. if (ci.m_openglVersion < 3)
  454. {
  455. forceOpenGL3 = false;
  456. }
  457. if (forceOpenGL3)
  458. {
  459. int glxMinor, glxMajor;
  460. if (!glXQueryVersion(m_data->m_dpy,&glxMajor,&glxMinor) || (((glxMajor==1)&&(glxMinor<3)) || (glxMajor<1)))
  461. {
  462. printf("Invalid GLX version: major %d, minor %d\n",glxMajor,glxMinor);
  463. exit(0);
  464. }
  465. static int visual_attribs[] =
  466. {
  467. GLX_X_RENDERABLE , True,
  468. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  469. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  470. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  471. GLX_RED_SIZE , 8,
  472. GLX_GREEN_SIZE , 8,
  473. GLX_BLUE_SIZE , 8,
  474. GLX_ALPHA_SIZE , 8,
  475. GLX_DEPTH_SIZE , 24,
  476. GLX_STENCIL_SIZE , 8,
  477. GLX_DOUBLEBUFFER , True,
  478. None
  479. };
  480. int fbcount;
  481. GLXFBConfig* fbc = glXChooseFBConfig(m_data->m_dpy, DefaultScreen(m_data->m_dpy), visual_attribs, &fbcount);
  482. if (!fbc)
  483. {
  484. printf( "Failed to retrieve a framebuffer config\n" );
  485. exit(1);
  486. }
  487. ///don't use highest samples, it is really slow on some NVIDIA Quadro cards
  488. #ifdef USE_HIGHEST_SAMPLES
  489. int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999;
  490. int i;
  491. for (i=0; i<fbcount; ++i)
  492. {
  493. XVisualInfo *vi = glXGetVisualFromFBConfig( m_data->m_dpy, fbc[i] );
  494. if ( vi )
  495. {
  496. int samp_buf, samples;
  497. glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf );
  498. glXGetFBConfigAttrib( m_data->m_dpy, fbc[i], GLX_SAMPLES , &samples );
  499. //printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
  500. // " SAMPLES = %d\n",
  501. // i, vi -> visualid, samp_buf, samples );
  502. if ( best_fbc < 0 || (samp_buf && (samples > best_num_samp)) )
  503. best_fbc = i, best_num_samp = samples;
  504. if ( worst_fbc < 0 || (!samp_buf || (samples < worst_num_samp)) )
  505. worst_fbc = i, worst_num_samp = samples;
  506. }
  507. MyXFree( vi );
  508. }
  509. m_data->m_bestFbc = fbc[ best_fbc ];
  510. #else
  511. m_data->m_bestFbc = *fbc;
  512. #endif
  513. // Be sure to free the FBConfig list allocated by glXChooseFBConfig()
  514. MyXFree( fbc );
  515. m_data->m_vi = glXGetVisualFromFBConfig( m_data->m_dpy, m_data->m_bestFbc );
  516. m_data->m_swa.colormap = m_data->m_cmap = MyXCreateColormap( m_data->m_dpy,
  517. RootWindow( m_data->m_dpy, m_data->m_vi->screen ),
  518. m_data->m_vi->visual, AllocNone );
  519. m_data->m_swa.background_pixmap = None ;
  520. m_data->m_swa.border_pixel = 0;
  521. m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask;
  522. ;
  523. m_data->m_root = RootWindow( m_data->m_dpy, m_data->m_vi->screen );
  524. m_data->m_win = MyXCreateWindow( m_data->m_dpy, m_data->m_root,
  525. 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput,
  526. m_data->m_vi->visual,
  527. CWBorderPixel|CWColormap|CWEventMask, &m_data->m_swa );
  528. //m_data->m_win = m_data->m_x11_XCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa);
  529. if (!m_data->m_win)
  530. {
  531. printf("Cannot create window\n");
  532. exit(0);
  533. }
  534. MyXMapWindow(m_data->m_dpy, m_data->m_win);
  535. MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL3 Window");
  536. } else
  537. {
  538. m_data->m_vi = glXChooseVisual(m_data->m_dpy, 0, att);
  539. printf("4\n");
  540. if(m_data->m_vi == NULL) {
  541. printf("\n\tno appropriate visual found\n\n");
  542. exit(0);
  543. }
  544. else {
  545. printf("\n\tvisual %p selected\n", (void *)m_data->m_vi->visualid); /* %p creates hexadecimal output like in glxinfo */
  546. }
  547. m_data->m_cmap = MyXCreateColormap(m_data->m_dpy, m_data->m_root, m_data->m_vi->visual, AllocNone);
  548. m_data->m_swa.colormap = m_data->m_cmap;
  549. m_data->m_swa.event_mask = ExposureMask | KeyReleaseMask | KeyPressMask |ButtonPressMask | ButtonReleaseMask |PointerMotionMask|StructureNotifyMask;
  550. m_data->m_win = MyXCreateWindow(m_data->m_dpy, m_data->m_root, 0, 0, ci.m_width, ci.m_height, 0, m_data->m_vi->depth, InputOutput, m_data->m_vi->visual, CWColormap | CWEventMask, &m_data->m_swa);
  551. MyXMapWindow(m_data->m_dpy, m_data->m_win);
  552. MyXStoreName(m_data->m_dpy, m_data->m_win, "OpenGL2 Window");
  553. }
  554. enableOpenGL();
  555. }
  556. void X11OpenGLWindow::closeWindow()
  557. {
  558. disableOpenGL();
  559. MyXDestroyWindow(m_data->m_dpy, m_data->m_win);
  560. MyXCloseDisplay(m_data->m_dpy);
  561. }
  562. int X11OpenGLWindow::getAsciiCodeFromVirtualKeycode(int keycode)
  563. {
  564. int result = 0;
  565. KeySym key, key_lc, key_uc;
  566. int keysyms_per_keycode_return;
  567. KeySym *keysym = MyXGetKeyboardMapping(m_data->m_dpy,
  568. keycode,
  569. 1,
  570. &keysyms_per_keycode_return);
  571. key = keysym[0];
  572. //key = MyXKeycodeToKeysym( m_data->m_dpy, keycode, 0 );
  573. switch( key )
  574. {
  575. case XK_Escape: return B3G_ESCAPE;
  576. case XK_Return: return B3G_RETURN;
  577. case XK_Control_L:
  578. case XK_Control_R: {
  579. return B3G_CONTROL;
  580. }
  581. case XK_Left: return B3G_LEFT_ARROW;
  582. case XK_Right: return B3G_RIGHT_ARROW;
  583. case XK_Up: return B3G_UP_ARROW;
  584. case XK_Down: return B3G_DOWN_ARROW;
  585. case XK_Alt_L:
  586. case XK_Alt_R:
  587. {
  588. return B3G_ALT;
  589. }
  590. case XK_Shift_L:
  591. case XK_Shift_R: return B3G_SHIFT;
  592. case XK_F1: return B3G_F1;
  593. case XK_F2: return B3G_F2;
  594. case XK_F3: return B3G_F3;
  595. case XK_F4: return B3G_F4;
  596. case XK_F5: return B3G_F5;
  597. case XK_F6: return B3G_F6;
  598. case XK_F7: return B3G_F7;
  599. case XK_F8: return B3G_F8;
  600. case XK_F9: return B3G_F9;
  601. case XK_F10: return B3G_F10;
  602. case XK_F11: return B3G_F11;
  603. case XK_F12: return B3G_F12;
  604. case XK_F13: return B3G_F13;
  605. case XK_F14: return B3G_F14;
  606. case XK_F15: return B3G_F15;
  607. default:
  608. // Make lowercase
  609. MyXConvertCase( key, &key_lc, &key_uc );
  610. key = key_lc;
  611. // Valid ISO 8859-1 character?
  612. if( (key >= 32 && key <= 126) ||(key >= 160 && key <= 255) )
  613. {
  614. return (int) key;
  615. }
  616. result = -1;
  617. }
  618. MyXFree(keysym);
  619. return result;
  620. }
  621. bool X11OpenGLWindow::isModifierKeyPressed(int key)
  622. {
  623. bool isPressed = false;
  624. switch (key)
  625. {
  626. case B3G_ALT:
  627. {
  628. isPressed = ((m_data->m_modifierFlags & MY_X11_ALT_KEY)!=0);
  629. break;
  630. };
  631. case B3G_SHIFT:
  632. {
  633. isPressed = ((m_data->m_modifierFlags & MY_X11_SHIFT_KEY)!=0);
  634. break;
  635. };
  636. case B3G_CONTROL:
  637. {
  638. isPressed = ((m_data->m_modifierFlags & MY_X11_CONTROL_KEY )!=0);
  639. break;
  640. };
  641. default:
  642. {
  643. }
  644. };
  645. return isPressed;
  646. }
  647. void X11OpenGLWindow::pumpMessage()
  648. {
  649. int buttonState = 1;
  650. // Process all pending events
  651. while( MyXPending( m_data->m_dpy ) )
  652. {
  653. MyXNextEvent(m_data->m_dpy, &m_data->m_xev);
  654. // printf("#");
  655. // fflush(stdout);
  656. switch( m_data->m_xev.type )
  657. {
  658. case KeyPress:
  659. {
  660. int keycode = getAsciiCodeFromVirtualKeycode(m_data->m_xev.xkey.keycode);
  661. switch (keycode)
  662. {
  663. case B3G_ALT:
  664. m_data->m_modifierFlags |= MY_X11_ALT_KEY;
  665. break;
  666. case B3G_SHIFT:
  667. m_data->m_modifierFlags |= MY_X11_SHIFT_KEY;
  668. break;
  669. case B3G_CONTROL:
  670. m_data->m_modifierFlags |= MY_X11_CONTROL_KEY;
  671. break;
  672. default:
  673. {}
  674. };
  675. if (m_data->m_keyboardCallback)
  676. {
  677. int state = 1;
  678. (*m_data->m_keyboardCallback)(keycode,state);
  679. // printf("keycode %d",keycode);
  680. // fflush(stdout);
  681. }
  682. break;
  683. }
  684. case KeyRelease:
  685. {
  686. // fflush(stdout);
  687. int keycode = getAsciiCodeFromVirtualKeycode( m_data->m_xev.xkey.keycode);
  688. switch (keycode)
  689. {
  690. case B3G_ALT:
  691. m_data->m_modifierFlags &= ~MY_X11_ALT_KEY;
  692. break;
  693. case B3G_SHIFT:
  694. m_data->m_modifierFlags &= ~MY_X11_SHIFT_KEY;
  695. break;
  696. case B3G_CONTROL:
  697. m_data->m_modifierFlags &= ~MY_X11_CONTROL_KEY;
  698. break;
  699. default:
  700. {}
  701. };
  702. if (m_data->m_keyboardCallback)
  703. {
  704. #if 0
  705. unsigned short is_retriggered = 0;
  706. ///filter out keyboard repeat
  707. //see http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications
  708. if (MyXEventsQueued(m_data->m_dpy, QueuedAfterReading))
  709. {
  710. XEvent nev;
  711. MyXPeekEvent(m_data->m_dpy, &nev);
  712. if (nev.type == KeyPress && nev.xkey.time == m_data->m_xev.xkey.time &&
  713. nev.xkey.keycode == m_data->m_xev.xkey.keycode)
  714. {
  715. fprintf (stdout, "key #%ld was retriggered.\n",
  716. (long) MyXLookupKeysym(&nev.xkey, 0));
  717. // delete retriggered KeyPress event
  718. MyXNextEvent(m_data->m_dpy, & m_data->m_xev);
  719. is_retriggered = 1;
  720. }
  721. }
  722. #endif
  723. int state = 0;
  724. (*m_data->m_keyboardCallback)(keycode,state);
  725. }
  726. break;
  727. }
  728. case ButtonRelease:
  729. buttonState = 0;
  730. //continue with ButtonPress code
  731. case ButtonPress:
  732. {
  733. // printf("!");
  734. // fflush(stdout);
  735. int button=-1;
  736. switch (m_data->m_xev.xbutton.button)
  737. {
  738. case Button1:
  739. {
  740. button=0;
  741. break;
  742. }
  743. case Button2:
  744. {
  745. button=1;
  746. break;
  747. }
  748. case Button3:
  749. {
  750. button=2;
  751. break;
  752. }
  753. case Button4:
  754. {
  755. if (m_data->m_wheelCallback)
  756. {
  757. (*m_data->m_wheelCallback)(0,10);
  758. }
  759. break;
  760. }
  761. case Button5:
  762. {
  763. if (m_data->m_wheelCallback)
  764. {
  765. (*m_data->m_wheelCallback)(0,-10);
  766. }
  767. break;
  768. }
  769. }
  770. int xpos = m_data->m_xev.xmotion.x;
  771. int ypos = m_data->m_xev.xmotion.y;
  772. if (button>=0 && m_data->m_mouseButtonCallback)
  773. {
  774. // printf("xpos = %d, ypos = %d\n",xpos,ypos);
  775. (*m_data->m_mouseButtonCallback)(button,buttonState,xpos,ypos);
  776. }
  777. break;
  778. }
  779. case MotionNotify:
  780. {
  781. // printf("!");
  782. // fflush(0);
  783. if (m_data->m_mouseMoveCallback)
  784. {
  785. int xpos = m_data->m_xev.xmotion.x;
  786. int ypos = m_data->m_xev.xmotion.y;
  787. (*m_data->m_mouseMoveCallback)(xpos,ypos);
  788. }
  789. break;
  790. }
  791. case ConfigureNotify:
  792. {
  793. // printf("@");
  794. // fflush(0);
  795. if (m_data->m_resizeCallback)
  796. {
  797. (*m_data->m_resizeCallback)(m_data->m_xev.xconfigure.width,m_data->m_xev.xconfigure.height);
  798. }
  799. break;
  800. }
  801. case ClientMessage:
  802. {
  803. // printf("?");
  804. // fflush(stdout);
  805. break;
  806. }
  807. case Expose:
  808. {
  809. break;
  810. }
  811. case DestroyNotify:
  812. {
  813. break;
  814. }
  815. default:
  816. {
  817. //XRRUpdateConfiguration( &event );
  818. }
  819. };
  820. }
  821. }
  822. void X11OpenGLWindow::startRendering()
  823. {
  824. pumpMessage();
  825. MyXGetWindowAttributes(m_data->m_dpy, m_data->m_win, &m_data->m_gwa);
  826. glViewport(0, 0, m_data->m_gwa.width, m_data->m_gwa.height);
  827. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //clear buffers
  828. //glCullFace(GL_BACK);
  829. //glFrontFace(GL_CCW);
  830. glEnable(GL_DEPTH_TEST);
  831. }
  832. void X11OpenGLWindow::renderAllObjects()
  833. {
  834. }
  835. void X11OpenGLWindow::endRendering()
  836. {
  837. glXSwapBuffers(m_data->m_dpy, m_data->m_win);
  838. }
  839. void X11OpenGLWindow::runMainLoop()
  840. {
  841. }
  842. float X11OpenGLWindow::getTimeInSeconds()
  843. {
  844. return 0.f;
  845. }
  846. bool X11OpenGLWindow::requestedExit() const
  847. {
  848. return m_requestedExit;
  849. }
  850. void X11OpenGLWindow::setRequestExit()
  851. {
  852. m_requestedExit=true;
  853. }
  854. void X11OpenGLWindow::setRenderCallback( b3RenderCallback renderCallback)
  855. {
  856. }
  857. void X11OpenGLWindow::setWindowTitle(const char* title)
  858. {
  859. MyXStoreName(m_data->m_dpy, m_data->m_win, title);
  860. }
  861. void X11OpenGLWindow::setWheelCallback(b3WheelCallback wheelCallback)
  862. {
  863. m_data->m_wheelCallback = wheelCallback;
  864. }
  865. void X11OpenGLWindow::setMouseMoveCallback(b3MouseMoveCallback mouseCallback)
  866. {
  867. m_data->m_mouseMoveCallback = mouseCallback;
  868. }
  869. void X11OpenGLWindow::setMouseButtonCallback(b3MouseButtonCallback mouseCallback)
  870. {
  871. m_data->m_mouseButtonCallback = mouseCallback;
  872. }
  873. void X11OpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback)
  874. {
  875. m_data->m_resizeCallback = resizeCallback;
  876. }
  877. void X11OpenGLWindow::setKeyboardCallback( b3KeyboardCallback keyboardCallback)
  878. {
  879. m_data->m_keyboardCallback = keyboardCallback;
  880. }
  881. b3MouseMoveCallback X11OpenGLWindow::getMouseMoveCallback()
  882. {
  883. return m_data->m_mouseMoveCallback;
  884. }
  885. b3MouseButtonCallback X11OpenGLWindow::getMouseButtonCallback()
  886. {
  887. return m_data->m_mouseButtonCallback;
  888. }
  889. b3ResizeCallback X11OpenGLWindow::getResizeCallback()
  890. {
  891. return m_data->m_resizeCallback;
  892. }
  893. b3WheelCallback X11OpenGLWindow::getWheelCallback()
  894. {
  895. return m_data->m_wheelCallback;
  896. }
  897. b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback()
  898. {
  899. return m_data->m_keyboardCallback;
  900. }
  901. #include <stdio.h>
  902. int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength)
  903. {
  904. int len = 0;
  905. FILE * output = popen("zenity --file-selection --file-filter=\"*.urdf\" --file-filter=\"*.*\"","r");
  906. if (output)
  907. {
  908. while( fgets(filename, maxNameLength-1, output) != NULL )
  909. {
  910. len=strlen(filename);
  911. if (len>0)
  912. {
  913. filename[len-1]=0;
  914. printf("file open (length=%d) = %s\n", len,filename);
  915. }
  916. }
  917. pclose(output);
  918. } else
  919. {
  920. printf("Error: fileOpenDialog no popen output, perhaps install zenity?\n");
  921. }
  922. MyXRaiseWindow(m_data->m_dpy, m_data->m_win);
  923. return len;
  924. }