From nobody Mon Apr 29 09:08:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579137215; cv=none; d=zohomail.com; s=zohoarc; b=fezOIWY9NRn6w/Y+74zl/VC533VwXpmkgiTqiEjf51OfoquIpbH/gwhn/bk7RqPb8NOmIn81PpN6OKeFap8YqiFIGsuZwyCsZbHAkrTiHGbZ9fn2AJIw2VTXQ4TXqzCl7lpZfDuFHQ4Q8xePppXNkF5oOu5UObN28Em1UpP/L/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579137215; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=uZf4xXGSrgu0iJ1m2di8r/o8rrTh6BO8CM7Fjof1QBs=; b=ATFTgLtEoI33TCqoZ9ARpe15jWOzJLYwLiDpDpVpbjFMFPopjcKpYQavDqMFSaHKmM+b6Fy2rmDfYOp3aT7uMm2SnciFB9yRguXqeW6uWi7HKe+yXLkBrBm1Zdi/jMdewtr55o/2zVJUPl479+foCsi8Jp2289Tv9vH+N82AI1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579137215067970.8838259958542; Wed, 15 Jan 2020 17:13:35 -0800 (PST) Received: from localhost ([::1]:34824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irtj3-00006F-60 for importer@patchew.org; Wed, 15 Jan 2020 20:13:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36088) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irtiC-00086R-Nk for qemu-devel@nongnu.org; Wed, 15 Jan 2020 20:12:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irti8-00064V-U9 for qemu-devel@nongnu.org; Wed, 15 Jan 2020 20:12:38 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:27946 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irti8-00063Q-NJ for qemu-devel@nongnu.org; Wed, 15 Jan 2020 20:12:36 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-110-DmSoJL1JOlO5PRQOokNapw-1; Wed, 15 Jan 2020 20:12:32 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA7CB100550E; Thu, 16 Jan 2020 01:12:30 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-18.brq.redhat.com [10.40.204.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41F875D9C9; Thu, 16 Jan 2020 01:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579137155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uZf4xXGSrgu0iJ1m2di8r/o8rrTh6BO8CM7Fjof1QBs=; b=YY3bS4glBzMwHC/r6WhnNQaUGfkDLLoiMx7hnMQ4xAt+XwrB9bQoaRlkGseqKNBfE/RKJR E+UJHFaFYb82mkxCbZKYdODJLwuojMoJ82QvznWI5sLb8PHWc4UhJh+dbRTZ2O69hEShAC yWfO+AFQsy0QG0I7EaX7RbIj1aM+C40= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , Gerd Hoffmann , qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later Date: Thu, 16 Jan 2020 02:12:17 +0100 Message-Id: <20200116011217.2144-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: DmSoJL1JOlO5PRQOokNapw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Nikola Pavlica Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The GdkMonitor was introduced in GTK+ 3.22: https://developer.gnome.org/gdk3/stable/api-index-3-22.html#api-index-3.22 If we build with older GTK+, the build fails: CC ui/gtk.o qemu/ui/gtk.c: In function =E2=80=98gd_vc_gfx_init=E2=80=99: qemu/ui/gtk.c:1973:5: error: unknown type name =E2=80=98GdkMonitor=E2=80= =99 GdkMonitor *monitor =3D gdk_display_get_monitor_at_window(dpy, win); ^ qemu/ui/gtk.c:1973:27: error: implicit declaration of function =E2=80=98g= dk_display_get_monitor_at_window=E2=80=99 [-Werror=3Dimplicit-function-decl= aration] GdkMonitor *monitor =3D gdk_display_get_monitor_at_window(dpy, win); ^ qemu/ui/gtk.c:1973:5: error: nested extern declaration of =E2=80=98gdk_di= splay_get_monitor_at_window=E2=80=99 [-Werror=3Dnested-externs] GdkMonitor *monitor =3D gdk_display_get_monitor_at_window(dpy, win); ^ qemu/ui/gtk.c:1973:27: error: initialization makes pointer from integer w= ithout a cast [-Werror=3Dint-conversion] GdkMonitor *monitor =3D gdk_display_get_monitor_at_window(dpy, win); ^ qemu/ui/gtk.c:2035:28: error: implicit declaration of function =E2=80=98g= dk_monitor_get_refresh_rate=E2=80=99 [-Werror=3Dimplicit-function-declarati= on] refresh_rate_millihz =3D gdk_monitor_get_refresh_rate(monitor); ^ qemu/ui/gtk.c:2035:5: error: nested extern declaration of =E2=80=98gdk_mo= nitor_get_refresh_rate=E2=80=99 [-Werror=3Dnested-externs] refresh_rate_millihz =3D 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 We only use the GdkMonitor API to get the monitor refresh rate. GTK+ provides convenient definition in (already include by ) to check which API are available. 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. Fixes: c4c00922cc (display/gtk: get proper refreshrate) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Gerd Hoffmann --- Sorry I missed that, I only tested Nikola's patch on my workstation which runs Fedora 30: $ pkg-config --modversion gtk+-3.0 3.24.11 If Gerd acks this patch, we might consider having it directly applied as a build fix. --- ui/gtk.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 7355d34fcf..d18892d1de 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1961,6 +1961,23 @@ static GtkWidget *gd_create_menu_machine(GtkDisplayS= tate *s) return machine_menu; } =20 +/* + * 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 =3D gtk_widget_get_display(s->window); + GdkWindow *win =3D gtk_widget_get_window(s->window); + GdkMonitor *monitor =3D 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, Vi= rtualConsole *vc, bool zoom_to_fit =3D false; int refresh_rate_millihz; =20 - GdkDisplay *dpy =3D gtk_widget_get_display(s->window); - GdkWindow *win =3D gtk_widget_get_window(s->window); - GdkMonitor *monitor =3D gdk_display_get_monitor_at_window(dpy, win); - vc->label =3D qemu_console_get_label(con); vc->s =3D s; vc->gfx.scale_x =3D 1.0; @@ -2032,7 +2045,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vir= tualConsole *vc, vc->gfx.kbd =3D qkbd_state_init(con); vc->gfx.dcl.con =3D con; =20 - refresh_rate_millihz =3D gdk_monitor_get_refresh_rate(monitor); + refresh_rate_millihz =3D gd_refresh_rate_millihz(s); if (refresh_rate_millihz) { vc->gfx.dcl.update_interval =3D MILLISEC_PER_SEC / refresh_rate_mi= llihz; } --=20 2.21.1