From dd006471a10e4e4cbe96520e0d726a6e892e4157 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 22 Dec 2024 14:20:28 +1100 Subject: [PATCH] #164 split the briefs --- inc/info.h | 12 +++++- src/info.c | 111 +++++++++++++++++++++++++++---------------------- src/layout.c | 15 +++---- tst/tst-info.c | 86 ++++++++++++++++++++++++-------------- 4 files changed, 130 insertions(+), 94 deletions(-) diff --git a/inc/info.h b/inc/info.h index 73da503..fb55eca 100644 --- a/inc/info.h +++ b/inc/info.h @@ -11,6 +11,8 @@ #include "log.h" #include "mode.h" +#define LEN_BRIEF 1024 * 64 + enum InfoEvent { ARRIVED, DEPARTED, @@ -36,8 +38,14 @@ void info_user_mode_string(struct UserMode *user_mode, char *buf, size_t nbuf); void info_mode_string(struct Mode *mode, char *buf, size_t nbuf); -// length 1024 * 64, consumer frees -char *render_deltas_brief(const enum ConfigState config_state, const struct SList * const heads); +// LEN_BRIEF, consumer frees +char *brief_deltas(const enum ConfigState config_state, const struct SList * const heads); + +// LEN_BRIEF, consumer frees +char *brief_delta_mode(const enum ConfigState config_state, const struct Head * const head); + +// LEN_BRIEF, consumer frees +char *brief_delta_adaptive_sync(const enum ConfigState config_state, const struct Head * const head); #endif // INFO_H diff --git a/src/info.c b/src/info.c index b6debae..d37a61d 100644 --- a/src/info.c +++ b/src/info.c @@ -444,14 +444,12 @@ void print_heads(enum LogThreshold t, enum InfoEvent event, struct SList *heads) } } -char *render_deltas_brief(const enum ConfigState config_state, const struct SList * const heads) { +char *brief_deltas(const enum ConfigState config_state, const struct SList * const heads) { if (!heads) { return NULL; } - static const int len = 1024 * 64; - - char *buf = (char*)calloc(len, sizeof(char)); + char *buf = (char*)calloc(LEN_BRIEF, sizeof(char)); char *bufp = buf; for (const struct SList *i = heads; i; i = i->nex) { @@ -459,75 +457,37 @@ char *render_deltas_brief(const enum ConfigState config_state, const struct SLis char *desc_or_name = head->description ? head->description : head->name; + // disable in own operation if (head->current.enabled && !head->desired.enabled) { - bufp += snprintf(bufp, len - (bufp - buf), "%s disabled\n", desc_or_name); - continue; - } - - // mode changes happen in their own operation, with an enable - if (head_current_mode_not_desired(head)) { - bufp += snprintf(bufp, len - (bufp - buf), "%s%s\n mode: ", // line up with vrr - desc_or_name, - (!head->current.enabled && head->desired.enabled) ? " enabled:" : "" - ); - - if (head->current.mode) { - bufp += snprintf(bufp, len - (bufp - buf), "%dx%d@%dHz -> ", - head->current.mode->width, - head->current.mode->height, - mhz_to_hz_rounded(head->current.mode->refresh_mhz) - ); - } else { - bufp += snprintf(bufp, len - (bufp - buf), "(no mode) -> "); - } - - if (head->desired.mode) { - bufp += snprintf(bufp, len - (bufp - buf), "%dx%d@%dHz\n", - head->desired.mode->width, - head->desired.mode->height, - mhz_to_hz_rounded(head->desired.mode->refresh_mhz) - ); - } else { - bufp += snprintf(bufp, len - (bufp - buf), "(no mode)\n"); - } - + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s disabled\n", desc_or_name); continue; } - // enable with no change in mode + // enable in own operation if (!head->current.enabled && head->desired.enabled) { - bufp += snprintf(bufp, len - (bufp - buf), "%s enabled\n", desc_or_name); - continue; - } - - // adaptive sync changes happen in their own operation - if (head_current_adaptive_sync_not_desired(head)) { - bufp += snprintf(bufp, len - (bufp - buf), "%s\n VRR: %s\n", // line up with mode - desc_or_name, - head->desired.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off" - ); + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s enabled\n", desc_or_name); continue; } if (head_current_not_desired(head)) { - bufp += snprintf(bufp, len - (bufp - buf), "%s\n", desc_or_name); + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s\n", desc_or_name); if (head->current.scale != head->desired.scale) { - bufp += snprintf(bufp, len - (bufp - buf), " scale: %.3f -> %.3f\n", + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), " scale: %.3f -> %.3f\n", wl_fixed_to_double(head->current.scale), wl_fixed_to_double(head->desired.scale) ); } if (head->current.transform != head->desired.transform) { - bufp += snprintf(bufp, len - (bufp - buf), " transform: %s -> %s\n", + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), " transform: %s -> %s\n", head->current.transform ? transform_name(head->current.transform) : "none", head->desired.transform ? transform_name(head->desired.transform) : "none" ); } if (head->current.x != head->desired.x || head->current.y != head->desired.y) { - bufp += snprintf(bufp, len - (bufp - buf), " position: %d,%d -> %d,%d\n", + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), " position: %d,%d -> %d,%d\n", head->current.x, head->current.y, head->desired.x, head->desired.y ); @@ -543,3 +503,54 @@ char *render_deltas_brief(const enum ConfigState config_state, const struct SLis return buf; } +char *brief_delta_mode(const enum ConfigState config_state, const struct Head * const head) { + if (!head) { + return NULL; + } + + char *buf = (char*)calloc(LEN_BRIEF, sizeof(char)); + char *bufp = buf; + + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s:\n ", + head->description ? head->description : head->name + ); + + if (head->current.mode) { + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%dx%d@%dHz -> ", + head->current.mode->width, + head->current.mode->height, + mhz_to_hz_rounded(head->current.mode->refresh_mhz) + ); + } else { + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "(no mode) -> "); + } + + if (head->desired.mode) { + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%dx%d@%dHz", + head->desired.mode->width, + head->desired.mode->height, + mhz_to_hz_rounded(head->desired.mode->refresh_mhz) + ); + } else { + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "(no mode)"); + } + + return buf; +} + + +char *brief_delta_adaptive_sync(const enum ConfigState config_state, const struct Head * const head) { + if (!head) { + return NULL; + } + + char *buf = (char*)calloc(LEN_BRIEF, sizeof(char)); + char *bufp = buf; + + bufp += snprintf(bufp, LEN_BRIEF - (bufp - buf), "%s:\n VRR %s", + head->description ? head->description : head->name, + head->desired.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off" + ); + + return buf; +} diff --git a/src/layout.c b/src/layout.c index f77b0bb..d55b92e 100644 --- a/src/layout.c +++ b/src/layout.c @@ -289,10 +289,7 @@ void apply(void) { head_changing_mode->zwlr_config_head = zwlr_output_configuration_v1_enable_head(zwlr_config, head_changing_mode->zwlr_head); zwlr_output_configuration_head_v1_set_mode(head_changing_mode->zwlr_config_head, head_changing_mode->desired.mode->zwlr_mode); - struct SList *heads = NULL; - slist_append(&heads, head_changing_mode); - deltas_brief = render_deltas_brief(displ->config_state, heads); - slist_free(&heads); + deltas_brief = brief_delta_mode(displ->config_state, head_changing_mode); } else if ((head_changing_adaptive_sync = slist_find_val(heads, head_current_adaptive_sync_not_desired))) { @@ -302,15 +299,13 @@ void apply(void) { head_changing_adaptive_sync->zwlr_config_head = zwlr_output_configuration_v1_enable_head(zwlr_config, head_changing_adaptive_sync->zwlr_head); zwlr_output_configuration_head_v1_set_adaptive_sync(head_changing_adaptive_sync->zwlr_config_head, head_changing_adaptive_sync->desired.adaptive_sync); - struct SList *heads = NULL; - slist_append(&heads, head_changing_adaptive_sync); - deltas_brief = render_deltas_brief(displ->config_state, heads); - slist_free(&heads); + deltas_brief = brief_delta_adaptive_sync(displ->config_state, head_changing_adaptive_sync); + } else { print_heads(INFO, DELTA, heads); - // all changes except mode + // all other changes for (i = heads_changing; i; i = i->nex) { struct Head *head = (struct Head*)i->val; @@ -324,7 +319,7 @@ void apply(void) { } } - deltas_brief = render_deltas_brief(displ->config_state, heads_changing); + deltas_brief = brief_deltas(displ->config_state, heads_changing); } zwlr_output_configuration_v1_apply(zwlr_config); diff --git a/tst/tst-info.c b/tst/tst-info.c index e843fa7..b815818 100644 --- a/tst/tst-info.c +++ b/tst/tst-info.c @@ -258,20 +258,33 @@ void print_head_deltas__enable(void **state) { free(expected_log); } -void render_deltas_brief__mode(void **state) { +void brief_delta_mode__to_no(void **state) { struct State *s = *state; s->head1->desired.mode = NULL; + char *deltas = brief_delta_mode(SUCCEEDED, s->head1); + + assert_string_equal(deltas, "" + "description1:\n" + " 100x200@30Hz -> (no mode)" + ); + + slist_free(&heads); + + free(deltas); +} + +void brief_delta_mode__from_no(void **state) { + struct State *s = *state; + s->head2->current.mode = NULL; - char *deltas = render_deltas_brief(SUCCEEDED, s->heads); + char *deltas = brief_delta_mode(SUCCEEDED, s->head2); assert_string_equal(deltas, "" - "description1\n" - " mode: 100x200@30Hz -> (no mode)\n" - "name2\n" - " mode: (no mode) -> 1400x1500@160Hz" + "name2:\n" + " (no mode) -> 1400x1500@160Hz" ); slist_free(&heads); @@ -279,24 +292,35 @@ void render_deltas_brief__mode(void **state) { free(deltas); } -void render_deltas_brief__vrr(void **state) { +void brief_delta_adaptive_sync__on(void **state) { struct State *s = *state; - s->head1->desired.mode = s->head1->current.mode; s->head1->current.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED; s->head1->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED; - s->head2->desired.mode = s->head2->current.mode; + char *deltas = brief_delta_adaptive_sync(SUCCEEDED, s->head1); + + assert_string_equal(deltas, "" + "description1:\n" + " VRR on" + ); + + slist_free(&heads); + + free(deltas); +} + +void brief_delta_adaptive_sync__off(void **state) { + struct State *s = *state; + s->head2->current.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED; s->head2->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED; - char *deltas = render_deltas_brief(SUCCEEDED, s->heads); + char *deltas = brief_delta_adaptive_sync(SUCCEEDED, s->head2); assert_string_equal(deltas, "" - "description1\n" - " VRR: on\n" - "name2\n" - " VRR: off" + "name2:\n" + " VRR off" ); slist_free(&heads); @@ -304,13 +328,10 @@ void render_deltas_brief__vrr(void **state) { free(deltas); } -void render_deltas_brief__other(void **state) { +void brief_deltas__all(void **state) { struct State *s = *state; - s->head1->desired.mode = s->head1->current.mode; - s->head2->desired.mode = s->head2->current.mode; - - char *deltas = render_deltas_brief(SUCCEEDED, s->heads); + char *deltas = brief_deltas(SUCCEEDED, s->heads); assert_string_equal(deltas, "" "description1\n" @@ -328,22 +349,20 @@ void render_deltas_brief__other(void **state) { free(deltas); } -void render_deltas_brief__enabled(void **state) { +void brief_deltas__enabled(void **state) { struct State *s = *state; s->head1->current.enabled = false; s->head1->desired.enabled = true; - s->head1->desired.mode = s->head1->current.mode; s->head2->current.enabled = false; s->head2->desired.enabled = true; - char *deltas = render_deltas_brief(SUCCEEDED, s->heads); + char *deltas = brief_deltas(SUCCEEDED, s->heads); assert_string_equal(deltas, "" "description1 enabled\n" - "name2 enabled:\n" - " mode: 1100x1200@130Hz -> 1400x1500@160Hz" + "name2 enabled" ); slist_free(&heads); @@ -351,17 +370,16 @@ void render_deltas_brief__enabled(void **state) { free(deltas); } -void render_deltas_brief__disabled(void **state) { +void brief_deltas__disabled(void **state) { struct State *s = *state; s->head1->current.enabled = true; s->head1->desired.enabled = false; - s->head1->desired.mode = s->head1->current.mode; s->head2->current.enabled = true; s->head2->desired.enabled = false; - char *deltas = render_deltas_brief(SUCCEEDED, s->heads); + char *deltas = brief_deltas(SUCCEEDED, s->heads); assert_string_equal(deltas, "" "description1 disabled\n" @@ -388,11 +406,15 @@ int main(void) { TEST(print_head_deltas__disable), TEST(print_head_deltas__enable), - TEST(render_deltas_brief__mode), - TEST(render_deltas_brief__vrr), - TEST(render_deltas_brief__other), - TEST(render_deltas_brief__enabled), - TEST(render_deltas_brief__disabled), + TEST(brief_delta_mode__to_no), + TEST(brief_delta_mode__from_no), + + TEST(brief_delta_adaptive_sync__on), + TEST(brief_delta_adaptive_sync__off), + + TEST(brief_deltas__all), + TEST(brief_deltas__enabled), + TEST(brief_deltas__disabled), }; return RUN(tests);