|
|
@ -16,74 +16,112 @@ |
|
|
|
#include <X11/keysym.h> |
|
|
|
#include <X11/keysym.h> |
|
|
|
|
|
|
|
|
|
|
|
typedef struct Item Item; |
|
|
|
typedef struct Item Item; |
|
|
|
|
|
|
|
|
|
|
|
struct Item { |
|
|
|
struct Item { |
|
|
|
Item *next; /* traverses all items */ |
|
|
|
Item *next; /* traverses all items */ |
|
|
|
Item *left, *right; /* traverses items matching current search pattern */ |
|
|
|
Item *left, *right; /* traverses items matching current search pattern */ |
|
|
|
char *text; |
|
|
|
char *text; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static Display *dpy; |
|
|
|
/* static */ |
|
|
|
static Window root; |
|
|
|
|
|
|
|
static Window win; |
|
|
|
|
|
|
|
static Bool done = False; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Item *allitem = NULL; /* first of all items */ |
|
|
|
|
|
|
|
static Item *item = NULL; /* first of pattern matching items */ |
|
|
|
|
|
|
|
static Item *sel = NULL; |
|
|
|
|
|
|
|
static Item *nextoff = NULL; |
|
|
|
|
|
|
|
static Item *prevoff = NULL; |
|
|
|
|
|
|
|
static Item *curroff = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int screen, mx, my, mw, mh; |
|
|
|
static char *title, text[4096]; |
|
|
|
static char *title = NULL; |
|
|
|
static int mx, my, mw, mh; |
|
|
|
static char text[4096]; |
|
|
|
|
|
|
|
static int ret = 0; |
|
|
|
static int ret = 0; |
|
|
|
static int nitem = 0; |
|
|
|
static int nitem = 0; |
|
|
|
static unsigned int cmdw = 0; |
|
|
|
static unsigned int cmdw = 0; |
|
|
|
static unsigned int tw = 0; |
|
|
|
static unsigned int tw = 0; |
|
|
|
static unsigned int cw = 0; |
|
|
|
static unsigned int cw = 0; |
|
|
|
static const int seek = 30; /* 30px */ |
|
|
|
static Bool done = False; |
|
|
|
|
|
|
|
static Item *allitems = NULL; /* first of all items */ |
|
|
|
static Brush brush = {0}; |
|
|
|
static Item *item = NULL; /* first of pattern matching items */ |
|
|
|
|
|
|
|
static Item *sel = NULL; |
|
|
|
static void draw_menu(); |
|
|
|
static Item *next = NULL; |
|
|
|
static void kpress(XKeyEvent * e); |
|
|
|
static Item *prev = NULL; |
|
|
|
|
|
|
|
static Item *curr = NULL; |
|
|
|
static char version[] = "dmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
|
|
|
static Window root; |
|
|
|
|
|
|
|
static Window win; |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
update_offsets() |
|
|
|
calcoffsets() |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int tw, w = cmdw + 2 * seek; |
|
|
|
unsigned int tw, w; |
|
|
|
|
|
|
|
|
|
|
|
if(!curroff) |
|
|
|
if(!curr) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
for(nextoff = curroff; nextoff; nextoff=nextoff->right) { |
|
|
|
w = cmdw + 2 * SPACE; |
|
|
|
tw = textw(&brush.font, nextoff->text); |
|
|
|
for(next = curr; next; next=next->right) { |
|
|
|
|
|
|
|
tw = textw(next->text); |
|
|
|
if(tw > mw / 3) |
|
|
|
if(tw > mw / 3) |
|
|
|
tw = mw / 3; |
|
|
|
tw = mw / 3; |
|
|
|
w += tw + brush.font.height; |
|
|
|
w += tw; |
|
|
|
if(w > mw) |
|
|
|
if(w > mw) |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
w = cmdw + 2 * seek; |
|
|
|
w = cmdw + 2 * SPACE; |
|
|
|
for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) { |
|
|
|
for(prev = curr; prev && prev->left; prev=prev->left) { |
|
|
|
tw = textw(&brush.font, prevoff->left->text); |
|
|
|
tw = textw(prev->left->text); |
|
|
|
if(tw > mw / 3) |
|
|
|
if(tw > mw / 3) |
|
|
|
tw = mw / 3; |
|
|
|
tw = mw / 3; |
|
|
|
w += tw + brush.font.height; |
|
|
|
w += tw; |
|
|
|
if(w > mw) |
|
|
|
if(w > mw) |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
update_items(char *pattern) |
|
|
|
drawmenu() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Item *i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dc.x = 0; |
|
|
|
|
|
|
|
dc.y = 0; |
|
|
|
|
|
|
|
dc.w = mw; |
|
|
|
|
|
|
|
dc.h = mh; |
|
|
|
|
|
|
|
drawtext(NULL, False, False); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* print command */ |
|
|
|
|
|
|
|
if(!title || text[0]) { |
|
|
|
|
|
|
|
cmdw = cw; |
|
|
|
|
|
|
|
if(cmdw && item) |
|
|
|
|
|
|
|
dc.w = cmdw; |
|
|
|
|
|
|
|
drawtext(text, False, False); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
cmdw = tw; |
|
|
|
|
|
|
|
dc.w = cmdw; |
|
|
|
|
|
|
|
drawtext(title, False, False); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dc.x += dc.w; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(curr) { |
|
|
|
|
|
|
|
dc.w = SPACE; |
|
|
|
|
|
|
|
drawtext((curr && curr->left) ? "<" : NULL, False, False); |
|
|
|
|
|
|
|
dc.x += dc.w; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* determine maximum items */ |
|
|
|
|
|
|
|
for(i = curr; i != next; i=i->right) { |
|
|
|
|
|
|
|
dc.border = False; |
|
|
|
|
|
|
|
dc.w = textw(i->text); |
|
|
|
|
|
|
|
if(dc.w > mw / 3) |
|
|
|
|
|
|
|
dc.w = mw / 3; |
|
|
|
|
|
|
|
drawtext(i->text, sel == i, sel == i); |
|
|
|
|
|
|
|
dc.x += dc.w; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dc.x = mw - SPACE; |
|
|
|
|
|
|
|
dc.w = SPACE; |
|
|
|
|
|
|
|
drawtext(next ? ">" : NULL, False, False); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); |
|
|
|
|
|
|
|
XFlush(dpy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
|
|
|
input(char *pattern) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int plen = strlen(pattern); |
|
|
|
unsigned int plen; |
|
|
|
Item *i, *j; |
|
|
|
Item *i, *j; |
|
|
|
|
|
|
|
|
|
|
|
if(!pattern) |
|
|
|
if(!pattern) |
|
|
@ -94,10 +132,11 @@ update_items(char *pattern) |
|
|
|
else |
|
|
|
else |
|
|
|
cmdw = tw; |
|
|
|
cmdw = tw; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plen = strlen(pattern); |
|
|
|
item = j = NULL; |
|
|
|
item = j = NULL; |
|
|
|
nitem = 0; |
|
|
|
nitem = 0; |
|
|
|
|
|
|
|
|
|
|
|
for(i = allitem; i; i=i->next) |
|
|
|
for(i = allitems; i; i=i->next) |
|
|
|
if(!plen || !strncmp(pattern, i->text, plen)) { |
|
|
|
if(!plen || !strncmp(pattern, i->text, plen)) { |
|
|
|
if(!j) |
|
|
|
if(!j) |
|
|
|
item = i; |
|
|
|
item = i; |
|
|
@ -108,7 +147,7 @@ update_items(char *pattern) |
|
|
|
j = i; |
|
|
|
j = i; |
|
|
|
nitem++; |
|
|
|
nitem++; |
|
|
|
} |
|
|
|
} |
|
|
|
for(i = allitem; i; i=i->next) |
|
|
|
for(i = allitems; i; i=i->next) |
|
|
|
if(plen && strncmp(pattern, i->text, plen) |
|
|
|
if(plen && strncmp(pattern, i->text, plen) |
|
|
|
&& strstr(i->text, pattern)) { |
|
|
|
&& strstr(i->text, pattern)) { |
|
|
|
if(!j) |
|
|
|
if(!j) |
|
|
@ -121,75 +160,19 @@ update_items(char *pattern) |
|
|
|
nitem++; |
|
|
|
nitem++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
curroff = prevoff = nextoff = sel = item; |
|
|
|
curr = prev = next = sel = item; |
|
|
|
|
|
|
|
calcoffsets(); |
|
|
|
update_offsets(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* creates brush structs for brush mode drawing */ |
|
|
|
|
|
|
|
static void |
|
|
|
|
|
|
|
draw_menu() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Item *i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
brush.x = 0; |
|
|
|
|
|
|
|
brush.y = 0; |
|
|
|
|
|
|
|
brush.w = mw; |
|
|
|
|
|
|
|
brush.h = mh; |
|
|
|
|
|
|
|
draw(dpy, &brush, False, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* print command */ |
|
|
|
|
|
|
|
if(!title || text[0]) { |
|
|
|
|
|
|
|
cmdw = cw; |
|
|
|
|
|
|
|
if(cmdw && item) |
|
|
|
|
|
|
|
brush.w = cmdw; |
|
|
|
|
|
|
|
draw(dpy, &brush, False, text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
cmdw = tw; |
|
|
|
|
|
|
|
brush.w = cmdw; |
|
|
|
|
|
|
|
draw(dpy, &brush, False, title); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
brush.x += brush.w; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(curroff) { |
|
|
|
|
|
|
|
brush.w = seek; |
|
|
|
|
|
|
|
draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0); |
|
|
|
|
|
|
|
brush.x += brush.w; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* determine maximum items */ |
|
|
|
|
|
|
|
for(i = curroff; i != nextoff; i=i->right) { |
|
|
|
|
|
|
|
brush.border = False; |
|
|
|
|
|
|
|
brush.w = textw(&brush.font, i->text); |
|
|
|
|
|
|
|
if(brush.w > mw / 3) |
|
|
|
|
|
|
|
brush.w = mw / 3; |
|
|
|
|
|
|
|
brush.w += brush.font.height; |
|
|
|
|
|
|
|
if(sel == i) { |
|
|
|
|
|
|
|
swap((void **)&brush.fg, (void **)&brush.bg); |
|
|
|
|
|
|
|
draw(dpy, &brush, True, i->text); |
|
|
|
|
|
|
|
swap((void **)&brush.fg, (void **)&brush.bg); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
draw(dpy, &brush, False, i->text); |
|
|
|
|
|
|
|
brush.x += brush.w; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
brush.x = mw - seek; |
|
|
|
|
|
|
|
brush.w = seek; |
|
|
|
|
|
|
|
draw(dpy, &brush, False, nextoff ? ">" : 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0); |
|
|
|
|
|
|
|
XFlush(dpy); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
kpress(XKeyEvent * e) |
|
|
|
kpress(XKeyEvent * e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
KeySym ksym; |
|
|
|
|
|
|
|
char buf[32]; |
|
|
|
char buf[32]; |
|
|
|
int num, prev_nitem; |
|
|
|
int num, prev_nitem; |
|
|
|
unsigned int i, len = strlen(text); |
|
|
|
unsigned int i, len; |
|
|
|
|
|
|
|
KeySym ksym; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
len = strlen(text); |
|
|
|
buf[0] = 0; |
|
|
|
buf[0] = 0; |
|
|
|
num = XLookupString(e, buf, sizeof(buf), &ksym, 0); |
|
|
|
num = XLookupString(e, buf, sizeof(buf), &ksym, 0); |
|
|
|
|
|
|
|
|
|
|
@ -210,8 +193,8 @@ kpress(XKeyEvent * e) |
|
|
|
case XK_U: |
|
|
|
case XK_U: |
|
|
|
case XK_u: |
|
|
|
case XK_u: |
|
|
|
text[0] = 0; |
|
|
|
text[0] = 0; |
|
|
|
update_items(text); |
|
|
|
input(text); |
|
|
|
draw_menu(); |
|
|
|
drawmenu(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case XK_bracketleft: |
|
|
|
case XK_bracketleft: |
|
|
@ -224,24 +207,24 @@ kpress(XKeyEvent * e) |
|
|
|
if(!(sel && sel->left)) |
|
|
|
if(!(sel && sel->left)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
sel=sel->left; |
|
|
|
sel=sel->left; |
|
|
|
if(sel->right == curroff) { |
|
|
|
if(sel->right == curr) { |
|
|
|
curroff = prevoff; |
|
|
|
curr = prev; |
|
|
|
update_offsets(); |
|
|
|
calcoffsets(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case XK_Tab: |
|
|
|
case XK_Tab: |
|
|
|
if(!sel) |
|
|
|
if(!sel) |
|
|
|
return; |
|
|
|
return; |
|
|
|
strncpy(text, sel->text, sizeof(text)); |
|
|
|
strncpy(text, sel->text, sizeof(text)); |
|
|
|
update_items(text); |
|
|
|
input(text); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case XK_Right: |
|
|
|
case XK_Right: |
|
|
|
if(!(sel && sel->right)) |
|
|
|
if(!(sel && sel->right)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
sel=sel->right; |
|
|
|
sel=sel->right; |
|
|
|
if(sel == nextoff) { |
|
|
|
if(sel == next) { |
|
|
|
curroff = nextoff; |
|
|
|
curr = next; |
|
|
|
update_offsets(); |
|
|
|
calcoffsets(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case XK_Return: |
|
|
|
case XK_Return: |
|
|
@ -265,9 +248,9 @@ kpress(XKeyEvent * e) |
|
|
|
prev_nitem = nitem; |
|
|
|
prev_nitem = nitem; |
|
|
|
do { |
|
|
|
do { |
|
|
|
text[--i] = 0; |
|
|
|
text[--i] = 0; |
|
|
|
update_items(text); |
|
|
|
input(text); |
|
|
|
} while(i && nitem && prev_nitem == nitem); |
|
|
|
} while(i && nitem && prev_nitem == nitem); |
|
|
|
update_items(text); |
|
|
|
input(text); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
@ -277,14 +260,14 @@ kpress(XKeyEvent * e) |
|
|
|
strncat(text, buf, sizeof(text)); |
|
|
|
strncat(text, buf, sizeof(text)); |
|
|
|
else |
|
|
|
else |
|
|
|
strncpy(text, buf, sizeof(text)); |
|
|
|
strncpy(text, buf, sizeof(text)); |
|
|
|
update_items(text); |
|
|
|
input(text); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
draw_menu(); |
|
|
|
drawmenu(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char * |
|
|
|
static char * |
|
|
|
read_allitems() |
|
|
|
readinput() |
|
|
|
{ |
|
|
|
{ |
|
|
|
static char *maxname = NULL; |
|
|
|
static char *maxname = NULL; |
|
|
|
char *p, buf[1024]; |
|
|
|
char *p, buf[1024]; |
|
|
@ -306,7 +289,7 @@ read_allitems() |
|
|
|
new->next = new->left = new->right = NULL; |
|
|
|
new->next = new->left = new->right = NULL; |
|
|
|
new->text = p; |
|
|
|
new->text = p; |
|
|
|
if(!i) |
|
|
|
if(!i) |
|
|
|
allitem = new; |
|
|
|
allitems = new; |
|
|
|
else
|
|
|
|
else
|
|
|
|
i->next = new; |
|
|
|
i->next = new; |
|
|
|
i = new; |
|
|
|
i = new; |
|
|
@ -315,21 +298,27 @@ read_allitems() |
|
|
|
return maxname; |
|
|
|
return maxname; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* extern */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int screen; |
|
|
|
|
|
|
|
Display *dpy; |
|
|
|
|
|
|
|
DC dc = {0}; |
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
|
int |
|
|
|
main(int argc, char *argv[]) |
|
|
|
main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
|
|
|
|
XSetWindowAttributes wa; |
|
|
|
|
|
|
|
char *maxname; |
|
|
|
char *maxname; |
|
|
|
|
|
|
|
int i; |
|
|
|
XEvent ev; |
|
|
|
XEvent ev; |
|
|
|
|
|
|
|
XSetWindowAttributes wa; |
|
|
|
|
|
|
|
|
|
|
|
/* command line args */ |
|
|
|
/* command line args */ |
|
|
|
for(i = 1; i < argc; i++) { |
|
|
|
for(i = 1; i < argc; i++) { |
|
|
|
if (argv[i][0] == '-') |
|
|
|
if (argv[i][0] == '-') |
|
|
|
switch (argv[i][1]) { |
|
|
|
switch (argv[i][1]) { |
|
|
|
case 'v': |
|
|
|
case 'v': |
|
|
|
fprintf(stdout, "%s", version); |
|
|
|
fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
|
|
|
exit(0); |
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 't': |
|
|
|
case 't': |
|
|
|
if(++i < argc) { |
|
|
|
if(++i < argc) { |
|
|
@ -350,7 +339,7 @@ main(int argc, char *argv[]) |
|
|
|
screen = DefaultScreen(dpy); |
|
|
|
screen = DefaultScreen(dpy); |
|
|
|
root = RootWindow(dpy, screen); |
|
|
|
root = RootWindow(dpy, screen); |
|
|
|
|
|
|
|
|
|
|
|
maxname = read_allitems(); |
|
|
|
maxname = readinput(); |
|
|
|
|
|
|
|
|
|
|
|
/* grab as early as possible, but after reading all items!!! */ |
|
|
|
/* grab as early as possible, but after reading all items!!! */ |
|
|
|
while(XGrabKeyboard(dpy, root, True, GrabModeAsync, |
|
|
|
while(XGrabKeyboard(dpy, root, True, GrabModeAsync, |
|
|
@ -358,8 +347,10 @@ main(int argc, char *argv[]) |
|
|
|
usleep(1000); |
|
|
|
usleep(1000); |
|
|
|
|
|
|
|
|
|
|
|
/* style */ |
|
|
|
/* style */ |
|
|
|
loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR); |
|
|
|
dc.bg = getcolor(BGCOLOR); |
|
|
|
loadfont(dpy, &brush.font, FONT); |
|
|
|
dc.fg = getcolor(FGCOLOR); |
|
|
|
|
|
|
|
dc.border = getcolor(BORDERCOLOR); |
|
|
|
|
|
|
|
setfont(FONT); |
|
|
|
|
|
|
|
|
|
|
|
wa.override_redirect = 1; |
|
|
|
wa.override_redirect = 1; |
|
|
|
wa.background_pixmap = ParentRelative; |
|
|
|
wa.background_pixmap = ParentRelative; |
|
|
@ -367,28 +358,25 @@ main(int argc, char *argv[]) |
|
|
|
|
|
|
|
|
|
|
|
mx = my = 0; |
|
|
|
mx = my = 0; |
|
|
|
mw = DisplayWidth(dpy, screen); |
|
|
|
mw = DisplayWidth(dpy, screen); |
|
|
|
mh = texth(&brush.font); |
|
|
|
mh = dc.font.height + 4; |
|
|
|
|
|
|
|
|
|
|
|
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, |
|
|
|
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, |
|
|
|
DefaultDepth(dpy, screen), CopyFromParent, |
|
|
|
DefaultDepth(dpy, screen), CopyFromParent, |
|
|
|
DefaultVisual(dpy, screen), |
|
|
|
DefaultVisual(dpy, screen), |
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
|
|
|
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); |
|
|
|
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); |
|
|
|
XFlush(dpy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* pixmap */ |
|
|
|
/* pixmap */ |
|
|
|
brush.gc = XCreateGC(dpy, root, 0, 0); |
|
|
|
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen)); |
|
|
|
brush.drawable = XCreatePixmap(dpy, win, mw, mh, |
|
|
|
dc.gc = XCreateGC(dpy, root, 0, 0); |
|
|
|
DefaultDepth(dpy, screen)); |
|
|
|
|
|
|
|
XFlush(dpy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(maxname) |
|
|
|
if(maxname) |
|
|
|
cw = textw(&brush.font, maxname) + brush.font.height; |
|
|
|
cw = textw(maxname); |
|
|
|
if(cw > mw / 3) |
|
|
|
if(cw > mw / 3) |
|
|
|
cw = mw / 3; |
|
|
|
cw = mw / 3; |
|
|
|
|
|
|
|
|
|
|
|
if(title) { |
|
|
|
if(title) { |
|
|
|
tw = textw(&brush.font, title) + brush.font.height; |
|
|
|
tw = textw(title); |
|
|
|
if(tw > mw / 3) |
|
|
|
if(tw > mw / 3) |
|
|
|
tw = mw / 3; |
|
|
|
tw = mw / 3; |
|
|
|
} |
|
|
|
} |
|
|
@ -396,10 +384,10 @@ main(int argc, char *argv[]) |
|
|
|
cmdw = title ? tw : cw; |
|
|
|
cmdw = title ? tw : cw; |
|
|
|
|
|
|
|
|
|
|
|
text[0] = 0; |
|
|
|
text[0] = 0; |
|
|
|
update_items(text); |
|
|
|
input(text); |
|
|
|
XMapRaised(dpy, win); |
|
|
|
XMapRaised(dpy, win); |
|
|
|
draw_menu(); |
|
|
|
drawmenu(); |
|
|
|
XFlush(dpy); |
|
|
|
XSync(dpy, False); |
|
|
|
|
|
|
|
|
|
|
|
/* main event loop */ |
|
|
|
/* main event loop */ |
|
|
|
while(!done && !XNextEvent(dpy, &ev)) { |
|
|
|
while(!done && !XNextEvent(dpy, &ev)) { |
|
|
@ -409,7 +397,7 @@ main(int argc, char *argv[]) |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Expose: |
|
|
|
case Expose: |
|
|
|
if(ev.xexpose.count == 0) |
|
|
|
if(ev.xexpose.count == 0) |
|
|
|
draw_menu(); |
|
|
|
drawmenu(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -417,8 +405,8 @@ main(int argc, char *argv[]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
XUngrabKeyboard(dpy, CurrentTime); |
|
|
|
XUngrabKeyboard(dpy, CurrentTime); |
|
|
|
XFreePixmap(dpy, brush.drawable); |
|
|
|
XFreePixmap(dpy, dc.drawable); |
|
|
|
XFreeGC(dpy, brush.gc); |
|
|
|
XFreeGC(dpy, dc.gc); |
|
|
|
XDestroyWindow(dpy, win); |
|
|
|
XDestroyWindow(dpy, win); |
|
|
|
XCloseDisplay(dpy); |
|
|
|
XCloseDisplay(dpy); |
|
|
|
|
|
|
|
|
|
|
|