📄 x11-init.c
字号:
_x.gccopy = xgc(_x.screenpm, -1, -1); _x.gcsimplesrc = xgc(_x.screenpm, FillStippled, -1); _x.gczero = xgc(_x.screenpm, -1, -1); _x.gcreplsrc = xgc(_x.screenpm, FillTiled, -1); pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1); _x.gcfill0 = xgc(pmid, FillSolid, 0); _x.gccopy0 = xgc(pmid, -1, -1); _x.gcsimplesrc0 = xgc(pmid, FillStippled, -1); _x.gczero0 = xgc(pmid, -1, -1); _x.gcreplsrc0 = xgc(pmid, FillTiled, -1); XFreePixmap(_x.display, pmid); termreplacescreenimage(_x.screenimage); return _x.screenimage;err0: /* * Should do a better job of cleaning up here. */ XCloseDisplay(_x.display); return nil;}int_xsetlabel(char *label){ XTextProperty name; /* * Label and other properties required by ICCCCM. */ memset(&name, 0, sizeof name); if(label == nil) label = "pjw-face-here"; name.value = (uchar*)label; name.encoding = XA_STRING; name.format = 8; name.nitems = strlen((char*)name.value); XSetWMProperties( _x.display, /* display */ _x.drawable, /* window */ &name, /* XA_WM_NAME property */ &name, /* XA_WM_ICON_NAME property */ nil, /* XA_WM_COMMAND */ 0, /* argc */ nil, /* XA_WM_NORMAL_HINTS */ nil, /* XA_WM_HINTS */ nil /* XA_WM_CLASSHINTS */ ); XFlush(_x.display); return 0;}/* * Create a GC with a particular fill style and XXX. * Disable generation of GraphicsExpose/NoExpose events in the GC. */static XGCxgc(XDrawable d, int fillstyle, int foreground){ XGC gc; XGCValues v; memset(&v, 0, sizeof v); v.function = GXcopy; v.graphics_exposures = False; gc = XCreateGC(_x.display, d, GCFunction|GCGraphicsExposures, &v); if(fillstyle != -1) XSetFillStyle(_x.display, gc, fillstyle); if(foreground != -1) XSetForeground(_x.display, gc, 0); return gc;}/* * Initialize map with the Plan 9 rgbv color map. */static voidplan9cmap(void){ int r, g, b, cr, cg, cb, v, num, den, idx, v7, idx7; static int once; if(once) return; once = 1; for(r=0; r!=4; r++) for(g = 0; g != 4; g++) for(b = 0; b!=4; b++) for(v = 0; v!=4; v++){ den=r; if(g > den) den=g; if(b > den) den=b; /* divide check -- pick grey shades */ if(den==0) cr=cg=cb=v*17; else { num=17*(4*den+v); cr=r*num/den; cg=g*num/den; cb=b*num/den; } idx = r*64 + v*16 + ((g*4 + b + v - r) & 15); _x.map[idx].red = cr*0x0101; _x.map[idx].green = cg*0x0101; _x.map[idx].blue = cb*0x0101; _x.map[idx].pixel = idx; _x.map[idx].flags = DoRed|DoGreen|DoBlue; v7 = v >> 1; idx7 = r*32 + v7*16 + g*4 + b; if((v & 1) == v7){ _x.map7to8[idx7][0] = idx; if(den == 0) { /* divide check -- pick grey shades */ cr = ((255.0/7.0)*v7)+0.5; cg = cr; cb = cr; } else { num=17*15*(4*den+v7*2)/14; cr=r*num/den; cg=g*num/den; cb=b*num/den; } _x.map7[idx7].red = cr*0x0101; _x.map7[idx7].green = cg*0x0101; _x.map7[idx7].blue = cb*0x0101; _x.map7[idx7].pixel = idx7; _x.map7[idx7].flags = DoRed|DoGreen|DoBlue; } else _x.map7to8[idx7][1] = idx; }}/* * Initialize and install the rgbv color map as a private color map * for this application. It gets the best colors when it has the * cursor focus. * * We always choose the best depth possible, but that might not * be the default depth. On such "suboptimal" systems, we have to allocate an * empty color map anyway, according to Axel Belinfante. */static int setupcmap(XWindow w){ char buf[30]; int i; u32int p, pp; XColor c; if(_x.depth <= 1) return 0; if(_x.depth >= 24) { if(_x.usetable == 0) _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone); /* * The pixel value returned from XGetPixel needs to * be converted to RGB so we can call rgb2cmap() * to translate between 24 bit X and our color. Unfortunately, * the return value appears to be display server endian * dependant. Therefore, we run some heuristics to later * determine how to mask the int value correctly. * Yeah, I know we can look at _x.vis->byte_order but * some displays say MSB even though they run on LSB. * Besides, this is more anal. */ c = _x.map[19]; /* known to have different R, G, B values */ if(!XAllocColor(_x.display, _x.cmap, &c)){ werrstr("XAllocColor: %r"); return -1; } p = c.pixel; pp = rgb2cmap((p>>16)&0xff,(p>>8)&0xff,p&0xff); if(pp != _x.map[19].pixel) { /* check if endian is other way */ pp = rgb2cmap(p&0xff,(p>>8)&0xff,(p>>16)&0xff); if(pp != _x.map[19].pixel){ werrstr("cannot detect X server byte order"); return -1; } switch(_x.chan){ case RGB24: _x.chan = BGR24; break; case XRGB32: _x.chan = XBGR32; break; default: werrstr("cannot byteswap channel %s", chantostr(buf, _x.chan)); break; } } }else if(_x.vis->class == TrueColor || _x.vis->class == DirectColor){ /* * Do nothing. We have no way to express a * mixed-endian 16-bit screen, so pretend they don't exist. */ if(_x.usetable == 0) _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocNone); }else if(_x.vis->class == PseudoColor){ if(_x.usetable == 0){ _x.cmap = XCreateColormap(_x.display, w, _x.vis, AllocAll); XStoreColors(_x.display, _x.cmap, _x.map, 256); for(i = 0; i < 256; i++){ _x.tox11[i] = i; _x.toplan9[i] = i; } }else{ for(i = 0; i < 128; i++){ c = _x.map7[i]; if(!XAllocColor(_x.display, _x.cmap, &c)){ werrstr("can't allocate colors in 7-bit map"); return -1; } _x.tox11[_x.map7to8[i][0]] = c.pixel; _x.tox11[_x.map7to8[i][1]] = c.pixel; _x.toplan9[c.pixel] = _x.map7to8[i][0]; } } }else{ werrstr("unsupported visual class %d", _x.vis->class); return -1; } return 0;}voidflushmemscreen(Rectangle r){ static Lock flushlock; if(up && !up->nlocks.ref && _x.nextscreenpm != _x.screenpm){ qlock(&_x.screenlock); XSync(_x.display, False); XFreePixmap(_x.display, _x.screenpm); _x.screenpm = _x.nextscreenpm; qunlock(&_x.screenlock); } if(r.min.x >= r.max.x || r.min.y >= r.max.y) return; lock(&flushlock); XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y, Dx(r), Dy(r), r.min.x, r.min.y); XFlush(_x.display); unlock(&flushlock);}void_xexpose(XEvent *e){ XExposeEvent *xe; Rectangle r; qlock(&_x.screenlock); if(_x.screenpm != _x.nextscreenpm){ qunlock(&_x.screenlock); return; } xe = (XExposeEvent*)e; r.min.x = xe->x; r.min.y = xe->y; r.max.x = xe->x+xe->width; r.max.y = xe->y+xe->height; XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y, Dx(r), Dy(r), r.min.x, r.min.y); XSync(_x.display, False); qunlock(&_x.screenlock);}int_xdestroy(XEvent *e){ XDestroyWindowEvent *xe; xe = (XDestroyWindowEvent*)e; if(xe->window == _x.drawable){ _x.destroyed = 1; return 1; } return 0;}int_xconfigure(XEvent *e){ Rectangle r; XConfigureEvent *xe = (XConfigureEvent*)e; if(!fullscreen){ int rx, ry; XWindow w; if(XTranslateCoordinates(_x.kmcon, _x.drawable, DefaultRootWindow(_x.display), 0, 0, &rx, &ry, &w)) windowrect = Rect(rx, ry, rx+xe->width, ry+xe->height); } if(xe->width == Dx(_x.screenr) && xe->height == Dy(_x.screenr)) return 0; r = Rect(0, 0, xe->width, xe->height); mouserect = r; qlock(&_x.screenlock); if(_x.screenpm != _x.nextscreenpm){ XCopyArea(_x.display, _x.screenpm, _x.drawable, _x.gccopy, r.min.x, r.min.y, Dx(r), Dy(r), r.min.x, r.min.y); XSync(_x.display, False); } qunlock(&_x.screenlock); _x.newscreenr = r; return 1;}int_xreplacescreenimage(void){ Memimage *m; XDrawable pixmap; Rectangle r; r = _x.newscreenr; pixmap = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth); m = _xallocmemimage(r, _x.chan, pixmap); if(_x.nextscreenpm != _x.screenpm) XFreePixmap(_x.display, _x.nextscreenpm); _x.nextscreenpm = pixmap; _x.screenr = r; _x.screenimage = m; termreplacescreenimage(m); drawreplacescreenimage(m); _x.screenpm = _x.nextscreenpm; return 1;}static intparsewinsize(char *s, Rectangle *r, int *havemin){ char c, *os; int i, j, k, l; os = s; *havemin = 0; *r = Rect(0,0,0,0); if(!isdigit((uchar)*s)) goto oops; i = strtol(s, &s, 0); if(*s == 'x'){ s++; if(!isdigit((uchar)*s)) goto oops; j = strtol(s, &s, 0); r->max.x = i; r->max.y = j; if(*s == 0) return 0; if(*s != '@') goto oops; s++; if(!isdigit((uchar)*s)) goto oops; i = strtol(s, &s, 0); if(*s != ',' && *s != ' ') goto oops; s++; if(!isdigit((uchar)*s)) goto oops; j = strtol(s, &s, 0); if(*s != 0) goto oops; *r = rectaddpt(*r, Pt(i,j)); *havemin = 1; return 0; } c = *s; if(c != ' ' && c != ',') goto oops; s++; if(!isdigit((uchar)*s)) goto oops; j = strtol(s, &s, 0); if(*s != c) goto oops; s++; if(!isdigit((uchar)*s)) goto oops; k = strtol(s, &s, 0); if(*s != c) goto oops; s++; if(!isdigit((uchar)*s)) goto oops; l = strtol(s, &s, 0); if(*s != 0) goto oops; *r = Rect(i,j,k,l); *havemin = 1; return 0;oops: werrstr("bad syntax in window size '%s'", os); return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -