Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLFW: Fix Relative Scale to account for Fractional Scaling on Wayland compositors #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/window_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ void GLFWGameWindow::setRelativeScale() {
int wx, wy;
glfwGetWindowSize(window, &wx, &wy);

relativeScale = (int) floor(((fx / wx) + (fy / wy)) / 2);
relativeScale = (((double) fx / (double) wx) + ((double) fy / (double) wy)) / 2.0;
// Update window size to match content size mismatch
width = fx;
height = fy;
resized = true;
}

int GLFWGameWindow::getRelativeScale() const {
double GLFWGameWindow::getRelativeScale() const {
return relativeScale;
}

Expand Down Expand Up @@ -134,8 +134,8 @@ void GLFWGameWindow::pollEvents() {
if(requestFullscreen) {
glfwGetWindowPos(window, &windowedX, &windowedY);
// convert pixels to window coordinates getRelativeScale() is 2 on macOS retina screens
windowedWidth = width / getRelativeScale();
windowedHeight = height / getRelativeScale();
windowedWidth = (int) floor(width / getRelativeScale());
windowedHeight = (int) floor(height / getRelativeScale());
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
int nModes = 0;
auto modes = glfwGetVideoModes(monitor, &nModes);
Expand Down
4 changes: 2 additions & 2 deletions src/window_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GLFWGameWindow : public GameWindow {
int width = -1, height = -1;
// width and height in window coordinates = pixels / relativeScale
int windowedWidth = -1, windowedHeight = -1;
int relativeScale;
double relativeScale;
bool resized = false;
bool focused = true;
bool warnedButtons = false;
Expand Down Expand Up @@ -59,7 +59,7 @@ class GLFWGameWindow : public GameWindow {

void makeCurrent(bool active) override;

int getRelativeScale() const;
double getRelativeScale() const;

void setRelativeScale();

Expand Down