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>,
	Cole Robinson <crobinso@redhat.com>
Subject: [Qemu-devel] [PATCH 04/22] gtk: Add a scrollbar for text consoles
Date: Tue,  6 May 2014 14:05:40 +0200	[thread overview]
Message-ID: <1399377958-20076-5-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1399377958-20076-1-git-send-email-kraxel@redhat.com>

From: Cole Robinson <crobinso@redhat.com>

Only show the scrollbar if the content doesn't fit on the visible space.

[ kraxel: fix box packing ]

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

diff --git a/ui/gtk.c b/ui/gtk.c
index 068a39b..6a3fe00 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -109,6 +109,8 @@ typedef struct VirtualConsole
 {
     GtkWidget *menu_item;
 #if defined(CONFIG_VTE)
+    GtkWidget *box;
+    GtkWidget *scrollbar;
     GtkWidget *terminal;
     CharDriverState *chr;
 #endif
@@ -1125,6 +1127,18 @@ static gboolean gd_focus_out_event(GtkWidget *widget,
 /** Virtual Console Callbacks **/
 
 #if defined(CONFIG_VTE)
+static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque)
+{
+    VirtualConsole *vc = opaque;
+
+    if (gtk_adjustment_get_upper(adjustment) >
+        gtk_adjustment_get_page_size(adjustment)) {
+        gtk_widget_show(vc->scrollbar);
+    } else {
+        gtk_widget_hide(vc->scrollbar);
+    }
+}
+
 static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     VirtualConsole *vc = chr->opaque;
@@ -1165,6 +1179,9 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL
     const char *label;
     char buffer[32];
     char path[32];
+    GtkWidget *box;
+    GtkWidget *scrollbar;
+    GtkAdjustment *vadjustment;
 
     snprintf(buffer, sizeof(buffer), "vc%d", index);
     snprintf(path, sizeof(path), "<QEMU>/View/VC%d", index);
@@ -1186,12 +1203,33 @@ static GSList *gd_vc_init(GtkDisplayState *s, VirtualConsole *vc, int index, GSL
     g_signal_connect(vc->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);
 
+#if VTE_CHECK_VERSION(0, 28, 0) && GTK_CHECK_VERSION(3, 0, 0)
+    vadjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vc->terminal));
+#else
+    vadjustment = vte_terminal_get_adjustment(VTE_TERMINAL(vc->terminal));
+#endif
+
+#if GTK_CHECK_VERSION(3, 0, 0)
+    box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
+    scrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, vadjustment);
+#else
+    box = gtk_hbox_new(false, 2);
+    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), scrollbar, FALSE, FALSE, 0);
+
     vc->chr->opaque = vc;
+    vc->box = box;
+    vc->scrollbar = scrollbar;
+
+    g_signal_connect(vadjustment, "changed",
+                     G_CALLBACK(gd_vc_adjustment_changed), vc);
 
-    gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), vc->terminal,
+    gtk_notebook_append_page(GTK_NOTEBOOK(s->notebook), box,
                              gtk_label_new(label));
     g_signal_connect(vc->menu_item, "activate",
                      G_CALLBACK(gd_menu_switch_vc), s);
-- 
1.8.3.1

  parent reply	other threads:[~2014-05-06 12:06 UTC|newest]

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

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=1399377958-20076-5-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=crobinso@redhat.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).