From 81a63545a031fdb5ca9fc459e59c9f4b02992511 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 24 Mar 2015 21:50:35 +0100 Subject: options: add conversion to string for geometry option types Pretty messy, which is why it wasn't done at first. (Also, I'd really like to have simpler syntax and semantics for this damn option, but who knows when this will happen.) Fixes #1705. --- options/m_option.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/options/m_option.c b/options/m_option.c index e0d35e6a24..ea4b8d18b9 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1990,6 +1990,35 @@ error: #undef READ_NUM #undef READ_SIGN +#define APPEND_PER(F, F_PER) \ + res = talloc_asprintf_append(res, "%d%s", gm->F, gm->F_PER ? "%" : "") + +static char *print_geometry(const m_option_t *opt, const void *val) +{ + const struct m_geometry *gm = val; + char *res = talloc_strdup(NULL, ""); + if (gm->wh_valid || gm->xy_valid) { + if (gm->wh_valid) { + APPEND_PER(w, w_per); + res = talloc_asprintf_append(res, "x"); + APPEND_PER(h, h_per); + } + if (gm->xy_valid) { + res = talloc_asprintf_append(res, "+"); + if (gm->x_sign) + res = talloc_asprintf_append(res, "-"); + APPEND_PER(x, x_per); + res = talloc_asprintf_append(res, "+"); + if (gm->y_sign) + res = talloc_asprintf_append(res, "-"); + APPEND_PER(y, y_per); + } + } + return res; +} + +#undef APPEND_PER + // xpos,ypos: position of the left upper corner // widw,widh: width and height of the window // scrw,scrh: width and height of the current screen @@ -2053,6 +2082,7 @@ const m_option_type_t m_option_type_geometry = { .name = "Window geometry", .size = sizeof(struct m_geometry), .parse = parse_geometry, + .print = print_geometry, .copy = copy_opt, }; @@ -2082,6 +2112,7 @@ const m_option_type_t m_option_type_size_box = { .name = "Window size", .size = sizeof(struct m_geometry), .parse = parse_size_box, + .print = print_geometry, .copy = copy_opt, }; -- cgit v1.2.3