static void loadExtStrings(XETC *tc) { char **extensionName=XListExtensions(tc->dpy,&numExtension); if (numExtension) { int i; extensionData = (_extensionData *)XtCalloc(numExtension, sizeof(_extensionData)); for (i = 0; i < numExtension; i++) { /* Arrange extensions in opcode order */ int opcode,event,error; if (XQueryExtension(tc->dpy,extensionName[i],&opcode,&event, &error)) { extensionData[opcode-128].extName = extensionName[i]; extensionData[opcode-128].extEvent = event; } else { /* This extension didn't load! Error! */ extensionData[opcode-128].extName = "Invalid_Extension"; } } XFreeExtensionList(extensionName); } }
static gboolean check_for_xquartz(GdkDisplay *dpy) { int nextensions; int i; gboolean match = FALSE; char **extensions = XListExtensions(gdk_x11_display_get_xdisplay(dpy), &nextensions); for (i = 0 ; extensions != NULL && i < nextensions ; i++) { if (strcmp(extensions[i], "Apple-WM") == 0 || strcmp(extensions[i], "Apple-DRI") == 0) match = TRUE; } if (extensions) XFreeExtensionList(extensions); return match; }
static Object P_List_Extensions (Object d) { Object ret; int n; register int i; register char **p; GC_Node; Check_Type (d, T_Display); Disable_Interrupts; p = XListExtensions (DISPLAY(d)->dpy, &n); Enable_Interrupts; ret = Make_Vector (n, Null); GC_Link (ret); for (i = 0; i < n; i++) { Object e; e = Make_String (p[i], strlen (p[i])); VECTOR(ret)->data[i] = e; } GC_Unlink; XFreeExtensionList (p); return ret; }
int main(int argc, char * argv[]) { int loop, num_extensions, num_devices; char **extensions; XDeviceInfo *devices; Display *dpy; Window root_win; unsigned long screen; int list = 0; if (argc != 3) { fprintf(stderr, "usage : %s <device name> (ABSOLUTE|RELATIVE)\n", argv[0]); exit(1); } if (strcmp(argv[1], "-l") == 0) { list = 1; } dpy = XOpenDisplay(NULL); if (!dpy) { printf("unable to connect to X Server try to set the DISPLAY variable\n"); exit(1); } #ifdef DEBUG printf("connected to %s\n", XDisplayString(dpy)); #endif screen = DefaultScreen(dpy); root_win = RootWindow(dpy, screen); extensions = XListExtensions(dpy, &num_extensions); for (loop = 0; loop < num_extensions && (strcmp(extensions[loop], "XInputExtension") != 0); loop++); XFreeExtensionList(extensions); if (loop != num_extensions) { devices = XListInputDevices(dpy, &num_devices); for(loop=0; loop<num_devices; loop++) { if (devices[loop].name && (StrCaseCmp(devices[loop].name, argv[1]) == 0)) if (devices[loop].use == IsXExtensionDevice) { XDevice *device; #ifdef DEBUG fprintf(stderr, "opening device %s\n", devices[loop].name ? devices[loop].name : "<noname>"); #endif device = XOpenDevice(dpy, devices[loop].id); if (device) { XSetDeviceMode(dpy, device, (strcmp("ABSOLUTE", argv[2]) == 0) ? Absolute : Relative); exit(0); } else { fprintf(stderr, "error opening device\n"); exit(1); } } } XFreeDeviceList(devices); } else { fprintf(stderr, "No XInput extension available\n"); exit(1); } if (list) { exit(0); } else { fprintf(stderr, "Extended device %s not found\n", argv[1]); exit(1); } }
static int X11Error(Display *display, XErrorEvent *event) { // Get an indication of how long ago the request that caused the error was // made. unsigned long age = NextRequest(display) - event->serial; // Get a string to represent the request that caused the error. nsAutoCString message; if (event->request_code < 128) { // Core protocol request message.AppendInt(event->request_code); } else { // Extension request // man XSetErrorHandler says "the error handler should not call any // functions (directly or indirectly) on the display that will generate // protocol requests or that will look for input events" so we use another // temporary Display to request extension information. This assumes on // the DISPLAY environment variable has been set and matches what was used // to open |display|. Display *tmpDisplay = XOpenDisplay(NULL); if (tmpDisplay) { int nExts; char** extNames = XListExtensions(tmpDisplay, &nExts); int first_error; if (extNames) { for (int i = 0; i < nExts; ++i) { int major_opcode, first_event; if (XQueryExtension(tmpDisplay, extNames[i], &major_opcode, &first_event, &first_error) && major_opcode == event->request_code) { message.Append(extNames[i]); message.Append('.'); message.AppendInt(event->minor_code); break; } } XFreeExtensionList(extNames); } XCloseDisplay(tmpDisplay); #ifdef MOZ_WIDGET_GTK2 // GDK2 calls XCloseDevice the devices that it opened on startup, but // the XI protocol no longer ensures that the devices will still exist. // If they have been removed, then a BadDevice error results. Ignore // this error. if (message.EqualsLiteral("XInputExtension.4") && event->error_code == first_error + 0) { return 0; } #endif } } char buffer[BUFSIZE]; if (message.IsEmpty()) { buffer[0] = '\0'; } else { XGetErrorDatabaseText(display, "XRequest", message.get(), "", buffer, sizeof(buffer)); } nsAutoCString notes; if (buffer[0]) { notes.Append(buffer); } else { notes.Append("Request "); notes.AppendInt(event->request_code); notes.Append('.'); notes.AppendInt(event->minor_code); } notes.Append(": "); // Get a string to describe the error. XGetErrorText(display, event->error_code, buffer, sizeof(buffer)); notes.Append(buffer); // For requests where Xlib gets the reply synchronously, |age| will be 1 // and the stack will include the function making the request. For // asynchronous requests, the current stack will often be unrelated to the // point of making the request, even if |age| is 1, but sometimes this may // help us count back to the point of the request. With XSynchronize on, // the stack will include the function making the request, even though // |age| will be 2 for asynchronous requests because XSynchronize is // implemented by an empty request from an XSync, which has not yet been // processed. if (age > 1) { // XSynchronize returns the previous "after function". If a second // XSynchronize call returns the same function after an enable call then // synchronization must have already been enabled. if (XSynchronize(display, True) == XSynchronize(display, False)) { notes.Append("; sync"); } else { notes.Append("; "); notes.AppendInt(uint32_t(age)); notes.Append(" requests ago"); } } #ifdef MOZ_CRASHREPORTER switch (XRE_GetProcessType()) { case GeckoProcessType_Default: case GeckoProcessType_Plugin: case GeckoProcessType_Content: CrashReporter::AppendAppNotesToCrashReport(notes); break; default: ; // crash report notes not supported. } #endif #ifdef DEBUG // The resource id is unlikely to be useful in a crash report without // context of other ids, but add it to the debug console output. notes.Append("; id=0x"); notes.AppendInt(uint32_t(event->resourceid), 16); #ifdef MOZ_X11 // Actually, for requests where Xlib gets the reply synchronously, // MOZ_X_SYNC=1 will not be necessary, but we don't have a table to tell us // which requests get a synchronous reply. if (!PR_GetEnv("MOZ_X_SYNC")) { notes.Append("\nRe-running with MOZ_X_SYNC=1 in the environment may give a more helpful backtrace."); } #endif #endif #ifdef MOZ_WIDGET_QT // We should not abort here if MOZ_X_SYNC is not set // until http://bugreports.qt.nokia.com/browse/QTBUG-4042 // not fixed, just print error value if (!PR_GetEnv("MOZ_X_SYNC")) { fprintf(stderr, "XError: %s\n", notes.get()); return 0; // temporary workaround for bug 161472 } #endif NS_RUNTIMEABORT(notes.get()); return 0; // not reached }
// create a new window and set it's characteristics Window OpenGLPbufferDisplayDevice::open_window(char *nm, int *size, int *loc, int argc, char** argv ) { char *dispname; if ((dispname = getenv("VMDGDISPLAY")) == NULL) dispname = getenv("DISPLAY"); if(!(glxsrv.dpy = XOpenDisplay(dispname))) { msgErr << "Exiting due to X-Windows GLX/OpenGL Pbuffer creation failure." << sendmsg; if (dispname != NULL) { msgErr << "Failed to open display: " << dispname << sendmsg; } return (Window)0; } // // Check for "Composite" extension and any others that might cause // stability issues and warn the user about any potential problems... // char **xextensionlist; int nextensions, xtn; int warncompositeext=0; xextensionlist = XListExtensions(glxsrv.dpy, &nextensions); for (xtn=0; xtn<nextensions; xtn++) { // printf("xtn[%d]: '%s'\n", xtn, xextensionlist[xtn]); if (xextensionlist[xtn] && !strcmp(xextensionlist[xtn], "Composite")) { warncompositeext=1; } } if (warncompositeext) { msgWarn << "Detected X11 'Composite' extension: if incorrect display occurs" << sendmsg; msgWarn << "try disabling this X server option. Most OpenGL drivers" << sendmsg; msgWarn << "disable stereoscopic display when 'Composite' is enabled." << sendmsg; } XFreeExtensionList(xextensionlist); // // get info about root window // glxsrv.dpyScreen = DefaultScreen(glxsrv.dpy); glxsrv.rootWindowID = RootWindow(glxsrv.dpy, glxsrv.dpyScreen); screenX = DisplayWidth(glxsrv.dpy, glxsrv.dpyScreen); screenY = DisplayHeight(glxsrv.dpy, glxsrv.dpyScreen); // (3) make sure the GLX extension is available if (!glXQueryExtension(glxsrv.dpy, NULL, NULL)) { msgErr << "The X server does not support the OpenGL GLX extension." << " Exiting ..." << sendmsg; XCloseDisplay(glxsrv.dpy); return (Window)0; } ext->hasstereo = TRUE; // stereo on until we find out otherwise. ext->stereodrawforced = FALSE; // no need for force stereo draws initially ext->hasmultisample = TRUE; // multisample on until we find out otherwise. // Find the best matching OpenGL framebuffer config for our purposes GLXFBConfig *fbc; fbc = vmd_get_fbconfig(&glxsrv, &ext->hasstereo, &ext->hasmultisample, &ext->nummultisamples); if (fbc == NULL) { msgErr << "No OpenGL Pbuffer configurations available" << sendmsg; return (Window)0; } // Create the OpenGL Pbuffer and associated GLX context const int pbconf[] = {GLX_PBUFFER_WIDTH, DEF_PBUFFER_XRES, GLX_PBUFFER_HEIGHT, DEF_PBUFFER_YRES, GLX_LARGEST_PBUFFER, 1, GLX_PRESERVED_CONTENTS, 1, None}; GLXPbuffer PBuffer = glXCreatePbuffer(glxsrv.dpy, fbc[0], pbconf); glxsrv.cx = glXCreateNewContext(glxsrv.dpy, fbc[0], GLX_RGBA_TYPE, 0, GL_TRUE); if (PBuffer == 0 || glxsrv.cx == NULL) { msgErr << "A TrueColor OpenGL Pbuffer is required, but not available." << sendmsg; msgErr << "The X server is not capable of displaying double-buffered," << sendmsg; msgErr << "RGB images with a Z buffer. Exiting ..." << sendmsg; XCloseDisplay(glxsrv.dpy); return (Window)0; } // set maximum allowable rendered image size for the Pbuffer // that was actually allocated, which may be smaller than we hoped... PbufferMaxXsz = DEF_PBUFFER_XRES; PbufferMaxYsz = DEF_PBUFFER_YRES; glXQueryDrawable(glxsrv.dpy, PBuffer, GLX_WIDTH, &PbufferMaxXsz); glXQueryDrawable(glxsrv.dpy, PBuffer, GLX_HEIGHT, &PbufferMaxYsz); msgInfo << "OpenGL Pbuffer size: " << PbufferMaxXsz << "x" << PbufferMaxYsz << sendmsg; // set default image size to incoming values, when possible. xSize = size[0]; ySize = size[1]; if (xSize < 0 || xSize > PbufferMaxXsz || ySize < 0 || ySize > PbufferMaxYsz) { msgWarn << "Ignored out-of-range OpenGL Pbuffer image dimension request: " << xSize << "x" << ySize << " (max: " << PbufferMaxXsz << "x" << PbufferMaxYsz << ")" << sendmsg; xSize = PbufferMaxXsz; ySize = PbufferMaxYsz; } // make the Pbuffer active glXMakeContextCurrent(glxsrv.dpy, PBuffer, PBuffer, glxsrv.cx); glXMakeCurrent(glxsrv.dpy, PBuffer, glxsrv.cx); // If we have acquired a multisample buffer with GLX, we // still need to test to see if we can actually use it. if (ext->hasmultisample) { int msampeext = 0; // check for ARB multisampling if (ext->vmdQueryExtension("GL_ARB_multisample")) { msampeext = 1; } if (!msampeext) { ext->hasmultisample = FALSE; ext->nummultisamples = 0; } } // (9) configure the rendering properly setup_initial_opengl_state(); // setup initial OpenGL state // normal return: window was successfully created have_window = TRUE; // return window id return PBuffer; }
int main(int argc, char * argv[]) { int loop, num_extensions, num_devices; char **extensions; XDeviceInfo *devices; Display *dpy; Window root_win; unsigned long screen; int list = 0; if (argc != 2) { fprintf(stderr, "usage : %s (-l | <device name>)\n", argv[0]); exit(1); } if (strcmp(argv[1], "-l") == 0) { list = 1; } dpy = XOpenDisplay(NULL); if (!dpy) { printf("unable to connect to X Server try to set the DISPLAY variable\n"); exit(1); } #ifdef DEBUG printf("connected to %s\n", XDisplayString(dpy)); #endif screen = DefaultScreen(dpy); root_win = RootWindow(dpy, screen); extensions = XListExtensions(dpy, &num_extensions); for (loop = 0; loop < num_extensions && (strcmp(extensions[loop], "XInputExtension") != 0); loop++); XFreeExtensionList(extensions); if (loop != num_extensions) { devices = XListInputDevices(dpy, &num_devices); for(loop=0; loop<num_devices; loop++) { if (list) { printf("\"%s\" [", devices[loop].name ? devices[loop].name : "<noname>"); switch(devices[loop].use) { case IsXPointer: printf("XPointer]\n"); break; case IsXKeyboard: printf("XKeyboard]\n"); break; case IsXExtensionDevice: printf("XExtensionDevice]\n"); break; default: printf("invalid value]\n"); break; } } else { if ((argc == 2) && devices[loop].name && (StrCaseCmp(devices[loop].name, argv[1]) == 0)) if (devices[loop].use == IsXExtensionDevice) { XDevice *device; #ifdef DEBUG fprintf(stderr, "opening device %s\n", devices[loop].name ? devices[loop].name : "<noname>"); #endif device = XOpenDevice(dpy, devices[loop].id); if (device) { XChangePointerDevice(dpy, device, 0, 1); exit(0); } else { fprintf(stderr, "error opening device\n"); exit(1); } } } } XFreeDeviceList(devices); } else { fprintf(stderr, "No XInput extension available\n"); exit(1); } if (list) { exit(0); } else { fprintf(stderr, "Extended device %s not found\n", argv[1]); exit(1); } }
void WindowMetrics::MeasureScreen(bool waitForWM) { #ifdef Q_WS_X11 // // Create the test window // testWindow = new TestWin; testWindow->show(); // // Try and determine if we're displaying X11 to a Mac. // int nExt = 0, appleDisplay = 0; char **ext = XListExtensions(QX11Info::display(), &nExt); for(int e = 0; e < nExt; ++e) { if(strcmp(ext[e], "Apple-DRI") == 0 || strcmp(ext[e], "Apple-WM") == 0) { appleDisplay++; } } XFreeExtensionList(ext); // // Calculate the metrics // CalculateScreen(testWindow, screenX, screenY, screenW, screenH); // We need for the window manager to put borders on the window // before we can determine their sizes if(waitForWM) WaitForWindowManagerToGrabWindow(testWindow); // We tried to put the main window at 100,100... // ...see where it *really* started out preshiftX = 100; preshiftY = 100; CalculateTopLeft(testWindow, preshiftX, preshiftY); preshiftX -= 100; preshiftY -= 100; // Determine the border sizes of the main window. CalculateBorders(testWindow, borderT, borderB, borderL, borderR); // Move it to the top left (we think) testWindow->move(borderL,borderT); testWindow->resize(2,2); if(waitForWM) { do { // If it's not at 0,0, then we have a shift WaitForWindowManagerToMoveWindow(testWindow); CalculateTopLeft(testWindow, shiftX, shiftY); } while ((shiftX == preshiftX+100 && shiftY == preshiftY+100) && appleDisplay == 0); // (sometimes we need to wait for more than one ConfigureNotify) } else CalculateTopLeft(testWindow, shiftX, shiftY); // Adjust preshift to account for the actual shift preshiftX += (borderL - shiftX); preshiftY += (borderT - shiftY); testWindow->hide(); #else // // Calculate the metrics // CalculateScreen(0, screenX, screenY, screenW, screenH); // // Determine the border sizes of the main window. // CalculateBorders(0, borderT, borderB, borderL, borderR); #if defined(Q_WS_WIN) preshiftX = shiftX = borderL; preshiftY = shiftY = borderT; #endif #endif }