static void
on_startup_sequence_changed (MetaScreen            *screen,
                             SnStartupSequence     *sequence,
                             ShellWindowTracker    *self)
{
  ShellApp *app;

  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);
          long tv_sec, tv_usec;

          sn_startup_sequence_get_initiated_time (sequence, &tv_sec, &tv_usec);

          _shell_app_set_starting (app, starting);
          set_focus_app (self, app);
          meta_display_focus_the_no_focus_window (display, screen, tv_sec);
        }
    }

  g_signal_emit (G_OBJECT (self), signals[STARTUP_SEQUENCE_CHANGED], 0, sequence);
}
static void
update_focus_app (ShellWindowTracker *self)
{
  MetaWindow *new_focus_win;
  ShellApp *new_focus_app;

  new_focus_win = meta_display_get_focus_window (shell_global_get_display (shell_global_get ()));

  /* we only consider an app focused if the focus window can be clearly
   * associated with a running app; this is the case if the focus window
   * or one of its parents is visible in the taskbar, e.g.
   *   - 'nautilus' should appear focused when its about dialog has focus
   *   - 'nautilus' should not appear focused when the DESKTOP has focus
   */
  while (new_focus_win && meta_window_is_skip_taskbar (new_focus_win))
    new_focus_win = meta_window_get_transient_for (new_focus_win);

  new_focus_app = new_focus_win ? shell_window_tracker_get_window_app (self, new_focus_win) : NULL;

  if (new_focus_app)
    {
      shell_app_update_window_actions (new_focus_app, new_focus_win);
      shell_app_update_app_menu (new_focus_app, new_focus_win);
    }

  set_focus_app (self, new_focus_app);
}
static void
update_focus_app (ShellWindowTracker *self)
{
  MetaWindow *new_focus_win;
  ShellApp *new_focus_app;

  new_focus_win = meta_display_get_focus_window (meta_screen_get_display (shell_global_get_screen (shell_global_get ())));
  new_focus_app = new_focus_win ? shell_window_tracker_get_window_app (self, new_focus_win) : NULL;

  set_focus_app (self, new_focus_app);
}
static void
update_focus_app (CinnamonWindowTracker *self)
{
  MetaWindow *new_focus_win;
  CinnamonApp *new_focus_app;

  new_focus_win = meta_display_get_focus_window (cinnamon_global_get_display (cinnamon_global_get ()));
  new_focus_app = new_focus_win ? cinnamon_window_tracker_get_window_app (self, new_focus_win) : NULL;

  set_focus_app (self, new_focus_app);
}
static void
on_focus_window_changed (MetaDisplay        *display,
                         GParamSpec         *spec,
                         ShellWindowTracker *tracker)
{
  MetaScreen *screen;
  MetaWindow *new_focus_win;
  ShellApp *new_focus_app;

  screen = shell_global_get_screen (shell_global_get ());

  new_focus_win = meta_display_get_focus_window (display);
  new_focus_app = new_focus_win ? g_hash_table_lookup (tracker->window_to_app, new_focus_win) : NULL;

  set_focus_app (tracker, new_focus_app);
}
static void
update_focus_app (ShellWindowTracker *self)
{
  MetaWindow *new_focus_win;
  ShellApp *new_focus_app;

  new_focus_win = meta_display_get_focus_window (shell_global_get_display (shell_global_get ()));
  new_focus_app = new_focus_win ? shell_window_tracker_get_window_app (self, new_focus_win) : NULL;

  if (new_focus_app)
    {
      shell_app_update_window_actions (new_focus_app, new_focus_win);
      shell_app_update_app_menu (new_focus_app, new_focus_win);
    }

  set_focus_app (self, new_focus_app);
}