Adding preselect patch

This commit is contained in:
bakkeby 2020-08-08 11:51:00 +02:00
parent 984476ba94
commit 478f49b1c4
3 changed files with 36 additions and 1 deletions

View File

@ -15,7 +15,7 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
### Changelog:
2020-08-08 - Added the symbols and managed patches
2020-08-08 - Added the symbols, managed and preselect patches
2020-08-05 - Added the grid, highlight, highpriority, dynamic options and numbers patches
@ -117,6 +117,10 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
- [prefix-completion](https://tools.suckless.org/dmenu/patches/prefix-completion/)
- changes the behaviour of matched items and the Tab key to allow tab completion
- [preselect](https://tools.suckless.org/dmenu/patches/preselect/)
- adds an option `-ps` to preselect an item by providing the index that should be pre-selected
*
- [printinputtext](https://tools.suckless.org/dmenu/patches/printinputtext/)
- this patch adds a flag (-t) which makes Return key ignore selection and print the input text to stdout
- the flag basically swaps the functions of Return and Shift+Return hotkeys

25
dmenu.c
View File

@ -94,6 +94,9 @@ static int managed = 0;
#if PRINTINPUTTEXT_PATCH
static int use_text_input = 0;
#endif // PRINTINPUTTEXT_PATCH
#if PRESELECT_PATCH
static unsigned int preselected = 0;
#endif // PRESELECT_PATCH
static Atom clip, utf8;
#if WMTYPE_PATCH
@ -1049,8 +1052,23 @@ run(void)
#endif // NON_BLOCKING_STDIN_PATCH
{
XEvent ev;
#if PRESELECT_PATCH
int i;
#endif // PRESELECT_PATCH
while (!XNextEvent(dpy, &ev)) {
#if PRESELECT_PATCH
if (preselected) {
for (i = 0; i < preselected; i++) {
if (sel && sel->right && (sel = sel->right) == next) {
curr = next;
calcoffsets();
}
}
drawmenu();
preselected = 0;
}
#endif // PRESELECT_PATCH
if (XFilterEvent(&ev, win))
continue;
switch(ev.type) {
@ -1379,6 +1397,9 @@ usage(void)
#if LINE_HEIGHT_PATCH
" [-h height]"
#endif // LINE_HEIGHT_PATCH
#if PRESELECT_PATCH
" [-ps index]"
#endif // PRESELECT_PATCH
#if NAVHISTORY_PATCH
" [-H histfile]"
#endif // NAVHISTORY_PATCH
@ -1529,6 +1550,10 @@ main(int argc, char *argv[])
#endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
#if PRESELECT_PATCH
else if (!strcmp(argv[i], "-ps")) /* preselected item */
preselected = atoi(argv[++i]);
#endif // PRESELECT_PATCH
#if DYNAMIC_OPTIONS_PATCH
else if (!strcmp(argv[i], "-dy")) /* dynamic command to run */
dynamic = argv[++i];

View File

@ -163,6 +163,12 @@
*/
#define PREFIXCOMPLETION_PATCH 0
/* This patch adds an option -ps to specify an item by providing the index that should be
* pre-selected.
* https://tools.suckless.org/dmenu/patches/preselect/
*/
#define PRESELECT_PATCH 0
/* This patch adds a flag (-t) which makes Return key to ignore selection and print the input
* text to stdout. The flag basically swaps the functions of Return and Shift+Return hotkeys.
* https://tools.suckless.org/dmenu/patches/printinputtext/