now procedural!
This commit is contained in:
parent
1faf2c9b8c
commit
ef4963523e
@ -3,16 +3,14 @@
|
||||
/* This is a hack I did years ago. Fork dmenu and start from there if you can.
|
||||
* ~ trinity */
|
||||
|
||||
#include <locale.h>
|
||||
#include <locale.h> /* setlocale(3), LC_CTYPE */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <string.h> /* strlen(3) */
|
||||
#include <sysexits.h> /* EX_USAGE */
|
||||
#include <unistd.h>
|
||||
#include <unistd.h> /* getopt(3) */
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
#ifdef XINERAMA
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
@ -25,16 +23,13 @@
|
||||
/* macros */
|
||||
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
|
||||
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
|
||||
/* enums */
|
||||
enum { Scheme, SchemeLast }; /* color schemes */
|
||||
/* enumerated because Suckless has SchemeNorm, SchemeSel, etc.
|
||||
* should be made into like one char *Scheme[2] */
|
||||
/* BTW SchemeLast is the size of an array of the schemes and it's used
|
||||
* in this program for iteration. Assumes enums will be assigned
|
||||
* 0,1,2,3... */
|
||||
* in this program for iteration. */
|
||||
|
||||
static char *embed;
|
||||
static int bh, mw, mh;
|
||||
@ -42,7 +37,6 @@ static int inputw = 0;
|
||||
static int lrpad; /* sum of left and right padding */
|
||||
static int mon = -1, screen;
|
||||
|
||||
static Atom clip, utf8;
|
||||
static Display *dpy;
|
||||
static Window root, parentwin, win;
|
||||
|
||||
@ -51,41 +45,10 @@ static Clr *scheme[SchemeLast];
|
||||
|
||||
#include "config.h"
|
||||
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < SchemeLast; i++)
|
||||
free(scheme[i]);
|
||||
drw_free(drw);
|
||||
XSync(dpy, False);
|
||||
XCloseDisplay(dpy);
|
||||
}
|
||||
|
||||
int
|
||||
textw(char *text) /* figure out how to remove me */
|
||||
{
|
||||
return (text && *text) ? TEXTW(text) - lrpad / 4 : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
drawmenu(char *text)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
drw_setscheme(drw, scheme[Scheme]);
|
||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||
|
||||
if (text && *text)
|
||||
x = drw_text(drw, x, 0, textw(text), bh, lrpad / 2, text, 0);
|
||||
|
||||
drw_map(drw, win, 0, 0, mw, mh);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
main(int argc, char *argv[]){
|
||||
int c;
|
||||
extern char *optarg;
|
||||
char text[text_s];
|
||||
int x, y, i, j;
|
||||
unsigned int du;
|
||||
@ -102,30 +65,37 @@ main(int argc, char *argv[])
|
||||
for(i = 0; i < text_s; ++i) /* initialize text[] */
|
||||
text[i] = '\0';
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */
|
||||
while((c = getopt(argc, argv, ":bf:m:B:F:w:")) != -1)
|
||||
switch(c){
|
||||
case 'b':
|
||||
topbar = 0;
|
||||
else if (i + 1 == argc){
|
||||
usage: fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n"
|
||||
"(-cb [color]) (-cf [color]) (-w [windowid])\n",
|
||||
break;
|
||||
case 'B': if(optarg){
|
||||
colors[Scheme][ColBg] = optarg;
|
||||
break;
|
||||
}case 'f': if(optarg){
|
||||
fonts[0] = optarg;
|
||||
break;
|
||||
}case 'F': if(optarg){
|
||||
colors[Scheme][ColFg] = argv[++i];
|
||||
break;
|
||||
}case 'm': if(optarg){
|
||||
mon = atoi(argv[++i]);
|
||||
break;
|
||||
}case 'w': if(optarg){
|
||||
embed = argv[++i];
|
||||
break;
|
||||
}default: /* optarg==0 falls through */
|
||||
fprintf(stderr,
|
||||
"Usage: %s (-b) (-B [background color])"
|
||||
"(-f [font]) (-F foreground color)\n"
|
||||
"\t(-m [monitor]) (-w [windowid)\n",
|
||||
argv[0]);
|
||||
return EX_USAGE;
|
||||
/* these options take one argument */
|
||||
}else if (!strcmp(argv[i], "-m"))
|
||||
mon = atoi(argv[++i]);
|
||||
else if (!strcmp(argv[i], "-fn")) /* font or font set */
|
||||
fonts[0] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-cb")) /* bg color */
|
||||
colors[Scheme][ColBg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-cf")) /* fg color */
|
||||
colors[Scheme][ColFg] = argv[++i];
|
||||
else if (!strcmp(argv[i], "-w")) /* embedding window id */
|
||||
embed = argv[++i];
|
||||
else
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||
fputs("warning: no locale support\n", stderr);
|
||||
fprintf(stderr, "%s: No locale support.\n", argv[0]);
|
||||
if (!(dpy = XOpenDisplay(NULL)))
|
||||
die("cannot open display");
|
||||
screen = DefaultScreen(dpy);
|
||||
@ -136,7 +106,7 @@ usage: fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n"
|
||||
die("could not get embedding window attributes: 0x%lx",
|
||||
parentwin);
|
||||
drw = drw_create(dpy, screen, root, wa.width, wa.height);
|
||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||
if (!drw_fontset_create(drw, fonts, (sizeof fonts) / (sizeof *fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h;
|
||||
|
||||
@ -150,9 +120,6 @@ usage: fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n"
|
||||
for (j = 0; j < SchemeLast; j++)
|
||||
scheme[j] = drw_scm_create(drw, colors[j], 2);
|
||||
|
||||
clip = XInternAtom(dpy, "CLIPBOARD", False);
|
||||
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
|
||||
/* calculate menu geometry */
|
||||
bh = drw->fonts->h + 2;
|
||||
mh = bh;
|
||||
@ -223,9 +190,25 @@ usage: fprintf(stderr, "Usage: %s (-b) (-fn [font]) (-m [monitor]\n"
|
||||
/* fgets adds a newline which will be printable in some fonts */
|
||||
if (strlen(text) > 0)
|
||||
text[strlen(text)-1] = '\0';
|
||||
drawmenu(text);
|
||||
drw_setscheme(drw, scheme[Scheme]);
|
||||
drw_rect(drw, 0, 0, mw, mh, 1, 1);
|
||||
|
||||
if(*text != '\0')
|
||||
drw_text(drw, x, 0,
|
||||
*text != '\0'
|
||||
? (drw_fontset_getwidth(drw, text)
|
||||
+ lrpad) - lrpad / 4
|
||||
: 0,
|
||||
bh, lrpad / 2, text, 0);
|
||||
|
||||
drw_map(drw, win, 0, 0, mw, mh);
|
||||
} while (fgets(text, text_s, stdin) != NULL || !BREAK_ON_EOF);
|
||||
|
||||
cleanup();
|
||||
for (i = 0; i < SchemeLast; i++)
|
||||
free(scheme[i]);
|
||||
drw_free(drw);
|
||||
XSync(dpy, False);
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user