[Xfce4-commits] [apps/xfdashboard] 02/03: Add command-line option "--view"

noreply at xfce.org noreply at xfce.org
Tue Aug 25 13:10:47 CEST 2015


This is an automated email from the git hooks/post-receive script.

nomad pushed a commit to branch master
in repository apps/xfdashboard.

commit fc17ce3c726ace049f1c0952ba3d8eff3bb5ebd9
Author: Stephan Haller <nomad at froevel.de>
Date:   Tue Aug 25 12:44:49 2015 +0200

    Add command-line option "--view"
    
    The command-line option "--view [internal name of view]" allows to specify which view to show when xfdashboard gets visible once. It "overrides" any view configured in settings.
    
    This commit completes implementation needed to fix bug #12144
---
 xfdashboard/application.c |   98 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 91 insertions(+), 7 deletions(-)

diff --git a/xfdashboard/application.c b/xfdashboard/application.c
index 5005b33..d163e2e 100644
--- a/xfdashboard/application.c
+++ b/xfdashboard/application.c
@@ -252,7 +252,7 @@ static void _xfdashboard_application_set_theme_name(XfdashboardApplication *self
 }
 
 /* Perform full initialization of this application instance */
-static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication *self)
+static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication *self, XfdashboardStage **outStage)
 {
 	XfdashboardApplicationPrivate	*priv;
 	GError							*error;
@@ -262,6 +262,7 @@ static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication
 #endif
 
 	g_return_val_if_fail(XFDASHBOARD_IS_APPLICATION(self), FALSE);
+	g_return_val_if_fail(outStage==NULL || *outStage==NULL, FALSE);
 
 	priv=self->priv;
 	error=NULL;
@@ -388,12 +389,14 @@ static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication
 
 	/* Create stage containing all monitors */
 	stage=xfdashboard_stage_new();
-	if(!priv->isDaemon) clutter_actor_show(stage);
 	g_signal_connect_swapped(stage, "delete-event", G_CALLBACK(_xfdashboard_application_on_delete_stage), self);
 
 	/* Emit signal 'theme-changed' to get current theme loaded at each stage created */
 	g_signal_emit(self, XfdashboardApplicationSignals[SIGNAL_THEME_CHANGED], 0, priv->theme);
 
+	/* Set return results */
+	if(outStage) *outStage=XFDASHBOARD_STAGE(stage);
+
 	/* Initialization was successful so return TRUE */
 #ifdef DEBUG
 	xfdashboard_notify(NULL, NULL, _("Welcome to %s (%s)!"), PACKAGE_NAME, PACKAGE_VERSION);
@@ -403,6 +406,36 @@ static gboolean _xfdashboard_application_initialize_full(XfdashboardApplication
 	return(TRUE);
 }
 
+/* Switch to requested view */
+static void _xfdashboard_application_switch_to_view(XfdashboardApplication *self, const gchar *inInternalViewName)
+{
+	GSList							*stages, *iter;
+
+	g_return_if_fail(XFDASHBOARD_IS_APPLICATION(self));
+
+	/* If no view name was specified then do nothing and return immediately */
+	if(!inInternalViewName ||
+		!inInternalViewName[0])
+	{
+		g_debug("No view to switch to specified");
+		return;
+	}
+
+	/* Iterate through list of stages and set specified view at stage */
+	g_debug("Trying to switch to view '%s'", inInternalViewName);
+
+	stages=clutter_stage_manager_list_stages(clutter_stage_manager_get_default());
+	for(iter=stages; iter; iter=g_slist_next(iter))
+	{
+		/* Tell stage to switch view */
+		if(XFDASHBOARD_IS_STAGE(iter->data))
+		{
+			xfdashboard_stage_set_switch_to_view(XFDASHBOARD_STAGE(iter->data),
+													inInternalViewName);
+		}
+	}
+}
+
 /* IMPLEMENTATION: GApplication */
 
 /* Received "activate" signal on primary instance */
@@ -432,6 +465,7 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 {
 	XfdashboardApplication			*self;
 	XfdashboardApplicationPrivate	*priv;
+	XfdashboardStage				*stage;
 	GOptionContext					*context;
 	gboolean						result;
 	gint							argc;
@@ -441,12 +475,14 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 	gboolean						optionQuit;
 	gboolean						optionRestart;
 	gboolean						optionToggle;
+	gchar							*optionSwitchToView;
 	GOptionEntry					XfdashboardApplicationOptions[]=
 									{
 										{ "daemonize", 'd', 0, G_OPTION_ARG_NONE, &optionDaemonize, N_("Fork to background"), NULL },
 										{ "quit", 'q', 0, G_OPTION_ARG_NONE, &optionQuit, N_("Quit running instance"), NULL },
 										{ "restart", 'r', 0, G_OPTION_ARG_NONE, &optionRestart, N_("Restart running instance"), NULL },
 										{ "toggle", 't', 0, G_OPTION_ARG_NONE, &optionToggle, N_("Toggles suspend/resume state if running instance was started in daemon mode otherwise it quits running non-daemon instance"), NULL },
+										{ "view", 0, 0, G_OPTION_ARG_STRING, &optionSwitchToView, N_(""), NULL },
 										{ NULL }
 									};
 
@@ -455,12 +491,14 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 	self=XFDASHBOARD_APPLICATION(inApplication);
 	priv=self->priv;
 	error=NULL;
+	stage=NULL;
 
 	/* Set up options */
 	optionDaemonize=FALSE;
 	optionQuit=FALSE;
 	optionRestart=FALSE;
 	optionToggle=FALSE;
+	optionSwitchToView=NULL;
 
 	context=g_option_context_new(N_("- A Gnome Shell like dashboard for Xfce4"));
 	g_option_context_add_group(context, gtk_get_option_group(TRUE));
@@ -484,8 +522,13 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 	g_option_context_free(context);
 	if(result==FALSE)
 	{
+		/* Show error */
 		g_print(N_("%s\n"), (error && error->message) ? error->message : _("unknown error"));
 		if(error) g_error_free(error);
+
+		/* Release allocated resources */
+		if(optionSwitchToView) g_free(optionSwitchToView);
+
 		return(XFDASHBOARD_APPLICATION_ERROR_FAILED);
 	}
 
@@ -496,6 +539,10 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 	{
 		/* Return state to restart this applicationa */
 		g_debug("Received request to restart application!");
+
+		/* Release allocated resources */
+		if(optionSwitchToView) g_free(optionSwitchToView);
+
 		return(XFDASHBOARD_APPLICATION_ERROR_RESTART);
 	}
 
@@ -506,6 +553,9 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 		g_debug("Quitting running instance!");
 		_xfdashboard_application_quit(self, TRUE);
 
+		/* Release allocated resources */
+		if(optionSwitchToView) g_free(optionSwitchToView);
+
 		return(XFDASHBOARD_APPLICATION_ERROR_QUIT);
 	}
 
@@ -520,11 +570,29 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 		/* If application is running in daemon mode, toggle between suspend/resume ... */
 		if(priv->isDaemon)
 		{
-			if(priv->isSuspended) _xfdashboard_application_activate(inApplication);
-				else _xfdashboard_application_quit(self, FALSE);
+			if(priv->isSuspended)
+			{
+				/* Switch to view if requested */
+				_xfdashboard_application_switch_to_view(self, optionSwitchToView);
+
+				/* Show application again */
+				_xfdashboard_application_activate(inApplication);
+			}
+				else
+				{
+					/* Hide application */
+					_xfdashboard_application_quit(self, FALSE);
+				}
 		}
 			/* ... otherwise if not running in daemon mode, just quit */
-			else _xfdashboard_application_quit(self, FALSE);
+			else
+			{
+				/* Hide application */
+				_xfdashboard_application_quit(self, FALSE);
+			}
+
+		/* Release allocated resources */
+		if(optionSwitchToView) g_free(optionSwitchToView);
 
 		/* Stop here because option was handled and application does not get initialized */
 		return(XFDASHBOARD_APPLICATION_ERROR_NONE);
@@ -547,14 +615,30 @@ static int _xfdashboard_application_command_line(GApplication *inApplication, GA
 	if(!priv->inited)
 	{
 		/* Perform full initialization of this application instance */
-		result=_xfdashboard_application_initialize_full(self);
+		result=_xfdashboard_application_initialize_full(self, &stage);
 		if(result==FALSE) return(XFDASHBOARD_APPLICATION_ERROR_FAILED);
+
+		/* Switch to view if requested */
+		_xfdashboard_application_switch_to_view(self, optionSwitchToView);
+
+		/* Show application if not started daemonized */
+		if(!priv->isDaemon) clutter_actor_show(CLUTTER_ACTOR(stage));
 	}
 
 	/* Check if this instance need to be activated. Is should only be done
 	 * if instance is initialized
 	 */
-	if(priv->inited) _xfdashboard_application_activate(inApplication);
+	if(priv->inited)
+	{
+		/* Switch to view if requested */
+		_xfdashboard_application_switch_to_view(self, optionSwitchToView);
+
+		/* Show application */
+		_xfdashboard_application_activate(inApplication);
+	}
+
+	/* Release allocated resources */
+	if(optionSwitchToView) g_free(optionSwitchToView);
 
 	/* All done successfully so return status code 0 for success */
 	priv->inited=TRUE;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list