Re: [hackers] [sent][PATCH] Use background color for transparent PNG images

2015-12-03 Thread Markus Teich
Alexis wrote:
> I noticed that PNG images with an alpha channel were rendered on a white
> background. The attached patch changes the behaviour, so that the PNG
> background is set to the background color from the color scheme, i.e.  bgcol
> from config.h.

Heyho Alexis,

sorry for the delay. I just merged all but this patch. Thanks for your
contribution.

I did not merge this one due to two reasons: First it did not work for me (which
might be caused by some weird png format for transparency?). Second since the
switch to farbfeld is due, this change is not relevant for the next release.

--Markus



[hackers] [sent] add 'sent: ' prefix to errors || Markus Teich

2015-12-03 Thread git
commit 7e558105e6e46a6a2592f2ee15220b99922cd1f0
Author: Markus Teich 
AuthorDate: Thu Dec 3 22:59:29 2015 +0100
Commit: Markus Teich 
CommitDate: Thu Dec 3 23:02:14 2015 +0100

add 'sent: ' prefix to errors

diff --git a/sent.c b/sent.c
index 6b22e61..e717a69 100644
--- a/sent.c
+++ b/sent.c
@@ -386,6 +386,8 @@ void eprintf(const char *fmt, ...)
 {
va_list ap;
 
+   fputs("sent: ", stderr);
+
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);



[hackers] [sent] Use consistent wording for error messages || Alexis

2015-12-03 Thread git
commit 824dae147e8c89465e09709764601d7d80dff819
Author: Alexis 
AuthorDate: Thu Nov 26 15:18:44 2015 +0100
Commit: Markus Teich 
CommitDate: Thu Dec 3 23:00:28 2015 +0100

Use consistent wording for error messages

diff --git a/sent.c b/sent.c
index baf6d4f..d6c2c0b 100644
--- a/sent.c
+++ b/sent.c
@@ -135,7 +135,7 @@ Image *pngopen(char *filename)
Image *img;
 
if (!(f = fopen(filename, "rb"))) {
-   eprintf("could not open file %s:", filename);
+   eprintf("Unable to open file %s:", filename);
return NULL;
}
 
@@ -251,25 +251,25 @@ int pngprepare(Image *img)
height = img->bufheight * xw.uw / img->bufwidth;
 
if (depth < 24) {
-   eprintf("display depths <24 not supported.");
+   eprintf("Display depths <24 not supported.");
return 0;
}
 
if (!(img->ximg = XCreateImage(xw.dpy, CopyFromParent, depth, ZPixmap, 
0,
NULL, width, height, 32, 0))) {
-   eprintf("could not create XImage");
+   eprintf("Unable to create XImage.");
return 0;
}
 
if (!(img->ximg->data = malloc(img->ximg->bytes_per_line * height))) {
-   eprintf("could not alloc data section for XImage");
+   eprintf("Unable to alloc data section for XImage.");
XDestroyImage(img->ximg);
img->ximg = NULL;
return 0;
}
 
