dmenu-numbers-4.9.diff 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From 61abc60dbfaa8ec63fcd176307308aee88a19e32 Mon Sep 17 00:00:00 2001
  2. From: Miles Alan <m@milesalan.com>
  3. Date: Sat, 10 Aug 2019 17:20:08 -0500
  4. Subject: [PATCH] Display number of matched and total items in top right corner
  5. ---
  6. dmenu.c | 25 +++++++++++++++++++++++--
  7. 1 file changed, 23 insertions(+), 2 deletions(-)
  8. diff --git a/dmenu.c b/dmenu.c
  9. index 6b8f51b..98c5810 100644
  10. --- a/dmenu.c
  11. +++ b/dmenu.c
  12. @@ -24,6 +24,8 @@
  13. * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
  14. #define LENGTH(X) (sizeof X / sizeof X[0])
  15. #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
  16. +#define NUMBERSMAXDIGITS 100
  17. +#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
  18. /* enums */
  19. enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
  20. @@ -34,6 +36,7 @@ struct item {
  21. int out;
  22. };
  23. +static char numbers[NUMBERSBUFSIZE] = "";
  24. static char text[BUFSIZ] = "";
  25. static char *embed;
  26. static int bh, mw, mh;
  27. @@ -126,6 +129,21 @@ drawitem(struct item *item, int x, int y, int w)
  28. return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
  29. }
  30. +static void
  31. +recalculatenumbers()
  32. +{
  33. + unsigned int numer = 0, denom = 0;
  34. + struct item *item;
  35. + if (matchend) {
  36. + numer++;
  37. + for (item = matchend; item && item->left; item = item->left)
  38. + numer++;
  39. + }
  40. + for (item = items; item && item->text; item++)
  41. + denom++;
  42. + snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
  43. +}
  44. +
  45. static void
  46. drawmenu(void)
  47. {
  48. @@ -151,6 +169,7 @@ drawmenu(void)
  49. drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
  50. }
  51. + recalculatenumbers();
  52. if (lines > 0) {
  53. /* draw vertical list */
  54. for (item = curr; item != next; item = item->right)
  55. @@ -165,13 +184,15 @@ drawmenu(void)
  56. }
  57. x += w;
  58. for (item = curr; item != next; item = item->right)
  59. - x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">")));
  60. + x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers)));
  61. if (next) {
  62. w = TEXTW(">");
  63. drw_setscheme(drw, scheme[SchemeNorm]);
  64. - drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
  65. + drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
  66. }
  67. }
  68. + drw_setscheme(drw, scheme[SchemeNorm]);
  69. + drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
  70. drw_map(drw, win, 0, 0, mw, mh);
  71. }
  72. --
  73. 2.19.2