From 73b95dd4519cd7dab617d528506def7f60b3ad17 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 20 Mar 2013 16:53:23 +0000 Subject: [PATCH] cogland: Add an option to split the desktop into four outputs Previously Cogland would always split the desktop into four outputs. Although this is quite neat to demonstrate that it's possible, it's quite annoying in practice while testing. This patch turns it into a command line option which defaults to off. Reviewed-by: Robert Bragg (cherry picked from commit 5570bf892268c8d2ea36bc26473aeb607c0e2c1d) --- examples/cogland.c | 66 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/examples/cogland.c b/examples/cogland.c index 3357608a4..029da0a04 100644 --- a/examples/cogland.c +++ b/examples/cogland.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -109,6 +110,47 @@ struct _CoglandCompositor GList *surfaces; }; +static CoglBool option_multiple_outputs = FALSE; + +static GOptionEntry +options[] = + { + { + "multiple", 'm', 0, G_OPTION_ARG_NONE, &option_multiple_outputs, + "Split the compositor into four outputs", NULL + }, + { NULL, 0, 0, 0, NULL, NULL, NULL } + }; + +static CoglBool +process_arguments (int *argc, char ***argv, + GError **error) +{ + GOptionContext *context; + CoglBool ret; + GOptionGroup *group; + + group = g_option_group_new (NULL, /* name */ + NULL, /* description */ + NULL, /* help_description */ + NULL, /* user_data */ + NULL /* destroy notify */); + g_option_group_add_entries (group, options); + context = g_option_context_new ("- An example Wayland compositor using Cogl"); + g_option_context_set_main_group (context, group); + ret = g_option_context_parse (context, argc, argv, error); + g_option_context_free (context); + + if (ret && *argc > 1) + { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION, + "Unknown option '%s'", (* argv)[1]); + ret = FALSE; + } + + return ret; +} + static uint32_t get_time (void) { @@ -959,6 +1001,7 @@ main (int argc, char **argv) CoglandCompositor compositor; GMainLoop *loop; CoglError *error = NULL; + GError *gerror = NULL; CoglVertexP2C4 triangle_vertices[] = { {0, 0.7, 0xff, 0x00, 0x00, 0x80}, {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff}, @@ -966,6 +1009,12 @@ main (int argc, char **argv) }; GSource *cogl_source; + if (!process_arguments (&argc, &argv, &gerror)) + { + fprintf (stderr, "%s\n", gerror->message); + return EXIT_FAILURE; + } + memset (&compositor, 0, sizeof (compositor)); compositor.wayland_display = wl_display_create (); @@ -1000,11 +1049,18 @@ main (int argc, char **argv) compositor.virtual_width = 640; compositor.virtual_height = 480; - /* Emulate compositing with multiple monitors... */ - cogland_compositor_create_output (&compositor, 0, 0, 320, 240); - cogland_compositor_create_output (&compositor, 320, 0, 320, 240); - cogland_compositor_create_output (&compositor, 0, 240, 320, 240); - cogland_compositor_create_output (&compositor, 320, 240, 320, 240); + if (option_multiple_outputs) + { + /* Emulate compositing with multiple monitors... */ + cogland_compositor_create_output (&compositor, 0, 0, 320, 240); + cogland_compositor_create_output (&compositor, 320, 0, 320, 240); + cogland_compositor_create_output (&compositor, 0, 240, 320, 240); + cogland_compositor_create_output (&compositor, 320, 240, 320, 240); + } + else + { + cogland_compositor_create_output (&compositor, 0, 0, 640, 480); + } if (wl_display_add_global (compositor.wayland_display, &wl_shell_interface, &compositor, bind_shell) == NULL)