diff --git a/ui/gtk.c b/ui/gtk.c index 7355d34fcffdbf00cb8e09c5b93d3fb86136df28..d18892d1de618c96d5890fe9b1697e29f41dbeef 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1961,6 +1961,23 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayState *s) return machine_menu; } +/* + * If available, return the refresh rate of the display in milli-Hertz, + * else return 0. + */ +static int gd_refresh_rate_millihz(GtkDisplayState *s) +{ +#ifdef GDK_VERSION_3_22 + GdkDisplay *dpy = gtk_widget_get_display(s->window); + GdkWindow *win = gtk_widget_get_window(s->window); + GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); + + return gdk_monitor_get_refresh_rate(monitor); +#else + return 0; +#endif +} + static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, QemuConsole *con, int idx, GSList *group, GtkWidget *view_menu) @@ -1968,10 +1985,6 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, bool zoom_to_fit = false; int refresh_rate_millihz; - GdkDisplay *dpy = gtk_widget_get_display(s->window); - GdkWindow *win = gtk_widget_get_window(s->window); - GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); - vc->label = qemu_console_get_label(con); vc->s = s; vc->gfx.scale_x = 1.0; @@ -2032,7 +2045,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, vc->gfx.kbd = qkbd_state_init(con); vc->gfx.dcl.con = con; - refresh_rate_millihz = gdk_monitor_get_refresh_rate(monitor); + refresh_rate_millihz = gd_refresh_rate_millihz(s); if (refresh_rate_millihz) { vc->gfx.dcl.update_interval = MILLISEC_PER_SEC / refresh_rate_millihz; }