1
0

rearranged several stuff

This commit is contained in:
arg@10ksloc.org 2006-08-04 10:23:36 +02:00
parent 7817523a68
commit 5077207088
6 changed files with 222 additions and 272 deletions

View File

@ -1,6 +1,7 @@
MIT/X Consortium License MIT/X Consortium License
(C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
(C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

View File

@ -1,4 +1,4 @@
# dwm version # dmenu version
VERSION = 0.0 VERSION = 0.0
# Customize below to fit your system # Customize below to fit your system

29
dmenu.h
View File

@ -7,6 +7,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xlocale.h> #include <X11/Xlocale.h>
#define SPACE 30 /* px */
typedef struct Brush Brush; typedef struct Brush Brush;
typedef struct DC DC; typedef struct DC DC;
typedef struct Fnt Fnt; typedef struct Fnt Fnt;
@ -29,30 +31,17 @@ struct DC { /* draw context */
GC gc; GC gc;
}; };
struct Brush { extern int screen;
GC gc; extern Display *dpy;
Drawable drawable; extern DC dc;
int x, y, w, h;
Fnt font;
unsigned long bg;
unsigned long fg;
unsigned long border;
};
/* draw.c */ /* draw.c */
extern void draw(Display *dpy, Brush *b, Bool border, const char *text); extern void drawtext(const char *text, Bool invert, Bool border);
extern void loadcolors(Display *dpy, int screen, Brush *b, extern unsigned long getcolor(const char *colstr);
const char *bg, const char *fg, const char *bo); extern void setfont(const char *fontstr);
extern void loadfont(Display *dpy, Fnt *font, const char *fontstr); extern unsigned int textw(const char *text);
extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
extern unsigned int textw(Fnt *font, char *text);
extern unsigned int texth(Fnt *font);
/* util.c */ /* util.c */
extern void *emalloc(unsigned int size); extern void *emalloc(unsigned int size);
extern void *emallocz(unsigned int size);
extern void eprint(const char *errstr, ...); extern void eprint(const char *errstr, ...);
extern char *estrdup(const char *str); extern char *estrdup(const char *str);
extern void swap(void **p1, void **p2);

188
draw.c
View File

@ -2,45 +2,62 @@
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details. * See LICENSE file for license details.
*/ */
#include "dmenu.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <X11/Xlocale.h>
#include "dmenu.h" /* static */
static void static void
drawborder(Display *dpy, Brush *b) drawborder(void)
{ {
XPoint points[5]; XPoint points[5];
XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
XSetForeground(dpy, b->gc, b->border); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
points[0].x = b->x; XSetForeground(dpy, dc.gc, dc.border);
points[0].y = b->y; points[0].x = dc.x;
points[1].x = b->w - 1; points[0].y = dc.y;
points[1].x = dc.w - 1;
points[1].y = 0; points[1].y = 0;
points[2].x = 0; points[2].x = 0;
points[2].y = b->h - 1; points[2].y = dc.h - 1;
points[3].x = -(b->w - 1); points[3].x = -(dc.w - 1);
points[3].y = 0; points[3].y = 0;
points[4].x = 0; points[4].x = 0;
points[4].y = -(b->h - 1); points[4].y = -(dc.h - 1);
XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious); XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
} }
void static unsigned int
draw(Display *dpy, Brush *b, Bool border, const char *text) textnw(const char *text, unsigned int len)
{ {
unsigned int x, y, w, h, len; XRectangle r;
static char buf[256];
XGCValues gcv;
XRectangle r = { b->x, b->y, b->w, b->h };
XSetForeground(dpy, b->gc, b->bg); if(dc.font.set) {
XFillRectangles(dpy, b->drawable, b->gc, &r, 1); XmbTextExtents(dc.font.set, text, len, NULL, &r);
return r.width;
}
return XTextWidth(dc.font.xfont, text, len);
}
/* extern */
void
drawtext(const char *text, Bool invert, Bool border)
{
int x, y, w, h;
static char buf[256];
unsigned int len;
XGCValues gcv;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
w = 0; w = 0;
if(border) if(border)
drawborder(dpy, b); drawborder();
if(!text) if(!text)
return; return;
@ -51,121 +68,94 @@ draw(Display *dpy, Brush *b, Bool border, const char *text)
memcpy(buf, text, len); memcpy(buf, text, len);
buf[len] = 0; buf[len] = 0;
h = b->font.ascent + b->font.descent; h = dc.font.ascent + dc.font.descent;
y = b->y + (b->h / 2) - (h / 2) + b->font.ascent; y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
x = b->x + (h / 2); x = dc.x + (h / 2);
/* shorten text if necessary */ /* shorten text if necessary */
while(len && (w = textnw(&b->font, buf, len)) > b->w - h) while(len && (w = textnw(buf, len)) > dc.w - h)
buf[--len] = 0; buf[--len] = 0;
if(w > b->w) if(w > dc.w)
return; /* too long */ return; /* too long */
gcv.foreground = b->fg; gcv.foreground = invert ? dc.bg : dc.fg;
gcv.background = b->bg; gcv.background = invert ? dc.fg : dc.bg;
if(b->font.set) { if(dc.font.set) {
XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv); XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
XmbDrawImageString(dpy, b->drawable, b->font.set, b->gc, XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
x, y, buf, len); x, y, buf, len);
} }
else { else {
gcv.font = b->font.xfont->fid; gcv.font = dc.font.xfont->fid;
XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv); XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len); XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
} }
} }
static unsigned long unsigned long
xloadcolors(Display *dpy, Colormap cmap, const char *colstr) getcolor(const char *colstr)
{ {
Colormap cmap = DefaultColormap(dpy, screen);
XColor color; XColor color;
XAllocNamedColor(dpy, cmap, colstr, &color, &color); XAllocNamedColor(dpy, cmap, colstr, &color, &color);
return color.pixel; return color.pixel;
} }
void void
loadcolors(Display *dpy, int screen, Brush *b, setfont(const char *fontstr)
const char *bg, const char *fg, const char *border)
{
Colormap cmap = DefaultColormap(dpy, screen);
b->bg = xloadcolors(dpy, cmap, bg);
b->fg = xloadcolors(dpy, cmap, fg);
b->border = xloadcolors(dpy, cmap, border);
}
unsigned int
textnw(Fnt *font, char *text, unsigned int len)
{
XRectangle r;
if(font->set) {
XmbTextExtents(font->set, text, len, NULL, &r);
return r.width;
}
return XTextWidth(font->xfont, text, len);
}
unsigned int
textw(Fnt *font, char *text)
{
return textnw(font, text, strlen(text));
}
unsigned int
texth(Fnt *font)
{
return font->height + 4;
}
void
loadfont(Display *dpy, Fnt *font, const char *fontstr)
{ {
char **missing, *def; char **missing, *def;
int n; int i, n;
missing = NULL; missing = NULL;
def = "?";
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
if(font->set) if(dc.font.set)
XFreeFontSet(dpy, font->set); XFreeFontSet(dpy, dc.font.set);
font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
if(missing) { if(missing) {
while(n--) while(n--)
fprintf(stderr, "missing fontset: %s\n", missing[n]); fprintf(stderr, "missing fontset: %s\n", missing[n]);
XFreeStringList(missing); XFreeStringList(missing);
if(font->set) { if(dc.font.set) {
XFreeFontSet(dpy, font->set); XFreeFontSet(dpy, dc.font.set);
font->set = NULL; dc.font.set = NULL;
} }
} }
if(font->set) { if(dc.font.set) {
XFontSetExtents *font_extents; XFontSetExtents *font_extents;
XFontStruct **xfonts; XFontStruct **xfonts;
char **font_names; char **font_names;
unsigned int i;
font->ascent = font->descent = 0; dc.font.ascent = dc.font.descent = 0;
font_extents = XExtentsOfFontSet(font->set); font_extents = XExtentsOfFontSet(dc.font.set);
n = XFontsOfFontSet(font->set, &xfonts, &font_names); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) { for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
if(font->ascent < (*xfonts)->ascent) if(dc.font.ascent < (*xfonts)->ascent)
font->ascent = (*xfonts)->ascent; dc.font.ascent = (*xfonts)->ascent;
if(font->descent < (*xfonts)->descent) if(dc.font.descent < (*xfonts)->descent)
font->descent = (*xfonts)->descent; dc.font.descent = (*xfonts)->descent;
xfonts++; xfonts++;
} }
} }
else { else {
if(font->xfont) if(dc.font.xfont)
XFreeFont(dpy, font->xfont); XFreeFont(dpy, dc.font.xfont);
font->xfont = NULL; dc.font.xfont = NULL;
font->xfont = XLoadQueryFont(dpy, fontstr); dc.font.xfont = XLoadQueryFont(dpy, fontstr);
if (!font->xfont) if (!dc.font.xfont)
font->xfont = XLoadQueryFont(dpy, "fixed"); dc.font.xfont = XLoadQueryFont(dpy, "fixed");
if (!font->xfont) if (!dc.font.xfont)
eprint("error, cannot load 'fixed' font\n"); eprint("error, cannot init 'fixed' font\n");
font->ascent = font->xfont->ascent; dc.font.ascent = dc.font.xfont->ascent;
font->descent = font->xfont->descent; dc.font.descent = dc.font.xfont->descent;
} }
font->height = font->ascent + font->descent; dc.font.height = dc.font.ascent + dc.font.descent;
}
unsigned int
textw(const char *text)
{
return textnw(text, strlen(text)) + dc.font.height;
} }

256
main.c
View File

@ -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 char *title, text[4096];
static Item *item = NULL; /* first of pattern matching items */ static int mx, my, mw, mh;
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 = NULL;
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()
{ {
unsigned int plen = strlen(pattern); 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;
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);

18
util.c
View File

@ -29,16 +29,6 @@ emalloc(unsigned int size)
return res; return res;
} }
void *
emallocz(unsigned int size)
{
void *res = calloc(1, size);
if(!res)
bad_malloc(size);
return res;
}
void void
eprint(const char *errstr, ...) eprint(const char *errstr, ...)
{ {
@ -58,11 +48,3 @@ estrdup(const char *str)
bad_malloc(strlen(str)); bad_malloc(strlen(str));
return res; return res;
} }
void
swap(void **p1, void **p2)
{
void *tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}