qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte
@ 2014-06-03  8:01 Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 1/5] gtk: factor out keycode mapping Gerd Hoffmann
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-03  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

Current gtk patch queue.  A bunch of cleanups and fixes.

Most notable change is patch #5 which winds up qemu text
terminal emulation in gtk, so '-chardev vc' works even
when building without vte (i.e. on windows).

Gerd Hoffmann (5):
  gtk: factor out keycode mapping
  gtk: cleanup backend dependencies
  gtk: factor out gtk3 grab into the new gd_grab_devices function
  gtk: update window size after showing/hiding tabs
  gtk: bind to text terminal consoles too

 configure |   4 +
 ui/gtk.c  | 298 ++++++++++++++++++++++++++++++++++----------------------------
 2 files changed, 170 insertions(+), 132 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/5] gtk: factor out keycode mapping
  2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
@ 2014-06-03  8:01 ` Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 2/5] gtk: cleanup backend dependencies Gerd Hoffmann
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-03  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index b908936..01d48cc 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -877,22 +877,18 @@ static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll,
     return TRUE;
 }
 
-static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
+static int gd_map_keycode(GtkDisplayState *s, int gdk_keycode)
 {
-    VirtualConsole *vc = opaque;
-    GtkDisplayState *s = vc->s;
-    int gdk_keycode = key->hardware_keycode;
-    int i;
+    int qemu_keycode;
 
 #ifdef _WIN32
-    UINT qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
+    qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
     switch (qemu_keycode) {
     case 103:   /* alt gr */
         qemu_keycode = 56 | SCANCODE_GREY;
         break;
     }
 #else
-    int qemu_keycode;
 
     if (gdk_keycode < 9) {
         qemu_keycode = 0;
@@ -913,6 +909,19 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
     }
 #endif
 
+    return qemu_keycode;
+}
+
+static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
+{
+    VirtualConsole *vc = opaque;
+    GtkDisplayState *s = vc->s;
+    int gdk_keycode = key->hardware_keycode;
+    int qemu_keycode;
+    int i;
+
+    qemu_keycode = gd_map_keycode(s, gdk_keycode);
+
     trace_gd_key_event(vc->label, gdk_keycode, qemu_keycode,
                        (key->type == GDK_KEY_PRESS) ? "down" : "up");
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 2/5] gtk: cleanup backend dependencies
  2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 1/5] gtk: factor out keycode mapping Gerd Hoffmann
@ 2014-06-03  8:01 ` Gerd Hoffmann
  2014-06-03 15:17   ` Richard Henderson
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 3/5] gtk: factor out gtk3 grab into the new gd_grab_devices function Gerd Hoffmann
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-03  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori, Richard Henderson

Make configure detect gtk x11 backend and link libX11 then.  Make
gtk backend specific code properly #ifdef'ed on the GTK_WINDOWING_*
backends at runtime).  Our gtk ui code should build and run fine on
any platform now.

This also fixes the linker failute due to the new XkbGetKeyboard call
added by commit 3158a3482b0093e41f2b2596fba50774ea31ae08.

Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
---
 configure |  4 ++++
 ui/gtk.c  | 70 ++++++++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 46 insertions(+), 28 deletions(-)

diff --git a/configure b/configure
index 0e516f9..acfd77a 100755
--- a/configure
+++ b/configure
@@ -1986,6 +1986,7 @@ fi
 
 if test "$gtk" != "no"; then
     gtkpackage="gtk+-$gtkabi"
+    gtkx11package="gtk+-x11-$gtkabi"
     if test "$gtkabi" = "3.0" ; then
       gtkversion="3.0.0"
     else
@@ -1994,6 +1995,9 @@ if test "$gtk" != "no"; then
     if $pkg_config --exists "$gtkpackage >= $gtkversion"; then
         gtk_cflags=`$pkg_config --cflags $gtkpackage`
         gtk_libs=`$pkg_config --libs $gtkpackage`
+        if $pkg_config --exists "$gtkx11package >= $gtkversion"; then
+            gtk_libs="$gtk_libs -lX11"
+        fi
         libs_softmmu="$gtk_libs $libs_softmmu"
         gtk="yes"
     elif test "$gtk" = "yes"; then
diff --git a/ui/gtk.c b/ui/gtk.c
index 01d48cc..d201190 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -68,7 +68,7 @@
 #include "keymaps.h"
 #include "sysemu/char.h"
 #include "qom/object.h"
-#ifndef _WIN32
+#ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
 #include <X11/XKBlib.h>
 #endif
@@ -112,6 +112,13 @@ static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
 #define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget)
 #endif
 
+#ifndef GDK_IS_X11_DISPLAY
+#define GDK_IS_X11_DISPLAY(dpy) (dpy == dpy)
+#endif
+#ifndef GDK_IS_WIN32_DISPLAY
+#define GDK_IS_WIN32_DISPLAY(dpy) (dpy == dpy)
+#endif
+
 #ifndef GDK_KEY_0
 #define GDK_KEY_0 GDK_0
 #define GDK_KEY_1 GDK_1
@@ -877,29 +884,34 @@ static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll,
     return TRUE;
 }
 
-static int gd_map_keycode(GtkDisplayState *s, int gdk_keycode)
+static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
 {
     int qemu_keycode;
 
-#ifdef _WIN32
-    qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
-    switch (qemu_keycode) {
-    case 103:   /* alt gr */
-        qemu_keycode = 56 | SCANCODE_GREY;
-        break;
+#ifdef GDK_WINDOWING_WIN32
+    if (GDK_IS_WIN32_DISPLAY(dpy)) {
+        qemu_keycode = MapVirtualKey(gdk_keycode, MAPVK_VK_TO_VSC);
+        switch (qemu_keycode) {
+        case 103:   /* alt gr */
+            qemu_keycode = 56 | SCANCODE_GREY;
+            break;
+        }
+        return qemu_keycode;
     }
-#else
+#endif
 
     if (gdk_keycode < 9) {
         qemu_keycode = 0;
     } else if (gdk_keycode < 97) {
         qemu_keycode = gdk_keycode - 8;
-    } else if (gdk_keycode < 158) {
+#ifdef GDK_WINDOWING_X11
+    } else if (GDK_IS_X11_DISPLAY(dpy) && gdk_keycode < 158) {
         if (s->has_evdev) {
             qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
         } else {
             qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
         }
+#endif
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
@@ -907,7 +919,6 @@ static int gd_map_keycode(GtkDisplayState *s, int gdk_keycode)
     } else {
         qemu_keycode = 0;
     }
-#endif
 
     return qemu_keycode;
 }
@@ -920,7 +931,8 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
     int qemu_keycode;
     int i;
 
-    qemu_keycode = gd_map_keycode(s, gdk_keycode);
+    qemu_keycode = gd_map_keycode(s, gtk_widget_get_display(widget),
+                                  gdk_keycode);
 
     trace_gd_key_event(vc->label, gdk_keycode, qemu_keycode,
                        (key->type == GDK_KEY_PRESS) ? "down" : "up");
@@ -1802,23 +1814,25 @@ static void gd_create_menus(GtkDisplayState *s)
 
 static void gd_set_keycode_type(GtkDisplayState *s)
 {
-#ifndef _WIN32
-    char *keycodes = NULL;
+#ifdef GDK_WINDOWING_X11
     GdkDisplay *display = gtk_widget_get_display(s->window);
-    Display *x11_display = gdk_x11_display_get_xdisplay(display);
-    XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask,
-                                     XkbUseCoreKbd);
-
-    if (desc && desc->names) {
-        keycodes = XGetAtomName(x11_display, desc->names->keycodes);
-    }
-    if (keycodes == NULL) {
-        fprintf(stderr, "could not lookup keycode name\n");
-    } else if (strstart(keycodes, "evdev", NULL)) {
-        s->has_evdev = true;
-    } else if (!strstart(keycodes, "xfree86", NULL)) {
-        fprintf(stderr, "unknown keycodes `%s', please report to "
-                "qemu-devel@nongnu.org\n", keycodes);
+    if (GDK_IS_X11_DISPLAY(display)) {
+        Display *x11_display = gdk_x11_display_get_xdisplay(display);
+        XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask,
+                                         XkbUseCoreKbd);
+        char *keycodes = NULL;
+
+        if (desc && desc->names) {
+            keycodes = XGetAtomName(x11_display, desc->names->keycodes);
+        }
+        if (keycodes == NULL) {
+            fprintf(stderr, "could not lookup keycode name\n");
+        } else if (strstart(keycodes, "evdev", NULL)) {
+            s->has_evdev = true;
+        } else if (!strstart(keycodes, "xfree86", NULL)) {
+            fprintf(stderr, "unknown keycodes `%s', please report to "
+                    "qemu-devel@nongnu.org\n", keycodes);
+        }
     }
 #endif
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 3/5] gtk: factor out gtk3 grab into the new gd_grab_devices function
  2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 1/5] gtk: factor out keycode mapping Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 2/5] gtk: cleanup backend dependencies Gerd Hoffmann
