Introduction
Introduction Statistics Contact Development Disclaimer Help
dmenu-numbers-20220512-28fb3e2.diff - sites - public wiki contents of suckless.…
git clone git://git.suckless.org/sites
Log
Files
Refs
---
dmenu-numbers-20220512-28fb3e2.diff (2804B)
---
1 From c4cd209c2e322563750d09a3b64194d11cc12a10 Mon Sep 17 00:00:00 2001
2 From: Ehsan Ghorbannezhad <[email protected]>
3 Date: Thu, 12 May 2022 22:32:47 +0430
4 Subject: [PATCH] the numbers patch, updated to fix segfault in some cond…
5
6 ---
7 dmenu.c | 27 ++++++++++++++++++++++++---
8 1 file changed, 24 insertions(+), 3 deletions(-)
9
10 diff --git a/dmenu.c b/dmenu.c
11 index 571bc35..70004e7 100644
12 --- a/dmenu.c
13 +++ b/dmenu.c
14 @@ -24,6 +24,8 @@
15 * MAX(0, MIN((y)+(h),(r).y_org+(r).height)…
16 #define LENGTH(X) (sizeof X / sizeof X[0])
17 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
18 +#define NUMBERSMAXDIGITS 100
19 +#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
20
21 /* enums */
22 enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes…
23 @@ -34,6 +36,7 @@ struct item {
24 int out;
25 };
26
27 +static char numbers[NUMBERSBUFSIZE] = "";
28 static char text[BUFSIZ] = "";
29 static char *embed;
30 static int bh, mw, mh;
31 @@ -86,7 +89,7 @@ calcoffsets(void)
32 if (lines > 0)
33 n = lines * bh;
34 else
35 - n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
36 + n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">") + …
37 /* calculate which items will begin the next page and previous …
38 for (i = 0, next = curr; next; next = next->right)
39 if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)…
40 @@ -143,6 +146,21 @@ drawitem(struct item *item, int x, int y, int w)
41 return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
42 }
43
44 +static void
45 +recalculatenumbers()
46 +{
47 + unsigned int numer = 0, denom = 0;
48 + struct item *item;
49 + if (matchend) {
50 + numer++;
51 + for (item = matchend; item && item->left; item = item->…
52 + numer++;
53 + }
54 + for (item = items; item && item->text; item++)
55 + denom++;
56 + snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
57 +}
58 +
59 static void
60 drawmenu(void)
61 {
62 @@ -168,6 +186,7 @@ drawmenu(void)
63 drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
64 }
65
66 + recalculatenumbers();
67 if (lines > 0) {
68 /* draw vertical list */
69 for (item = curr; item != next; item = item->right)
70 @@ -182,13 +201,15 @@ drawmenu(void)
71 }
72 x += w;
73 for (item = curr; item != next; item = item->right)
74 - x = drawitem(item, x, 0, textw_clamp(item->text…
75 + x = drawitem(item, x, 0, textw_clamp(item->text…
76 if (next) {
77 w = TEXTW(">");
78 drw_setscheme(drw, scheme[SchemeNorm]);
79 - drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">",…
80 + drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh…
81 }
82 }
83 + drw_setscheme(drw, scheme[SchemeNorm]);
84 + drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad…
85 drw_map(drw, win, 0, 0, mw, mh);
86 }
87
88 --
89 2.36.1
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.