Skip to content

Commit

Permalink
alex-courtis#138 truncate scaled dimensions to match wayland
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 28, 2023
1 parent 921aa79 commit 53fef68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ void head_scaled_dimensions(struct Head *head) {
head->scaled.height = head->desired.mode->width;
}

head->scaled.height = (int32_t)((double)head->scaled.height * 256 / head->desired.scale + 0.5);
head->scaled.width = (int32_t)((double)head->scaled.width * 256 / head->desired.scale + 0.5);
// wayland truncates when calculating size so we do the same
head->scaled.height = (int32_t)((double)head->scaled.height * 256 / head->desired.scale);
head->scaled.width = (int32_t)((double)head->scaled.width * 256 / head->desired.scale);
}

struct Mode *head_find_mode(struct Head *head) {
Expand Down
2 changes: 1 addition & 1 deletion tst/tst-head.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void head_scaled_dimensions__calculated(void **state) {

head_scaled_dimensions(&head);
assert_int_equal(head.scaled.width, 33);
assert_int_equal(head.scaled.height, 67);
assert_int_equal(head.scaled.height, 66); // wayland truncates when calculating size
}

void head_find_mode__none(void **state) {
Expand Down
14 changes: 14 additions & 0 deletions tst/tst-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ void mode_user_mode__exact_hz_failed(void **state) {
assert_ptr_equal(actual, slist_at(modes, 0));
}

void mode_dpi__(void **state) {
struct Head head = { .width_mm = 1000, .height_mm = 500, };
struct Mode mode = { .width = 2000, .height = 1000, .head = &head };

// nice roundish number to prevent odd test fails
double expected = 50.8;

double actual = mode_dpi(&mode);

assert_double_equal(actual, expected, 0);
}

int main(void) {
const struct CMUnitTest tests[] = {
TEST(mode_mhz_to_hz_str__),
Expand All @@ -157,6 +169,8 @@ int main(void) {
TEST(mode_user_mode__failed),
TEST(mode_user_mode__exact_hz_match),
TEST(mode_user_mode__exact_hz_failed),

TEST(mode_dpi__),
};

return RUN(tests);
Expand Down

0 comments on commit 53fef68

Please sign in to comment.