Adding relative input width patch and bumping to 28fb3e2

This commit is contained in:
bakkeby 2022-06-21 10:22:20 +02:00
parent 59d8327727
commit d3b51477fc
3 changed files with 43 additions and 8 deletions

View File

@ -1,5 +1,5 @@
Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this dmenu 5.1 (33685b0, Similar to [dwm-flexipatch](https://github.com/bakkeby/dwm-flexipatch) this dmenu 5.1 (28fb3e2,
2022-03-28) project has a different take on patching. It uses preprocessor directives to decide 2022-05-01) project has a different take on patching. It uses preprocessor directives to decide
whether or not to include a patch during build time. Essentially this means that this build, for whether or not to include a patch during build time. Essentially this means that this build, for
better or worse, contains both the patched _and_ the original code. The aim being that you can better or worse, contains both the patched _and_ the original code. The aim being that you can
select which patches to include and the build will contain that code and nothing more. select which patches to include and the build will contain that code and nothing more.
@ -28,6 +28,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/YjT2DD6j
### Changelog: ### Changelog:
2022-06-21 - Adding relative input width patch
2022-03-02 - Bump to 5.1 2022-03-02 - Bump to 5.1
2021-05-23 - Adding support for `ctrl+v` to paste and adding emoji-highlight patch 2021-05-23 - Adding support for `ctrl+v` to paste and adding emoji-highlight patch
@ -203,6 +205,14 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/YjT2DD6j
- adds a new flag to dmenu with which text input will be rejected if it would result in no - adds a new flag to dmenu with which text input will be rejected if it would result in no
matching item matching item
- relative_input_width
- prior to commit [e1e1de7](https://git.suckless.org/dmenu/commit/e1e1de7b3b8399cba90ddca9613f837b2dbef7b9.html)
the input width was calculated based on the input options
- this feature was removed in favour of hardcoding the input width to always take up 1/3rd of
the available space
- this patch adds that feature back in with some bespoke performance optimisations at the cost
of accuracy and correctness
- [restrict-return](https://tools.suckless.org/dmenu/patches/restrict-return/) - [restrict-return](https://tools.suckless.org/dmenu/patches/restrict-return/)
- adds a `-1` option which disables Shift-Return and Ctrl-Return - adds a `-1` option which disables Shift-Return and Ctrl-Return
- this guarantees that dmenu will only output one item, and that item was read from stdin - this guarantees that dmenu will only output one item, and that item was read from stdin

22
dmenu.c
View File

@ -1501,13 +1501,17 @@ static void
setup(void) setup(void)
{ {
int x, y, i, j; int x, y, i, j;
unsigned int du, tmp; unsigned int du;
#if RELATIVE_INPUT_WIDTH_PATCH
unsigned int tmp, minstrlen = 0, curstrlen = 0;
int numwidthchecks = 100;
struct item *item;
#endif // RELATIVE_INPUT_WIDTH_PATCH
XSetWindowAttributes swa; XSetWindowAttributes swa;
XIM xim; XIM xim;
Window w, dw, *dws; Window w, dw, *dws;
XWindowAttributes wa; XWindowAttributes wa;
XClassHint ch = {"dmenu", "dmenu"}; XClassHint ch = {"dmenu", "dmenu"};
struct item *item;
#ifdef XINERAMA #ifdef XINERAMA
XineramaScreenInfo *info; XineramaScreenInfo *info;
Window pw; Window pw;
@ -1644,12 +1648,22 @@ setup(void)
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
#endif // PANGO_PATCH #endif // PANGO_PATCH
#endif // CENTER_PATCH #endif // CENTER_PATCH
for (item = items; item && item->text; ++item) { #if RELATIVE_INPUT_WIDTH_PATCH
for (item = items; !lines && item && item->text; ++item) {
curstrlen = strlen(item->text);
if (numwidthchecks || minstrlen < curstrlen) {
numwidthchecks = MAX(numwidthchecks - 1, 0);
minstrlen = MAX(minstrlen, curstrlen);
if ((tmp = textw_clamp(item->text, mw/3)) > inputw) { if ((tmp = textw_clamp(item->text, mw/3)) > inputw) {
if ((inputw = tmp) == mw/3) inputw = tmp;
if (tmp == mw/3)
break; break;
} }
} }
}
#else
inputw = mw / 3; /* input width: ~33.33% of monitor width */
#endif // RELATIVE_INPUT_WIDTH_PATCH
match(); match();
/* create menu window */ /* create menu window */

View File

@ -273,6 +273,17 @@
*/ */
#define REJECTNOMATCH_PATCH 0 #define REJECTNOMATCH_PATCH 0
/* The input width used to be relative to the input options prior to commit e1e1de7:
* https://git.suckless.org/dmenu/commit/e1e1de7b3b8399cba90ddca9613f837b2dbef7b9.html
*
* This had a performance hit when using large data sets and was removed in favour of having the
* input width take up 1/3rd of the available space.
*
* This option adds that feature back in with some performance optimisations at the cost of
* accuracy and correctness.
*/
#define RELATIVE_INPUT_WIDTH_PATCH 0
/* This patch adds a '-1' option which disables Shift-Return and Ctrl-Return. /* This patch adds a '-1' option which disables Shift-Return and Ctrl-Return.
* This guarantees that dmenu will only output one item, and that item was read from stdin. * This guarantees that dmenu will only output one item, and that item was read from stdin.
* The original patch used '-r'. This was changed to '-1' to avoid conflict with the incremental * The original patch used '-r'. This was changed to '-1' to avoid conflict with the incremental