My build of dmenu from suckless.org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

121 lines
3.4 KiB

  1. From 8cd37e1ab9e7cb025224aeb3543f1a5be8bceb93 Mon Sep 17 00:00:00 2001
  2. From: Nihal Jere <nihal@nihaljere.xyz>
  3. Date: Sat, 11 Jan 2020 21:16:08 -0600
  4. Subject: [PATCH] center patch now has adjustable minimum width
  5. ---
  6. config.def.h | 2 ++
  7. dmenu.1 | 3 +++
  8. dmenu.c | 39 ++++++++++++++++++++++++++++++++-------
  9. 3 files changed, 37 insertions(+), 7 deletions(-)
  10. diff --git a/config.def.h b/config.def.h
  11. index 1edb647..88ef264 100644
  12. --- a/config.def.h
  13. +++ b/config.def.h
  14. @@ -2,6 +2,8 @@
  15. /* Default settings; can be overriden by command line. */
  16. static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
  17. +static int centered = 0; /* -c option; centers dmenu on screen */
  18. +static int min_width = 500; /* minimum width when centered */
  19. /* -fn option overrides fonts[0]; default X11 font or font set */
  20. static const char *fonts[] = {
  21. "monospace:size=10"
  22. diff --git a/dmenu.1 b/dmenu.1
  23. index 323f93c..c036baa 100644
  24. --- a/dmenu.1
  25. +++ b/dmenu.1
  26. @@ -40,6 +40,9 @@ which lists programs in the user's $PATH and runs the result in their $SHELL.
  27. .B \-b
  28. dmenu appears at the bottom of the screen.
  29. .TP
  30. +.B \-c
  31. +dmenu appears centered on the screen.
  32. +.TP
  33. .B \-f
  34. dmenu grabs the keyboard before reading stdin if not reading from a tty. This
  35. is faster, but will lock up X until stdin reaches end\-of\-file.
  36. diff --git a/dmenu.c b/dmenu.c
  37. index 65f25ce..041c7f8 100644
  38. --- a/dmenu.c
  39. +++ b/dmenu.c
  40. @@ -89,6 +89,15 @@ calcoffsets(void)
  41. break;
  42. }
  43. +static int
  44. +max_textw(void)
  45. +{
  46. + int len = 0;
  47. + for (struct item *item = items; item && item->text; item++)
  48. + len = MAX(TEXTW(item->text), len);
  49. + return len;
  50. +}
  51. +
  52. static void
  53. cleanup(void)
  54. {
  55. @@ -611,6 +620,7 @@ setup(void)
  56. bh = drw->fonts->h + 2;
  57. lines = MAX(lines, 0);
  58. mh = (lines + 1) * bh;
  59. + promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
  60. #ifdef XINERAMA
  61. i = 0;
  62. if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
  63. @@ -637,9 +647,16 @@ setup(void)
  64. if (INTERSECT(x, y, 1, 1, info[i]))
  65. break;
  66. - x = info[i].x_org;
  67. - y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
  68. - mw = info[i].width;
  69. + if (centered) {
  70. + mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width);
  71. + x = info[i].x_org + ((info[i].width - mw) / 2);
  72. + y = info[i].y_org + ((info[i].height - mh) / 2);
  73. + } else {
  74. + x = info[i].x_org;
  75. + y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
  76. + mw = info[i].width;
  77. + }
  78. +
  79. XFree(info);
  80. } else
  81. #endif
  82. @@ -647,11 +664,17 @@ setup(void)
  83. if (!XGetWindowAttributes(dpy, parentwin, &wa))
  84. die("could not get embedding window attributes: 0x%lx",
  85. parentwin);
  86. - x = 0;
  87. - y = topbar ? 0 : wa.height - mh;
  88. - mw = wa.width;
  89. +
  90. + if (centered) {
  91. + mw = MIN(MAX(max_textw() + promptw, min_width), wa.width);
  92. + x = (wa.width - mw) / 2;
  93. + y = (wa.height - mh) / 2;
  94. + } else {
  95. + x = 0;
  96. + y = topbar ? 0 : wa.height - mh;
  97. + mw = wa.width;
  98. + }
  99. }
  100. - promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
  101. inputw = MIN(inputw, mw/3);
  102. match();
  103. @@ -709,6 +732,8 @@ main(int argc, char *argv[])
  104. topbar = 0;
  105. else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
  106. fast = 1;
  107. + else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */
  108. + centered = 1;
  109. else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
  110. fstrncmp = strncasecmp;
  111. fstrstr = cistrstr;
  112. --
  113. 2.24.1