dmenu

my fork of dmenu
Index Commits Files Refs README LICENSE
commit 6f65032a43bcb4099c497775f276eb22af46df9b
parent 5f3067878286e39d683cb8ecb04cd0870176130b
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Wed, 16 Mar 2022 00:11:52 -0300

Reorganized code

Diffstat:
Aconfig.h | 32++++++++++++++++++++++++++++++++
Admenu | 0
Mdmenu.c | 45+++++++++++++++++++++++++++++----------------
Admenu.o | 0
Adrw.o | 0
Apatches/dmenu-mousesupport-scrollperline.diff | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Astest | 0
Astest.o | 0
Autil.o | 0
9 files changed, 135 insertions(+), 16 deletions(-)
diff --git a/config.h b/config.h
@@ -0,0 +1,32 @@
+/* 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 fuzzy = 1;                      /* -F  option; if 0, dmenu doesn't use fuzzy matching     */
+static int centered = 0;                    /* -c option; centers dmenu on screen */
+/* static int min_width = -200;                    /1* minimum width when centered *1/ */
+/* -fn option overrides fonts[0]; default X11 font or font set */
+static const char *fonts[] = {
+    "DejaVuSansMono Nerd Font:style=Regular:size=8"
+};
+static const char *prompt      = NULL;      /* -p  option; prompt to the left of input field */
+static const char *colors[SchemeLast][2] = {
+    /*     fg         bg       */
+    [SchemeNorm] = { "#bbbbbb", "#222222" },
+    [SchemeSel] = { "#eeeeee", "#005577" },
+    [SchemeOut] = { "#000000", "#00ffff" },
+};
+/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
+static unsigned int lines      = 0;
+/* -h option; minimum height of a menu line */
+static unsigned int lineheight = 0;
+static unsigned int min_lineheight = 8;
+
+/*
+ * Characters not considered part of a word while deleting words
+ * for example: " /?\"&[]"
+ */
+static const char worddelimiters[] = " ";
+
+/* Size of the window border */
+static unsigned int border_width = 0;
diff --git a/dmenu b/dmenu
Binary files differ.
diff --git a/dmenu.c b/dmenu.c
@@ -93,18 +93,7 @@ calcoffsets(void)
         if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
             break;
 
-    for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
-        if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n)
-            break;
-}
-
-static int
-max_textw(void)
-{
-    int len = 0;
-    for (struct item *item = items; item && item->text; item++)
-        len = MAX(TEXTW(item->text), len);
-    return len;
+    prev = curr->left;
 }
 
 static void
@@ -158,8 +147,10 @@ drawmenu(void)
         drw_setscheme(drw, scheme[SchemeSel]);
         x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
     }
+
     /* draw input field */
     w = (lines > 0 || !matches) ? mw - x : inputw;
+
     drw_setscheme(drw, scheme[SchemeNorm]);
     drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
 
@@ -613,7 +604,7 @@ buttonpress(XEvent *e)
 {
     struct item *item;
     XButtonPressedEvent *ev = &e->xbutton;
-    int x = 0, y = 0, h = bh, w;
+    int x = 0, y = 0, h = bh, w, i, n;
 
     if (ev->window != win)
         return;
@@ -648,14 +639,36 @@ buttonpress(XEvent *e)
     }
     /* scroll up */
     if (ev->button == Button4 && prev) {
-        sel = curr = prev;
+        curr = prev;
+
+        if (lines > 0)
+            n = (lines - 1) * bh;
+        else
+            n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
+
+        /* we need to seek the final element */
+        for (i = 0, next = curr; next->right; next = next->right)
+            if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
+                break;
+        
+        if(sel == next->right) {
+            if(lines > 0) 
+                sel = next;
+            else 
+                sel = next->left;
+        }
+
         calcoffsets();
         drawmenu();
         return;
     }
     /* scroll down */
     if (ev->button == Button5 && next) {
-        sel = curr = next;
+        curr = curr->right;
+
+        if(sel == curr->left)
+            sel = curr;
+
         calcoffsets();
         drawmenu();
         return;
@@ -900,7 +913,7 @@ setup(void)
         /* no focused window is on screen, so use pointer location instead */
         if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
             for (i = 0; i < n; i++)
-                if (INTERSECT(x, y, 1, 1, info[i]))
+                if (INTERSECT(x, y, 1, 1, info[i]) != 0)
                     break;
 
         if (centered) {
diff --git a/dmenu.o b/dmenu.o
Binary files differ.
diff --git a/drw.o b/drw.o
Binary files differ.
diff --git a/patches/dmenu-mousesupport-scrollperline.diff b/patches/dmenu-mousesupport-scrollperline.diff
@@ -0,0 +1,74 @@
+diff --git a/dmenu.c b/dmenu.c
+index d997033..e623001 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -93,9 +93,7 @@ calcoffsets(void)
+         if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
+             break;
+ 
+-    for (i = 0, prev = curr; prev && prev->left; prev = prev->left)
+-        if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n)
+-            break;
++    prev = curr->left;
+ }
+ 
+ static int
+@@ -158,8 +156,10 @@ drawmenu(void)
+         drw_setscheme(drw, scheme[SchemeSel]);
+         x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
+     }
++
+     /* draw input field */
+     w = (lines > 0 || !matches) ? mw - x : inputw;
++
+     drw_setscheme(drw, scheme[SchemeNorm]);
+     drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
+ 
+@@ -613,7 +613,7 @@ buttonpress(XEvent *e)
+ {
+     struct item *item;
+     XButtonPressedEvent *ev = &e->xbutton;
+-    int x = 0, y = 0, h = bh, w;
++    int x = 0, y = 0, h = bh, w, i, n;
+ 
+     if (ev->window != win)
+         return;
+@@ -648,14 +648,36 @@ buttonpress(XEvent *e)
+     }
+     /* scroll up */
+     if (ev->button == Button4 && prev) {
+-        sel = curr = prev;
++        curr = prev;
++
++        if (lines > 0)
++            n = (lines - 1) * bh;
++        else
++            n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
++
++        /* we need to seek the final element */
++        for (i = 0, next = curr; next->right; next = next->right)
++            if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n)
++                break;
++        
++        if(sel == next->right) {
++            if(lines > 0) 
++                sel = next;
++            else 
++                sel = next->left;
++        }
++
+         calcoffsets();
+         drawmenu();
+         return;
+     }
+     /* scroll down */
+     if (ev->button == Button5 && next) {
+-        sel = curr = next;
++        curr = curr->right;
++
++        if(sel == curr->left)
++            sel = curr;
++
+         calcoffsets();
+         drawmenu();
+         return;
diff --git a/stest b/stest
Binary files differ.
diff --git a/stest.o b/stest.o
Binary files differ.
diff --git a/util.o b/util.o
Binary files differ.