render: pass geometry+color config in an options struct
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 b461d67 · Browse files · 3 files·+48 added−33 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+48 added−33 removed
- other:+48 added−33 removed
Provenance
- Commit
4edbcc1- Tree
9322ee5- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
b461d67
3 files changed+48 added−33 removed
modified:main.c+25 added-12 removed
1025 unmodified lines1026 int1027 main(int argc, char *const *argv)1028 {1029 static const struct option longopts[] = {1030- {"output" , required_argument, 0, 'o'},1031- {"font", required_argument, 0, 'f'},1032- {"geometry", required_argument, 0, 'g'},1033- {NULL, no_argument, 0, 0},1030+ {"output" , required_argument, 0, 'o'},1031+ {"font", required_argument, 0, 'f'},1032+ {"geometry", required_argument, 0, 'g'},1033+ {"text-color", required_argument, 0, 't'},1034+ {"match-color", required_argument, 0, 'm'},1035+ {NULL, no_argument, 0, 0},1036 };1037 1038 const char *output_name = NULL;1039 const char *font_name = "monospace";1040+ uint32_t text_color = 0xffffffff;1041+ uint32_t match_color = 0xcc9393ff;1042 1043 while (true) {1040- int c = getopt_long(argc, argv, ":o:f:g:", longopts, NULL);1044+ int c = getopt_long(argc, argv, ":o:f:g:t:m:", longopts, NULL);1045 if (c == -1)1046 break;1047 1048 switch (c) {11 unmodified lines1060 return EXIT_FAILURE;1061 }1062 break;1063 1060- case 'W':1061- if (sscanf(optarg, "%d", &width) != 1) {1062- LOG_ERR("%s: invalid width (must be an integer)", optarg);1064+ case 't':1065+ if (sscanf(optarg, "%x", &text_color) != 1) {1066+ LOG_ERR("%s: invalid color", optarg);1067 return EXIT_FAILURE;1068 }1069 break;1070 1067- case 'H':1068- if (sscanf(optarg, "%d", &height) != 1) {1069- LOG_ERR("%s: invalid height (must be an integer)", optarg);1071+ case 'm':1072+ if (sscanf(optarg, "%x", &match_color) != 1) {1073+ LOG_ERR("%s: invalid color", optarg);1074 return EXIT_FAILURE;1075 }1076 break;1077 153 unmodified lines1231 /* Trigger a 'configure' event, after which we'll have the width */1232 wl_surface_commit(c.wl.surface);1233 wl_display_roundtrip(c.wl.display);1234 1231- c.render = render_init(font, width, height, x_margin, y_margin, border_size);1235+ struct options options = {1236+ .width = width,1237+ .height = height,1238+ .x_margin = x_margin,1239+ .y_margin = y_margin,1240+ .border_size = border_size,1241+ .text_color = text_color,1242+ .match_color = match_color,1243+ };1244+ c.render = render_init(font, options);1245 1246 refresh(&c);1247 1248 wl_display_dispatch_pending(c.wl.display);99 unmodified linesmodified:render.c+11 added-19 removed
7 unmodified lines8 #include "log.h"9 #include "font.h"10 11 struct render {12- int width;13- int height;14- int x_margin;15- int y_margin;16- int border_size;12+ struct options options;13 cairo_scaled_font_t *regular_font;14 };15 16 void17 render_prompt(const struct render *render, struct buffer *buf,18 const struct prompt *prompt)19 {24- const double x_margin = render->x_margin;25- const double y_margin = render->y_margin;26- const double border_size = render->border_size;20+ const double x_margin = render->options.x_margin;21+ const double y_margin = render->options.y_margin;22+ const double border_size = render->options.border_size;23 24 cairo_set_scaled_font(buf->cairo, render->regular_font);25 26 cairo_font_extents_t fextents;166 unmodified lines193 render_match_list(const struct render *render, struct buffer *buf,194 const struct match matches[], size_t match_count,195 size_t match_length, size_t selected)196 {201- const double x_margin = render->x_margin;202- const double y_margin = render->y_margin;203- const double border_size = render->border_size;197+ const double x_margin = render->options.x_margin;198+ const double y_margin = render->options.y_margin;199+ const double border_size = render->options.border_size;200 201 assert(match_count == 0 || selected < match_count);202 203 cairo_set_scaled_font(buf->cairo, render->regular_font);62 unmodified lines266 /* Application title */267 render_match_text(268 buf, &cur_x, y,269 match->application->title, match->start_title, match_length,274- render->regular_font, 0xffffffff, 0xcc9393ff);270+ render->regular_font,271+ render->options.text_color, render->options.match_color);272 273 y += row_height;274 }275 }276 277 struct render *281-render_init(cairo_scaled_font_t *font, int width, int height,282- int x_margin, int y_margin, int border_size)278+render_init(cairo_scaled_font_t *font, struct options options)279 {280 struct render *render = calloc(1, sizeof(*render));285- render->width = width;286- render->height = height;287- render->x_margin = x_margin;288- render->y_margin = y_margin;289- render->border_size = border_size;281+ render->options = options;282 render->regular_font = font;283 return render;284 }285 9 unmodified linesmodified:render.h+12 added-2 removed
4 unmodified lines5 #include "shm.h"6 #include "match.h"7 #include "tllist.h"8 9+struct options {10+ int width;11+ int height;12+ int x_margin;13+ int y_margin;14+ int border_size;15+16+ uint32_t text_color;17+ uint32_t match_color;18+};19+20 struct prompt {21 char *text;22 size_t cursor;23 };24 25 struct render;15-struct render *render_init(cairo_scaled_font_t *font, int width, int height,16- int x_margin, int y_margin, int border_size);26+struct render *render_init(cairo_scaled_font_t *font, struct options options);27 void render_destroy(struct render *render);28 29 void render_prompt(30 const struct render *render, struct buffer *buf,5 unmodified lines