diff options
| author | Connor Lane Smith <cls@lubutu.com> | 2010-08-10 13:38:49 +0100 |
|---|---|---|
| committer | Connor Lane Smith <cls@lubutu.com> | 2010-08-10 13:38:49 +0100 |
| commit | caf524626894bdee3756c4065bca44152d0efe9a (patch) | |
| tree | 9ee7ec6fe548c15b3b8a8e512d37a1dda4670666 | |
| parent | 93af72e116a528baac490e528b416dee65c79d3e (diff) | |
simplifications
| -rw-r--r-- | config.mk | 1 | ||||
| -rw-r--r-- | dmenu.c | 32 |
2 files changed, 14 insertions, 19 deletions
| @@ -7,7 +7,6 @@ VERSION = 4.2 | |||
| 7 | PREFIX = /usr/local | 7 | PREFIX = /usr/local |
| 8 | MANPREFIX = ${PREFIX}/share/man | 8 | MANPREFIX = ${PREFIX}/share/man |
| 9 | 9 | ||
| 10 | # Xlib | ||
| 11 | X11INC = /usr/X11R6/include | 10 | X11INC = /usr/X11R6/include |
| 12 | X11LIB = /usr/X11R6/lib | 11 | X11LIB = /usr/X11R6/lib |
| 13 | 12 | ||
| @@ -4,8 +4,8 @@ | |||
| 4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | #include <unistd.h> | 6 | #include <unistd.h> |
| 7 | #include <X11/Xatom.h> | ||
| 8 | #include <X11/Xlib.h> | 7 | #include <X11/Xlib.h> |
| 8 | #include <X11/Xatom.h> | ||
| 9 | #include <X11/Xutil.h> | 9 | #include <X11/Xutil.h> |
| 10 | #ifdef XINERAMA | 10 | #ifdef XINERAMA |
| 11 | #include <X11/extensions/Xinerama.h> | 11 | #include <X11/extensions/Xinerama.h> |
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <draw.h> | 13 | #include <draw.h> |
| 14 | 14 | ||
| 15 | #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) | 15 | #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) |
| 16 | #define LINEH (dc->font.height + 2) | ||
| 16 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | 17 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
| 17 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) | 18 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
| 18 | #define UTF8_CODEPOINT(c) (((c) & 0xc0) != 0x80) | 19 | #define UTF8_CODEPOINT(c) (((c) & 0xc0) != 0x80) |
| @@ -38,7 +39,7 @@ static void run(void); | |||
| 38 | static void setup(void); | 39 | static void setup(void); |
| 39 | static void usage(void); | 40 | static void usage(void); |
| 40 | 41 | ||
| 41 | static char text[4096]; | 42 | static char text[BUFSIZ]; |
| 42 | static size_t cursor = 0; | 43 | static size_t cursor = 0; |
| 43 | static const char *prompt = NULL; | 44 | static const char *prompt = NULL; |
| 44 | static const char *normbgcolor = "#cccccc"; | 45 | static const char *normbgcolor = "#cccccc"; |
| @@ -74,21 +75,18 @@ appenditem(Item *item, Item **list, Item **last) { | |||
| 74 | 75 | ||
| 75 | void | 76 | void |
| 76 | calcoffsets(void) { | 77 | calcoffsets(void) { |
| 77 | unsigned int h, i, n; | 78 | unsigned int i, n; |
| 78 | 79 | ||
| 79 | h = dc->font.height+2; | ||
| 80 | if(lines > 0) | 80 | if(lines > 0) |
| 81 | n = lines * h; | 81 | n = lines * LINEH; |
| 82 | else | 82 | else |
| 83 | n = mw - (promptw + inputw + textw(dc, "<") + textw(dc, ">")); | 83 | n = mw - (promptw + inputw + textw(dc, "<") + textw(dc, ">")); |
| 84 | 84 | ||
| 85 | prev = next = curr; | 85 | for(i = 0, next = curr; i <= n && next; next = next->right) |
| 86 | for(i = 0; next; next = next->right) | 86 | i += (lines > 0) ? LINEH : MIN(textw(dc, next->text), mw/3); |
| 87 | if((i += (lines > 0) ? h : MIN(textw(dc, next->text), mw/3)) > n) | 87 | |
| 88 | break; | 88 | for(i = 0, prev = curr; i <= n && prev && prev->left; prev = prev->left) |
| 89 | for(i = 0; prev && prev->left; prev = prev->left) | 89 | i += (lines > 0) ? LINEH : MIN(textw(dc, prev->left->text), mw/3); |
| 90 | if((i += (lines > 0) ? h : MIN(textw(dc, prev->left->text), mw/3)) > n) | ||
| 91 | break; | ||
| 92 | } | 90 | } |
| 93 | 91 | ||
| 94 | char * | 92 | char * |
| @@ -108,9 +106,8 @@ drawmenu(void) { | |||
| 108 | 106 | ||
| 109 | dc->x = 0; | 107 | dc->x = 0; |
| 110 | dc->y = 0; | 108 | dc->y = 0; |
| 109 | dc->h = LINEH; | ||
| 111 | drawrect(dc, 0, 0, mw, mh, BG(dc, normcol)); | 110 | drawrect(dc, 0, 0, mw, mh, BG(dc, normcol)); |
| 112 | dc->h = dc->font.height + 2; | ||
| 113 | dc->y = topbar ? 0 : mh - dc->h; | ||
| 114 | 111 | ||
| 115 | if(prompt) { | 112 | if(prompt) { |
| 116 | dc->w = promptw; | 113 | dc->w = promptw; |
| @@ -123,11 +120,10 @@ drawmenu(void) { | |||
| 123 | drawrect(dc, curpos, 2, 1, dc->h - 4, FG(dc, normcol)); | 120 | drawrect(dc, curpos, 2, 1, dc->h - 4, FG(dc, normcol)); |
| 124 | 121 | ||
| 125 | if(lines > 0) { | 122 | if(lines > 0) { |
| 126 | dc->y = topbar ? dc->h : 0; | ||
| 127 | dc->w = mw - dc->x; | 123 | dc->w = mw - dc->x; |
| 128 | for(item = curr; item != next; item = item->right) { | 124 | for(item = curr; item != next; item = item->right) { |
| 129 | drawtext(dc, item->text, (item == sel) ? selcol : normcol); | ||
| 130 | dc->y += dc->h; | 125 | dc->y += dc->h; |
| 126 | drawtext(dc, item->text, (item == sel) ? selcol : normcol); | ||
| 131 | } | 127 | } |
| 132 | } | 128 | } |
| 133 | else if(matches) { | 129 | else if(matches) { |
| @@ -237,7 +233,7 @@ keypress(XKeyEvent *ev) { | |||
| 237 | } | 233 | } |
| 238 | switch(ksym) { | 234 | switch(ksym) { |
| 239 | default: | 235 | default: |
| 240 | if(!iscntrl((int)*buf)) | 236 | if(isprint(*buf)) |
| 241 | insert(buf, MIN(strlen(buf), sizeof text - cursor)); | 237 | insert(buf, MIN(strlen(buf), sizeof text - cursor)); |
| 242 | break; | 238 | break; |
| 243 | case XK_BackSpace: | 239 | case XK_BackSpace: |
| @@ -451,7 +447,7 @@ setup(void) { | |||
| 451 | selcol[ColFG] = getcolor(dc, selfgcolor); | 447 | selcol[ColFG] = getcolor(dc, selfgcolor); |
| 452 | 448 | ||
| 453 | /* menu geometry */ | 449 | /* menu geometry */ |
| 454 | mh = (dc->font.height + 2) * (lines + 1); | 450 | mh = (lines + 1) * LINEH; |
| 455 | #ifdef XINERAMA | 451 | #ifdef XINERAMA |
| 456 | if((info = XineramaQueryScreens(dc->dpy, &n))) { | 452 | if((info = XineramaQueryScreens(dc->dpy, &n))) { |
| 457 | int i, di; | 453 | int i, di; |
