diff --git a/inc/displ.h b/inc/displ.h index a76dcb7..d66295b 100644 --- a/inc/displ.h +++ b/inc/displ.h @@ -35,8 +35,6 @@ struct Displ { char *zxdg_output_manager_interface; enum ConfigState config_state; - - char *delta_message; }; void displ_init(void); diff --git a/inc/global.h b/inc/global.h index 3cd7d02..5944188 100644 --- a/inc/global.h +++ b/inc/global.h @@ -10,4 +10,6 @@ extern struct SList *cfg_file_paths; extern struct Head *head_changing_mode; extern struct Head *head_changing_adaptive_sync; +extern char *deltas_brief; + #endif // GLOBAL_H diff --git a/src/global.c b/src/global.c index 827cdbe..3e7de8b 100644 --- a/src/global.c +++ b/src/global.c @@ -9,3 +9,5 @@ struct SList *cfg_file_paths = NULL; struct Head *head_changing_mode = NULL; struct Head *head_changing_adaptive_sync = NULL; +char *deltas_brief = NULL; + diff --git a/src/info.c b/src/info.c index 06081dc..e95cb01 100644 --- a/src/info.c +++ b/src/info.c @@ -462,21 +462,37 @@ char *render_deltas_brief(const enum ConfigState config_state, const struct SLis continue; } - // mode changes happen in their own operation + // 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: %dx%d@%dHz -> %dx%d@%dHz\n", // line up with vrr + bufp += snprintf(bufp, len - (bufp - buf), "%s%s:\n mode: ", // line up with vrr head->name, - (!head->current.enabled && head->desired.enabled) ? ": enabled" : "", - head->current.mode->width, - head->current.mode->height, - mhz_to_hz_rounded(head->current.mode->refresh_mhz), - head->desired.mode->width, - head->desired.mode->height, - mhz_to_hz_rounded(head->desired.mode->refresh_mhz) + (!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"); + } + continue; } + // enable with no change in mode if (!head->current.enabled && head->desired.enabled) { bufp += snprintf(bufp, len - (bufp - buf), "%s: enabled\n", head->name); continue; diff --git a/src/layout.c b/src/layout.c index f661ca3..92ade16 100644 --- a/src/layout.c +++ b/src/layout.c @@ -327,8 +327,8 @@ void apply(void) { zwlr_output_configuration_v1_apply(zwlr_config); - free(displ->delta_message); - displ->delta_message = render_deltas_brief(displ->config_state, heads_changing); + free(deltas_brief); + deltas_brief = render_deltas_brief(displ->config_state, heads_changing); displ->config_state = OUTSTANDING; @@ -368,7 +368,7 @@ void handle_success(void) { log_info("\nExecuting CHANGE_SUCCESS_CMD:"); log_info(" %s", cfg->change_success_cmd); - spawn_sh_cmd(cfg->change_success_cmd, displ->delta_message); + spawn_sh_cmd(cfg->change_success_cmd, deltas_brief); } log_info("\nChanges successful"); @@ -438,8 +438,8 @@ void layout(void) { break; } - free(displ->delta_message); - displ->delta_message = NULL; + free(deltas_brief); + deltas_brief = NULL; desire(); apply(); diff --git a/tst/tst-info.c b/tst/tst-info.c index 24814cd..ec25306 100644 --- a/tst/tst-info.c +++ b/tst/tst-info.c @@ -259,19 +259,45 @@ void print_head_deltas__enable(void **state) { free(expected_log); } -void render_deltas_brief__mode_vrr(void **state) { +void render_deltas_brief__mode(void **state) { struct State *s = *state; - s->head2->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED; + s->head1->desired.mode = NULL; + + s->head2->current.mode = NULL; + + char *deltas = render_deltas_brief(SUCCEEDED, s->heads); + + assert_string_equal(deltas, "" + "name1:\n" + " mode: 100x200@30Hz -> (no mode)\n" + "name2:\n" + " mode: (no mode) -> 1400x1500@160Hz" + ); + + slist_free(&heads); + + free(deltas); +} + +void render_deltas_brief__vrr(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; + 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); assert_string_equal(deltas, "" "name1:\n" - " mode: 100x200@30Hz -> 400x500@60Hz\n" + " VRR: on\n" "name2:\n" - " VRR: on" + " VRR: off" ); slist_free(&heads); @@ -363,7 +389,8 @@ int main(void) { TEST(print_head_deltas__disable), TEST(print_head_deltas__enable), - TEST(render_deltas_brief__mode_vrr), + TEST(render_deltas_brief__mode), + TEST(render_deltas_brief__vrr), TEST(render_deltas_brief__other), TEST(render_deltas_brief__enabled), }; diff --git a/tst/tst-layout.c b/tst/tst-layout.c index 974301c..6f5f620 100644 --- a/tst/tst-layout.c +++ b/tst/tst-layout.c @@ -59,7 +59,6 @@ int after_all(void **state) { int before_each(void **state) { cfg = cfg_default(); - displ = calloc(1, sizeof(struct Displ)); struct State *s = calloc(1, sizeof(struct State)); @@ -83,8 +82,6 @@ int after_each(void **state) { head_changing_mode = NULL; head_changing_adaptive_sync = NULL; - free(displ); - cfg_destroy(); struct State *s = *state; @@ -645,14 +642,14 @@ void handle_success__head_changing_mode(void **state) { void handle_success__change_success_cmd(void **state) { cfg->change_success_cmd = strdup("echo \"hi from way-displays\""); - displ->delta_message = strdup("DP-1: enabled\n mode: xx->yy"); + deltas_brief = strdup("DP-1: enabled\n mode: xx->yy"); expect_string(__wrap_spawn_sh_cmd, command, cfg->change_success_cmd); - expect_string(__wrap_spawn_sh_cmd, message, displ->delta_message); + expect_string(__wrap_spawn_sh_cmd, message, deltas_brief); handle_success(); - free(displ->delta_message); + free(deltas_brief); assert_log(INFO, "\nExecuting CHANGE_SUCCESS_CMD:\n" " echo \"hi from way-displays\"\n"