📄 xlib.c
字号:
&& XMatchVisualInfo (new->display, new->screen, 8, StaticGray, &vis)) { found = 1; } for (i = 8; i && !found; i--) if (XMatchVisualInfo (new->display, new->screen, i, GrayScale, &vis)) { found = 1; } if (!found && XMatchVisualInfo (new->display, new->screen, 1, StaticGray, &vis)) { found = 8; } if (!found) { new->visual = defaultvisual; vis.depth = new->depth = DefaultDepth (new->display, new->screen); } else { new->visual = vis.visual; new->depth = vis.depth; } switch (new->visual->class) { case StaticColor: case StaticGray: smallcolor: new->truecolor = 0; new->fixedcolormap = 1; break; case PseudoColor: case GrayScale: if (new->depth <= 8) { new->truecolor = 0; new->fixedcolormap = 0; } else { goto visuals; } break; case TrueColor: new->truecolor = 1; new->fixedcolormap = 1; if (new->depth <= 8) goto smallcolor; if (new->depth > 32) { goto visuals; } break; default: visuals: printf ("Unusuported visual. Please contact authors. Maybe it will be supported in next release:)\n"); return (NULL); } new->privatecolormap = params->privatecolormap; new->attributes->colormap = new->defaultcolormap = DefaultColormap (new->display, new->screen); if (new->visual->visualid != defaultvisual->visualid) { new->privatecolormap = 1; } if ( /*!new->fixedcolormap && */ new->privatecolormap) { unsigned long pixels[256]; int i; new->attributes->colormap = XCreateColormap (new->display, RootWindow (new->display, new->screen), new->visual, AllocNone); if (new->visual->visualid == defaultvisual->visualid && new->visual->class == PseudoColor) { XAllocColorCells (new->display, new->attributes->colormap, 1, 0, 0, pixels, MAX (new->visual->map_entries, 256)); for (i = 0; i < 16; i++) { new->xcolor.c[i].pixel = pixels[i]; } XQueryColors (new->display, new->defaultcolormap, new->xcolor.c, 16); XStoreColors (new->display, new->attributes->colormap, new->xcolor.c, 16); } } new->colormap = new->attributes->colormap; new->attr_mask |= CWColormap; new->window_name = (char *) s; new->height = y; new->width = x; new->border_width = 2; new->lastx = 0; new->lasty = 0; new->font_struct = (XFontStruct *) NULL; if (params->fullscreen || params->rootwindow) { Window wtmp; int tmp; /* Get size of the root window */ XGetGeometry (new->display, RootWindow (new->display, new->screen), &wtmp, &tmp, &tmp, &new->width, &new->height, (unsigned int *) &tmp, /* border width */ (unsigned int *) &tmp); /* depth */ new->border_width = 0; } if (params->windowid != -1) { Window wtmp; int tmp; new->parent_window = params->windowid; XGetGeometry (new->display, new->parent_window, &wtmp, &tmp, &tmp, &new->width, &new->height, (unsigned int *) &tmp, /* border width */ (unsigned int *) &tmp); /* depth */ XSelectInput (new->display, new->parent_window, ResizeRedirectMask); } if (params->rootwindow) new->window = RootWindow (new->display, new->screen); else new->window = XCreateWindow (new->display, new->parent_window, 0, 0, new->width, new->height, new->border_width, new->depth, new->class, new->visual, new->attr_mask, new->attributes); classHint.res_name = (char *) "xaos"; classHint.res_class = (char *) "XaoS"; hints = XAllocWMHints (); hints->initial_state = NormalState; hints->window_group = new->window; hints->flags = (WindowGroupHint | StateHint); { int fake = 0; if (prog_argc < 2) fake = 1; if (fake == 0) if (strcmp (prog_argv[prog_argc - 2], "-driver") && strcmp (prog_argv[prog_argc - 1], "x11")) fake = 1; if (fake) { int i; faked_argv = (char **) malloc ((prog_argc + 2) * sizeof (char *)); for (i = 0; i < prog_argc; i++) faked_argv[i] = prog_argv[i]; faked_argv[prog_argc] = (char *) "-driver"; faked_argv[prog_argc + 1] = (char *) "x11"; XSetWMProperties (new->display, new->window, NULL, NULL, faked_argv, prog_argc + 2, NULL, hints, &classHint); free (faked_argv); } else XSetWMProperties (new->display, new->window, NULL, NULL, prog_argv, prog_argc, NULL, hints, &classHint); } XSetIconName (new->display, new->window, "xaos"); wmDeleteWindow = XInternAtom (new->display, "WM_DELETE_WINDOW", False); XSetWMProtocols (new->display, new->window, &wmDeleteWindow, 1); new->gc = XCreateGC (new->display, new->window, 0L, &(new->xgcvalues)); XSetBackground (new->display, new->gc, BlackPixel (new->display, new->screen)); XSetForeground (new->display, new->gc, WhitePixel (new->display, new->screen)); XStoreName (new->display, new->window, new->window_name); XMapWindow (new->display, new->window); if (params->fullscreen || params->rootwindow) XSetInputFocus (new->display, new->window, RevertToNone, CurrentTime); return (new);}voidxsetcolor (xdisplay * d, int col){ switch (col) { case 0: XSetForeground (d->display, d->gc, BlackPixel (d->display, d->screen)); break; case 1: XSetForeground (d->display, d->gc, WhitePixel (d->display, d->screen)); break; default: if ((col - 2) > d->xcolor.n) { fprintf (stderr, "color error\n"); exit (-1); } XSetForeground (d->display, d->gc, d->xcolor.c[col - 2].pixel); break; }}voidxsetpaletterange (xdisplay * d, ui_palette c, int start, int end){ int i; if (d->visual->class == StaticColor || d->visual->class == TrueColor) { for (i = start; i < end; i++) d->xcolor.c[i].pixel = i; XQueryColors (d->display, d->colormap, d->xcolor.c + start, end - start); for (i = start; i < end; i++) { c[i - start][0] = d->xcolor.c[i].red / 256; c[i - start][1] = d->xcolor.c[i].green / 256; c[i - start][2] = d->xcolor.c[i].blue / 256; } } else { for (i = start; i < end; i++) { d->xcolor.c[i].pixel = i; d->xcolor.c[i].flags = DoRed | DoGreen | DoBlue; d->xcolor.c[i].red = c[i - start][0] * 256; d->xcolor.c[i].green = c[i - start][1] * 256; d->xcolor.c[i].blue = c[i - start][2] * 256; } XStoreColors (d->display, d->colormap, d->xcolor.c + start, end - start); }}intxalloc_color (xdisplay * d, int r, int g, int b, int readwrite){ d->xcolor.n++; d->xcolor.c[d->xcolor.n - 1].flags = DoRed | DoGreen | DoBlue; d->xcolor.c[d->xcolor.n - 1].red = r; d->xcolor.c[d->xcolor.n - 1].green = g; d->xcolor.c[d->xcolor.n - 1].blue = b; d->xcolor.c[d->xcolor.n - 1].pixel = d->xcolor.n - 1; if ((readwrite && !d->fixedcolormap) || d->privatecolormap) { unsigned long cell; if (d->privatecolormap) { cell = d->xcolor.c[d->xcolor.n - 1].pixel += 16; if ((int) d->xcolor.c[d->xcolor.n - 1].pixel >= d->visual->map_entries) { d->xcolor.n--; return (-1); } } else { if (!XAllocColorCells (d->display, d->colormap, 0, 0, 0, &cell, 1)) { d->xcolor.n--; if (d->xcolor.n <= 32) printf ("Colormap is too full! close some colorfull applications or use -private\n"); return (-1); } d->xcolor.c[d->xcolor.n - 1].pixel = cell; } XStoreColor (d->display, d->colormap, &(d->xcolor.c[d->xcolor.n - 1])); return ((int) cell); } if (!XAllocColor (d->display, d->colormap, &(d->xcolor.c[d->xcolor.n - 1]))) { d->xcolor.n--; if (d->xcolor.n <= 32) printf ("Colormap is too full! close some colorfull aplications or use -private\n"); return (-1); } d->pixels[d->xcolor.n - 1] = d->xcolor.c[d->xcolor.n - 1].pixel; return (d->depth != 8 ? d->xcolor.n - 1 : (int) d->xcolor.c[d->xcolor.n - 1].pixel);}voidxfree_colors (xdisplay * d){ unsigned long pixels[256]; int i; for (i = 0; i < d->xcolor.n; i++) pixels[i] = d->xcolor.c[i].pixel; if (!d->privatecolormap) XFreeColors (d->display, d->colormap, pixels, d->xcolor.n, 0); d->xcolor.n = 0;}voidxfree_display (xdisplay * d){ XSync (d->display, 0); if (d->font_struct != (XFontStruct *) NULL) { XFreeFont (d->display, d->font_struct); } XUnmapWindow (d->display, d->window); XDestroyWindow (d->display, d->window); XCloseDisplay (d->display); free ((void *) d->attributes); free ((void *) d);}voidxclear_screen (xdisplay * d){ XClearWindow (d->display, d->window); d->screen_changed = 1;}voidxmoveto (xdisplay * d, int x, int y){ d->lastx = x, d->lasty = y;}intxsetfont (xdisplay * d, CONST char *font_name){ if (d->font_struct != (XFontStruct *) NULL) { XFreeFont (d->display, d->font_struct); } d->font_struct = XLoadQueryFont (d->display, font_name); XSetFont (d->display, d->gc, d->font_struct->fid); if (!d->font_struct) { fprintf (stderr, "could not load font: %s\n", font_name); exit (-1); } return (d->font_struct->max_bounds.ascent + d->font_struct->max_bounds.descent);}voidxouttext (xdisplay * d, CONST char *string){ int sz; sz = (int) strlen (string); XDrawImageString (d->display, d->window, d->gc, d->lastx, d->lasty, string, sz);}voidxresize (xdisplay * d, XEvent * ev){ XSync (d->display, False); d->width = ev->xconfigure.width; d->height = ev->xconfigure.height;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -