dmenu-password-5.0.diff 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From c4de1032bd4c247bc20b6ab92a10a8d778966679 Mon Sep 17 00:00:00 2001
  2. From: Mehrad Mahmoudian <m.mahmoudian@gmail.com>
  3. Date: Tue, 4 May 2021 12:05:09 +0300
  4. Subject: [PATCH] patched with password patch
  5. ---
  6. dmenu.1 | 5 ++++-
  7. dmenu.c | 21 +++++++++++++++++----
  8. 2 files changed, 21 insertions(+), 5 deletions(-)
  9. diff --git a/dmenu.1 b/dmenu.1
  10. index 323f93c..762f707 100644
  11. --- a/dmenu.1
  12. +++ b/dmenu.1
  13. @@ -3,7 +3,7 @@
  14. dmenu \- dynamic menu
  15. .SH SYNOPSIS
  16. .B dmenu
  17. -.RB [ \-bfiv ]
  18. +.RB [ \-bfivP ]
  19. .RB [ \-l
  20. .IR lines ]
  21. .RB [ \-m
  22. @@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
  23. .B \-i
  24. dmenu matches menu items case insensitively.
  25. .TP
  26. +.B \-P
  27. +dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored.
  28. +.TP
  29. .BI \-l " lines"
  30. dmenu lists items vertically, with the given number of lines.
  31. .TP
  32. diff --git a/dmenu.c b/dmenu.c
  33. index 65f25ce..ad8f63b 100644
  34. --- a/dmenu.c
  35. +++ b/dmenu.c
  36. @@ -37,7 +37,7 @@ struct item {
  37. static char text[BUFSIZ] = "";
  38. static char *embed;
  39. static int bh, mw, mh;
  40. -static int inputw = 0, promptw;
  41. +static int inputw = 0, promptw, passwd = 0;
  42. static int lrpad; /* sum of left and right padding */
  43. static size_t cursor;
  44. static struct item *items = NULL;
  45. @@ -132,6 +132,7 @@ drawmenu(void)
  46. unsigned int curpos;
  47. struct item *item;
  48. int x = 0, y = 0, w;
  49. + char *censort;
  50. drw_setscheme(drw, scheme[SchemeNorm]);
  51. drw_rect(drw, 0, 0, mw, mh, 1, 1);
  52. @@ -143,7 +144,12 @@ drawmenu(void)
  53. /* draw input field */
  54. w = (lines > 0 || !matches) ? mw - x : inputw;
  55. drw_setscheme(drw, scheme[SchemeNorm]);
  56. - drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
  57. + if (passwd) {
  58. + censort = ecalloc(1, sizeof(text));
  59. + memset(censort, '.', strlen(text));
  60. + drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0);
  61. + free(censort);
  62. + } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
  63. curpos = TEXTW(text) - TEXTW(&text[cursor]);
  64. if ((curpos += lrpad / 2 - 1) < w) {
  65. @@ -524,6 +530,11 @@ readstdin(void)
  66. char buf[sizeof text], *p;
  67. size_t i, imax = 0, size = 0;
  68. unsigned int tmpmax = 0;
  69. + if(passwd){
  70. + inputw = lines = 0;
  71. + return;
  72. + }
  73. +
  74. /* read each line from stdin and add it to the item list */
  75. for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
  76. @@ -689,7 +700,7 @@ setup(void)
  77. static void
  78. usage(void)
  79. {
  80. - fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
  81. + fputs("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
  82. " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
  83. exit(1);
  84. }
  85. @@ -712,7 +723,9 @@ main(int argc, char *argv[])
  86. else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
  87. fstrncmp = strncasecmp;
  88. fstrstr = cistrstr;
  89. - } else if (i + 1 == argc)
  90. + } else if (!strcmp(argv[i], "-P")) /* is the input a password */
  91. + passwd = 1;
  92. + else if (i + 1 == argc)
  93. usage();
  94. /* these options take one argument */
  95. else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
  96. --
  97. 2.31.1