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
|
void
|
||||||
_shell_app_set_starting (ShellApp *app,
|
_shell_app_set_starting (ShellApp *app,
|
||||||
gboolean starting)
|
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_windows (ShellApp *app);
|
||||||
|
|
||||||
|
GSList *shell_app_get_pids (ShellApp *app);
|
||||||
|
|
||||||
gboolean shell_app_is_on_workspace (ShellApp *app, MetaWorkspace *workspace);
|
gboolean shell_app_is_on_workspace (ShellApp *app, MetaWorkspace *workspace);
|
||||||
|
|
||||||
int shell_app_compare (ShellApp *app, ShellApp *other);
|
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.
|
* 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 *
|
ShellApp *
|
||||||
shell_window_tracker_get_app_from_pid (ShellWindowTracker *self,
|
shell_window_tracker_get_app_from_pid (ShellWindowTracker *self,
|
||||||
int pid)
|
int pid)
|
||||||
{
|
{
|
||||||
ShellGlobal *global = shell_global_get ();
|
GSList *running = shell_window_tracker_get_running_apps (self, "");
|
||||||
GList *windows, *iter;
|
GSList *iter;
|
||||||
|
ShellApp *result = NULL;
|
||||||
|
|
||||||
windows = shell_global_get_windows (global);
|
for (iter = running; iter; iter = iter->next)
|
||||||
for (iter = windows; iter; iter = iter->next)
|
|
||||||
{
|
{
|
||||||
MutterWindow *win = iter->data;
|
ShellApp *app = iter->data;
|
||||||
MetaWindow *metawin;
|
GSList *pids = shell_app_get_pids (app);
|
||||||
int windowpid;
|
GSList *pids_iter;
|
||||||
ShellApp *app;
|
|
||||||
|
|
||||||
metawin = mutter_window_get_meta_window (win);
|
for (pids_iter = pids; pids_iter; pids_iter = pids_iter->next)
|
||||||
windowpid = meta_window_get_pid (metawin);
|
{
|
||||||
if (windowpid != pid)
|
int app_pid = GPOINTER_TO_INT (pids_iter->data);
|
||||||
continue;
|
if (app_pid == pid)
|
||||||
|
{
|
||||||
app = shell_window_tracker_get_window_app (self, metawin);
|
result = app;
|
||||||
if (app)
|
break;
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
}
|
||||||
|
g_slist_free (pids);
|
||||||
|
|
||||||
|
if (result != NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_slist_free (running);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user