URI: 
       dmenu-grid-4.9.diff - sites - public wiki contents of suckless.org
  HTML git clone git://git.suckless.org/sites
   DIR Log
   DIR Files
   DIR Refs
       ---
       dmenu-grid-4.9.diff (3353B)
       ---
            1 From 39ab9676914bd0d8105d0f96bbd7611a53077438 Mon Sep 17 00:00:00 2001
            2 From: Miles Alan <m@milesalan.com>
            3 Date: Sat, 4 Jul 2020 11:19:04 -0500
            4 Subject: [PATCH] Add -g option to display entries in the given number of grid
            5  columns
            6 
            7 This option can be used in conjunction with -l to format dmenu's options in
            8 arbitrary size grids. For example, to create a 4 column by 6 line grid, you
            9 could use: dmenu -g 4 -l 6
           10 ---
           11  config.def.h |  3 ++-
           12  dmenu.1      |  7 ++++++-
           13  dmenu.c      | 22 ++++++++++++++++------
           14  3 files changed, 24 insertions(+), 8 deletions(-)
           15 
           16 diff --git a/config.def.h b/config.def.h
           17 index 1edb647..96cf3c9 100644
           18 --- a/config.def.h
           19 +++ b/config.def.h
           20 @@ -13,8 +13,9 @@ static const char *colors[SchemeLast][2] = {
           21          [SchemeSel] = { "#eeeeee", "#005577" },
           22          [SchemeOut] = { "#000000", "#00ffff" },
           23  };
           24 -/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
           25 +/* -l and -g options; controls number of lines and columns in grid if > 0 */
           26  static unsigned int lines      = 0;
           27 +static unsigned int columns    = 0;
           28  
           29  /*
           30   * Characters not considered part of a word while deleting words
           31 diff --git a/dmenu.1 b/dmenu.1
           32 index 323f93c..d0a734a 100644
           33 --- a/dmenu.1
           34 +++ b/dmenu.1
           35 @@ -4,6 +4,8 @@ dmenu \- dynamic menu
           36  .SH SYNOPSIS
           37  .B dmenu
           38  .RB [ \-bfiv ]
           39 +.RB [ \-g
           40 +.IR columns ]
           41  .RB [ \-l
           42  .IR lines ]
           43  .RB [ \-m
           44 @@ -47,8 +49,11 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
           45  .B \-i
           46  dmenu matches menu items case insensitively.
           47  .TP
           48 +.BI \-g " columns"
           49 +dmenu lists items in a grid with the given number of columns.
           50 +.TP
           51  .BI \-l " lines"
           52 -dmenu lists items vertically, with the given number of lines.
           53 +dmenu lists items in a grid with the given number of lines.
           54  .TP
           55  .BI \-m " monitor"
           56  dmenu is displayed on the monitor number supplied. Monitor numbers are starting
           57 diff --git a/dmenu.c b/dmenu.c
           58 index 6b8f51b..d79b6bb 100644
           59 --- a/dmenu.c
           60 +++ b/dmenu.c
           61 @@ -77,7 +77,7 @@ calcoffsets(void)
           62          int i, n;
           63  
           64          if (lines > 0)
           65 -                n = lines * bh;
           66 +                n = lines * columns * bh;
           67          else
           68                  n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
           69          /* calculate which items will begin the next page and previous page */
           70 @@ -152,9 +152,15 @@ drawmenu(void)
           71          }
           72  
           73          if (lines > 0) {
           74 -                /* draw vertical list */
           75 -                for (item = curr; item != next; item = item->right)
           76 -                        drawitem(item, x, y += bh, mw - x);
           77 +                /* draw grid */
           78 +                int i = 0;
           79 +                for (item = curr; item != next; item = item->right, i++)
           80 +                        drawitem(
           81 +                                item,
           82 +                                x + ((i / lines) *  ((mw - x) / columns)),
           83 +                                y + (((i % lines) + 1) * bh),
           84 +                                (mw - x) / columns
           85 +                        );
           86          } else if (matches) {
           87                  /* draw horizontal list */
           88                  x += inputw;
           89 @@ -708,9 +714,13 @@ main(int argc, char *argv[])
           90                  } else if (i + 1 == argc)
           91                          usage();
           92                  /* these options take one argument */
           93 -                else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
           94 +                else if (!strcmp(argv[i], "-g")) {   /* number of columns in grid */
           95 +                        columns = atoi(argv[++i]);
           96 +                        if (lines == 0) lines = 1;
           97 +                } else if (!strcmp(argv[i], "-l")) { /* number of lines in grid */
           98                          lines = atoi(argv[++i]);
           99 -                else if (!strcmp(argv[i], "-m"))
          100 +                        if (columns == 0) columns = 1;
          101 +                } else if (!strcmp(argv[i], "-m"))
          102                          mon = atoi(argv[++i]);
          103                  else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
          104                          prompt = argv[++i];
          105 -- 
          106 2.23.1
          107