main: move static window configuration variables into context 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 4edbcc1 · Browse files · 1 file·+29 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+29 added−18 removed
- other:+29 added−18 removed
Provenance
- Commit
32cfbdd- Tree
6c3e359- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
4edbcc1
1 file changed+29 added−18 removed
modified:main.c+29 added-18 removed
103 unmodified lines104 } repeat;105 106 bool frame_is_scheduled;107 struct buffer *pending;108+109+ /* Window configuration */110+ int width;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; } background;116 };117 110-/* Window size */111-static int width = 500;112-static int height = 300;113-114-static const double x_margin = 20;115-static const double y_margin = 4;116-static const double border_size = 1;117-118 static int max_matches;119 120 static void refresh(struct context *c);121 static void update_matches(struct context *c);865 unmodified lines987 988 static void989 refresh(struct context *c)990 {991- struct buffer *buf = shm_get_buffer(c->wl.shm, width, height);991+ struct buffer *buf = shm_get_buffer(c->wl.shm, c->width, c->height);992 993 /* Background */994- cairo_set_source_rgba(buf->cairo, 0.247, 0.247, 0.247, 0.9);994+ cairo_set_source_rgba(995+ buf->cairo,996+ c->background.r, c->background.g, c->background.b, c->background.a);997 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);998 cairo_paint(buf->cairo);999 1000 /* 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);1003 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_OVER);1002- cairo_rectangle(buf->cairo, 0, 0, width, height);1004+ cairo_rectangle(buf->cairo, 0, 0, c->width, c->height);1005 cairo_stroke(buf->cairo);1006 1007 render_prompt(c->render, buf, &c->prompt);1008 render_match_list(c->render, buf, c->matches, c->match_count,29 unmodified lines1038 };1039 1040 const char *output_name = NULL;1041 const char *font_name = "monospace";1042+1043+ int width = 500;1044+ int height = 300;1045 uint32_t text_color = 0xffffffff;1046 uint32_t match_color = 0xcc9393ff;1047 1048 while (true) {62 unmodified lines1111 .pipe_read_fd = repeat_pipe_fds[0],1112 .pipe_write_fd = repeat_pipe_fds[1],1113 .cmd = REPEAT_STOP,1114 },1115+ .width = width,1116+ .height = height,1117+ .x_margin = 20,1118+ .y_margin = 4,1119+ .border_size = 1,1120+ .background = {0.247, 0.247, 0.247, 0.9},1121 };1122 1123 mtx_init(&c.repeat.mutex, mtx_plain);1124 cnd_init(&c.repeat.cond);12 unmodified lines1137 1138 LOG_DBG("height: %f, ascent: %f, descent: %f",1139 fextents.height, fextents.ascent, fextents.descent);1140 1130- const double line_height = 2 * y_margin + fextents.height;1131- max_matches = (height - 2 * border_size - line_height) / line_height;1141+ const double line_height = 2 * c.y_margin + fextents.height;1142+ max_matches = (height - 2 * c.border_size - line_height) / line_height;1143 LOG_DBG("max matches: %d", max_matches);1144 1145 xdg_find_programs(fextents.height, &c.applications);1146 c.matches = malloc(tll_length(c.applications) * sizeof(c.matches[0]));96 unmodified lines1243 wl_surface_commit(c.wl.surface);1244 wl_display_roundtrip(c.wl.display);1245 1246 struct options options = {1236- .width = width,1237- .height = height,1238- .x_margin = x_margin,1239- .y_margin = y_margin,1240- .border_size = border_size,1247+ .width = c.width,1248+ .height = c.height,1249+ .x_margin = c.x_margin,1250+ .y_margin = c.y_margin,1251+ .border_size = c.border_size,1252 .text_color = text_color,1253 .match_color = match_color,1254 };1255 c.render = render_init(font, options);103 unmodified lines