@ 2014-06-03  8:01 ` Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 4/5] gtk: update window size after showing/hiding tabs Gerd Hoffmann
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-03  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 100 +++++++++++++++++++++++----------------------------------------
 1 file changed, 36 insertions(+), 64 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index d201190..544126c 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1162,28 +1162,39 @@ static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
     gd_update_full_redraw(vc);
 }
 
-static void gd_grab_keyboard(VirtualConsole *vc)
-{
 #if GTK_CHECK_VERSION(3, 0, 0)
+static void gd_grab_devices(VirtualConsole *vc, bool grab,
+                            GdkInputSource source, GdkEventMask mask,
+                            GdkCursor *cursor)
+{
     GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
     GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
-    GList *devices = gdk_device_manager_list_devices(mgr,
-                                                     GDK_DEVICE_TYPE_MASTER);
-    GList *tmp = devices;
-    while (tmp) {
+    GList *devs = gdk_device_manager_list_devices(mgr, GDK_DEVICE_TYPE_MASTER);
+    GList *tmp = devs;
+
+    for (tmp = devs; tmp; tmp = tmp->next) {
         GdkDevice *dev = tmp->data;
-        if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) {
-            gdk_device_grab(dev,
-                            gtk_widget_get_window(vc->gfx.drawing_area),
-                            GDK_OWNERSHIP_NONE,
-                            FALSE,
-                            GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
-                            NULL,
-                            GDK_CURRENT_TIME);
+        if (gdk_device_get_source(dev) != source) {
+            continue;
+        }
+        if (grab) {
+            GdkWindow *win = gtk_widget_get_window(vc->gfx.drawing_area);
+            gdk_device_grab(dev, win, GDK_OWNERSHIP_NONE, FALSE,
+                            mask, cursor, GDK_CURRENT_TIME);
+        } else {
+            gdk_device_ungrab(dev, GDK_CURRENT_TIME);
         }
-        tmp = tmp->next;
     }
-    g_list_free(devices);
+    g_list_free(devs);
+}
+#endif
+
+static void gd_grab_keyboard(VirtualConsole *vc)
+{
+#if GTK_CHECK_VERSION(3, 0, 0)
+    gd_grab_devices(vc, true, GDK_SOURCE_KEYBOARD,
+                   GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+                   NULL);
 #else
     gdk_keyboard_grab(gtk_widget_get_window(vc->gfx.drawing_area),
                       FALSE,
@@ -1203,20 +1214,7 @@ static void gd_ungrab_keyboard(GtkDisplayState *s)
     s->kbd_owner = NULL;
 
 #if GTK_CHECK_VERSION(3, 0, 0)
-    GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
-    GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
-    GList *devices = gdk_device_manager_list_devices(mgr,
-                                                     GDK_DEVICE_TYPE_MASTER);
-    GList *tmp = devices;
-    while (tmp) {
-        GdkDevice *dev = tmp->data;
-        if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) {
-            gdk_device_ungrab(dev,
-                              GDK_CURRENT_TIME);
-        }
-        tmp = tmp->next;
-    }
-    g_list_free(devices);
+    gd_grab_devices(vc, false, GDK_SOURCE_KEYBOARD, 0, NULL);
 #else
     gdk_keyboard_ungrab(GDK_CURRENT_TIME);
 #endif
@@ -1228,28 +1226,13 @@ static void gd_grab_pointer(VirtualConsole *vc)
     GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
 #if GTK_CHECK_VERSION(3, 0, 0)
     GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
-    GList *devices = gdk_device_manager_list_devices(mgr,
-                                                     GDK_DEVICE_TYPE_MASTER);
-    GList *tmp = devices;
-    while (tmp) {
-        GdkDevice *dev = tmp->data;
-        if (gdk_device_get_source(dev) == GDK_SOURCE_MOUSE) {
-            gdk_device_grab(dev,
-                            gtk_widget_get_window(vc->gfx.drawing_area),
-                            GDK_OWNERSHIP_NONE,
-                            FALSE, /* All events to come to our
-                                      window directly */
-                            GDK_POINTER_MOTION_MASK |
-                            GDK_BUTTON_PRESS_MASK |
-                            GDK_BUTTON_RELEASE_MASK |
-                            GDK_BUTTON_MOTION_MASK |
-                            GDK_SCROLL_MASK,
-                            vc->s->null_cursor,
-                            GDK_CURRENT_TIME);
-        }
-        tmp = tmp->next;
-    }
-    g_list_free(devices);
+    gd_grab_devices(vc, true, GDK_SOURCE_MOUSE,
+                    GDK_POINTER_MOTION_MASK |
+                    GDK_BUTTON_PRESS_MASK |
+                    GDK_BUTTON_RELEASE_MASK |
+                    GDK_BUTTON_MOTION_MASK |
+                    GDK_SCROLL_MASK,
+                    vc->s->null_cursor);
     gdk_device_get_position(gdk_device_manager_get_client_pointer(mgr),
                             NULL, &vc->s->grab_x_root, &vc->s->grab_y_root);
 #else
@@ -1282,18 +1265,7 @@ static void gd_ungrab_pointer(GtkDisplayState *s)
     GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
 #if GTK_CHECK_VERSION(3, 0, 0)
     GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
-    GList *devices = gdk_device_manager_list_devices(mgr,
-                                                     GDK_DEVICE_TYPE_MASTER);
-    GList *tmp = devices;
-    while (tmp) {
-        GdkDevice *dev = tmp->data;
-        if (gdk_device_get_source(dev) == GDK_SOURCE_MOUSE) {
-            gdk_device_ungrab(dev,
-                              GDK_CURRENT_TIME);
-        }
-        tmp = tmp->next;
-    }
-    g_list_free(devices);
+    gd_grab_devices(vc, false, GDK_SOURCE_MOUSE, 0, NULL);
     gdk_device_warp(gdk_device_manager_get_client_pointer(mgr),
                     gtk_widget_get_screen(vc->gfx.drawing_area),
                     vc->s->grab_x_root, vc->s->grab_y_root);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 4/5] gtk: update window size after showing/hiding tabs
  2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 3/5] gtk: factor out gtk3 grab into the new gd_grab_devices function Gerd Hoffmann
@ 2014-06-03  8:01 ` Gerd Hoffmann
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 5/5] gtk: bind to text terminal consoles too Gerd Hoffmann
  2014-06-04  7:25 ` [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Stefan Weil
  5 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-03  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ui/gtk.c b/ui/gtk.c
index 544126c..b02fcd6 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1005,12 +1005,14 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
 static void gd_menu_show_tabs(GtkMenuItem *item, void *opaque)
 {
     GtkDisplayState *s = opaque;
+    VirtualConsole *vc = gd_vc_find_current(s);
 
     if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->show_tabs_item))) {
         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), TRUE);
     } else {
         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(s->notebook), FALSE);
     }
+    gd_update_windowsize(vc);
 }
 
 static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event,
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 5/5] gtk: bind to text terminal consoles too
  2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 4/5] gtk: update window size after showing/hiding tabs Gerd Hoffmann
@ 2014-06-03  8:01 ` Gerd Hoffmann
  2014-06-04  7:25 ` [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Stefan Weil
  5 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-03  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

This way gtk has text terminal consoles even when building without vte.
Most notably you'll get a monitor tab on windows now.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 109 ++++++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 73 insertions(+), 36 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index b02fcd6..773d935 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -289,7 +289,8 @@ static void gd_update_cursor(VirtualConsole *vc)
     GtkDisplayState *s = vc->s;
     GdkWindow *window;
 
-    if (vc->type != GD_VC_GFX) {
+    if (vc->type != GD_VC_GFX ||
+        !qemu_console_is_graphic(vc->gfx.dcl.con)) {
         return;
     }
 
@@ -422,7 +423,8 @@ static void gtk_release_modifiers(GtkDisplayState *s)
     VirtualConsole *vc = gd_vc_find_current(s);
     int i, keycode;
 
-    if (vc->type != GD_VC_GFX) {
+    if (vc->type != GD_VC_GFX ||
+        !qemu_console_is_graphic(vc->gfx.dcl.con)) {
         return;
     }
     for (i = 0; i < ARRAY_SIZE(modifier_keycode); i++) {
@@ -441,6 +443,7 @@ static void gd_update(DisplayChangeListener *dcl,
                       int x, int y, int w, int h)
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
+    GdkWindow *win;
     int x1, x2, y1, y2;
     int mx, my;
     int fbw, fbh;
@@ -463,8 +466,11 @@ static void gd_update(DisplayChangeListener *dcl,
     fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
     fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
 
-    gdk_drawable_get_size(gtk_widget_get_window(vc->gfx.drawing_area),
-                          &ww, &wh);
+    win = gtk_widget_get_window(vc->gfx.drawing_area);
+    if (!win) {
+        return;
+    }
+    gdk_drawable_get_size(win, &ww, &wh);
 
     mx = my = 0;
     if (ww > fbw) {
@@ -923,6 +929,23 @@ static int gd_map_keycode(GtkDisplayState *s, GdkDisplay *dpy, int gdk_keycode)
     return qemu_keycode;
 }
 
+static gboolean gd_text_key_down(GtkWidget *widget,
+                                 GdkEventKey *key, void *opaque)
+{
+    VirtualConsole *vc = opaque;
+    QemuConsole *con = vc->gfx.dcl.con;
+
+    if (key->length) {
+        kbd_put_string_console(con, key->string, key->length);
+    } else {
+        int num = gd_map_keycode(vc->s, gtk_widget_get_display(widget),
+                                 key->hardware_keycode);
+        int qcode = qemu_input_key_number_to_qcode(num);
+        kbd_put_qcode_console(con, qcode);
+    }
+    return TRUE;
+}
+
 static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
 {
     VirtualConsole *vc = opaque;
@@ -1049,7 +1072,8 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
     GtkDisplayState *s = opaque;
     VirtualConsole *vc = gd_vc_find_current(s);
 
-    if (vc->type == GD_VC_GFX) {
+    if (vc->type == GD_VC_GFX &&
+        qemu_console_is_graphic(vc->gfx.dcl.con)) {
         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
                                        FALSE);
     }
@@ -1062,11 +1086,14 @@ static void gd_menu_untabify(GtkMenuItem *item, void *opaque)
                          G_CALLBACK(gd_tab_window_close), vc);
         gtk_widget_show_all(vc->window);
 
-        GtkAccelGroup *ag = gtk_accel_group_new();
-        gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
+        if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
+            GtkAccelGroup *ag = gtk_accel_group_new();
+            gtk_window_add_accel_group(GTK_WINDOW(vc->window), ag);
 
-        GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab), vc, NULL);
-        gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
+            GClosure *cb = g_cclosure_new_swap(G_CALLBACK(gd_win_grab),
+                                               vc, NULL);
+            gtk_accel_group_connect(ag, GDK_KEY_g, HOTKEY_MODIFIERS, 0, cb);
+        }
 
         gd_update_geometry_hints(vc);
         gd_update_caption(s);
@@ -1083,8 +1110,10 @@ static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
         gtk_widget_set_size_request(s->menu_bar, 0, 0);
         if (vc->type == GD_VC_GFX) {
             gtk_widget_set_size_request(vc->gfx.drawing_area, -1, -1);
-            gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
-                                           TRUE);
+            if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
+                gtk_check_menu_item_set_active
+                    (GTK_CHECK_MENU_ITEM(s->grab_item), TRUE);
+            }
         }
         gtk_window_fullscreen(GTK_WINDOW(s->window));
         s->full_screen = TRUE;
@@ -1327,7 +1356,8 @@ static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
 #endif
     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item),
                                    TRUE);
-    on_vga = (vc->type == GD_VC_GFX);
+    on_vga = (vc->type == GD_VC_GFX &&
+              qemu_console_is_graphic(vc->gfx.dcl.con));
     if (!on_vga) {
         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
                                        FALSE);
@@ -1532,25 +1562,30 @@ static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
     g_signal_connect(vc->gfx.drawing_area, "expose-event",
                      G_CALLBACK(gd_expose_event), vc);
 #endif
-    g_signal_connect(vc->gfx.drawing_area, "event",
-                     G_CALLBACK(gd_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "button-press-event",
-                     G_CALLBACK(gd_button_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "button-release-event",
-                     G_CALLBACK(gd_button_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "scroll-event",
-                     G_CALLBACK(gd_scroll_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "key-press-event",
-                     G_CALLBACK(gd_key_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "key-release-event",
-                     G_CALLBACK(gd_key_event), vc);
-
-    g_signal_connect(vc->gfx.drawing_area, "enter-notify-event",
-                     G_CALLBACK(gd_enter_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "leave-notify-event",
-                     G_CALLBACK(gd_leave_event), vc);
-    g_signal_connect(vc->gfx.drawing_area, "focus-out-event",
-                     G_CALLBACK(gd_focus_out_event), vc);
+    if (qemu_console_is_graphic(vc->gfx.dcl.con)) {
+        g_signal_connect(vc->gfx.drawing_area, "event",
+                         G_CALLBACK(gd_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "button-press-event",
+                         G_CALLBACK(gd_button_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "button-release-event",
+                         G_CALLBACK(gd_button_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "scroll-event",
+                         G_CALLBACK(gd_scroll_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "key-press-event",
+                         G_CALLBACK(gd_key_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "key-release-event",
+                         G_CALLBACK(gd_key_event), vc);
+
+        g_signal_connect(vc->gfx.drawing_area, "enter-notify-event",
+                         G_CALLBACK(gd_enter_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "leave-notify-event",
+                         G_CALLBACK(gd_leave_event), vc);
+        g_signal_connect(vc->gfx.drawing_area, "focus-out-event",
+                         G_CALLBACK(gd_focus_out_event), vc);
+    } else {
+        g_signal_connect(vc->gfx.drawing_area, "key-press-event",
+                         G_CALLBACK(gd_text_key_down), vc);
+    }
 }
 
 static void gd_connect_signals(GtkDisplayState *s)
@@ -1639,8 +1674,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
     obj = object_property_get_link(OBJECT(con), "device", &local_err);
     if (obj) {
         vc->label = g_strdup_printf("%s", object_get_typename(obj));
-    } else {
+    } else if (qemu_console_is_graphic(con)) {
         vc->label = g_strdup_printf("VGA");
+    } else {
+        vc->label = g_strdup_printf("vc%d", idx);
     }
 
     vc->s = s;
@@ -1664,14 +1701,14 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
     vc->tab_item = vc->gfx.drawing_area;
     gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook),
                              vc->tab_item, gtk_label_new(vc->label));
-    gd_connect_vc_gfx_signals(vc);
-
-    group = gd_vc_menu_init(s, vc, idx, group, view_menu);
 
     vc->gfx.dcl.ops = &dcl_ops;
     vc->gfx.dcl.con = con;
     register_displaychangelistener(&vc->gfx.dcl);
 
+    gd_connect_vc_gfx_signals(vc);
+    group = gd_vc_menu_init(s, vc, idx, group, view_menu);
+
     return group;
 }
 
@@ -1739,7 +1776,7 @@ static GtkWidget *gd_create_menu_view(GtkDisplayState *s, GtkAccelGroup *accel_g
     /* gfx */
     for (vc = 0;; vc++) {
         con = qemu_console_lookup_by_index(vc);
-        if (!con || !qemu_console_is_graphic(con)) {
+        if (!con) {
             break;
         }
         group = gd_vc_gfx_init(s, &s->vc[vc], con,
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 2/5] gtk: cleanup backend dependencies
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 2/5] gtk: cleanup backend dependencies Gerd Hoffmann
@ 2014-06-03 15:17   ` Richard Henderson
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2014-06-03 15:17 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Anthony Liguori

