summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2024-08-05 18:15:19 +0400
committerSuleyman Farajli <suleyman@farajli.net>2024-08-05 18:15:19 +0400
commit5fa8857aa8dd86d1703c469791554c071ff95b8c (patch)
tree336f0d8524fb6b20b542bfeb9eb716e92c9e0093
parentbf33e34bbb3e907bf91fe2799ffa8f2d55661645 (diff)
parent82d03a93baef4f8b939e8385603323207779e51f (diff)
Merge branch 'grid' into center
-rw-r--r--config.def.h1
-rw-r--r--dmenu.c22
2 files changed, 18 insertions, 5 deletions
diff --git a/config.def.h b/config.def.h
index 832896f..a2296f6 100644
--- a/config.def.h
+++ b/config.def.h
@@ -18,6 +18,7 @@ static const char *colors[SchemeLast][2] = {
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0;
+static unsigned int columns = 0;
/*
* Characters not considered part of a word while deleting words
diff --git a/dmenu.c b/dmenu.c
index 32d6a9d..9fc07f7 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -83,7 +83,7 @@ calcoffsets(void)
int i, n;
if (lines > 0)
- n = lines * bh;
+ n = lines * columns * bh;
else
n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
/* calculate which items will begin the next page and previous page */
@@ -177,9 +177,15 @@ drawmenu(void)
}
if (lines > 0) {
- /* draw vertical list */
- for (item = curr; item != next; item = item->right)
- drawitem(item, x, y += bh, mw - x);
+ /* draw grid */
+ int i = 0;
+ for (item = curr; item != next; item = item->right, i++)
+ drawitem(
+ item,
+ x + ((i / lines) * ((mw - x) / columns)),
+ y + (((i % lines) + 1) * bh),
+ (mw - x) / columns
+ );
} else if (matches) {
/* draw horizontal list */
x += inputw;
@@ -768,7 +774,13 @@ main(int argc, char *argv[])
/* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]);
- else if (!strcmp(argv[i], "-m"))
+ else if (!strcmp(argv[i], "-g")) { /* number of columns in grid */
+ columns = atoi(argv[++i]);
+ if (lines == 0) lines = 1;
+ } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
+ lines = atoi(argv[++i]);
+ if (columns == 0) columns = 1;
+ } else if (!strcmp(argv[i], "-m"))
mon = atoi(argv[++i]);
else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i];