Skip to content

Commit

Permalink
#164 render a brief change message to set as $WD_MESSAGE for the command
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 18, 2024
1 parent 66b2cf4 commit af7adbf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
18 changes: 10 additions & 8 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,18 @@ char *render_deltas_brief(const enum ConfigState config_state, const struct SLis
for (const struct SList *i = heads; i; i = i->nex) {
const struct Head * head = i->val;

char *desc_or_name = head->description ? head->description : head->name;

if (head->current.enabled && !head->desired.enabled) {
bufp += snprintf(bufp, len - (bufp - buf), "%s: disabled\n", head->name);
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
head->name,
(!head->current.enabled && head->desired.enabled) ? ": enabled" : ""
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) {
Expand Down Expand Up @@ -494,21 +496,21 @@ char *render_deltas_brief(const enum ConfigState config_state, const struct SLis

// enable with no change in mode
if (!head->current.enabled && head->desired.enabled) {
bufp += snprintf(bufp, len - (bufp - buf), "%s: enabled\n", head->name);
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
head->name,
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"
);
continue;
}

if (head_current_not_desired(head)) {
bufp += snprintf(bufp, len - (bufp - buf), "%s:\n", head->name);
bufp += snprintf(bufp, len - (bufp - buf), "%s\n", desc_or_name);

if (head->current.scale != head->desired.scale) {
bufp += snprintf(bufp, len - (bufp - buf), " scale: %.3f -> %.3f\n",
Expand Down
21 changes: 10 additions & 11 deletions tst/tst-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ int before_each(void **state) {
slist_append(&s->head2->modes_failed, mode_failed);

s->head2->name = strdup("name2");
s->head2->description = strdup("description2");
s->head2->width_mm = 3;
s->head2->height_mm = 4;
s->head2->make = strdup("make2");
Expand Down Expand Up @@ -269,9 +268,9 @@ void render_deltas_brief__mode(void **state) {
char *deltas = render_deltas_brief(SUCCEEDED, s->heads);

assert_string_equal(deltas, ""
"name1:\n"
"description1\n"
" mode: 100x200@30Hz -> (no mode)\n"
"name2:\n"
"name2\n"
" mode: (no mode) -> 1400x1500@160Hz"
);

Expand All @@ -294,9 +293,9 @@ void render_deltas_brief__vrr(void **state) {
char *deltas = render_deltas_brief(SUCCEEDED, s->heads);

assert_string_equal(deltas, ""
"name1:\n"
"description1\n"
" VRR: on\n"
"name2:\n"
"name2\n"
" VRR: off"
);

Expand All @@ -314,11 +313,11 @@ void render_deltas_brief__other(void **state) {
char *deltas = render_deltas_brief(SUCCEEDED, s->heads);

assert_string_equal(deltas, ""
"name1:\n"
"description1\n"
" scale: 2.000 -> 4.000\n"
" transform: 180 -> 90\n"
" position: 700,800 -> 900,1000\n"
"name2:\n"
"name2\n"
" scale: 8.000 -> 16.000\n"
" transform: 270 -> none\n"
" position: 1700,1800 -> 1900,11000"
Expand All @@ -342,8 +341,8 @@ void render_deltas_brief__enabled(void **state) {
char *deltas = render_deltas_brief(SUCCEEDED, s->heads);

assert_string_equal(deltas, ""
"name1: enabled\n"
"name2: enabled:\n"
"description1 enabled\n"
"name2 enabled:\n"
" mode: 1100x1200@130Hz -> 1400x1500@160Hz"
);

Expand All @@ -365,8 +364,8 @@ void render_deltas_brief__disabled(void **state) {
char *deltas = render_deltas_brief(SUCCEEDED, s->heads);

assert_string_equal(deltas, ""
"name1: disabled\n"
"name2: disabled"
"description1 disabled\n"
"name2 disabled"
);

slist_free(&heads);
Expand Down

0 comments on commit af7adbf

Please sign in to comment.