dmenu-yosh/COMPLETE_PATCH.diff

819 lines
25 KiB
Diff

diff --git a/config.def.h b/config.def.h
index e9a5b16..1edb647 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,51 +1,23 @@
/* See LICENSE file for copyright and license details. */
/* Default settings; can be overriden by command line. */
-static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
-static int centered = 0; /* -c option; centers dmenu on screen */
-static int colorprompt = 1; /* -p option; if 1, prompt uses SchemeSel, otherwise SchemeNorm */
-static int min_width = 480; /* minimum width when centered */
-static const unsigned int alpha = 0xD0;
-
+static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
- "Terminus:size=9"
+ "monospace:size=10"
};
static const char *prompt = NULL; /* -p option; prompt to the left of input field */
static const char *colors[SchemeLast][2] = {
/* fg bg */
- [SchemeNorm] = { "#a7acc5", "#2d0827" },
- [SchemeSel] = { "#f9f5e9", "#402c4e" },
- [SchemeSelHighlight] = { "#d93352", "#402c4e" },
- [SchemeNormHighlight] = { "#f15b94", "#2d0827" },
- [SchemeOut] = { "#2d0827", "#c7acc5" },
-};
-
-static const unsigned int alphas[SchemeLast][2] = {
- [SchemeNorm] = { OPAQUE, alpha },
- [SchemeSel] = { OPAQUE, alpha },
- [SchemeOut] = { OPAQUE, alpha },
- [SchemeSelHighlight] = { OPAQUE, alpha },
- [SchemeNormHighlight] = { OPAQUE, alpha},
+ [SchemeNorm] = { "#bbbbbb", "#222222" },
+ [SchemeSel] = { "#eeeeee", "#005577" },
+ [SchemeOut] = { "#000000", "#00ffff" },
};
-
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0;
-/* -h option; minimum height of a menu line */
-static unsigned int lineheight = 20;
-static unsigned int min_lineheight = 20;
/*
* Characters not considered part of a word while deleting words
* for example: " /?\"&[]"
*/
-static const char worddelimiters[] = " /?\"&[]";
-
-/* -n option; preselected item starting from 0 */
-static unsigned int preselected = 0;
-/* Size of the window border */
-static unsigned int border_width = 0;
-/* tsv-alt: reverse the order of tab separation.
- * 0 = display<TAB>output. 1 = output<TAB>display
- * can be reversed with -r as well */
-static int revtab = 0;
+static const char worddelimiters[] = " ";
diff --git a/config.mk b/config.mk
index fa2b4fc..566348b 100644
--- a/config.mk
+++ b/config.mk
@@ -21,7 +21,7 @@ FREETYPEINC = /usr/include/freetype2
# includes and libs
INCS = -I$(X11INC) -I$(FREETYPEINC)
-LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) -lXrender
+LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS)
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS)
diff --git a/dmenu.1 b/dmenu.1
index 2654608..323f93c 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -3,19 +3,11 @@
dmenu \- dynamic menu
.SH SYNOPSIS
.B dmenu
-.RB [ \-bfivr ]
+.RB [ \-bfiv ]
.RB [ \-l
.IR lines ]
-.RB [ \-h
-.IR height ]
.RB [ \-m
.IR monitor ]
-.RB [ \-x
-.IR xoffset ]
-.RB [ \-y
-.IR yoffset ]
-.RB [ \-z
-.IR width ]
.RB [ \-p
.IR prompt ]
.RB [ \-fn
@@ -30,8 +22,6 @@ dmenu \- dynamic menu
.IR color ]
.RB [ \-w
.IR windowid ]
-.RB [ \-n
-.IR number ]
.P
.BR dmenu_run " ..."
.SH DESCRIPTION
@@ -50,47 +40,20 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
.B \-b
dmenu appears at the bottom of the screen.
.TP
-.B \-c
-dmenu appears centered on the screen.
-.TP
.B \-f
dmenu grabs the keyboard before reading stdin if not reading from a tty. This
is faster, but will lock up X until stdin reaches end\-of\-file.
.TP
-.B \-s
-dmenu matches menu items case sensitively.
-.TP
-.B \-S
-dmenu does not sort menu items after matching.
+.B \-i
+dmenu matches menu items case insensitively.
.TP
.BI \-l " lines"
dmenu lists items vertically, with the given number of lines.
.TP
-.BI \-h " height"
-dmenu uses a menu line of at least 'height' pixels tall, but no less than 8.
-.TP
.BI \-m " monitor"
dmenu is displayed on the monitor number supplied. Monitor numbers are starting
from 0.
.TP
-.BI \-x " xoffset"
-dmenu is placed at this offset measured from the left side of the monitor.
-Can be negative.
-If option
-.B \-m
-is present, the measurement will use the given monitor.
-.TP
-.BI \-y " yoffset"
-dmenu is placed at this offset measured from the top of the monitor. If the
-.B \-b
-option is used, the offset is measured from the bottom. Can be negative.
-If option
-.B \-m
-is present, the measurement will use the given monitor.
-.TP
-.BI \-z " width"
-sets the width of the dmenu window.
-.TP
.BI \-p " prompt"
defines the prompt to be displayed to the left of the input field.
.TP
@@ -117,12 +80,6 @@ prints version information to stdout, then exits.
.TP
.BI \-w " windowid"
embed into windowid.
-.TP
-.BI \-n " number"
-preseslected item starting from 0.
-.TP
-.B \-r
-tsv-alt: reverse the behavior of tab separation.
.SH USAGE
dmenu is completely controlled by the keyboard. Items are selected using the
arrow keys, page up, page down, home, and end.
diff --git a/dmenu.c b/dmenu.c
index 1080062..e7be8af 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -1,7 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <ctype.h>
#include <locale.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -11,7 +10,6 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
-#include <X11/Xproto.h>
#include <X11/Xutil.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
@@ -26,36 +24,26 @@
* MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
-#define NUMBERSMAXDIGITS 100
-#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
-
-#define OPAQUE 0xffU
/* enums */
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeLast }; /* color schemes */
+enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
struct item {
char *text;
- char *otext;
struct item *left, *right;
int out;
};
-static char numbers[NUMBERSBUFSIZE] = "";
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
-static int inputw = 96, promptw;
-static int dmx = 0; /* put dmenu at this x offset */
-static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
-static unsigned int dmw = 0; /* make dmenu this wide */
+static int inputw = 0, promptw;
static int lrpad; /* sum of left and right padding */
static size_t cursor;
static struct item *items = NULL;
static struct item *matches, *matchend;
static struct item *prev, *curr, *next, *sel;
static int mon = -1, screen;
-static bool sortmatches = true;
static Atom clip, utf8;
static Display *dpy;
@@ -65,17 +53,10 @@ static XIC xic;
static Drw *drw;
static Clr *scheme[SchemeLast];
-static int useargb = 0;
-static Visual *visual;
-static int depth;
-static Colormap cmap;
-
#include "config.h"
-static char * cistrstr(const char *s, const char *sub);
-static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
-static char *(*fstrstr)(const char *, const char *) = cistrstr;
-static void xinitvisual();
+static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
+static char *(*fstrstr)(const char *, const char *) = strstr;
static unsigned int
textw_clamp(const char *str, unsigned int n)
@@ -105,7 +86,7 @@ calcoffsets(void)
if (lines > 0)
n = lines * bh;
else
- n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">") + TEXTW(numbers));
+ n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right)
if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)) > n)
@@ -115,15 +96,6 @@ calcoffsets(void)
break;
}
-static int
-max_textw(void)
-{
- int len = 0;
- for (struct item *item = items; item && item->text; item++)
- len = MAX(TEXTW(item->text), len);
- return len;
-}
-
static void
cleanup(void)
{
@@ -133,7 +105,7 @@ cleanup(void)
for (i = 0; i < SchemeLast; i++)
free(scheme[i]);
for (i = 0; items && items[i].text; ++i)
- free(revtab ? items[i].otext : items[i].text);
+ free(items[i].text);
free(items);
drw_free(drw);
XSync(dpy, False);
@@ -158,43 +130,6 @@ cistrstr(const char *h, const char *n)
return NULL;
}
-static void
-drawhighlights(struct item *item, int x, int y, int maxw)
-{
- char restorechar, tokens[sizeof text], *highlight, *token;
- int indentx, highlightlen;
-
- drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]);
- strcpy(tokens, text);
- for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) {
- highlight = fstrstr(item->text, token);
- while (highlight) {
- // Move item str end, calc width for highlight indent, & restore
- highlightlen = highlight - item->text;
- restorechar = *highlight;
- item->text[highlightlen] = '\0';
- indentx = TEXTW(item->text);
- item->text[highlightlen] = restorechar;
-
- // Move highlight str end, draw highlight, & restore
- restorechar = highlight[strlen(token)];
- highlight[strlen(token)] = '\0';
- if (indentx - (lrpad / 2) - 1 < maxw)
- drw_text(
- drw,
- x + indentx - (lrpad / 2), // there was a -1 here idk why
- y,
- MIN(maxw - indentx, TEXTW(highlight) - lrpad),
- bh, 0, highlight, 0
- );
- highlight[strlen(token)] = restorechar;
-
- if (strlen(highlight) - strlen(token) < strlen(token)) break;
- highlight = fstrstr(highlight + strlen(token), token);
- }
- }
-}
-
static int
drawitem(struct item *item, int x, int y, int w)
{
@@ -205,24 +140,7 @@ drawitem(struct item *item, int x, int y, int w)
else
drw_setscheme(drw, scheme[SchemeNorm]);
- int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
- drawhighlights(item, x, y, w);
- return r;
-}
-
-static void
-recalculatenumbers()
-{
- unsigned int numer = 0, denom = 0;
- struct item *item;
- if (matchend) {
- numer++;
- for (item = matchend; item && item->left; item = item->left)
- numer++;
- }
- for (item = items; item && item->text; item++)
- denom++;
- snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
+ return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
}
static void
@@ -230,14 +148,13 @@ drawmenu(void)
{
unsigned int curpos;
struct item *item;
- int x = 0, y = 0, fh = drw->fonts->h, w;
+ int x = 0, y = 0, w;
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, 0, 0, mw, mh, 1, 1);
if (prompt && *prompt) {
- if (colorprompt)
- drw_setscheme(drw, scheme[SchemeSel]);
+ drw_setscheme(drw, scheme[SchemeSel]);
x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
}
/* draw input field */
@@ -248,14 +165,13 @@ drawmenu(void)
curpos = TEXTW(text) - TEXTW(&text[cursor]);
if ((curpos += lrpad / 2 - 1) < w) {
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
+ drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
}
- recalculatenumbers();
if (lines > 0) {
/* draw vertical list */
for (item = curr; item != next; item = item->right)
- drawitem(item, 0, y += bh, mw);
+ drawitem(item, x, y += bh, mw - x);
} else if (matches) {
/* draw horizontal list */
x += inputw;
@@ -266,15 +182,13 @@ drawmenu(void)
}
x += w;
for (item = curr; item != next; item = item->right)
- x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">") - TEXTW(numbers)));
+ x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">")));
if (next) {
w = TEXTW(">");
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, mw - w - TEXTW(numbers) - border_width * 2, 0, w, bh, lrpad / 2, ">", 0);
+ drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
}
}
- drw_setscheme(drw, scheme[SchemeNorm]);
- drw_text(drw, mw - TEXTW(numbers) - border_width * 2, 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
drw_map(drw, win, 0, 0, mw, mh);
}
@@ -339,18 +253,13 @@ match(void)
break;
if (i != tokc) /* not all tokens match */
continue;
-
- if (!sortmatches)
+ /* exact matches go first, then prefixes, then substrings */
+ if (!tokc || !fstrncmp(text, item->text, textsize))
appenditem(item, &matches, &matchend);
- else {
- /* exact matches go first, then prefixes, then substrings */
- if (!tokc || !fstrncmp(text, item->text, textsize))
- appenditem(item, &matches, &matchend);
- else if (!fstrncmp(tokv[0], item->text, len))
- appenditem(item, &lprefix, &prefixend);
- else
- appenditem(item, &lsubstr, &substrend);
- }
+ else if (!fstrncmp(tokv[0], item->text, len))
+ appenditem(item, &lprefix, &prefixend);
+ else
+ appenditem(item, &lsubstr, &substrend);
}
if (lprefix) {
if (matches) {
@@ -462,9 +371,9 @@ keypress(XKeyEvent *ev)
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
insert(NULL, nextrune(-1) - cursor);
break;
- case XK_v: /* paste selection */
- case XK_V:
- XConvertSelection(dpy, (ev->state & ShiftMask) ? XA_PRIMARY : clip,
+ case XK_y: /* paste selection */
+ case XK_Y:
+ XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime);
return;
case XK_Left:
@@ -581,7 +490,7 @@ insert:
break;
case XK_Return:
case XK_KP_Enter:
- puts((sel && !(ev->state & ShiftMask)) ? sel->otext : text);
+ puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
if (!(ev->state & ControlMask)) {
cleanup();
exit(0);
@@ -651,15 +560,11 @@ readstdin(void)
die("cannot realloc %zu bytes:", size);
if (line[len - 1] == '\n')
line[len - 1] = '\0';
- items[i].text = items[i].otext = line;
- if ((line = strchr(line, '\t'))) {
- *line++ = '\0';
- revtab ? (items[i].text = line) : (items[i].otext = line);
- }
+ items[i].text = line;
items[i].out = 0;
}
if (items)
- items[i].text = items[i].otext = NULL;
+ items[i].text = NULL;
lines = MIN(lines, i);
}
@@ -667,19 +572,8 @@ static void
run(void)
{
XEvent ev;
- int i;
while (!XNextEvent(dpy, &ev)) {
- if (preselected) {
- for (i = 0; i < preselected; i++) {
- if (sel && sel->right && (sel = sel->right) == next) {
- curr = next;
- calcoffsets();
- }
- }
- drawmenu();
- preselected = 0;
- }
if (XFilterEvent(&ev, win))
continue;
switch(ev.type) {
@@ -729,17 +623,15 @@ setup(void)
#endif
/* init appearance */
for (j = 0; j < SchemeLast; j++)
- scheme[j] = drw_scm_create(drw, colors[j], alphas[i], 2);
+ scheme[j] = drw_scm_create(drw, colors[j], 2);
clip = XInternAtom(dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dpy, "UTF8_STRING", False);
/* calculate menu geometry */
bh = drw->fonts->h + 2;
- bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
lines = MAX(lines, 0);
mh = (lines + 1) * bh;
- promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#ifdef XINERAMA
i = 0;
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
@@ -766,16 +658,9 @@ setup(void)
if (INTERSECT(x, y, 1, 1, info[i]) != 0)
break;
- if (centered) {
- mw = (dmw>0 ? dmw : MIN(MAX(max_textw() + promptw, min_width), info[i].width));
- x = info[i].x_org + ((info[i].width - mw) / 2);
- y = info[i].y_org + ((info[i].height - mh) / 2);
- } else {
- x = info[i].x_org;
- y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
- mw = (dmw>0 ? dmw : info[i].width);
- }
-
+ x = info[i].x_org;
+ y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
+ mw = info[i].width;
XFree(info);
} else
#endif
@@ -783,31 +668,21 @@ setup(void)
if (!XGetWindowAttributes(dpy, parentwin, &wa))
die("could not get embedding window attributes: 0x%lx",
parentwin);
-
- if (centered) {
- mw = (dmw>0 ? dmw : MIN(MAX(max_textw() + promptw, min_width), wa.width));
- x = (wa.width - mw) / 2;
- y = (wa.height - mh) / 2;
- } else {
- x = dmx;
- y = topbar ? dmy : wa.height - mh - dmy;
- mw = (dmw>0 ? dmw : wa.width);
- }
+ x = 0;
+ y = topbar ? 0 : wa.height - mh;
+ mw = wa.width;
}
- inputw = MIN(inputw, mw/3);
+ promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
+ inputw = mw / 3; /* input width: ~33% of monitor width */
match();
/* create menu window */
swa.override_redirect = True;
- swa.background_pixel = 0;
- swa.border_pixel = 0;
- swa.colormap = cmap;
+ swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
- win = XCreateWindow(dpy, parentwin, x, y - (topbar ? 0 : border_width * 2), mw - border_width * 2, mh, border_width,
- depth, CopyFromParent, visual,
- CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &swa);
- if (border_width)
- XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel);
+ win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
+ CopyFromParent, CopyFromParent, CopyFromParent,
+ CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
XSetClassHint(dpy, win, &ch);
@@ -835,9 +710,8 @@ setup(void)
static void
usage(void)
{
- die("usage: dmenu [-bfsvScr] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
- " [-x xoffset] [-y yoffset] [-z width] [-bw bwidth]\n"
- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] [-n number]");
+ die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
}
int
@@ -855,30 +729,14 @@ main(int argc, char *argv[])
topbar = 0;
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
fast = 1;
- else if (!strcmp(argv[i], "-S")) /* do not sort matches */
- sortmatches = false;
- else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */
- fstrncmp = strncmp;
- fstrstr = strstr;
- } else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
- centered = 1;
- else if (!strcmp(argv[i], "-r")) /* reverse the tab separation */
- revtab = (!revtab);
- else if (i + 1 == argc)
+ else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
+ fstrncmp = strncasecmp;
+ fstrstr = cistrstr;
+ } else if (i + 1 == argc)
usage();
/* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-x")) /* window x offset */
- dmx = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */
- dmy = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */
- dmw = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
- lineheight = atoi(argv[++i]);
- lineheight = MAX(lineheight, min_lineheight);
- }
else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
@@ -895,10 +753,6 @@ main(int argc, char *argv[])
colors[SchemeSel][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
- else if (!strcmp(argv[i], "-n")) /* preselected item */
- preselected = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-bw"))
- border_width = atoi(argv[++i]); /* border width */
else
usage();
@@ -913,8 +767,7 @@ main(int argc, char *argv[])
if (!XGetWindowAttributes(dpy, parentwin, &wa))
die("could not get embedding window attributes: 0x%lx",
parentwin);
- xinitvisual();
- drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
+ drw = drw_create(dpy, screen, root, wa.width, wa.height);
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
@@ -936,40 +789,3 @@ main(int argc, char *argv[])
return 1; /* unreachable */
}
-
- void
-xinitvisual()
-{
- XVisualInfo *infos;
- XRenderPictFormat *fmt;
- int nitems;
- int i;
-
- XVisualInfo tpl = {
- .screen = screen,
- .depth = 32,
- .class = TrueColor
- };
- long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
-
- infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
- visual = NULL;
- for(i = 0; i < nitems; i ++) {
- fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
- if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
- visual = infos[i].visual;
- depth = infos[i].depth;
- cmap = XCreateColormap(dpy, root, visual, AllocNone);
- useargb = 1;
- break;
- }
- }
-
- XFree(infos);
-
- if (! visual) {
- visual = DefaultVisual(dpy, screen);
- depth = DefaultDepth(dpy, screen);
- cmap = DefaultColormap(dpy, screen);
- }
-}
diff --git a/dmenu_run b/dmenu_run
index 28fcfbc..834ede5 100755
--- a/dmenu_run
+++ b/dmenu_run
@@ -1,14 +1,2 @@
#!/bin/sh
-set -efu
-
-# dmenu_run improved
-# command ending with '!', is started in the terminal.
-
-test -s "$HOME"/.dmenurc && . "$HOME"/.dmenurc
-
-cmd="$(dmenu_path | dmenu "$@")"
-
-case "$cmd" in
- *\!) "${TERMINAL:-urxvt}" -e "${cmd%?}" & ;;
- *) IFS=' ' ${cmd} & ;;
-esac
+dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
diff --git a/drw.c b/drw.c
index 42700e5..a58a2b4 100644
--- a/drw.c
+++ b/drw.c
@@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen)
}
Drw *
-drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap)
+drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
{
Drw *drw = ecalloc(1, sizeof(Drw));
@@ -70,11 +70,8 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
drw->root = root;
drw->w = w;
drw->h = h;
- drw->visual = visual;
- drw->depth = depth;
- drw->cmap = cmap;
- drw->drawable = XCreatePixmap(dpy, root, w, h, depth);
- drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL);
+ drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
+ drw->gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw;
@@ -90,7 +87,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
drw->h = h;
if (drw->drawable)
XFreePixmap(drw->dpy, drw->drawable);
- drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth);
+ drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
}
void
@@ -184,22 +181,21 @@ drw_fontset_free(Fnt *font)
}
void
-drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha)
+drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
{
if (!drw || !dest || !clrname)
return;
- if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap,
+ if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
+ DefaultColormap(drw->dpy, drw->screen),
clrname, dest))
die("error, cannot allocate color '%s'", clrname);
-
- dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24);
}
/* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */
Clr *
-drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount)
+drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
{
size_t i;
Clr *ret;
@@ -209,7 +205,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], si
return NULL;
for (i = 0; i < clrcount; i++)
- drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]);
+ drw_clr_create(drw, &ret[i], clrnames[i]);
return ret;
}
@@ -267,7 +263,9 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
} else {
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
- d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap);
+ d = XftDrawCreate(drw->dpy, drw->drawable,
+ DefaultVisual(drw->dpy, drw->screen),
+ DefaultColormap(drw->dpy, drw->screen));
x += lpad;
w -= lpad;
}
diff --git a/drw.h b/drw.h
index 48f2f93..fd7631b 100644
--- a/drw.h
+++ b/drw.h
@@ -20,9 +20,6 @@ typedef struct {
Display *dpy;
int screen;
Window root;
- Visual *visual;
- unsigned int depth;
- Colormap cmap;
Drawable drawable;
GC gc;
Clr *scheme;
@@ -30,7 +27,7 @@ typedef struct {
} Drw;
/* Drawable abstraction */
-Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual*, unsigned int, Colormap);
+Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
void drw_free(Drw *drw);
@@ -42,8 +39,8 @@ unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
/* Colorscheme abstraction */
-void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha);
-Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount);
+void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
+Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);