GLFW: Fix Relative Scale to account for Fractional Scaling on Wayland compositors #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request fixes a bug that is present on the GLFW implementation.
Normally, when you have a HiDPI monitor (e.g. Apple Retina Display or almost any 4K monitor), you need to scale up the monitor's content so that the content isn't too small to view. On X11, usually this only has integer scaling (1x, 2x, 3x), and X11 only measures physical pixels. This leads to an issue where 1x may be too small, but 2x is too big. Wayland uses logical pixels instead. With this in mind, Wayland has something called "Fractional Scaling", so instead of going from 1x to 2x, you can settle for somewhere in between, like 1.25x or 1.5x.
However, the relative scale implementation for GLFW completely fails to take into account fractional scaling. In the current implementation, it truncates any scale to an integer. While that may work in X11, this will not fly by with Wayland. In my case, I have a monitor with 150% scaling, but this implementation truncates that to 100% as 150% is not an integer (1.5x).
This leads to some horrible bugs, the most notable one being the application's cursor position being completely misaligned with the OS's cursor. By making relative scale a double instead of an integer, relative scale can now take fractional scaling into account and fix these bugs.