From 6499e6a6313a7dda8fc75329e01d37e585839ba6 Mon Sep 17 00:00:00 2001 From: Laslo Hunhold 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 --- 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 © 2014-2020 Hiltjo Posthuma © 2015-2019 Quentin Rameau +© 2021 Laslo Hunhold 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