qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PATCH 06/25] gtk: VirtualConsole restruction
Date: Wed, 21 May 2014 10:43:42 +0200	[thread overview]
Message-ID: <1400661841-16031-7-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1400661841-16031-1-git-send-email-kraxel@redhat.com>

Move all vte-related items into VirtualVteConsole substruct.

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

diff --git a/ui/gtk.c b/ui/gtk.c
index 49753ef..78f6ccc 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -105,15 +105,23 @@ static const int modifier_keycode[] = {
     0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
 };
 
-typedef struct VirtualConsole
-{
-    GtkWidget *menu_item;
 #if defined(CONFIG_VTE)
+typedef struct VirtualVteConsole {
     GtkWidget *box;
     GtkWidget *scrollbar;
     GtkWidget *terminal;
     CharDriverState *chr;
+} VirtualVteConsole;
+#endif
+
+typedef struct VirtualConsole {
+    GtkWidget *menu_item;
+    GtkWidget *tab_item;
+    union {
+#if defined(CONFIG_VTE)
+        VirtualVteConsole vte;
 #endif
+    };
 } VirtualConsole;
 
 typedef struct GtkDisplayState
@@ -178,6 +186,36 @@ static GtkDisplayState *global_state;
 
 /** Utility Functions **/
 
+static VirtualConsole *gd_vc_find_by_menu(GtkDisplayState *s)
+{
+    VirtualConsole *vc;
+    gint i;
+
+    for (i = 0; i < s->nb_vcs; i++) {
+        vc = &s->vc[i];
+        if (gtk_check_menu_item_get_active
+            (GTK_CHECK_MENU_ITEM(vc->menu_item))) {
+            return vc;
+        }
+    }
+    return NULL;
+}
+
+static VirtualConsole *gd_vc_find_by_page(GtkDisplayState *s, gint page)
+{
+    VirtualConsole *vc;
+    gint i, p;
+
+    for (i = 0; i < s->nb_vcs; i++) {
+        vc = &s->vc[i];
+        p = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook), vc->tab_item);
+        if (p == page) {
+            return vc;
+        }
+    }
+    return NULL;
+}
+
 static bool gd_is_grab_active(GtkDisplayState *s)
 {
     return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->grab_item));
@@ -817,17 +855,12 @@ static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque)
         gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), page);
     } else {
         gtk_release_modifiers(s);
-#if defined(CONFIG_VTE)
-        gint i;
-        for (i = 0; i < s->nb_vcs; i++) {
-            if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(s->vc[i].menu_item))) {
-                page = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook),
-                                             s->vc[i].box);
-                gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), page);
-                return;
-            }
+        VirtualConsole *vc = gd_vc_find_by_menu(s);
+        if (vc) {
+            page = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook),
+                                         vc->tab_item);
+            gtk_notebook_set_current_page(GTK_NOTEBOOK(s->notebook), page);
         }
-#endif
     }
 }
 
@@ -1091,20 +1124,12 @@ static void gd_change_page(GtkNotebook *nb, gpointer arg1, guint arg2,
     if (on_vga) {
         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->vga_item), TRUE);
     } else {
-#if defined(CONFIG_VTE)
         VirtualConsole *vc;
-        gint page, i;
-        for (i = 0; i < s->nb_vcs; i++) {
-            vc = &s->vc[i];
-            page = gtk_notebook_page_num(GTK_NOTEBOOK(s->notebook), vc->box);
-            if (page == arg2) {
-                gtk_check_menu_item_set_active
-                    (GTK_CHECK_MENU_ITEM(vc->menu_item), TRUE);
-            }
+        vc = gd_vc_find_by_page(s, arg2);
+        if (vc) {
+            gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(vc->menu_item),
+                                           TRUE);
         }
-#else
-        g_assert_not_reached();
-#endif
     }
 
     gtk_widget_set_sensitive(s->grab_item, on_vga);
@@ -1153,9 +1178,9 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
 
     if (gtk_adjustment_get_upper(adjustment) >
         gtk_adjustment_get_page_size(adjustment)) {
-        gtk_widget_show(vc->scrollbar);
+        gtk_widget_show(vc->vte.scrollbar);
     } else {
-        gtk_widget_hide(vc->scrollbar);
+        gtk_widget_hide(vc->vte.scrollbar);
     }
 }
 
@@ -1163,7 +1188,7 @@ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     VirtualConsole *vc = chr->opaque;
 
-    vte_terminal_feed(VTE_TERMINAL(vc->terminal), (const char *)buf, len);
+    vte_terminal_feed(VTE_TERMINAL(vc->vte.terminal), (const char *)buf, len);
     return len;
 }
 
@@ -1189,7 +1214,7 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size,
 {
     VirtualConsole *vc = user_data;
 
-    qemu_chr_be_write(vc->chr, (uint8_t  *)text, (unsigned int)size);
+    qemu_chr_be_write(vc->vte.chr, (uint8_t  *)text, (unsigned int)size);
     return TRUE;
 }
 
@@ -1206,10 +1231,10 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL
     snprintf(buffer, sizeof(buffer), "vc%d", index);
     snprintf(path, sizeof(path), "<QEMU>/View/VC%d", index);
 
