[gnome-shell] [ShellApp] refactor handling startup sequence



commit 6925a82204d1654d6f8efe5d9770dc9905bd50f4
Author: Maxim Ermilov <zaspire rambler ru>
Date:   Thu Oct 7 01:30:30 2010 +0400

    [ShellApp] refactor handling startup sequence
    
    1. move logic to shell-app.c
    2. change state to RUNNING only after startup sequence complete
    3. correct handle state for applications with several .desktop files
    https://bugzilla.gnome.org/show_bug.cgi?id=623688

 src/shell-app-private.h    |    5 +++-
 src/shell-app.c            |   45 ++++++++++++++++++++++++++++++-------------
 src/shell-window-tracker.c |   20 +------------------
 3 files changed, 36 insertions(+), 34 deletions(-)
---
diff --git a/src/shell-app-private.h b/src/shell-app-private.h
index 664c7a1..052dfbc 100644
--- a/src/shell-app-private.h
+++ b/src/shell-app-private.h
@@ -5,6 +5,9 @@
 #include "shell-app.h"
 #include "shell-app-system.h"
 
+#define SN_API_NOT_YET_FROZEN 1
+#include <libsn/sn.h>
+
 G_BEGIN_DECLS
 
 ShellAppInfo *_shell_app_get_info (ShellApp *app);
@@ -13,7 +16,7 @@ ShellApp* _shell_app_new_for_window (MetaWindow *window);
 
 ShellApp* _shell_app_new (ShellAppInfo *appinfo);
 
-void _shell_app_set_starting (ShellApp *app, gboolean starting);
+void _shell_app_handle_startup_sequence (ShellApp *app, SnStartupSequence *sequence);
 
 void _shell_app_add_window (ShellApp *app, MetaWindow *window);
 
diff --git a/src/shell-app.c b/src/shell-app.c
index 566b1e7..ad32636 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -665,15 +665,11 @@ shell_app_state_transition (ShellApp      *app,
                       state == SHELL_APP_STATE_STARTING));
   app->state = state;
 
-  if (app->state != SHELL_APP_STATE_RUNNING && app->running_state)
+  if (app->state == SHELL_APP_STATE_STOPPED && app->running_state)
     {
       unref_running_state (app->running_state);
       app->running_state = NULL;
     }
-  else if (app->state == SHELL_APP_STATE_RUNNING)
-    {
-      create_running_state (app);
-    }
 
   _shell_window_tracker_notify_app_state_changed (shell_window_tracker_get_default (), app);
 
@@ -733,11 +729,11 @@ _shell_app_add_window (ShellApp        *app,
 
   g_object_freeze_notify (G_OBJECT (app));
 
-  /* Ensure we've initialized running state */
-  if (app->state != SHELL_APP_STATE_RUNNING)
+  if (app->state != SHELL_APP_STATE_STARTING)
     shell_app_state_transition (app, SHELL_APP_STATE_RUNNING);
 
-  g_assert (app->running_state != NULL);
+  if (!app->running_state)
+      create_running_state (app);
 
   app->running_state->window_sort_stale = TRUE;
   app->running_state->windows = g_slist_prepend (app->running_state->windows, g_object_ref (window));
@@ -800,13 +796,34 @@ shell_app_get_pids (ShellApp *app)
 }
 
 void
-_shell_app_set_starting (ShellApp        *app,
-                         gboolean         starting)
+_shell_app_handle_startup_sequence (ShellApp          *app,
+                                    SnStartupSequence *sequence)
 {
-  if (starting && app->state == SHELL_APP_STATE_STOPPED)
-    shell_app_state_transition (app, SHELL_APP_STATE_STARTING);
-  else if (!starting && app->state == SHELL_APP_STATE_STARTING)
-    shell_app_state_transition (app, SHELL_APP_STATE_RUNNING);
+  gboolean starting = !sn_startup_sequence_get_completed (sequence);
+
+  /* The Shell design calls for on application launch, the app title
+   * appears at top, and no X window is focused.  So when we get
+   * a startup-notification for this app, transition it to STARTING
+   * if it's currently stopped, set it as our application focus,
+   * but focus the no_focus window.
+   */
+  if (starting && shell_app_get_state (app) == SHELL_APP_STATE_STOPPED)
+    {
+      MetaScreen *screen = shell_global_get_screen (shell_global_get ());
+      MetaDisplay *display = meta_screen_get_display (screen);
+
+      shell_app_state_transition (app, SHELL_APP_STATE_STARTING);
+      meta_display_focus_the_no_focus_window (display, screen,
+                                              sn_startup_sequence_get_timestamp (sequence));
+    }
+
+  if (!starting)
+    {
+      if (app->running_state && app->running_state->windows)
+        shell_app_state_transition (app, SHELL_APP_STATE_RUNNING);
+      else /* application have > 1 .desktop file */
+        shell_app_state_transition (app, SHELL_APP_STATE_STOPPED);
+    }
 }
 
 /**
diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c
index c187bd2..cb276e4 100644
--- a/src/shell-window-tracker.c
+++ b/src/shell-window-tracker.c
@@ -658,25 +658,7 @@ on_startup_sequence_changed (MetaScreen            *screen,
 
   app = shell_startup_sequence_get_app ((ShellStartupSequence*)sequence);
   if (app)
-    {
-      gboolean starting = !sn_startup_sequence_get_completed (sequence);
-
-      /* The Shell design calls for on application launch, the app title
-       * appears at top, and no X window is focused.  So when we get
-       * a startup-notification for this app, transition it to STARTING
-       * if it's currently stopped, set it as our application focus,
-       * but focus the no_focus window.
-       */
-      if (starting && shell_app_get_state (app) == SHELL_APP_STATE_STOPPED)
-        {
-          MetaScreen *screen = shell_global_get_screen (shell_global_get ());
-          MetaDisplay *display = meta_screen_get_display (screen);
-
-          _shell_app_set_starting (app, starting);
-          meta_display_focus_the_no_focus_window (display, screen,
-                                                  sn_startup_sequence_get_timestamp (sequence));
-        }
-    }
+    _shell_app_handle_startup_sequence (app, sequence);
 
   g_signal_emit (G_OBJECT (self), signals[STARTUP_SEQUENCE_CHANGED], 0, sequence);
 }



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