static Window CreateWindow(Display *dpy, XVisualInfo *visinfo, int width, int height, const char *name) { int screen = DefaultScreen(dpy); Window win; XSetWindowAttributes attr; unsigned long mask; Window root; root = RootWindow(dpy, screen); /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); if (win) { XSizeHints sizehints; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize; XSetNormalHints(dpy, win, &sizehints); XSetStandardProperties(dpy, win, name, name, None, (char **)NULL, 0, &sizehints); XMapWindow(dpy, win); } return win; }
int XSetStandardProperties ( Display *dpy, Window w, /* window to decorate */ _Xconst char *name, /* name of application */ _Xconst char *icon_string,/* name string for icon */ Pixmap icon_pixmap, /* pixmap to use as icon, or None */ char **argv, /* command to be used to restart application */ int argc, /* count of arguments */ XSizeHints *hints) /* size hints for window in its normal state */ { XWMHints phints; phints.flags = 0; if (name != NULL) XStoreName (dpy, w, name); if (icon_string != NULL) { XChangeProperty (dpy, w, XA_WM_ICON_NAME, XA_STRING, 8, PropModeReplace, (unsigned char *)icon_string, safestrlen(icon_string)); } if (icon_pixmap != None) { phints.icon_pixmap = icon_pixmap; phints.flags |= IconPixmapHint; } if (argv != NULL) XSetCommand(dpy, w, argv, argc); if (hints != NULL) XSetNormalHints(dpy, w, hints); if (phints.flags != 0) XSetWMHints(dpy, w, &phints); return 1; }
uintptr_t doNewWindow(int width, int height) { XSetWindowAttributes attr; attr.colormap = x_colormap; attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | StructureNotifyMask | FocusChangeMask; Window win = XCreateWindow( x_dpy, x_root, 0, 0, width, height, 0, x_visual_info->depth, InputOutput, x_visual_info->visual, CWColormap | CWEventMask, &attr); XSizeHints sizehints; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize; XSetNormalHints(x_dpy, win, &sizehints); Atom atoms[2]; atoms[0] = wm_delete_window; atoms[1] = wm_take_focus; XSetWMProtocols(x_dpy, win, atoms, 2); XSetStandardProperties(x_dpy, win, "App", "App", None, (char **)NULL, 0, &sizehints); return win; }
int main() { auto display = XOpenDisplay(NULL); auto screen = DefaultScreen(display); auto depth = DefaultDepth(display, screen); XSetWindowAttributes attributes; attributes.border_pixel = BlackPixel(display,screen); attributes.background_pixel = WhitePixel(display,screen); attributes.override_redirect = True; auto window = XCreateWindow( display, RootWindow(display, screen), 0,0,1280,720, 2,depth, InputOutput, CopyFromParent, CWBackPixel|CWBorderPixel|CWOverrideRedirect, &attributes); XSizeHints size_hints; size_hints.flags = PPosition | PSize; size_hints.x = 0; size_hints.y = 0; size_hints.width = 1280; size_hints.height = 720; XSetNormalHints(display, window, &size_hints); XMapWindow(display, window); XFlush(display); while(true) {} return 0; }
XxWindow::XxWindow ( EzString Name , XxWindow *Parent , int XPos, int YPos, int Width, int Height , EzString Title ) : XxDrawable (Name), Member (this), WindowsMember (this) { Window XxParentWindow; Atom atom; XxWindow::Parent = Parent; Hints.x = XPos; Hints.y = YPos; Hints.width = Width; Hints.height = Height; XxAttrs.event_mask = ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask; XxAttrMask = CWEventMask; WindowsMember.Attach (WindowsOwner); if (Parent != NULL) Member.Attach (Parent->Owner); XxParentWindow = (Parent == NULL ? GetRootWindow () : Parent->Xid); Xid = XCreateWindow ( GetDisplay (), XxParentWindow , Hints.x, Hints.y, Hints.width, Hints.height , 0, GetDepth () , InputOutput, CopyFromParent , XxAttrMask, &XxAttrs); XxAttrMask = 0; Hints.max_width = Width; Hints.max_height = Height; Hints.min_width = Width; Hints.min_height = Height; Hints.flags = PMinSize | PMaxSize | PPosition | PSize; XSetNormalHints (GetDisplay (), Xid, &Hints); // XStoreName (GetDisplay (), Xid, "Test"); XMapRaised (GetDisplay (), Xid); XSelectInput (GetDisplay (), Xid, XxAttrs.event_mask); if (Parent == NULL) { atom = GetWmDeleteWindow (); XStoreName (GetDisplay (), Xid, Title); XSetWMProtocols (GetDisplay (), Xid, &atom, 1); }; };
void _eglutNativeInitWindow(struct eglut_window *win, const char *title, int x, int y, int w, int h) { XVisualInfo *visInfo, visTemplate; int num_visuals; Window root, xwin; XSetWindowAttributes attr; unsigned long mask; EGLint vid; if (!eglGetConfigAttrib(_eglut->dpy, win->config, EGL_NATIVE_VISUAL_ID, &vid)) _eglutFatal("failed to get visual id"); /* The X window visual must match the EGL config */ visTemplate.visualid = vid; visInfo = XGetVisualInfo(_eglut->native_dpy, VisualIDMask, &visTemplate, &num_visuals); if (!visInfo) _eglutFatal("failed to get an visual of id 0x%x", vid); root = RootWindow(_eglut->native_dpy, DefaultScreen(_eglut->native_dpy)); /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(_eglut->native_dpy, root, visInfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; xwin = XCreateWindow(_eglut->native_dpy, root, x, y, w, h, 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr); if (!xwin) _eglutFatal("failed to create a window"); XFree(visInfo); /* set hints and properties */ { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = w; sizehints.height = h; sizehints.flags = USSize | USPosition; XSetNormalHints(_eglut->native_dpy, xwin, &sizehints); XSetStandardProperties(_eglut->native_dpy, xwin, title, title, None, (char **) NULL, 0, &sizehints); } XMapWindow(_eglut->native_dpy, xwin); win->native.u.window = xwin; win->native.width = w; win->native.height = h; }
static Window make_rgb_db_window( Display *dpy, int xpos, int ypos, unsigned int width, unsigned int height ) { int attrib[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; GLXContext ctx; XVisualInfo *visinfo; scrnum = DefaultScreen( dpy ); root = RootWindow( dpy, scrnum ); visinfo = glXChooseVisual( dpy, scrnum, attrib ); if (!visinfo) { printf("Error: couldn't get an RGB, Double-buffered visual\n"); exit(1); } /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( dpy, root, 0, 0, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr ); { XSizeHints sizehints; sizehints.x = xpos; sizehints.y = ypos; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(dpy, win, &sizehints); XSetStandardProperties(dpy, win, ProgramName, ProgramName, None, (char **)NULL, 0, &sizehints); } ctx = glXCreateContext( dpy, visinfo, NULL, True ); glXMakeCurrent( dpy, win, ctx ); return win; }
pxError pxWindow::init(int left, int top, int width, int height) { Window rootwin; int scr; Display* dpy = mDisplayRef.getDisplay(); scr = DefaultScreen(dpy); rootwin = RootWindow(dpy, scr); win=XCreateSimpleWindow(dpy, rootwin, left, top, width, height, 0, BlackPixel(dpy, scr), BlackPixel(dpy, scr)); if (win) { XSizeHints size_hints ; size_hints.flags = PPosition ; size_hints.x = left ; size_hints.y = top ; XSetNormalHints( dpy, win, &size_hints) ; XWindowAttributes attr; XGetWindowAttributes(dpy, win, &attr); this->onSize(attr.width, attr.height); XSelectInput(dpy, win, PointerMotionMask| ExposureMask| ButtonPressMask|ButtonReleaseMask| KeyPressMask|KeyReleaseMask | StructureNotifyMask | LeaveWindowMask ); registerWindow(win, this); XSetWindowBackgroundPixmap(dpy, win, None); closeatom = XInternAtom(dpy, "WM_DELETE_WINDOW", false); XSetWMProtocols(dpy, win, &closeatom, 1); this->onCreate(); } return win?PX_OK:PX_FAIL; }
EglDrawable(const Visual *vis, int w, int h, bool pbuffer) : Drawable(vis, w, h, pbuffer), api(EGL_OPENGL_ES_API) { XVisualInfo *visinfo = static_cast<const EglVisual *>(visual)->visinfo; Window root = RootWindow(display, screen); /* window attributes */ XSetWindowAttributes attr; attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask; unsigned long mask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; int x = 0, y = 0; window = XCreateWindow( display, root, x, y, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(display, window, &sizehints); const char *name = "glretrace"; XSetStandardProperties( display, window, name, name, None, (char **)NULL, 0, &sizehints); eglWaitNative(EGL_CORE_NATIVE_ENGINE); EGLConfig config = static_cast<const EglVisual *>(visual)->config; surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL); }
// Create an X11 window to render in. This is only used by testing void X11Device::createWindow(const char *name, int x, int y, int width, int height) { GNASH_REPORT_FUNCTION; if (!_display) { log_error("No Display device set!"); return; } if (!_root) { log_error("No drawable window set!"); return; } XSetWindowAttributes attr; unsigned long mask; // Window root; // XVisualInfo visTemplate; // int num_visuals; // window attributes attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(_display, _root, _vinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; _window = XCreateWindow(_display, _root, 0, 0, width, height, 0, _vinfo->depth, InputOutput, _vinfo->visual, mask, &attr); // set hints and properties XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(_display, _window, &sizehints); XSetStandardProperties(_display, _window, name, name, None, (char **)NULL, 0, &sizehints); XMapWindow(_display, _window); }
Window createWindow(XVisualInfo *visinfo, const char *name, int width, int height) { Window root = RootWindow(display, screen); /* window attributes */ XSetWindowAttributes attr; attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | KeyPressMask; unsigned long mask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; int x = 0, y = 0; Window window = XCreateWindow( display, root, x, y, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(display, window, &sizehints); XSetStandardProperties( display, window, name, name, None, (char **)NULL, 0, &sizehints); XSync(display, False); return window; }
void unlock_window_size (void) { XSizeHints sizehint; sizehint.x = winX - 100; sizehint.y = winY; sizehint.width = display.winW; sizehint.height = display.winH; sizehint.min_width = display.winW; sizehint.min_height = display.winH; sizehint.max_width = display.winW; sizehint.max_height = display.winH; sizehint.flags = USPosition | USSize | PMinSize; XSetNormalHints (display.dpy, display.win, &sizehint); }
GlxDrawable(const Visual *vis, int w, int h, bool pbuffer) : Drawable(vis, w, h, pbuffer) { XVisualInfo *visinfo = static_cast<const GlxVisual *>(visual)->visinfo; Window root = RootWindow(display, screen); /* window attributes */ XSetWindowAttributes attr; attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | KeyPressMask; unsigned long mask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; int x = 0, y = 0; window = XCreateWindow( display, root, x, y, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(display, window, &sizehints); const char *name = "glretrace"; XSetStandardProperties( display, window, name, name, None, (char **)NULL, 0, &sizehints); glXWaitX(); }
static Window make_gl_window(Display *dpy, XVisualInfo *visinfo, int width, int height) { int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; int x = 0, y = 0; char *name = NULL; scrnum = DefaultScreen( dpy ); root = RootWindow( dpy, scrnum ); /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( dpy, root, x, y, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr ); /* set hints and properties */ { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(dpy, win, &sizehints); XSetStandardProperties(dpy, win, name, name, None, (char **)NULL, 0, &sizehints); } return win; }
/* * Create an RGB, double-buffered X window. * Return the window and context handles. */ static void make_x_window(Display *x_dpy, EGLDisplay egl_dpy, const char *name, int x, int y, int width, int height, Window *winRet, EGLContext *ctxRet, EGLSurface *surfRet) { static const EGLint attribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; XVisualInfo *visInfo, visTemplate; int num_visuals; EGLContext ctx; EGLConfig config; EGLint num_configs; EGLint vid; scrnum = DefaultScreen( x_dpy ); root = RootWindow( x_dpy, scrnum ); if (!eglChooseConfig( egl_dpy, attribs, &config, 1, &num_configs)) { printf("Error: couldn't get an EGL visual config\n"); exit(1); } assert(config); assert(num_configs > 0); if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { printf("Error: eglGetConfigAttrib() failed\n"); exit(1); } /* The X window visual must match the EGL config */ visTemplate.visualid = vid; visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); if (!visInfo) { printf("Error: couldn't get X visual\n"); exit(1); } /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( x_dpy, root, visInfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow( x_dpy, root, 0, 0, width, height, 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr ); /* set hints and properties */ { XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(x_dpy, win, &sizehints); XSetStandardProperties(x_dpy, win, name, name, None, (char **)NULL, 0, &sizehints); } eglBindAPI(EGL_OPENGL_ES_API); ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); if (!ctx) { printf("Error: eglCreateContext failed\n"); exit(1); } /* test eglQueryContext() */ { EGLint val; eglQueryContext(egl_dpy, ctx, EGL_CONTEXT_CLIENT_VERSION, &val); assert(val == 2); } *surfRet = eglCreateWindowSurface(egl_dpy, config, win, NULL); if (!*surfRet) { printf("Error: eglCreateWindowSurface failed\n"); exit(1); } /* sanity checks */ { EGLint val; eglQuerySurface(egl_dpy, *surfRet, EGL_WIDTH, &val); assert(val == width); eglQuerySurface(egl_dpy, *surfRet, EGL_HEIGHT, &val); assert(val == height); assert(eglGetConfigAttrib(egl_dpy, config, EGL_SURFACE_TYPE, &val)); assert(val & EGL_WINDOW_BIT); } XFree(visInfo); *winRet = win; *ctxRet = ctx; }
void xskin_start_interface( int pipe_in ) { int xskin_sc; XEvent xskin_e; XSetWindowAttributes xskin_attr; XSizeHints xskin_hint; XClassHint xskin_chint; XTextProperty ct; char *namlist[2]; /* setup window */ xskin_d = XOpenDisplay( NULL ); xskin_sc = DefaultScreen( xskin_d ); xskin_r = RootWindow( xskin_d, xskin_sc ); xskin_gc = DefaultGC( xskin_d, xskin_sc ); xskin_vis = DefaultVisual( xskin_d, xskin_sc ); xskin_depth = DefaultDepth( xskin_d, xskin_sc ); xskin_w = XCreateSimpleWindow( xskin_d, xskin_r, 0, 0, skin_width, skin_height, 0, WhitePixel( xskin_d, xskin_sc ), BlackPixel( xskin_d, xskin_sc ) ); xskin_attr.backing_store = True; xskin_attr.override_redirect = False; XChangeWindowAttributes( xskin_d, xskin_w, CWBackingStore|CWOverrideRedirect, &xskin_attr ); XSelectInput( xskin_d, xskin_w, KeyPressMask|ExposureMask| EnterWindowMask|LeaveWindowMask| ButtonPressMask|ButtonReleaseMask| Button1MotionMask ); xskin_hint.flags = USSize | PMinSize | PMaxSize | USPosition; xskin_hint.width = xskin_hint.min_width = xskin_hint.max_width = skin_width; xskin_hint.height = xskin_hint.min_height = xskin_hint.max_height = skin_height; XSetNormalHints( xskin_d, xskin_w, &xskin_hint ); xskin_chint.res_name = XSKIN_RES_NAME; xskin_chint.res_class = XSKIN_RES_CLASS; XSetClassHint( xskin_d, xskin_w, &xskin_chint ); namlist[0]=(char *)safe_malloc(strlen(XSKIN_WINDOW_NAME)+1); strcpy( namlist[0], XSKIN_WINDOW_NAME ); XmbTextListToTextProperty( xskin_d, namlist, 1, XCompoundTextStyle, &ct ); XSetWMName( xskin_d, xskin_w, &ct ); XSetWMIconName( xskin_d, xskin_w, &ct ); free(namlist[0]); /* setup pixmaps */ if ( load_skins()!=0 ) goto finish; XSetWindowBackgroundPixmap( xskin_d, xskin_w, xskin_back ); XClearWindow( xskin_d, xskin_w ); XMapWindow( xskin_d, xskin_w ); while( 1 ) { XNextEvent( xskin_d, &xskin_e ); if ( xskin_e.type == Expose ) break; } fshuf=0; frep=0; fequ=1; fpll=1; fplay=0; fpause=0; fremain=0; play_val=1; vol_val=50; last_current_time=0; total_time=0; speana_buf = NULL; strcpy( last_text, "welcome to timidity" ); install_sighandler(); repaint(); ts_spectrum( -1, speana_buf ); XFlush(xskin_d); xskin_jobs( pipe_in ); /* tskin main jobs */ finish: signal_vector(0); /* finish */ }
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[] = "N-Body Simulation", *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; }
int puglCreateWindow(PuglView* view, const char* title) { PuglInternals* const impl = view->impl; impl->display = XOpenDisplay(NULL); impl->screen = DefaultScreen(impl->display); XVisualInfo* const vi = getVisual(view); if (!vi) { XCloseDisplay(impl->display); impl->display = NULL; return 1; } #ifdef PUGL_HAVE_GL int glxMajor, glxMinor; glXQueryVersion(impl->display, &glxMajor, &glxMinor); PUGL_LOGF("GLX Version %d.%d\n", glxMajor, glxMinor); #endif Window xParent = view->parent ? (Window)view->parent : RootWindow(impl->display, impl->screen); Colormap cmap = XCreateColormap( impl->display, xParent, vi->visual, AllocNone); XSetWindowAttributes attr; memset(&attr, 0, sizeof(XSetWindowAttributes)); attr.background_pixel = BlackPixel(impl->display, impl->screen); attr.border_pixel = BlackPixel(impl->display, impl->screen); attr.colormap = cmap; attr.event_mask = (ExposureMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask); impl->win = XCreateWindow( impl->display, xParent, 0, 0, view->width, view->height, 0, vi->depth, InputOutput, vi->visual, CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &attr); if (!createContext(view, vi)) { XDestroyWindow(impl->display, impl->win); impl->win = 0; XCloseDisplay(impl->display); impl->display = NULL; return 1; } XSizeHints sizeHints; memset(&sizeHints, 0, sizeof(sizeHints)); if (!view->resizable) { sizeHints.flags = PMinSize|PMaxSize; sizeHints.min_width = view->width; sizeHints.min_height = view->height; sizeHints.max_width = view->width; sizeHints.max_height = view->height; XSetNormalHints(impl->display, impl->win, &sizeHints); } else if (view->min_width > 0 && view->min_height > 0) { sizeHints.flags = PMinSize; sizeHints.min_width = view->min_width; sizeHints.min_height = view->min_height; XSetNormalHints(impl->display, impl->win, &sizeHints); } if (title) { XStoreName(impl->display, impl->win, title); } if (!view->parent) { Atom wmDelete = XInternAtom(impl->display, "WM_DELETE_WINDOW", True); XSetWMProtocols(impl->display, impl->win, &wmDelete, 1); } if (glXIsDirect(impl->display, impl->ctx)) { PUGL_LOG("DRI enabled (to disable, set LIBGL_ALWAYS_INDIRECT=1\n"); } else { PUGL_LOG("No DRI available\n"); } XFree(vi); return PUGL_SUCCESS; }
int openwindow(int swidth,int sheight) { static int firsttime = 1; void initX(),beep(); int createGC(Window,GC*); XSetWindowAttributes theWindowAttributes; XSizeHints theSizeHints; unsigned long theWindowMask; if(firsttime) { firsttime = 0; initX(); } ww = swidth; wh = sheight; if(swidth <= 0) swidth = 10; if(sheight <= 0) sheight = 10; theWindowMask = CWBackPixel | CWBorderPixel | CWOverrideRedirect; theWindowAttributes.border_pixel = theBlackPixel = BlackPixel( theDisplay,theScreen ); theWindowAttributes.background_pixel = theWhitePixel = WhitePixel( theDisplay,theScreen ); theWindowAttributes.override_redirect = False; theWindow = XCreateWindow(theDisplay, RootWindow(theDisplay,theScreen), orgx,orgy, swidth,sheight, BORDER_WIDTH, theDepth, InputOutput, CopyFromParent, theWindowMask, &theWindowAttributes); theSizeHints.flags = PPosition | PSize; theSizeHints.x = orgx; theSizeHints.y = orgy; theSizeHints.width = swidth; theSizeHints.height = sheight; XSetNormalHints( theDisplay, theWindow, &theSizeHints ); if (createGC(theWindow, &theGC) == 0 ) { XDestroyWindow(theDisplay, theWindow); beep(); return(0); } XMapWindow( theDisplay, theWindow ); XFlush( theDisplay ); getcolors(); return( 1 ); }
void dev_open( char *id ) { extern char *getenv(); static RGBPRIMS myprims = STDPRIMS; static int atlBest[] = {GLX_RGBA, GLX_RED_SIZE,8, GLX_GREEN_SIZE,8, GLX_BLUE_SIZE,8, GLX_DEPTH_SIZE,15, None}; char *ev; double gamval = GAMMA; RGBPRIMP dpri = stdprims; XSetWindowAttributes ourwinattr; XWMHints ourxwmhints; XSizeHints oursizhints; /* set quadtree globals */ qtMinNodesiz = 3; qtDepthEps = 0.07; /* 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); /* set gamma and tone mapping */ if ((ev = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL || (ev = getenv("DISPLAY_GAMMA")) != NULL) gamval = atof(ev); if ((ev = getenv("DISPLAY_PRIMARIES")) != NULL && sscanf(ev, "%f %f %f %f %f %f %f %f", &myprims[RED][CIEX],&myprims[RED][CIEY], &myprims[GRN][CIEX],&myprims[GRN][CIEY], &myprims[BLU][CIEX],&myprims[BLU][CIEY], &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) dpri = myprims; tmGlobal = tmInit(mytmflags(), dpri, gamval); if (tmGlobal == NULL) error(SYSTEM, "not enough memory in dev_open"); /* 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); /* set window manager hints */ ourxwmhints.flags = InputHint|IconPixmapHint; ourxwmhints.input = True; ourxwmhints.icon_pixmap = XCreateBitmapFromData(ourdisplay, gwind, x11icon_bits, x11icon_width, x11icon_height); XSetWMHints(ourdisplay, gwind, &ourxwmhints); oursizhints.min_width = MINWIDTH; oursizhints.min_height = MINHEIGHT; oursizhints.flags = PMinSize; XSetNormalHints(ourdisplay, gwind, &oursizhints); /* set GLX context */ glXMakeCurrent(ourdisplay, gwind, gctx); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_CULL_FACE); glMatrixMode(GL_PROJECTION); glOrtho(0., 1., 0., 1., -.01, 1.01); glTranslated(0., 0., -1.01); /* figure out sensible view */ pwidth = (double)DisplayWidthMM(ourdisplay, ourscreen) / DisplayWidth(ourdisplay, ourscreen); pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / DisplayHeight(ourdisplay, ourscreen); odev.v = stdview; odev.v.type = VT_PER; /* map the window */ XMapWindow(ourdisplay, gwind); dev_input(); /* sets size and view angles */ /* allocate our leaf pile */ if (!qtAllocLeaves(DisplayWidth(ourdisplay,ourscreen) * DisplayHeight(ourdisplay,ourscreen) * 3 / (qtMinNodesiz*qtMinNodesiz*2))) error(SYSTEM, "insufficient memory for value storage"); odev.name = id; odev.ifd = ConnectionNumber(ourdisplay); /* initialize cone array */ initcones(); }
static void make_window( Display *dpy, const char *name, int x, int y, int width, int height, Window *winRet, GLXContext *ctxRet) { int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; GLXContext ctx; XVisualInfo *visinfo; scrnum = DefaultScreen( dpy ); root = RootWindow( dpy, scrnum ); // 3.2 support //#ifdef glXCreateContextAttribsARB if (gContextVersionMajor > 2) { // We asked for OpenGL3+, but can we do it? typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); // Verify GL driver supports glXCreateContextAttribsARB() glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; // Verify that GLX implementation supports the new context create call if ( strstr( glXQueryExtensionsString( dpy, scrnum ), "GLX_ARB_create_context" ) != 0 ) glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddress( (const GLubyte *) "glXCreateContextAttribsARB" ); if ( !glXCreateContextAttribsARB ) { printf( "Can't create new-style GL context\n" ); } // We need this for OpenGL3 int elemc; GLXFBConfig *fbcfg; int attribs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, // ? GLX_RED_SIZE, 1, // 1 = prefer high precision GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None }; int i = 12; if (gMode & GLUT_DOUBLE) { attribs[i++] = GLX_DOUBLEBUFFER; attribs[i++] = 1; } if (gMode & GLUT_DEPTH) { attribs[i++] = GLX_DEPTH_SIZE; attribs[i++] = 1; } if (gMode & GLUT_STENCIL) { attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = 8; // Smallest available, at least 8. Configurable setting needed! } if (gMode & GLUT_MULTISAMPLE) { attribs[i++] = GLX_SAMPLE_BUFFERS; attribs[i++] = 1; attribs[i++] = GLX_SAMPLES; attribs[i++] = 4; } fbcfg = glXChooseFBConfig(dpy, scrnum, attribs, &elemc); if (!fbcfg) { fbcfg = glXChooseFBConfig(dpy, scrnum, NULL, &elemc); } if (!fbcfg) printf("Couldn't get FB configs\n"); int gl3attr[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, gContextVersionMajor, GLX_CONTEXT_MINOR_VERSION_ARB, gContextVersionMinor, // GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, None }; ctx = glXCreateContextAttribsARB(dpy, fbcfg[0], NULL, 1, gl3attr); if (ctx == NULL) printf("No ctx!\n"); visinfo = glXGetVisualFromFBConfig(dpy, fbcfg[0]); if (!visinfo) printf("Error: couldn't create OpenGL window with this pixel format.\n"); } else // old style //#endif { int attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, // 1 = prefer high precision GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None }; int i = 7; if (gMode & GLUT_DOUBLE) attribs[i++] = GLX_DOUBLEBUFFER; if (gMode & GLUT_DEPTH) { attribs[i++] = GLX_DEPTH_SIZE; attribs[i++] = 1; } if (gMode & GLUT_STENCIL) { attribs[i++] = GLX_STENCIL_SIZE; attribs[i++] = 8; // Smallest available, at least 8. Configurable setting needed! } visinfo = glXChooseVisual( dpy, scrnum, attribs ); if (!visinfo) { printf("Error: couldn't get a visual according to settings\n"); exit(1); } ctx = glXCreateContext( dpy, visinfo, 0, True ); if (ctx == NULL) printf("No ctx!\n"); } /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPress | ButtonReleaseMask | Button1MotionMask | PointerMotionMask; attr.override_redirect = 0; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect; win = XCreateWindow( dpy, root, x, y, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr ); // Register delete! wmDeleteMessage = XInternAtom(dpy, "WM_DELETE_WINDOW", False); XSetWMProtocols(dpy, win, &wmDeleteMessage, 1); // Register /* set hints and properties */ XSizeHints sizehints; sizehints.x = x; sizehints.y = y; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(dpy, win, &sizehints); XSetStandardProperties(dpy, win, name, name, None, (char **)NULL, 0, &sizehints); //text fontinfo = XLoadQueryFont(dpy,"6x10"); XAllocNamedColor(dpy, DefaultColormap(dpy, scrnum),"red", &color,&dummy); gr_values.font = fontinfo->fid; gr_values.foreground = color.pixel; gc=XCreateGC(dpy,win,GCFont+GCForeground, &gr_values); if (!ctx) { printf("Error: glXCreateContext failed\n"); exit(1); } XFree(visinfo); *winRet = win; *ctxRet = ctx; }
static void open_form_window(void) { int x, y, width, height; unsigned int fwidth = 0, fheight = 0; unsigned int xadder = 0, yadder = 0; /*char *window_name = "HyperDoc";*/ /*char *icon_name = "HT";*/ XrmValue value; char *str_type[50]; XSizeHints size_hints; int userSpecified = 0; char userdefaults[50], progdefaults[50]; strcpy(progdefaults, "=950x450+0+0"); if (XrmGetResource(rDB, "FriCAS.hyperdoc.FormGeometry", "FriCAS.hyperdoc.FormGeometry", str_type, &value) == True) { strncpy(userdefaults, value.addr, (int) value.size); userSpecified = 1; } else strcpy(userdefaults, progdefaults); XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults, 0, fwidth, fheight, xadder, yadder, &x, &y, &width, &height); gWindow->border_width = get_border_properties(); gWindow->width = 1; gWindow->height = 1; gWindow->fMainWindow = XCreateSimpleWindow(gXDisplay, RootWindow(gXDisplay, gXScreenNumber), x, y, width, height, gWindow->border_width, gBorderColor, WhitePixel(gXDisplay, gXScreenNumber)); gWindow->fScrollWindow = XCreateSimpleWindow(gXDisplay, gWindow->fMainWindow, 1, 1, 1, 1, 0, BlackPixel(gXDisplay, gXScreenNumber), WhitePixel(gXDisplay, gXScreenNumber)); makeScrollBarWindows(); makeTitleBarWindows(); set_name_and_icon(); XSelectInput(gXDisplay, gWindow->fScrollWindow, PointerMotionMask); XSelectInput(gXDisplay, gWindow->fMainWindow, StructureNotifyMask | PointerMotionMask); XDefineCursor(gXDisplay, gWindow->fMainWindow, gNormalCursor); /* now give the window manager some hints */ size_hints.flags = 0; size_hints.min_width = width; size_hints.min_height = height; size_hints.flags |= PMinSize; size_hints.width = width; size_hints.height = height; size_hints.flags |= (userSpecified ? USSize : PSize); size_hints.x = x; size_hints.y = y; size_hints.flags |= (userSpecified ? USPosition : PPosition); XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints); XFlush(gXDisplay); }
static void set_size_hints(Window w) { int x, y; unsigned int width, height; char userdefaults[50]; char progdefaults[50]; char *str_type[50]; unsigned int fwidth = 0, fheight = 0; unsigned int xadder = 0, yadder = 0; int geo = 0; /* return flag from XGetGeometry */ unsigned int depth, bw=0; Window root; XSizeHints size_hints; XPoint xp; XrmValue value; size_hints.flags = 0; strcpy(progdefaults, "=600x450+0+0"); if (w) { /* * The window should be queried for it's size and position. Then the * new window should be given almost the same locations */ if (XGetGeometry(gXDisplay, w, &root, &x, &y, &width, &height, &bw, &depth)) { xp = getWindowPositionXY(gXDisplay, w); x = xp.x + 40; y = xp.y + 40; if (x < 0) x = 0; if (y < 0) y = 0; size_hints.flags |= (USSize | USPosition); } else { fprintf(stderr, "(HyperDoc) Error Querying window configuration: %ld.\n", w); x = y = 0; width = 600; height = 450; size_hints.flags |= (PSize | PPosition); } } else { /* this is the first window, so lets try to find a nice spot for it */ if (XrmGetResource(rDB, "FriCAS.hyperdoc.Geometry", "FriCAS.hyperdoc.Geometry", str_type, &value) == True) { strncpy(userdefaults, value.addr, (int) value.size); geo = XParseGeometry(userdefaults, &x, &y, &width, &height); } else { strcpy(userdefaults, progdefaults); } size_hints.flags |= (geo & (WidthValue | HeightValue)) ? USSize : PSize; size_hints.flags |= (geo & (XValue | YValue)) ? USPosition : PPosition; geo = XGeometry(gXDisplay, gXScreenNumber, userdefaults, progdefaults, bw, fwidth, fheight, xadder, yadder, &x, &y, (int *)&width, (int *)&height); } size_hints.x = x; size_hints.y = y; size_hints.width = width; size_hints.height = height; getTitleBarMinimumSize(&(size_hints.min_width), &(size_hints.min_height)); #if 0 size_hints.min_width = MIN_WINDOW_SIZE; size_hints.min_height = MIN_WINDOW_SIZE; #endif size_hints.flags |= PMinSize; XSetNormalHints(gXDisplay, gWindow->fMainWindow, &size_hints); /* just in case a hint isn't enough ... */ XFlush(gXDisplay); /* XMoveResizeWindow(gXDisplay, gWindow->fMainWindow, x, y, width, height); */ }
window_t* window_create(unsigned int adapter, const char* title, size_t length, unsigned int width, unsigned int height, bool show) { FOUNDATION_UNUSED(length); Display* display = XOpenDisplay(0); if (!display) { log_error(HASH_WINDOW, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to open X display")); goto fail; } unsigned int screen = adapter; if (!screen) screen = DefaultScreen(display); XVisualInfo* visual = _get_xvisual(display, screen, 24, 16, 0); if (!visual) { log_errorf(HASH_WINDOW, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to get X visual")); goto fail; } Colormap colormap = XCreateColormap(display, XRootWindow(display, screen), visual->visual, AllocNone); log_debugf(HASH_WINDOW, STRING_CONST("Creating window on screen %d with dimensions %dx%d"), screen, width, height); XSetWindowAttributes attrib; attrib.colormap = colormap; attrib.background_pixel = 0; attrib.border_pixel = 0; attrib.event_mask = ExposureMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeyPressMask | KeyReleaseMask | KeymapStateMask | VisibilityChangeMask | FocusChangeMask; Window drawable = XCreateWindow(display, XRootWindow(display, screen), 0, 0, width, height, 0, visual->depth, InputOutput, visual->visual, CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &attrib); XSizeHints sizehints; sizehints.x = 0; sizehints.y = 0; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(display, drawable, &sizehints); XSetStandardProperties(display, drawable, title, title, None, 0, 0, &sizehints); if (show) { XMapWindow(display, drawable); XFlush(display); } Atom atom_delete = XInternAtom(display, "WM_DELETE_WINDOW", False); XSetWMProtocols(display, drawable, &atom_delete, 1); XFlush(display); XSync(display, False); XIC xic = 0; XIM xim = XOpenIM(display, 0, 0, 0); if(xim) { xic = XCreateIC(xim, XNInputStyle, XIMPreeditNone | XIMStatusNone, XNClientWindow, drawable, nullptr); if(xic) { /*XGetICValues(ic, XNFilterEvents, &fevent, NULL); mask = ExposureMask | KeyPressMask | FocusChangeMask; XSelectInput(display, window, mask|fevent);*/ } else { log_warn(HASH_WINDOW, WARNING_SUSPICIOUS, STRING_CONST("Unable to create X input context")); } } else { log_warn(HASH_WINDOW, WARNING_SUSPICIOUS, STRING_CONST("Unable to open X input method")); } window_t* window = memory_allocate(HASH_WINDOW, sizeof(window_t), 0, MEMORY_PERSISTENT | MEMORY_ZERO_INITIALIZED); window->display = display; window->visual = visual; window->screen = screen; window->drawable = drawable; window->atom = atom_delete; window->xim = xim; window->xic = xic; return window; fail: return 0; }
bool CanvasX11::ensure_x_window() { if (xwin_) return true; if (!xdpy_) { Log::error("Error: X11 Display has not been initialized!\n"); return false; } XVisualInfo *vis_info = get_xvisualinfo(); if (!vis_info) { Log::error("Error: Could not get a valid XVisualInfo!\n"); return false; } Log::debug("Creating XWindow W: %d H: %d VisualID: 0x%x\n", width_, height_, vis_info->visualid); /* window attributes */ XSetWindowAttributes attr; unsigned long mask; Window root = RootWindow(xdpy_, DefaultScreen(xdpy_)); attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(xdpy_, root, vis_info->visual, AllocNone); attr.event_mask = KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; xwin_ = XCreateWindow(xdpy_, root, 0, 0, width_, height_, 0, vis_info->depth, InputOutput, vis_info->visual, mask, &attr); XFree(vis_info); if (!xwin_) { Log::error("Error: XCreateWindow() failed!\n"); return false; } /* set hints and properties */ { static const char *name("glmark2 "GLMARK_VERSION); XSizeHints sizehints; sizehints.min_width = width_; sizehints.min_height = height_; sizehints.max_width = width_; sizehints.max_height = height_; sizehints.flags = PMaxSize | PMinSize; XSetNormalHints(xdpy_, xwin_, &sizehints); XSetStandardProperties(xdpy_, xwin_, name, name, None, NULL, 0, &sizehints); } /* Gracefully handle Window Delete event from window manager */ Atom wmDelete = XInternAtom(xdpy_, "WM_DELETE_WINDOW", True); XSetWMProtocols(xdpy_, xwin_, &wmDelete, 1); return true; }
void Create_Window (char *geometry) { short q; Visual *vid; XSetWindowAttributes xswa; XSizeHints sizehint; XWMHints wmhints; int depth; unsigned char wname[256]; /* Window Name */ unsigned long vmask = CWEventMask | CWBackPixel | CWBackingStore; depth = DefaultDepth (display.dpy, display.screen); xswa.event_mask = 0; xswa.background_pixel = display.bg; xswa.backing_store = Always; printf ("DefaultVisual id=%d bp-rgb=%d map-entries=%d\n" ,(int) (*DefaultVisual (display.dpy, display.screen)).visualid ,(*DefaultVisual (display.dpy, display.screen)).bits_per_rgb ,(*DefaultVisual (display.dpy, display.screen)).map_entries); vid = DefaultVisual (display.dpy, display.screen); display.cmap = XDefaultColormap (display.dpy, display.screen); display.win = XCreateWindow (display.dpy, display.root, winX, winY, display.winW, display.winH, 0, depth, InputOutput, /* vid , */ DefaultVisual (display.dpy, display.screen), /* PseudoColor, */ vmask, &xswa); sizehint.x = winX - 100; sizehint.y = winY; sizehint.width = display.winW; sizehint.height = display.winH; sizehint.min_width = display.winW; sizehint.min_height = display.winH; sizehint.max_width = display.winW; sizehint.max_height = display.winH; /* GCS FIX: Be careful about resizing the opening screen */ /* WCK: Fixed. We lock it now, and unlock it after the opening screen. not gorgeous, but it works for now. Still need to clean up.*/ #define NO_RESIZABLE_WINDOWS 1 if (geometry != NULL) { #if defined (NO_RESIZABLE_WINDOWS) sizehint.flags = USPosition | USSize | PMinSize | PMaxSize; #else sizehint.flags = USPosition | USSize | PMinSize; #endif } else { #if defined (NO_RESIZABLE_WINDOWS) sizehint.flags = PPosition | PSize | PMinSize | PMaxSize; #else sizehint.flags = PPosition | PSize | PMinSize; #endif } XSetNormalHints (display.dpy, display.win, &sizehint); display.protocol_atom = XInternAtom (display.dpy, "WM_PROTOCOLS", False); display.kill_atom = XInternAtom (display.dpy, "WM_DELETE_WINDOW", False); /* Title */ sprintf ((char *) wname, _("xlincity, Version %s, " "(Copyright) IJ Peters - copying policy GNU GPL"), VERSION); XChangeProperty (display.dpy, display.win, XA_WM_NAME, XA_STRING, 8, PropModeReplace, wname, strlen ((char *) wname)); /* Window Manager Hints (This is supposed to make input work.) */ wmhints.flags = InputHint; wmhints.input = True; XSetWMHints (display.dpy, display.win, &wmhints); XMapWindow (display.dpy, display.win); XSelectInput (display.dpy, display.win, KeyPressMask | ButtonPressMask | ButtonReleaseMask | ExposureMask | StructureNotifyMask); for (q = 0; q < 256; q++) { display.pixcolour_gc[q] = XCreateGC (display.dpy ,display.win, 0, NULL); XSetForeground (display.dpy, display.pixcolour_gc[q], q); XSetBackground (display.dpy, display.pixcolour_gc[q] ,display.bg); XSetGraphicsExposures (display.dpy, display.pixcolour_gc[q] ,False); } }
gboolean gst_imx_egl_viv_sink_egl_platform_init_window(GstImxEglVivSinkEGLPlatform *platform, guintptr window_handle, gboolean event_handling, GstVideoInfo *video_info, gboolean fullscreen, gint x_coord, gint y_coord, guint width, guint height, gboolean borderless) { EGLint num_configs; EGLConfig config; Window x11_window; Display *x11_display = (Display *)(platform->native_display); static EGLint const eglconfig_attribs[] = { EGL_RED_SIZE, 1, EGL_GREEN_SIZE, 1, EGL_BLUE_SIZE, 1, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; static EGLint const ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; if (!eglChooseConfig(platform->egl_display, eglconfig_attribs, &config, 1, &num_configs)) { GST_ERROR("eglChooseConfig failed: %s", gst_imx_egl_viv_sink_egl_platform_get_last_error_string()); return FALSE; } EGL_PLATFORM_LOCK(platform); { EGLint native_visual_id; XVisualInfo visual_info_template; XVisualInfo *visual_info; int num_matching_visuals; XSetWindowAttributes attr; int screen_num; Window root_window; Atom net_wm_state_atom, net_wm_state_fullscreen_atom; GST_INFO("Creating new X11 window with EGL context (parent window: %" G_GUINTPTR_FORMAT ")", window_handle); if (!eglGetConfigAttrib(platform->egl_display, config, EGL_NATIVE_VISUAL_ID, &native_visual_id)) { GST_ERROR("eglGetConfigAttrib failed: %s", gst_imx_egl_viv_sink_egl_platform_get_last_error_string()); EGL_PLATFORM_UNLOCK(platform); return FALSE; } screen_num = DefaultScreen(x11_display); root_window = RootWindow(x11_display, screen_num); memset(&visual_info_template, 0, sizeof(visual_info_template)); visual_info_template.visualid = native_visual_id; visual_info = XGetVisualInfo(x11_display, VisualIDMask, &visual_info_template, &num_matching_visuals); if (visual_info == NULL) { GST_ERROR("Could not get visual info for native visual ID %d", native_visual_id); EGL_PLATFORM_UNLOCK(platform); return FALSE; } memset(&attr, 0, sizeof(attr)); attr.background_pixmap = None; attr.background_pixel = BlackPixel(x11_display, screen_num); attr.border_pixmap = CopyFromParent; attr.border_pixel = BlackPixel(x11_display, screen_num); attr.backing_store = NotUseful; attr.override_redirect = borderless ? True : False; attr.cursor = None; if (window_handle != 0) { platform->parent_window = (Window)window_handle; /* Out of the parent window events, only the structure * notifications are of interest here */ XSelectInput(x11_display, platform->parent_window, StructureNotifyMask); } // TODO: xlib error handler /* This video output window can be embedded into other windows, for example inside * media player user interfaces. This is done by making the specified window as * the parent of the video playback window. */ x11_window = XCreateWindow( x11_display, (window_handle != 0) ? platform->parent_window : root_window, x_coord, y_coord, (width != 0) ? (gint)width : GST_VIDEO_INFO_WIDTH(video_info), (height != 0) ? (gint)height : GST_VIDEO_INFO_HEIGHT(video_info), 0, visual_info->depth, InputOutput, visual_info->visual, CWBackPixel | CWColormap | CWBorderPixel | CWBackingStore | CWOverrideRedirect, &attr ); platform->native_window = (EGLNativeWindowType)x11_window; net_wm_state_atom = XInternAtom(x11_display, "_NET_WM_STATE", True); net_wm_state_fullscreen_atom = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", True); platform->wm_delete_atom = XInternAtom(x11_display, "WM_DELETE_WINDOW", True); XSetWMProtocols(x11_display, x11_window, &(platform->wm_delete_atom), 1); XStoreName(x11_display, x11_window, "eglvivsink window"); gst_imx_egl_viv_sink_egl_platform_set_event_handling_nolock(platform, event_handling); XSizeHints sizehints; sizehints.x = 0; sizehints.y = 0; sizehints.width = GST_VIDEO_INFO_WIDTH(video_info); sizehints.height = GST_VIDEO_INFO_HEIGHT(video_info); sizehints.flags = PPosition | PSize; XSetNormalHints(x11_display, x11_window, &sizehints); if (fullscreen) { XChangeProperty( x11_display, x11_window, net_wm_state_atom, XA_ATOM, 32, PropModeReplace, (unsigned char*)&net_wm_state_fullscreen_atom, 1 ); } XClearWindow(x11_display, x11_window); XMapRaised(x11_display, x11_window); if (fullscreen) { XEvent event; event.type = ClientMessage; event.xclient.window = x11_window; event.xclient.message_type = net_wm_state_atom; event.xclient.format = 32; event.xclient.data.l[0] = 1; event.xclient.data.l[1] = net_wm_state_fullscreen_atom; event.xclient.data.l[3] = 0l; XSendEvent( x11_display, root_window, 0, SubstructureNotifyMask, &event ); } XSync(x11_display, False); } eglBindAPI(EGL_OPENGL_ES_API); platform->egl_context = eglCreateContext(platform->egl_display, config, EGL_NO_CONTEXT, ctx_attribs); platform->egl_surface = eglCreateWindowSurface(platform->egl_display, config, platform->native_window, NULL); eglMakeCurrent(platform->egl_display, platform->egl_surface, platform->egl_surface, platform->egl_context); { XWindowAttributes window_attr; XGetWindowAttributes(x11_display, x11_window, &window_attr); if (platform->window_resized_event_cb != NULL) platform->window_resized_event_cb(platform, window_attr.width, window_attr.height, platform->user_context); else glViewport(0, 0, window_attr.width, window_attr.height); } EGL_PLATFORM_UNLOCK(platform); return TRUE; }
int makeLightingPanel(void) { int i; XSetWindowAttributes cwAttrib, controlAttrib; XSizeHints sizehint; Pixmap lightbits,lightmask; XColor foreColor, backColor; lightbits = XCreateBitmapFromData(dsply,rtWindow, lightBitmap_bits, lightBitmap_width,lightBitmap_height); lightmask = XCreateBitmapFromData(dsply,rtWindow, lightMask_bits, lightMask_width,lightMask_height); cwAttrib.background_pixel = backgroundColor; cwAttrib.border_pixel = foregroundColor; cwAttrib.event_mask = lightMASK; cwAttrib.colormap = colorMap; cwAttrib.override_redirect = overrideManager; foreColor.pixel = lightCursorForeground; XQueryColor(dsply,colorMap,&foreColor); backColor.pixel = lightCursorBackground; XQueryColor(dsply,colorMap,&backColor); cwAttrib.cursor = XCreatePixmapCursor(dsply,lightbits,lightmask, &foreColor,&backColor, lightBitmap_x_hot,lightBitmap_y_hot); lightingWindow = 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,lightingWindow,&sizehint); XSetStandardProperties(dsply,lightingWindow,"Lighting Panel 3D", "Lighting Panel",None,NULL,0,&sizehint); /*** lighting axes window ***/ cwAttrib.event_mask = 0; lightingAxes = XCreateWindow(dsply,lightingWindow, lightingAxesX,lightingAxesY, lightingAxesSize,lightingAxesSize, 0,CopyFromParent,InputOutput,CopyFromParent, controlCreateMASK,&cwAttrib); sizehint.flags = USPosition | USSize; sizehint.x = lightingAxesX; sizehint.y = lightingAxesY; sizehint.width = lightingAxesSize; sizehint.height = lightingAxesSize; /*** the None stands for icon pixmap ***/ XSetNormalHints(dsply,lightingAxes,&sizehint); XSetStandardProperties(dsply,lightingAxes,"Lighting Axes","Lighting Axes", None,NULL,0,&sizehint); XMapWindow(dsply,lightingAxes); /*** draw lighting buttons ***/ initLightButtons(control->buttonQueue); /* controlAttrib.event_mask = (control->buttonQueue[lightingButtonsStart]).mask; (control->buttonQueue[lightingButtonsStart]).self = XCreateWindow(dsply, lightingWindow, (control->buttonQueue[lightingButtonsStart]).buttonX, (control->buttonQueue[lightingButtonsStart]).buttonY, (control->buttonQueue[lightingButtonsStart]).buttonWidth, (control->buttonQueue[lightingButtonsStart]).buttonHeight, 0,0,InputOnly,CopyFromParent, buttonCreateMASK,&controlAttrib); XMakeAssoc(dsply,table,(control->buttonQueue[lightingButtonsStart]).self, &((control->buttonQueue[lightingButtonsStart]).buttonKey)); XMapWindow(dsply,(control->buttonQueue[lightingButtonsStart]).self); */ for (i=(lightingButtonsStart + 1); i<(lightingButtonsEnd); i++) { controlAttrib.event_mask = (control->buttonQueue[i]).mask; (control->buttonQueue[i]).self = XCreateWindow(dsply,lightingWindow, (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); } /* assign global direction variables for light projections */ sinTheta = sin(-viewport->theta); cosTheta = cos(-viewport->theta); sinPhi = sin(viewport->phi); cosPhi = cos(viewport->phi); return(0); } /* makeLightingPanel() */
static struct window * AddWindow(const char *displayName, int xpos, int ypos, const struct window *shareWindow) { Display *dpy; Window win; GLXContext ctx; int attrib[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None }; int scrnum; XSetWindowAttributes attr; unsigned long mask; Window root; XVisualInfo *visinfo; int width = 300, height = 300; if (NumWindows >= MAX_WINDOWS) return NULL; dpy = XOpenDisplay(displayName); if (!dpy) { Error(displayName, "Unable to open display"); return NULL; } scrnum = DefaultScreen(dpy); root = RootWindow(dpy, scrnum); visinfo = glXChooseVisual(dpy, scrnum, attrib); if (!visinfo) { Error(displayName, "Unable to find RGB, double-buffered visual"); return NULL; } /* window attributes */ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, xpos, ypos, width, height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); if (!win) { Error(displayName, "Couldn't create window"); return NULL; } { XSizeHints sizehints; sizehints.x = xpos; sizehints.y = ypos; sizehints.width = width; sizehints.height = height; sizehints.flags = USSize | USPosition; XSetNormalHints(dpy, win, &sizehints); XSetStandardProperties(dpy, win, displayName, displayName, None, (char **)NULL, 0, &sizehints); } ctx = glXCreateContext(dpy, visinfo, shareWindow ? shareWindow->Context : NULL, True); if (!ctx) { Error(displayName, "Couldn't create GLX context"); return NULL; } XMapWindow(dpy, win); if (!glXMakeCurrent(dpy, win, ctx)) { Error(displayName, "glXMakeCurrent failed"); printf("glXMakeCurrent failed in Redraw()\n"); return NULL; } /* save the info for this window */ { static int id = 0; struct window *h = &Windows[NumWindows]; strcpy(h->DisplayName, displayName); h->Dpy = dpy; h->Win = win; h->Context = ctx; h->Angle = 0.0; h->Id = id++; NumWindows++; return &Windows[NumWindows-1]; } }
int initsystem(void) /* retourne 1 si initialisation reussie */ { int i; int windowW; int windowH; XSetWindowAttributes xswa; XGCValues xgcv; XSizeHints xsh; windowW=WIDTH*RATIO; windowH=HEIGHT*RATIO; display=XOpenDisplay(0); if (!display) return(0); else { mousek=0; XAutoRepeatOff(display); timestart=last=systime(); screen=XDefaultScreenOfDisplay(display); rdepth=sdepth=XDefaultDepthOfScreen(screen); if (emulmono) sdepth=1; XSynchronize(display,0); black=XBlackPixelOfScreen(screen); white=XWhitePixelOfScreen(screen); colormap=XDefaultColormapOfScreen(screen); visual=XDefaultVisualOfScreen(screen); xswa.event_mask=VisibilityChangeMask; xswa.background_pixel=black; xswa.border_pixel=white; xswa.override_redirect=0; xswa.backing_store=Always; xswa.bit_gravity=StaticGravity; xswa.win_gravity=CenterGravity; window=XCreateWindow(display,XRootWindowOfScreen(screen), randval(50),randval(100),windowW,windowH,0, XDefaultDepthOfScreen(screen),InputOutput, XDefaultVisualOfScreen(screen), CWWinGravity|CWBitGravity|CWBackingStore|CWEventMask| CWBackPixel|CWOverrideRedirect|CWBorderPixel,&xswa); if (sdepth!=1) xcolormap=XCreateColormap(display,window, visual,AllocAll); xgcv.foreground = white; xgcv.background = black; gc=XCreateGC(display,window,GCForeground | GCBackground,&xgcv); XSetGraphicsExposures(display,gc,False); /* CAPITAL!!! : evite d'accumuler sans cesse des expose events */ xsh.x=0; xsh.y=0; xsh.width=windowW; xsh.height=windowH; xsh.min_width=windowW; xsh.max_width=windowW; xsh.min_height=windowH; xsh.max_height=windowH; xsh.flags=PPosition|PSize|PMinSize|PMaxSize; XSetNormalHints(display, window, &xsh); XStoreName(display,window,""); XMapWindow(display, window); XSelectInput(display,window,PointerMotionMask|ButtonPressMask| ButtonReleaseMask|KeyPressMask|KeyReleaseMask); XFlush(display); XSync(display,0); for (i=0; i<(NBCOLORS+2); i++) { if (i&1) pixels[i]=white; else pixels[i]=black; if (i==NBCOLORS) pixels[i]=0; if (i==(NBCOLORS+1)) pixels[i]=(1<<rdepth)-1; xgcv.foreground=pixels[i]; xgcv.background=black; gctab[i]=XCreateGC(display,window, GCForeground|GCBackground,&xgcv); XSetFunction(display,gctab[i],GXcopy); XSetFillStyle(display,gctab[i],FillSolid); } ecran[0]=XCreatePixmap(display,window,windowW,windowH,rdepth); ecran[1]=XCreatePixmap(display,window,windowW,windowH,rdepth); for(i=0; i<9; i++) graypixmap[i]=XCreatePixmapFromBitmapData(display,window, &graypat[i][0],8,8,white,black,rdepth); setpalette(egapal); cls(); swap(); cls(); empty(); waitdelay(500); return(1); } }