On 06/03/2014 01:01 AM, Gerd Hoffmann wrote:
> Make configure detect gtk x11 backend and link libX11 then.  Make
> gtk backend specific code properly #ifdef'ed on the GTK_WINDOWING_*
> backends at runtime).  Our gtk ui code should build and run fine on
> any platform now.
> 
> This also fixes the linker failute due to the new XkbGetKeyboard call
> added by commit 3158a3482b0093e41f2b2596fba50774ea31ae08.
> 
> Cc: Richard Henderson <rth@twiddle.net>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  configure |  4 ++++
>  ui/gtk.c  | 70 ++++++++++++++++++++++++++++++++++++++-------------------------
>  2 files changed, 46 insertions(+), 28 deletions(-)

Tested-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte
  2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2014-06-03  8:01 ` [Qemu-devel] [PATCH 5/5] gtk: bind to text terminal consoles too Gerd Hoffmann
@ 2014-06-04  7:25 ` Stefan Weil
  2014-06-04  7:40   ` Gerd Hoffmann
  5 siblings, 1 reply; 9+ messages in thread
From: Stefan Weil @ 2014-06-04  7:25 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

Am 03.06.2014 10:01, schrieb Gerd Hoffmann:
>   Hi,
>
> Current gtk patch queue.  A bunch of cleanups and fixes.
>
> Most notable change is patch #5 which winds up qemu text
> terminal emulation in gtk, so '-chardev vc' works even
> when building without vte (i.e. on windows).
>
> Gerd Hoffmann (5):
>   gtk: factor out keycode mapping
>   gtk: cleanup backend dependencies
>   gtk: factor out gtk3 grab into the new gd_grab_devices function
>   gtk: update window size after showing/hiding tabs
>   gtk: bind to text terminal consoles too
>
>  configure |   4 +
>  ui/gtk.c  | 298 ++++++++++++++++++++++++++++++++++----------------------------
>  2 files changed, 170 insertions(+), 132 deletions(-)
>

Hi Gerd,

its great to get text terminals without VTE now.

I tested the series on a Linux x86_64 host. Native QEMU for this host
seems to work fine. QEMU for 64 bit Windows with wine64 shows several
issues:

* The text consoles are named vc1, vc2, vc3 in the menu.
* The text consoles show a black left border initially.
* Booting a Linux guest is extremely slow. I see several timeouts:
  err:ntdll:RtlpWaitForCriticalSection section 0x9a9560 "?" wait timed
out in thread 0030,
 blocked by 002c, retrying (60 sec)

Regards
Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte
  2014-06-04  7:25 ` [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Stefan Weil
@ 2014-06-04  7:40   ` Gerd Hoffmann
  0 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2014-06-04  7:40 UTC (permalink / raw)
  To: Stefan Weil; +Cc: qemu-devel

> Hi Gerd,
> 
> its great to get text terminals without VTE now.
> 
> I tested the series on a Linux x86_64 host. Native QEMU for this host
> seems to work fine. QEMU for 64 bit Windows with wine64 shows several
> issues:
> 
> * The text consoles are named vc1, vc2, vc3 in the menu.

Yep.  It's because we don't have access to the chardev.
Fixing that (non-hackish) needs some infrastructure work:

  * Make chardevs objects, link them in the qom tree.
  * Make chardev label a object property.
  * Add a chardev link to QemuConsoles (simliar to the device
    link we have today for gfx consoles).

Then we can figure a better name in the ui.

> * Booting a Linux guest is extremely slow. I see several timeouts:
>   err:ntdll:RtlpWaitForCriticalSection section 0x9a9560 "?" wait timed
> out in thread 0030,

Hmm.  No idea.  But its pretty much a blocker given that this stuff will
be active on windows by default.  Tried real windows too?  Any chance to
get a stacktrace for the place where it blocks?  Maybe that gives a
clue ...

thanks,
  Gerd

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-06-04  7:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-03  8:01 [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Gerd Hoffmann
2014-06-03  8:01 ` [Qemu-devel] [PATCH 1/5] gtk: factor out keycode mapping Gerd Hoffmann
2014-06-03  8:01 ` [Qemu-devel] [PATCH 2/5] gtk: cleanup backend dependencies Gerd Hoffmann
2014-06-03 15:17   ` Richard Henderson
2014-06-03  8:01 ` [Qemu-devel] [PATCH 3/5] gtk: factor out gtk3 grab into the new gd_grab_devices function Gerd Hoffmann
2014-06-03  8:01 ` [Qemu-devel] [PATCH 4/5] gtk: update window size after showing/hiding tabs Gerd Hoffmann
2014-06-03  8:01 ` [Qemu-devel] [PATCH 5/5] gtk: bind to text terminal consoles too Gerd Hoffmann
2014-06-04  7:25 ` [Qemu-devel] [PATCH 0/5] gtk: fixes, cleanups and text consoles without vte Stefan Weil
2014-06-04  7:40   ` Gerd Hoffmann

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).