[wiki] [sites] Add improved dmenu xft patch || Danil Semelenov

From: <git_AT_suckless.org>
Date: Thu, 17 Sep 2015 22:26:45 +0200

commit 9fd0904cebfcc0f585f344da2efbd2e3ca8c6458
Author: Danil Semelenov <mail_AT_danil.mobi>
Date: Thu Sep 17 23:26:31 2015 +0300

    Add improved dmenu xft patch

diff --git a/tools.suckless.org/dmenu/patches/dmenu-4.5-xft-improved.diff b/tools.suckless.org/dmenu/patches/dmenu-4.5-xft-improved.diff
new file mode 100644
index 0000000..12f8ce7
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/dmenu-4.5-xft-improved.diff
_AT_@ -0,0 +1,425 @@
+diff --git a/config.mk b/config.mk
+index 92a5e63..9cff5db 100644
+--- a/config.mk
++++ b/config.mk
+_AT_@ -12,9 +12,13 @@ X11LIB = /usr/X11R6/lib
+ XINERAMALIBS = -lXinerama
+ XINERAMAFLAGS = -DXINERAMA
+
++# Xft, comment if you don't want it
++XFTINC = -I/usr/include/freetype2
++XFTLIBS = -lXft -lXrender -lfreetype -lz -lfontconfig
++
+ # includes and libs
+-INCS = -I${X11INC}
+-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
++INCS = -I${X11INC} ${XFTINC}
++LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${XFTLIBS}
+
+ # flags
+ CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
+diff --git a/dmenu.1 b/dmenu.1
+index 0784cd9..f29ca36 100644
+--- a/dmenu.1
++++ b/dmenu.1
+_AT_@ -53,7 +53,7 @@ dmenu lists items vertically, with the given number of lines.
+ defines the prompt to be displayed to the left of the input field.
+ .TP
+ .BI \-fn " font"
+-defines the font or font set used.
++defines the font or font set used. eg. "fixed" or "Monospace-12:normal" (an xft font)
+ .TP
+ .BI \-nb " color"
+ defines the normal background color.
+diff --git a/dmenu.c b/dmenu.c
+index 4ea95f8..b4549ef 100644
+--- a/dmenu.c
++++ b/dmenu.c
+_AT_@ -17,6 +17,7 @@
+ * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
+ #define MIN(a,b) ((a) < (b) ? (a) : (b))
+ #define MAX(a,b) ((a) > (b) ? (a) : (b))
++#define DEFFONT "monospace-9" /* xft example: "Monospace-11" */
+
+ typedef struct Item Item;
+ struct Item {
+_AT_@ -26,6 +27,7 @@ struct Item {
+
+ static void appenditem(Item *item, Item **list, Item **last);
+ static void calcoffsets(void);
++static void cleanup(void);
+ static char *cistrstr(const char *s, const char *sub);
+ static void drawmenu(void);
+ static void grabkeyboard(void);
+_AT_@ -50,10 +52,12 @@ static const char *normfgcolor = "#bbbbbb";
+ static const char *selbgcolor = "#005577";
+ static const char *selfgcolor = "#eeeeee";
+ static unsigned int lines = 0;
+-static unsigned long normcol[ColLast];
+-static unsigned long selcol[ColLast];
++static ColorSet *normcol;
++static ColorSet *selcol;
+ static Atom clip, utf8;
+ static Bool topbar = True;
++static Bool running = True;
++static int ret = 0;
+ static DC *dc;
+ static Item *items = NULL;
+ static Item *matches, *matchend;
+_AT_@ -104,7 +108,9 @@ main(int argc, char *argv[]) {
+ usage();
+
+ dc = initdc();
+- initfont(dc, font);
++ initfont(dc, font ? font : DEFFONT);
++ normcol = initcolor(dc, normfgcolor, normbgcolor);
++ selcol = initcolor(dc, selfgcolor, selbgcolor);
+
+ if(fast) {
+ grabkeyboard();
+_AT_@ -117,7 +123,8 @@ main(int argc, char *argv[]) {
+ setup();
+ run();
+
+- return 1; /* unreachable */
++ cleanup();
++ return ret;
+ }
+
+ void
+_AT_@ -160,6 +167,15 @@ cistrstr(const char *s, const char *sub) {
+ }
+
+ void
++cleanup(void) {
++ freecol(dc, normcol);
++ freecol(dc, selcol);
++ XDestroyWindow(dc->dpy, win);
++ XUngrabKeyboard(dc->dpy, CurrentTime);
++ freedc(dc);
++}
++
++void
+ drawmenu(void) {
+ int curpos;
+ Item *item;
+_AT_@ -167,7 +183,7 @@ drawmenu(void) {
+ dc->x = 0;
+ dc->y = 0;
+ dc->h = bh;
+- drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
++ drawrect(dc, 0, 0, mw, mh, True, normcol->BG);
+
+ if(prompt) {
+ dc->w = promptw;
+_AT_@ -177,8 +193,9 @@ drawmenu(void) {
+ /* draw input field */
+ dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
+ drawtext(dc, text, normcol);
++ dc->x += 2;
+ if((curpos = textnw(dc, text, cursor) + dc->h/2 - 2) < dc->w)
+- drawrect(dc, curpos, 2, 1, dc->h - 4, True, FG(dc, normcol));
++ drawrect(dc, curpos, 2, 1, dc->h - 4, True, normcol->FG);
+
+ if(lines > 0) {
+ /* draw vertical list */
+_AT_@ -321,7 +338,8 @@ keypress(XKeyEvent *ev) {
+ sel = matchend;
+ break;
+ case XK_Escape:
+- exit(EXIT_FAILURE);
++ ret = EXIT_FAILURE;
++ running = False;
+ case XK_Home:
+ if(sel == matches) {
+ cursor = 0;
+_AT_@ -359,7 +377,8 @@ keypress(XKeyEvent *ev) {
+ case XK_Return:
+ case XK_KP_Enter:
+ puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
+- exit(EXIT_SUCCESS);
++ ret = EXIT_SUCCESS;
++ running = False;
+ case XK_Right:
+ if(text[cursor] != '
Received on Thu Sep 17 2015 - 22:26:45 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 17 2015 - 22:36:10 CEST