From nobody Sun Feb 8 18:35:20 2026 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 Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510915419562287.962626268844; Fri, 17 Nov 2017 02:43:39 -0800 (PST) Received: from localhost ([::1]:45048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFe7R-0003Bb-7q for importer@patchew.org; Fri, 17 Nov 2017 05:43:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFdvE-0000nw-G0 for qemu-devel@nongnu.org; Fri, 17 Nov 2017 05:30:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFdvB-0007N3-Pi for qemu-devel@nongnu.org; Fri, 17 Nov 2017 05:30:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFdvB-0007L6-DK for qemu-devel@nongnu.org; Fri, 17 Nov 2017 05:30:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91B4FC01A69E for ; Fri, 17 Nov 2017 10:30:52 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-103.ams2.redhat.com [10.36.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 005D25C893; Fri, 17 Nov 2017 10:30:49 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 8DE9D409C3; Fri, 17 Nov 2017 11:30:46 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 17 Nov 2017 11:30:28 +0100 Message-Id: <20171117103046.15943-7-kraxel@redhat.com> In-Reply-To: <20171117103046.15943-1-kraxel@redhat.com> References: <20171117103046.15943-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 17 Nov 2017 10:30:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/24] sdl: use DisplayOptions 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 , Markus Armbruster , Gerd Hoffmann 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" Switch sdl ui to use qapi DisplayOptions for configuration. Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 8 ++++---- ui/sdl.c | 19 +++++++++++++------ ui/sdl2.c | 33 +++++++++++++++++++-------------- vl.c | 13 +++++++++++-- qapi/ui.json | 5 +++-- 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 58d1a3d27c..deee5bb606 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -435,16 +435,16 @@ void surface_gl_setup_viewport(QemuGLShader *gls, =20 /* sdl.c */ #ifdef CONFIG_SDL -void sdl_display_early_init(int opengl); -void sdl_display_init(DisplayState *ds, int full_screen); +void sdl_display_early_init(DisplayOptions *opts); +void sdl_display_init(DisplayState *ds, DisplayOptions *opts); #else -static inline void sdl_display_early_init(int opengl) +static inline void sdl_display_early_init(DisplayOptions *opts) { /* This must never be called if CONFIG_SDL is disabled */ error_report("SDL support is disabled"); abort(); } -static inline void sdl_display_init(DisplayState *ds, int full_screen) +static inline void sdl_display_init(DisplayState *ds, DisplayOptions *opts) { /* This must never be called if CONFIG_SDL is disabled */ error_report("SDL support is disabled"); diff --git a/ui/sdl.c b/ui/sdl.c index 6ce67eeb5a..972592fe42 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -39,6 +39,7 @@ =20 static DisplayChangeListener *dcl; static DisplaySurface *surface; +static DisplayOptions *opts; static SDL_Surface *real_screen; static SDL_Surface *guest_screen =3D NULL; static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ @@ -788,6 +789,7 @@ static void handle_activation(SDL_Event *ev) static void sdl_refresh(DisplayChangeListener *dcl) { SDL_Event ev1, *ev =3D &ev1; + bool allow_close =3D true; int idle =3D 1; =20 if (last_vm_running !=3D runstate_is_running()) { @@ -812,7 +814,10 @@ static void sdl_refresh(DisplayChangeListener *dcl) handle_keyup(ev); break; case SDL_QUIT: - if (!no_quit) { + if (opts->has_window_close && !opts->window_close) { + allow_close =3D false; + } + if (allow_close) { no_shutdown =3D 0; qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI); } @@ -911,9 +916,9 @@ static const DisplayChangeListenerOps dcl_ops =3D { .dpy_cursor_define =3D sdl_mouse_define, }; =20 -void sdl_display_early_init(int opengl) +void sdl_display_early_init(DisplayOptions *opts) { - if (opengl =3D=3D 1 /* on */) { + if (opts->has_gl && opts->gl) { fprintf(stderr, "SDL1 display code has no opengl support.\n" "Please recompile qemu with SDL2, using\n" @@ -921,7 +926,7 @@ void sdl_display_early_init(int opengl) } } =20 -void sdl_display_init(DisplayState *ds, int full_screen) +void sdl_display_init(DisplayState *ds, DisplayOptions *o) { int flags; uint8_t data =3D 0; @@ -929,6 +934,8 @@ void sdl_display_init(DisplayState *ds, int full_screen) SDL_SysWMinfo info; char *filename; =20 + assert(o->type =3D=3D DISPLAY_TYPE_SDL); + opts =3D o; #if defined(__APPLE__) /* always use generic keymaps */ if (!keyboard_layout) @@ -940,7 +947,7 @@ void sdl_display_init(DisplayState *ds, int full_screen) exit(1); } =20 - if (!full_screen) { + if (opts->has_full_screen && opts->full_screen) { setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0); } #ifdef __linux__ @@ -981,7 +988,7 @@ void sdl_display_init(DisplayState *ds, int full_screen) g_free(filename); } =20 - if (full_screen) { + if (opts->has_full_screen && opts->full_screen) { gui_fullscreen =3D 1; sdl_grab_start(); } diff --git a/ui/sdl2.c b/ui/sdl2.c index 105c461b21..34002129e1 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -32,6 +32,7 @@ =20 static int sdl2_num_outputs; static struct sdl2_console *sdl2_console; +static DisplayOptions *opts; =20 static SDL_Surface *guest_sprite_surface; static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ @@ -507,6 +508,7 @@ static void handle_mousewheel(SDL_Event *ev) static void handle_windowevent(SDL_Event *ev) { struct sdl2_console *scon =3D get_scon_from_window(ev->window.windowID= ); + bool allow_close =3D true; =20 if (!scon) { return; @@ -544,7 +546,10 @@ static void handle_windowevent(SDL_Event *ev) update_displaychangelistener(&scon->dcl, 500); break; case SDL_WINDOWEVENT_CLOSE: - if (!no_quit) { + if (opts->has_window_close && !opts->window_close) { + allow_close =3D false; + } + if (allow_close) { no_shutdown =3D 0; qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI); } @@ -565,6 +570,7 @@ static void handle_windowevent(SDL_Event *ev) void sdl2_poll_events(struct sdl2_console *scon) { SDL_Event ev1, *ev =3D &ev1; + bool allow_close =3D true; int idle =3D 1; =20 if (scon->last_vm_running !=3D runstate_is_running()) { @@ -587,7 +593,10 @@ void sdl2_poll_events(struct sdl2_console *scon) handle_textinput(ev); break; case SDL_QUIT: - if (!no_quit) { + if (opts->has_window_close && !opts->window_close) { + allow_close =3D false; + } + if (allow_close) { no_shutdown =3D 0; qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI); } @@ -717,24 +726,17 @@ static const DisplayChangeListenerOps dcl_gl_ops =3D { }; #endif =20 -void sdl_display_early_init(int opengl) +void sdl_display_early_init(DisplayOptions *o) { - switch (opengl) { - case -1: /* default */ - case 0: /* off */ - break; - case 1: /* on */ + assert(o->type =3D=3D DISPLAY_TYPE_SDL); + if (o->has_gl && o->gl) { #ifdef CONFIG_OPENGL display_opengl =3D 1; #endif - break; - default: - g_assert_not_reached(); - break; } } =20 -void sdl_display_init(DisplayState *ds, int full_screen) +void sdl_display_init(DisplayState *ds, DisplayOptions *o) { int flags; uint8_t data =3D 0; @@ -742,6 +744,9 @@ void sdl_display_init(DisplayState *ds, int full_screen) int i; SDL_SysWMinfo info; =20 + assert(o->type =3D=3D DISPLAY_TYPE_SDL); + opts =3D o; + #ifdef __linux__ /* on Linux, SDL may use fbcon|directfb|svgalib when run without * accessible $DISPLAY to open X11 window. This is often the case @@ -816,7 +821,7 @@ void sdl_display_init(DisplayState *ds, int full_screen) g_free(filename); } =20 - if (full_screen) { + if (opts->has_full_screen && opts->full_screen) { gui_fullscreen =3D 1; sdl_grab_start(0); } diff --git a/vl.c b/vl.c index af67c86de0..b34fbf1a09 100644 --- a/vl.c +++ b/vl.c @@ -2157,6 +2157,7 @@ static LegacyDisplayType select_display(const char *p) if (strstart(p, "sdl", &opts)) { #ifdef CONFIG_SDL display =3D DT_SDL; + dpy.type =3D DISPLAY_TYPE_SDL; while (*opts) { const char *nextopt; =20 @@ -2171,19 +2172,25 @@ static LegacyDisplayType select_display(const char = *p) warn_report("alt_grab sdl option is unsupported, ignoring"= ); } else if (strstart(opts, ",window_close=3D", &nextopt)) { opts =3D nextopt; + dpy.has_window_close =3D true; if (strstart(opts, "on", &nextopt)) { no_quit =3D 0; + dpy.window_close =3D true; } else if (strstart(opts, "off", &nextopt)) { no_quit =3D 1; + dpy.window_close =3D false; } else { goto invalid_sdl_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_sdl_args; } @@ -3788,6 +3795,7 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_sdl: #ifdef CONFIG_SDL display_type =3D DT_SDL; + dpy.type =3D DISPLAY_TYPE_SDL; break; #else error_report("SDL support is disabled"); @@ -4455,6 +4463,7 @@ int main(int argc, char **argv, char **envp) dpy.type =3D DISPLAY_TYPE_GTK; #elif defined(CONFIG_SDL) display_type =3D DT_SDL; + dpy.type =3D DISPLAY_TYPE_SDL; #elif defined(CONFIG_COCOA) display_type =3D DT_COCOA; #elif defined(CONFIG_VNC) @@ -4475,7 +4484,7 @@ int main(int argc, char **argv, char **envp) } =20 if (display_type =3D=3D DT_SDL) { - sdl_display_early_init(request_opengl); + sdl_display_early_init(&dpy); } =20 qemu_console_early_init(); @@ -4812,7 +4821,7 @@ int main(int argc, char **argv, char **envp) curses_display_init(ds, full_screen); break; case DT_SDL: - sdl_display_init(ds, full_screen); + sdl_display_init(ds, &dpy); break; case DT_COCOA: cocoa_display_init(ds, full_screen); diff --git a/qapi/ui.json b/qapi/ui.json index dbb745bd53..e7d3e8729b 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1009,7 +1009,7 @@ # ## { 'enum' : 'DisplayType', - 'data' : [ 'default', 'none', 'gtk' ] } + 'data' : [ 'default', 'none', 'gtk', 'sdl' ] } =20 ## # @DisplayOptions: @@ -1025,4 +1025,5 @@ 'discriminator' : 'type', 'data' : { 'default' : 'DisplayNoOpts', 'none' : 'DisplayNoOpts', - 'gtk' : 'DisplayGTK' } } + 'gtk' : 'DisplayGTK', + 'sdl' : 'DisplayNoOpts' } } --=20 2.9.3