wlwin.c
来自「细胞自动机的一个源代码」· C语言 代码 · 共 193 行
C
193 行
#include "wlwin.h"void checkerrfunc(char *s, int e) { if (!e) { fprintf(stderr, "ERROR: %s ==> 0", s); }}int wlinit(wlWindow *w, int argc, char *argv[]) { int def_config[] = {GLX_DOUBLEBUFFER, GLX_RGBA, GLX_DEPTH_SIZE, 16, None}; int i, j, e; XStandardColormap *stdCmaps; w->g_config = (int *)malloc(sizeof(def_config)); memcpy(w->g_config, def_config, sizeof(def_config)); w->g_dispname = NULL; w->g_dpy = XOpenDisplay(w->g_dispname); checkerr((w->g_dpy)); e = glXQueryExtension(w->g_dpy, NULL, NULL); checkerr(e); w->g_vi = glXChooseVisual(w->g_dpy, DefaultScreen(w->g_dpy), w->g_config); checkerr(w->g_vi); checkerr((w->g_vi->class == TrueColor)); if (XmuLookupStandardColormap(w->g_dpy, w->g_vi->screen, w->g_vi->visualid, w->g_vi->depth, XA_RGB_DEFAULT_MAP, False, True)) { if (XGetRGBColormaps(w->g_dpy, RootWindow(w->g_dpy, w->g_vi->screen), &stdCmaps, &j, XA_RGB_DEFAULT_MAP)) { for (i=0; i<j; i++) { if (stdCmaps[i].visualid == w->g_vi->visualid) { w->g_cm = stdCmaps[i].colormap; XFree(stdCmaps); break; } } checkerr((i!=j)); } } else { w->g_cm = XCreateColormap(w->g_dpy, RootWindow(w->g_dpy, w->g_vi->screen), w->g_vi->visual, AllocNone); } w->g_cx = glXCreateContext(w->g_dpy, w->g_vi, NULL, True); checkerr(w->g_cx); w->g_szHints.flags = 0; w->g_szHints.flags |= PAspect | USSize; w->g_szHints.width = WL_W; w->g_szHints.height = WL_H; w->g_szHints.x = w->g_szHints.max_aspect.x = WL_W; w->g_szHints.y = w->g_szHints.max_aspect.y = WL_H; w->g_swa.colormap = w->g_cm; w->g_swa.border_pixel = 0; w->g_swa.event_mask = ExposureMask | StructureNotifyMask | \ ButtonPressMask | ButtonMotionMask | ButtonReleaseMask | \ KeyPressMask | KeyReleaseMask; w->g_win = XCreateWindow(w->g_dpy, RootWindow(w->g_dpy, w->g_vi->screen), w->g_szHints.x, w->g_szHints.y, WL_W, WL_H, 0, w->g_vi->depth, InputOutput, w->g_vi->visual, CWBorderPixel | CWColormap | CWEventMask, &(w->g_swa)); w->g_gcvals.line_width = 5; w->g_gcvals.foreground = 45; w->g_gc = XCreateGC(w->g_dpy, w->g_win, GCForeground|GCLineWidth, &(w->g_gcvals)); XSetStandardProperties(w->g_dpy, w->g_win, "CAGL", "cagl", None, argv, argc, &(w->g_szHints)); w->g_wmHints = XAllocWMHints(); w->g_wmHints->initial_state = NormalState; w->g_wmHints->flags = StateHint; XSetWMHints(w->g_dpy, w->g_win, w->g_wmHints); w->g_wmDeleteWindow = XInternAtom(w->g_dpy, "WM_DELETE_WINDOW", False); XSetWMProtocols(w->g_dpy, w->g_win, &(w->g_wmDeleteWindow), 1); glXMakeCurrent(w->g_dpy, w->g_win, w->g_cx); XMapWindow(w->g_dpy, w->g_win); return(0);}int should_disp=0;int wlmain(wlWindow *w) { XEvent e; KeySym ks; if ((!should_disp) && (!XPending(w->g_dpy))) { (*(w->g_idle))(); return(0); } while (XPending(w->g_dpy)) { XNextEvent(w->g_dpy, &e); switch (e.type) { case ConfigureNotify: //printf("ConfigureNotify\n"); // (*(w->g_config))(e.xconfigure.width, // e.xconfigure.height); (*(w->g_confignotify))(e.xconfigure.width, e.xconfigure.height); should_disp=1; break; case Expose: //printf("Expose\n"); should_disp=1; //(*(w->g_disp))(); break; case MotionNotify: //printf("MotionNotify\n"); (*(w->g_motion))(e.xmotion.x, e.xmotion.y, e.xmotion.state); break; case ButtonPress: //printf("ButtonPress\n"); (*(w->g_butt))(e.xbutton.x, e.xbutton.y, e.xbutton.type, e.xbutton.button); break; case ButtonRelease: //printf("ButtonRelease\n"); (*(w->g_butt))(e.xbutton.x, e.xbutton.y, e.xbutton.type, e.xbutton.button); break; case KeyPress: //printf("KeyPress\n"); ks = XLookupKeysym((XKeyEvent *) &e, 0); (*(w->g_key))(ks, e.type); //e.xkey.state); break; case KeyRelease: //printf("KeyRelease\n"); ks = XLookupKeysym((XKeyEvent *) &e, 0); (*(w->g_key))(ks, e.type); //e.xkey.state); break; case ClientMessage: printf("gotta go\n"); exit(0); break; } } if (should_disp) { (*(w->g_disp))(); } should_disp=0; return(0);}void wlpostredisplay() { should_disp=1;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?