static void
ntf_wm_handle_demands_attention (MetaWindow *window)
{
  NtfTray         *tray;
  NtfNotification *ntf;
  NtfSource       *src = NULL;
  gint             pid;
  const gchar     *machine;
  gint             id;

  g_return_if_fail (META_IS_WINDOW (window));

  id      = GPOINTER_TO_INT (window);
  pid     = meta_window_get_pid (window);
  machine = meta_window_get_client_machine (window);

  tray = ntf_overlay_get_tray (FALSE);

  ntf = ntf_tray_find_notification (tray, subsystem_id, id);

  if (!ntf)
    {
      gchar *srcid = g_strdup_printf ("application-%d@%s", pid, machine);

      g_debug ("creating new notification for source %s", srcid);

      if (!(src = ntf_sources_find_for_id (srcid)))
        {
          if ((src = ntf_source_new_for_pid (machine, pid)))
            ntf_sources_add (src);
        }

      if (src)
        ntf = ntf_notification_new (src, subsystem_id, id, FALSE);

      if (ntf)
        {
          g_signal_connect (ntf, "closed",
                            G_CALLBACK (ntf_wm_ntf_closed_cb),
                            NULL);

          ntf_wm_update_notification (ntf, window);
          ntf_tray_add_notification (tray, ntf);
        }

      g_free (srcid);
    }
  else
    {
      g_debug ("updating existing notification");
      ntf_wm_update_notification (ntf, window);
    }

  g_signal_connect (window, "notify::demands-attention",
                    G_CALLBACK (ntf_wm_meta_window_demands_attention_cb),
                    NULL);
  g_signal_connect (window, "notify::urgent",
                    G_CALLBACK (ntf_wm_meta_window_demands_attention_cb),
                    NULL);
}
/**
 * shell_app_system_get_from_pid:
 * @self; A #ShellAppSystem
 * @pid: A Unix process identifier
 *
 * Look up the application corresponding to a process.
 *
 * Returns: (transfer full): A #ShellApp, or %NULL if none
 */
ShellApp *
shell_window_tracker_get_app_from_pid (ShellWindowTracker *self, 
                                       int                 pid)
{
  ShellGlobal *global = shell_global_get ();
  GList *windows, *iter;
  
  windows = shell_global_get_windows (global);
  for (iter = windows; iter; iter = iter->next)
    {
      MutterWindow *win = iter->data;
      MetaWindow *metawin;
      int windowpid;
      ShellApp *app;
      
      metawin = mutter_window_get_meta_window (win);
      windowpid = meta_window_get_pid (metawin);
      if (windowpid != pid)
        continue;
      
      app = shell_window_tracker_get_window_app (self, metawin);
      if (app)
        return app;
    }
  return NULL;
}
/*
 * get_app_from_window_pid:
 * @tracker: a #ShellWindowTracker
 * @window: a #MetaWindow
 *
 * Check if the pid associated with @window corresponds to an
 * application.
 *
 * Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
 */
static ShellApp *
get_app_from_window_pid (ShellWindowTracker  *tracker,
                         MetaWindow          *window)
{
  ShellApp *result;
  int pid;

  if (meta_window_is_remote (window))
    return NULL;

  pid = meta_window_get_pid (window);

  if (pid == -1)
    return NULL;

  result = shell_window_tracker_get_app_from_pid (tracker, pid);

  if (result == NULL)
    result = g_hash_table_lookup (tracker->launched_pid_to_app, GINT_TO_POINTER (pid));

  if (result != NULL)
    g_object_ref (result);

  return result;
}
Beispiel #4
0
/**
 * cinnamon_app_get_pids:
 * @app: a #CinnamonApp
 *
 * Returns: (transfer container) (element-type int): An unordered list of process identifiers associated with this application.
 */
GSList *
cinnamon_app_get_pids (CinnamonApp *app)
{
  GSList *result;
  GSList *iter;

  result = NULL;
  for (iter = cinnamon_app_get_windows (app); iter; iter = iter->next)
    {
      MetaWindow *window = iter->data;
      int pid = meta_window_get_pid (window);
      /* Note in the (by far) common case, app will only have one pid, so
       * we'll hit the first element, so don't worry about O(N^2) here.
       */
      if (!g_slist_find (result, GINT_TO_POINTER (pid)))
        result = g_slist_prepend (result, GINT_TO_POINTER (pid));
    }
  return result;
}