Associate process identifiers with applications
Cache the set of pids for an application, in preparation for landing an XSMP patch which requires this information. https://bugzilla.gnome.org/show_bug.cgi?id=619542
This commit is contained in:
parent
e4a6bf994f
commit
bf6d0dc808
@ -739,6 +739,32 @@ _shell_app_remove_window (ShellApp *app,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* shell_app_get_pids:
|
||||
* @app: a #ShellApp
|
||||
*
|
||||
* Returns: (transfer container) (element-type int): An unordered list of process identifers associated with this application.
|
||||
*/
|
||||
GSList *
|
||||
shell_app_get_pids (ShellApp *app)
|
||||
{
|
||||
GSList *result;
|
||||
GSList *iter;
|
||||
|
||||
result = NULL;
|
||||
for (iter = shell_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;
|
||||
}
|
||||
|
||||
void
|
||||
_shell_app_set_starting (ShellApp *app,
|
||||
gboolean starting)
|
||||
|
@ -56,6 +56,8 @@ guint shell_app_get_n_windows (ShellApp *app);
|
||||
|
||||
GSList *shell_app_get_windows (ShellApp *app);
|
||||
|
||||
GSList *shell_app_get_pids (ShellApp *app);
|
||||
|
||||
gboolean shell_app_is_on_workspace (ShellApp *app, MetaWorkspace *workspace);
|
||||
|
||||
int shell_app_compare (ShellApp *app, ShellApp *other);
|
||||
|
@ -746,33 +746,40 @@ shell_window_tracker_get_window_app (ShellWindowTracker *monitor,
|
||||
*
|
||||
* Look up the application corresponding to a process.
|
||||
*
|
||||
* Returns: (transfer full): A #ShellApp, or %NULL if none
|
||||
* Returns: (transfer none): 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;
|
||||
GSList *running = shell_window_tracker_get_running_apps (self, "");
|
||||
GSList *iter;
|
||||
ShellApp *result = NULL;
|
||||
|
||||
windows = shell_global_get_windows (global);
|
||||
for (iter = windows; iter; iter = iter->next)
|
||||
for (iter = running; iter; iter = iter->next)
|
||||
{
|
||||
MutterWindow *win = iter->data;
|
||||
MetaWindow *metawin;
|
||||
int windowpid;
|
||||
ShellApp *app;
|
||||
ShellApp *app = iter->data;
|
||||
GSList *pids = shell_app_get_pids (app);
|
||||
GSList *pids_iter;
|
||||
|
||||
metawin = mutter_window_get_meta_window (win);
|
||||
windowpid = meta_window_get_pid (metawin);
|
||||
if (windowpid != pid)
|
||||
continue;
|
||||
for (pids_iter = pids; pids_iter; pids_iter = pids_iter->next)
|
||||
{
|
||||
int app_pid = GPOINTER_TO_INT (pids_iter->data);
|
||||
if (app_pid == pid)
|
||||
{
|
||||
result = app;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_slist_free (pids);
|
||||
|
||||
app = shell_window_tracker_get_window_app (self, metawin);
|
||||
if (app)
|
||||
return app;
|
||||
if (result != NULL)
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
g_slist_free (running);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user