* [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later
@ 2020-01-16 1:12 Philippe Mathieu-Daudé
2020-01-16 8:13 ` Gerd Hoffmann
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-16 1:12 UTC (permalink / raw)
To: Peter Maydell, Gerd Hoffmann, qemu-devel, Daniel P . Berrangé
Cc: Marc-André Lureau, Philippe Mathieu-Daudé, Nikola Pavlica
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 <gdk/gdkversionmacros.h>
(already include by <gdk/gdk.h>) 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é <philmd@redhat.com>
---
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;
}
--
2.21.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later
2020-01-16 1:12 [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later Philippe Mathieu-Daudé
@ 2020-01-16 8:13 ` Gerd Hoffmann
2020-01-16 10:16 ` Daniel P. Berrangé
2020-02-08 10:54 ` Jan Kiszka
2 siblings, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2020-01-16 8:13 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Peter Maydell, Daniel P . Berrangé,
qemu-devel, Marc-André Lureau, Nikola Pavlica
Hi,
> Fixes: c4c00922cc (display/gtk: get proper refreshrate)
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> 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
Even RHEL-7 has a gtk version new enough for that, so my build tests
didn't catch it either ...
> If Gerd acks this patch, we might consider having it directly
> applied as a build fix.
Fine with me.
cheers,
Gerd
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later
2020-01-16 1:12 [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later Philippe Mathieu-Daudé
2020-01-16 8:13 ` Gerd Hoffmann
@ 2020-01-16 10:16 ` Daniel P. Berrangé
2020-01-16 10:20 ` Philippe Mathieu-Daudé
2020-02-08 10:54 ` Jan Kiszka
2 siblings, 1 reply; 5+ messages in thread
From: Daniel P. Berrangé @ 2020-01-16 10:16 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Peter Maydell, Nikola Pavlica, Gerd Hoffmann,
Marc-André Lureau, qemu-devel
On Thu, Jan 16, 2020 at 02:12:17AM +0100, Philippe Mathieu-Daudé wrote:
> 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:
Presumably the problem here is Ubuntu Xenial 16.04 which
only has 3.18.9 ?
We should put in a sanity check for this against our min version
#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_14
#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_14
into glib-compat.h
For that matter we can update our min version to 3.18 I believe
since that looks like the oldest version any supported build
platform has.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later
2020-01-16 10:16 ` Daniel P. Berrangé
@ 2020-01-16 10:20 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-16 10:20 UTC (permalink / raw)
To: Daniel P. Berrangé
Cc: Peter Maydell, Nikola Pavlica, Gerd Hoffmann,
Marc-André Lureau, qemu-devel
On 1/16/20 11:16 AM, Daniel P. Berrangé wrote:
> On Thu, Jan 16, 2020 at 02:12:17AM +0100, Philippe Mathieu-Daudé wrote:
>> 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:
>
> Presumably the problem here is Ubuntu Xenial 16.04 which
> only has 3.18.9 ?
Indeed:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
$ pkg-config --modversion gtk+-3.0
3.18.9
> We should put in a sanity check for this against our min version
>
> #define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_14
> #define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_14
>
> into glib-compat.h
>
> For that matter we can update our min version to 3.18 I believe
> since that looks like the oldest version any supported build
> platform has.
>
> Regards,
> Daniel
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later
2020-01-16 1:12 [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later Philippe Mathieu-Daudé
2020-01-16 8:13 ` Gerd Hoffmann
2020-01-16 10:16 ` Daniel P. Berrangé
@ 2020-02-08 10:54 ` Jan Kiszka
2 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2020-02-08 10:54 UTC (permalink / raw)
To: Philippe Mathieu-Daudé,
Peter Maydell, Gerd Hoffmann, qemu-devel,
Daniel P . Berrangé
Cc: Marc-André Lureau, Nikola Pavlica
On 16.01.20 02:12, Philippe Mathieu-Daudé wrote:
> 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 <gdk/gdkversionmacros.h>
> (already include by <gdk/gdk.h>) 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é <philmd@redhat.com>
> ---
> 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;
> }
>
This (as well as c4c00922cc) gives
qemu-system-x86_64: Gdk: gdk_window_get_origin: assertion 'GDK_IS_WINDOW (window)' failed
on startup under gtk 3.22.30 (mate 1.20.1).
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-02-08 10:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 1:12 [PATCH] ui/gtk: Get display refresh rate with GDK version 3.22 or later Philippe Mathieu-Daudé
2020-01-16 8:13 ` Gerd Hoffmann
2020-01-16 10:16 ` Daniel P. Berrangé
2020-01-16 10:20 ` Philippe Mathieu-Daudé
2020-02-08 10:54 ` Jan Kiszka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).