[gedit/dbus] Make distinction between running gedit as a service and not



commit 85a22e1f67059b59d94ce019f128d27a1f882c6a
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Mon May 3 21:39:53 2010 +0200

    Make distinction between running gedit as a service and not
    
    When gedit is started as a service, it initially does not show a window.
    This is because it really makes no sense to display a window on a
    random display somewhere. The first Open call will construct a window
    at the right display/workspace/viewport etc.

 gedit/gedit-dbus.c |   16 +++++++++++++---
 gedit/gedit-dbus.h |    3 ++-
 gedit/gedit.c      |   13 ++++++++-----
 3 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/gedit/gedit-dbus.c b/gedit/gedit-dbus.c
index 0b96a58..c86a61e 100644
--- a/gedit/gedit-dbus.c
+++ b/gedit/gedit-dbus.c
@@ -384,7 +384,16 @@ static GeditDBusResult
 handle_master (GeditDBus *dbus)
 {
 	/* let the main gedit thing do its thing */
-	return GEDIT_DBUS_RESULT_PROCEED;
+	if (g_getenv ("DBUS_STARTER_ADDRESS"))
+	{
+		/* started as a service, we don't want to popup a window on
+		   some random display */
+		return GEDIT_DBUS_RESULT_PROCEED_NOWINDOW;
+	}
+	else
+	{
+		return GEDIT_DBUS_RESULT_PROCEED;
+	}
 }
 
 static GeditDBusResult
@@ -915,7 +924,8 @@ gedit_dbus_run (GeditDBus *dbus)
 			/* we are the main gedit process */
 			return handle_master (dbus);
 		break;
+		default:
+			g_assert_not_reached ();
+		break;
 	}
-
-	g_assert_not_reached ();
 }
diff --git a/gedit/gedit-dbus.h b/gedit/gedit-dbus.h
index 9532c3c..687dbb1 100644
--- a/gedit/gedit-dbus.h
+++ b/gedit/gedit-dbus.h
@@ -43,7 +43,8 @@ typedef enum
 {
 	GEDIT_DBUS_RESULT_SUCCESS,
 	GEDIT_DBUS_RESULT_FAILED,
-	GEDIT_DBUS_RESULT_PROCEED
+	GEDIT_DBUS_RESULT_PROCEED,
+	GEDIT_DBUS_RESULT_PROCEED_NOWINDOW
 } GeditDBusResult;
 
 struct _GeditDBus {
diff --git a/gedit/gedit.c b/gedit/gedit.c
index d8e174a..e1084ec 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -65,7 +65,7 @@
 #endif
 
 static void
-gedit_main (GeditCommandLine *command_line)
+gedit_main (GeditCommandLine *command_line, gboolean service)
 {
 	GeditPluginsEngine *engine;
 	GeditWindow *window;
@@ -107,12 +107,12 @@ gedit_main (GeditCommandLine *command_line)
 	gedit_win32_prepare (app);
 	gedit_osx_prepare (app);
 
-	if (gedit_session_is_restored ())
+	if (!service && gedit_session_is_restored ())
 	{
 		restored = gedit_session_load ();
 	}
 
-	if (!restored)
+	if (!service && !restored)
 	{
 		GSList *file_list;
 
@@ -155,7 +155,6 @@ gedit_main (GeditCommandLine *command_line)
 #endif
 }
 
-
 int
 main (int argc, char *argv[])
 {
@@ -164,6 +163,7 @@ main (int argc, char *argv[])
 	gboolean ret;
 	GeditDBus *dbus;
 	GeditDBusResult dbusret;
+	gboolean service = FALSE;
 
 	/* Init type system as soon as possible */
 	g_type_init ();
@@ -221,9 +221,12 @@ main (int argc, char *argv[])
 		break;
 		case GEDIT_DBUS_RESULT_PROCEED:
 		break;
+		case GEDIT_DBUS_RESULT_PROCEED_NOWINDOW:
+			service = TRUE;
+		break;
 	}
 
-	gedit_main (command_line);
+	gedit_main (command_line, service);
 
 	g_object_unref (dbus);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]