int main(int argc, char *argv[]) { Bool fast = False; int i; if(strcmp(argv[0], "dmenu_run") == 0) /* called as `dmenu_run' */ dmenurun = True; for(i = 1; i < argc; i++) /* these options take no arguments */ if(!strcmp(argv[i], "-v")) { /* prints version information */ puts("dmenu-"VERSION", © 2006-2014 dmenu engineers, see LICENSE for details"); exit(EXIT_SUCCESS); } else if(!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ topbar = False; else if(!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ fast = True; else if(!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ fstrncmp = strncasecmp; fstrstr = cistrstr; } else if(i+1 == argc) usage(); /* these options take one argument */ else if(!strcmp(argv[i], "-l")) /* number of lines in vertical list */ lines = atoi(argv[++i]); else if(!strcmp(argv[i], "-m")) mon = atoi(argv[++i]); else if(!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ prompt = argv[++i]; else if(!strcmp(argv[i], "-fn")) /* font or font set */ font = argv[++i]; else if(!strcmp(argv[i], "-nb")) /* normal background color */ normbgcolor = argv[++i]; else if(!strcmp(argv[i], "-nf")) /* normal foreground color */ normfgcolor = argv[++i]; else if(!strcmp(argv[i], "-sb")) /* selected background color */ selbgcolor = argv[++i]; else if(!strcmp(argv[i], "-sf")) /* selected foreground color */ selfgcolor = argv[++i]; else usage(); dc = initdc(); initfont(dc, font); if(fast) { grabkeyboard(); readstdin(); } else { readstdin(); grabkeyboard(); } setup(); run(); return 1; /* unreachable */ }
/* * Term hook * Initialize a new term */ static void term_init_svgalib(term *t) { int vgamode; /* Only one term */ (void) t; vga_init(); /* The palette is 256x3 bytes big (RGB). */ C_MAKE(pal, 768, byte); #ifdef USE_GRAPHICS /* Hardwire this mode in for now */ vgamode = G1024x768x256; /* Set up the bitmap buffer context */ gl_setcontextvgavirtual(vgamode); buffer = gl_allocatecontext(); gl_getcontext(buffer); /* Load bitmap into virtual screen */ term_load_bitmap(); #endif /* USE_GRAPHICS */ /* Hardwire this mode in for now */ vgamode = G640x480x256; /* Set up the physical screen context */ if (vga_setmode(vgamode) < 0) { quit("Graphics mode not available!"); } gl_setcontextvga(vgamode); screen = gl_allocatecontext(); gl_getcontext(screen); /* Is this needed? */ gl_enablepageflipping(screen); /* Set up palette colors */ setpal(); /* Load the character font data */ initfont(); /* Color 0 isn't transparent */ gl_setwritemode(WRITEMODE_OVERWRITE); }
void creategui() { int x, y, w = width, h = height; XSetWindowAttributes wa; if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("no locale support\n", stderr); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); initfont(font); cursor = XCreateFontCursor(dpy, XC_left_ptr); dc.norm[ColBG] = getcolor(normbgcolor); dc.norm[ColFG] = getcolor(normfgcolor); dc.sel[ColBG] = getcolor(selbgcolor); dc.sel[ColFG] = getcolor(selfgcolor); dc.drawable = XCreatePixmap(dpy, root, w, 2 * h, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, NULL); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); if (!dc.font.set) XSetFont(dpy, dc.gc, dc.font.xfont->fid); wa.cursor = cursor; wa.background_pixel = dc.norm[ColBG]; XChangeWindowAttributes(dpy, root, CWBackPixel|CWCursor, &wa); x = (DisplayWidth(dpy, screen) - w) / 2; y = DisplayHeight(dpy, screen) / 2; createinput(userprompt, x, y - h, w, h, innerpx, False); createinput(passprompt, x, y, w, h, innerpx, True); im = XOpenIM(dpy, NULL, NULL, NULL); ic = XCreateIC(im, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, inputs->win, XNFocusWindow, inputs->win, NULL); }
int main(int argc, char *argv[]) { Bool fast = False; int i; for(i = 1; i < argc; i++) /* these options take no arguments */ if(!strcmp(argv[i], "-v")) { /* prints version information */ puts("dmenu-"VERSION", © 2006-2012 dmenu engineers, see LICENSE for details"); exit(EXIT_SUCCESS); } else if(!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ topbar = False; else if(!strcmp(argv[i], "-q")) quiet = True; else if(!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ fast = True; else if(!strcmp(argv[i], "-z")) /* enable fuzzy matching */ fuzzy = True; else if(!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ fstrncmp = strncasecmp; fstrstr = cistrstr; fstrchr = strchri; } else if(i+1 == argc) usage(); /* these options take one argument */ else if(!strcmp(argv[i], "-x")) xoffset = atoi(argv[++i]); else if(!strcmp(argv[i], "-y")) yoffset = atoi(argv[++i]); else if(!strcmp(argv[i], "-w")) width = atoi(argv[++i]); else if(!strcmp(argv[i], "-l")) /* number of lines in vertical list */ lines = atoi(argv[++i]); else if(!strcmp(argv[i], "-h")) /* minimum height of single line */ line_height = atoi(argv[++i]); else if(!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ prompt = argv[++i]; else if(!strcmp(argv[i], "-fn")) /* font or font set */ font = argv[++i]; else if(!strcmp(argv[i], "-nb")) /* normal background color */ normbgcolor = argv[++i]; else if(!strcmp(argv[i], "-nf")) /* normal foreground color */ normfgcolor = argv[++i]; else if(!strcmp(argv[i], "-sb")) /* selected background color */ selbgcolor = argv[++i]; else if(!strcmp(argv[i], "-sf")) /* selected foreground color */ selfgcolor = argv[++i]; else usage(); dc = initdc(); initfont(dc, font ? font : DEFFONT); normcol = initcolor(dc, normfgcolor, normbgcolor); selcol = initcolor(dc, selfgcolor, selbgcolor); if(fast) { grabkeyboard(); readstdin(); } else { readstdin(); grabkeyboard(); } setup(); run(); cleanup(); return ret; }
void setup(int topbar, const char *bg, unsigned int lines) { int x = 0, y = 0; /* position of the window */ /* if (!dc) { */ dc = initdc(); /* } */ initfont(dc, font); XInitThreads(); screen = DefaultScreen(dc->dpy); Window root = RootWindow(dc->dpy, screen); XSetWindowAttributes swa; XIM xim; #ifdef XINERAMA int n; XineramaScreenInfo *info; #endif clip = XInternAtom(dc->dpy, "CLIPBOARD", False); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); /* calculate menu geometry */ bh = dc->font.height + 2; lines = MAX(lines, 0); mh = (lines + 1) * bh; #ifdef XINERAMA if((info = XineramaQueryScreens(dc->dpy, &n))) { int a, j, di, i = 0, area = 0; unsigned int du; Window w, pw, dw, *dws; XWindowAttributes wa; XGetInputFocus(dc->dpy, &w, &di); if(w != root && w != PointerRoot && w != None) { /* find top-level window containing current input focus */ do { if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws) XFree(dws); } while(w != root && w != pw); /* find xinerama screen with which the window intersects most */ if(XGetWindowAttributes(dc->dpy, pw, &wa)) for(j = 0; j < n; j++) if((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { area = a; i = j; } } /* no focused window is on screen, so use pointer location instead */ if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) for(i = 0; i < n; i++) if(INTERSECT(x, y, 1, 1, info[i])) break; x = info[i].x_org; y = info[i].y_org + (topbar ? 0 : info[i].height - mh); mw = info[i].width; XFree(info); } else #endif { x = 0; y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; mw = DisplayWidth(dc->dpy, screen); } /* create menu window */ swa.override_redirect = True; swa.background_pixel = getcolor(dc, bg); swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0, DefaultDepth(dc->dpy, screen), CopyFromParent, DefaultVisual(dc->dpy, screen), CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); XResizeWindow(dc->dpy, win, mw, mh); /* open input methods */ xim = XOpenIM(dc->dpy, NULL, NULL, NULL); xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, XNFocusWindow, win, NULL); XMapRaised(dc->dpy, win); resizedc(dc, mw, mh); mapdc(dc, win, mw, mh); }
void setup(void) { XSetWindowAttributes wa; XTextProperty str; XSizeHints *sizeh; XClassHint *ch; int i, sh, sw, ls; /* init screen */ screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); sw = DisplayWidth(dpy, screen) - 1; sh = DisplayHeight(dpy, screen) - 1; initfont(font); /* init atoms */ /* init appearance */ for (i = 0, www = 0; i < nentries; i++) { ls = textnw(entries[i]->label, strlen(entries[i]->label)); if (ls > www) www = ls; } www *= widthscaling; if (!ww) { if (horizontal) { ww = www * nentries; } else { ww = www; } } if (!wh) { if (horizontal) { wh = dc.font.height * heightscaling; } else { wh = nentries * dc.font.height * heightscaling; } } if (!wy) wy = (sh - wh) / 2; if (wy < 0) wy = sh + wy - wh; if (!wx) wx = (sw - ww) / 2; if (wx < 0) wx = sw + wx - ww; dc.norm[ColBG] = getcolor(normbgcolor); dc.norm[ColFG] = getcolor(normfgcolor); dc.press[ColBG] = getcolor(pressbgcolor); dc.press[ColFG] = getcolor(pressfgcolor); dc.high[ColBG] = getcolor(highlightbgcolor); dc.high[ColFG] = getcolor(highlightfgcolor); dc.drawable = XCreatePixmap(dpy, root, ww, wh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); if(!dc.font.set) XSetFont(dpy, dc.gc, dc.font.xfont->fid); for(i = 0; i < nentries; i++) entries[i]->pressed = 0; wa.override_redirect = !wmborder; wa.border_pixel = dc.norm[ColFG]; wa.background_pixel = dc.norm[ColBG]; win = XCreateWindow(dpy, root, wx, wy, ww, wh, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect | CWBorderPixel | CWBackingPixel, &wa); XSelectInput(dpy, win, StructureNotifyMask|KeyReleaseMask| ButtonReleaseMask|ButtonPressMask| ExposureMask|LeaveWindowMask|PointerMotionMask); sizeh = XAllocSizeHints(); sizeh->flags = PMaxSize | PMinSize; sizeh->min_width = sizeh->max_width = ww; sizeh->min_height = sizeh->max_height = wh; XStringListToTextProperty(&name, 1, &str); ch = XAllocClassHint(); ch->res_class = name; ch->res_name = name; XSetWMProperties(dpy, win, &str, &str, NULL, 0, sizeh, NULL, ch); XFree(ch); XFree(str.value); XFree(sizeh); XMapRaised(dpy, win); updateentries(); drawmenu(); }
Bool loadfont(DC *dc, const char *fontstr) { initfont(dc,fontstr); return True; }
int main(int argc, char *argv[]) { int i; progname = "dmenu"; for(i = 1; i < argc; i++) /* single flags */ if(!strcmp(argv[i], "-v") || !strcmp(argv[1], "--version")) { fputs("dmenu-"VERSION", © 2006-2011 dmenu engineers, see LICENSE for details\n", stdout); exit(EXIT_SUCCESS); } else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--bottom")) topbar = False; else if(!strcmp(argv[i], "-e") || !strcmp(argv[i], "--echo")) message = True; else if(!strcmp(argv[i], "-ec") || !strcmp(argv[i], "--echo-centre")) message = True, messageposition = CENTRE; else if(!strcmp(argv[i], "-er") || !strcmp(argv[i], "--echo-right")) message = True, messageposition = RIGHT; else if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--insensitive")) fstrncmp = strncasecmp; else if(!strcmp(argv[i], "-r") || !strcmp(argv[i], "--return-early")) returnearly = True; else if(i==argc-1) usage(); /* opts that need 1 arg */ else if(!strcmp(argv[i], "-et") || !strcmp(argv[i], "--echo-timeout")) timeout = atoi(argv[++i]); else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--height")) height = atoi(argv[++i]); else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--lines")) lines = atoi(argv[++i]); else if(!strcmp(argv[i], "-m") || !strcmp(argv[i], "--monitor")) monitor = atoi(argv[++i]); else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--prompt")) prompt = argv[++i]; else if(!strcmp(argv[i], "-po") || !strcmp(argv[i], "--prompt-only")) prompt = argv[++i], nostdin = True; else if(!strcmp(argv[i], "-fn") || !strcmp(argv[i], "--font-name")) font = argv[++i]; else if(!strcmp(argv[i], "-nb") || !strcmp(argv[i], "--normal-background")) normbgcolor = argv[++i]; else if(!strcmp(argv[i], "-nf") || !strcmp(argv[i], "--normal-foreground")) normfgcolor = argv[++i]; else if(!strcmp(argv[i], "-sb") || !strcmp(argv[i], "--selected-background")) selbgcolor = argv[++i]; else if(!strcmp(argv[i], "-sf") || !strcmp(argv[i], "--selected-foreground")) selfgcolor = argv[++i]; else usage(); if(message) { signal(SIGALRM, alarmhandler); alarm(timeout); } dc = initdc(); initfont(dc, font); if(!nostdin) { readstdin(); } setup(); run(); return EXIT_FAILURE; /* should not reach */ }
int main(void) { int count = 0; int G_pressed = 0, R_pressed = 1; char vstring[10], wstring[10]; double x1_old, y1_old; double x2_old, y2_old; double x1_new, y1_new; double x2_new, y2_new; double vx, vy, wx, wy; double v, w; posvel pv; x1_old = 100.0; y1_old = 100.0; vx = 10.0; vy = 5.0; x2_old = 250.0; y2_old = 250.0; wx = -8.0; wy = 4.0; v = sqrt(pow(wx,2)+pow(wy,2)); w = sqrt(pow(vx,2)+pow(vy,2)); /* open the graphics window */ initwindow(XWINDOW, YWINDOW); /* allow mouse operations */ initmouse(); /* allow keyboard operations */ initkeyboard(); /* create an event queue */ create_event_queue(); /* register display, mouse and keyboard as event sources */ reg_display_events(); reg_mouse_events(); reg_keyboard_events(); /* initialize the font */ initfont(); outtextxy(4,5,"To quit press left mouse button or close graphics window"); outtextxy(4,15,"To pause press right mouse button"); outtextxy(4,25,"To change ball speed use arrow keys (up/down = red, left/right = blue)"); outtextxy(4,35,"To make the red ball green press G or g "); do { if (check_if_event()) { /* wait for event */ wait_for_event(); if (event_close_display()) break; else if (event_mouse_button_down()) { if (event_mouse_left_button_down()) break; else if (event_mouse_right_button_down()) wait_for_event(); } else if (event_key_down()) { /* change speed of first ball */ if(event_key_up_arrow()) { vx = 1.25*vx; vy = 1.25*vy; } else if(event_key_down_arrow()) { vx = 0.75*vx; vy = 0.75*vy; } else if(event_key_left_arrow()) { wx = 0.75*wx; wy = 0.75*wy; } else if(event_key_right_arrow()) { wx = 1.25*wx; wy = 1.25*wy; } if (event_key('G')) { G_pressed = 1; R_pressed = 0; } else if (event_key('R')) { R_pressed = 1; G_pressed = 0; } } } v = sqrt(pow(wx,2)+pow(wy,2)); w = sqrt(pow(vx,2)+pow(vy,2)); /* calculate new ball positions */ x1_new = x1_old + vx*TICK; y1_new = y1_old + vy*TICK; x2_new = x2_old + wx*TICK; y2_new = y2_old + wy*TICK; /* handle what to do if balls hit boundaries */ pv = hit_boundary(x1_new, vx, 1); x1_new = pv.pos; vx = pv.vel; pv = hit_boundary(x2_new, wx, 1); x2_new = pv.pos; wx = pv.vel; pv = hit_boundary(y1_new, vy, 0); y1_new = pv.pos; vy = pv.vel; pv = hit_boundary(y2_new, wy, 0); y2_new = pv.pos; wy = pv.vel; /* draw balls on screen buffer in new positions */ filled_circle(x1_new, y1_new, RADIUS , BLUE); if (G_pressed) filled_circle(x2_new, y2_new, RADIUS , GREEN); else if (R_pressed) filled_circle(x2_new, y2_new, RADIUS , RED); /* make the balls visible on the screen display and remove the balls in the previous positions */ sprintf(vstring, "%4.2lf", v); sprintf(wstring, "%4.2lf", w); setcolor(RED); outtextxy(VEL_TEXT_X,VEL_TEXT_Y,"v = "); /* clear area for numeric output */ filled_rectangle(VEL_TEXT_X+40, VEL_TEXT_Y-10, VEL_TEXT_X+100, VEL_TEXT_Y+20, BLACK); outtextxy(VEL_TEXT_X+60,VEL_TEXT_Y,vstring); setcolor(BLUE); outtextxy(VEL_TEXT_X+120,VEL_TEXT_Y,"w = "); /* clear area for numeric output */ filled_rectangle(VEL_TEXT_X+160, VEL_TEXT_Y-10, VEL_TEXT_X+220, VEL_TEXT_Y+20, BLACK); outtextxy(VEL_TEXT_X+180,VEL_TEXT_Y,wstring); update_display(); /* remove the balls in the previous positions on the screen buffer */ filled_circle(x1_old, y1_old, RADIUS , BLACK); filled_circle(x2_old, y2_old, RADIUS , BLACK); /* update the old positions */ x1_old = x1_new; y1_old = y1_new; x2_old = x2_new; y2_old = y2_new; count++; pausefor(8); /* wait 8 miliseconds */ } while (count < MAXCOUNT); /* close the mouse */ closemouse(); /* remove the display */ closegraph(); return 0; }