michaelforney / swc

a library for making a simple Wayland compositor
MIT License
626 stars 53 forks source link

refresh rate? #77

Open chimps-ahoy opened 4 months ago

chimps-ahoy commented 4 months ago

I am wondering how the compositor detects/configures the refresh rate of the display.

I am writing my own window manager with swc and I noticed when testing it that my display was only running at 60hz when on X11 it runs at the full 170hz. I checked with the example wm and it is still the case.

I wasn't able to find a function call or anything to check/set the refresh rate, so I figured I'd ask :)

chimps-ahoy commented 4 months ago

i have come to update this after doing some more research, but this can also be closed and i will open another issue if that is better.

the obvious solution is to wlr-output-management-unstable-v1 which would allow the use of tools like wlr-randr (and i will look into this on my own and submit a pr if i manage to do anything, but i have not done something like that before and it seems like a big task so i do not know if i will be successfull), but i think a solution that could get good results with much less work would be to have the compositor select the output with the highest refresh rate on creation.

taking a look at libswc/output.c @ lines:92-100, we can see that the preferred output mode is set to the last preferred mode found (lines 95 and 96), and if none are preferred we use the first one found.

this could be changed to select the mode with the highest refresh that still has preferred == true, and if no preferred modes are found, we take the one with the highest refresh. this could all be implemented by simply sorting the array (perhaps with the std qsort function to keep the code short and simple?)

i did try this solution on my local machine, but the compositor (i just used example/wm to test) wasn't even able to find/load my drivers, and never started (definitely a mistake on my part), so i figured i would suggest it here, as i am still unfamiliar with the codebase and someone else may take a look and have an idea.

thanks :)