add preselect patch

This commit is contained in:
hazen2215 2023-06-22 23:22:53 +09:00
parent ca390636ed
commit 35d070b093
4 changed files with 19 additions and 0 deletions

View File

@ -21,3 +21,6 @@ static unsigned int lines = 0;
* for example: " /?\"&[]" * for example: " /?\"&[]"
*/ */
static const char worddelimiters[] = " "; static const char worddelimiters[] = " ";
/* -n option; preselected item starting from 0 */
static unsigned int preselected = 0;

View File

@ -21,3 +21,6 @@ static unsigned int lines = 0;
* for example: " /?\"&[]" * for example: " /?\"&[]"
*/ */
static const char worddelimiters[] = " "; static const char worddelimiters[] = " ";
/* -n option; preselected item starting from 0 */
static unsigned int preselected = 0;

View File

@ -22,6 +22,8 @@ dmenu \- dynamic menu
.IR color ] .IR color ]
.RB [ \-w .RB [ \-w
.IR windowid ] .IR windowid ]
.RB [ \-n
.IR number ]
.P .P
.BR dmenu_run " ..." .BR dmenu_run " ..."
.SH DESCRIPTION .SH DESCRIPTION
@ -80,6 +82,9 @@ prints version information to stdout, then exits.
.TP .TP
.BI \-w " windowid" .BI \-w " windowid"
embed into windowid. embed into windowid.
.TP
.BI \-n " number"
preseslected item starting from 0.
.SH USAGE .SH USAGE
dmenu is completely controlled by the keyboard. Items are selected using the dmenu is completely controlled by the keyboard. Items are selected using the
arrow keys, page up, page down, home, and end. arrow keys, page up, page down, home, and end.

View File

@ -678,6 +678,12 @@ setup(void)
promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
inputw = mw / 3; /* input width: ~33% of monitor width */ inputw = mw / 3; /* input width: ~33% of monitor width */
match(); match();
for (i = 0; i < preselected; i++) {
if (sel && sel->right && (sel = sel->right) == next) {
curr = next;
calcoffsets();
}
}
/* create menu window */ /* create menu window */
swa.override_redirect = True; swa.override_redirect = True;
@ -757,6 +763,8 @@ main(int argc, char *argv[])
colors[SchemeSel][ColFg] = argv[++i]; colors[SchemeSel][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */ else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i]; embed = argv[++i];
else if (!strcmp(argv[i], "-n")) /* preselected item */
preselected = atoi(argv[++i]);
else else
usage(); usage();