Skip to content

Commit

Permalink
Merge branch 'master' into chore-cppcheck-2.14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis authored Jun 16, 2024
2 parents dd0de65 + f806b30 commit b5661c4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bld/vg.supp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
Memcheck:Leak
match-leak-kinds: reachable
...
fun:gobject_init
obj:*libgobject*
fun:call_init
fun:call_init
fun:_dl_init
Expand Down
4 changes: 2 additions & 2 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ void info_mode_string(struct Mode *mode, char *buf, size_t nbuf) {
return;
}

snprintf(buf, nbuf, "%dx%d@%dHz (%d,%03dmHz) %s",
snprintf(buf, nbuf, "%dx%d@%dHz (%d,%03dmHz)%s",
mode->width,
mode->height,
mhz_to_hz_rounded(mode->refresh_mhz),
mode->refresh_mhz / 1000,
mode->refresh_mhz % 1000,
mode->preferred ? "(preferred)" : ""
mode->preferred ? " (preferred)" : ""
);
}

Expand Down
18 changes: 13 additions & 5 deletions src/listener_zwlr_output_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,21 @@ static void preferred(void *data,

// some heads may advertise multiple preferred modes; ignore subsequent
if (mode->head) {
struct Mode *preferred_mode;
if ((preferred_mode = head_preferred_mode(mode->head))) {
struct Mode *mode_preferred;
if ((mode_preferred = head_preferred_mode(mode->head))) {

static char mode_preferred_buf[2048];
info_mode_string(mode_preferred, mode_preferred_buf, sizeof(mode_preferred_buf));

static char mode_buf[2048];
info_mode_string(mode, mode_buf, sizeof(mode_buf));
static char preferred_mode_buf[2048];
info_mode_string(preferred_mode, preferred_mode_buf, sizeof(preferred_mode_buf));
log_warn("\n%s already specified for '%s', ignoring %s", mode_buf, mode->head->name, preferred_mode_buf);

if (mode_preferred->head && mode_preferred->head->name) {
log_info("\n%s: multiple preferred modes advertised: using initial %s, ignoring %s", mode_preferred->head->name, mode_preferred_buf, mode_buf);
} else {
log_info("\n???: multiple preferred modes advertised: using initial %s, ignoring %s", mode_preferred_buf, mode_buf);
}

return;
}
}
Expand Down
78 changes: 78 additions & 0 deletions tst/tst-listener_zwlr_output_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "tst.h"
#include "asserts.h"
#include "util.h"

#include <cmocka.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client-protocol.h>

#include "cfg.h"
#include "slist.h"
#include "log.h"
#include "info.h"

#include "listeners.h"

int before_all(void **state) {
return 0;
}

int after_all(void **state) {
return 0;
}

int before_each(void **state) {
return 0;
}

int after_each(void **state) {
assert_logs_empty();

return 0;
}

void preferred__first(void **state) {
struct Head head = { .name = "NAM", };
struct Mode mode_existing = { .width = 3840, .height = 2160, .preferred = false, .refresh_mhz = 60000, .head = &head, };
struct Mode mode_preferred = { .width = 2560, .height = 1440, .preferred = false, .refresh_mhz = 30000, .head = &head, };

slist_append(&head.modes, &mode_existing);
slist_append(&head.modes, &mode_preferred);

zwlr_output_mode_listener()->preferred(&mode_preferred, NULL);

assert_false(mode_existing.preferred);
assert_true(mode_preferred.preferred);

slist_free(&head.modes);
}

void preferred__subsequent(void **state) {
struct Head head = { .name = "NAM", };
struct Mode mode_existing = { .width = 3840, .height = 2160, .preferred = true, .refresh_mhz = 60000, .head = &head, };
struct Mode mode_subsequent = { .width = 2560, .height = 1440, .preferred = false, .refresh_mhz = 30000, .head = &head, };

slist_append(&head.modes, &mode_existing);
slist_append(&head.modes, &mode_subsequent);

zwlr_output_mode_listener()->preferred(&mode_subsequent, NULL);

assert_log(INFO, "\nNAM: multiple preferred modes advertised: using initial 3840x2160@60Hz (60,000mHz) (preferred), ignoring 2560x1440@30Hz (30,000mHz)\n");

assert_true(mode_existing.preferred);
assert_false(mode_subsequent.preferred);

slist_free(&head.modes);
}

int main(void) {
const struct CMUnitTest tests[] = {
TEST(preferred__first),
TEST(preferred__subsequent)
};

return RUN(tests);
}

0 comments on commit b5661c4

Please sign in to comment.