commit - 8e122ff16695a745ae73701550954dd9798b239a
commit + ae80152942c8b3656641b4a0134042375164dc6e
blob - aa4fa834f941d80c14d1d81f80222facffb574b8
blob + 7aa4f86701101cbc050057c97db8c9d85a4c54a5
--- mymenu.1
+++ mymenu.1
.Sh NAME
.Nm mymenu
.Nd simple menu for XOrg
+.Sh SYNOPSIS
+.Nm
+.Bk -words
+.Op Fl hva
+.Op Fl p Ar prompt
+.Op Fl x Ar coord
+.Op Fl y Ar coord
+.Op Fl w Ar width
+.Op Fl h Ar height
+.Op Fl P Ar padding
+.Op Fl l Ar layout
+.Op Fl f Ar font
+.Op Fl b Ar borders
+.Op Fl B Ar color
+.Op Fl t Ar color
+.Op Fl T Ar color
+.Op Fl c Ar color
+.Op Fl C Ar color
+.Op Fl s Ar color
+.Op Fl S Ar color
+.Ek
.Sh DESCRIPTION
The
.Nm
and print the user selection to
.Ic stdout
on exit.
-.Sh OPTIONS
-.Bl -tag -width Ds
-.It Fl a
-The first completion (if any) is always selected. This is like dmenu.
+
+The following options are available and take the maximum precedence
+over the (respective) ones defined in the
+.Sy X Resource Database
+.Bl -tag -width indent-two
.It Fl h
Print a small usage message to stderr.
.It Fl v
Print version and exit.
+.It Fl a
+The first completion (if any) is always selected. This is like dmenu.
+.It Fl p Ar prompt
+Override the prompt
+.It Fl x Ar val
+Override the positioning on the X axis, parsed as the resource MyMenu.x
+.It Fl y Ar val
+Override the positioning on the Y axis, parsed as the resource MyMenu.y
+.It Fl P Ar padding
+Override the padding. See the MyMenu.padding resource.
+.It Fl l Ar layout
+Override the layout. Parsed as MyMenu.layout.
+.It Fl f Ar font
+Override the font. See MyMenu.font.
+.It Fl w Ar val
+Override the width. Parsed as MyMenu.width.
+.It Fl h Ar val
+Override the height. Parsed as MyMenu.height.
+.It Fl b Ar borders
+Override the borders size. Parsed as MyMenu.border.size.
+.It Fl B Ar colors
+Override the borders color. Parsed as MyMenu.border.color.
+.It Fl t Ar color
+Override the prompt foreground color. See MyMenu.prompt.foreground.
+.It Fl T Ar color
+Override the prompt background color. See MyMenu.prompt.background.
+.It Fl c Ar color
+Override the completion foreground color. See MyMenu.completion.foreground.
+.It Fl C Ar color
+Override the completion background color. See MyMenu.completion.background.
+.It Fl s Ar color
+Override the highlighted completion foreground color. See MyMenu.completion_highlighted.foreground.
+.It Fl S Ar color
+Override the highlighted completion background color. See MyMenu.completion_highlighted.background.
.El
.Sh RESOURCES
-
-The appearance of the menu is defined through the \fBX Resource
-Database\fR.
.Bl -tag -width Ds
.It MyMenu.font
The font name to use. By default is set to "fixed" if compiled without
.It
C-w (delete last word) does not work well with multi-byte string. The
whole UTF-8 support is still kinda naïve and should be improved.
+.It
+Keep in mind that sometimes the order of the options matter. First are
+parsed (if any) the xrdb options, then the command line flags
+.Sy in the provided order!
+That meas that if you're providing first the x coordinate, let's say
+"middle", and
+.Sy after that
+you are overriding the width, the window
+.Sy will not be
+centered.
+
+As a general rule of thumb, if you're overriding the width and/or the
+height of the window, remember to override the x and y coordinates as
+well.
.El
.Sh EXIT STATUS
blob - d7f30c306a587c5ae051f559385f237c119cf18d
blob + a3799a212afaf7e478c6c183efd87a9b0d36f9d6
--- mymenu.1.md
+++ mymenu.1.md
**mymenu** - simple menu for XOrg
+# SYNOPSIS
+
+**mymenu**
+\[**-hva**]
+\[**-p** *prompt*]
+\[**-x** *coord*]
+\[**-y** *coord*]
+\[**-w** *width*]
+\[**-h** *height*]
+\[**-P** *padding*]
+\[**-l** *layout*]
+\[**-f** *font*]
+\[**-b** *borders*]
+\[**-B** *color*]
+\[**-t** *color*]
+\[**-T** *color*]
+\[**-c** *color*]
+\[**-C** *color*]
+\[**-s** *color*]
+\[**-S** *color*]
+
# DESCRIPTION
The
**stdout**
on exit.
-# OPTIONS
+The following options are available and take the maximum precedence
+over the (respective) ones defined in the
+**X Resource Database**
-**-a**
-
-> The first completion (if any) is always selected. This is like dmenu.
-
**-h**
> Print a small usage message to stderr.
> Print version and exit.
-# RESOURCES
+**-a**
-The appearance of the menu is defined through the **X Resource**
-Database.
+> The first completion (if any) is always selected. This is like dmenu.
+**-p** *prompt*
+
+> Override the prompt
+
+**-x** *val*
+
+> Override the positioning on the X axis, parsed as the resource MyMenu.x
+
+**-y** *val*
+
+> Override the positioning on the Y axis, parsed as the resource MyMenu.y
+
+**-P** *padding*
+
+> Override the padding. See the MyMenu.padding resource.
+
+**-l** *layout*
+
+> Override the layout. Parsed as MyMenu.layout.
+
+**-f** *font*
+
+> Override the font. See MyMenu.font.
+
+**-w** *val*
+
+> Override the width. Parsed as MyMenu.width.
+
+**-h** *val*
+
+> Override the height. Parsed as MyMenu.height.
+
+**-b** *borders*
+
+> Override the borders size. Parsed as MyMenu.border.size.
+
+**-B** *colors*
+
+> Override the borders color. Parsed as MyMenu.border.color.
+
+**-t** *color*
+
+> Override the prompt foreground color. See MyMenu.prompt.foreground.
+
+**-T** *color*
+
+> Override the prompt background color. See MyMenu.prompt.background.
+
+**-c** *color*
+
+> Override the completion foreground color. See MyMenu.completion.foreground.
+
+**-C** *color*
+
+> Override the completion background color. See MyMenu.completion.background.
+
+**-s** *color*
+
+> Override the highlighted completion foreground color. See MyMenu.completion\_highlighted.foreground.
+
+**-S** *color*
+
+> Override the highlighted completion background color. See MyMenu.completion\_highlighted.background.
+
+# RESOURCES
+
MyMenu.font
> The font name to use. By default is set to "fixed" if compiled without
> The X coordinate of the topmost left corner of the window. Much like
> MyMenu.height and MyMenu.width both a pixel dimension and percentage
-> could be supplied. In addition to it, the special value "middle" could
-> be used: in that case the window will be centered on the x axes.
+> could be supplied. In addition to it, some special value can be used.
+> start
+
+> > Alias for 0;
+
+> middle
+
+> > Compute the correct value to make sure that mymenu will be
+> > horizontally centered;
+
+> end
+
+> > Compute the correct value to make sure that mymenu will be right
+> > aligned.
+
MyMenu.y
> The Y coordinate of the topmost left corner of the window. Like the X
> coordinate a pixel dimension, percentage dimension or the special
-> value "middle" could be supplied.
+> value "start", "middle", "end" could be supplied.
MyMenu.padding
* C-w (delete last word) does not work well with multi-byte string. The
whole UTF-8 support is still kinda naïve and should be improved.
+* Keep in mind that sometimes the order of the options matter. First are
+ parsed (if any) the xrdb options, then the command line flags
+ **in the provided order!**
+ That meas that if you're providing first the x coordinate, let's say
+ "middle", and
+ **after that**
+ you are overriding the width, the window
+ **will not be**
+ centered.
+
+ As a general rule of thumb, if you're overriding the width and/or the
+ height of the window, remember to override the x and y coordinates as
+ well.
+
# EXIT STATUS
0 when the user select an entry, 1 when the user press Esc, EX\_USAGE
Omar Polo <omar.polo@europecom.net>
-OpenBSD 6.3 - July 8, 2018
+OpenBSD 6.3 - July 13, 2018
blob - 163555b1909f7845b8404d58cd7006244ca95345
blob + ca4b44a2b22aa8f0be6776b8f79f596c9f15af4d
--- mymenu.c
+++ mymenu.c
#else
# define default_fontname "fixed"
#endif
+
+#define ARGS "hvap:x:y:P:l:f:w:h:b:B:t:T:c:C:s:S:"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
// by default the first completion isn't selected
bool first_selected = false;
- // parse the command line options
+ // first round of args parsing for early terminating options
int ch;
- while ((ch = getopt(argc, argv, "ahv")) != -1) {
+ while ((ch = getopt(argc, argv, ARGS)) != -1) {
switch (ch) {
- case 'a':
- first_selected = true;
- break;
+ /* case 'a': */
+ /* first_selected = true; */
+ /* break; */
case 'h':
usage(*argv);
return 0;
fprintf(stderr, "%s version: %s\n", *argv, VERSION);
return 0;
default:
- usage(*argv);
- return EX_USAGE;
+ break;
}
}
struct completions *cs = compls_new();
check_allocation(cs);
- update_completions(cs, text, lines, first_selected);
-
// start talking to xorg
Display *d = XOpenDisplay(nil);
if (d == nil) {
fprintf(stderr, "no font defined, using %s\n", fontname);
if (XrmGetResource(xdb, "MyMenu.layout", "*", datatype, &value) == true) {
- char *v = strdup(value.addr);
- check_allocation(v);
- horizontal_layout = !strcmp(v, "horizontal");
- free(v);
+ horizontal_layout = !strcmp(value.addr, "horizontal");
}
else
fprintf(stderr, "no layout defined, using horizontal\n");
XAllocNamedColor(d, cmap, colors[2], &border_s_bg, &tmp);
XAllocNamedColor(d, cmap, colors[3], &border_w_bg, &tmp);
} else {
- fprintf(stderr, "error while parsing MyMenu.border.size\n");
+ fprintf(stderr, "error while parsing MyMenu.border.color\n");
}
} else {
XAllocNamedColor(d, cmap, "white", &border_n_bg, &tmp);
- XAllocNamedColor(d, cmap, "white", &border_e_bg, &tmp);
+ XAllocNamedColor(d, cmap, "white", &borde
XAllocNamedColor(d, cmap, "white", &border_s_bg, &tmp);
XAllocNamedColor(d, cmap, "white", &border_w_bg, &tmp);
}
XAllocNamedColor(d, cmap, "white", &border_w_bg, &tmp);
}
+ // second round of args parsing
+ optind = 0; // reset the option index
+ while ((ch = getopt(argc, argv, ARGS)) != -1) {
+ switch (ch) {
+ case 'a':
+ first_selected = true;
+ break;
+ case 'p': {
+ char *newprompt = strdup(optarg);
+ if (newprompt != nil) {
+ free(ps1);
+ ps1 = newprompt;
+ }
+ break;
+ }
+ case 'x':
+ x = parse_int_with_pos(optarg, x, d_width, width);
+ break;
+ case 'y':
+ y = parse_int_with_pos(optarg, y, d_height, height);
+ break;
+ case 'P':
+ padding = parse_integer(optarg, padding);
+ break;
+ case 'l':
+ horizontal_layout = !strcmp(optarg, "horizontal");
+ break;
+ case 'f': {
+ char *newfont = strdup(optarg);
+ if (newfont != nil) {
+ free(fontname);
+ fontname = newfont;
+ }
+ break;
+ }
+ case 'w':
+ width = parse_int_with_percentage(optarg, width, d_width);
+ break;
+ case 'h':
+ height = parse_int_with_percentage(optarg, height, d_height);
+ break;
+ case 'b': {
+ char **borders = parse_csslike(optarg);
+ if (borders != nil) {
+ border_n = parse_integer(borders[0], 0);
+ border_e = parse_integer(borders[1], 0);
+ border_s = parse_integer(borders[2], 0);
+ border_w = parse_integer(borders[3], 0);
+ } else {
+ fprintf(stderr, "Error parsing b option\n");
+ }
+ break;
+ }
+ case 'B': {
+ char **colors = parse_csslike(optarg);
+ if (colors != nil) {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, colors[0], &border_n_bg, &tmp);
+ XAllocNamedColor(d, cmap, colors[1], &border_e_bg, &tmp);
+ XAllocNamedColor(d, cmap, colors[2], &border_s_bg, &tmp);
+ XAllocNamedColor(d, cmap, colors[3], &border_w_bg, &tmp);
+ } else {
+ fprintf(stderr, "error while parsing B option\n");
+ }
+ break;
+ }
+ case 't': {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, optarg, &p_fg, &tmp);
+ break;
+ }
+ case 'T': {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, optarg, &p_bg, &tmp);
+ break;
+ }
+ case 'c': {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, optarg, &compl_fg, &tmp);
+ break;
+ }
+ case 'C': {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, optarg, &compl_bg, &tmp);
+ break;
+ }
+ case 's': {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, optarg, &compl_highlighted_fg, &tmp);
+ break;
+ }
+ case 'S': {
+ XColor tmp;
+ XAllocNamedColor(d, cmap, optarg, &compl_highlighted_bg, &tmp);
+ break;
+ }
+ default:
+ fprintf(stderr, "Unrecognized option %c\n", ch);
+ status = ERR;
+ break;
+ }
+ }
+
+ // since only now we know if the first should be selected, update
+ // the completion here
+ update_completions(cs, text, lines, first_selected);
+
// load the font
#ifdef USE_XFT
XftFont *font = XftFontOpenName(d, DefaultScreen(d), fontname);