From patchwork Sun Oct 23 18:47:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 9391167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6E4BB60231 for ; Sun, 23 Oct 2016 18:48:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60DE828B38 for ; Sun, 23 Oct 2016 18:48:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 555D728B40; Sun, 23 Oct 2016 18:48:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B4B1228B38 for ; Sun, 23 Oct 2016 18:48:07 +0000 (UTC) Received: from localhost ([::1]:42042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byNoV-0007AO-0J for patchwork-qemu-devel@patchwork.kernel.org; Sun, 23 Oct 2016 14:48:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byNnq-00076Z-H0 for qemu-devel@nongnu.org; Sun, 23 Oct 2016 14:47:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byNnn-00011I-Dq for qemu-devel@nongnu.org; Sun, 23 Oct 2016 14:47:26 -0400 Received: from hera.aquilenet.fr ([141.255.128.1]:56484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byNnn-00010z-4A for qemu-devel@nongnu.org; Sun, 23 Oct 2016 14:47:23 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 6AFA48E5D; Sun, 23 Oct 2016 20:47:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id myMDYCz3V6PQ; Sun, 23 Oct 2016 20:47:21 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B84F09779; Sun, 23 Oct 2016 20:47:20 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1byNnj-0001Xp-J1; Sun, 23 Oct 2016 20:47:19 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org Date: Sun, 23 Oct 2016 20:47:18 +0200 Message-Id: <20161023184718.5892-4-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161023184718.5892-1-samuel.thibault@ens-lyon.org> References: <20161023184718.5892-1-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 141.255.128.1 Subject: [Qemu-devel] [PATCH 3/3] Move getting XWindow ID from baum driver to graphical backend 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: Samuel Thibault , Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds two console functions, qemu_console_set_window_id and qemu_graphic_console_get_window_id, to let graphical backend record the window id in the QemuConsole structure, and let the baum driver read it. We can then move the SDL code from the baum driver to the sdl ui code, and add SDL2 and Gtk versions of the code. Signed-off-by: Samuel Thibault --- backends/baum.c | 20 +++----------------- include/ui/console.h | 3 +++ ui/console.c | 18 ++++++++++++++++++ ui/gtk.c | 15 +++++++++++++-- ui/sdl.c | 16 ++++++++++++++++ ui/sdl2.c | 7 +++++++ 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/backends/baum.c b/backends/baum.c index 2905404..53d1521 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -27,12 +27,10 @@ #include "sysemu/char.h" #include "qemu/timer.h" #include "hw/usb.h" +#include "ui/console.h" #include #include #include -#ifdef CONFIG_SDL -#include -#endif #if 0 #define DPRINTF(fmt, ...) \ @@ -227,11 +225,6 @@ static const uint8_t nabcc_translation[2][256] = { /* The guest OS has started discussing with us, finish initializing BrlAPI */ static int baum_deferred_init(BaumDriverState *baum) { -#if defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - SDL_SysWMinfo info; -#endif -#endif int tty; if (baum->deferred_init) { @@ -243,15 +236,8 @@ static int baum_deferred_init(BaumDriverState *baum) return 0; } -#if defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - memset(&info, 0, sizeof(info)); - SDL_VERSION(&info.version); - if (SDL_GetWMInfo(&info)) - tty = info.info.x11.wmwindow; - else -#endif -#endif + tty = qemu_graphic_console_get_window_id(); + if (tty == -1) tty = BRLAPI_TTY_DEFAULT; if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) { diff --git a/include/ui/console.h b/include/ui/console.h index e2589e2..cf07e41 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -394,6 +394,9 @@ uint32_t qemu_console_get_head(QemuConsole *con); QemuUIInfo *qemu_console_get_ui_info(QemuConsole *con); int qemu_console_get_width(QemuConsole *con, int fallback); int qemu_console_get_height(QemuConsole *con, int fallback); +/* Return the low-level window id for the first graphical console */ +int qemu_graphic_console_get_window_id(void); +void qemu_console_set_window_id(int index, int window_id); void console_select(unsigned int index); void qemu_console_resize(QemuConsole *con, int width, int height); diff --git a/ui/console.c b/ui/console.c index fa3e658..2d0d57c 100644 --- a/ui/console.c +++ b/ui/console.c @@ -124,6 +124,7 @@ struct QemuConsole { int dcls; DisplayChangeListener *gl; bool gl_block; + int window_id; /* Graphic console state. */ Object *device; @@ -273,6 +274,23 @@ void graphic_hw_gl_block(QemuConsole *con, bool block) } } +int qemu_graphic_console_get_window_id(void) +{ + int i; + for (i = 0; i < nb_consoles; i++) { + if (consoles[i]->console_type == GRAPHIC_CONSOLE) { + return consoles[i]->window_id; + } + } + return -1; +} + +void qemu_console_set_window_id(int index, int window_id) +{ + assert(index < nb_consoles); + consoles[index]->window_id = window_id; +} + void graphic_hw_invalidate(QemuConsole *con) { if (!con) { diff --git a/ui/gtk.c b/ui/gtk.c index 58d20ee..c33a93e 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -2155,6 +2155,8 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) GtkDisplayState *s = g_malloc0(sizeof(*s)); char *filename; GdkDisplay *window_display; + int i; + Window window_id; if (!gtkinit) { fprintf(stderr, "gtk initialization failed\n"); @@ -2217,8 +2219,6 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) { VirtualConsole *cur = gd_vc_find_current(s); if (cur) { - int i; - for (i = 0; i < s->nb_vcs; i++) { VirtualConsole *vc = &s->vc[i]; if (vc && vc->type == GD_VC_VTE && vc != cur) { @@ -2238,6 +2238,17 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) } gd_set_keycode_type(s); + + window_id = GDK_WINDOW_XID(gtk_widget_get_window(s->window)); + for (i = 0; ; i++) { + /* All consoles share the same window */ + QemuConsole *con = qemu_console_lookup_by_index(i); + if (con) { + qemu_console_set_window_id(i, (int) window_id); + } else { + break; + } + } } void early_gtk_display_init(int opengl) diff --git a/ui/sdl.c b/ui/sdl.c index d8cf5bc..8e0c417 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -947,6 +947,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) int flags; uint8_t data = 0; const SDL_VideoInfo *vi; + SDL_SysWMinfo info; char *filename; #if defined(__APPLE__) @@ -1023,5 +1024,20 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0); sdl_cursor_normal = SDL_GetCursor(); + memset(&info, 0, sizeof(info)); + SDL_VERSION(&info.version); + if (SDL_GetWMInfo(&info)) { + int i; + for (i = 0; ; i++) { + /* All consoles share the same window */ + QemuConsole *con = qemu_console_lookup_by_index(i); + if (con) { + qemu_console_set_window_id(i, info.info.x11.wmwindow); + } else { + break; + } + } + } + atexit(sdl_cleanup); } diff --git a/ui/sdl2.c b/ui/sdl2.c index 30d2a3c..b464f16 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -761,6 +761,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) uint8_t data = 0; char *filename; int i; + SDL_SysWMinfo info; if (no_frame) { gui_noframe = 1; @@ -786,6 +787,8 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) exit(1); } SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1"); + memset(&info, 0, sizeof(info)); + SDL_VERSION(&info.version); for (i = 0;; i++) { QemuConsole *con = qemu_console_lookup_by_index(i); @@ -813,6 +816,10 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame) #endif sdl2_console[i].dcl.con = con; register_displaychangelistener(&sdl2_console[i].dcl); + + if (SDL_GetWindowWMInfo(sdl2_console[i].real_window, &info)) { + qemu_console_set_window_id(i, info.info.x11.window); + } } /* Load a 32x32x4 image. White pixels are transparent. */