From nobody Fri Oct 24 22:15:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519135033233978.0722076808039; Tue, 20 Feb 2018 05:57:13 -0800 (PST) Received: from localhost ([::1]:55673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eo8Pv-00043l-TK for importer@patchew.org; Tue, 20 Feb 2018 08:57:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eo8Gn-0005Jh-8r for qemu-devel@nongnu.org; Tue, 20 Feb 2018 08:47:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eo8Gi-00072d-LS for qemu-devel@nongnu.org; Tue, 20 Feb 2018 08:47:45 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33824 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eo8Gi-00071p-F3 for qemu-devel@nongnu.org; Tue, 20 Feb 2018 08:47:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2723AEB705 for ; Tue, 20 Feb 2018 13:47:29 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E01A2166BB6; Tue, 20 Feb 2018 13:47:24 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CA7751751D; Tue, 20 Feb 2018 14:47:23 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 20 Feb 2018 14:47:14 +0100 Message-Id: <20180220134723.11776-4-kraxel@redhat.com> In-Reply-To: <20180220134723.11776-1-kraxel@redhat.com> References: <20180220134723.11776-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 20 Feb 2018 13:47:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 20 Feb 2018 13:47:30 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/12] gtk: add and use DisplayOptions + DisplayGTK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Gerd Hoffmann , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add QAPI DisplayType enum, DisplayOptions union and DisplayGTK struct. Switch gtk configuration to use the qapi type. Some bookkeeping (fullscreen for example) is done twice now, this is temporary until more/all UIs are switched over to qapi configuration. Signed-off-by: Gerd Hoffmann Reviewed-by: Eric Blake Message-id: 20180202111022.19269-5-kraxel@redhat.com Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 9 ++++---- ui/gtk.c | 32 ++++++++++++++++------------- vl.c | 23 ++++++++++++++++----- qapi/ui.json | 58 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 98 insertions(+), 24 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 12fef80923..82cb000e3b 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -486,18 +486,17 @@ int index_from_key(const char *key, size_t key_length= ); =20 /* gtk.c */ #ifdef CONFIG_GTK -void early_gtk_display_init(int opengl); -void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hov= er); +void early_gtk_display_init(DisplayOptions *opts); +void gtk_display_init(DisplayState *ds, DisplayOptions *opts); #else -static inline void gtk_display_init(DisplayState *ds, bool full_screen, - bool grab_on_hover) +static inline void gtk_display_init(DisplayState *ds, DisplayOptions *opts) { /* This must never be called if CONFIG_GTK is disabled */ error_report("GTK support is disabled"); abort(); } =20 -static inline void early_gtk_display_init(int opengl) +static inline void early_gtk_display_init(DisplayOptions *opts) { /* This must never be called if CONFIG_GTK is disabled */ error_report("GTK support is disabled"); diff --git a/ui/gtk.c b/ui/gtk.c index 1537751afa..ad4910c70d 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -230,6 +230,8 @@ struct GtkDisplayState { =20 bool modifier_pressed[ARRAY_SIZE(modifier_keycode)]; bool ignore_keys; + + DisplayOptions *opts; }; =20 typedef struct VCChardev { @@ -778,9 +780,14 @@ static gboolean gd_window_close(GtkWidget *widget, Gdk= Event *event, void *opaque) { GtkDisplayState *s =3D opaque; + bool allow_close =3D true; int i; =20 - if (!no_quit) { + if (s->opts->has_window_close && !s->opts->window_close) { + allow_close =3D false; + } + + if (allow_close) { for (i =3D 0; i < s->nb_vcs; i++) { if (s->vc[i].type !=3D GD_VC_GFX) { continue; @@ -2290,7 +2297,7 @@ static void gd_create_menus(GtkDisplayState *s) =20 static gboolean gtkinit; =20 -void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hov= er) +void gtk_display_init(DisplayState *ds, DisplayOptions *opts) { VirtualConsole *vc; =20 @@ -2302,6 +2309,8 @@ void gtk_display_init(DisplayState *ds, bool full_scr= een, bool grab_on_hover) fprintf(stderr, "gtk initialization failed\n"); exit(1); } + assert(opts->type =3D=3D DISPLAY_TYPE_GTK); + s->opts =3D opts; =20 #if !GTK_CHECK_VERSION(3, 0, 0) g_printerr("Running QEMU with GTK 2.x is deprecated, and will be remov= ed\n" @@ -2388,15 +2397,17 @@ void gtk_display_init(DisplayState *ds, bool full_s= creen, bool grab_on_hover) vc && vc->type =3D=3D GD_VC_VTE); #endif =20 - if (full_screen) { + if (opts->has_full_screen && + opts->full_screen) { gtk_menu_item_activate(GTK_MENU_ITEM(s->full_screen_item)); } - if (grab_on_hover) { + if (opts->u.gtk.has_grab_on_hover && + opts->u.gtk.grab_on_hover) { gtk_menu_item_activate(GTK_MENU_ITEM(s->grab_on_hover_item)); } } =20 -void early_gtk_display_init(int opengl) +void early_gtk_display_init(DisplayOptions *opts) { /* The QEMU code relies on the assumption that it's always run in * the C locale. Therefore it is not prepared to deal with @@ -2422,11 +2433,8 @@ void early_gtk_display_init(int opengl) return; } =20 - switch (opengl) { - case -1: /* default */ - case 0: /* off */ - break; - case 1: /* on */ + assert(opts->type =3D=3D DISPLAY_TYPE_GTK); + if (opts->has_gl && opts->gl) { #if defined(CONFIG_OPENGL) #if defined(CONFIG_GTK_GL) gtk_gl_area_init(); @@ -2434,10 +2442,6 @@ void early_gtk_display_init(int opengl) gtk_egl_init(); #endif #endif - break; - default: - g_assert_not_reached(); - break; } =20 keycode_map =3D gd_get_keymap(&keycode_maplen); diff --git a/vl.c b/vl.c index 746e2c169c..a82b7cf16f 100644 --- a/vl.c +++ b/vl.c @@ -151,9 +151,9 @@ static int rtc_date_offset =3D -1; /* -1 means no chang= e */ QEMUClockType rtc_clock; int vga_interface_type =3D VGA_NONE; static int full_screen =3D 0; +static DisplayOptions dpy; int no_frame; int no_quit =3D 0; -static bool grab_on_hover; Chardev *serial_hds[MAX_SERIAL_PORTS]; Chardev *parallel_hds[MAX_PARALLEL_PORTS]; Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES]; @@ -2188,24 +2188,29 @@ static LegacyDisplayType select_display(const char = *p) } else if (strstart(p, "gtk", &opts)) { #ifdef CONFIG_GTK display =3D DT_GTK; + dpy.type =3D DISPLAY_TYPE_GTK; while (*opts) { const char *nextopt; =20 if (strstart(opts, ",grab_on_hover=3D", &nextopt)) { opts =3D nextopt; + dpy.u.gtk.has_grab_on_hover =3D true; if (strstart(opts, "on", &nextopt)) { - grab_on_hover =3D true; + dpy.u.gtk.grab_on_hover =3D true; } else if (strstart(opts, "off", &nextopt)) { - grab_on_hover =3D false; + dpy.u.gtk.grab_on_hover =3D false; } else { goto invalid_gtk_args; } } else if (strstart(opts, ",gl=3D", &nextopt)) { opts =3D nextopt; + dpy.has_gl =3D true; if (strstart(opts, "on", &nextopt)) { request_opengl =3D 1; + dpy.gl =3D true; } else if (strstart(opts, "off", &nextopt)) { request_opengl =3D 0; + dpy.gl =3D false; } else { goto invalid_gtk_args; } @@ -2222,6 +2227,7 @@ static LegacyDisplayType select_display(const char *p) #endif } else if (strstart(p, "none", &opts)) { display =3D DT_NONE; + dpy.type =3D DISPLAY_TYPE_NONE; } else { error_report("unknown display type"); exit(1); @@ -3252,6 +3258,7 @@ int main(int argc, char **argv, char **envp) qemu_opts_parse_noisily(olist, "graphics=3Doff", false); nographic =3D true; display_type =3D DT_NONE; + dpy.type =3D DISPLAY_TYPE_NONE; break; case QEMU_OPTION_curses: #ifdef CONFIG_CURSES @@ -3639,6 +3646,8 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_full_screen: full_screen =3D 1; + dpy.has_full_screen =3D true; + dpy.full_screen =3D true; break; case QEMU_OPTION_no_frame: g_printerr("The -no-frame switch is deprecated, and will b= e\n" @@ -3653,6 +3662,8 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_no_quit: no_quit =3D 1; + dpy.has_window_close =3D true; + dpy.window_close =3D false; break; case QEMU_OPTION_sdl: #ifdef CONFIG_SDL @@ -4320,6 +4331,7 @@ int main(int argc, char **argv, char **envp) if (display_type =3D=3D DT_DEFAULT && !display_remote) { #if defined(CONFIG_GTK) display_type =3D DT_GTK; + dpy.type =3D DISPLAY_TYPE_GTK; #elif defined(CONFIG_SDL) display_type =3D DT_SDL; #elif defined(CONFIG_COCOA) @@ -4328,6 +4340,7 @@ int main(int argc, char **argv, char **envp) vnc_parse("localhost:0,to=3D99,id=3Ddefault", &error_abort); #else display_type =3D DT_NONE; + dpy.type =3D DISPLAY_TYPE_NONE; #endif } =20 @@ -4341,7 +4354,7 @@ int main(int argc, char **argv, char **envp) } =20 if (display_type =3D=3D DT_GTK) { - early_gtk_display_init(request_opengl); + early_gtk_display_init(&dpy); } =20 if (display_type =3D=3D DT_SDL) { @@ -4686,7 +4699,7 @@ int main(int argc, char **argv, char **envp) cocoa_display_init(ds, full_screen); break; case DT_GTK: - gtk_display_init(ds, full_screen, grab_on_hover); + gtk_display_init(ds, &dpy); break; default: break; diff --git a/qapi/ui.json b/qapi/ui.json index d6679aa8f5..878a3bd2a6 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -985,3 +985,61 @@ 'data': { '*device': 'str', '*head' : 'int', 'events' : [ 'InputEvent' ] } } + + +## +# @DisplayNoOpts: +# +# Empty struct for displays without config options. +# +# Since: 2.12 +# +## +{ 'struct' : 'DisplayNoOpts', + 'data' : { } } + +## +# @DisplayGTK: +# +# GTK display options. +# +# @grab-on-hover: Grab keyboard input on mouse hover. +# +# Since: 2.12 +# +## +{ 'struct' : 'DisplayGTK', + 'data' : { '*grab-on-hover' : 'bool' } } + +## +# @DisplayType: +# +# Display (user interface) type. +# +# Since: 2.12 +# +## +{ 'enum' : 'DisplayType', + 'data' : [ 'none', 'gtk' ] } + +## +# @DisplayOptions: +# +# Display (user interface) options. +# +# @type: Which DisplayType qemu should use. +# @full-screen: Start user interface in fullscreen mode (default: off). +# @window-close: Allow to quit qemu with window close button (default: on= ). +# @gl: Enable OpenGL support (default: off). +# +# Since: 2.12 +# +## +{ 'union' : 'DisplayOptions', + 'base' : { 'type' : 'DisplayType', + '*full-screen' : 'bool', + '*window-close' : 'bool', + '*gl' : 'bool' }, + 'discriminator' : 'type', + 'data' : { 'none' : 'DisplayNoOpts', + 'gtk' : 'DisplayGTK' } } --=20 2.9.3