Skip to content

Commit

Permalink
#164 change messages are on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 10, 2024
1 parent f7a5920 commit de59ff8
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 44 deletions.
97 changes: 55 additions & 42 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void print_cfg_commands(enum LogThreshold t, struct Cfg *cfg) {
}
}

void print_head_current(enum LogThreshold t, struct Head *head) {
void print_head_current(enum LogThreshold t, enum InfoEvent event, struct Head *head) {
static const struct Output *output = NULL;

if (!head)
Expand Down Expand Up @@ -339,45 +339,61 @@ void print_head_current(enum LogThreshold t, struct Head *head) {
}
}

void print_head_desired(enum LogThreshold t, struct Head *head) {
void print_head_deltas(enum LogThreshold t, struct Head *head) {
if (!head)
return;

if (head->desired.enabled) {
if (head_current_mode_not_desired(head)) {
// mode changes happen in their own operation
if (!head->current.enabled || head->current.mode != head->desired.mode) {
print_mode(t, head->desired.mode);
}
} else if (head_current_adaptive_sync_not_desired(head)) {
// adaptive sync changes happen in their own operation
log_(t, " VRR: %s", head->desired.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off");
} else {
if (!head->current.enabled || head->current.scale != head->desired.scale) {
log_(t, " scale: %.3f%s",
wl_fixed_to_double(head->desired.scale),
(!head->width_mm || !head->height_mm) ? " (default, size not specified)" : ""
);
}
if (!head->current.enabled || head->current.x != head->desired.x || head->current.y != head->desired.y) {
log_(t, " position: %d,%d",
head->desired.x,
head->desired.y
);
}
if (!head->current.enabled || head->current.transform != head->desired.transform) {
if (head->desired.transform) {
log_(t, " transform: %s", transform_name(head->desired.transform));
} else {
log_(t, " transform: none");
}
}
}
if (!head->current.enabled) {
log_(t, " (enabled)");
if (head->current.enabled && !head->desired.enabled) {
log_(t, " (enabled) -> (disabled)");
return;
}

if (!head->current.enabled == head->desired.enabled) {
log_(t, " (disabled) -> (enabled)");
}

// mode changes happen in their own operation
if (head_current_mode_not_desired(head)) {
if (!head->current.enabled || head->current.mode != head->desired.mode) {
static char buf_current[2048];
static char buf_desired[2048];

info_mode_string(head->current.mode, buf_current, sizeof(buf_current));
info_mode_string(head->desired.mode, buf_desired, sizeof(buf_desired));

log_(t, " mode: %s -> %s", buf_current, buf_desired);
}
} else {
log_(t, " (disabled)");
return;
}

// adaptive sync changes happen in their own operation
if (head_current_adaptive_sync_not_desired(head)) {
log_(t, " VRR: %s -> %s",
head->current.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off",
head->desired.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off"
);
return;
}

if (!head->current.enabled || head->current.scale != head->desired.scale) {
log_(t, " scale: %.3f -> %.3f",
wl_fixed_to_double(head->current.scale),
wl_fixed_to_double(head->desired.scale)
);
}

if (!head->current.enabled || head->current.x != head->desired.x || head->current.y != head->desired.y) {
log_(t, " position: %d,%d -> %d,%d",
head->current.x, head->current.y,
head->desired.x, head->desired.y
);
}

if (!head->current.enabled || head->current.transform != head->desired.transform) {
log_(t, " transform: %s -> %s",
head->current.transform ? transform_name(head->current.transform) : "none",
head->desired.transform ? transform_name(head->desired.transform) : "none"
);
}
}

Expand Down Expand Up @@ -415,7 +431,7 @@ void print_head(enum LogThreshold t, enum InfoEvent event, struct Head *head) {
print_modes_res_refresh(t, head);
print_modes_failed(t, head);
log_(t, " current:");
print_head_current(t, head);
print_head_current(t, event, head);
break;
case DEPARTED:
log_(t, "\n%s Departed:", head->name);
Expand All @@ -426,11 +442,8 @@ void print_head(enum LogThreshold t, enum InfoEvent event, struct Head *head) {
break;
case DELTA:
if (head_current_not_desired(head)) {
log_(t, "\n%s Changing:", head->name);
log_(t, " from:");
print_head_current(t, head);
log_(t, " to:");
print_head_desired(t, head);
log_(t, "\n%s:", head->name);
print_head_deltas(t, head);
}
break;
default:
Expand Down
4 changes: 4 additions & 0 deletions tst/info/print-head-deltas-disable.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

name:
(enabled) -> (disabled)

4 changes: 4 additions & 0 deletions tst/info/print-head-deltas-mode.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

name:
mode: 100x200@30Hz (30,000mHz) (preferred) -> 400x500@60Hz (60,000mHz)

7 changes: 7 additions & 0 deletions tst/info/print-head-deltas-other.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

name:
(disabled) -> (enabled)
scale: 2.000 -> 4.000
position: 700,800 -> 900,1000
transform: 180 -> 90

4 changes: 4 additions & 0 deletions tst/info/print-head-deltas-vrr.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

name:
VRR: off -> on

55 changes: 53 additions & 2 deletions tst/tst-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ int before_each(void **state) {

head->desired.mode = mode_des;
head->desired.scale = 1024;
head->desired.enabled = false;
head->desired.enabled = true;
head->desired.x = 900;
head->desired.y = 1000;
head->desired.transform = WL_OUTPUT_TRANSFORM_90;
head->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED;
head->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED;

return 0;
}
Expand Down Expand Up @@ -146,6 +146,53 @@ void print_head_departed(void **state) {
free(expected_log);
}

void print_head_deltas__mode(void **state) {
head->current.enabled = true;
head->desired.enabled = true;

print_head(INFO, DELTA, head);

char *expected_log = read_file("tst/info/print-head-deltas-mode.log");
assert_log(INFO, expected_log);
free(expected_log);
}

void print_head_deltas__vrr(void **state) {
head->current.enabled = true;
head->desired.enabled = true;
head->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED;
head->desired.mode = head->current.mode;

print_head(INFO, DELTA, head);

char *expected_log = read_file("tst/info/print-head-deltas-vrr.log");
assert_log(INFO, expected_log);
free(expected_log);
}

void print_head_deltas__other(void **state) {
head->current.enabled = false;
head->desired.enabled = true;
head->desired.mode = head->current.mode;

print_head(INFO, DELTA, head);

char *expected_log = read_file("tst/info/print-head-deltas-other.log");
assert_log(INFO, expected_log);
free(expected_log);
}

void print_head_deltas__disable(void **state) {
head->current.enabled = true;
head->desired.enabled = false;

print_head(INFO, DELTA, head);

char *expected_log = read_file("tst/info/print-head-deltas-disable.log");
assert_log(INFO, expected_log);
free(expected_log);
}

int main(void) {
const struct CMUnitTest tests[] = {
TEST(print_cfg_commands__empty),
Expand All @@ -154,6 +201,10 @@ int main(void) {
TEST(print_head_arrived__all),
TEST(print_head_arrived__min),
TEST(print_head_departed),
TEST(print_head_deltas__mode),
TEST(print_head_deltas__vrr),
TEST(print_head_deltas__other),
TEST(print_head_deltas__disable),
};

return RUN(tests);
Expand Down

0 comments on commit de59ff8

Please sign in to comment.