Move getting XWindow ID from baum driver to graphical backend
v3 cover Move getting XWindow ID from baum driver to graphical backend
Hello,
This is a respin of moving getting XWindow ID from baum to actual graphical backends. This only contains the new API, the move of existing code to the new API, and the addition of support for SDL2. Gtk will need more discussion and work.
Compared to v2, this fixes build on 64bit windows, where the window handle needs to be explictly truncated to 32bit (such handles are guaranteed to be 32bit)
Samuel
Samuel Thibault (4):
console: add API to get underlying gui window ID
console: move window ID code from baum to sdl
sdl2: set window ID
gtk: set window ID
backends/baum.c | 25 +++---------------------- include/ui/console.h | 3 +++ ui/console.c | 15 +++++++++++++++ ui/gtk.c | 25 +++++++++++++++++++++++-- ui/sdl.c | 25 +++++++++++++++++++++++++ ui/sdl2.c | 7 +++++++ 6 files changed, 76 insertions(+), 24 deletions(-)
Signature · 1 line
2.10.1
PATCH v3 1/4 console: add API to get underlying gui window ID
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.
--- include/ui/console.h | 3 +++ ui/console.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+)
include/ui/console.h +3 -0
@@ -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);
ui/console.c +15 -0
@@ -124,6 +124,7 @@ struct QemuConsole {int dcls;DisplayChangeListener *gl;bool gl_block; +int window_id;/* Graphic console state. */ Object *device;
@@ -273,6 +274,20 @@ void graphic_hw_gl_block(QemuConsole *con, bool block) } } +int qemu_graphic_console_get_window_id (void ) +{ +if (consoles[0 ]->console_type ==GRAPHIC_CONSOLE ) { +return consoles[0 ]->window_id; + } +return -1 ; +} + +void qemu_console_set_window_id (int index,int window_id) +{ +assert (index >=0 && index < nb_consoles); + consoles[index]->window_id = window_id; +} +void graphic_hw_invalidate (QemuConsole *con) {if (!con) {
Signature · 1 line
2.10.1
Re: [Qemu-devel] [PATCH 1/4] console: add API to get underlying gui window ID
include/ui/console.h uint32_t qemu_console_get_head(QemuConsole *con); · line 399
Quoted 5 lines
int
qemu_console_get_width(QemuConsole *con, int fallback); intqemu_console_get_height(QemuConsole *con, int fallback);include/ui/console.h +3
-0+/* 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);
Both qemu_console_{set,get}_window_id should have a QemuConsole *con argument, like the other ones.
There is also no reason to limit this interface to graphic consoles. baum.c can use qemu_console_lookup_by_index() and qemu_console_is_graphic() to implement this logic (sorry, missed this on the first review).
cheers,
Gerd
PATCH v3 2/4 console: move window ID code from baum to sdl
In reply to Samuel ThibaultThis moves the SDL bits for window ID from the baum driver to SDL, as well as fixing the build for non-X11.
--- backends/baum.c | 25 +++---------------------- ui/sdl.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-)
backends/baum.c +3 -22
@@ -27,12 +27,10 @@#include "sysemu/char.h" #include "qemu/timer.h" #include "hw/usb.h" +#include "ui/console.h" #include <brlapi.h> #include <brlapi_constants.h> #include <brlapi_keycodes.h> -#ifdef CONFIG_SDL -#include <SDL_syswm.h> -#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,21 +236,9 @@ 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 defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - } -#endif -#endifif (brlapi__enterTtyMode (baum->brlapi, tty,NULL ) ==-1 ) {brlapi_perror ("baum: brlapi__enterTtyMode" );
ui/sdl.c +25 -0
@@ -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,29 @@ 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) { +#if defined(SDL_VIDEO_DRIVER_X11 ) +qemu_console_set_window_id (i, info.info.x11.wmwindow); +#elif defined(SDL_VIDEO_DRIVER_NANOX ) || \ + defined(SDL_VIDEO_DRIVER_WINDIB ) || defined(SDL_VIDEO_DRIVER_DDRAW ) || \ + defined(SDL_VIDEO_DRIVER_GAPI ) || \ + defined(SDL_VIDEO_DRIVER_RISCOS ) +qemu_console_set_window_id (i, (int ) (uintptr_t ) info.window); +#else +qemu_console_set_window_id (i, info.data); +#endif + }else { +break ; + } + } + } +atexit (sdl_cleanup); }
Signature · 1 line
2.10.1
PATCH v3 3/4 sdl2: set window ID
In reply to Samuel ThibaultThis uses the console API to record the window ID of the SDL2 windows.
--- ui/sdl2.c | 7 +++++++ 1 file changed, 7 insertions(+)
ui/sdl2.c +7 -0
@@ -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. */
Signature · 1 line
2.10.1
PATCH v3 4/4 gtk: set window ID
In reply to Samuel ThibaultThis uses the console API to record the window ID of the GTK windows.
--- ui/gtk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
ui/gtk.c +23 -2
@@ -2170,6 +2170,13 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)GtkDisplayState *s =g_malloc0 (sizeof (*s));char *filename;GdkDisplay *window_display; +GdkWindow *gdk_window; +#ifdef GDK_WINDOWING_X11 +Window window_id; +#elif defined(GDK_WINDOWING_WIN32 ) +HWND window_id; +#endif +int i;if (!gtkinit) {fprintf (stderr,"gtk initialization failed\n" );
@@ -2232,8 +2239,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) {
@@ -2253,6 +2258,22 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) }gd_set_keycode_type (s); + + gdk_window =gtk_widget_get_window (s->window); +#ifdef GDK_WINDOWING_X11 + window_id =GDK_WINDOW_XID (gdk_window); +#elif defined(GDK_WINDOWING_WIN32 ) + window_id =gdk_win32_window_get_impl_hwnd (gdk_window); +#endif +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)
Signature · 1 line
2.10.1
Re: [Qemu-devel] [PATCH 4/4] gtk: set window ID
Quoted 1 line · Samuel Thibault, on Mon 31 Oct 2016 17:00:07 +0100, wrote:
This uses the console API to record the window ID of the GTK windows.
Ah, sorry, I let this one through, please ignore it, it'll need rework as discussed in the other thread.
Samuel
Re: [Qemu-devel] [PATCH 4/4] gtk: set window ID
In reply to Samuel ThibaultQuoted 35 lines · Samuel Thibault
This uses the console API to record the window ID of the GTK windows.
Signed-off-by Samuel Thibault <[email protected]>--- ui/gtk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)ui/gtk.c +7
-2@@ -2170,6 +2170,13 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)GtkDisplayState *s =g_malloc0 (sizeof (*s));char *filename;GdkDisplay *window_display; +GdkWindow *gdk_window; +#ifdef GDK_WINDOWING_X11 +Window window_id; +#elif defined(GDK_WINDOWING_WIN32 ) +HWND window_id; +#endif +int i;if (!gtkinit) {fprintf (stderr,"gtk initialization failed\n" );@@ -2232,8 +2239,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) {
ui/gtk.c void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) · line 2267
Quoted 10 lines
ui/gtk.c +7
-0@@ -2253,6 +2258,22 @@ void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) }gd_set_keycode_type (s); + + gdk_window =gtk_widget_get_window (s->window); +#ifdef GDK_WINDOWING_X11 + window_id =GDK_WINDOW_XID (gdk_window); +#elif defined(GDK_WINDOWING_WIN32 ) + window_id =gdk_win32_window_get_impl_hwnd (gdk_window); +#endif
There are other GTK3 backends that may well be used - Wayland, Broadway and Quartz. You can't use the compile time check on its own any more as a single GTK can be built with multiple backends at once.
So to fully generalize you need
eg you'll need
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY(dpy)) {
...
}
#endif
#ifdef GDK_WINDOWING_WIN32
if (GDK_IS_WIN32_DISPLAY(dpy)) {
...
}
#endif
#ifdef GDK_WINDOWING_QUARTZ
if (GDK_IS_QUARTZ_DISPLAY(dpy)) {
...
}
#endif
...and wayland, broadway...ui/gtk.c void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover) · line 2276
Quoted 9 lines
ui/gtk.c +9
-0+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 ; + } + }
If neither X11 or Win32 backends are defined, this will error since window_id will not be declared.
Regards,
Daniel
Signature · 3 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|