[gnome-terminal/gsettings] server: Allow opening a new tab in an existing window



commit d45bdf8b938812c67cdbdf8bfab0ae58c4d9a9ac
Author: Christian Persch <chpe gnome org>
Date:   Thu May 3 18:29:17 2012 +0200

    server: Allow opening a new tab in an existing window

 configure.ac         |    4 +-
 src/client.c         |    2 +-
 src/server.c         |    4 +-
 src/terminal-app.c   |    9 ++-
 src/terminal-app.h   |    2 +-
 src/terminal-gdbus.c |  145 ++++++++++++++++++++++++++++----------------------
 6 files changed, 93 insertions(+), 73 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 12fc15a..f0dbbb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,7 +38,7 @@ GNOME_DEBUG_CHECK
 AM_GLIB_GNU_GETTEXT
 
 GLIB_REQUIRED=2.32.0
-GIO_REQUIRED=2.32.0
+GIO_REQUIRED=2.33.1
 GSETTINGS_DESKTOP_SCHEMAS_REQUIRED=0.1.0
 
 AC_MSG_CHECKING([which gtk+ version to compile against])
@@ -54,7 +54,7 @@ AC_MSG_RESULT([$with_gtk])
 
 case "$with_gtk" in
   3.0) GTK_API_VERSION=3.0
-       GTK_REQUIRED=3.4.0
+       GTK_REQUIRED=3.5.3
        VTE_PC_VERSION=-2.90
        VTE_REQUIRED=0.32.1
        ;;
diff --git a/src/client.c b/src/client.c
index 1fde9fc..0668eeb 100644
--- a/src/client.c
+++ b/src/client.c
@@ -687,7 +687,7 @@ handle_open (int *argc,
     g_dbus_error_strip_remote_error (error);
     _printerr ("Error: %s\n", error->message);
     g_error_free (error);
-    g_clear_object (fd_list);
+    g_clear_object (&fd_list);
     g_object_unref (receiver);
     option_data_free (data);
     return FALSE;
diff --git a/src/server.c b/src/server.c
index 89ad33f..23078c8 100644
--- a/src/server.c
+++ b/src/server.c
@@ -166,8 +166,7 @@ main (int argc, char **argv)
     exit (EXIT_FAILURE);
   }
 
-  data.app = terminal_app_new (bus_name ? bus_name : TERMINAL_UNIQUE_NAME);
-
+  data.app = terminal_app_new ();
   data.loop = g_main_loop_new (NULL, FALSE);
   data.owns_name = FALSE;
 
@@ -193,6 +192,7 @@ main (int argc, char **argv)
 
 out:
 
+  g_free (bus_name);
   terminal_app_shutdown ();
 
   return exit_code;
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 6623aac..b96cbdb 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -1325,11 +1325,14 @@ terminal_app_class_init (TerminalAppClass *klass)
 /* Public API */
 
 GApplication *
-terminal_app_new (const char *id)
+terminal_app_new (void)
 {
+  const GApplicationFlags flags = G_APPLICATION_NON_UNIQUE |
+                                  G_APPLICATION_IS_SERVICE;
+
   return g_object_new (TERMINAL_TYPE_APP,
-                       "application-id", id,
-                       "flags", (glong) (G_APPLICATION_NON_UNIQUE | G_APPLICATION_IS_SERVICE),
+                       "application-id", TERMINAL_UNIQUE_NAME,
+                       "flags", flags,
                        NULL);
 }
 
diff --git a/src/terminal-app.h b/src/terminal-app.h
index 17dbae9..855a9cd 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -48,7 +48,7 @@ typedef struct _TerminalApp TerminalApp;
 
 GType terminal_app_get_type (void);
 
-GApplication *terminal_app_new (const char *id);
+GApplication *terminal_app_new (void);
 
 TerminalApp* terminal_app_get (void);
 
diff --git a/src/terminal-gdbus.c b/src/terminal-gdbus.c
index 9e1ecf0..15fb69e 100644
--- a/src/terminal-gdbus.c
+++ b/src/terminal-gdbus.c
@@ -355,73 +355,82 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
   TerminalObjectSkeleton *skeleton;
   char *object_path;
   GSettings *profile = NULL;
-  GdkScreen *gdk_screen;
-  const char *startup_id, *display_name;
-  char *role, *geometry, *profile_name, *title;
-  int screen_number;
-  gboolean start_maximized, start_fullscreen;
-  gboolean present_window, present_window_set = FALSE;
+  const char *profile_name, *title;
   gboolean zoom_set = FALSE;
   gdouble zoom = 1.0;
-
+  guint window_id;
   gboolean active = TRUE;
+  gboolean have_new_window, present_window, present_window_set;
 
