From 7da268c164adfeeabbbd0d16526a3518f8a921bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Mon, 11 Jul 2011 15:49:09 +0100 Subject: [PATCH] Add support for --fullscreen option --- man/virt-viewer.pod | 4 ++++ src/virt-viewer-main.c | 10 +++++++--- src/virt-viewer.c | 21 +++++++++++++++++++++ src/virt-viewer.h | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/man/virt-viewer.pod b/man/virt-viewer.pod index d5d823d..ec74f33 100644 --- a/man/virt-viewer.pod +++ b/man/virt-viewer.pod @@ -57,6 +57,10 @@ Zoom level of the display window in percentage. Range 10-200. Do not attempt to tunnel the console over SSH, even if the main connection URI used SSH. +=item -f, --fullscreen + +Start with the window maximised to fullscreen + =item --debug Print debugging information diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c index b176022..e3d4b54 100644 --- a/src/virt-viewer-main.c +++ b/src/virt-viewer-main.c @@ -50,6 +50,7 @@ int main(int argc, char **argv) gboolean direct = FALSE; gboolean waitvm = FALSE; gboolean reconnect = FALSE; + gboolean fullscreen = FALSE; const char *help_msg = N_("Run '" PACKAGE " --help' to see a full list of available command line options"); const GOptionEntry options [] = { { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, @@ -68,9 +69,11 @@ int main(int argc, char **argv) N_("Zoom level of window, in percentage"), "ZOOM" }, { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug, N_("display debugging information"), NULL }, - { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, + { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen, + N_("Open in full screen mode"), NULL }, + { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, "DOMAIN-NAME|ID|UUID" }, - { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; setlocale(LC_ALL, ""); @@ -104,7 +107,7 @@ int main(int argc, char **argv) return 1; } - ret = virt_viewer_start(uri, args[0], zoom, direct, waitvm, reconnect, verbose, debug, NULL); + ret = virt_viewer_start(uri, args[0], zoom, direct, waitvm, reconnect, verbose, debug, fullscreen, NULL); if (ret != 0) return ret; @@ -118,5 +121,6 @@ int main(int argc, char **argv) * c-indent-level: 8 * c-basic-offset: 8 * tab-width: 8 + * indent-tabs-mode: t * End: */ diff --git a/src/virt-viewer.c b/src/virt-viewer.c index c546bf3..7f2de77 100644 --- a/src/virt-viewer.c +++ b/src/virt-viewer.c @@ -520,6 +520,22 @@ virt_viewer_enter_fullscreen(VirtViewer *viewer) ViewAutoDrawer_SetActive(VIEW_AUTODRAWER(viewer->layout), TRUE); } +static gboolean +window_state_cb(GtkWidget *widget G_GNUC_UNUSED, GdkEventWindowState *event, + gpointer data) +{ + VirtViewer *viewer = data; + + if (!(event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)) + return TRUE; + + if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) + virt_viewer_enter_fullscreen(viewer); + else + virt_viewer_leave_fullscreen(viewer); + + return TRUE; +} static void virt_viewer_toolbar_leave_fullscreen(GtkWidget *button G_GNUC_UNUSED, @@ -1539,6 +1555,7 @@ virt_viewer_start(const char *uri, gboolean reconnect, gboolean verbose, gboolean debug, + gboolean fullscreen, GtkWidget *container) { VirtViewer *viewer; @@ -1627,6 +1644,9 @@ virt_viewer_start(const char *uri, viewer->accelList = g_slist_append(viewer->accelList, accels->data); g_object_ref(G_OBJECT(accels->data)); } + g_signal_connect(G_OBJECT(window), "window-state-event", G_CALLBACK(window_state_cb), viewer); + if (fullscreen) + gtk_window_fullscreen(GTK_WINDOW(window)); gtk_widget_show_all(viewer->window); } @@ -1658,5 +1678,6 @@ virt_viewer_start(const char *uri, * c-indent-level: 8 * c-basic-offset: 8 * tab-width: 8 + * indent-tabs-mode: t * End: */ diff --git a/src/virt-viewer.h b/src/virt-viewer.h index 086cf2c..3f2e4c8 100644 --- a/src/virt-viewer.h +++ b/src/virt-viewer.h @@ -37,6 +37,7 @@ extern int virt_viewer_start(const char *uri, gboolean reconnect, gboolean verbose, gboolean debug, + gboolean fullscreen, GtkWidget *container); #endif /* VIRT_VIEWER_H */