[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
This commit is contained in:
Maxim Ermilov 2010-10-07 01:30:30 +04:00
parent 64efa61dc2
commit 6925a82204
3 changed files with 36 additions and 34 deletions

View File

@ -5,6 +5,9 @@
#include "shell-app.h" #include "shell-app.h"
#include "shell-app-system.h" #include "shell-app-system.h"
#define SN_API_NOT_YET_FROZEN 1
#include <libsn/sn.h>
G_BEGIN_DECLS G_BEGIN_DECLS
ShellAppInfo *_shell_app_get_info (ShellApp *app); 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); 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); void _shell_app_add_window (ShellApp *app, MetaWindow *window);

View File

@ -665,15 +665,11 @@ shell_app_state_transition (ShellApp *app,
state == SHELL_APP_STATE_STARTING)); state == SHELL_APP_STATE_STARTING));
app->state = state; 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); unref_running_state (app->running_state);
app->running_state = NULL; 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); _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)); g_object_freeze_notify (G_OBJECT (app));
/* Ensure we've initialized running state */ if (app->state != SHELL_APP_STATE_STARTING)
if (app->state != SHELL_APP_STATE_RUNNING)
shell_app_state_transition (app, SHELL_APP_STATE_RUNNING); 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->window_sort_stale = TRUE;
app->running_state->windows = g_slist_prepend (app->running_state->windows, g_object_ref (window)); 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 void
_shell_app_set_starting (ShellApp *app, _shell_app_handle_startup_sequence (ShellApp *app,
gboolean starting) SnStartupSequence *sequence)
{ {
if (starting && app->state == SHELL_APP_STATE_STOPPED) gboolean starting = !sn_startup_sequence_get_completed (sequence);
shell_app_state_transition (app, SHELL_APP_STATE_STARTING);
else if (!starting && app->state == SHELL_APP_STATE_STARTING) /* The Shell design calls for on application launch, the app title
shell_app_state_transition (app, SHELL_APP_STATE_RUNNING); * 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);
}
} }
/** /**

View File

@ -658,25 +658,7 @@ on_startup_sequence_changed (MetaScreen *screen,
app = shell_startup_sequence_get_app ((ShellStartupSequence*)sequence); app = shell_startup_sequence_get_app ((ShellStartupSequence*)sequence);
if (app) if (app)
{ _shell_app_handle_startup_sequence (app, sequence);
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));
}
}
g_signal_emit (G_OBJECT (self), signals[STARTUP_SEQUENCE_CHANGED], 0, sequence); g_signal_emit (G_OBJECT (self), signals[STARTUP_SEQUENCE_CHANGED], 0, sequence);
} }