Skip to content
Myr

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

3 files+48 added−33 removed

modified:main.c+25 added-12 removed
1025 unmodified lines
1026int1027main(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 };10371038 const char *output_name = NULL;1039 const char *font_name = "monospace";1040 uint32_t text_color = 0xffffffff;1041 uint32_t match_color = 0xcc9393ff;10421043 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;10471048 switch (c) {
11 unmodified lines
1060 return EXIT_FAILURE;1061 }1062 break;10631060 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;10701067 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 lines
1231 /* 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);12341231 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);12451246 refresh(&c);12471248 wl_display_dispatch_pending(c.wl.display);
99 unmodified lines
modified:render.c+11 added-19 removed
7 unmodified lines
8#include "log.h"9#include "font.h"1011struct 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};1516void17render_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;2324 cairo_set_scaled_font(buf->cairo, render->regular_font);2526 cairo_font_extents_t fextents;
166 unmodified lines
193render_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;200201 assert(match_count == 0 || selected < match_count);202203 cairo_set_scaled_font(buf->cairo, render->regular_font);
62 unmodified lines
266 /* 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);272273 y += row_height;274 }275}276277struct render *281render_init(cairo_scaled_font_t *font, int width, int height,282 int x_margin, int y_margin, int border_size)278render_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 lines
modified:render.h+12 added-2 removed
4 unmodified lines
5#include "shm.h"6#include "match.h"7#include "tllist.h"89struct options {10 int width;11 int height;12 int x_margin;13 int y_margin;14 int border_size;1516 uint32_t text_color;17 uint32_t match_color;18};1920struct prompt {21 char *text;22 size_t cursor;23};2425struct render;15struct render *render_init(cairo_scaled_font_t *font, int width, int height,16 int x_margin, int y_margin, int border_size);26struct render *render_init(cairo_scaled_font_t *font, struct options options);27void render_destroy(struct render *render);2829void render_prompt(30 const struct render *render, struct buffer *buf,
5 unmodified lines