This adds basic guest control commands to a new menu - a nice added-value for the GTK UI.
Signed-off-by: Jan Kiszka <jan.kis...@siemens.com> --- ui/gtk.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 63 insertions(+), 1 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index bc4ec67..5445a61 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -84,6 +84,12 @@ typedef struct GtkDisplayState GtkWidget *file_menu; GtkWidget *quit_item; + GtkWidget *control_menu_item; + GtkWidget *control_menu; + GtkWidget *stop_item; + GtkWidget *reset_item; + GtkWidget *powerdown_item; + GtkWidget *view_menu_item; GtkWidget *view_menu; GtkWidget *full_screen_item; @@ -117,6 +123,8 @@ typedef struct GtkDisplayState GdkCursor *null_cursor; Notifier mouse_mode_notifier; gboolean free_scale; + + bool external_stop_update; } GtkDisplayState; static GtkDisplayState *global_state; @@ -160,14 +168,19 @@ static void gd_update_caption(GtkDisplayState *s) const char *status = ""; gchar *title; const char *grab = ""; + bool is_stopped = !runstate_is_running(); if (gd_is_grab_active(s)) { grab = " - Press Ctrl+Alt+G to release grab"; } - if (!runstate_is_running()) { + if (is_stopped) { status = " [Stopped]"; } + s->external_stop_update = true; + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->stop_item), + is_stopped); + s->external_stop_update = false; if (qemu_name) { title = g_strdup_printf("QEMU (%s)%s%s", qemu_name, status, grab); @@ -589,6 +602,30 @@ static void gd_menu_quit(GtkMenuItem *item, void *opaque) qmp_quit(NULL); } +static void gd_menu_stop(GtkMenuItem *item, void *opaque) +{ + GtkDisplayState *s = opaque; + + if (s->external_stop_update) { + return; + } + if (runstate_is_running()) { + qmp_stop(NULL); + } else { + qmp_cont(NULL); + } +} + +static void gd_menu_reset(GtkMenuItem *item, void *opaque) +{ + qmp_system_reset(NULL); +} + +static void gd_menu_powerdown(GtkMenuItem *item, void *opaque) +{ + qmp_system_powerdown(NULL); +} + static void gd_menu_switch_vc(GtkMenuItem *item, void *opaque) { GtkDisplayState *s = opaque; @@ -954,6 +991,12 @@ static void gd_connect_signals(GtkDisplayState *s) g_signal_connect(s->quit_item, "activate", G_CALLBACK(gd_menu_quit), s); + g_signal_connect(s->stop_item, "activate", + G_CALLBACK(gd_menu_stop), s); + g_signal_connect(s->reset_item, "activate", + G_CALLBACK(gd_menu_reset), s); + g_signal_connect(s->powerdown_item, "activate", + G_CALLBACK(gd_menu_powerdown), s); g_signal_connect(s->full_screen_item, "activate", G_CALLBACK(gd_menu_full_screen), s); g_signal_connect(s->zoom_in_item, "activate", @@ -995,6 +1038,22 @@ static void gd_create_menus(GtkDisplayState *s) "<QEMU>/File/Quit"); gtk_accel_map_add_entry("<QEMU>/File/Quit", item.keyval, item.modifier); + s->control_menu = gtk_menu_new(); + gtk_menu_set_accel_group(GTK_MENU(s->control_menu), accel_group); + s->control_menu_item = gtk_menu_item_new_with_mnemonic(_("_Control")); + + s->stop_item = gtk_check_menu_item_new_with_mnemonic(_("_Stop")); + gtk_menu_append(GTK_MENU(s->control_menu), s->stop_item); + + separator = gtk_separator_menu_item_new(); + gtk_menu_append(GTK_MENU(s->control_menu), separator); + + s->reset_item = gtk_image_menu_item_new_with_mnemonic(_("_Reset")); + gtk_menu_append(GTK_MENU(s->control_menu), s->reset_item); + + s->powerdown_item = gtk_image_menu_item_new_with_mnemonic(_("_Power-down")); + gtk_menu_append(GTK_MENU(s->control_menu), s->powerdown_item); + s->view_menu = gtk_menu_new(); gtk_menu_set_accel_group(GTK_MENU(s->view_menu), accel_group); s->view_menu_item = gtk_menu_item_new_with_mnemonic(_("_View")); @@ -1072,6 +1131,9 @@ static void gd_create_menus(GtkDisplayState *s) gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->file_menu_item), s->file_menu); gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->file_menu_item); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->control_menu_item), s->control_menu); + gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->control_menu_item); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(s->view_menu_item), s->view_menu); gtk_menu_shell_append(GTK_MENU_SHELL(s->menu_bar), s->view_menu_item); } -- 1.7.3.4