diff options
author | Cole Robinson <crobinso@redhat.com> | 2014-04-29 15:24:32 -0400 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2014-05-26 08:41:03 +0200 |
commit | 0fb20d1c39def06a592dd17922e0f0d6fe049000 (patch) | |
tree | fde58e64598e06b07e563bd912ce462ba52a404f /ui/gtk.c | |
parent | ee5f31e48b5a754c44df5f006a845344f9efd753 (diff) |
gtk: Add a scrollbar for text consoles
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>
Diffstat (limited to 'ui/gtk.c')
-rw-r--r-- | ui/gtk.c | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -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); |