-  if (!g_variant_lookup (options, "display", "^&ay", &display_name)) {
-    g_dbus_method_invocation_return_error (invocation, 
-                                           G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
-                                           "No display specified");
-    goto out;
-  }
+  if (g_variant_lookup (options, "window-id", "u", &window_id)) {
+    GtkWindow *win;
 
-  screen_number = 0;
-  gdk_screen = terminal_util_get_screen_by_display_name (display_name, screen_number);
-  if (gdk_screen == NULL) {
-    g_dbus_method_invocation_return_error (invocation, 
-                                           G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
-                                           "No screen %d on display \"%s\"",
-                                           screen_number, display_name);
-    goto out;
-  }
+    win = gtk_application_get_window_by_id (GTK_APPLICATION (app), window_id);
 
-  if (!g_variant_lookup (options, "desktop-startup-id", "^&ay", &startup_id))
-    startup_id = NULL;
-  if (!g_variant_lookup (options, "geometry", "&s", &geometry))
-    geometry = NULL;
-  if (!g_variant_lookup (options, "role", "&s", &role))
-    role = NULL;
-  if (!g_variant_lookup (options, "maximize-window", "b", &start_maximized))
-    start_maximized = FALSE;
-  if (!g_variant_lookup (options, "fullscreen-window", "b", &start_fullscreen))
-    start_fullscreen = FALSE;
-  if (!g_variant_lookup (options, "profile", "&s", &profile_name))
-    profile_name = NULL;
-  if (!g_variant_lookup (options, "title", "&s", &title))
-    title = NULL;
+    if (!TERMINAL_IS_WINDOW (win)) {
+      g_dbus_method_invocation_return_error (invocation,
+                                             G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+                                             "Nonexisting window %u referenced",
+                                             window_id);
+      goto out;
+    }
 
-  if (g_variant_lookup (options, "present-window", "b", &present_window)) {
-    present_window_set = TRUE;
-  }
-  if (g_variant_lookup (options, "zoom", "d", &zoom)) {
-    zoom_set = TRUE;
-  }
+    window = TERMINAL_WINDOW (win);
+    have_new_window = FALSE;
+  } else {
+    const char *startup_id, *display_name, *role;
+    gboolean start_maximized, start_fullscreen;
+    int screen_number;
+    GdkScreen *gdk_screen;
+
+    /* Create a new window */
+
+    if (!g_variant_lookup (options, "display", "^&ay", &display_name)) {
+      g_dbus_method_invocation_return_error (invocation, 
+                                             G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+                                             "No display specified");
+      goto out;
+    }
 
-  window = terminal_app_new_window (app, gdk_screen);
+    screen_number = 0;
+    gdk_screen = terminal_util_get_screen_by_display_name (display_name, screen_number);
+    if (gdk_screen == NULL) {
+      g_dbus_method_invocation_return_error (invocation, 
+                                             G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+                                             "No screen %d on display \"%s\"",
+                                             screen_number, display_name);
+      goto out;
+    }
 
-  /* Restored windows shouldn't demand attention; see bug #586308. */
-  if (present_window_set && !present_window)
-    terminal_window_set_is_restored (window);
+    window = terminal_app_new_window (app, gdk_screen);
 
-  if (startup_id != NULL)
-    gtk_window_set_startup_id (GTK_WINDOW (window), startup_id);
+    if (g_variant_lookup (options, "desktop-startup-id", "^&ay", &startup_id))
+      gtk_window_set_startup_id (GTK_WINDOW (window), startup_id);
 
-  /* Overwrite the default, unique window role set in terminal_window_init */
-  if (role)
-    gtk_window_set_role (GTK_WINDOW (window), role);
+    /* Overwrite the default, unique window role set in terminal_window_init */
+    if (g_variant_lookup (options, "role", "&s", &role))
+      gtk_window_set_role (GTK_WINDOW (window), role);
 
-  if (start_fullscreen)
-    gtk_window_fullscreen (GTK_WINDOW (window));
-  if (start_maximized)
-    gtk_window_maximize (GTK_WINDOW (window));
+    if (g_variant_lookup (options, "fullscreen-window", "b", &start_fullscreen) &&
+        start_fullscreen) {
+      gtk_window_fullscreen (GTK_WINDOW (window));
+    }
+    if (g_variant_lookup (options, "maximize-window", "b", &start_maximized) &&
+        start_maximized) {
+      gtk_window_maximize (GTK_WINDOW (window));
+    }
+
+    have_new_window = TRUE;
+  }
+
+  g_assert (window != NULL);
+
+  if (!g_variant_lookup (options, "profile", "&s", &profile_name))
+    profile_name = NULL;
+  if (!g_variant_lookup (options, "title", "&s", &title))
+    title = NULL;
+  if (g_variant_lookup (options, "zoom", "d", &zoom))
+    zoom_set = TRUE;
 
   profile = terminal_app_get_profile (app, profile_name);
   g_assert (profile);
@@ -450,18 +459,26 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
   if (active)
     terminal_window_switch_screen (window, screen);
 
-  if (geometry)
-    {
+  if (g_variant_lookup (options, "present-window", "b", &present_window))
+    present_window_set = TRUE;
+  else
+    present_window_set = FALSE;
+
+  if (have_new_window) {
+    const char *geometry;
+
+    if (g_variant_lookup (options, "geometry", "&s", &geometry) &&
+        !terminal_window_parse_geometry (window, geometry))
       _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
-                            "[window %p] applying geometry %s\n",
-                            window, geometry);
+                             "Invalid geometry string \"%s\"", geometry);
 
-      if (!terminal_window_parse_geometry (window, geometry))
-        _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
-                               "Invalid geometry string \"%s\"", geometry);
-    }
+    /* Restored windows shouldn't demand attention; see bug #586308. */
+    if (present_window_set && !present_window)
+      terminal_window_set_is_restored (window);
+  }
 
-  gtk_window_present (GTK_WINDOW (window));
+  if (have_new_window || (present_window_set && present_window))
+    gtk_window_present (GTK_WINDOW (window));
 
   terminal_factory_complete_create_instance (factory, invocation, object_path);
 



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