commit 8e122ff16695a745ae73701550954dd9798b239a from: Omar Polo date: Fri Jul 13 08:18:27 2018 UTC Added special values "start" and "end" for positioning commit - ec3f78245c04d6231b613e9851d5970796da7947 commit + 8e122ff16695a745ae73701550954dd9798b239a blob - cd06db009f8bc60fc5d51788677d317e06e87728 blob + aa4fa834f941d80c14d1d81f80222facffb574b8 --- mymenu.1 +++ mymenu.1 @@ -50,12 +50,21 @@ relative percentage will be computed (relative to the .It MyMenu.x 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. +.Bl -tag +.It start +Alias for 0; +.It middle +Compute the correct value to make sure that mymenu will be +horizontally centered; +.It end +Compute the correct value to make sure that mymenu will be right +aligned. +.El .It 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. .It MyMenu.padding Change the padding. In the horizontal layout the padding is the space between the rectangle of the completion and the text as well as the blob - 2b124ec450357b4716a503db435d060ed02bb120 blob + 163555b1909f7845b8404d58cd7006244ca95345 --- mymenu.c +++ mymenu.c @@ -713,12 +713,17 @@ int parse_int_with_percentage(const char *str, int def return parse_integer(str, default_value); } -// like parse_int_with_percentage but understands the special value -// "middle" that is (max - self) / 2 -int parse_int_with_middle(const char *str, int default_value, int max, int self) { - if (!strcmp(str, "middle")) { +// like parse_int_with_percentage but understands some special values +// - "middle" that is (max - self) / 2 +// - "start" that is 0 +// - "end" that is (max - self) +int parse_int_with_pos(const char *str, int default_value, int max, int self) { + if (!strcmp(str, "start")) + return 0; + if (!strcmp(str, "middle")) return (max - self)/2; - } + if (!strcmp(str, "end")) + return max-self; return parse_int_with_percentage(str, default_value, max); } @@ -1017,12 +1022,12 @@ int main(int argc, char **argv) { fprintf(stderr, "no height defined, using %d\n", height); if (XrmGetResource(xdb, "MyMenu.x", "*", datatype, &value) == true) - x = parse_int_with_middle(value.addr, x, d_width, width); + x = parse_int_with_pos(value.addr, x, d_width, width); else fprintf(stderr, "no x defined, using %d\n", x); if (XrmGetResource(xdb, "MyMenu.y", "*", datatype, &value) == true) - y = parse_int_with_middle(value.addr, y, d_height, height); + y = parse_int_with_pos(value.addr, y, d_height, height); else fprintf(stderr, "no y defined, using %d\n", y);