Skip to content

Commit

Permalink
#164 revert to original info deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 10, 2024
1 parent bd5de3e commit 8611705
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 70 deletions.
99 changes: 42 additions & 57 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, enum InfoEvent event, struct Head *head) {
void print_head_current(enum LogThreshold t, struct Head *head) {
static const struct Output *output = NULL;

if (!head)
Expand All @@ -324,11 +324,9 @@ void print_head_current(enum LogThreshold t, enum InfoEvent event, struct Head *
if (head->current.transform) {
log_(t, " transform: %s", transform_name(head->current.transform));
}
}

print_mode(t, head->current.mode);
print_mode(t, head->current.mode);

if (head->current.enabled) {
log_(t, " VRR: %s", head->current.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off");
} else {
log_(t, " (disabled)");
Expand All @@ -339,61 +337,45 @@ void print_head_current(enum LogThreshold t, enum InfoEvent event, struct Head *
}
}

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

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.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);
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");
}
}
}
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.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.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.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"
);
if (!head->current.enabled) {
log_(t, " (enabled)");
}
} else {
log_(t, " (disabled)");
}
}

Expand Down Expand Up @@ -431,7 +413,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, event, head);
print_head_current(t, head);
break;
case DEPARTED:
log_(t, "\n%s Departed:", head->name);
Expand All @@ -443,7 +425,10 @@ void print_head(enum LogThreshold t, enum InfoEvent event, struct Head *head) {
case DELTA:
if (head_current_not_desired(head)) {
log_(t, "\n%s Changing:", head->name);
print_head_deltas(t, head);
log_(t, " from:");
print_head_current(t, head);
log_(t, " to:");
print_head_desired(t, head);
}
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void pid_file_create(void) {
void spawn_sh_cmd(const char * const command, char * const message) {

// experiments show that environment variable length tops out at 128k: variable itself plus contents
message[1024 * 120] = '\0';
// message[1024 * 120] = '\0';

pid_t pid = fork();
if (pid < 0) {
Expand Down
1 change: 0 additions & 1 deletion tst/info/print-head-arrived-min.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
width: (not specified)
height: (not specified)
current:
(no mode)
(disabled)

9 changes: 8 additions & 1 deletion tst/info/print-head-deltas-disable.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

name Changing:
(enabled) -> (disabled)
from:
scale: 2.000 (26.458)
position: 700,800
transform: 180
mode: 100x200@30Hz (30,000mHz) (preferred)
VRR: off
to:
(disabled)

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

name Changing:
from:
(disabled)
to:
mode: 400x500@60Hz (60,000mHz)
(enabled)

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

name Changing:
mode: 100x200@30Hz (30,000mHz) (preferred) -> 400x500@60Hz (60,000mHz)
from:
scale: 2.000 (26.458)
position: 700,800
transform: 180
mode: 100x200@30Hz (30,000mHz) (preferred)
VRR: off
to:
mode: 400x500@60Hz (60,000mHz)

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

name Changing:
(disabled) -> (enabled)
scale: 2.000 -> 4.000
position: 700,800 -> 900,1000
transform: 180 -> 90
from:
scale: 2.000 (26.458)
position: 700,800
transform: 180
mode: 100x200@30Hz (30,000mHz) (preferred)
VRR: off
to:
scale: 4.000
position: 900,1000
transform: 90

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

name Changing:
VRR: off -> on
from:
scale: 2.000 (26.458)
position: 700,800
transform: 180
mode: 100x200@30Hz (30,000mHz) (preferred)
VRR: off
to:
VRR: on

File renamed without changes.
21 changes: 17 additions & 4 deletions tst/tst-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ void print_head_arrived__min(void **state) {
free(expected_log);
}

void print_head_departed(void **state) {
void print_head_departed__ok(void **state) {
print_head(INFO, DEPARTED, head);

char *expected_log = read_file("tst/info/print-head-departed.log");
char *expected_log = read_file("tst/info/print-head-departed-ok.log");
assert_log(INFO, expected_log);
free(expected_log);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ void print_head_deltas__vrr(void **state) {
}

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

Expand All @@ -193,18 +193,31 @@ void print_head_deltas__disable(void **state) {
free(expected_log);
}

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

print_head(INFO, DELTA, head);

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

int main(void) {
const struct CMUnitTest tests[] = {
TEST(print_cfg_commands__empty),
TEST(print_cfg_commands__ok),

TEST(print_head_arrived__all),
TEST(print_head_arrived__min),
TEST(print_head_departed),
TEST(print_head_departed__ok),

TEST(print_head_deltas__mode),
TEST(print_head_deltas__vrr),
TEST(print_head_deltas__other),
TEST(print_head_deltas__disable),
TEST(print_head_deltas__enable),
};

return RUN(tests);
Expand Down

0 comments on commit 8611705

Please sign in to comment.