On Sun, 15 Aug 2021 23:44:58 +0600
NRK <[email protected]> wrote:

Dear NRK,

> currently config.h allows users to set the value of topbar to 0.
> however if one does that, there's no way for him to get a topbar
> again. it makes more sense to have -b as a toggle instead.

this trades one problem for another given dmenu suddenly changes
behaviour unexpectedly.

Imagine someone having set up dmenu to be at the top by default (using
config.h), but having a certain launcher script that invokes dmenu to
be at the bottom by passing "-b". Now said user, using the launcher
script often, learns to prefer the bottom bar and sets it as such in
config.h. Assuming the b-flag will just be a redundancy, he keeps them
in his launcher, only to be surprised that dmenu suddenly shows up at
the top.

In my opinion, and the maintainer's may differ in that regard,
behaviour of flags should not be surprising when the defaults have been
changed.

Because of that, why not add another flag "-t" that forces dmenu to
appear at the top of the screen. This makes it immediately obvious what
happens (rather than turning b into a position-toggle, which makes zero
phonetic sense and effectively renders the b-flag unusable for scripts
because its inconsistent) and adds very little overhead.

See the attached patch (also @Hiltjo, what do you think?). :)

With best regards

Laslo
From 6499e6a6313a7dda8fc75329e01d37e585839ba6 Mon Sep 17 00:00:00 2001
From: Laslo Hunhold <[email protected]>
Date: Mon, 16 Aug 2021 09:36:49 +0200
Subject: [PATCH] Add t-flag complementing b-flag (top/bottom-positioning)

There currently is no way to override the bottom-positioning if it
has been set as a default in config.h. The simplest solution is to
just add a complementary t-flag which overrides whatever behaviour
has been set.

This is more favourable compared to turning the b-flag into a toggle,
given it would lead to inconsistent behaviour (scripts can't rely on it)
and break the phonetic readability of the letter "b".

Separate t- and b-flags are very clear and add negligible overhead.

Signed-off-by: Laslo Hunhold <[email protected]>
---
 LICENSE      |  1 +
 config.def.h |  2 +-
 dmenu.1      |  6 +++++-
 dmenu.c      | 20 +++++++++++++++-----
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/LICENSE b/LICENSE
index 3afd28e..f4a0e4f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -10,6 +10,7 @@ MIT/X Consortium License
 © 2010-2012 Connor Lane Smith <[email protected]>
 © 2014-2020 Hiltjo Posthuma <[email protected]>
 © 2015-2019 Quentin Rameau <[email protected]>
+© 2021 Laslo Hunhold <[email protected]>
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
diff --git a/config.def.h b/config.def.h
index 1edb647..6a3839a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,7 +1,7 @@
 /* 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 topbar = 1;                      /* -b/-t option; if 0, dmenu appears at bottom     */
 /* -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 323f93c..15c5e68 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -3,7 +3,8 @@
 dmenu \- dynamic menu
 .SH SYNOPSIS
 .B dmenu
-.RB [ \-bfiv ]
+.RB [ \-b | \-t ]
+.RB [ \-fiv ]
 .RB [ \-l
 .IR lines ]
 .RB [ \-m
@@ -75,6 +76,9 @@ defines the selected background color.
 .BI \-sf " color"
 defines the selected foreground color.
 .TP
+.B \-t
+dmenu appears at the top of the screen.
+.TP
 .B \-v
 prints version information to stdout, then exits.
 .TP
diff --git a/dmenu.c b/dmenu.c
index 98507d9..85f1fa5 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -709,18 +709,20 @@ int
 main(int argc, char *argv[])
 {
 	XWindowAttributes wa;
-	int i, fast = 0;
+	int i, bflag = 0, tflag = 0, fast = 0;
 
 	for (i = 1; i < argc; i++)
 		/* these options take no arguments */
 		if (!strcmp(argv[i], "-v")) {      /* prints version information */
 			puts("dmenu-"VERSION);
 			exit(0);
-		} else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */
-			topbar = 0;
-		else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */
+		} else if (!strcmp(argv[i], "-b")) { /* appears at the bottom of the screen */
+			bflag = 1;
+		} else if (!strcmp(argv[i], "-t")) {  /* appears at the top of the screen */
+			tflag = 1;
+		} else if (!strcmp(argv[i], "-f")) { /* grabs keyboard before reading stdin */
 			fast = 1;
-		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
+		} else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
 		} else if (i + 1 == argc)
@@ -747,6 +749,14 @@ main(int argc, char *argv[])
 		else
 			usage();
 
+	if (bflag && tflag) {
+		usage();
+	} else if (bflag) {
+		topbar = 0;
+	} else if (tflag) {
+		topbar = 1;
+	}
+
 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		fputs("warning: no locale support\n", stderr);
 	if (!(dpy = XOpenDisplay(NULL)))
-- 
2.32.0

Reply via email to