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 11, 2024
1 parent 791b892 commit 874b7b4
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 27 deletions.
2 changes: 0 additions & 2 deletions inc/displ.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ struct Displ {
char *zxdg_output_manager_interface;

enum ConfigState config_state;

char *delta_message;
};

void displ_init(void);
Expand Down
2 changes: 2 additions & 0 deletions inc/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

34 changes: 25 additions & 9 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -438,8 +438,8 @@ void layout(void) {
break;
}

free(displ->delta_message);
displ->delta_message = NULL;
free(deltas_brief);
deltas_brief = NULL;

desire();
apply();
Expand Down
37 changes: 32 additions & 5 deletions tst/tst-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
};
Expand Down
9 changes: 3 additions & 6 deletions tst/tst-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

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

0 comments on commit 874b7b4

Please sign in to comment.