📄 xinit.c
字号:
if (w > wavail) w = wavail;if (h > havail) h = havail;/* Find out if the user specified the position */q_user_pos = (x >= 0) && (y >= 0);border_width = 0;if (x < 0) x = 0;if (y < 0) y = 0;x = (x + w > wavail) ? wavail - w : x;y = (y + h > havail) ? havail - h : y;/* We need XCreateWindow since we may need an visual other than the default one */XGetWindowAttributes( XBWin->disp, RootWindow(XBWin->disp,XBWin->screen), &in_window_attributes );window_attributes.background_pixmap = None;window_attributes.background_pixel = backgnd_pixel;/* No border for now */window_attributes.border_pixmap = None;/* window_attributes.border_pixel = border_pixel; */window_attributes.bit_gravity = in_window_attributes.bit_gravity;window_attributes.win_gravity = in_window_attributes.win_gravity; /* Backing store is too slow in color systems */window_attributes.backing_store = 0;window_attributes.backing_pixel = backgnd_pixel;window_attributes.save_under = 1;window_attributes.event_mask = 0;window_attributes.do_not_propagate_mask = 0;window_attributes.override_redirect = 0;window_attributes.colormap = XBWin->cmap;/* None for cursor does NOT mean none, it means Parent's cursor */window_attributes.cursor = None; wmask = CWBackPixmap | CWBackPixel | CWBorderPixmap | CWBitGravity | CWWinGravity | CWBackingStore | CWBackingPixel | CWOverrideRedirect | CWSaveUnder | CWEventMask | CWDontPropagate | CWCursor | CWColormap ;/* depth should really be the depth of the visual in use */depth = DefaultDepth( XBWin->disp, XBWin->screen );XBWin->win = XCreateWindow( XBWin->disp, RootWindow(XBWin->disp,XBWin->screen), x, y, w, h, border_width, depth, InputOutput, XBWin->vis, wmask, &window_attributes );if (!XBWin->win) return ERR_CAN_NOT_OPEN_WINDOW;/* set resize hints (prohibit?) */size_hints.x = x;size_hints.y = y;size_hints.min_width = 4*border_width;size_hints.min_height = 4*border_width;size_hints.width = w;size_hints.height = h;if (q_user_pos) size_hints.flags = USPosition | USSize | PMinSize; /* | PAspect; */else size_hints.flags = PPosition | PSize | PMinSize; /* | PAspect; *//* Set the standard properties */XSetStandardProperties( XBWin->disp, XBWin->win, label, label, 0, (char **)0, 0, &size_hints );/* make the window visible */XSelectInput( XBWin->disp, XBWin->win, ExposureMask | StructureNotifyMask );XMapWindow( XBWin->disp, XBWin->win );/* some window systems are cruel and interfere with the placement of windows. We wait here for the window to be created or to die */if (XB_wait_map( XBWin, (void (*)( XBWindow *, int, int, int, int ))0 )) { XBWin->win = (Window)0; return 0; }/* Initial values for the upper left corner */XBWin->x = 0;XBWin->y = 0;return 0;}/* There should also be a routine that gets this data from a widget, so that this structure can be used with a widget set *//* XBGetArgs - Get the X related arguments (geometry for now) Input Parameters:. Argc - pointer to argument count. argv - argument vector. flag - 1 if the "found" arguments should be stripped from the argument list Output Parameters:. px,py - position of window. pw,ph - width and height of window Note: The output parameters are unchanged if they are not set. The form of the argument is$ -geometry width x height + xoffset + yoffset$ with no spaces. For example$ -geometry 400x400$ for a 400 x 400 window, and$ -geometry +100+200$ for a window located at (100,200). */void XBGetArgs( Argc, argv, flag, px, py, pw, ph )int *Argc, flag;char **argv;int *px, *py, *pw, *ph;{ char val[128]; int vallen; int st, xx, yy; unsigned int ww, hh; vallen = 128; if (ArgGetString( Argc, argv, flag, "-geometry", val, vallen )) { /* value is of form wxh+x+y */ st = XParseGeometry( val, &xx, &yy, &ww, &hh ); if (st & XValue) *px = xx; if (st & YValue) *py = yy; if (st & WidthValue) *pw = (int)ww; if (st & HeightValue) *ph = (int)hh; }}/* XBGetArgsDisplay - Get the X display name from the argument list Input Parameters:. Argc - pointer to argument count. argv - argument vector. flag - 1 if the "found" arguments should be stripped from the argument list. dlen - length of dname Output Parameters:. dname - Name of display Note: The output parameter is unchanged if they are not set. The form of the argument is$ -display name */void XBGetArgsDisplay( Argc, argv, flag, dlen, dname )int *Argc, flag;char **argv, *dname;int dlen;{ ArgGetString( Argc, argv, flag, "-display", dname, dlen );}int XBiQuickWindow( mywindow, host, name, x, y, nx, ny, nc )XBWindow *mywindow;char *host, *name;int x, y, nx, ny, nc;{ if (XBOpenDisplay( mywindow, host )) { fprintf( stderr, "Could not open display\n" ); return 1; } if (XBSetVisual( mywindow, 1, (Colormap)0, nc )) { fprintf( stderr, "Could not set visual to default\n" ); return 1; } if (XBOpenWindow( mywindow )) { fprintf( stderr, "Could not open the window\n" ); return 1; }/* Use cmapping[0] for the background */ if (XBDisplayWindow( mywindow, name, x, y, nx, ny, mywindow->cmapping[0])) { fprintf( stderr, "Could not display window\n" ); return 1; }/* Set the foreground */ XBSetGC( mywindow, mywindow->cmapping[1] ); XBClearWindow(mywindow,0,0,mywindow->w,mywindow->h); return 0;}/* XBQuickWindow - Create an X window Input parameters:. mywindow - A pointer to an XBWindow structure that will be used to hold information on the window. This should be acquired with XBWinCreate.. host - name of the display. name - title (name) of the window. x,y - coordinates of the upper left corner of the window. If <0, use user-positioning (normally, the window manager will ask the user where to put the window). nx,ny - width and height of the window Note: This creates a window with various defaults (visual, colormap, etc) A small modification to this routine would allow Black and White windows to be used on color displays; this would be useful for testing codes. */int XBQuickWindow( mywindow, host, name, x, y, nx, ny )XBWindow *mywindow;char *host, *name;int x, y, nx, ny;{/* Just to be careful, clear mywindow */ MEMSET( mywindow, 0, sizeof(XBWindow) ); return XBiQuickWindow( mywindow, host, name, x, y, nx, ny, 0 );}/* And a quick version (from an already defined window) */int XBQuickWindowFromWindow( mywindow, host, win )XBWindow *mywindow;char *host;Window win;{ Window root; int d; unsigned int ud; if (XBOpenDisplay( mywindow, host )) { fprintf( stderr, "Could not open display\n" ); return 1; } if (XBSetVisual( mywindow, 1, (Colormap)0, 0 )) { fprintf( stderr, "Could not set visual to default\n" ); return 1; } mywindow->win = win; XGetGeometry( mywindow->disp, mywindow->win, &root, &d, &d, (unsigned int *)&mywindow->w, (unsigned int *)&mywindow->h, &ud, &ud ); mywindow->x = mywindow->y = 0; XBSetGC( mywindow, mywindow->cmapping[1] ); return 0;}/* XBFlush - Flush all X 11 requests. Input parameter:. XBWin - window Note: Using an X drawing routine does not necessarily cause the the server to receive and draw the requests. Use this routine if necessary to force the server to draw (doing so may slow down the program, so don't insert unnecessary XBFlush calls). If double-buffering is enabled, this routine copies from the buffer to the window before flushing the requests. This is the appropriate action for animation. */void XBFlush( XBWin )XBWindow *XBWin;{ if (XBWin->drw) { XCopyArea( XBWin->disp, XBWin->drw, XBWin->win, XBWin->gc.set, 0, 0, XBWin->w, XBWin->h, XBWin->x, XBWin->y ); } XFlush( XBWin->disp );}/* XBSetWindowLabel - Sets new label in open window. Input Parameters:. window - Window to set label for. label - Label to give window */void XBSetWindowLabel( XBwin, label )XBWindow *XBwin;char *label;{ XTextProperty prop; XGetWMName(XBwin->disp,XBwin->win,&prop); prop.value = (unsigned char *)label; prop.nitems = (long) strlen(label); XSetWMName(XBwin->disp,XBwin->win,&prop);}/* XBCaptureWindowToFile - Capture a window and write it in xwd format to a file Input Parameters:. XBWin - XB Window to write out. fname - name of file Notes: This command uses XGetImage; thus, the window must be unobscured. The current implementation actually uses xwd called by spawning a process. Later implementations may write the file directly. Be sure that you have XBFlush()'ed the output; X11 does not require that the image be current until a flush is executed. */void XBCaptureWindowToFile( XBWin, fname )XBWindow *XBWin;char *fname;{#ifdef HAVE_SYSTEM char cmdbuf[1024]; sprintf( cmdbuf, "xwd -id %ld > %s\n", (long)XBWin->win, fname ); system( cmdbuf );#else fprintf( stderr, "This machine does not support the system call\n\which is needed by XBCaptureWindowToFile\n" );#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -