Xinqi Bao's Git
projects
/
dmenu.git
/ diff
summary
|
log
|
commit
|
diff
|
tree
raw
|
patch
|
inline
| side by side (parent:
0b8072a
)
cursor fix + style
author
Connor Lane Smith <
[email protected]
>
Mon, 9 Aug 2010 10:54:46 +0000
(11:54 +0100)
committer
Connor Lane Smith <
[email protected]
>
Mon, 9 Aug 2010 10:54:46 +0000
(11:54 +0100)
dmenu.c
diff
|
blob
|
history
diff --git
a/dmenu.c
b/dmenu.c
index
a1d0ed2
..
fa37f49
100644
(file)
--- a/
dmenu.c
+++ b/
dmenu.c
@@
-30,7
+30,7
@@
static char *cistrstr(const char *s, const char *sub);
static void drawmenu(void);
static void grabkeyboard(void);
static void insert(const char *s, ssize_t n);
static void drawmenu(void);
static void grabkeyboard(void);
static void insert(const char *s, ssize_t n);
-static void keypress(XKeyEvent *e);
+static void keypress(XKeyEvent *e
v
);
static void match(void);
static void paste(void);
static void readstdin(void);
static void match(void);
static void paste(void);
static void readstdin(void);
@@
-73,8
+73,7
@@
appenditem(Item *item, Item **list, Item **last) {
}
void
}
void
-calcoffsets(void)
-{
+calcoffsets(void) {
unsigned int h, i, n;
h = dc->font.height+2;
unsigned int h, i, n;
h = dc->font.height+2;
@@
-104,26
+103,24
@@
cistrstr(const char *s, const char *sub) {
void
drawmenu(void) {
void
drawmenu(void) {
+ int curpos;
Item *item;
dc->x = 0;
dc->y = 0;
drawrect(dc, 0, 0, mw, mh, BG(dc, normcol));
Item *item;
dc->x = 0;
dc->y = 0;
drawrect(dc, 0, 0, mw, mh, BG(dc, normcol));
-
dc->h = dc->font.height + 2;
dc->y = topbar ? 0 : mh - dc->h;
dc->h = dc->font.height + 2;
dc->y = topbar ? 0 : mh - dc->h;
- /* print prompt? */
+
if(prompt) {
dc->w = promptw;
drawtext(dc, prompt, selcol);
dc->x = dc->w;
}
if(prompt) {
dc->w = promptw;
drawtext(dc, prompt, selcol);
dc->x = dc->w;
}
- dc->w = mw - dc->x;
- /* print input field */
- if(matches && lines == 0 && textw(dc, text) <= inputw)
- dc->w = inputw;
+ dc->w = (lines > 0 || !matches) ? mw - dc->x : 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));
+ if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
+ drawrect(dc, curpos, 2, 1, dc->h - 4, FG(dc, normcol));
if(lines > 0) {
dc->y = topbar ? dc->h : 0;
if(lines > 0) {
dc->y = topbar ? dc->h : 0;
@@
-133,7
+130,7
@@
drawmenu(void) {
dc->y += dc->h;
}
}
dc->y += dc->h;
}
}
- else if(
curr && (dc->w == inputw || curr->next)
) {
+ else if(
matches
) {
dc->x += inputw;
dc->w = textw(dc, "<");
if(curr->left)
dc->x += inputw;
dc->w = textw(dc, "<");
if(curr->left)
@@
-173,15
+170,15
@@
insert(const char *s, ssize_t n) {
}
void
}
void
-keypress(XKeyEvent *e) {
- char buf[
sizeof text
];
+keypress(XKeyEvent *e
v
) {
+ char buf[
32
];
int n;
size_t len;
KeySym ksym;
len = strlen(text);
int n;
size_t len;
KeySym ksym;
len = strlen(text);
- XLookupString(e, buf, sizeof buf, &ksym, NULL);
- if(e->state & ControlMask) {
+ XLookupString(e
v
, buf, sizeof buf, &ksym, NULL);
+ if(e
v
->state & ControlMask) {
switch(tolower(ksym)) {
default:
return;
switch(tolower(ksym)) {
default:
return;
@@
-235,7
+232,6
@@
keypress(XKeyEvent *e) {
break;
case XK_y: /* paste selection */
XConvertSelection(dc->dpy, XA_PRIMARY, utf8, None, win, CurrentTime);
break;
case XK_y: /* paste selection */
XConvertSelection(dc->dpy, XA_PRIMARY, utf8, None, win, CurrentTime);
- /* causes SelectionNotify event */
return;
}
}
return;
}
}
@@
-289,8
+285,7
@@
keypress(XKeyEvent *e) {
case XK_Up:
if(!sel || !sel->left)
return;
case XK_Up:
if(!sel || !sel->left)
return;
- sel = sel->left;
- if(sel->right == curr) {
+ if((sel = sel->left)->right == curr) {
curr = prev;
calcoffsets();
}
curr = prev;
calcoffsets();
}
@@
-309,7
+304,7
@@
keypress(XKeyEvent *e) {
break;
case XK_Return:
case XK_KP_Enter:
break;
case XK_Return:
case XK_KP_Enter:
- fputs((sel && !(e->state & ShiftMask)) ? sel->text : text, stdout);
+ fputs((sel && !(e
v
->state & ShiftMask)) ? sel->text : text, stdout);
fflush(stdout);
exit(EXIT_SUCCESS);
case XK_Right:
fflush(stdout);
exit(EXIT_SUCCESS);
case XK_Right:
@@
-322,8
+317,7
@@
keypress(XKeyEvent *e) {
case XK_Down:
if(!sel || !sel->right)
return;
case XK_Down:
if(!sel || !sel->right)
return;
- sel = sel->right;
- if(sel == next) {
+ if((sel = sel->right) == next) {
curr = next;
calcoffsets();
}
curr = next;
calcoffsets();
}
@@
-404,7
+398,7
@@
readstdin(void) {
if(!(new = malloc(sizeof *new)))
eprintf("cannot malloc %u bytes\n", sizeof *new);
if(!(new->text = strdup(buf)))
if(!(new = malloc(sizeof *new)))
eprintf("cannot malloc %u bytes\n", sizeof *new);
if(!(new->text = strdup(buf)))
- eprintf("cannot strdup %u bytes\n", strlen(buf));
+ eprintf("cannot strdup %u bytes\n", strlen(buf)
+1
);
inputw = MAX(inputw, textw(dc, new->text));
new->next = new->left = new->right = NULL;
if(item)
inputw = MAX(inputw, textw(dc, new->text));
new->next = new->left = new->right = NULL;
if(item)
@@
-485,9
+479,9
@@
setup(void) {
wa.background_pixmap = ParentRelative;
wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
wa.background_pixmap = ParentRelative;
wa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
- DefaultDepth(dc->dpy, screen), CopyFromParent,
- DefaultVisual(dc->dpy, screen),
- CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
+
DefaultDepth(dc->dpy, screen), CopyFromParent,
+
DefaultVisual(dc->dpy, screen),
+
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
grabkeyboard();
setcanvas(dc, mw, mh);
grabkeyboard();
setcanvas(dc, mw, mh);