diff options
| -rw-r--r-- | dinput.c | 31 | ||||
| -rw-r--r-- | dmenu.c | 21 |
2 files changed, 20 insertions, 32 deletions
| @@ -21,9 +21,8 @@ | |||
| 21 | 21 | ||
| 22 | /* forward declarations */ | 22 | /* forward declarations */ |
| 23 | static void cleanup(void); | 23 | static void cleanup(void); |
| 24 | static void drawcursor(void); | ||
| 25 | static void drawinput(void); | 24 | static void drawinput(void); |
| 26 | static Bool grabkeyboard(void); | 25 | static void grabkeyboard(void); |
| 27 | static void kpress(XKeyEvent *e); | 26 | static void kpress(XKeyEvent *e); |
| 28 | static void run(void); | 27 | static void run(void); |
| 29 | static void setup(void); | 28 | static void setup(void); |
| @@ -35,7 +34,7 @@ static char *prompt = NULL; | |||
| 35 | static char text[4096]; | 34 | static char text[4096]; |
| 36 | static int promptw = 0; | 35 | static int promptw = 0; |
| 37 | static int screen; | 36 | static int screen; |
| 38 | static unsigned int cursor = 0; | 37 | static size_t cursor = 0; |
| 39 | static unsigned int numlockmask = 0; | 38 | static unsigned int numlockmask = 0; |
| 40 | static unsigned int mw, mh; | 39 | static unsigned int mw, mh; |
| 41 | static unsigned long normcol[ColLast]; | 40 | static unsigned long normcol[ColLast]; |
| @@ -54,46 +53,36 @@ cleanup(void) { | |||
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | void | 55 | void |
| 57 | drawcursor(void) { | ||
| 58 | XRectangle r = { dc.x, dc.y + 2, 1, dc.font.height - 2 }; | ||
| 59 | |||
| 60 | r.x += textnw(&dc, text, cursor) + dc.font.height / 2; | ||
| 61 | |||
| 62 | XSetForeground(dpy, dc.gc, normcol[ColFG]); | ||
| 63 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | ||
| 64 | } | ||
| 65 | |||
| 66 | void | ||
| 67 | drawinput(void) | 56 | drawinput(void) |
| 68 | { | 57 | { |
| 69 | dc.x = 0; | 58 | dc.x = 0; |
| 70 | dc.y = 0; | 59 | dc.y = 0; |
| 71 | dc.w = mw; | 60 | dc.w = mw; |
| 72 | dc.h = mh; | 61 | dc.h = mh; |
| 73 | drawtext(&dc, NULL, normcol, False); | 62 | drawtext(&dc, NULL, normcol); |
| 74 | /* print prompt? */ | 63 | /* print prompt? */ |
| 75 | if(prompt) { | 64 | if(prompt) { |
| 76 | dc.w = promptw; | 65 | dc.w = promptw; |
| 77 | drawtext(&dc, prompt, selcol, False); | 66 | drawtext(&dc, prompt, selcol); |
| 78 | dc.x += dc.w; | 67 | dc.x += dc.w; |
| 79 | } | 68 | } |
| 80 | dc.w = mw - dc.x; | 69 | dc.w = mw - dc.x; |
| 81 | drawtext(&dc, *text ? text : NULL, normcol, False); | 70 | drawtext(&dc, text, normcol); |
| 82 | drawcursor(); | 71 | drawcursor(&dc, text, cursor, normcol); |
| 83 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 72 | commitdraw(&dc, win); |
| 84 | } | 73 | } |
| 85 | 74 | ||
| 86 | Bool | 75 | void |
| 87 | grabkeyboard(void) { | 76 | grabkeyboard(void) { |
| 88 | unsigned int len; | 77 | unsigned int len; |
| 89 | 78 | ||
| 90 | for(len = 1000; len; len--) { | 79 | for(len = 1000; len; len--) { |
| 91 | if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) | 80 | if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) |
| 92 | == GrabSuccess) | 81 | == GrabSuccess) |
| 93 | break; | 82 | return; |
| 94 | usleep(1000); | 83 | usleep(1000); |
| 95 | } | 84 | } |
| 96 | return len > 0; | 85 | exit(EXIT_FAILURE); |
| 97 | } | 86 | } |
| 98 | 87 | ||
| 99 | void | 88 | void |
| @@ -162,25 +162,25 @@ drawmenu(void) { | |||
| 162 | dc.y = 0; | 162 | dc.y = 0; |
| 163 | dc.w = mw; | 163 | dc.w = mw; |
| 164 | dc.h = mh; | 164 | dc.h = mh; |
| 165 | drawtext(&dc, NULL, normcol, False); | 165 | drawtext(&dc, NULL, normcol); |
| 166 | dc.h = dc.font.height + 2; | 166 | dc.h = dc.font.height + 2; |
| 167 | dc.y = topbar ? 0 : mh - dc.h; | 167 | dc.y = topbar ? 0 : mh - dc.h; |
| 168 | /* print prompt? */ | 168 | /* print prompt? */ |
| 169 | if(prompt) { | 169 | if(prompt) { |
| 170 | dc.w = promptw; | 170 | dc.w = promptw; |
| 171 | drawtext(&dc, prompt, selcol, False); | 171 | drawtext(&dc, prompt, selcol); |
| 172 | dc.x += dc.w; | 172 | dc.x += dc.w; |
| 173 | } | 173 | } |
| 174 | dc.w = mw - dc.x; | 174 | dc.w = mw - dc.x; |
| 175 | /* print command */ | 175 | /* print command */ |
| 176 | if(cmdw && item && lines == 0) | 176 | if(cmdw && item && lines == 0) |
| 177 | dc.w = cmdw; | 177 | dc.w = cmdw; |
| 178 | drawtext(&dc, *text ? text : NULL, normcol, False); | 178 | drawtext(&dc, text, normcol); |
| 179 | if(lines > 0) | 179 | if(lines > 0) |
| 180 | drawmenuv(); | 180 | drawmenuv(); |
| 181 | else if(curr) | 181 | else if(curr) |
| 182 | drawmenuh(); | 182 | drawmenuh(); |
| 183 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 183 | commitdraw(&dc, win); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | void | 186 | void |
| @@ -189,16 +189,16 @@ drawmenuh(void) { | |||
| 189 | 189 | ||
| 190 | dc.x += cmdw; | 190 | dc.x += cmdw; |
| 191 | dc.w = spaceitem; | 191 | dc.w = spaceitem; |
| 192 | drawtext(&dc, curr->left ? "<" : NULL, normcol, False); | 192 | drawtext(&dc, curr->left ? "<" : NULL, normcol); |
| 193 | dc.x += dc.w; | 193 | dc.x += dc.w; |
| 194 | for(i = curr; i != next; i = i->right) { | 194 | for(i = curr; i != next; i = i->right) { |
| 195 | dc.w = MIN(textw(&dc, i->text), mw / 3); | 195 | dc.w = MIN(textw(&dc, i->text), mw / 3); |
| 196 | drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); | 196 | drawtext(&dc, i->text, (sel == i) ? selcol : normcol); |
| 197 | dc.x += dc.w; | 197 | dc.x += dc.w; |
| 198 | } | 198 | } |
| 199 | dc.w = spaceitem; | 199 | dc.w = spaceitem; |
| 200 | dc.x = mw - dc.w; | 200 | dc.x = mw - dc.w; |
| 201 | drawtext(&dc, next ? ">" : NULL, normcol, False); | 201 | drawtext(&dc, next ? ">" : NULL, normcol); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | void | 204 | void |
| @@ -209,7 +209,7 @@ drawmenuv(void) { | |||
| 209 | dc.y = topbar ? dc.h : 0; | 209 | dc.y = topbar ? dc.h : 0; |
| 210 | dc.w = mw - dc.x; | 210 | dc.w = mw - dc.x; |
| 211 | for(i = curr; i != next; i = i->right) { | 211 | for(i = curr; i != next; i = i->right) { |
| 212 | drawtext(&dc, i->text, (sel == i) ? selcol : normcol, False); | 212 | drawtext(&dc, i->text, (sel == i) ? selcol : normcol); |
| 213 | dc.y += dc.h; | 213 | dc.y += dc.h; |
| 214 | } | 214 | } |
| 215 | if(!XGetWindowAttributes(dpy, win, &wa)) | 215 | if(!XGetWindowAttributes(dpy, win, &wa)) |
| @@ -224,11 +224,10 @@ grabkeyboard(void) { | |||
| 224 | for(len = 1000; len; len--) { | 224 | for(len = 1000; len; len--) { |
| 225 | if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) | 225 | if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) |
| 226 | == GrabSuccess) | 226 | == GrabSuccess) |
| 227 | break; | 227 | return; |
| 228 | usleep(1000); | 228 | usleep(1000); |
| 229 | } | 229 | } |
| 230 | if(!len) | 230 | exit(EXIT_FAILURE); |
| 231 | exit(EXIT_FAILURE); | ||
| 232 | } | 231 | } |
| 233 | 232 | ||
| 234 | void | 233 | void |
