mirror of git://git.suckless.org/dwm
several new changes, made gridmenu working
This commit is contained in:
parent
8a34fa50f7
commit
39677ec766
14
Makefile
14
Makefile
|
@ -5,10 +5,12 @@ include config.mk
|
||||||
|
|
||||||
WMSRC = wm.c draw.c util.c
|
WMSRC = wm.c draw.c util.c
|
||||||
WMOBJ = ${WMSRC:.c=.o}
|
WMOBJ = ${WMSRC:.c=.o}
|
||||||
|
MENSRC = gridmenu.c draw.c util.c
|
||||||
|
MENOBJ = ${MENSRC:.c=.o}
|
||||||
MAN = gridwm.1
|
MAN = gridwm.1
|
||||||
BIN = gridwm gridmenu
|
BIN = gridwm gridmenu
|
||||||
|
|
||||||
all: config gridwm
|
all: config gridwm gridmenu
|
||||||
@echo finished
|
@echo finished
|
||||||
|
|
||||||
config:
|
config:
|
||||||
|
@ -22,18 +24,22 @@ config:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@${CC} -c ${CFLAGS} $<
|
@${CC} -c ${CFLAGS} $<
|
||||||
|
|
||||||
${WMOBJ}: wm.h draw.h config.h
|
${WMOBJ}: wm.h draw.h config.h util.h
|
||||||
|
|
||||||
|
gridmenu: ${MENOBJ}
|
||||||
|
@echo LD $@
|
||||||
|
@${CC} -o $@ ${MENOBJ} ${LDFLAGS}
|
||||||
|
|
||||||
gridwm: ${WMOBJ}
|
gridwm: ${WMOBJ}
|
||||||
@echo LD $@
|
@echo LD $@
|
||||||
@${CC} -o $@ ${WMOBJ} ${LDFLAGS}
|
@${CC} -o $@ ${WMOBJ} ${LDFLAGS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f gridwm *.o
|
rm -f gridwm gridmenu *.o core
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
mkdir -p gridwm-${VERSION}
|
mkdir -p gridwm-${VERSION}
|
||||||
cp -R Makefile README LICENSE config.mk ${WMSRC} ${MAN} gridwm-${VERSION}
|
cp -R Makefile README LICENSE config.mk *.h *.c ${MAN} gridwm-${VERSION}
|
||||||
tar -cf gridwm-${VERSION}.tar gridwm-${VERSION}
|
tar -cf gridwm-${VERSION}.tar gridwm-${VERSION}
|
||||||
gzip gridwm-${VERSION}.tar
|
gzip gridwm-${VERSION}.tar
|
||||||
rm -rf gridwm-${VERSION}
|
rm -rf gridwm-${VERSION}
|
||||||
|
|
8
config.h
8
config.h
|
@ -3,7 +3,7 @@
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FONT "fixed"
|
#define FONT "-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*"
|
||||||
#define FGCOLOR "#000000"
|
#define FGCOLOR "#000000"
|
||||||
#define BGCOLOR "#ffaa00"
|
#define BGCOLOR "#ffaa00"
|
||||||
#define BOCOLOR "#000000"
|
#define BORDERCOLOR "#000000"
|
||||||
|
|
41
draw.c
41
draw.c
|
@ -14,7 +14,7 @@ drawborder(Display *dpy, Brush *b)
|
||||||
{
|
{
|
||||||
XPoint points[5];
|
XPoint points[5];
|
||||||
XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
|
XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
XSetForeground(dpy, b->gc, b->color.border);
|
XSetForeground(dpy, b->gc, b->border);
|
||||||
points[0].x = b->rect.x;
|
points[0].x = b->rect.x;
|
||||||
points[0].y = b->rect.y;
|
points[0].y = b->rect.y;
|
||||||
points[1].x = b->rect.width - 1;
|
points[1].x = b->rect.width - 1;
|
||||||
|
@ -29,54 +29,54 @@ drawborder(Display *dpy, Brush *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
draw(Display *dpy, Brush *b)
|
draw(Display *dpy, Brush *b, Bool border, const char *text)
|
||||||
{
|
{
|
||||||
unsigned int x, y, w, h, len;
|
unsigned int x, y, w, h, len;
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
XGCValues gcv;
|
XGCValues gcv;
|
||||||
|
|
||||||
XSetForeground(dpy, b->gc, b->color.bg);
|
XSetForeground(dpy, b->gc, b->bg);
|
||||||
XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
|
XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
|
||||||
|
|
||||||
if(b->border)
|
if(border)
|
||||||
drawborder(dpy, b);
|
drawborder(dpy, b);
|
||||||
|
|
||||||
if(!b->text)
|
if(!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
len = strlen(b->text);
|
len = strlen(text);
|
||||||
if(len >= sizeof(buf))
|
if(len >= sizeof(buf))
|
||||||
len = sizeof(buf) - 1;
|
len = sizeof(buf) - 1;
|
||||||
memcpy(buf, b->text, len);
|
memcpy(buf, text, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
|
|
||||||
h = b->font->ascent + b->font->descent;
|
h = b->font.ascent + b->font.descent;
|
||||||
y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font->ascent;
|
y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font.ascent;
|
||||||
x = b->rect.x + (h / 2);
|
x = b->rect.x + (h / 2);
|
||||||
|
|
||||||
/* shorten text if necessary */
|
/* shorten text if necessary */
|
||||||
while(len && (w = textwidth_l(b->font, buf, len)) > b->rect.width - h)
|
while(len && (w = textwidth_l(&b->font, buf, len)) > b->rect.width - h)
|
||||||
buf[--len] = 0;
|
buf[--len] = 0;
|
||||||
|
|
||||||
if(w > b->rect.width)
|
if(w > b->rect.width)
|
||||||
return; /* too long */
|
return; /* too long */
|
||||||
|
|
||||||
gcv.foreground = b->color.fg;
|
gcv.foreground = b->fg;
|
||||||
gcv.background = b->color.bg;
|
gcv.background = b->bg;
|
||||||
if(b->font->set) {
|
if(b->font.set) {
|
||||||
XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv);
|
XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv);
|
||||||
XmbDrawImageString(dpy, b->drawable, b->font->set, b->gc,
|
XmbDrawImageString(dpy, b->drawable, b->font.set, b->gc,
|
||||||
x, y, buf, len);
|
x, y, buf, len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gcv.font = b->font->xfont->fid;
|
gcv.font = b->font.xfont->fid;
|
||||||
XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
|
XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
|
||||||
XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len);
|
XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long
|
static unsigned long
|
||||||
xloadcolor(Display *dpy, Colormap cmap, const char *colstr)
|
xloadcolors(Display *dpy, Colormap cmap, const char *colstr)
|
||||||
{
|
{
|
||||||
XColor color;
|
XColor color;
|
||||||
XAllocNamedColor(dpy, cmap, colstr, &color, &color);
|
XAllocNamedColor(dpy, cmap, colstr, &color, &color);
|
||||||
|
@ -84,13 +84,13 @@ xloadcolor(Display *dpy, Colormap cmap, const char *colstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
loadcolor(Display *dpy, int screen, Color *c,
|
loadcolors(Display *dpy, int screen, Brush *b,
|
||||||
const char *bg, const char *fg, const char *border)
|
const char *bg, const char *fg, const char *border)
|
||||||
{
|
{
|
||||||
Colormap cmap = DefaultColormap(dpy, screen);
|
Colormap cmap = DefaultColormap(dpy, screen);
|
||||||
c->bg = xloadcolor(dpy, cmap, bg);
|
b->bg = xloadcolors(dpy, cmap, bg);
|
||||||
c->fg = xloadcolor(dpy, cmap, fg);
|
b->fg = xloadcolors(dpy, cmap, fg);
|
||||||
c->border = xloadcolor(dpy, cmap, border);
|
b->border = xloadcolors(dpy, cmap, border);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
|
@ -160,4 +160,5 @@ loadfont(Display *dpy, Fnt *font, const char *fontstr)
|
||||||
font->ascent = font->xfont->ascent;
|
font->ascent = font->xfont->ascent;
|
||||||
font->descent = font->xfont->descent;
|
font->descent = font->xfont->descent;
|
||||||
}
|
}
|
||||||
|
font->height = font->ascent + font->descent;
|
||||||
}
|
}
|
||||||
|
|
31
draw.h
31
draw.h
|
@ -3,4 +3,33 @@
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern void error(char *errstr, ...);
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xlocale.h>
|
||||||
|
|
||||||
|
typedef struct Brush Brush;
|
||||||
|
typedef struct Fnt Fnt;
|
||||||
|
|
||||||
|
struct Fnt {
|
||||||
|
XFontStruct *xfont;
|
||||||
|
XFontSet set;
|
||||||
|
int ascent;
|
||||||
|
int descent;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Brush {
|
||||||
|
GC gc;
|
||||||
|
Drawable drawable;
|
||||||
|
XRectangle rect;
|
||||||
|
Fnt font;
|
||||||
|
unsigned long bg;
|
||||||
|
unsigned long fg;
|
||||||
|
unsigned long border;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void draw(Display *dpy, Brush *b, Bool border, const char *text);
|
||||||
|
extern void loadcolors(Display *dpy, int screen, Brush *b,
|
||||||
|
const char *bg, const char *fg, const char *bo);
|
||||||
|
extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
|
||||||
|
extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
|
||||||
|
extern unsigned int textwidth(Fnt *font, char *text);
|
||||||
|
|
243
gridmenu.c
243
gridmenu.c
|
@ -4,6 +4,10 @@
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "draw.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -12,14 +16,10 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <X11/cursorfont.h>
|
#include <X11/cursorfont.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
#include <blitz.h>
|
|
||||||
#include <cext.h>
|
|
||||||
|
|
||||||
typedef struct Item Item;
|
typedef struct Item Item;
|
||||||
|
|
||||||
struct Item {
|
struct Item {
|
||||||
|
@ -28,37 +28,40 @@ struct Item {
|
||||||
char *text;
|
char *text;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *title = nil;
|
static Display *dpy;
|
||||||
static Bool done = False;
|
static Window root;
|
||||||
static int ret = 0;
|
|
||||||
static char text[4096];
|
|
||||||
static BlitzColor selcolor;
|
|
||||||
static BlitzColor normcolor;
|
|
||||||
static Window win;
|
static Window win;
|
||||||
static XRectangle mrect;
|
static XRectangle rect;
|
||||||
static Item *allitem = nil; /* first of all items */
|
static Bool done = False;
|
||||||
static Item *item = nil; /* first of pattern matching items */
|
|
||||||
static Item *sel = nil;
|
static Item *allitem = 0; /* first of all items */
|
||||||
static Item *nextoff = nil;
|
static Item *item = 0; /* first of pattern matching items */
|
||||||
static Item *prevoff = nil;
|
static Item *sel = 0;
|
||||||
static Item *curroff = nil;
|
static Item *nextoff = 0;
|
||||||
|
static Item *prevoff = 0;
|
||||||
|
static Item *curroff = 0;
|
||||||
|
|
||||||
|
static int screen;
|
||||||
|
static char *title = 0;
|
||||||
|
static char text[4096];
|
||||||
|
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 twidth = 0;
|
static unsigned int twidth = 0;
|
||||||
static unsigned int cwidth = 0;
|
static unsigned int cwidth = 0;
|
||||||
static Blitz blz = {0};
|
|
||||||
static BlitzBrush brush = {0};
|
|
||||||
static const int seek = 30; /* 30px */
|
static const int seek = 30; /* 30px */
|
||||||
|
|
||||||
static void draw_menu(void);
|
static Brush brush = {0};
|
||||||
static void handle_kpress(XKeyEvent * e);
|
|
||||||
|
|
||||||
static char version[] = "wmiimenu - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n";
|
static void draw_menu(void);
|
||||||
|
static void kpress(XKeyEvent * e);
|
||||||
|
|
||||||
|
static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s", "usage: wmiimenu [-v] [-t <title>]\n");
|
fprintf(stderr, "%s", "usage: gridmenu [-v] [-t <title>]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,21 +74,21 @@ update_offsets()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
|
for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
|
||||||
tw = blitz_textwidth(brush.font, nextoff->text);
|
tw = textwidth(&brush.font, nextoff->text);
|
||||||
if(tw > mrect.width / 3)
|
if(tw > rect.width / 3)
|
||||||
tw = mrect.width / 3;
|
tw = rect.width / 3;
|
||||||
w += tw + mrect.height;
|
w += tw + brush.font.height;
|
||||||
if(w > mrect.width)
|
if(w > rect.width)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = cmdw + 2 * seek;
|
w = cmdw + 2 * seek;
|
||||||
for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
|
for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
|
||||||
tw = blitz_textwidth(brush.font, prevoff->left->text);
|
tw = textwidth(&brush.font, prevoff->left->text);
|
||||||
if(tw > mrect.width / 3)
|
if(tw > rect.width / 3)
|
||||||
tw = mrect.width / 3;
|
tw = rect.width / 3;
|
||||||
w += tw + mrect.height;
|
w += tw + brush.font.height;
|
||||||
if(w > mrect.width)
|
if(w > rect.width)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +107,7 @@ update_items(char *pattern)
|
||||||
else
|
else
|
||||||
cmdw = twidth;
|
cmdw = twidth;
|
||||||
|
|
||||||
item = j = nil;
|
item = j = 0;
|
||||||
nitem = 0;
|
nitem = 0;
|
||||||
|
|
||||||
for(i = allitem; i; i=i->next)
|
for(i = allitem; i; i=i->next)
|
||||||
|
@ -114,7 +117,7 @@ update_items(char *pattern)
|
||||||
else
|
else
|
||||||
j->right = i;
|
j->right = i;
|
||||||
i->left = j;
|
i->left = j;
|
||||||
i->right = nil;
|
i->right = 0;
|
||||||
j = i;
|
j = i;
|
||||||
nitem++;
|
nitem++;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +129,7 @@ update_items(char *pattern)
|
||||||
else
|
else
|
||||||
j->right = i;
|
j->right = i;
|
||||||
i->left = j;
|
i->left = j;
|
||||||
i->right = nil;
|
i->right = 0;
|
||||||
j = i;
|
j = i;
|
||||||
nitem++;
|
nitem++;
|
||||||
}
|
}
|
||||||
|
@ -141,72 +144,62 @@ static void
|
||||||
draw_menu()
|
draw_menu()
|
||||||
{
|
{
|
||||||
unsigned int offx = 0;
|
unsigned int offx = 0;
|
||||||
|
|
||||||
Item *i;
|
Item *i;
|
||||||
|
|
||||||
brush.align = WEST;
|
brush.rect = rect;
|
||||||
|
|
||||||
brush.rect = mrect;
|
|
||||||
brush.rect.x = 0;
|
brush.rect.x = 0;
|
||||||
brush.rect.y = 0;
|
brush.rect.y = 0;
|
||||||
brush.color = normcolor;
|
draw(dpy, &brush, False, 0);
|
||||||
brush.border = False;
|
|
||||||
blitz_draw_tile(&brush);
|
|
||||||
|
|
||||||
/* print command */
|
/* print command */
|
||||||
if(!title || text[0]) {
|
if(!title || text[0]) {
|
||||||
brush.color = normcolor;
|
|
||||||
cmdw = cwidth;
|
cmdw = cwidth;
|
||||||
if(cmdw && item)
|
if(cmdw && item)
|
||||||
brush.rect.width = cmdw;
|
brush.rect.width = cmdw;
|
||||||
blitz_draw_label(&brush, text);
|
draw(dpy, &brush, False, text);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmdw = twidth;
|
cmdw = twidth;
|
||||||
brush.color = selcolor;
|
|
||||||
brush.rect.width = cmdw;
|
brush.rect.width = cmdw;
|
||||||
blitz_draw_label(&brush, title);
|
draw(dpy, &brush, False, title);
|
||||||
}
|
}
|
||||||
offx += brush.rect.width;
|
offx += brush.rect.width;
|
||||||
|
|
||||||
brush.align = CENTER;
|
|
||||||
if(curroff) {
|
if(curroff) {
|
||||||
brush.color = normcolor;
|
|
||||||
brush.rect.x = offx;
|
brush.rect.x = offx;
|
||||||
brush.rect.width = seek;
|
brush.rect.width = seek;
|
||||||
offx += brush.rect.width;
|
offx += brush.rect.width;
|
||||||
blitz_draw_label(&brush, (curroff && curroff->left) ? "<" : nil);
|
draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0);
|
||||||
|
|
||||||
/* determine maximum items */
|
/* determine maximum items */
|
||||||
for(i = curroff; i != nextoff; i=i->right) {
|
for(i = curroff; i != nextoff; i=i->right) {
|
||||||
brush.color = normcolor;
|
|
||||||
brush.border = False;
|
brush.border = False;
|
||||||
brush.rect.x = offx;
|
brush.rect.x = offx;
|
||||||
brush.rect.width = blitz_textwidth(brush.font, i->text);
|
brush.rect.width = textwidth(&brush.font, i->text);
|
||||||
if(brush.rect.width > mrect.width / 3)
|
if(brush.rect.width > rect.width / 3)
|
||||||
brush.rect.width = mrect.width / 3;
|
brush.rect.width = rect.width / 3;
|
||||||
brush.rect.width += mrect.height;
|
brush.rect.width += brush.font.height;
|
||||||
if(sel == i) {
|
if(sel == i) {
|
||||||
brush.color = selcolor;
|
swap((void **)&brush.fg, (void **)&brush.bg);
|
||||||
brush.border = True;
|
draw(dpy, &brush, True, i->text);
|
||||||
|
swap((void **)&brush.fg, (void **)&brush.bg);
|
||||||
}
|
}
|
||||||
blitz_draw_label(&brush, i->text);
|
else
|
||||||
|
draw(dpy, &brush, False, i->text);
|
||||||
offx += brush.rect.width;
|
offx += brush.rect.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
brush.color = normcolor;
|
brush.rect.x = rect.width - seek;
|
||||||
brush.border = False;
|
|
||||||
brush.rect.x = mrect.width - seek;
|
|
||||||
brush.rect.width = seek;
|
brush.rect.width = seek;
|
||||||
blitz_draw_label(&brush, nextoff ? ">" : nil);
|
draw(dpy, &brush, False, nextoff ? ">" : 0);
|
||||||
}
|
}
|
||||||
XCopyArea(blz.dpy, brush.drawable, win, brush.gc, 0, 0, mrect.width,
|
XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, rect.width,
|
||||||
mrect.height, 0, 0);
|
rect.height, 0, 0);
|
||||||
XSync(blz.dpy, False);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_kpress(XKeyEvent * e)
|
kpress(XKeyEvent * e)
|
||||||
{
|
{
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
@ -272,7 +265,7 @@ handle_kpress(XKeyEvent * e)
|
||||||
case XK_Tab:
|
case XK_Tab:
|
||||||
if(!sel)
|
if(!sel)
|
||||||
return;
|
return;
|
||||||
cext_strlcpy(text, sel->text, sizeof(text));
|
strncpy(text, sel->text, sizeof(text));
|
||||||
update_items(text);
|
update_items(text);
|
||||||
break;
|
break;
|
||||||
case XK_Right:
|
case XK_Right:
|
||||||
|
@ -314,9 +307,9 @@ handle_kpress(XKeyEvent * e)
|
||||||
if((num == 1) && !iscntrl((int) buf[0])) {
|
if((num == 1) && !iscntrl((int) buf[0])) {
|
||||||
buf[num] = 0;
|
buf[num] = 0;
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
cext_strlcat(text, buf, sizeof(text));
|
strncat(text, buf, sizeof(text));
|
||||||
else
|
else
|
||||||
cext_strlcpy(text, buf, sizeof(text));
|
strncpy(text, buf, sizeof(text));
|
||||||
update_items(text);
|
update_items(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -326,24 +319,24 @@ handle_kpress(XKeyEvent * e)
|
||||||
static char *
|
static char *
|
||||||
read_allitems()
|
read_allitems()
|
||||||
{
|
{
|
||||||
static char *maxname = nil;
|
static char *maxname = 0;
|
||||||
char *p, buf[1024];
|
char *p, buf[1024];
|
||||||
unsigned int len = 0, max = 0;
|
unsigned int len = 0, max = 0;
|
||||||
Item *i, *new;
|
Item *i, *new;
|
||||||
|
|
||||||
i = nil;
|
i = 0;
|
||||||
while(fgets(buf, sizeof(buf), stdin)) {
|
while(fgets(buf, sizeof(buf), stdin)) {
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
if (buf[len - 1] == '\n')
|
if (buf[len - 1] == '\n')
|
||||||
buf[len - 1] = 0;
|
buf[len - 1] = 0;
|
||||||
p = cext_estrdup(buf);
|
p = estrdup(buf);
|
||||||
if(max < len) {
|
if(max < len) {
|
||||||
maxname = p;
|
maxname = p;
|
||||||
max = len;
|
max = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
new = cext_emalloc(sizeof(Item));
|
new = emalloc(sizeof(Item));
|
||||||
new->next = new->left = new->right = nil;
|
new->next = new->left = new->right = 0;
|
||||||
new->text = p;
|
new->text = p;
|
||||||
if(!i)
|
if(!i)
|
||||||
allitem = new;
|
allitem = new;
|
||||||
|
@ -360,10 +353,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
char *maxname, *p;
|
char *maxname;
|
||||||
BlitzFont font = {0};
|
|
||||||
GC gc;
|
|
||||||
Drawable pmap;
|
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
/* command line args */
|
/* command line args */
|
||||||
|
@ -388,93 +378,70 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
blz.dpy = XOpenDisplay(0);
|
dpy = XOpenDisplay(0);
|
||||||
if(!blz.dpy) {
|
if(!dpy)
|
||||||
fprintf(stderr, "%s", "wmiimenu: cannot open dpy\n");
|
error("gridmenu: cannot open dpy\n");
|
||||||
exit(1);
|
screen = DefaultScreen(dpy);
|
||||||
}
|
root = RootWindow(dpy, screen);
|
||||||
blz.screen = DefaultScreen(blz.dpy);
|
|
||||||
blz.root = RootWindow(blz.dpy, blz.screen);
|
|
||||||
|
|
||||||
maxname = read_allitems();
|
maxname = read_allitems();
|
||||||
|
|
||||||
/* grab as early as possible, but after reading all items!!! */
|
/* grab as early as possible, but after reading all items!!! */
|
||||||
while(XGrabKeyboard
|
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
||||||
(blz.dpy, blz.root, True, GrabModeAsync,
|
|
||||||
GrabModeAsync, CurrentTime) != GrabSuccess)
|
GrabModeAsync, CurrentTime) != GrabSuccess)
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
font.fontstr = getenv("WMII_FONT");
|
/* style */
|
||||||
if (!font.fontstr)
|
loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
|
||||||
font.fontstr = cext_estrdup(BLITZ_FONT);
|
loadfont(dpy, &brush.font, FONT);
|
||||||
blitz_loadfont(&blz, &font);
|
|
||||||
|
|
||||||
if((p = getenv("WMII_NORMCOLORS")))
|
|
||||||
cext_strlcpy(normcolor.colstr, p, sizeof(normcolor.colstr));
|
|
||||||
if(strlen(normcolor.colstr) != 23)
|
|
||||||
cext_strlcpy(normcolor.colstr, BLITZ_NORMCOLORS, sizeof(normcolor.colstr));
|
|
||||||
blitz_loadcolor(&blz, &normcolor);
|
|
||||||
|
|
||||||
if((p = getenv("WMII_SELCOLORS")))
|
|
||||||
cext_strlcpy(selcolor.colstr, p, sizeof(selcolor.colstr));
|
|
||||||
if(strlen(selcolor.colstr) != 23)
|
|
||||||
cext_strlcpy(selcolor.colstr, BLITZ_SELCOLORS, sizeof(selcolor.colstr));
|
|
||||||
blitz_loadcolor(&blz, &selcolor);
|
|
||||||
|
|
||||||
wa.override_redirect = 1;
|
wa.override_redirect = 1;
|
||||||
wa.background_pixmap = ParentRelative;
|
wa.background_pixmap = ParentRelative;
|
||||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask
|
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask
|
||||||
| SubstructureRedirectMask | SubstructureNotifyMask;
|
| SubstructureRedirectMask | SubstructureNotifyMask;
|
||||||
|
|
||||||
mrect.width = DisplayWidth(blz.dpy, blz.screen);
|
rect.width = DisplayWidth(dpy, screen);
|
||||||
mrect.height = font.ascent + font.descent + 4;
|
rect.height = brush.font.height + 4;
|
||||||
mrect.y = DisplayHeight(blz.dpy, blz.screen) - mrect.height;
|
rect.y = DisplayHeight(dpy, screen) - rect.height;
|
||||||
mrect.x = 0;
|
rect.x = 0;
|
||||||
|
|
||||||
win = XCreateWindow(blz.dpy, blz.root, mrect.x, mrect.y,
|
win = XCreateWindow(dpy, root, rect.x, rect.y,
|
||||||
mrect.width, mrect.height, 0, DefaultDepth(blz.dpy, blz.screen),
|
rect.width, rect.height, 0, DefaultDepth(dpy, screen),
|
||||||
CopyFromParent, DefaultVisual(blz.dpy, blz.screen),
|
CopyFromParent, DefaultVisual(dpy, screen),
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
XDefineCursor(blz.dpy, win, XCreateFontCursor(blz.dpy, XC_xterm));
|
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
|
||||||
XSync(blz.dpy, False);
|
XFlush(dpy);
|
||||||
|
|
||||||
/* pixmap */
|
/* pixmap */
|
||||||
gc = XCreateGC(blz.dpy, win, 0, 0);
|
brush.gc = XCreateGC(dpy, win, 0, 0);
|
||||||
pmap = XCreatePixmap(blz.dpy, win, mrect.width, mrect.height,
|
brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height,
|
||||||
DefaultDepth(blz.dpy, blz.screen));
|
DefaultDepth(dpy, screen));
|
||||||
|
XFlush(dpy);
|
||||||
XSync(blz.dpy, False);
|
|
||||||
|
|
||||||
brush.blitz = &blz;
|
|
||||||
brush.color = normcolor;
|
|
||||||
brush.drawable = pmap;
|
|
||||||
brush.gc = gc;
|
|
||||||
brush.font = &font;
|
|
||||||
|
|
||||||
if(maxname)
|
if(maxname)
|
||||||
cwidth = blitz_textwidth(brush.font, maxname) + mrect.height;
|
cwidth = textwidth(&brush.font, maxname) + brush.font.height;
|
||||||
if(cwidth > mrect.width / 3)
|
if(cwidth > rect.width / 3)
|
||||||
cwidth = mrect.width / 3;
|
cwidth = rect.width / 3;
|
||||||
|
|
||||||
if(title) {
|
if(title) {
|
||||||
twidth = blitz_textwidth(brush.font, title) + mrect.height;
|
twidth = textwidth(&brush.font, title) + brush.font.height;
|
||||||
if(twidth > mrect.width / 3)
|
if(twidth > rect.width / 3)
|
||||||
twidth = mrect.width / 3;
|
twidth = rect.width / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdw = title ? twidth : cwidth;
|
cmdw = title ? twidth : cwidth;
|
||||||
|
|
||||||
text[0] = 0;
|
text[0] = 0;
|
||||||
update_items(text);
|
update_items(text);
|
||||||
XMapRaised(blz.dpy, win);
|
XMapRaised(dpy, win);
|
||||||
draw_menu();
|
draw_menu();
|
||||||
XSync(blz.dpy, False);
|
XFlush(dpy);
|
||||||
|
|
||||||
/* main event loop */
|
/* main event loop */
|
||||||
while(!XNextEvent(blz.dpy, &ev)) {
|
while(!XNextEvent(dpy, &ev)) {
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
handle_kpress(&ev.xkey);
|
kpress(&ev.xkey);
|
||||||
break;
|
break;
|
||||||
case Expose:
|
case Expose:
|
||||||
if(ev.xexpose.count == 0) {
|
if(ev.xexpose.count == 0) {
|
||||||
|
@ -488,11 +455,11 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
XUngrabKeyboard(blz.dpy, CurrentTime);
|
XUngrabKeyboard(dpy, CurrentTime);
|
||||||
XFreePixmap(blz.dpy, pmap);
|
XFreePixmap(dpy, brush.drawable);
|
||||||
XFreeGC(blz.dpy, gc);
|
XFreeGC(dpy, brush.gc);
|
||||||
XDestroyWindow(blz.dpy, win);
|
XDestroyWindow(dpy, win);
|
||||||
XCloseDisplay(blz.dpy);
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
59
util.c
59
util.c
|
@ -6,6 +6,7 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
error(char *errstr, ...) {
|
error(char *errstr, ...) {
|
||||||
|
@ -16,3 +17,61 @@ error(char *errstr, ...) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
bad_malloc(unsigned int size)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "fatal: could not malloc() %d bytes\n",
|
||||||
|
(int) size);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
emallocz(unsigned int size)
|
||||||
|
{
|
||||||
|
void *res = calloc(1, size);
|
||||||
|
if(!res)
|
||||||
|
bad_malloc(size);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
emalloc(unsigned int size)
|
||||||
|
{
|
||||||
|
void *res = malloc(size);
|
||||||
|
if(!res)
|
||||||
|
bad_malloc(size);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
erealloc(void *ptr, unsigned int size)
|
||||||
|
{
|
||||||
|
void *res = realloc(ptr, size);
|
||||||
|
if(!res)
|
||||||
|
bad_malloc(size);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
estrdup(const char *str)
|
||||||
|
{
|
||||||
|
void *res = strdup(str);
|
||||||
|
if(!res)
|
||||||
|
bad_malloc(strlen(str));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
failed_assert(char *a, char *file, int line)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
swap(void **p1, void **p2)
|
||||||
|
{
|
||||||
|
void *tmp = *p1;
|
||||||
|
*p1 = *p2;
|
||||||
|
*p2 = tmp;
|
||||||
|
}
|
||||||
|
|
47
util.h
47
util.h
|
@ -3,39 +3,14 @@
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
extern void error(char *errstr, ...);
|
||||||
#include <X11/Xlocale.h>
|
extern void *emallocz(unsigned int size);
|
||||||
|
extern void *emalloc(unsigned int size);
|
||||||
typedef struct Brush Brush;
|
extern void *erealloc(void *ptr, unsigned int size);
|
||||||
typedef struct Color Color;
|
extern char *estrdup(const char *str);
|
||||||
typedef struct Fnt Fnt;
|
#define eassert(a) do { \
|
||||||
|
if(!(a)) \
|
||||||
struct Color {
|
failed_assert(#a, __FILE__, __LINE__); \
|
||||||
unsigned long bg;
|
} while (0)
|
||||||
unsigned long fg;
|
void failed_assert(char *a, char *file, int line);
|
||||||
unsigned long border;
|
void swap(void **p1, void **p2);
|
||||||
};
|
|
||||||
|
|
||||||
struct Fnt {
|
|
||||||
XFontStruct *xfont;
|
|
||||||
XFontSet set;
|
|
||||||
int ascent;
|
|
||||||
int descent;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Brush {
|
|
||||||
GC gc;
|
|
||||||
Drawable drawable;
|
|
||||||
XRectangle rect;
|
|
||||||
Bool border;
|
|
||||||
Fnt *font;
|
|
||||||
Color color;
|
|
||||||
const char *text;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern void draw(Display *dpy, Brush *b);
|
|
||||||
extern void loadcolor(Display *dpy, int screen, Color *c,
|
|
||||||
const char *bg, const char *fg, const char *bo);
|
|
||||||
extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
|
|
||||||
extern unsigned int textwidth(Fnt *font, char *text);
|
|
||||||
extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
|
|
||||||
|
|
15
wm.c
15
wm.c
|
@ -13,15 +13,20 @@
|
||||||
|
|
||||||
#include "wm.h"
|
#include "wm.h"
|
||||||
|
|
||||||
|
/* X structs */
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
Window root;
|
Window root;
|
||||||
XRectangle rect;
|
XRectangle rect;
|
||||||
int screen, sel_screen;
|
Pixmap pmap;
|
||||||
Atom wm_atom[WMLast];
|
Atom wm_atom[WMLast];
|
||||||
Atom net_atom[NetLast];
|
Atom net_atom[NetLast];
|
||||||
Cursor cursor[CurLast];
|
Cursor cursor[CurLast];
|
||||||
|
|
||||||
|
int screen, sel_screen;
|
||||||
unsigned int kmask, numlock_mask;
|
unsigned int kmask, numlock_mask;
|
||||||
Pixmap pmap;
|
|
||||||
|
/* draw structs */
|
||||||
|
Brush brush = {0};
|
||||||
|
|
||||||
enum { WM_PROTOCOL_DELWIN = 1 };
|
enum { WM_PROTOCOL_DELWIN = 1 };
|
||||||
|
|
||||||
|
@ -208,7 +213,7 @@ main(int argc, char *argv[])
|
||||||
XSetErrorHandler(startup_error_handler);
|
XSetErrorHandler(startup_error_handler);
|
||||||
/* this causes an error if some other WM is running */
|
/* this causes an error if some other WM is running */
|
||||||
XSelectInput(dpy, root, SubstructureRedirectMask);
|
XSelectInput(dpy, root, SubstructureRedirectMask);
|
||||||
XSync(dpy, False);
|
XFlush(dpy);
|
||||||
|
|
||||||
if(other_wm_running)
|
if(other_wm_running)
|
||||||
error("gridwm: another window manager is already running\n");
|
error("gridwm: another window manager is already running\n");
|
||||||
|
@ -246,6 +251,10 @@ main(int argc, char *argv[])
|
||||||
wa.cursor = cursor[CurNormal];
|
wa.cursor = cursor[CurNormal];
|
||||||
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
||||||
|
|
||||||
|
/* style */
|
||||||
|
loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
|
||||||
|
loadfont(dpy, &brush.font, FONT);
|
||||||
|
|
||||||
scan_wins();
|
scan_wins();
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
8
wm.h
8
wm.h
|
@ -3,6 +3,7 @@
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -48,11 +49,14 @@ struct Tag {
|
||||||
extern Display *dpy;
|
extern Display *dpy;
|
||||||
extern Window root;
|
extern Window root;
|
||||||
extern XRectangle rect;
|
extern XRectangle rect;
|
||||||
extern int screen, sel_screen;
|
|
||||||
extern unsigned int kmask, numlock_mask;
|
|
||||||
extern Atom wm_atom[WMLast];
|
extern Atom wm_atom[WMLast];
|
||||||
extern Atom net_atom[NetLast];
|
extern Atom net_atom[NetLast];
|
||||||
extern Cursor cursor[CurLast];
|
extern Cursor cursor[CurLast];
|
||||||
extern Pixmap pmap;
|
extern Pixmap pmap;
|
||||||
|
|
||||||
|
extern int screen, sel_screen;
|
||||||
|
extern unsigned int kmask, numlock_mask;
|
||||||
|
|
||||||
|
extern Brush brush;
|
||||||
|
|
||||||
/* wm.c */
|
/* wm.c */
|
||||||
|
|
Loading…
Reference in New Issue