[dev] [dmenu] patch for Xft support

2011-12-30 Thread Aragon Gouveia

Hi,

A while ago Dan Brown contributed an Xft patch for dmenu 4.2.1:

http://lists.suckless.org/dev/1011/6474.html

For some reason it was never added to the patches section of 
suckless.org.  I've attached an updated patch for 4.4.1.



Regards,
Aragon
--- dmenu.c.orig2011-09-19 11:48:13.0 +0200
+++ dmenu.c 2011-12-31 00:48:16.0 +0200
@@ -16,6 +16,7 @@
 #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) 
&& (y) < (ry)+(rh))
 #define MIN(a,b)((a) < (b) ? (a) : (b))
 #define MAX(a,b)((a) > (b) ? (a) : (b))
+#define DEFFONT "fixed" /* xft example: "Monospace-11" */
 
 typedef struct Item Item;
 struct Item {
@@ -25,6 +26,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);
@@ -49,10 +51,12 @@ static const char *normbgcolor = "#c
 static const char *normfgcolor = "#00";
 static const char *selbgcolor  = "#0066ff";
 static const char *selfgcolor  = "#ff";
-static unsigned long normcol[ColLast];
-static unsigned long selcol[ColLast];
+static ColorSet *normcol;
+static ColorSet *selcol;
 static Atom utf8;
 static Bool topbar = True;
+static Bool running = True;
+static int ret = 0;
 static DC *dc;
 static Item *items = NULL;
 static Item *matches, *matchend;
@@ -102,7 +106,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();
@@ -115,7 +121,8 @@ main(int argc, char *argv[]) {
setup();
run();
 
-   return EXIT_FAILURE; /* unreachable */
+   cleanup();
+   return ret;
 }
 
 void
@@ -158,6 +165,16 @@ cistrstr(const char *s, const char *sub)
 }
 
 void
+cleanup(void) {
+Item *itm;
+freecol(dc, normcol);
+freecol(dc, selcol);
+XDestroyWindow(dc->dpy, win);
+XUngrabKeyboard(dc->dpy, CurrentTime);
+freedc(dc);
+}
+
+void
 drawmenu(void) {
int curpos;
Item *item;
@@ -165,7 +182,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;
@@ -175,7 +192,7 @@ drawmenu(void) {
dc->w = (lines > 0 || !matches) ? mw - dc->x : inputw;
drawtext(dc, text, normcol);
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) {
dc->w = mw - dc->x;
@@ -301,7 +318,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;
@@ -337,7 +355,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] != '\0') {
cursor = nextrune(+1);
@@ -449,7 +468,7 @@ void
 run(void) {
XEvent ev;
 
-   while(!XNextEvent(dc->dpy, &ev))
+   while(running && !XNextEvent(dc->dpy, &ev))
switch(ev.type) {
case Expose:
if(ev.xexpose.count == 0)
@@ -479,11 +498,6 @@ setup(void) {
XineramaScreenInfo *info;
 #endif
 
-   normcol[ColBG] = getcolor(dc, normbgcolor);
-   normcol[ColFG] = getcolor(dc, normfgcolor);
-   selcol[ColBG]  = getcolor(dc, selbgcolor);
-   selcol[ColFG]  = getcolor(dc, selfgcolor);
-
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
 
/* menu geometry */
--- draw.c.orig 2011-09-19 11:48:13.0 +0200
+++ draw.c  2011-12-31 01:44:39.0 +0200
@@ -9,9 +9,6 @@
 
 #define MAX(a, b)  ((a) > (b) ? (a) : (b))
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
-#define DEFAULTFN  "fixed"
-
-static Bool loadfont(DC *dc, const char *fontstr);
 
 void
 drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, 
unsigned long color) {
@@ -23,7 +20,7 @@ drawrect(DC *dc, int x, int y, unsigned 
 }
 
 void
-drawtext(DC *dc, const char *text, unsigned long col[ColLast]) {
+drawtext(DC *dc, const char *text, ColorSet *col) {
char buf[BUFSIZ];
size_t mn, n

Re: [dev] [dmenu] patch for Xft support

2012-01-01 Thread Aragon Gouveia

Hi,

On 12/31/11 18:24, Connor Lane Smith wrote:

The suckless site is publicly modifiable [1]. If you could add the
patch to the dmenu patches section that would be great.


Done, thanks!


Regards,
Aragon



Re: [dev] dmenu tip build error

2012-01-25 Thread Aragon Gouveia

On 01/25/12 12:26, Connor Lane Smith wrote:

I think that patch is GNU-specific. The problem is that using
-D_POSIX_C_SOURCE=2 was breaking builds on FreeBSD


FWIW, my update to FreeBSD's dmenu port patches those bits, so it's 
probably OK if you don't worry too much about it for FreeBSD. :)