Re: [hackers] dmenu][PATCH reversed

2016-02-21 Thread Maurycy Skier

On 20/02/16 22:35, FRIGN wrote:

On Sat, 20 Feb 2016 22:28:14 +0100
Maurycy Skier  wrote:

Hey Maurycy,


Hi, I hope I am doing everything right.

sadly no. Please better send your patch using git format-patch.
You do it like this:

Make your changes on the files, then do git add, git commit and then
do "git format-patch -1" to generate a patch with proper description
and authorship.


P.S. You could also add another target to Makefile: git-diff. It'd go
like this:
git-diff:
   git-diff > dmenu-${VERSION}-${PATCHNAME}.diff

Absolutely not, see above.

Thanks for your patch, but please resend it with git format-patch in a
response to this thread! :)

Cheers

FRIGN



Ok, here you go.
>From c99d58e6211271780f7b28464807aadb62fca41f Mon Sep 17 00:00:00 2001
From: Maurycy Skier 
Date: Sun, 21 Feb 2016 11:58:42 +0100
Subject: [PATCH] add option to reverse the list and put prompt under it

---
 config.def.h |  1 +
 dmenu.1  |  8 
 dmenu.c  | 18 +-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/config.def.h b/config.def.h
index dcffd38..9a65a47 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,7 @@
 /* Default settings; can be overriden by command line. */
 
 static int topbar = 1;  /* -b  option; if 0, dmenu appears at bottom */
+static int reversed = 0;  /* -r  option; if 1, prompt appears under the list */
 /* -fn option overrides fonts[0]; default X11 font or font set */
 static const char *fonts[] = {
 	"monospace:size=10"
diff --git a/dmenu.1 b/dmenu.1
index d3ab805..c6938db 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -6,6 +6,7 @@ dmenu \- dynamic menu
 .RB [ \-b ]
 .RB [ \-f ]
 .RB [ \-i ]
+.RB [ \-r ]
 .RB [ \-l
 .RB [ \-m
 .IR monitor ]
@@ -48,6 +49,13 @@ X until stdin reaches end\-of\-file.
 .B \-i
 dmenu matches menu items case insensitively.
 .TP
+.B \-r
+reverses the list and puts the prompt under it (looks nice with
+.B \-b
+and
+.B \-l
+).
+.TP
 .BI \-l " lines"
 dmenu lists items vertically, with the given number of lines.
 .TP
diff --git a/dmenu.c b/dmenu.c
index e0c2f80..62eb762 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -120,30 +120,36 @@ drawmenu(void)
 	int curpos;
 	struct item *item;
 	int x = 0, y = 0, h = bh, w;
+	int inputy = reversed ? lines * h : 0;
 
 	drw_setscheme(drw, [SchemeNorm]);
 	drw_rect(drw, 0, 0, mw, mh, 1, 1, 1);
 
 	if (prompt && *prompt) {
 		drw_setscheme(drw, [SchemeSel]);
-		drw_text(drw, x, 0, promptw, bh, prompt, 0);
+		drw_text(drw, x, inputy, promptw, bh, prompt, 0);
 		x += promptw;
 	}
 	/* draw input field */
 	w = (lines > 0 || !matches) ? mw - x : inputw;
 	drw_setscheme(drw, [SchemeNorm]);
-	drw_text(drw, x, 0, w, bh, text, 0);
+	drw_text(drw, x, inputy, w, bh, text, 0);
 
 	if ((curpos = TEXTNW(text, cursor) + bh / 2 - 2) < w) {
 		drw_setscheme(drw, [SchemeNorm]);
-		drw_rect(drw, x + curpos + 2, 2, 1, bh - 4, 1, 1, 0);
+		drw_rect(drw, x + curpos + 2, inputy + 2, 1, bh - 4, 1, 1, 0);
 	}
 
 	if (lines > 0) {
 		/* draw vertical list */
+		if (reversed)
+			y = lines * h;
 		w = mw - x;
 		for (item = curr; item != next; item = item->right) {
-			y += h;
+			if (reversed)
+y -= h;
+			else
+y += h;
 			if (item == sel)
 drw_setscheme(drw, [SchemeSel]);
 			else if (item->out)
@@ -610,7 +616,7 @@ setup(void)
 static void
 usage(void)
 {
-	fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+	fputs("usage: dmenu [-b] [-f] [-i] [-r] [-l lines] [-p prompt] [-fn font][-m monitor]\n"
 	  " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(1);
 }
@@ -629,6 +635,8 @@ 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], "-r"))   /* reverses the list and puts the prompt under it */
+			reversed = 1;
 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
-- 
2.7.0



Re: [hackers] dmenu][PATCH reversed

2016-02-21 Thread Hiltjo Posthuma
On Sat, Feb 20, 2016 at 10:28 PM, Maurycy Skier  wrote:
> Hi, I hope I am doing everything right.
>
> I added a new option (-r) which reverses the list and puts the input under
> it. If you've used Vimperator or CtrlP plugin in Vim you can say it tries to
> make dmenu lookalike (with -b and -l option).
>

Hi,

You can add this to the wiki. Make sure to maintain the patch against
dmenu releases.

Kind regards,
Hiltjo



Re: [hackers] dmenu][PATCH reversed

2016-02-20 Thread FRIGN
On Sat, 20 Feb 2016 22:28:14 +0100
Maurycy Skier  wrote:

Hey Maurycy,

> Hi, I hope I am doing everything right.

sadly no. Please better send your patch using git format-patch.
You do it like this:

Make your changes on the files, then do git add, git commit and then
do "git format-patch -1" to generate a patch with proper description
and authorship.

> P.S. You could also add another target to Makefile: git-diff. It'd go
> like this:
> git-diff:
>   git-diff > dmenu-${VERSION}-${PATCHNAME}.diff

Absolutely not, see above.

Thanks for your patch, but please resend it with git format-patch in a
response to this thread! :)

Cheers

FRIGN

-- 
FRIGN