Skip to content

Instantly share code, notes, and snippets.

@n3r0bi0m4n
Created January 13, 2026 13:45
Show Gist options
  • Select an option

  • Save n3r0bi0m4n/c2d802a4992ccadbfe386f120f508e72 to your computer and use it in GitHub Desktop.

Select an option

Save n3r0bi0m4n/c2d802a4992ccadbfe386f120f508e72 to your computer and use it in GitHub Desktop.
wayland refresh rate for each screen
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client.h>
static void nop() {}
typedef struct Output
{
uint32_t id;
int printed;
} Output;
static void output_mode(void *data, struct wl_output *o,
uint32_t flags, int32_t w, int32_t h, int32_t r)
{
(void)o;
(void)w;
(void)h;
if (!(flags & WL_OUTPUT_MODE_CURRENT))
return;
Output *out = data;
if (out->printed)
return;
out->printed = 1;
printf("%u: %.3f\n", out->id, r / 1000.0);
}
static const struct wl_output_listener output_listener = {
.geometry = (void *)nop,
.mode = output_mode,
.done = (void *)nop,
.scale = (void *)nop,
};
static void registry_global(void *data, struct wl_registry *reg,
uint32_t id, const char *iface, uint32_t ver)
{
(void)data;
(void)ver;
if (strcmp(iface, "wl_output"))
return;
struct wl_output *o = wl_registry_bind(reg, id, &wl_output_interface, 2);
Output *out = calloc(1, sizeof *out);
out->id = id;
wl_output_add_listener(o, &output_listener, out);
}
static const struct wl_registry_listener registry_listener = {
.global = registry_global,
.global_remove = (void *)nop,
};
int main(void)
{
struct wl_display *d = wl_display_connect(NULL);
if (!d)
return 1;
struct wl_registry *r = wl_display_get_registry(d);
wl_registry_add_listener(r, &registry_listener, NULL);
wl_display_roundtrip(d);
wl_display_roundtrip(d);
while (wl_display_dispatch(d) != -1)
{
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment