From patchwork Thu Jan 16 01:12:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11335777 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3BF5B13B4 for ; Thu, 16 Jan 2020 01:13:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD569222C3 for ; Thu, 16 Jan 2020 01:13:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YY3bS4gl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD569222C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irtit-00006F-J6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 15 Jan 2020 20:13:23 -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 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= 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Peter Maydell , Gerd Hoffmann , qemu-devel@nongnu.org, =?utf-8?q?Daniel_?= =?utf-8?q?P_=2E_Berrang=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 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_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Nikola Pavlica Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 ‘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 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é 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(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; }