Skip to content

Commit

Permalink
#164 split the briefs
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Dec 22, 2024
1 parent 426fe35 commit dd00647
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 94 deletions.
12 changes: 10 additions & 2 deletions inc/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "log.h"
#include "mode.h"

#define LEN_BRIEF 1024 * 64

enum InfoEvent {
ARRIVED,
DEPARTED,
Expand All @@ -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

111 changes: 61 additions & 50 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,90 +444,50 @@ 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) {
const struct Head * head = i->val;

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
);
Expand All @@ -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;
}
15 changes: 5 additions & 10 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {

Expand All @@ -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;

Expand All @@ -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);
Expand Down
86 changes: 54 additions & 32 deletions tst/tst-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,59 +258,80 @@ 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);

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);

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"
Expand All @@ -328,40 +349,37 @@ 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);

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"
Expand All @@ -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);
Expand Down

0 comments on commit dd00647

Please sign in to comment.