-    vc->chr = vcs[index];
+    vc->vte.chr = vcs[index];
 
-    if (vc->chr->label) {
-        label = vc->chr->label;
+    if (vc->vte.chr->label) {
+        label = vc->vte.chr->label;
     } else {
         label = buffer;
     }
@@ -1219,16 +1244,17 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL
     gtk_menu_item_set_accel_path(GTK_MENU_ITEM(vc->menu_item), path);
     gtk_accel_map_add_entry(path, GDK_KEY_2 + index, HOTKEY_MODIFIERS);
 
-    vc->terminal = vte_terminal_new();
-    g_signal_connect(vc->terminal, "commit", G_CALLBACK(gd_vc_in), vc);
+    vc->vte.terminal = vte_terminal_new();
+    g_signal_connect(vc->vte.terminal, "commit", G_CALLBACK(gd_vc_in), vc);
 
-    vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->terminal), -1);
-    vte_terminal_set_size(VTE_TERMINAL(vc->terminal), 80, 25);
+    vte_terminal_set_scrollback_lines(VTE_TERMINAL(vc->vte.terminal), -1);
+    vte_terminal_set_size(VTE_TERMINAL(vc->vte.terminal), 80, 25);
 
 #if VTE_CHECK_VERSION(0, 28, 0) && GTK_CHECK_VERSION(3, 0, 0)
-    vadjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vc->terminal));
+    vadjustment = gtk_scrollable_get_vadjustment
+        (GTK_SCROLLABLE(vc->vte.terminal));
 #else
-    vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->terminal));
+    vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->vte.terminal));
 #endif
 
 #if GTK_CHECK_VERSION(3, 0, 0)
@@ -1239,26 +1265,27 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL
     scrollbar = gtk_vscrollbar_new(vadjustment);
 #endif
 
-    gtk_box_pack_start(GTK_BOX(box), vc->terminal, TRUE, TRUE, 0);
+    gtk_box_pack_start(GTK_BOX(box), vc->vte.terminal, TRUE, TRUE, 0);
     gtk_box_pack_start(GTK_BOX(box), scrollbar, FALSE, FALSE, 0);
 
-    vc->chr->opaque = vc;
-    vc->box = box;
-    vc->scrollbar = scrollbar;
+    vc->vte.chr->opaque = vc;
+    vc->vte.box = box;
+    vc->vte.scrollbar = scrollbar;
 
     g_signal_connect(vadjustment, "changed",
                      G_CALLBACK(gd_vc_adjustment_changed), vc);
 
-    gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), box,
+    vc->tab_item = box;
+    gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), vc->tab_item,
                              gtk_label_new(label));
     g_signal_connect(vc->menu_item, "activate",
                      G_CALLBACK(gd_menu_switch_vc), s);
 
     gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), vc->menu_item);
 
-    qemu_chr_be_generic_open(vc->chr);
-    if (vc->chr->init) {
-        vc->chr->init(vc->chr);
+    qemu_chr_be_generic_open(vc->vte.chr);
+    if (vc->vte.chr->init) {
+        vc->vte.chr->init(vc->vte.chr);
     }
 
     return group;
-- 
1.8.3.1

  parent reply	other threads:[~2014-05-21  8:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-21  8:43 [Qemu-devel] [PATCH 00/25] qemu gtk ui overhaul Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 01/25] gtk: zap scrolled_window Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 02/25] gtk: zap vte size requests Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 03/25] gtk: cleanup CONFIG_VTE ifdef a bit Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 04/25] gtk: Add a scrollbar for text consoles Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 05/25] gtk: remove page numbering assumtions from the code Gerd Hoffmann
2014-05-21  8:43 ` Gerd Hoffmann [this message]
2014-05-21  8:43 ` [Qemu-devel] [PATCH 07/25] gtk: move vga state into VirtualGfxConsole Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 08/25] gtk: support multiple gfx displays Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 09/25] gtk: use device type as label Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 10/25] gtk: simplify resize Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 11/25] gtk: allow moving tabs to windows and back Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 12/25] gtk: add tab to trace events Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 13/25] gtk: add gd_grab trace event Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 14/25] gtk: keep track of grab owner Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 15/25] gtk: skip keyboard grab when hover autograb is active Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 16/25] gtk: update gd_update_caption Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 17/25] gtk: fix grab checks Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 18/25] gtk: update all windows on mouse mode changes Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 19/25] gtk: detached window pointer grabs Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 20/25] gtk: enable untabify for gfx Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 21/25] gtk: Add handling for the xfree86 keycodes Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 22/25] gtk: zap unused global_state Gerd Hoffmann
2014-05-21  8:43 ` [Qemu-devel] [PATCH 23/25] gtk: window sizing overhaul Gerd Hoffmann
2014-05-21  8:44 ` [Qemu-devel] [PATCH 24/25] gtk: workaround gtk2 vte resize issue Gerd Hoffmann
2014-05-21  8:44 ` [Qemu-devel] [PATCH 25/25] gtk: factor out gtk3 grab into the new gd_grab_devices function Gerd Hoffmann
2014-05-21 20:52 ` [Qemu-devel] [PATCH 00/25] qemu gtk ui overhaul Stefan Weil
2014-05-22  6:24   ` Gerd Hoffmann
2014-05-22  6:58     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1400661841-16031-7-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).