aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qemu-gtk.c147
-rw-r--r--qemu-gtk.h2
2 files changed, 129 insertions, 20 deletions
diff --git a/qemu-gtk.c b/qemu-gtk.c
index 1c9e466..ff18d6c 100644
--- a/qemu-gtk.c
+++ b/qemu-gtk.c
@@ -58,13 +58,55 @@ static void config_write(void)
/* ------------------------------------------------------------------ */
+static void vtes_set_font(struct qemu_window *win)
+{
+ if (win->monitor.vte)
+ vte_terminal_set_font_from_string(VTE_TERMINAL(win->monitor.vte),
+ win->tty_font);
+ if (win->console.vte)
+ vte_terminal_set_font_from_string(VTE_TERMINAL(win->console.vte),
+ win->tty_font);
+ if (win->gdb_vte)
+ vte_terminal_set_font_from_string(VTE_TERMINAL(win->gdb_vte),
+ win->tty_font);
+}
+
+static void vtes_set_colors(struct qemu_window *win)
+{
+ GdkColor fg = {0,0,0,0};
+ GdkColor bg = {0,0,0,0};
+
+ gdk_color_parse(win->tty_fg, &fg);
+ gdk_color_parse(win->tty_bg, &bg);
+ if (win->monitor.vte) {
+ vte_terminal_set_color_foreground(VTE_TERMINAL(win->monitor.vte), &fg);
+ vte_terminal_set_color_background(VTE_TERMINAL(win->monitor.vte), &bg);
+ }
+ if (win->console.vte) {
+ vte_terminal_set_color_foreground(VTE_TERMINAL(win->console.vte), &fg);
+ vte_terminal_set_color_background(VTE_TERMINAL(win->console.vte), &bg);
+ }
+ if (win->gdb_vte) {
+ vte_terminal_set_color_foreground(VTE_TERMINAL(win->gdb_vte), &fg);
+ vte_terminal_set_color_background(VTE_TERMINAL(win->gdb_vte), &bg);
+ }
+}
+
static void vte_configure(struct qemu_window *win, GtkWidget *vte)
{
+ GdkColor fg = {0,0,0,0};
+ GdkColor bg = {0,0,0,0};
+
vte_terminal_set_scrollback_lines(VTE_TERMINAL(vte), 4096);
vte_terminal_set_backspace_binding(VTE_TERMINAL(vte),
VTE_ERASE_ASCII_BACKSPACE);
- if (win->tty_font)
- vte_terminal_set_font_from_string(VTE_TERMINAL(vte), win->tty_font);
+
+ fprintf(stderr, "%s: %s %s\n", __FUNCTION__, win->tty_fg, win->tty_bg);
+ gdk_color_parse(win->tty_fg, &fg);
+ gdk_color_parse(win->tty_bg, &bg);
+ vte_terminal_set_color_foreground(VTE_TERMINAL(vte), &fg);
+ vte_terminal_set_color_background(VTE_TERMINAL(vte), &bg);
+ vte_terminal_set_font_from_string(VTE_TERMINAL(vte), win->tty_font);
}
static void tabs_configure(struct qemu_window *win)
@@ -185,20 +227,61 @@ static void menu_cb_config_font(GtkAction *action, void *data)
win->tty_font = gtk_font_selection_dialog_get_font_name
(GTK_FONT_SELECTION_DIALOG(dialog));
g_key_file_set_string(config, "tty", "font", win->tty_font);
- if (win->monitor.vte)
- vte_terminal_set_font_from_string(VTE_TERMINAL(win->monitor.vte),
- win->tty_font);
- if (win->console.vte)
- vte_terminal_set_font_from_string(VTE_TERMINAL(win->console.vte),
- win->tty_font);
- if (win->gdb_vte)
- vte_terminal_set_font_from_string(VTE_TERMINAL(win->gdb_vte),
- win->tty_font);
+ vtes_set_font(win);
break;
}
gtk_widget_destroy(dialog);
}
+static int pickcolor(char *title, char *group, char *key, char *current)
+{
+ GtkWidget *dialog;
+ GdkColor color = {0,0,0,0};
+ GtkColorSelection *csel;
+ char name[16];
+ int rc = -1;
+
+ gdk_color_parse(current, &color);
+ dialog = gtk_color_selection_dialog_new(title);
+ csel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);
+ gtk_color_selection_set_has_opacity_control(csel, FALSE);
+ gtk_color_selection_set_current_color(csel, &color);
+
+ gtk_widget_show_all(dialog);
+ switch (gtk_dialog_run(GTK_DIALOG(dialog))) {
+ case GTK_RESPONSE_OK:
+ gtk_color_selection_get_current_color(csel, &color);
+ snprintf(name, sizeof(name), "#%04x%04x%04x",
+ color.red, color.green, color.blue);
+ g_key_file_set_string(config, group, key, name);
+ rc = 0;
+ }
+ gtk_widget_destroy(dialog);
+ return rc;
+}
+
+static void menu_cb_config_fg(GtkAction *action, void *data)
+{
+ struct qemu_window *win = data;
+ GError *err = NULL;
+
+ if (0 != pickcolor("Terminal text color", "tty", "foreground", win->tty_fg))
+ return;
+ win->tty_fg = g_key_file_get_string(config, "tty", "foreground", &err);
+ vtes_set_colors(win);
+}
+
+static void menu_cb_config_bg(GtkAction *action, void *data)
+{
+ struct qemu_window *win = data;
+ GError *err = NULL;
+
+ if (0 != pickcolor("Terminal background", "tty", "background", win->tty_bg))
+ return;
+ win->tty_bg = g_key_file_get_string(config, "tty", "background", &err);
+ vtes_set_colors(win);
+}
+
static void menu_cb_send_ctrlaltdel(GtkToggleAction *action, gpointer userdata)
{
struct qemu_window *win = userdata;
@@ -265,8 +348,8 @@ static void menu_cb_run_gdb(GtkAction *action, gpointer userdata)
if (win->gdb_vte)
return;
win->gdb_vte = vte_terminal_new();
- vte_configure(win, win->gdb_vte);
tabs_add(win, win->gdb_vte, "gdb", -1);
+ vte_configure(win, win->gdb_vte);
monitor_append(win, "gdbserver 1234");
len = snprintf(cmd, sizeof(cmd), "target remote %s:1234\n", win->monitor.hostname);
@@ -527,18 +610,27 @@ static const GtkActionEntry entries[] = {
.callback = G_CALLBACK(menu_cb_close),
},{
- /* --- input menu --- */
- .name = "SendCtrlAltDel",
- .label = "Send Ctrl-Alt-Del",
- .callback = G_CALLBACK(menu_cb_send_ctrlaltdel),
- },{
-
/* --- view menu --- */
.name = "TerminalFont",
.stock_id = GTK_STOCK_SELECT_FONT,
.label = "Terminal _font ...",
.callback = G_CALLBACK(menu_cb_config_font),
},{
+ .name = "TerminalForeground",
+ .stock_id = GTK_STOCK_SELECT_COLOR,
+ .label = "Terminal _text color ...",
+ .callback = G_CALLBACK(menu_cb_config_fg),
+ },{
+ .name = "TerminalBackground",
+ .label = "Terminal _background ...",
+ .callback = G_CALLBACK(menu_cb_config_bg),
+ },{
+
+ /* --- input menu --- */
+ .name = "SendCtrlAltDel",
+ .label = "Send Ctrl-Alt-Del",
+ .callback = G_CALLBACK(menu_cb_send_ctrlaltdel),
+ },{
/* --- vm menu --- */
.name = "MonitorStop",
@@ -603,7 +695,10 @@ static char ui_xml[] =
" <menu action='ViewMenu'>"
" <menuitem action='FullScreen'/>"
" <menuitem action='ScaleDisplay'/>"
+" <separator/>"
" <menuitem action='TerminalFont'/>"
+" <menuitem action='TerminalForeground'/>"
+" <menuitem action='TerminalBackground'/>"
" </menu>"
" <menu action='InputMenu'>"
" <menuitem action='GrabMouse'/>"
@@ -711,6 +806,18 @@ static struct qemu_window *qemu_create_window(void)
win->vnc_grab_kbd = g_key_file_get_boolean(config, "vnc", "grab-kbd", &err);
err = NULL;
win->tty_font = g_key_file_get_string(config, "tty", "font", &err);
+ err = NULL;
+ win->tty_fg = g_key_file_get_string(config, "tty", "foreground", &err);
+ err = NULL;
+ win->tty_bg = g_key_file_get_string(config, "tty", "background", &err);
+
+ /* config defaults */
+ if (!win->tty_fg)
+ win->tty_font = "console 12";
+ if (!win->tty_fg)
+ win->tty_fg = "white";
+ if (!win->tty_bg)
+ win->tty_bg = "black";
/* apply config */
item = gtk_ui_manager_get_widget(win->ui, "/MainMenu/ViewMenu/ScaleDisplay");
@@ -757,10 +864,10 @@ void qemu_conn_tab(struct qemu_window *win, struct qemu_conn *conn, int pos)
if (conn->vte)
return;
conn->vte = vte_terminal_new();
- vte_configure(win, conn->vte);
g_signal_connect(conn->vte, "commit",
G_CALLBACK(conn_user_input), conn);
tabs_add(win, conn->vte, conn->name, pos);
+ vte_configure(win, conn->vte);
}
/* ------------------------------------------------------------------ */
@@ -834,6 +941,7 @@ main(int argc, char *argv[])
exit(1);
}
win->quit_on_shutdown = quit_on_shutdown;
+ gtk_widget_show_all(win->toplevel);
/* tabs */
if (monitor_tab)
@@ -844,7 +952,6 @@ main(int argc, char *argv[])
}
/* main loop */
- gtk_widget_show_all(win->toplevel);
gtk_main();
/* cleanup */
diff --git a/qemu-gtk.h b/qemu-gtk.h
index 96e3113..bccd665 100644
--- a/qemu-gtk.h
+++ b/qemu-gtk.h
@@ -70,6 +70,8 @@ struct qemu_window {
gboolean vnc_grab_mouse;
gboolean vnc_grab_kbd;
char *tty_font;
+ char *tty_fg;
+ char *tty_bg;
};
/* qemu-gtk.c */