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

[Bug] Issues with Wayland fractional scaling #2002

Open
1 task done
Surasia opened this issue Dec 12, 2024 · 13 comments
Open
1 task done

[Bug] Issues with Wayland fractional scaling #2002

Surasia opened this issue Dec 12, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@Surasia
Copy link

Surasia commented Dec 12, 2024

Operating System

Linux 6.12.4-arch1-1 (GNOME 47)

What's the issue you encountered?

ImHex seems to encounter some issues with Wayland's fractional scaling (set to 175% in my case), where the following occur:

  • OS Window decorations seem to not respect theme (light/dark on GNOME)
    image

  • When OS Window decorations are disabled, ImHex's own decorations don't show up
    image

  • Font is not scaled to the same resolution to the rest of the UI, which makes anti aliasing very blurry.
    image
    image

  • Context menus appear in incorrect positions (not consistently reproducible)

  • Mouse cursor seems to artifact (issue disappears when screen recording?)

How can the issue be reproduced?

Use Wayland Windowing system in addition to setting fractional scaling settings in your DE, observe issues in ImHex when built from source.

ImHex Version

21b315b

ImHex Build Type

  • Nightly or built from sources

Installation type

Through ninja install

Additional context?

I also used xlsclients to make sure that ImHex was not using XWayland, and it is not. Weirdly enough, I observed similar issues when running on XWayland, such as the window decorations being in the incorrect theme.

@Surasia Surasia added the bug Something isn't working label Dec 12, 2024
@WerWolv
Copy link
Owner

WerWolv commented Dec 12, 2024

Hey
I believe there's multiple different things at play here.

  • The window decoration is being handled by libdecor on Wayland which is entirely managed by glfw. I believe there's a separate config file somewhere for the libdecor theme that you need to set to the theme you want, it generally does not respect the system theme.
  • The font issues are to be expected. The default font is a pixel-perfect bitmap font. It will only ever look good when scaled in integer amounts. You can choose the second default font which doesn't have that issue or simply load a custom font.
  • The mouse cursor artifacts I believe are because wayland renders its own mouse cursor. And if the application doesn't run exactly at the monitor frame rate, it will cause artifacts

@Surasia
Copy link
Author

Surasia commented Dec 13, 2024

For the window decorations, I wasn't able to change it via legacy GTK settings (which libdecor should inherit), but I assume it is an issue on my end. (solution was to use Adwaita theme) I assume the Imhex-style window decorations are not planned?

The font itself is not the default one, it is JetBrainsMono Nerd Font with 1.5x scaling. It works (scales) fine on Windows, but I think fractional scaling is not being taken into account when determining the resolution in which the text should be rasterize.

@lg28literconvectionmicrowaveoven

For me, (on KDE Wayland), everything is perfect except for fractional scaling causing the application to look blurry. It seems to be scaling well save the blurriness.

@Promix953
Copy link

With wayland, I'm using 2x at 4K resolution, and custom fonts, and the anti-aliasing is still blurry.

@WerWolv
Copy link
Owner

WerWolv commented Jan 1, 2025

I believe the issue is the same as we had on macOS where I fixed it by rendering the font at the full resolution now.
Is there some good way to get the current scaling factor in a way that works on most DEs?

@Surasia
Copy link
Author

Surasia commented Jan 1, 2025

glfwGetMonitorPhysicalSize might be useful to determine screen scaling? also should work cross platform

@WerWolv
Copy link
Owner

WerWolv commented Jan 3, 2025

Latest commit (dcd80fe) improved window size and font / image scaling on Wayland. Please try it out and see if it works better

For reference, I still don't have a 4K monitor or anything of that sort but the window now looks the same as the X11 window when setting e.g the GNOME scaling to 200%

@Promix953
Copy link

Latest commit (dcd80fe) improved window size and font / image scaling on Wayland. Please try it out and see if it works better

For reference, I still don't have a 4K monitor or anything of that sort but the window now looks the same as the X11 window when setting e.g the GNOME scaling to 200%

screenshot_03012025_223412

Wow, the text is clearer now.
Good job!

@WerWolv
Copy link
Owner

WerWolv commented Jan 3, 2025

Awesome! Thanks for reporting back

@WerWolv
Copy link
Owner

WerWolv commented Jan 3, 2025

Also, side-by-side view here. Left is X11 through xwayland, right is Wayland native

image

Edit: Looks like window rounding is different between the two still so maybe some style scaling issues are still at play. Will iron those out over time. Should be usable for now though I hope!

@Surasia
Copy link
Author

Surasia commented Jan 3, 2025

@WerWolv With the latest commit, it seems that the scaling reported is incorrect. I have fractional scaling set to 175%, but it seems to report 0.9x as the native scale on Wayland. Windows worked previously and set native scaling to 1.8x, but now seems to use 1.0x as its native value.
image
image

@Surasia
Copy link
Author

Surasia commented Jan 3, 2025

Update: Scaling from glfw seems to be reported incorrectly, it ceils the scaling.
I used this code snippet with python-glfw and ran it both on Linux and Windows:

import glfw

def main():
    glfw.init()
    m = glfw.get_monitor_content_scale(glfw.get_primary_monitor())
    print(m)


if __name__ == "__main__":
    main()

Windows prints (1.75, 1.75) while it is (2.0, 2.0) on Linux. Also, I'm not sure if this is relevant or not, but GLFW_SCALE_TO_MONITOR doesn't work on Wayland.

edit: this does seem to also be the reason why scaling doesn't match up between platforms.

@WerWolv
Copy link
Owner

WerWolv commented Jan 3, 2025

Thank you!
Yeah I had to trick around a bit because Wayland consistently rendered the window content at the correct resolution, the window was just double the size it should have been. As if Wayland was applying its own scaling on top of the one I'm doing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants