Skip to content

Commit

Permalink
ui/gtk: Get display refresh rate with GDK version 3.22 or later
Browse files Browse the repository at this point in the history
Commit c4c0092 introduced the use of the GdkMonitor API, which
was introduced in GTK+ 3.22:
https://developer.gnome.org/gdk3/stable/api-index-3-22.html#api-index-3.22

Unfortunately this break building with older versions, as on Ubuntu
Xenial which provides GTK+ 3.18:

  $ lsb_release -cd
  Description:    Ubuntu 16.04.5 LTS
  Codename:       xenial

  $ ./configure && make
  GTK support       yes (3.18.9)
  GTK GL support    no
  [...]
    CC      ui/gtk.o
  qemu/ui/gtk.c: In function ‘gd_vc_gfx_init’:
  qemu/ui/gtk.c:1973:5: error: unknown type name ‘GdkMonitor’
       GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
       ^
  qemu/ui/gtk.c:1973:27: error: implicit declaration of function ‘gdk_display_get_monitor_at_window’ [-Werror=implicit-function-declaration]
       GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
                             ^
  qemu/ui/gtk.c:1973:5: error: nested extern declaration of ‘gdk_display_get_monitor_at_window’ [-Werror=nested-externs]
       GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
       ^
  qemu/ui/gtk.c:1973:27: error: initialization makes pointer from integer without a cast [-Werror=int-conversion]
       GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win);
                             ^
  qemu/ui/gtk.c:2035:28: error: implicit declaration of function ‘gdk_monitor_get_refresh_rate’ [-Werror=implicit-function-declaration]
       refresh_rate_millihz = gdk_monitor_get_refresh_rate(monitor);
                              ^
  qemu/ui/gtk.c:2035:5: error: nested extern declaration of ‘gdk_monitor_get_refresh_rate’ [-Werror=nested-externs]
       refresh_rate_millihz = gdk_monitor_get_refresh_rate(monitor);
       ^
  cc1: all warnings being treated as errors
  qemu/rules.mak:69: recipe for target 'ui/gtk.o' failed
  make: *** [ui/gtk.o] Error 1

GTK+ provides convenient definition in <gdk/gdkversionmacros.h>
(already include by <gdk/gdk.h>) to check which API are available.

We only use the GdkMonitor API to get the monitor refresh rate.

Extract this code as a new gd_refresh_rate_millihz() function,
and check GDK_VERSION_3_22 is defined before calling its API.
If it is not defined, return 0. This is safe and fixes our build
failure (see https://travis-ci.org/qemu/qemu/builds/636992508).

Reported-by: Travis-CI
Reviewed-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Message-id: [email protected]
Fixes: c4c0092 (display/gtk: get proper refreshrate)
Reviewed-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
philmd authored and pm215 committed Jan 16, 2020
1 parent e021e6f commit 28b58f1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions ui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1961,17 +1961,30 @@ 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)
{
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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 28b58f1

Please sign in to comment.