Ejemplo n.º 1
0
Archivo: dmenu.c Proyecto: Loomx/Git
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 */
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
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 */
}