Browse Source

merged *{h,v} functions

master
Connor Lane Smith 15 years ago
parent
commit
b7695fa98c
  1. 77
      dmenu.c

77
dmenu.c

@ -25,12 +25,9 @@ struct Item {
}; };
static void appenditem(Item *item, Item **list, Item **last); static void appenditem(Item *item, Item **list, Item **last);
static void calcoffsetsh(void); static void calcoffsets(void);
static void calcoffsetsv(void);
static char *cistrstr(const char *s, const char *sub); static char *cistrstr(const char *s, const char *sub);
static void drawmenu(void); static void drawmenu(void);
static void drawmenuh(void);
static void drawmenuv(void);
static void grabkeyboard(void); static void grabkeyboard(void);
static void insert(const char *s, ssize_t n); static void insert(const char *s, ssize_t n);
static void keypress(XKeyEvent *e); static void keypress(XKeyEvent *e);
@ -63,7 +60,6 @@ static Window root, win;
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
static char *(*fstrstr)(const char *, const char *) = strstr; static char *(*fstrstr)(const char *, const char *) = strstr;
static void (*calcoffsets)(void) = calcoffsetsh;
void void
appenditem(Item *item, Item **list, Item **last) { appenditem(Item *item, Item **list, Item **last) {
@ -77,29 +73,25 @@ appenditem(Item *item, Item **list, Item **last) {
} }
void void
calcoffsetsh(void) { calcoffsets(void)
unsigned int w, x; {
unsigned int h, i, n;
w = promptw + inputw + textw(dc, "<") + textw(dc, ">"); h = dc->font.height+2;
for(x = w, next = curr; next; next = next->right) if(lines > 0)
if((x += MIN(textw(dc, next->text), mw / 3)) > mw) n = lines * h;
else
n = mw - (promptw + inputw + textw(dc, "<") + textw(dc, ">"));
prev = next = curr;
for(i = 0; next; next = next->right)
if((i += (lines > 0) ? h : MIN(textw(dc, next->text), mw/3)) > n)
break; break;
for(x = w, prev = curr; prev && prev->left; prev = prev->left) for(i = 0; prev && prev->left; prev = prev->left)
if((x += MIN(textw(dc, prev->left->text), mw / 3)) > mw) if((i += (lines > 0) ? h : MIN(textw(dc, prev->left->text), mw/3)) > n)
break; break;
} }
void
calcoffsetsv(void) {
unsigned int i;
next = prev = curr;
for(i = 0; i < lines && next; i++)
next = next->right;
for(i = 0; i < lines && prev && prev->left; i++)
prev = prev->left;
}
char * char *
cistrstr(const char *s, const char *sub) { cistrstr(const char *s, const char *sub) {
size_t len; size_t len;
@ -112,6 +104,8 @@ cistrstr(const char *s, const char *sub) {
void void
drawmenu(void) { drawmenu(void) {
Item *item;
dc->x = 0; dc->x = 0;
dc->y = 0; dc->y = 0;
drawrect(dc, 0, 0, mw, mh, BG(dc, normcol)); drawrect(dc, 0, 0, mw, mh, BG(dc, normcol));
@ -129,20 +123,19 @@ drawmenu(void) {
dc->w = inputw; dc->w = inputw;
drawtext(dc, text, normcol); drawtext(dc, text, normcol);
drawrect(dc, textnw(dc, text, cursor) + dc->h/2 - 2, 2, 1, dc->h - 4, FG(dc, normcol)); drawrect(dc, textnw(dc, text, cursor) + dc->h/2 - 2, 2, 1, dc->h - 4, FG(dc, normcol));
if(lines > 0)
drawmenuv();
else if(curr && (dc->w == inputw || curr->next))
drawmenuh();
commitdraw(dc, win);
}
void
drawmenuh(void) {
Item *item;
if(lines > 0) {
dc->y = topbar ? dc->h : 0;
dc->w = mw - dc->x;
for(item = curr; item != next; item = item->right) {
drawtext(dc, item->text, (item == sel) ? selcol : normcol);
dc->y += dc->h;
}
}
else if(curr && (dc->w == inputw || curr->next)) {
dc->x += inputw; dc->x += inputw;
dc->w = textw(dc, "<"); dc->w = textw(dc, "<");
if(curr->left) if(prev)
drawtext(dc, "<", normcol); drawtext(dc, "<", normcol);
for(item = curr; item != next; item = item->right) { for(item = curr; item != next; item = item->right) {
dc->x += dc->w; dc->x += dc->w;
@ -154,17 +147,7 @@ drawmenuh(void) {
if(next) if(next)
drawtext(dc, ">", normcol); drawtext(dc, ">", normcol);
} }
commitdraw(dc, win);
void
drawmenuv(void) {
Item *item;
dc->y = topbar ? dc->h : 0;
dc->w = mw - dc->x;
for(item = curr; item != next; item = item->right) {
drawtext(dc, item->text, (item == sel) ? selcol : normcol);
dc->y += dc->h;
}
} }
void void
@ -494,7 +477,6 @@ setup(void) {
y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh; y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh;
mw = DisplayWidth(dc->dpy, screen); mw = DisplayWidth(dc->dpy, screen);
} }
/* input window */ /* input window */
wa.override_redirect = True; wa.override_redirect = True;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
@ -543,8 +525,7 @@ main(int argc, char *argv[]) {
usage(); usage();
/* double flags */ /* double flags */
else if(!strcmp(argv[i], "-l")) { else if(!strcmp(argv[i], "-l")) {
if((lines = atoi(argv[++i])) > 0) lines = atoi(argv[++i]);
calcoffsets = calcoffsetsv;
} }
else if(!strcmp(argv[i], "-p")) else if(!strcmp(argv[i], "-p"))
prompt = argv[++i]; prompt = argv[++i];

Loading…
Cancel
Save