merged *{h,v} functions
This commit is contained in:
parent
b54c179d58
commit
b7695fa98c
1 changed files with 42 additions and 61 deletions
91
dmenu.c
91
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,42 +123,31 @@ 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;
|
|
||||||
|
|
||||||
dc->x += inputw;
|
|
||||||
dc->w = textw(dc, "<");
|
|
||||||
if(curr->left)
|
|
||||||
drawtext(dc, "<", normcol);
|
|
||||||
for(item = curr; item != next; item = item->right) {
|
|
||||||
dc->x += dc->w;
|
|
||||||
dc->w = MIN(textw(dc, item->text), mw / 3);
|
|
||||||
drawtext(dc, item->text, (item == sel) ? selcol : normcol);
|
|
||||||
}
|
|
||||||
dc->w = textw(dc, ">");
|
|
||||||
dc->x = mw - dc->w;
|
|
||||||
if(next)
|
|
||||||
drawtext(dc, ">", normcol);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drawmenuv(void) {
|
|
||||||
Item *item;
|
|
||||||
|
|
||||||
|
if(lines > 0) {
|
||||||
dc->y = topbar ? dc->h : 0;
|
dc->y = topbar ? dc->h : 0;
|
||||||
dc->w = mw - dc->x;
|
dc->w = mw - dc->x;
|
||||||
for(item = curr; item != next; item = item->right) {
|
for(item = curr; item != next; item = item->right) {
|
||||||
drawtext(dc, item->text, (item == sel) ? selcol : normcol);
|
drawtext(dc, item->text, (item == sel) ? selcol : normcol);
|
||||||
dc->y += dc->h;
|
dc->y += dc->h;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if(curr && (dc->w == inputw || curr->next)) {
|
||||||
|
dc->x += inputw;
|
||||||
|
dc->w = textw(dc, "<");
|
||||||
|
if(prev)
|
||||||
|
drawtext(dc, "<", normcol);
|
||||||
|
for(item = curr; item != next; item = item->right) {
|
||||||
|
dc->x += dc->w;
|
||||||
|
dc->w = MIN(textw(dc, item->text), mw/3);
|
||||||
|
drawtext(dc, item->text, (item == sel) ? selcol : normcol);
|
||||||
|
}
|
||||||
|
dc->w = textw(dc, ">");
|
||||||
|
dc->x = mw - dc->w;
|
||||||
|
if(next)
|
||||||
|
drawtext(dc, ">", normcol);
|
||||||
|
}
|
||||||
|
commitdraw(dc, win);
|
||||||
}
|
}
|
||||||
|
|
||||||
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…
Reference in a new issue