Skip to content
Myr

main: make border-width/color configurable

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 2da72aa · Browse files · 3 files+41 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+41 added−4 removed

  • other:+41 added−4 removed

3 files+41 added−4 removed

modified:main.c+34 added-4 removed
110 unmodified lines
111 int height;112 const double x_margin;113 const double y_margin;114 const double border_size;115 struct { double r, g, b, a; } border_color;116 struct { double r, g, b, a; } background;117};118119static int max_matches;
878 unmodified lines
998 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);999 cairo_paint(buf->cairo);10001001 /* Border */1001 cairo_set_source_rgba(buf->cairo, 1.0, 1.0, 1.0, 1.0);1002 cairo_set_line_width(buf->cairo, 2 * 1);1002 cairo_set_source_rgba(1003 buf->cairo,1004 c->border_color.r, c->border_color.g, c->border_color.b,1005 c->border_color.a);1006 cairo_set_line_width(buf->cairo, 2 * c->border_size);1007 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_OVER);1008 cairo_rectangle(buf->cairo, 0, 0, c->width, c->height);1009 cairo_stroke(buf->cairo);1010
27 unmodified lines
1038 {"geometry", required_argument, 0, 'g'},1039 {"background-color", required_argument, 0, 'b'},1040 {"text-color", required_argument, 0, 't'},1041 {"match-color", required_argument, 0, 'm'},1042 {"border-width", required_argument, 0, 'B'},1043 {"border-color", required_argument, 0, 'C'},1044 {NULL, no_argument, 0, 0},1045 };10461047 const char *output_name = NULL;1048 const char *font_name = "monospace";10491050 int width = 500;1051 int height = 300;1052 int border_width = 1;1053 uint32_t text_color = 0xffffffff;1054 uint32_t match_color = 0xcc9393ff;1055 uint32_t background = 0x000000ff;1056 uint32_t border_color = 0xffffffff;10571058 while (true) {1051 int c = getopt_long(argc, argv, ":o:f:g:b:t:m:", longopts, NULL);1059 int c = getopt_long(argc, argv, ":o:f:g:b:t:m:B:C:", longopts, NULL);1060 if (c == -1)1061 break;10621063 switch (c) {
32 unmodified lines
1096 return EXIT_FAILURE;1097 }1098 break;10991100 case 'B':1101 if (sscanf(optarg, "%d", &border_width) != 1) {1102 LOG_ERR(1103 "%s: invalid border width (must be an integer)", optarg);1104 return EXIT_FAILURE;1105 }1106 break;11071108 case 'C':1109 if (sscanf(optarg, "%x", &border_color) != 1) {1110 LOG_ERR("%s: invalid color", optarg);1111 return EXIT_FAILURE;1112 }1113 break;11141115 case ':':1116 fprintf(stderr, "error: -%c: missing required argument\n", optopt);1117 return EXIT_FAILURE;1118
28 unmodified lines
1147 .width = width,1148 .height = height,1149 .x_margin = 20,1150 .y_margin = 4,1128 .border_size = 1,1151 .border_size = border_width,1152 .background = {1153 (double)((background >> 24) & 0xff) / 255.0,1154 (double)((background >> 16) & 0xff) / 255.0,1155 (double)((background >> 8) & 0xff) / 255.0,1156 (double)((background >> 0) & 0xff) / 255.0,1157 },1158 .border_color = {1159 (double)((border_color >> 24) & 0xff) / 255.0,1160 (double)((border_color >> 16) & 0xff) / 255.0,1161 (double)((border_color >> 8) & 0xff) / 255.0,1162 (double)((border_color >> 0) & 0xff) / 255.0,1163 },1164 };11651166 mtx_init(&c.repeat.mutex, mtx_plain);1167 cnd_init(&c.repeat.cond);
125 unmodified lines
1293 .y_margin = c.y_margin,1294 .border_size = c.border_size,1295 .text_color = text_color,1296 .match_color = match_color,1297 .border_color = border_color,1298 };1299 c.render = render_init(font, options);13001301 refresh(&c);
101 unmodified lines
modified:render.c+6 added
92 unmodified lines
9394 cairo_glyph_free(glyphs);95 cairo_text_cluster_free(clusters);9697 r = (double)((render->options.border_color >> 24) & 0xff) / 255.0;98 g = (double)((render->options.border_color >> 16) & 0xff) / 255.0;99 b = (double)((render->options.border_color >> 8) & 0xff) / 255.0;100 a = (double)((render->options.border_color >> 0) & 0xff) / 255.0;101102 cairo_set_source_rgba(buf->cairo, r, g, b, a);103 cairo_set_line_width(buf->cairo, border_size);104 cairo_move_to(buf->cairo, 0, border_size + 2 * y_margin + fextents.height + border_size / 2);105 cairo_line_to(buf->cairo, buf->width, border_size + 2 * y_margin + fextents.height + border_size / 2);106 cairo_stroke(buf->cairo);
199 unmodified lines
modified:render.h+1 added
13 unmodified lines
14 int border_size;1516 uint32_t text_color;17 uint32_t match_color;18 uint32_t border_color;19};2021struct prompt {22 char *text;
14 unmodified lines