if (!XInitImage(img->ximg)) {
-   eprintf("could not init XImage");
+   eprintf("Unable to init XImage.");
free(img->ximg->data);
XDestroyImage(img->ximg);
img->ximg = NULL;
@@ -422,7 +422,7 @@ void load(FILE *fp)
 
if ((slidecount+1) * sizeof(*slides) >= size)
if (!(slides = realloc(slides, (size += BUFSIZ
-   die("cannot realloc %u bytes:", size);
+   die("Unable to realloc %u bytes:", size);
 
/* read one slide */
maxlines = 0;
@@ -435,12 +435,12 @@ void load(FILE *fp)
if (s->linecount >= maxlines) {
maxlines = 2 * s->linecount + 1;
if (!(s->lines = realloc(s->lines, maxlines * 
sizeof(s->lines[0]
-   die("cannot realloc %u bytes:", 
maxlines * sizeof(s->lines[0]));
+   die("Unable to realloc %u bytes:", 
maxlines * sizeof(s->lines[0]));
}
 
blen = strlen(buf);
if (!(s->lines[s->linecount] = strdup(buf)))
-   die("cannot strdup:");
+   die("Unable to strdup:");
if (s->lines[s->linecount][blen-1] == '\n')
s->lines[s->linecount][blen-1] = '\0';
 
@@ -470,9 +470,9 @@ void advance(const Arg *arg)
idx = new_idx;
xdraw();
if (slidecount > idx + 1 && slides[idx + 1].img && 
!pngread(slides[idx + 1].img))
-   die("could not read image %s", slides[idx + 
1].lines[0]);
+   die("Unable to read image %s.", slides[idx + 
1].lines[0]);
if (0 < idx && slides[idx - 1].img && !pngread(slides[idx - 
1].img))
-   die("could not read image %s", slides[idx - 
1].lines[0]);
+   die("Unable to read image %s.", slides[idx - 
1].lines[0]);
}
 }
 
@@ -537,9 +537,9 @@ void xdraw()
 0);
drw_map(d, xw.win, 0, 0, xw.w, xw.h);
} else if (!(im->state & LOADED) && !pngread(im)) {
-   eprintf("could not read image %s", slides[idx].lines[0]);
+   eprintf("Unable to read image %s.", slides[idx].lines[0]);
} else if (!(im->state & SCALED) && !pngprepare(im)) {
-   eprintf("could not prepare image %s for drawing", 
slides[idx].lines[0]);
+   eprintf("Unable to prepare image %s for drawing.", 
slides[idx].lines[0]);
} else if (!(im->state & DRAWN)) {
pngdraw(im);
}
@@ -552,7 +552,7 @@ void xhints()
XSizeHints *sizeh = NULL;
 
if (!(sizeh = XAllocSizeHints()))
-   die("sent: Could not alloc size hints");
+   die("Unable to alloc size hints.");
 
sizeh->flags = PSize;
sizeh->height = xw.h;
@@ -567,7 +567,7 @@ void xinit()
XTextProperty prop;
 
if (!(xw.dpy = XOpenDisplay(NULL)))
-   die("Can't open display.");
+   die("Unable to open display.");
xw.scr = XDefaultScreen(xw.dpy);
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
resize(DisplayWidth(xw.dpy, xw.scr), DisplayHeight(xw.dpy, xw.scr));
@@ -585,7 +5

[hackers] [sent] Refactor die() to use eprintf() || Alexis

2015-12-03 Thread git
commit 91aeb01dcef28aea6e15ba7d1c9a094d01dfc41e
Author: Alexis 
AuthorDate: Thu Nov 26 15:20:09 2015 +0100
Commit: Markus Teich 
CommitDate: Thu Dec 3 23:00:44 2015 +0100

Refactor die() to use eprintf()

diff --git a/sent.c b/sent.c
index d6c2c0b..6b22e61 100644
--- a/sent.c
+++ b/sent.c
@@ -376,15 +376,9 @@ void die(const char *fmt, ...)
va_list ap;
 
va_start(ap, fmt);
-   vfprintf(stderr, fmt, ap);
+   eprintf(fmt, ap);
va_end(ap);
 
-   if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':') {
-   fputc(' ', stderr);
-   perror(NULL);
-   } else {
-   fputc('\n', stderr);
-   }
exit(1);
 }
 



[hackers] [sent] Add 'n' and 'p' keys to navigate slides || Alexis

2015-12-03 Thread git
commit 98e18541897b019d1c8bbd4b7a0ba51e65974a98
Author: Alexis 
AuthorDate: Thu Nov 26 15:22:01 2015 +0100
Commit: Markus Teich 
CommitDate: Thu Dec 3 23:00:53 2015 +0100

Add 'n' and 'p' keys to navigate slides

diff --git a/config.def.h b/config.def.h
index 0a56047..2dae620 100644
--- a/config.def.h
+++ b/config.def.h
@@ -42,4 +42,6 @@ static Shortcut shortcuts[] = {
{ XK_Up,  advance,{.i = -1} },
{ XK_Next,advance,{.i = +1} },
{ XK_Prior,   advance,{.i = -1} },
+   { XK_n,   advance,{.i = +1} },
+   { XK_p,   advance,{.i = -1} },
 };



Re: [hackers] [dmenu][RFC][PATCH] History functionality

2015-12-03 Thread Silvan Jegen
Hi

On Thu, Dec 3, 2015 at 11:57 AM, Xarchus  wrote:
> And a couple of fixes for the 'history' patch:
>
> - fixed the code in the BEGIN block of the inline awk program in dmenu_run;
>   if no history file was supplied the awk script was just ignoring any
> output from dmenu
>
> - improved the history/cache parsing/de-duplication awk one-liner in
>   dmenu_path; the former 'NR==FNR' test was not enough: in case of a not
> supplied or empty history file it attempted to remove a count followed by a
> tab from the file names in the cache. Obviously to find such an occurrence
> would be crazy rare, so it was quite harmless (I suppose that you don't
> have any executables in your path of the form "count\tname", do you ?
> Anyway, now you can :) )
>
> New patch attached.

Thanks!

At the moment I don't have time to test the patch I am afraid but I
will test it as soon as I find the time.

I would prefer to not deal with the case the HISTORY is unset and just
assume it is. The reason being that if people don't want to use the
history functionality, they should not use this patch. Under this
assumption the code can be further simplified.

I also prefer setting the HISTORY variable to a file name explicitly
as opposed to in an environment variable with fallback code but that
may only be me. Setting the history file name directly in dmenu_run is
not any harder than setting an environment variable and checking for
default location would also not be needed then.


Cheers,

Silvan



Re: [hackers] [dmenu][RFC][PATCH] History functionality

2015-12-03 Thread Xarchus
And a couple of fixes for the 'history' patch:

- fixed the code in the BEGIN block of the inline awk program in dmenu_run;
  if no history file was supplied the awk script was just ignoring any
output from dmenu

- improved the history/cache parsing/de-duplication awk one-liner in
  dmenu_path; the former 'NR==FNR' test was not enough: in case of a not
supplied or empty history file it attempted to remove a count followed by a
tab from the file names in the cache. Obviously to find such an occurrence
would be crazy rare, so it was quite harmless (I suppose that you don't
have any executables in your path of the form "count\tname", do you ?
Anyway, now you can :) )

New patch attached.

diff --git a/dmenu_path b/dmenu_path
old mode 100644
new mode 100755
index 338bac4..b81a85a
--- a/dmenu_path
+++ b/dmenu_path
@@ -1,4 +1,10 @@
 #!/bin/sh
+HISTORY="$1"
+
+if stest -v -qfrw "$HISTORY"; then
+   unset HISTORY
+fi
+
 cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
 if [ -d "$cachedir" ]; then
cache=$cachedir/dmenu_run
@@ -7,7 +13,7 @@ else
 fi
 IFS=:
 if stest -dqr -n "$cache" $PATH; then
-   stest -flx $PATH | sort -u | tee "$cache"
-else
-   cat "$cache"
+   stest -flx $PATH | sort -u > "$cache"
 fi
+awk '!cache { sub("^[0-9]+\t","") } !x[$0]++' "$HISTORY" cache=1 "$cache"
+
diff --git a/dmenu_run b/dmenu_run
index 834ede5..e93a790 100755
--- a/dmenu_run
+++ b/dmenu_run
@@ -1,2 +1,43 @@
 #!/bin/sh
-dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
+
+historyfile="$DMENU_RUN_USE_HISTORY"
+
+if [ -n "$historyfile" ]; then
+   if [ "$historyfile" = "DEFAULT" ]; then
+   cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
+   if [ -d "$cachedir" ]; then
+   historyfile=$cachedir/dmenu_history
+   else
+   historyfile=$HOME/.dmenu_history # if no xdg dir, fall 
back to dotfile in ~
+   fi
+   fi
+fi
+
+dmenu_path $historyfile | dmenu "$@" \
+   | awk -v histfile=$historyfile '
+   BEGIN {
+   FS=OFS="\t"
+   if(histfile) {
+   while ( (getline < histfile) > 0 ) {
+   count=$1
+   sub("^[0-9]+\t","")
+   fname=$0
+   history[fname]=count
+   }
+   close(histfile)
+   }
+   }
+
+   {
+   history[$0]++
+   print
+   }
+
+   END {
+   if(!histfile)
+   exit
+   for (f in history)
+   print history[f],f | "sort -t '\t' -k1rn >" 
histfile
+   }
+   ' \
+   | while read cmd; do ${SHELL:-"/bin/sh"} -c "$cmd" & done