short WPcrfi( int pid, short x, short y, char *filnam, char *akod, short anum, DBint *iid) /* Skapar snabbvalsikon (CRE_FICON) i grafiskt fönster. * * In: pid = ID för grafiskt fönster. * x,y = Placering. * filnam = Vägbeskrivning till ikonfil * akod = Aktionskod. * anum = Aktionsnummer. * iid = Pekare till resultat. * * Ut: *iid = Ikonens ID. * * Felkod: * WP1552 = %s är en otillåten aktionskod. * WP1522 = Fönstret %s finns ej * WP1532 = Fönstret %s är av fel typ * WP1542 = Fönster %s är fullt * * (C)microform ab 1996-05-20 J. Kjellander * ******************************************************!*/ { short status,action; int i; char errbuf[80]; WPWIN *winptr; WPGWIN *gwinpt; WPICON *icoptr; /* ***Vilken aktionskod ? */ if ( akod[1] != '\0' ) return(erpush("WP1512",akod)); switch ( akod[0] ) { case 'f': action = CFUNC; break; case 'm': action = MENU; break; case 'p': action = PART; break; case 'r': action = RUN; break; case 'M': action = MFUNC; break; default: return(erpush("WP1552",akod)); break; } /* ***Fixa C-pekare till det grafiska fönstrets entry i wpwtab. */ if ( (winptr=WPwgwp(pid)) == NULL ) { sprintf(errbuf,"%d",(int)pid); return(erpush("WP1522",errbuf)); } /* ***Kolla att det är ett WPGWIN och fixa en pekare till ***förälder-fönstret självt. */ if ( winptr->typ != TYP_GWIN ) { sprintf(errbuf,"%d",(int)pid); return(erpush("WP1532",errbuf)); } else gwinpt = (WPGWIN *)winptr->ptr; /* ***Skapa ID för den nya knappen, dvs fixa ***en ledig plats i förälderns fönstertabell. */ i = 0; while ( i < WP_GWSMAX && gwinpt->wintab[i].ptr != NULL ) ++i; if ( i == WP_GWSMAX ) { sprintf(errbuf,"%d",(int)pid); return(erpush("WP1542",errbuf)); } else *iid = i; /* ***Prova att skapa en ikon. */ status = WPwcic(gwinpt->id.x_id,x,y,(short)1, filnam,WP_BGND2,WP_FGND,&icoptr); if ( status < 0 ) return(status); /* ***Länka in den i WPGWIN-fönstret. */ gwinpt->wintab[*iid].typ = TYP_ICON; gwinpt->wintab[*iid].ptr = (char *)icoptr; icoptr->id.w_id = *iid; icoptr->id.p_id = pid; XMapWindow(xdisp,icoptr->id.x_id); /* ***Aktion. */ icoptr->acttyp = action; icoptr->actnum = anum; return(0); }
Display * x11setup(Window *win, GC *gc, int width, int height) { /* --------------------------- X11 graphics setup ------------------------------ */ Display *display; unsigned int win_x,win_y, /* window position */ border_width, /* border width in pixels */ display_width, display_height, /* size of screen */ screen; /* which screen */ char window_name[] = "Mandelbrot", *display_name = NULL; unsigned long valuemask = 0; XGCValues values; XSizeHints size_hints; //Pixmap bitmap; //XPoint points[800]; FILE *fopen ();//, *fp; //char str[100]; XSetWindowAttributes attr[1]; if ( (display = XOpenDisplay (display_name)) == NULL ) { /* connect to Xserver */ fprintf (stderr, "Cannot connect to X server %s\n",XDisplayName (display_name) ); exit (-1); } screen = DefaultScreen (display); /* get screen size */ display_width = DisplayWidth (display, screen); display_height = DisplayHeight (display, screen); win_x = 0; win_y = 0; /* set window position */ border_width = 4; /* create opaque window */ *win = XCreateSimpleWindow (display, RootWindow (display, screen), win_x, win_y, width, height, border_width, WhitePixel (display, screen), BlackPixel (display, screen)); size_hints.flags = USPosition|USSize; size_hints.x = win_x; size_hints.y = win_y; size_hints.width = width; size_hints.height = height; size_hints.min_width = 300; size_hints.min_height = 300; XSetNormalHints (display, *win, &size_hints); XStoreName(display, *win, window_name); *gc = XCreateGC (display, *win, valuemask, &values); /* create graphics context */ XSetBackground (display, *gc, BlackPixel (display, screen)); XSetForeground (display, *gc, WhitePixel (display, screen)); XSetLineAttributes (display, *gc, 1, LineSolid, CapRound, JoinRound); attr[0].backing_store = Always; attr[0].backing_planes = 1; attr[0].backing_pixel = BlackPixel(display, screen); XChangeWindowAttributes(display, *win, CWBackingStore | CWBackingPlanes | CWBackingPixel, attr); XSelectInput(display, *win, KeyPressMask); XMapWindow (display, *win); XSync(display, 0); /* --------------------------- End of X11 graphics setup ------------------------------ */ return display; }
void set_title(void) { //Set the window title bar. XMapWindow(dpy, win); XStoreName(dpy, win, "David A. Hernandez II CS335 Lab1 Waterfall Model"); }
/** * Shows a window. * * Synonymous to "mapping" a window in X Window System terminology. * * @param win The window to show. * @ingroup Ecore_X_Window_Visibility */ EAPI void ecore_x_window_show(Ecore_X_Window win) { LOGFN(__FILE__, __LINE__, __FUNCTION__); XMapWindow(_ecore_x_disp, win); } /* ecore_x_window_show */
int main(int argc, char **argv) { AppInfo app; XEvent event; XineramaScreenInfo *screens; int nscreens; memset(&app, 0, sizeof(app)); progclass = "SshAskpass"; app.toplevelShell = XtAppInitialize(&(app.appContext), progclass, NULL, 0, &argc, argv, defaults, NULL, 0); app.argc = argc; app.argv = argv; app.dpy = XtDisplay(app.toplevelShell); app.screen = DefaultScreenOfDisplay(app.dpy); app.rootWindow = RootWindowOfScreen(app.screen); app.black = BlackPixel(app.dpy, DefaultScreen(app.dpy)); app.white = WhitePixel(app.dpy, DefaultScreen(app.dpy)); app.colormap = DefaultColormapOfScreen(app.screen); app.resourceDb = XtDatabase(app.dpy); XtGetApplicationNameAndClass(app.dpy, &progname, &progclass); app.appName = progname; app.appClass = progclass; /* For resources.c. */ db = app.resourceDb; /* Seconds after which keyboard/pointer grab fail. */ app.grabFailTimeout = 5; /* Number of seconds to wait between grab attempts. */ app.grabRetryInterval = 1; app.pid = getpid(); { struct rlimit resourceLimit; int status; status = getrlimit(RLIMIT_CORE, &resourceLimit); if (-1 == status) { fprintf(stderr, "%s[%ld]: getrlimit failed (%s)\n", app.appName, (long) app.pid, strerror(errno)); exit(EXIT_STATUS_ERROR); } resourceLimit.rlim_cur = 0; status = setrlimit(RLIMIT_CORE, &resourceLimit); if (-1 == status) { fprintf(stderr, "%s[%ld]: setrlimit failed (%s)\n", app.appName, (long) app.pid, strerror(errno)); exit(EXIT_STATUS_ERROR); } } app.screen_width = WidthOfScreen(app.screen); app.screen_height = HeightOfScreen(app.screen); app.screen_xoffset = 0; app.screen_yoffset = 0; if (XineramaIsActive(app.dpy) && (screens = XineramaQueryScreens(app.dpy, &nscreens)) != NULL && nscreens) { app.screen_width = screens[0].width; app.screen_height = screens[0].height; app.screen_xoffset = screens[0].x_org; app.screen_yoffset = screens[0].y_org; XFree(screens); } app.xResolution = app.screen_width * 1000 / WidthMMOfScreen(app.screen); app.yResolution = app.screen_height * 1000 / HeightMMOfScreen(app.screen); createDialog(&app); createGCs(&app); app.eventMask = 0; app.eventMask |= ExposureMask; app.eventMask |= ButtonPressMask; app.eventMask |= ButtonReleaseMask; app.eventMask |= Button1MotionMask; app.eventMask |= KeyPressMask; createDialogWindow(&app); XMapWindow(app.dpy, app.dialog->dialogWindow); if (app.inputTimeout > 0) { app.inputTimeoutActive = True; app.inputTimeoutTimerId = XtAppAddTimeOut(app.appContext, app.inputTimeout, handleInputTimeout, (XtPointer) &app); } while(True) { XtAppNextEvent(app.appContext, &event); switch (event.type) { case Expose: grabServer(&app); grabKeyboard(&app); grabPointer(&app); if (event.xexpose.count) { break; } paintDialog(&app); break; case ButtonPress: case ButtonRelease: handleButtonPress(&app, &event); break; case MotionNotify: handlePointerMotion(&app, &event); case KeyPress: handleKeyPress(&app, &event); break; case ClientMessage: if ((32 == event.xclient.format) && ((unsigned long) event.xclient.data.l[0] == app.wmDeleteWindowAtom)) { cancelAction(&app); } break; default: break; } } fprintf(stderr, "%s[%ld]: This should not happen.\n", app.appName, (long) app.pid); return(EXIT_STATUS_ANOMALY); }
void makeVolumePanel (void) { int i; XSetWindowAttributes cwAttrib, controlAttrib; XSizeHints sizehint; Pixmap volumebits, volumemask; XColor foreColor, backColor; volumebits = XCreateBitmapFromData(dsply,rtWindow,volumeBitmap_bits, volumeBitmap_width,volumeBitmap_height); volumemask = XCreateBitmapFromData(dsply,rtWindow,volumeMask_bits, volumeMask_width,volumeMask_height); cwAttrib.background_pixel = backgroundColor; cwAttrib.border_pixel = foregroundColor; cwAttrib.event_mask = volumeMASK; cwAttrib.colormap = colorMap; cwAttrib.override_redirect = overrideManager; foreColor.pixel = volumeCursorForeground; XQueryColor(dsply,colorMap,&foreColor); backColor.pixel = volumeCursorBackground; XQueryColor(dsply,colorMap,&backColor); cwAttrib.cursor = XCreatePixmapCursor(dsply,volumebits,volumemask, &foreColor,&backColor, volumeBitmap_x_hot, volumeBitmap_y_hot); volumeWindow = XCreateWindow(dsply,control->controlWindow, -3,-3,controlWidth,controlHeight,3, CopyFromParent,InputOutput,CopyFromParent, controlCreateMASK,&cwAttrib); sizehint.flags = USPosition | USSize; sizehint.x = 0; sizehint.y = 0; sizehint.width = controlWidth; sizehint.height = controlHeight; /*** the None stands for icon pixmap ***/ XSetNormalHints(dsply,volumeWindow,&sizehint); XSetStandardProperties(dsply,volumeWindow,"Volume Panel 3D", "View Volume",None,NULL,0,&sizehint); /*** volume frustrum window ***/ /*** do volume buttons ***/ initVolumeButtons(control->buttonQueue); for (i=volumeButtonsStart; i<(volumeButtonsEnd); i++) { controlAttrib.event_mask = (control->buttonQueue[i]).mask; (control->buttonQueue[i]).self = XCreateWindow(dsply,volumeWindow, (control->buttonQueue[i]).buttonX, (control->buttonQueue[i]).buttonY, (control->buttonQueue[i]).buttonWidth, (control->buttonQueue[i]).buttonHeight, 0,0,InputOnly,CopyFromParent, buttonCreateMASK,&controlAttrib); XMakeAssoc(dsply,table,(control->buttonQueue[i]).self, &((control->buttonQueue[i]).buttonKey)); XMapWindow(dsply,(control->buttonQueue[i]).self); } } /* makeVolumePanel() */
static bool gfx_ctx_x_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { XEvent event; bool true_full = false, windowed_full; int val, x_off = 0, y_off = 0; XVisualInfo *vi = NULL; XSetWindowAttributes swa = {0}; int (*old_handler)(Display*, XErrorEvent*) = NULL; settings_t *settings = config_get_ptr(); gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data; x11_install_sighandlers(); if (!x) return false; windowed_full = settings->video.windowed_fullscreen; true_full = false; switch (x_api) { case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_ES_API: #ifdef HAVE_OPENGL vi = glXGetVisualFromFBConfig(g_x11_dpy, x->g_fbc); if (!vi) goto error; #endif break; case GFX_CTX_NONE: default: { XVisualInfo vi_template; /* For default case, just try to obtain a visual from template. */ int nvisuals = 0; memset(&vi_template, 0, sizeof(vi_template)); vi_template.screen = DefaultScreen(g_x11_dpy); vi = XGetVisualInfo(g_x11_dpy, VisualScreenMask, &vi_template, &nvisuals); if (!vi || nvisuals < 1) goto error; } break; } swa.colormap = g_x11_cmap = XCreateColormap(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonReleaseMask | ButtonPressMask; swa.override_redirect = fullscreen ? True : False; if (fullscreen && !windowed_full) { if (x11_enter_fullscreen(g_x11_dpy, width, height, &x->g_desktop_mode)) { x->g_should_reset_mode = true; true_full = true; } else RARCH_ERR("[GLX]: Entering true fullscreen failed. Will attempt windowed mode.\n"); } if (settings->video.monitor_index) g_x11_screen = settings->video.monitor_index - 1; #ifdef HAVE_XINERAMA if (fullscreen || g_x11_screen != 0) { unsigned new_width = width; unsigned new_height = height; if (x11_get_xinerama_coord(g_x11_dpy, g_x11_screen, &x_off, &y_off, &new_width, &new_height)) RARCH_LOG("[GLX]: Using Xinerama on screen #%u.\n", g_x11_screen); else RARCH_LOG("[GLX]: Xinerama is not active on screen.\n"); if (fullscreen) { width = new_width; height = new_height; } } #endif RARCH_LOG("[GLX]: X = %d, Y = %d, W = %u, H = %u.\n", x_off, y_off, width, height); g_x11_win = XCreateWindow(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen), x_off, y_off, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa); XSetWindowBackground(g_x11_dpy, g_x11_win, 0); switch (x_api) { case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_ES_API: #ifdef HAVE_OPENGL x->g_glx_win = glXCreateWindow(g_x11_dpy, x->g_fbc, g_x11_win, 0); #endif break; case GFX_CTX_NONE: default: break; } x11_set_window_attr(g_x11_dpy, g_x11_win); x11_update_window_title(NULL); if (fullscreen) x11_show_mouse(g_x11_dpy, g_x11_win, false); if (true_full) { RARCH_LOG("[GLX]: Using true fullscreen.\n"); XMapRaised(g_x11_dpy, g_x11_win); } else if (fullscreen) { /* We attempted true fullscreen, but failed. * Attempt using windowed fullscreen. */ XMapRaised(g_x11_dpy, g_x11_win); RARCH_LOG("[GLX]: Using windowed fullscreen.\n"); /* We have to move the window to the screen we want * to go fullscreen on first. * x_off and y_off usually get ignored in XCreateWindow(). */ x11_move_window(g_x11_dpy, g_x11_win, x_off, y_off, width, height); x11_windowed_fullscreen(g_x11_dpy, g_x11_win); } else { XMapWindow(g_x11_dpy, g_x11_win); /* If we want to map the window on a different screen, * we'll have to do it by force. * Otherwise, we should try to let the window manager sort it out. * x_off and y_off usually get ignored in XCreateWindow(). */ if (g_x11_screen) x11_move_window(g_x11_dpy, g_x11_win, x_off, y_off, width, height); } x11_event_queue_check(&event); switch (x_api) { case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_ES_API: #ifdef HAVE_OPENGL if (!x->g_ctx) { if (x->g_core_es || x->g_debug) { int attribs[16]; int *aptr = attribs; if (x->g_core_es) { *aptr++ = GLX_CONTEXT_MAJOR_VERSION_ARB; *aptr++ = g_major; *aptr++ = GLX_CONTEXT_MINOR_VERSION_ARB; *aptr++ = g_minor; if (x->g_core_es_core) { /* Technically, we don't have core/compat until 3.2. * Version 3.1 is either compat or not depending on * GL_ARB_compatibility. */ *aptr++ = GLX_CONTEXT_PROFILE_MASK_ARB; #ifdef HAVE_OPENGLES2 *aptr++ = GLX_CONTEXT_ES_PROFILE_BIT_EXT; #else *aptr++ = GLX_CONTEXT_CORE_PROFILE_BIT_ARB; #endif } } if (x->g_debug) { *aptr++ = GLX_CONTEXT_FLAGS_ARB; *aptr++ = GLX_CONTEXT_DEBUG_BIT_ARB; } *aptr = None; x->g_ctx = glx_create_context_attribs(g_x11_dpy, x->g_fbc, NULL, True, attribs); if (x->g_use_hw_ctx) { RARCH_LOG("[GLX]: Creating shared HW context.\n"); x->g_hw_ctx = glx_create_context_attribs(g_x11_dpy, x->g_fbc, x->g_ctx, True, attribs); if (!x->g_hw_ctx) RARCH_ERR("[GLX]: Failed to create new shared context.\n"); } } else { x->g_ctx = glXCreateNewContext(g_x11_dpy, x->g_fbc, GLX_RGBA_TYPE, 0, True); if (x->g_use_hw_ctx) { x->g_hw_ctx = glXCreateNewContext(g_x11_dpy, x->g_fbc, GLX_RGBA_TYPE, x->g_ctx, True); if (!x->g_hw_ctx) RARCH_ERR("[GLX]: Failed to create new shared context.\n"); } } if (!x->g_ctx) { RARCH_ERR("[GLX]: Failed to create new context.\n"); goto error; } } else { video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT_ACK, NULL); RARCH_LOG("[GLX]: Using cached GL context.\n"); } glXMakeContextCurrent(g_x11_dpy, x->g_glx_win, x->g_glx_win, x->g_ctx); #endif break; case GFX_CTX_VULKAN_API: #ifdef HAVE_VULKAN { bool quit, resize; unsigned width, height; x11_check_window(x, &quit, &resize, &width, &height, 0); /* Use XCB surface since it's the most supported WSI. * We can obtain the XCB connection directly from X11. */ if (!vulkan_surface_create(&x->vk, VULKAN_WSI_XCB, g_x11_dpy, &g_x11_win, width, height, x->g_interval)) goto error; } #endif break; case GFX_CTX_NONE: default: break; } XSync(g_x11_dpy, False); x11_install_quit_atom(); switch (x_api) { case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_ES_API: #ifdef HAVE_OPENGL glXGetConfig(g_x11_dpy, vi, GLX_DOUBLEBUFFER, &val); x->g_is_double = val; if (x->g_is_double) { const char *swap_func = NULL; g_pglSwapIntervalEXT = (void (*)(Display*, GLXDrawable, int)) glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT"); g_pglSwapIntervalSGI = (int (*)(int)) glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI"); g_pglSwapInterval = (int (*)(int)) glXGetProcAddress((const GLubyte*)"glXSwapIntervalMESA"); if (g_pglSwapIntervalEXT) swap_func = "glXSwapIntervalEXT"; else if (g_pglSwapInterval) swap_func = "glXSwapIntervalMESA"; else if (g_pglSwapIntervalSGI) swap_func = "glXSwapIntervalSGI"; if (!g_pglSwapInterval && !g_pglSwapIntervalEXT && !g_pglSwapIntervalSGI) RARCH_WARN("[GLX]: Cannot find swap interval call.\n"); else RARCH_LOG("[GLX]: Found swap function: %s.\n", swap_func); } else RARCH_WARN("[GLX]: Context is not double buffered!.\n"); #endif break; case GFX_CTX_NONE: default: break; } gfx_ctx_x_swap_interval(data, x->g_interval); /* This can blow up on some drivers. * It's not fatal, so override errors for this call. */ old_handler = XSetErrorHandler(x_nul_handler); XSetInputFocus(g_x11_dpy, g_x11_win, RevertToNone, CurrentTime); XSync(g_x11_dpy, False); XSetErrorHandler(old_handler); XFree(vi); vi = NULL; if (!x11_input_ctx_new(true_full)) goto error; return true; error: if (vi) XFree(vi); gfx_ctx_x_destroy_resources(x); if (x) free(x); g_x11_screen = 0; return false; }
// main method largely inspired from opengl wiki // http://www.opengl.org/wiki/Tutorial%3a_OpenGL_3.0_Context_Creation_%28GLX%29 int main (int argc, char** argv) { Display* display = XOpenDisplay(nullptr); if (display == nullptr) { printf("Failed to open X display\n"); exit(1); } int visual_attribs[] = { GLX_RED_SIZE , 8, GLX_GREEN_SIZE , 8, GLX_BLUE_SIZE , 8, GLX_ALPHA_SIZE , 8, GLX_DEPTH_SIZE , 24, GLX_DOUBLEBUFFER , True, None }; int glx_major, glx_minor; if (!glXQueryVersion(display, &glx_major, &glx_minor) || ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) { printf("Invalid GLX version"); exit(1); } int fbcount; GLXFBConfig* fbc = glXChooseFBConfig(display, DefaultScreen(display), visual_attribs, &fbcount); if (fbc == nullptr) { printf("Failed to retrieve a framebuffer config\n"); exit(1); } // Pick the FB config/visual with the most samples per pixel int best_fbc = -1, best_num_samp = -1; for (int i = 0; i < fbcount; i++) { XVisualInfo *vi = glXGetVisualFromFBConfig(display, fbc[i]); if (vi != nullptr) { int samp_buf, samples; glXGetFBConfigAttrib(display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf); glXGetFBConfigAttrib(display, fbc[i], GLX_SAMPLES, &samples); if (best_fbc < 0 || (samp_buf && samples > best_num_samp)) { best_fbc = i, best_num_samp = samples; } } XFree(vi); } GLXFBConfig bestFbc = fbc[best_fbc]; XFree(fbc); XVisualInfo *vi = glXGetVisualFromFBConfig(display, bestFbc); XSetWindowAttributes swa; Colormap cmap; swa.colormap = cmap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone); swa.background_pixmap = None; swa.border_pixel = 0; swa.event_mask = StructureNotifyMask | KeyPressMask; Window win = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, 800, 600, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa); if (!win) { printf("Failed to create window.\n"); exit(1); } XFree(vi); XStoreName(display, win, "Tutorial 02"); XMapWindow(display, win); // Get the default screen's GLX extension list const char *glxExts = glXQueryExtensionsString(display, DefaultScreen(display)); glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB((const GLubyte *) "glXCreateContextAttribsARB"); GLXContext ctx = nullptr; // Install an X error handler so the application won't exit if GL 3.0 // context allocation fails. ctxErrorOccurred = false; int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler); // Check for the GLX_ARB_create_context extension string and the function. if (isExtensionSupported(glxExts, "GLX_ARB_create_context") && glXCreateContextAttribsARB) { int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 1, None }; ctx = glXCreateContextAttribsARB(display, bestFbc, 0, True, context_attribs); // Sync to ensure any errors generated are processed. XSync(display, False); if (ctxErrorOccurred || ctx == nullptr) { printf("Could not create GL 3.0 context\n"); exit(1); } } // Sync to ensure any errors generated are processed. XSync(display, False); // Restore the original error handler XSetErrorHandler(oldHandler); glXMakeCurrent(display, win, ctx); // must be called AFTER the OpenGL context has been created glewInit(); reshape(800, 600); bool done = false; while (!done) { while (XPending(display) > 0) { XEvent event; XNextEvent(display, &event); switch (event.type) { case Expose: break; case ConfigureNotify: reshape(event.xconfigure.width, event.xconfigure.height); break; case KeyPress: done = true; break; } } render(); glXSwapBuffers(display, win); } glXDestroyContext(display, ctx); XDestroyWindow(display, win); XFreeColormap(display, cmap); XCloseDisplay(display); }
static void dev_open( /* initialize GLX driver */ char *id ) { static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,4, GLX_GREEN_SIZE,4, GLX_BLUE_SIZE,4, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE,15, None}; XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; /* open display server */ ourdisplay = XOpenDisplay(NULL); if (ourdisplay == NULL) error(USER, "cannot open X-windows; DISPLAY variable set?\n"); /* find a usable visual */ ourvinf = glXChooseVisual(ourdisplay, ourscreen, atlBest); if (ourvinf == NULL) error(USER, "no suitable visuals available"); /* get a context */ gctx = glXCreateContext(ourdisplay, ourvinf, NULL, GL_TRUE); /* open window */ ourwinattr.background_pixel = ourblack; ourwinattr.border_pixel = ourblack; ourwinattr.event_mask = ourmask; /* this is stupid */ ourwinattr.colormap = XCreateColormap(ourdisplay, ourroot, ourvinf->visual, AllocNone); gwind = XCreateWindow(ourdisplay, ourroot, 0, 0, DisplayWidth(ourdisplay,ourscreen)-2*BORWIDTH, DisplayHeight(ourdisplay,ourscreen)-2*BORWIDTH, BORWIDTH, ourvinf->depth, InputOutput, ourvinf->visual, CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &ourwinattr); if (gwind == 0) error(SYSTEM, "cannot create window\n"); XStoreName(ourdisplay, gwind, id); #ifndef NOSTEREO if (stereo) /* check if stereo working */ switch (XSGIQueryStereoMode(ourdisplay, gwind)) { case STEREO_TOP: case STEREO_BOTTOM: break; case STEREO_OFF: error(USER, "wrong video mode: run \"/usr/gfx/setmon -n STR_TOP\" first"); case X_STEREO_UNSUPPORTED: error(USER, "stereo not supported on this screen"); default: error(INTERNAL, "unknown stereo mode"); } #endif /* set window manager hints */ ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, (char *)glradicon_bits, glradicon_width, glradicon_height); XSetWMHints(ourdisplay, gwind, &ourxwmhints); /* set GLX context */ glXMakeCurrent(ourdisplay, gwind, gctx); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glEnable(GL_LIGHTING); glFrontFace(GL_CCW); glCullFace(GL_BACK); if (backvis) glDisable(GL_CULL_FACE); else glEnable(GL_CULL_FACE); glDrawBuffer(GL_BACK); /* figure out sensible view */ pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / DisplayWidth(ourdisplay, ourscreen); pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / DisplayHeight(ourdisplay, ourscreen); if (stereo) { /* set stereo mode */ setstereobuf(STEREO_BUFFER_LEFT); pheight *= 2.; } /* map the window */ XMapWindow(ourdisplay, gwind); no_render++; do dev_input(0); /* get resize event */ while ((hres == 0) & (vres == 0)); no_render--; rgl_checkerr("initializing GLX"); }
static bool gfx_ctx_set_video_mode( unsigned width, unsigned height, bool fullscreen) { struct sigaction sa = {{0}}; sa.sa_handler = sighandler; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); int x_off = 0; int y_off = 0; bool windowed_full = g_settings.video.windowed_fullscreen; bool true_full = false; XSetWindowAttributes swa = {0}; XVisualInfo *vi = glXGetVisualFromFBConfig(g_dpy, g_fbc); if (!vi) goto error; swa.colormap = g_cmap = XCreateColormap(g_dpy, RootWindow(g_dpy, vi->screen), vi->visual, AllocNone); swa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask; swa.override_redirect = fullscreen ? True : False; if (fullscreen && !windowed_full) { if (x11_enter_fullscreen(g_dpy, width, height, &g_desktop_mode)) { g_should_reset_mode = true; true_full = true; } else RARCH_ERR("[GLX]: Entering true fullscreen failed. Will attempt windowed mode.\n"); } if (g_settings.video.monitor_index) g_screen = g_settings.video.monitor_index - 1; #ifdef HAVE_XINERAMA if (fullscreen || g_screen != 0) { unsigned new_width = width; unsigned new_height = height; if (x11_get_xinerama_coord(g_dpy, g_screen, &x_off, &y_off, &new_width, &new_height)) RARCH_LOG("[GLX]: Using Xinerama on screen #%u.\n", g_screen); else RARCH_LOG("[GLX]: Xinerama is not active on screen.\n"); if (fullscreen) { width = new_width; height = new_height; } } #endif RARCH_LOG("[GLX]: X = %d, Y = %d, W = %u, H = %u.\n", x_off, y_off, width, height); g_win = XCreateWindow(g_dpy, RootWindow(g_dpy, vi->screen), x_off, y_off, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa); XSetWindowBackground(g_dpy, g_win, 0); gfx_ctx_update_window_title(true); x11_set_window_attr(g_dpy, g_win); if (fullscreen) x11_hide_mouse(g_dpy, g_win); if (true_full) { RARCH_LOG("[GLX]: Using true fullscreen.\n"); XMapRaised(g_dpy, g_win); } else if (fullscreen) // We attempted true fullscreen, but failed. Attempt using windowed fullscreen. { XMapRaised(g_dpy, g_win); RARCH_LOG("[GLX]: Using windowed fullscreen.\n"); // We have to move the window to the screen we want to go fullscreen on first. // x_off and y_off usually get ignored in XCreateWindow(). x11_move_window(g_dpy, g_win, x_off, y_off, width, height); x11_windowed_fullscreen(g_dpy, g_win); } else { XMapWindow(g_dpy, g_win); // If we want to map the window on a different screen, we'll have to do it by force. // Otherwise, we should try to let the window manager sort it out. // x_off and y_off usually get ignored in XCreateWindow(). if (g_screen) x11_move_window(g_dpy, g_win, x_off, y_off, width, height); } XEvent event; XIfEvent(g_dpy, &event, glx_wait_notify, NULL); XSetInputFocus(g_dpy, g_win, RevertToNone, CurrentTime); g_ctx = glXCreateNewContext(g_dpy, g_fbc, GLX_RGBA_TYPE, 0, True); if (!g_ctx) { RARCH_ERR("[GLX]: Failed to create new context.\n"); goto error; } glXMakeCurrent(g_dpy, g_win, g_ctx); XSync(g_dpy, False); g_quit_atom = XInternAtom(g_dpy, "WM_DELETE_WINDOW", False); if (g_quit_atom) XSetWMProtocols(g_dpy, g_win, &g_quit_atom, 1); int val; glXGetConfig(g_dpy, vi, GLX_DOUBLEBUFFER, &val); g_is_double = val; if (g_is_double) { if (!g_pglSwapInterval) g_pglSwapInterval = (int (*)(int))glXGetProcAddress((const GLubyte*)"glXSwapInterval"); if (!g_pglSwapInterval) g_pglSwapInterval = (int (*)(int))glXGetProcAddress((const GLubyte*)"glXSwapIntervalMESA"); if (!g_pglSwapInterval) g_pglSwapInterval = (int (*)(int))glXGetProcAddress((const GLubyte*)"glXSwapIntervalSGI"); if (!g_pglSwapInterval) RARCH_WARN("[GLX]: Cannot find swap interval call.\n"); } else RARCH_WARN("[GLX]: Context is not double buffered!.\n"); gfx_ctx_swap_interval(g_interval); XFree(vi); g_has_focus = true; g_inited = true; driver.display_type = RARCH_DISPLAY_X11; driver.video_display = (uintptr_t)g_dpy; driver.video_window = (uintptr_t)g_win; g_true_full = true_full; return true; error: if (vi) XFree(vi); gfx_ctx_destroy(); return false; }
int main(int argc, char **argv) { /* code add by andrew GONG for reading file from command line argument */ point p[N]; point q[N]; point array[V]; unsigned int G[V][V]; point s = {0, 0}; point t = {0, 0}; int i, j, k; int press; i = j = k = 0; press = 0; for (i = 0; i < N; i++) { p[i].x = p[i].y = 0; q[i].x = q[i].y = 0; } if(argc != 2) { printf("usage:%s filename", argv[0]); } else { FILE *file = fopen(argv[1], "r"); if(file == 0) { printf("Could not open file!\n"); } else { i = 0; printf("%s\n", argv[1]); while(!feof(file)) { if(fscanf(file, "S (%d, %d) (%d, %d)\n", &p[i].x, &p[i].y, &q[i].x, &q[i].y) != 4) { break; } else { i++; } } } fclose(file); } /* opening display: basic connection to X Server */ if( (display_ptr = XOpenDisplay(display_name)) == NULL ) { printf("Could not open display. \n"); exit(-1); } printf("Connected to X server %s\n", XDisplayName(display_name)); screen_num = DefaultScreen(display_ptr); screen_ptr = DefaultScreenOfDisplay(display_ptr); color_map = XDefaultColormap(display_ptr, screen_num); display_width = DisplayWidth(display_ptr, screen_num); display_height = DisplayHeight(display_ptr, screen_num); printf("Width %d, Height %d, Screen Number %d\n", display_width, display_height, screen_num); /* creating the window */ border_width = 10; win_x = 0; win_y = 0; win_width = display_width/2; win_height = (unsigned int) (win_width / 1.7); /* rectangular window */ win= XCreateSimpleWindow(display_ptr, RootWindow(display_ptr, screen_num), win_x, win_y, win_width, win_height, border_width, BlackPixel(display_ptr, screen_num), WhitePixel(display_ptr, screen_num)); /* now try to put it on screen, this needs cooperation of window manager */ size_hints = XAllocSizeHints(); wm_hints = XAllocWMHints(); class_hints = XAllocClassHint(); if( size_hints == NULL || wm_hints == NULL || class_hints == NULL ) { printf("Error allocating memory for hints. \n"); exit(-1); } size_hints -> flags = PPosition | PSize | PMinSize ; size_hints -> min_width = 60; size_hints -> min_height = 60; XStringListToTextProperty(&win_name_string, 1, &win_name); XStringListToTextProperty(&icon_name_string, 1, &icon_name); wm_hints -> flags = StateHint | InputHint ; wm_hints -> initial_state = NormalState; wm_hints -> input = False; class_hints -> res_name = "x_use_example"; class_hints -> res_class = "examples"; XSetWMProperties(display_ptr, win, &win_name, &icon_name, argv, argc, size_hints, wm_hints, class_hints); /* what events do we want to receive */ XSelectInput(display_ptr, win, ExposureMask | StructureNotifyMask | ButtonPressMask); /* finally: put window on screen */ XMapWindow(display_ptr, win); XFlush(display_ptr); /* create graphics context, so that we may draw in this window */ gc = XCreateGC(display_ptr, win, valuemask, &gc_values); XSetForeground(display_ptr, gc, BlackPixel(display_ptr, screen_num)); XSetLineAttributes(display_ptr, gc, 2, LineSolid, CapRound, JoinRound); /* and three other graphics contexts, to draw in yellow and red and grey */ gc_yellow = XCreateGC( display_ptr, win, valuemask, &gc_yellow_values); XSetLineAttributes(display_ptr, gc_yellow, 2, LineSolid, CapRound, JoinRound); if(XAllocNamedColor(display_ptr, color_map, "yellow", &tmp_color1, &tmp_color2 ) == 0) {printf("failed to get color yellow\n"); exit(-1); } else XSetForeground(display_ptr, gc_yellow, tmp_color1.pixel); gc_red = XCreateGC(display_ptr, win, valuemask, &gc_red_values); /* XSetLineAttributes(display_ptr, gc_red, 6, LineSolid, CapRound, JoinRound); */ if( XAllocNamedColor(display_ptr, color_map, "red", &tmp_color1, &tmp_color2) == 0 ) {printf("failed to get color red\n"); exit(-1);} else XSetForeground(display_ptr, gc_red, tmp_color1.pixel); gc_grey = XCreateGC(display_ptr, win, valuemask, &gc_grey_values); if( XAllocNamedColor(display_ptr, color_map, "light grey", &tmp_color1, &tmp_color2) == 0) {printf("failed to get color grey\n"); exit(-1);} else XSetForeground(display_ptr, gc_grey, tmp_color1.pixel); /* and now it starts: the event loop */ while(1) { XNextEvent( display_ptr, &report ); switch(report.type) { case Expose: /* (re-)draw the example figure. This event happens * each time some part ofthe window gets exposed (becomes visible) */ /* print all the obstacles */ for (i = 0; i < N; i++) { if (p[i].x != 0 && p[i].y != 0 && q[i].x != 0 && q[i].y !=0) { XDrawLine(display_ptr, win, gc, p[i].x, p[i].y, q[i].x, q[i].y); } } break; case ConfigureNotify: /* This event happens when the user changes the size of the window */ win_width = report.xconfigure.width; win_height = report.xconfigure.height; break; /* This event happens when the user pushes a mouse button. I draw * a circle to show the point where it happened, but do not save * the position; so when the next redraw event comes, these circles * disappear again. */ case ButtonPress: { int x, y; x = report.xbutton.x; y = report.xbutton.y; /* read point s, t */ if (press == 0) { s.x = report.xbutton.x; s.y = report.xbutton.y; } else if (press == 1) { t.x = report.xbutton.x; t.y = report.xbutton.y; } press += 1; if (report.xbutton.button == Button1) XFillArc(display_ptr, win, gc_red, x - win_height/40, y - win_height/40, win_height / 20, win_height / 20, 0, 360*64); else XFillArc(display_ptr, win, gc_yellow, x - win_height / 40, y - win_height / 40, win_height / 20, win_height / 20, 0, 360*64); printf("%d, %d, %d, %d\n", s.x, s.y, t.x, t.y); printf("press = %d\n", press); if (press == 2) { XFlush(display_ptr); /* construction graph G *s is the first point and t is the last point */ array[0].x = s.x; array[0].y = s.y; array[V-1].x = t.x; array[V-1].y = t.y; for (i = 1; i < V-1; i++) { if ( i <= N ) { array[i].x = p[i-1].x; array[i].y = p[i-1].y; } else if (i > N) { array[i].x = q[i-N-1].x; array[i].y = q[i-N-1].y; } } for (i = 0; i < V; i++) { int j; for(j = 0; j < V; j++) { if (( array[i].x == 0 && array[i].y == 0 ) || ( array[j].x == 0 && array[j].y == 0)) { G[i][j] = INT_MAX; } else { G[i][j] = distant(array[i],array[j]); } for (k = 0; k < N; k++) { if (p[k].x != 0 && p[k].y != 0 && q[k].x != 0 && q[k].y != 0 && array[i].x !=0 && array[i].y !=0 && intersect( array[i], array[j], p[k], q[k])) { G[i][j] = INT_MAX; } } } } dijkstra(G, 0, array); } } break; default: /* this is a catch-all for other events; it does not do anything. *One could look at the report type to see what the event was */ break; } } exit(0); }
GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) : calibrator(calibrator0), time_elapsed(0) { display = XOpenDisplay(NULL); if (display == NULL) { throw std::runtime_error("Unable to connect to X server"); } screen_num = DefaultScreen(display); // Load font and get font information structure font_info = XLoadQueryFont(display, "9x15"); if (font_info == NULL) { // fall back to native font font_info = XLoadQueryFont(display, "fixed"); if (font_info == NULL) { XCloseDisplay(display); throw std::runtime_error("Unable to open neither '9x15' nor 'fixed' font"); } } #ifdef HAVE_X11_XRANDR // get screensize from xrandr int nsizes; XRRScreenSize* randrsize = XRRSizes(display, screen_num, &nsizes); if (nsizes != 0) { set_display_size(randrsize->width, randrsize->height); } else { set_display_size(DisplayWidth(display, screen_num), DisplayHeight(display, screen_num)); } # else set_display_size(DisplayWidth(display, screen_num), DisplayHeight(display, screen_num)); #endif // Register events on the window XSetWindowAttributes attributes; attributes.override_redirect = True; attributes.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; win = XCreateWindow(display, RootWindow(display, screen_num), 0, 0, display_width, display_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWEventMask, &attributes); XMapWindow(display, win); // Listen to events XGrabKeyboard(display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime); calib_input = calibrator->register_events(); if (!calib_input) { XGrabPointer(display, win, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); } Colormap colormap = DefaultColormap(display, screen_num); XColor color; for (int i = 0; i != nr_colors; i++) { XParseColor(display, colormap, colors[i], &color); XAllocColor(display, colormap, &color); pixel[i] = color.pixel; } XSetWindowBackground(display, win, pixel[GRAY]); XClearWindow(display, win); gc = XCreateGC(display, win, 0, NULL); XSetFont(display, gc, font_info->fid); // Setup timer for animation signal(SIGALRM, sigalarm_handler); struct itimerval timer; timer.it_value.tv_sec = time_step/1000; timer.it_value.tv_usec = (time_step % 1000) * 1000; timer.it_interval = timer.it_value; setitimer(ITIMER_REAL, &timer, NULL); }
int main(int argc, char **argv) { int state_count = 0; Atom states[10]; Atom type = 0; int i,x_r,y_r; unsigned int h_r,w_r; int ret; int ewmh_state_arg = 0; int ewmh_type_arg = 0; int mwm_func_arg = 0; int mwm_decor_arg = 0; int has_ewmh_desktop = 0; Atom ewmh_desktop = 0; XSizeHints hints; XClassHint classhints; XWMHints wm_hints; PropMwmHints mwm_hints; Window trans_win = 0; if (!(dpy = XOpenDisplay(""))) { fprintf(stderr, "can't open display\n"); exit(1); } screen = DefaultScreen(dpy); Root = RootWindow(dpy, screen); InitAtom(); hints.width = 170; hints.height = 100; hints.x = 0; hints.y = 0; hints.flags = 0; wm_hints.flags = 0; mwm_hints.props[0] = 0; mwm_hints.props[1] = 0; mwm_hints.props[2] = 0; mwm_hints.props[3] = 0; win = XCreateSimpleWindow( dpy, Root, 0, 0, hints.width, hints.height, 0, 0, 0); for (i = 1; i < argc; i++) { char *error_arg = NULL; if (strcasecmp(argv[i], "--help") == 0) { show_usage(); exit(0); } else if (strcasecmp(argv[i], "--ewmh-state") == 0) { ewmh_state_arg = 1; ewmh_type_arg = 0; mwm_func_arg = 0; mwm_decor_arg = 0; } else if (strcasecmp(argv[i], "--ewmh-type") == 0) { ewmh_state_arg = 0; ewmh_type_arg = 1; mwm_func_arg = 0; mwm_decor_arg = 0; } else if (strcasecmp(argv[i], "--mwm-func") == 0) { ewmh_state_arg = 0; ewmh_type_arg = 0; mwm_func_arg = 1; mwm_decor_arg = 0; } else if (strcasecmp(argv[i], "--mwm-decor") == 0) { ewmh_state_arg = 0; ewmh_type_arg = 0; mwm_func_arg = 0; mwm_decor_arg = 1; } else if (strcasecmp(argv[i], "--min-size") == 0) { i++; hints.min_width = atoi(argv[i]); i++; hints.min_height = atoi(argv[i]); hints.flags |= PMinSize; } else if (strcasecmp(argv[i], "--max-size") == 0) { i++; hints.max_width = atoi(argv[i]); i++; hints.max_height = atoi(argv[i]); hints.flags |= PMaxSize; } else if (strcasecmp(argv[i], "--inc-size") == 0) { i++; hints.width_inc = atoi(argv[i]); i++; hints.height_inc = atoi(argv[i]); hints.flags |= PResizeInc; } else if (strcasecmp(argv[i], "--p-geometry") == 0) { i++; ret = XParseGeometry(argv[i], &x_r, &y_r, &w_r, &h_r); if ((ret & WidthValue) && (ret & HeightValue)) { hints.width = w_r; hints.height = h_r; hints.flags |= PSize; } if ((ret & XValue) && (ret & YValue)) { hints.x = x_r; hints.y = y_r; hints.win_gravity = NorthWestGravity; if (ret & XNegative) { hints.x += XDisplayWidth(dpy, screen) - hints.width; hints.win_gravity = NorthEastGravity; } if (ret & YNegative) { hints.y += XDisplayHeight(dpy, screen) - hints.height; if (ret & XNegative) { hints.win_gravity = SouthEastGravity; } else { hints.win_gravity = SouthWestGravity; } hints.flags |= PWinGravity; } hints.flags |= PPosition; } } else if (strcasecmp(argv[i], "--us-geometry") == 0) { i++; ret = XParseGeometry(argv[i], &x_r, &y_r, &w_r, &h_r); if ((ret & WidthValue) && (ret & HeightValue)) { hints.width = w_r; hints.height = h_r; hints.flags |= USSize; } if ((ret & XValue) && (ret & YValue)) { hints.x = x_r; hints.y = y_r; hints.win_gravity=NorthWestGravity; if (ret & XNegative) { hints.x += XDisplayWidth(dpy,screen) - hints.width; hints.win_gravity=NorthEastGravity; } if (ret & YNegative) { hints.y += XDisplayHeight(dpy,screen) - hints.height; if (ret & XNegative) { hints.win_gravity = SouthEastGravity; } else { hints.win_gravity = SouthWestGravity; } } hints.flags |= USPosition | PWinGravity; } } else if (strcasecmp(argv[i], "--input") == 0) { i++; if (strcasecmp(argv[i], "true") == 0) { wm_hints.input = input_mode = True; wm_hints.flags |= InputHint; } else if (strcasecmp(argv[i], "false") == 0) { wm_hints.input = input_mode = False; wm_hints.flags |= InputHint; } else { error_arg = "--input"; } } else if (strcasecmp(argv[i], "--focus-proto") == 0) { has_focus_proto = 1; } else if (strcasecmp(argv[i], "--no-delete-proto") == 0) { has_delete_proto = 0; } else if (strcasecmp(argv[i], "--wm-state") == 0) { wm_hints.flags |= StateHint; i++; if (strcasecmp(argv[i], "withdrawn") == 0) { wm_hints.initial_state = WithdrawnState; } else if (strcasecmp(argv[i], "normal") == 0) { wm_hints.initial_state = NormalState; } else if (strcasecmp(argv[i], "iconic") == 0) { wm_hints.initial_state = IconicState; } else { error_arg = "--wm-state"; } } else if (strcasecmp(argv[i], "--wm-urgency") == 0) { wm_hints.flags |= XUrgencyHint; } else if (strcasecmp(argv[i], "--wm-group") == 0) { wm_hints.flags |= WindowGroupHint; i++; if (strcasecmp(argv[i], "window") == 0) { wm_hints.window_group = win; } else if (strcasecmp(argv[i], "root") == 0) { wm_hints.window_group = Root; } else { wm_hints.window_group = strtoul(argv[i], NULL, 0); } } else if (strcasecmp(argv[i], "--transient") == 0) { i++; if (strcasecmp(argv[i],"root") == 0) { trans_win = Root; } else { trans_win = strtoul(argv[i], NULL, 0); } } else if (strcasecmp(argv[i], "--mwm-input") == 0) { mwm_hints.props[0] |= MWM_HINTS_INPUT_MODE; i++; if (strcasecmp(argv[i], "modless") == 0) { mwm_hints.props[3] = MWM_INPUT_MODELESS; } else if (strcasecmp(argv[i], "app_modal") == 0) { mwm_hints.props[3] = MWM_INPUT_PRIMARY_APPLICATION_MODAL; } else if (strcasecmp(argv[i], "sys_modal") == 0) { mwm_hints.props[3] = MWM_INPUT_SYSTEM_MODAL; } else if (strcasecmp(argv[i], "full_app_modal") == 0) { mwm_hints.props[3] = MWM_INPUT_FULL_APPLICATION_MODAL; } else { error_arg = "--mwm-input"; } } else if (strcasecmp(argv[i], "--ewmh-desktop") == 0) { has_ewmh_desktop = 1; i++; ewmh_desktop = atol(argv[i]); } else if (ewmh_state_arg && state_count < 10) { if (strcasecmp(argv[i], "hidden") == 0) { states[state_count++] = ATOM_NET_WM_STATE_HIDDEN; } else if (strcasecmp(argv[i], "shaded") == 0) { states[state_count++] = ATOM_NET_WM_STATE_SHADED; } else if (strcasecmp(argv[i], "sticky") == 0) { states[state_count++] = ATOM_NET_WM_STATE_STICKY; } else if (strcasecmp(argv[i], "skippager") == 0) { states[state_count++] = ATOM_NET_WM_STATE_SKIP_PAGER; } else if (strcasecmp(argv[i], "skiptaskbar") == 0) { states[state_count++] = ATOM_NET_WM_STATE_SKIP_TASKBAR; } else if (strcasecmp(argv[i], "maxhoriz") == 0) { states[state_count++] = ATOM_NET_WM_STATE_MAXIMIZED_HORIZ; } else if (strcasecmp(argv[i], "maxvert") == 0) { states[state_count++] = ATOM_NET_WM_STATE_MAXIMIZED_VERT; } else if (strcasecmp(argv[i], "modal") == 0) { states[state_count++] = ATOM_NET_WM_STATE_MODAL; } else if (strcasecmp(argv[i], "staysontop") == 0) { states[state_count++] = ATOM_NET_WM_STATE_STAYS_ON_TOP; } else if (strcasecmp(argv[i], "fullscreen") == 0) { states[state_count++] = ATOM_NET_WM_STATE_FULLSCREEN; } else { error_arg = "--ewmh-state"; } } else if (ewmh_type_arg) { if (strcasecmp(argv[i], "normal") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_NORMAL; } else if (strcasecmp(argv[i], "dock") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_DOCK; } else if (strcasecmp(argv[i], "toolbar") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_TOOLBAR; } else if (strcasecmp(argv[i], "desktop") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_DESKTOP; } else if (strcasecmp(argv[i], "menu") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_MENU; } else if (strcasecmp(argv[i], "dialog") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_DIALOG; } else if (strcasecmp(argv[i], "splash") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_SPLASH; } else if (strcasecmp(argv[i], "utility") == 0) { type = ATOM_NET_WM_WINDOW_TYPE_UTILITY; } else { error_arg = "--ewmh-type"; } } else if (mwm_func_arg) { mwm_hints.props[0] |= MWM_HINTS_FUNCTIONS; if (strcasecmp(argv[i], "all") == 0) { mwm_hints.props[1] |= MWM_FUNC_ALL; } else if (strcasecmp(argv[i], "resize") == 0) { mwm_hints.props[1] |= MWM_FUNC_RESIZE; } else if (strcasecmp(argv[i], "move") == 0) { mwm_hints.props[1] |= MWM_FUNC_MOVE; } else if (strcasecmp(argv[i], "minimize") == 0) { mwm_hints.props[1] |= MWM_FUNC_MINIMIZE; } else if (strcasecmp(argv[i], "maximize") == 0) { mwm_hints.props[1] |= MWM_FUNC_MAXIMIZE; } else if (strcasecmp(argv[i], "close") == 0) { mwm_hints.props[1] |= MWM_FUNC_CLOSE; } else { error_arg = "--mwm-func"; } } else if (mwm_decor_arg) { mwm_hints.props[0] |= MWM_HINTS_DECORATIONS; if (strcasecmp(argv[i], "all") == 0) { mwm_hints.props[2] |= MWM_DECOR_ALL; } else if (strcasecmp(argv[i], "border") == 0) { mwm_hints.props[2] |= MWM_DECOR_BORDER; } else if (strcasecmp(argv[i], "resizeh") == 0) { mwm_hints.props[2] |= MWM_DECOR_RESIZEH; } else if (strcasecmp(argv[i], "title") == 0) { mwm_hints.props[2] |= MWM_DECOR_TITLE; } else if (strcasecmp(argv[i], "menu") == 0) { mwm_hints.props[2] |= MWM_DECOR_MENU; } else if (strcasecmp(argv[i], "minimize") == 0) { mwm_hints.props[2] |= MWM_DECOR_MINIMIZE; } else if (strcasecmp(argv[i], "maximize") == 0) { mwm_hints.props[2] |= MWM_DECOR_MAXIMIZE; } else { error_arg = "--mwm-decor"; } } else { error_arg = "regular"; } if (error_arg) { show_usage(); printf("Invalid %s argument: %s\n", error_arg, argv[i]); exit(1); } } XSelectInput(dpy, win, StructureNotifyMask); if (wm_hints.flags) { XSetWMHints(dpy, win, &wm_hints); } if (state_count != 0) { XChangeProperty( dpy, win, ATOM_NET_WM_STATE, XA_ATOM, 32, PropModeReplace, (unsigned char *)states, state_count); } if (type != 0) { XChangeProperty( dpy, win, ATOM_NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace, (unsigned char *)&type, 1); } if (has_ewmh_desktop) { XChangeProperty( dpy, win, ATOM_NET_WM_DESKTOP, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&ewmh_desktop, 1); } if (has_delete_proto || has_focus_proto) { Atom proto[2]; int j = 0; if (has_delete_proto) proto[j++] = ATOM_WM_DELETE_WINDOW; if (has_focus_proto) proto[j++] = ATOM_WM_TAKE_FOCUS; XSetWMProtocols(dpy, win, proto, j); } { XTextProperty nametext; char *list[] = { NULL, NULL }; list[0] = "Hints Test"; classhints.res_name = strdup("hints_test"); classhints.res_class = strdup("HintsTest"); if (!XStringListToTextProperty(list, 1, &nametext)) { fprintf(stderr, "Failed to convert name to XText\n"); exit(1); } XSetWMProperties( dpy, win, &nametext, &nametext, NULL, 0, &hints, NULL, &classhints); XFree(nametext.value); } if (mwm_hints.props[0] != 0) { XChangeProperty( dpy, win, ATOM_MOTIF_WM_HINTS, ATOM_MOTIF_WM_HINTS, 32, PropModeReplace,(unsigned char *)&mwm_hints, PROP_MWM_HINTS_ELEMENTS); } if (trans_win !=0) XSetTransientForHint(dpy, win, trans_win); XMapWindow(dpy, win); XSetWindowBackground(dpy, win, 0); Xloop(); return 1; }
short WPmcic( wpw_id pid, short x, short y, short bw, char *fnam, short cb, short cf, DBint *iid) /* Skapar WPICON-fönster och länkar in i ett WPIWIN. * * In: pid = Förälder. * x = Läge i X-led. * y = Läge i Y-led. * bw = Ramens bredd. * fnam = Ikon-fil. * cb = Bakgrundsfärg. * cf = Förgrundsfärg. * iid = Pekare till utdata. * * Ut: *iid = Giltigt entry i förälderns wintab. * * Felkod: WP1262 = Föräldern %s finns ej. * WP1272 = Föräldern %s är ej ett WPIWIN. * WP1282 = För många subfönster i %s. * * (C)microform ab 13/1/94 J. Kjellander * ******************************************************!*/ { char errbuf[80]; short i,status; WPWIN *winptr; WPIWIN *iwinptr; WPICON *icoptr; /* ***Fixa C-pekare till förälderns entry i wpwtab. */ if ( (winptr=WPwgwp(pid)) == NULL ) { sprintf(errbuf,"%d",(int)pid); return(erpush("WP1262",errbuf)); } /* ***Kolla att det är ett WPIWIN och fixa en pekare till ***förälder-fönstret självt. */ if ( winptr->typ != TYP_IWIN ) { sprintf(errbuf,"%d",(int)pid); return(erpush("WP1272",errbuf)); } else iwinptr = (WPIWIN *)winptr->ptr; /* ***Skapa ID för den nya ikonen, dvs. fixa ***en ledig plats i förälderns fönstertabell. */ i = 0; while ( i < WP_IWSMAX && iwinptr->wintab[i].ptr != NULL ) ++i; if ( i == WP_IWSMAX ) { sprintf(errbuf,"%d",(int)pid); return(erpush("WP1282",errbuf)); } else *iid = i; /* ***Skapa ikonen. */ if ( (status=WPwcic(iwinptr->id.x_id,x,y,bw,fnam,cb,cf, &icoptr)) < 0 ) return(status); /* ***Länka in den i WPIWIN-fönstret. */ iwinptr->wintab[*iid].typ = TYP_ICON; iwinptr->wintab[*iid].ptr = (char *)icoptr; icoptr->id.w_id = *iid; icoptr->id.p_id = pid; /* ***Om WPIWIN-fönstret redan är mappat skall ikonen mappas nu. */ if ( iwinptr->mapped ) XMapWindow(xdisp,icoptr->id.x_id); return(0); }
void WindowImpl::open() { const char *display; GLXFBConfig *fbConfigs; int nFBConfig; XVisualInfo *vInfo; XSetWindowAttributes swa; display = getenv("DISPLAY"); if (display == nullptr) fail("DISPLAY not set"); dpy = XOpenDisplay(display); if (dpy == nullptr) fail("Failed to open display"); glXExtensions = glXQueryExtensionsString(dpy, DefaultScreen(dpy)); glXCreateContextAttribsARB = reinterpret_cast<PFNGLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress((const GLubyte *)"glXCreateContextAttribsARB")); #ifdef DISPLAY_GLX_INFO printf("Client version: %s\n", glXGetClientString(dpy, GLX_VERSION)); printf("Client vendor: %s\n", glXGetClientString(dpy, GLX_VENDOR)); printf("Client extensions: %s\n", glXGetClientString(dpy, GLX_EXTENSIONS)); printf("Server version: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_VERSION)); printf("Server vendor: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_VENDOR)); printf("Server extensions: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_EXTENSIONS)); printf("Connection extensions: %s\n", glXExtensions); #endif fbConfigs = glXChooseFBConfig(dpy, DefaultScreen(dpy), framebufferAttribs, &nFBConfig); if (fbConfigs == nullptr) fail("Failed to find suitable framebuffer config"); #ifdef DISPLAY_GLX_INFO { int config_id; glXGetFBConfigAttrib(dpy, fbConfigs[0], GLX_FBCONFIG_ID, &config_id); printf("Chose FBConfig %#x\n", config_id); } #endif vInfo = glXGetVisualFromFBConfig(dpy, fbConfigs[0]); if (vInfo == nullptr) fail("Failed to load framebuffer X visual"); cmap = XCreateColormap(dpy, RootWindow(dpy, vInfo->screen), vInfo->visual, AllocNone); swa.border_pixel = 0; swa.event_mask = StructureNotifyMask; swa.colormap = cmap; win = XCreateWindow(dpy, RootWindow(dpy, vInfo->screen), 0, 0, 640, 480, 0, vInfo->depth, InputOutput, vInfo->visual, CWBorderPixel | CWColormap | CWEventMask, &swa); if (glXCreateContextAttribsARB != nullptr) ctx = glXCreateContextAttribsARB(dpy, fbConfigs[0], nullptr, True, contextAttribs); else ctx = glXCreateNewContext(dpy, fbConfigs[0], GLX_RGBA_TYPE, nullptr, True); if (ctx == nullptr) { fail("Failed to create OpenGL context"); } xWin = glXCreateWindow(dpy, fbConfigs[0], win, nullptr); XFree(vInfo); XFree(fbConfigs); XMapWindow(dpy, win); if (!glXMakeContextCurrent(dpy, xWin, xWin, ctx)) fail("Failed to make context current"); printf("OpenGL version: %s\n", glGetString(GL_VERSION)); wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False); XSetWMProtocols(dpy, win, &wm_delete_window, 1); XSync(dpy, False); }
// From <https://www.opengl.org/wiki/Programming_OpenGL_in_Linux:_GLX_and_Xlib> int main(int argc, char** argv){ Initialised = false; StartTime = GetClock(); double time; Display* dpy; Window root; XVisualInfo* vi; Colormap cmap; XSetWindowAttributes swa; Window win; GLXContext glc; XWindowAttributes gwa; XEvent xev; GLint att[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None}; dpy = XOpenDisplay(0); if(dpy == 0){ printf("\n\tcannot connect to X server\n\n"); return 1; } root = DefaultRootWindow(dpy); vi = glXChooseVisual(dpy, 0, att); if(vi == 0){ printf("\n\tno appropriate visual found\n\n"); return 1; }else{ // %p creates hexadecimal output like in glxinfo printf("\n\tvisual %p selected\n", (void*)vi->visualid); } cmap = XCreateColormap(dpy, root, vi->visual, AllocNone); swa.colormap = cmap; swa.event_mask = ExposureMask | KeyPressMask; win = XCreateWindow( dpy, root, 0, 0, 640, 480, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa ); XMapWindow(dpy, win); XStoreName(dpy, win, "OpenGL Sample"); glc = glXCreateContext(dpy, vi, 0, GL_TRUE); glXMakeCurrent(dpy, win, glc); if(!InitGLEW()){ glXMakeCurrent (dpy, None, 0); glXDestroyContext(dpy, glc); XDestroyWindow (dpy, win); XCloseDisplay (dpy); return 1; } if(!LoadShader ("OpenGL/Texture.vp", "OpenGL/Texture.fp")) return 1; if(!LoadTexture("Pic/greatwall.jpg")) return 1; Initialised = true; bool running = true; while(running){ while(XCheckWindowEvent(dpy, win, 0xFFFFFFFF, &xev)){ switch(xev.type){ case Expose: XGetWindowAttributes(dpy, win, &gwa); Render(gwa.width, gwa.height); glXSwapBuffers(dpy, win); break; case KeyPress: // printf("KeyPress: keycode %u state %u\n", xev.xkey.keycode, xev.xkey.state); if(xev.xkey.keycode == Key_Escape) running = false; else OnKeyDown(xev.xkey.keycode); break; } } XGetWindowAttributes(dpy, win, &gwa); Render(gwa.width, gwa.height); glXSwapBuffers(dpy, win); RenderTime(GetClock()-time); time = GetClock(); usleep(1000); } glXMakeCurrent (dpy, None, 0); glXDestroyContext(dpy, glc); XDestroyWindow (dpy, win); XCloseDisplay (dpy); free(InputBuffer ); free(OutputBuffer); return 0; }
int InitX() { XColor xColor; Colormap colormap; dpy = XOpenDisplay(NULL); if(dpy == NULL) { fprintf(stderr, "ERROR: Unable to open X display\n"); return 1; } clrBlack = BlackPixel(dpy, DefaultScreen(dpy)); clrWhite = WhitePixel(dpy, DefaultScreen(dpy)); colormap = DefaultColormap(dpy, DefaultScreen(dpy)); XParseColor(dpy, colormap, "red", &xColor); XAllocColor(dpy, colormap, &xColor); clrRed = xColor.pixel; XParseColor(dpy, colormap, "blue", &xColor); XAllocColor(dpy, colormap, &xColor); clrBlue = xColor.pixel; XParseColor(dpy, colormap, "orange", &xColor); XAllocColor(dpy, colormap, &xColor); clrOrange = xColor.pixel; wmDeleteMessage = XInternAtom(dpy, "WM_DELETE_WINDOW", False); // Create the window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 400, 300, 8, clrBlack, clrWhite); XSetWMProtocols(dpy, win, &wmDeleteMessage, 1); XSelectInput(dpy, win, StructureNotifyMask | ExposureMask | KeyPressMask); XGCValues values; XFontStruct *font; font = XLoadQueryFont(dpy, "fixed"); if(!font) { fprintf(stderr, "No fixed font?\n"); return 2; } values.line_width = 1; values.line_style = LineSolid; values.font = font->fid; gc = XCreateGC(dpy, win, GCLineWidth|GCLineStyle|GCFont, &values); XStoreName(dpy, win, "xtemp"); // Map the window (that is, make it appear on the screen) XMapWindow(dpy, win); // Tell the GC we draw using black on white XSetForeground(dpy, gc, clrBlack); XSetBackground(dpy, gc, clrWhite); // Wait for the MapNotify event for(;;) { XEvent e; XNextEvent(dpy, &e); if (e.type == MapNotify) break; } return 0; }
void set_title(void) { //Set the window title bar. XMapWindow(dpy, win); XStoreName(dpy, win, "335 Lab1 LMB for particle"); }
void set_title(void) { //Set the window title bar. XMapWindow(dpy, win); XStoreName(dpy, win, "Game"); }
/* Stereo thread - For GL_STEREO */ static void * nvstusb_stereo_thread(void * in_pv_arg) { struct nvstusb_context *ctx = (struct nvstusb_context *) in_pv_arg; Display *dpy; Window win; /* Openning X display */ dpy = XOpenDisplay(0); /* Preparing new X window */ Window s_window; static int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None }; XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList); s_window = RootWindow(dpy, vi->screen); XSetWindowAttributes swa; swa.colormap = XCreateColormap(dpy, s_window, vi->visual, AllocNone); swa.override_redirect = true; /* Create X window 1x1 top left of screen */ win = XCreateWindow(dpy, s_window , 0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual, CWColormap|CWOverrideRedirect, &swa); XMapWindow(dpy, win); /* Create glX context */ GLXContext glx_ctx = glXCreateContext(dpy, vi, 0, true); glXMakeCurrent(dpy, win, glx_ctx); /* Loop until stop */ while (ctx->b_thread_running) { /* Send swap to usb controler */ nvstusb_swap(ctx, nvstusb_quad, NULL /*f_swap*/); /* Read status from usb controler */ struct nvstusb_keys k; nvstusb_get_keys(ctx, &k); if (k.toggled3D) { nvstusb_invert_eyes(ctx); } } /* Destroy context */ glx_ctx = glXGetCurrentContext(); glXDestroyContext(dpy, glx_ctx); return NULL; }
int main(int argc, char* argv[]) { struct body a = {2, 2, 0, 0, 0, 0, 0}; struct body b = {1, 1, 0, 0, 0, 0, 0}; int N = 200; int iter = 1000; if(argc == 1) { float dist = distance (a, b); printf("Test distance: %f\n", dist); } if(argc == 3) { N = atoi(argv[1]); iter = atoi(argv[2]); } #ifdef ANIMATE XPoint* points = malloc(sizeof(XPoint)*N); Display* disp; Window window, rootwin; int screen; disp = XOpenDisplay(NULL); screen = DefaultScreen(disp); rootwin = RootWindow(disp,screen); window = XCreateSimpleWindow(disp,rootwin, 0,0,X_SIZE,Y_SIZE,1,0,0); GC gc = XCreateGC(disp, window, 0, 0); XSetForeground(disp, gc, WhitePixel(disp, screen)); XSetBackground(disp, gc, BlackPixel(disp, screen)); XMapWindow(disp,window); XClearWindow(disp,window); copyToXBuffer(star, points, N); XDrawPoints(disp, window, gc, points, N, 0); XFlush(disp); #endif clock_t start = clock(); for(int i = 0; i < iter; i++) { #ifdef ANIMATE copyToXBuffer(star, points, N); XDrawPoints(disp, window, gc, points, N, CoordModeOrigin); XClearWindow(disp,window); #endif } clock_t stop = clock(); float diff = (float)(stop - start)/CLOCKS_PER_SEC; printf("Total: %lf seconds\n",diff); printf("Bodies: %d\n",N); printf("Iterations: %d\n", iter); #ifdef ANIMATE XCloseDisplay(disp); #endif return 0; }
int DisplayBitmap( PBITMAP pBmp, char *filename ) { int scrn; XVisualInfo *visi = NULL; XSetWindowAttributes xwndsetattr; XWindowAttributes xwndattr; Colormap clrmap; XSizeHints szhints; XEvent event; GLXContext glctx; Atom wm_delete_window; XWMHints hints; Pixmap icon; char *s; if (!pBmp) { fprintf( stderr, "Can't read %s\n", filename ); return 1; } if ( pBmp->sampleformat!=BITMAP_UINT8 && pBmp->sampleformat!=BITMAP_IEEE ) { fprintf( stderr, "Can't display %s: not 8 bits or IEEE 32 bits per sample.\n", filename ); return 1; } if ( pBmp->nsamples!=1 && pBmp->nsamples!=3 && pBmp->nsamples!=4 ) { fprintf( stderr, "Can't display %s: not an 8, 24, or 32 bit per pixel image.\n", filename ); return 1; } dspy = XOpenDisplay( 0 ); if (!dspy) { fprintf( stderr, "Error connecting to X server\n" ); exit( -1 ); } scrn = DefaultScreen( dspy ); visi = glXChooseVisual( dspy, scrn, attributeListSgl ); if ( !visi ) { visi = glXChooseVisual( dspy, scrn, attributeListDbl ); switchbuffer = 1; } glctx = glXCreateContext( dspy, visi, 0, GL_TRUE ); clrmap = XCreateColormap( dspy, RootWindow(dspy, visi->screen ), visi->visual, AllocNone ); xwndsetattr.colormap = clrmap; xwndsetattr.border_pixel = 0; xwndsetattr.event_mask = StructureNotifyMask; wnd = XCreateWindow( dspy, RootWindow( dspy, visi->screen ), 0, /* x */ 0, /* y */ pBmp->xres, /* width */ pBmp->yres, /* height */ 0, visi->depth, InputOutput, visi->visual, CWBorderPixel | CWColormap | CWEventMask, &xwndsetattr ); XGetWindowAttributes( dspy, wnd, &xwndattr ); /* OpenGL likes the bitmap data to have the bottom row first, not the * top row. Note the left most column is the first column. */ pBmp = OrientBitmap( pBmp, BITMAP_BOTLEFT ); /* Get a hook in on the user quitting the app. This will prevent * that annoying "X connection to 0:0 broken" message. */ wm_delete_window = XInternAtom( dspy, "WM_DELETE_WINDOW", False ); (void) XSetWMProtocols( dspy, wnd, &wm_delete_window, 1 ); s = strrchr( filename, '/' ); if (!s) s = filename; else s++; XStoreName( dspy, wnd, s ); icon = XCreateBitmapFromData( dspy, wnd, (const char *)affine_bits, affine_width, affine_height ); hints.icon_pixmap = icon; hints.flags = IconPixmapHint; XSetWMHints( dspy, wnd, &hints ); szhints.flags = PMinSize | PMaxSize; szhints.min_width = pBmp->xres; szhints.max_width = pBmp->xres; szhints.min_height = pBmp->yres; szhints.max_height = pBmp->yres; XSetNormalHints( dspy, wnd, &szhints ); XMapWindow( dspy, wnd ); /* Connect the context to the window. */ glXMakeCurrent(dspy, wnd, glctx); glShadeModel(GL_FLAT); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glViewport(0,0,pBmp->xres,pBmp->yres); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,pBmp->xres,0.0,pBmp->yres,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); XSelectInput( dspy, wnd, ExposureMask | StructureNotifyMask ); for (;;) { XNextEvent( dspy, &event ); switch (event.type) { case MapNotify: DisplayBits( pBmp, 0, 0, pBmp->xres, pBmp->yres ); break; case Expose: if ( event.xexpose.window == wnd ) DisplayBits( pBmp, event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height ); break; case ClientMessage: if (event.xclient.data.l[0] == wm_delete_window && event.xclient.window == wnd ) goto Exit; break; } } Exit: if (wnd) XDestroyWindow( dspy, wnd ); if (visi) XFree(visi); if (pBmp) DestroyBitmap( pBmp ); return 0; }
int main (int argc, char** argv) { // 1. X stuff //1.1 X display g_xdisplay = XOpenDisplay (NULL); if (g_xdisplay == NULL) { return EGL_FALSE; } g_xroot = DefaultRootWindow (g_xdisplay); //1.2 X window XSetWindowAttributes swa; swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask; g_xwindow = XCreateWindow (g_xdisplay, g_xroot, 0, 0, g_xwindow_width, g_xwindow_height, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &swa); XSetWindowAttributes xattr; xattr.override_redirect = 0; XChangeWindowAttributes (g_xdisplay, g_xwindow, CWOverrideRedirect, &xattr); XWMHints hints; hints.input = 1; hints.flags = InputHint; XSetWMHints(g_xdisplay, g_xwindow, &hints); XMapWindow (g_xdisplay, g_xwindow); XStoreName (g_xdisplay, g_xwindow, g_xwindow_title); Atom wm_state; wm_state = XInternAtom (g_xdisplay, "_NET_WM_STATE", 0); // 2. EGL stuff // 2.1 egl display. g_egldisplay = eglGetDisplay ((EGLNativeDisplayType)g_egldisplay); if (g_egldisplay == EGL_NO_DISPLAY) { return EGL_FALSE; } // 2.2 Initialize EGL EGLint major_version; EGLint minor_version; if (!eglInitialize (g_egldisplay, &major_version, &minor_version)) { return EGL_FALSE; } // 2.3 configuration management EGLint num_configs; EGLint attrib_list[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6, EGL_BLUE_SIZE, 5, EGL_NONE }; if (!eglGetConfigs (g_egldisplay, NULL, 0, &num_configs)) { return EGL_FALSE; } if (!eglChooseConfig (g_egldisplay, attrib_list, &g_eglconfig, 1, &num_configs)) { return EGL_FALSE; } // 2.4 surface creation g_eglsurface = eglCreateWindowSurface (g_egldisplay, g_eglconfig, (EGLNativeWindowType)g_xwindow, NULL); if (g_eglsurface == EGL_NO_SURFACE) { return EGL_FALSE; } // 2.5 Create a GL context EGLint context_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; g_eglcontext = eglCreateContext (g_egldisplay, g_eglconfig, EGL_NO_CONTEXT, context_attribs); if (g_eglcontext == EGL_NO_CONTEXT) { return EGL_FALSE; } // 2.6 Make the context current if (!eglMakeCurrent(g_egldisplay, g_eglsurface, g_eglsurface, g_eglcontext)) { return EGL_FALSE; } //3. init graphics pipeline. if (!init_pipeline ()) return GL_FALSE; //4. Main Loop int state = 1; XEvent xev; while (state) { XNextEvent (g_xdisplay, &xev); switch (xev.type) { case Expose: draw_geometry (); break; case DestroyNotify: state = 0; break; default: draw_geometry (); break; } // we must call eglSwapBuffers to show the back buffer. eglSwapBuffers (g_egldisplay, g_eglsurface); } }
GL_Window::GL_Window(int w, int h) { int width = w; int height = h; XSetWindowAttributes swa; x_display = XOpenDisplay(NULL); DefaultScreen(x_display); root = DefaultRootWindow(x_display); swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | ButtonPressMask | MotionNotify | ButtonReleaseMask | StructureNotifyMask; win = XCreateWindow(x_display, root, 0, 0, width, height, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &swa); // handle window close correctly XMapWindow(x_display, win); Atom delmsg = XInternAtom(x_display, "WM_DELETE_WINDOW", False); XSetWMProtocols(x_display, win, &delmsg, 1); // limit resize to 16:9 ratio XSizeHints *hints = XAllocSizeHints(); hints->flags |= PAspect; hints->min_aspect.x = 16; hints->min_aspect.y = 9; hints->max_aspect.x = 16; hints->max_aspect.y = 9; XSetWMNormalHints(x_display, win, hints); XFree(hints); // EGL stuff EGLint major, minor; EGLint numConfigs; EGLConfig config; const EGLint configAttribs[] = { EGL_RENDERABLE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_NONE }; const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; display = eglGetDisplay((EGLNativeDisplayType)x_display); eglInitialize(display, &major, &minor); eglChooseConfig(display, configAttribs, &config, 1, &numConfigs); surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)win, NULL); context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs); eglMakeCurrent(display, surface, surface, context); }
void map_mw(t_x11 *x11,t_molwin *mw) { XMapWindow(x11->disp,mw->wd.self); }
/* * Vytvoøit a namapovat top-level okno, vytvoøit dal¹í zdroje (napø. GC) */ static void create_resources(int argc, char *argv[]) { XWMHints *wm_hints; /* Doporuèení pro window manager */ XSizeHints *size_hints; /* Doporuèená velikost okna */ XClassHint *class_hint; /* Jméno a tøída pro resource manager */ XTextProperty window_name, icon_name; /* Jména pro window manager */ XGCValues gc_values; /* Hodnoty pro nastavení GC */ char *str_window_name = (char *)"Hello Window"; /* Titulek okna */ char *str_icon_name = (char *)"Hello Icon"; /* Titulek ikony */ /* Vytvoøit top-level okno */ topwin_x = topwin_y = 0; /* Okno umístí window manager */ topwin_w = screen_width / 2; topwin_h = screen_height / 2; topwin_b = 0; topwin = XCreateSimpleWindow(display, root, topwin_x, topwin_y, topwin_w, topwin_h, topwin_b, black, white); debug("Created top-level window ID %#lx\n", topwin); /* Vytvoøit ikonu pro top-level okno */ topwin_icon = XCreateBitmapFromData(display, topwin, Xlib_icon_bits, Xlib_icon_width, Xlib_icon_height); debug("Created icon %#lx for top-level window\n", topwin_icon); /* Nastavit properties pro window manager */ if(!(size_hints = XAllocSizeHints()) || !(wm_hints = XAllocWMHints()) || !(class_hint = XAllocClassHint())) { fprintf(stderr, "Cannot allocate memory\n"); exit(1); } /* Poloha a velikost se bere ze skuteèných hodnot okna v oka¾iku * namapování. PPosition | PSize øíká, ¾e hodnoty nastavil program (a * window manager je mù¾e mìnit podle potøeby). USSize | USPosition by * znamenalo, ¾e hodnoty zadal u¾ivatel (napø. na pøíkazové øádce) a * window manager by je nemìl mìnit. */ size_hints->flags = PPosition | PSize | PMinSize; /* Window manager by nemìl okno nikdy zmen¹it na ménì ne¾ * min_width x min_height pixelù. */ size_hints->min_width = 200; size_hints->min_height = 100; wm_hints->initial_state = NormalState;/* Na zaèátku má být zobrazeno normální okno (ne ikona) */ wm_hints->input = True; /* Aplikace potøebuje vstup z klávesnice */ wm_hints->icon_pixmap = topwin_icon; wm_hints->flags = StateHint | InputHint | IconPixmapHint; /* Ulo¾ení jména okna a ikony */ if(!XStringListToTextProperty(&str_window_name, 1, &window_name) || !XStringListToTextProperty(&str_icon_name, 1, &icon_name)) { fprintf(stderr, "XStringListToTextProperty() for failed\n"); exit(1); } /* Jméno programu a tøídy pro hledání v resource databázi */ class_hint->res_name = progname; class_hint->res_class = (char *) "HelloWorld"; /* Nastavit v¹echny properties */ XSetWMProperties(display, topwin, &window_name, &icon_name, argv, argc, size_hints, wm_hints, class_hint); /* Vybrat události pro top-level okno */ XSelectInput(display, topwin, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); /* Vytvoøit GC */ gc_values.background = white; gc_values.foreground = black; my_gc = XCreateGC(display, topwin, GCBackground | GCForeground, &gc_values); XCopyGC(display, def_gc, GCFont, my_gc); /* default font */ /* Získat atomy */ targets = XInternAtom(display, "TARGETS", False); sel_prop = XInternAtom(display, "SEL_PROP", False); /* Namapovat top-level okno */ XMapWindow(display, topwin); }
static struct DriverInstance* X11_new_instance(const char* server_name, int xpos, int ypos, int width, int height, int mmx_supported, char* error_text, int text_len) { struct DriverInstance* sh = (struct DriverInstance*) malloc(sizeof(*sh)); int screen; int err; const char* server_name_ptr; if (width > MAX_RES_X || height > MAX_RES_Y) { snprintf(error_text, text_len, "Max resolution (%ix%i) exceeded by given resolution (%i,%i)", MAX_RES_X, MAX_RES_Y, width, height); free(sh); return 0; } sh->mmx_supported = mmx_supported; sh->width = width; sh->height = height; sh->used_extensions = 0; sh->data = 0; sh->data_size = 0; sh->ximage = 0; sh->image_width = 0; sh->image_height = 0; sh->shminfo.shmaddr = 0; sh->xv_port = 0xffffffff; sh->xv_format_id = -1; sh->xv_image = 0; if (strcmp(server_name,"default") == 0) server_name_ptr = getenv("DISPLAY"); //use the DISPLAY environment variable else server_name_ptr = server_name; // use the userdefined display if (server_name_ptr == 0) { snprintf(error_text, text_len, "Don't know which display to use. Set the DISPLAY variable!"); free(sh); return 0; } DEBUG_PRINTF("x11output: Connecting to '%s'...\n", server_name_ptr); sh->display = XOpenDisplay(server_name_ptr); if (sh->display == NULL) { snprintf(error_text, text_len, "Cannot connect to X server '%s'", server_name); free(sh); return 0; } if (check_xshm_extension(sh->display)) { if (init_xshm_stuff(sh, error_text, text_len) != 0) sh->used_extensions |= USE_XSHM; else printf(" x11output: could not init XShm: '%s', turning off xshm\n", error_text); } if (check_xv_extension(sh->display)) { sh->used_extensions |= USE_XV; } screen = DefaultScreen(sh->display); sh->win = XCreateSimpleWindow(sh->display, RootWindow(sh->display, screen), xpos, ypos, width, height, 0, BlackPixel(sh->display, screen), WhitePixel(sh->display, screen)); //TODO: error handling XMapWindow(sh->display, sh->win); sh->gc = XCreateGC(sh->display, sh->win, 0, NULL); err = find_best_visual(sh->display, &sh->vis); if (err) { snprintf(error_text, text_len, "Could not find matching visual\n" "XServer must be set up at 24 bit depth or 16 bit depth"); XDestroyWindow(sh->display, sh->win); deinit_xv_stuff(sh); free(sh); return 0; } if (sh->vis.depth == 16) { printf(" x11output: Screen set to 16bit color-depth. You might want to " "switch\n to 24bit for better performance\n"); } if ((sh->used_extensions & USE_XV) == USE_XV) { if (init_xv_stuff(sh, error_text, text_len) == 0) { printf(" x11output: turning off Xv support: '%s'\n", error_text); sh->used_extensions &= ~USE_XV; } } if ((sh->used_extensions & USE_XSHM) == USE_XSHM) { if ((sh->used_extensions & USE_XV) == 0) { /* create shared memory ximage */ sh->ximage = XShmCreateImage (sh->display, sh->vis.visual, sh->vis.depth, ZPixmap, 0, &sh->shminfo, width, height); if (sh->ximage == 0) { snprintf(error_text, text_len, "Could not create xshm image"); deinit_xv_stuff(sh); deinit_xshm_stuff(sh); XDestroyWindow(sh->display, sh->win); free(sh); return 0; } sh->ximage->data = sh->shminfo.shmaddr; } } if (sh->used_extensions & USE_XV) printf(" x11output: using Xv extension\n"); if (sh->used_extensions & USE_XSHM) printf(" x11output: using XShm extension\n"); XFlush( sh->display ); return sh; }
/** * Flashes one entire screen. This is done by making a window the size of the * whole screen (or reusing the old one, if it's still around), mapping it, * painting it white and then black, and then unmapping it. We set saveunder so * that all the windows behind it come back immediately. * * Unlike frame flashes, we don't do fullscreen flashes with a timeout; rather, * we do them in one go, because we don't have to rely on the theme code * redrawing the frame for us in order to do the flash. * * \param display The display which owns the screen (rather redundant) * \param screen The screen to flash * * \bug The way I read it, this appears not to do the flash * the first time we flash a particular display. Am I wrong? * * \bug This appears to destroy our current XSync status. */ static void bell_flash_screen (MetaDisplay *display, MetaScreen *screen) { Window root = screen->xroot; int width = screen->rect.width; int height = screen->rect.height; if (screen->flash_window == None) { Visual *visual = (Visual *)CopyFromParent; XSetWindowAttributes xswa; int depth = CopyFromParent; xswa.save_under = True; xswa.override_redirect = True; /* * TODO: use XGetVisualInfo and determine which is an * overlay, if one is present, and use the Overlay visual * for this window (for performance reasons). * Not sure how to tell this yet... */ screen->flash_window = XCreateWindow (display->xdisplay, root, 0, 0, width, height, 0, depth, InputOutput, visual, /* note: XSun doesn't like SaveUnder here */ CWSaveUnder | CWOverrideRedirect, &xswa); XSelectInput (display->xdisplay, screen->flash_window, ExposureMask); XMapWindow (display->xdisplay, screen->flash_window); XSync (display->xdisplay, False); XFlush (display->xdisplay); XUnmapWindow (display->xdisplay, screen->flash_window); } else { /* just draw something in the window */ GC gc = XCreateGC (display->xdisplay, screen->flash_window, 0, NULL); XMapWindow (display->xdisplay, screen->flash_window); XSetForeground (display->xdisplay, gc, WhitePixel (display->xdisplay, XScreenNumberOfScreen (screen->xscreen))); XFillRectangle (display->xdisplay, screen->flash_window, gc, 0, 0, width, height); XSetForeground (display->xdisplay, gc, BlackPixel (display->xdisplay, XScreenNumberOfScreen (screen->xscreen))); XFillRectangle (display->xdisplay, screen->flash_window, gc, 0, 0, width, height); XFlush (display->xdisplay); XSync (display->xdisplay, False); XUnmapWindow (display->xdisplay, screen->flash_window); XFreeGC (display->xdisplay, gc); } if (meta_prefs_get_focus_mode () != G_DESKTOP_FOCUS_MODE_CLICK && !display->mouse_mode) meta_display_increment_focus_sentinel (display); XFlush (display->xdisplay); }
static EGLBoolean egl_manager_create_window(struct egl_manager *eman, const char *name, EGLint w, EGLint h, EGLBoolean need_surface, EGLBoolean fullscreen, const EGLint *attrib_list) { XVisualInfo vinfo_template, *vinfo = NULL; EGLint val, num_vinfo; Window root; XSetWindowAttributes attrs; unsigned long mask; EGLint x = 0, y = 0; if (!eglGetConfigAttrib(eman->dpy, eman->conf, EGL_NATIVE_VISUAL_ID, &val)) { printf("eglGetConfigAttrib() failed\n"); return EGL_FALSE; } if (val) { vinfo_template.visualid = (VisualID) val; vinfo = XGetVisualInfo(eman->xdpy, VisualIDMask, &vinfo_template, &num_vinfo); } /* try harder if window surface is not needed */ if (!vinfo && !need_surface && eglGetConfigAttrib(eman->dpy, eman->conf, EGL_BUFFER_SIZE, &val)) { if (val == 32) val = 24; vinfo_template.depth = val; vinfo = XGetVisualInfo(eman->xdpy, VisualDepthMask, &vinfo_template, &num_vinfo); } if (!vinfo) { printf("XGetVisualInfo() failed\n"); return EGL_FALSE; } root = DefaultRootWindow(eman->xdpy); if (fullscreen) { x = y = 0; w = DisplayWidth(eman->xdpy, DefaultScreen(eman->xdpy)); h = DisplayHeight(eman->xdpy, DefaultScreen(eman->xdpy)); } /* window attributes */ attrs.background_pixel = 0; attrs.border_pixel = 0; attrs.colormap = XCreateColormap(eman->xdpy, root, vinfo->visual, AllocNone); attrs.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; attrs.override_redirect = fullscreen; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; eman->xwin = XCreateWindow(eman->xdpy, root, x, y, w, h, 0, vinfo->depth, InputOutput, vinfo->visual, mask, &attrs); XFree(vinfo); /* set hints and properties */ { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = w; sizehints.height = h; sizehints.flags = USSize | USPosition; XSetNormalHints(eman->xdpy, eman->xwin, &sizehints); XSetStandardProperties(eman->xdpy, eman->xwin, name, name, None, (char **)NULL, 0, &sizehints); } if (need_surface) { eman->win = eglCreateWindowSurface(eman->dpy, eman->conf, eman->xwin, attrib_list); if (eman->win == EGL_NO_SURFACE) { printf("eglCreateWindowSurface() failed\n"); XDestroyWindow(eman->xdpy, eman->xwin); eman->xwin = None; return EGL_FALSE; } } eman->gc = XCreateGC(eman->xdpy, eman->xwin, 0, NULL); XMapWindow(eman->xdpy, eman->xwin); return EGL_TRUE; }
int main(int argc, char *argv[]) { Display *display; int screen; Window window; XEvent event; /* open connection with the server */ display = XOpenDisplay(NULL); if (!display) { printf("Cannot open display\n"); exit(EXIT_FAILURE); } screen = DefaultScreen(display); /* create window */ window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 100, 100, 1, BlackPixel(display, screen), WhitePixel(display, screen)); /* select kind of events we are interested in */ XSelectInput(display, window, ExposureMask | KeyPressMask); /* map (show) the window */ XMapWindow(display, window); int i = 0; char buffer[127]; XWindowAttributes winInfos; /* event loop */ while (1) { XNextEvent(display, &event); /* draw or redraw the window */ //if (event.type == Expose) { XGetWindowAttributes(display, window, &winInfos); XFillRectangle( display, window, DefaultGC(display, screen), 20, 20, 10, 10); sprintf(buffer, "width=%d", winInfos.width); XDrawString( display, window, DefaultGC(display, screen), winInfos.width / 2, 10, buffer, strlen(buffer)); sprintf(buffer, "height=%d", winInfos.height); XDrawString( display, window, DefaultGC(display, screen), 0, winInfos.height / 2, buffer, strlen(buffer)); } /* exit on key press */ if (event.type == KeyPress) break; } /* close connection to server */ XCloseDisplay(display); return EXIT_SUCCESS; }