2009-10-15 23:28:29 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2009-11-24 14:07:40 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-03-05 15:49:24 +00:00
|
|
|
#include <meta/display.h>
|
|
|
|
#include <meta/group.h>
|
|
|
|
#include <meta/util.h>
|
|
|
|
#include <meta/window.h>
|
2018-01-03 07:55:38 +00:00
|
|
|
#include <meta/meta-workspace-manager.h>
|
2018-08-22 22:00:36 +00:00
|
|
|
#include <meta/meta-startup-notification.h>
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2010-06-07 20:31:30 +00:00
|
|
|
#include "shell-window-tracker-private.h"
|
2009-10-15 23:28:29 +00:00
|
|
|
#include "shell-app-private.h"
|
|
|
|
#include "shell-global.h"
|
2010-10-31 19:39:32 +00:00
|
|
|
#include "st.h"
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
/* This file includes modified code from
|
|
|
|
* desktop-data-engine/engine-dbus/hippo-application-monitor.c
|
|
|
|
* in the functions collecting application usage data.
|
|
|
|
* Written by Owen Taylor, originally licensed under LGPL 2.1.
|
|
|
|
* Copyright Red Hat, Inc. 2006-2008
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:shell-window-tracker
|
|
|
|
* @short_description: Associate windows with applications
|
|
|
|
*
|
|
|
|
* Maintains a mapping from windows to applications (.desktop file ids).
|
|
|
|
* It currently implements this with some heuristics on the WM_CLASS X11
|
|
|
|
* property (and some static override regexps); in the future, we want to
|
|
|
|
* have it also track through startup-notification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct _ShellWindowTracker
|
|
|
|
{
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
ShellApp *focus_app;
|
|
|
|
|
|
|
|
/* <MetaWindow * window, ShellApp *app> */
|
|
|
|
GHashTable *window_to_app;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (ShellWindowTracker, shell_window_tracker, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_FOCUS_APP
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
STARTUP_SEQUENCE_CHANGED,
|
2010-04-20 18:47:45 +00:00
|
|
|
TRACKED_WINDOWS_CHANGED,
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static void shell_window_tracker_finalize (GObject *object);
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 18:07:44 +00:00
|
|
|
static void set_focus_app (ShellWindowTracker *tracker,
|
|
|
|
ShellApp *new_focus_app);
|
2009-10-15 23:28:29 +00:00
|
|
|
static void on_focus_window_changed (MetaDisplay *display, GParamSpec *spec, ShellWindowTracker *tracker);
|
|
|
|
|
2011-08-11 10:37:24 +00:00
|
|
|
static void track_window (ShellWindowTracker *tracker, MetaWindow *window);
|
|
|
|
static void disassociate_window (ShellWindowTracker *tracker, MetaWindow *window);
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2018-08-22 22:02:37 +00:00
|
|
|
static ShellApp * shell_startup_sequence_get_app (MetaStartupSequence *sequence);
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
shell_window_tracker_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellWindowTracker *tracker = SHELL_WINDOW_TRACKER (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FOCUS_APP:
|
|
|
|
g_value_set_object (value, tracker->focus_app);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_window_tracker_class_init (ShellWindowTrackerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->get_property = shell_window_tracker_get_property;
|
|
|
|
gobject_class->finalize = shell_window_tracker_finalize;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_FOCUS_APP,
|
|
|
|
g_param_spec_object ("focus-app",
|
|
|
|
"Focus App",
|
|
|
|
"Focused application",
|
|
|
|
SHELL_TYPE_APP,
|
2019-07-25 17:34:19 +00:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
signals[STARTUP_SEQUENCE_CHANGED] = g_signal_new ("startup-sequence-changed",
|
|
|
|
SHELL_TYPE_WINDOW_TRACKER,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2018-08-22 22:00:36 +00:00
|
|
|
G_TYPE_NONE, 1, META_TYPE_STARTUP_SEQUENCE);
|
2010-04-20 18:47:45 +00:00
|
|
|
signals[TRACKED_WINDOWS_CHANGED] = g_signal_new ("tracked-windows-changed",
|
|
|
|
SHELL_TYPE_WINDOW_TRACKER,
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2010-04-20 18:47:45 +00:00
|
|
|
G_TYPE_NONE, 0);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
2020-07-03 14:59:07 +00:00
|
|
|
static gboolean
|
|
|
|
check_app_id_prefix (ShellApp *app,
|
|
|
|
const char *prefix)
|
|
|
|
{
|
|
|
|
if (prefix == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return g_str_has_prefix (shell_app_get_id (app), prefix);
|
|
|
|
}
|
|
|
|
|
2014-01-04 16:33:20 +00:00
|
|
|
/*
|
2012-04-06 18:02:04 +00:00
|
|
|
* get_app_from_window_wmclass:
|
|
|
|
*
|
|
|
|
* Looks only at the given window, and attempts to determine
|
|
|
|
* an application based on WM_CLASS. If one can't be determined,
|
|
|
|
* return %NULL.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
|
|
|
|
*/
|
|
|
|
static ShellApp *
|
|
|
|
get_app_from_window_wmclass (MetaWindow *window)
|
|
|
|
{
|
|
|
|
ShellApp *app;
|
|
|
|
ShellAppSystem *appsys;
|
|
|
|
const char *wm_class;
|
|
|
|
const char *wm_instance;
|
2020-07-03 14:59:07 +00:00
|
|
|
const char *sandbox_id;
|
2020-07-08 09:59:13 +00:00
|
|
|
g_autofree char *app_prefix = NULL;
|
2012-04-06 18:02:04 +00:00
|
|
|
|
|
|
|
appsys = shell_app_system_get_default ();
|
2020-07-08 09:59:13 +00:00
|
|
|
|
2020-07-03 14:59:07 +00:00
|
|
|
sandbox_id = meta_window_get_sandboxed_app_id (window);
|
2020-07-08 09:59:13 +00:00
|
|
|
if (sandbox_id)
|
|
|
|
app_prefix = g_strdup_printf ("%s.", sandbox_id);
|
2012-04-06 18:02:04 +00:00
|
|
|
|
|
|
|
/* Notes on the heuristics used here:
|
|
|
|
much of the complexity here comes from the desire to support
|
|
|
|
Chrome apps.
|
|
|
|
|
|
|
|
From https://bugzilla.gnome.org/show_bug.cgi?id=673657#c13
|
|
|
|
|
|
|
|
Currently chrome sets WM_CLASS as follows (the first string is the 'instance',
|
|
|
|
the second one is the 'class':
|
|
|
|
|
|
|
|
For the normal browser:
|
|
|
|
WM_CLASS(STRING) = "chromium", "Chromium"
|
|
|
|
|
|
|
|
For a bookmarked page (through 'Tools -> Create application shortcuts')
|
|
|
|
WM_CLASS(STRING) = "wiki.gnome.org__GnomeShell_ApplicationBased", "Chromium"
|
|
|
|
|
|
|
|
For an application from the chrome store (with a .desktop file created through
|
|
|
|
right click, "Create shortcuts" from Chrome's apps overview)
|
|
|
|
WM_CLASS(STRING) = "crx_blpcfgokakmgnkcojhhkbfbldkacnbeo", "Chromium"
|
|
|
|
|
|
|
|
The .desktop file has a matching StartupWMClass, but the name differs, e.g. for
|
|
|
|
the store app (youtube) there is
|
|
|
|
|
|
|
|
.local/share/applications/chrome-blpcfgokakmgnkcojhhkbfbldkacnbeo-Default.desktop
|
|
|
|
|
|
|
|
with
|
|
|
|
|
|
|
|
StartupWMClass=crx_blpcfgokakmgnkcojhhkbfbldkacnbeo
|
|
|
|
|
2013-08-08 08:40:01 +00:00
|
|
|
Note that chromium (but not google-chrome!) includes a StartupWMClass=chromium
|
|
|
|
in their .desktop file, so we must match the instance first.
|
|
|
|
|
|
|
|
Also note that in the good case (regular gtk+ app without hacks), instance and
|
|
|
|
class are the same except for case and there is no StartupWMClass at all.
|
|
|
|
*/
|
2012-04-06 18:02:04 +00:00
|
|
|
|
2013-08-08 08:40:01 +00:00
|
|
|
/* first try a match from WM_CLASS (instance part) to StartupWMClass */
|
2012-04-06 18:02:04 +00:00
|
|
|
wm_instance = meta_window_get_wm_class_instance (window);
|
|
|
|
app = shell_app_system_lookup_startup_wmclass (appsys, wm_instance);
|
2020-07-08 09:59:13 +00:00
|
|
|
if (app != NULL && check_app_id_prefix (app, app_prefix))
|
2012-04-06 18:02:04 +00:00
|
|
|
return g_object_ref (app);
|
|
|
|
|
2013-08-08 08:40:01 +00:00
|
|
|
/* then try a match from WM_CLASS to StartupWMClass */
|
|
|
|
wm_class = meta_window_get_wm_class (window);
|
|
|
|
app = shell_app_system_lookup_startup_wmclass (appsys, wm_class);
|
2020-07-08 09:59:13 +00:00
|
|
|
if (app != NULL && check_app_id_prefix (app, app_prefix))
|
2012-04-06 18:02:04 +00:00
|
|
|
return g_object_ref (app);
|
|
|
|
|
2013-08-08 08:40:01 +00:00
|
|
|
/* then try a match from WM_CLASS (instance part) to .desktop */
|
2012-04-06 18:02:04 +00:00
|
|
|
app = shell_app_system_lookup_desktop_wmclass (appsys, wm_instance);
|
2020-07-08 09:59:13 +00:00
|
|
|
if (app != NULL && check_app_id_prefix (app, app_prefix))
|
2012-04-06 18:02:04 +00:00
|
|
|
return g_object_ref (app);
|
|
|
|
|
2013-08-08 08:40:01 +00:00
|
|
|
/* finally, try a match from WM_CLASS to .desktop */
|
|
|
|
app = shell_app_system_lookup_desktop_wmclass (appsys, wm_class);
|
2020-07-08 09:59:13 +00:00
|
|
|
if (app != NULL && check_app_id_prefix (app, app_prefix))
|
2013-08-08 08:40:01 +00:00
|
|
|
return g_object_ref (app);
|
|
|
|
|
2012-04-06 18:02:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-04 16:33:20 +00:00
|
|
|
/*
|
2016-10-07 15:54:09 +00:00
|
|
|
* get_app_from_id:
|
2014-01-04 15:49:34 +00:00
|
|
|
* @window: a #MetaWindow
|
|
|
|
*
|
|
|
|
* Looks only at the given window, and attempts to determine
|
2016-10-07 15:54:09 +00:00
|
|
|
* an application based on %id. If one can't be determined,
|
2014-01-04 15:49:34 +00:00
|
|
|
* return %NULL.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
|
|
|
|
*/
|
2013-08-18 16:41:22 +00:00
|
|
|
static ShellApp *
|
2016-10-07 15:54:09 +00:00
|
|
|
get_app_from_id (MetaWindow *window,
|
|
|
|
const char *id)
|
2013-08-18 16:41:22 +00:00
|
|
|
{
|
|
|
|
ShellApp *app;
|
|
|
|
ShellAppSystem *appsys;
|
2020-07-03 15:28:45 +00:00
|
|
|
g_autofree char *desktop_file = NULL;
|
2013-08-18 16:41:22 +00:00
|
|
|
|
2016-10-07 15:54:09 +00:00
|
|
|
g_return_val_if_fail (id != NULL, NULL);
|
2013-08-18 16:41:22 +00:00
|
|
|
|
2016-10-07 15:54:09 +00:00
|
|
|
appsys = shell_app_system_get_default ();
|
2013-08-18 16:41:22 +00:00
|
|
|
|
|
|
|
desktop_file = g_strconcat (id, ".desktop", NULL);
|
|
|
|
app = shell_app_system_lookup_app (appsys, desktop_file);
|
2014-01-04 15:49:34 +00:00
|
|
|
if (app)
|
2020-07-03 15:28:45 +00:00
|
|
|
return g_object_ref (app);
|
2013-08-18 16:41:22 +00:00
|
|
|
|
2020-07-03 15:28:45 +00:00
|
|
|
return NULL;
|
2013-08-18 16:41:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 15:54:09 +00:00
|
|
|
/*
|
|
|
|
* get_app_from_gapplication_id:
|
|
|
|
* @window: a #MetaWindow
|
|
|
|
*
|
|
|
|
* Looks only at the given window, and attempts to determine
|
|
|
|
* an application based on _GTK_APPLICATION_ID. If one can't be determined,
|
|
|
|
* return %NULL.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
|
|
|
|
*/
|
|
|
|
static ShellApp *
|
|
|
|
get_app_from_gapplication_id (MetaWindow *window)
|
|
|
|
{
|
|
|
|
const char *id;
|
|
|
|
|
|
|
|
id = meta_window_get_gtk_application_id (window);
|
|
|
|
if (!id)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return get_app_from_id (window, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-10-21 02:49:24 +00:00
|
|
|
* get_app_from_sandboxed_app_id:
|
2016-10-07 15:54:09 +00:00
|
|
|
* @window: a #MetaWindow
|
|
|
|
*
|
|
|
|
* Looks only at the given window, and attempts to determine
|
2017-10-21 02:49:24 +00:00
|
|
|
* an application based on its Flatpak or Snap ID. If one can't be determined,
|
2016-10-07 15:54:09 +00:00
|
|
|
* return %NULL.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
|
|
|
|
*/
|
|
|
|
static ShellApp *
|
2017-10-21 02:49:24 +00:00
|
|
|
get_app_from_sandboxed_app_id (MetaWindow *window)
|
2016-10-07 15:54:09 +00:00
|
|
|
{
|
|
|
|
const char *id;
|
|
|
|
|
2017-10-21 02:49:24 +00:00
|
|
|
id = meta_window_get_sandboxed_app_id (window);
|
2016-10-07 15:54:09 +00:00
|
|
|
if (!id)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return get_app_from_id (window, id);
|
|
|
|
}
|
|
|
|
|
2014-01-04 16:33:20 +00:00
|
|
|
/*
|
2010-02-24 16:29:44 +00:00
|
|
|
* get_app_from_window_group:
|
|
|
|
* @monitor: a #ShellWindowTracker
|
|
|
|
* @window: a #MetaWindow
|
2009-10-15 23:28:29 +00:00
|
|
|
*
|
2010-02-24 16:29:44 +00:00
|
|
|
* Check other windows in the group for @window to see if we have
|
|
|
|
* an application for one of them.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
|
2009-10-15 23:28:29 +00:00
|
|
|
*/
|
2010-02-24 16:29:44 +00:00
|
|
|
static ShellApp*
|
2011-08-11 10:37:24 +00:00
|
|
|
get_app_from_window_group (ShellWindowTracker *tracker,
|
2010-02-24 16:29:44 +00:00
|
|
|
MetaWindow *window)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
|
|
|
ShellApp *result;
|
|
|
|
GSList *group_windows;
|
|
|
|
MetaGroup *group;
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
group = meta_window_get_group (window);
|
|
|
|
if (group == NULL)
|
2010-02-24 16:29:44 +00:00
|
|
|
return NULL;
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2010-02-24 16:29:44 +00:00
|
|
|
group_windows = meta_group_list_windows (group);
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
/* Try finding a window in the group of type NORMAL; if we
|
|
|
|
* succeed, use that as our source. */
|
|
|
|
for (iter = group_windows; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
MetaWindow *group_window = iter->data;
|
|
|
|
|
|
|
|
if (meta_window_get_window_type (group_window) != META_WINDOW_NORMAL)
|
|
|
|
continue;
|
|
|
|
|
2011-08-11 10:37:24 +00:00
|
|
|
result = g_hash_table_lookup (tracker->window_to_app, group_window);
|
2010-02-24 16:29:44 +00:00
|
|
|
if (result)
|
|
|
|
break;
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (group_windows);
|
|
|
|
|
2010-02-24 16:29:44 +00:00
|
|
|
if (result)
|
|
|
|
g_object_ref (result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-04 16:33:20 +00:00
|
|
|
/*
|
2011-02-19 15:19:31 +00:00
|
|
|
* get_app_from_window_pid:
|
2011-08-11 10:37:24 +00:00
|
|
|
* @tracker: a #ShellWindowTracker
|
2011-02-19 15:19:31 +00:00
|
|
|
* @window: a #MetaWindow
|
|
|
|
*
|
|
|
|
* Check if the pid associated with @window corresponds to an
|
2014-12-08 18:53:39 +00:00
|
|
|
* application.
|
2011-02-19 15:19:31 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer full): A newly-referenced #ShellApp, or %NULL
|
|
|
|
*/
|
2010-12-21 02:06:03 +00:00
|
|
|
static ShellApp *
|
|
|
|
get_app_from_window_pid (ShellWindowTracker *tracker,
|
|
|
|
MetaWindow *window)
|
|
|
|
{
|
2011-02-19 15:19:31 +00:00
|
|
|
ShellApp *result;
|
2020-04-08 14:23:11 +00:00
|
|
|
pid_t pid;
|
2010-12-21 02:06:03 +00:00
|
|
|
|
|
|
|
if (meta_window_is_remote (window))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pid = meta_window_get_pid (window);
|
|
|
|
|
2020-04-06 18:28:00 +00:00
|
|
|
if (pid < 1)
|
2011-02-08 19:37:22 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-12-08 18:53:39 +00:00
|
|
|
result = shell_window_tracker_get_app_from_pid (tracker, pid);
|
2011-02-19 15:19:31 +00:00
|
|
|
if (result != NULL)
|
|
|
|
g_object_ref (result);
|
|
|
|
|
|
|
|
return result;
|
2010-12-21 02:06:03 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 16:29:44 +00:00
|
|
|
/**
|
|
|
|
* get_app_for_window:
|
|
|
|
*
|
|
|
|
* Determines the application associated with a window, using
|
|
|
|
* all available information such as the window's MetaGroup,
|
|
|
|
* and what we know about other windows.
|
2011-02-19 15:19:31 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #ShellApp, or NULL if none is found
|
2010-02-24 16:29:44 +00:00
|
|
|
*/
|
|
|
|
static ShellApp *
|
2011-08-11 10:37:24 +00:00
|
|
|
get_app_for_window (ShellWindowTracker *tracker,
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
MetaWindow *window)
|
2010-02-24 16:29:44 +00:00
|
|
|
{
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
ShellApp *result = NULL;
|
2014-01-17 15:54:13 +00:00
|
|
|
MetaWindow *transient_for;
|
2010-02-24 16:29:44 +00:00
|
|
|
const char *startup_id;
|
|
|
|
|
2014-01-17 15:54:13 +00:00
|
|
|
transient_for = meta_window_get_transient_for (window);
|
|
|
|
if (transient_for != NULL)
|
|
|
|
return get_app_for_window (tracker, transient_for);
|
|
|
|
|
2010-02-24 16:29:44 +00:00
|
|
|
/* First, we check whether we already know about this window,
|
|
|
|
* if so, just return that.
|
|
|
|
*/
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
if (meta_window_get_window_type (window) == META_WINDOW_NORMAL
|
|
|
|
|| meta_window_is_remote (window))
|
2010-02-24 16:29:44 +00:00
|
|
|
{
|
2011-08-11 10:37:24 +00:00
|
|
|
result = g_hash_table_lookup (tracker->window_to_app, window);
|
2010-02-24 16:29:44 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
|
|
|
g_object_ref (result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
if (meta_window_is_remote (window))
|
|
|
|
return _shell_app_new_for_window (window);
|
|
|
|
|
2020-07-03 15:34:23 +00:00
|
|
|
/* Check if the app's WM_CLASS specifies an app; this is
|
|
|
|
* canonical if it does.
|
|
|
|
*/
|
|
|
|
result = get_app_from_window_wmclass (window);
|
|
|
|
if (result != NULL)
|
|
|
|
return result;
|
|
|
|
|
2017-10-21 02:49:24 +00:00
|
|
|
/* Check if the window was opened from within a sandbox; if this
|
2016-10-07 15:54:09 +00:00
|
|
|
* is the case, a corresponding .desktop file is guaranteed to match;
|
|
|
|
*/
|
2017-10-21 02:49:24 +00:00
|
|
|
result = get_app_from_sandboxed_app_id (window);
|
2016-10-07 15:54:09 +00:00
|
|
|
if (result != NULL)
|
|
|
|
return result;
|
|
|
|
|
2013-08-18 16:41:22 +00:00
|
|
|
/* Check if the window has a GApplication ID attached; this is
|
|
|
|
* canonical if it does
|
|
|
|
*/
|
|
|
|
result = get_app_from_gapplication_id (window);
|
|
|
|
if (result != NULL)
|
|
|
|
return result;
|
|
|
|
|
2011-08-11 10:37:24 +00:00
|
|
|
result = get_app_from_window_pid (tracker, window);
|
2009-10-15 23:28:29 +00:00
|
|
|
if (result != NULL)
|
2010-02-24 16:29:44 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
/* Now we check whether we have a match through startup-notification */
|
|
|
|
startup_id = meta_window_get_startup_id (window);
|
|
|
|
if (startup_id)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
2010-02-24 16:29:44 +00:00
|
|
|
GSList *iter, *sequences;
|
|
|
|
|
2011-08-11 10:37:24 +00:00
|
|
|
sequences = shell_window_tracker_get_startup_sequences (tracker);
|
2010-02-24 16:29:44 +00:00
|
|
|
for (iter = sequences; iter; iter = iter->next)
|
|
|
|
{
|
2018-08-22 22:00:36 +00:00
|
|
|
MetaStartupSequence *sequence = iter->data;
|
|
|
|
const char *id = meta_startup_sequence_get_id (sequence);
|
2010-02-24 16:29:44 +00:00
|
|
|
if (strcmp (id, startup_id) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
result = shell_startup_sequence_get_app (sequence);
|
|
|
|
if (result)
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
{
|
|
|
|
result = g_object_ref (result);
|
|
|
|
break;
|
|
|
|
}
|
2010-02-24 16:29:44 +00:00
|
|
|
}
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
2010-02-24 16:29:44 +00:00
|
|
|
/* If we didn't get a startup-notification match, see if we matched
|
|
|
|
* any other windows in the group.
|
|
|
|
*/
|
|
|
|
if (result == NULL)
|
2011-08-11 10:37:24 +00:00
|
|
|
result = get_app_from_window_group (tracker, window);
|
2010-02-24 16:29:44 +00:00
|
|
|
|
|
|
|
/* Our last resort - we create a fake app from the window */
|
|
|
|
if (result == NULL)
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 17:35:01 +00:00
|
|
|
result = _shell_app_new_for_window (window);
|
2010-02-24 16:29:44 +00:00
|
|
|
|
|
|
|
return result;
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 23:42:07 +00:00
|
|
|
static void
|
|
|
|
update_focus_app (ShellWindowTracker *self)
|
|
|
|
{
|
|
|
|
MetaWindow *new_focus_win;
|
|
|
|
ShellApp *new_focus_app;
|
|
|
|
|
2011-07-13 16:34:31 +00:00
|
|
|
new_focus_win = meta_display_get_focus_window (shell_global_get_display (shell_global_get ()));
|
2014-01-24 15:26:49 +00:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2011-05-24 23:42:07 +00:00
|
|
|
new_focus_app = new_focus_win ? shell_window_tracker_get_window_app (self, new_focus_win) : NULL;
|
|
|
|
|
2011-12-15 06:25:35 +00:00
|
|
|
if (new_focus_app)
|
2012-05-17 16:18:53 +00:00
|
|
|
{
|
|
|
|
shell_app_update_window_actions (new_focus_app, new_focus_win);
|
2018-10-04 17:20:40 +00:00
|
|
|
shell_app_update_app_actions (new_focus_app, new_focus_win);
|
2012-05-17 16:18:53 +00:00
|
|
|
}
|
2011-12-15 06:25:35 +00:00
|
|
|
|
2011-05-24 23:42:07 +00:00
|
|
|
set_focus_app (self, new_focus_app);
|
2014-01-24 15:11:49 +00:00
|
|
|
|
|
|
|
g_clear_object (&new_focus_app);
|
2011-05-24 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-10-13 00:20:22 +00:00
|
|
|
tracked_window_changed (ShellWindowTracker *self,
|
|
|
|
MetaWindow *window)
|
2011-05-24 23:42:07 +00:00
|
|
|
{
|
|
|
|
/* It's simplest to just treat this as a remove + add. */
|
|
|
|
disassociate_window (self, window);
|
|
|
|
track_window (self, window);
|
2014-01-24 17:23:48 +00:00
|
|
|
/* also just recalculate the focused app, in case it was the focused
|
2011-05-24 23:42:07 +00:00
|
|
|
window that changed */
|
|
|
|
update_focus_app (self);
|
|
|
|
}
|
|
|
|
|
2014-10-13 00:20:22 +00:00
|
|
|
static void
|
|
|
|
on_wm_class_changed (MetaWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellWindowTracker *self = SHELL_WINDOW_TRACKER (user_data);
|
|
|
|
tracked_window_changed (self, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_gtk_application_id_changed (MetaWindow *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellWindowTracker *self = SHELL_WINDOW_TRACKER (user_data);
|
|
|
|
tracked_window_changed (self, window);
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:52:11 +00:00
|
|
|
static void
|
|
|
|
on_window_unmanaged (MetaWindow *window,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
disassociate_window (SHELL_WINDOW_TRACKER (user_data), window);
|
|
|
|
}
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
static void
|
|
|
|
track_window (ShellWindowTracker *self,
|
|
|
|
MetaWindow *window)
|
|
|
|
{
|
|
|
|
ShellApp *app;
|
|
|
|
|
|
|
|
app = get_app_for_window (self, window);
|
|
|
|
if (!app)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* At this point we've stored the association from window -> application */
|
|
|
|
g_hash_table_insert (self->window_to_app, window, app);
|
|
|
|
|
2011-05-24 23:42:07 +00:00
|
|
|
g_signal_connect (window, "notify::wm-class", G_CALLBACK (on_wm_class_changed), self);
|
2014-10-13 00:20:22 +00:00
|
|
|
g_signal_connect (window, "notify::gtk-application-id", G_CALLBACK (on_gtk_application_id_changed), self);
|
2021-11-16 19:52:11 +00:00
|
|
|
g_signal_connect (window, "unmanaged", G_CALLBACK (on_window_unmanaged), self);
|
2011-05-24 23:42:07 +00:00
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
_shell_app_add_window (app, window);
|
|
|
|
|
2010-04-20 18:47:45 +00:00
|
|
|
g_signal_emit (self, signals[TRACKED_WINDOWS_CHANGED], 0);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_window_tracker_on_window_added (MetaWorkspace *workspace,
|
2019-07-19 16:17:54 +00:00
|
|
|
MetaWindow *window,
|
|
|
|
gpointer user_data)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
2021-11-11 17:40:42 +00:00
|
|
|
track_window (SHELL_WINDOW_TRACKER (user_data), window);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
disassociate_window (ShellWindowTracker *self,
|
|
|
|
MetaWindow *window)
|
|
|
|
{
|
|
|
|
ShellApp *app;
|
|
|
|
|
|
|
|
app = g_hash_table_lookup (self->window_to_app, window);
|
|
|
|
if (!app)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_object_ref (app);
|
|
|
|
|
|
|
|
g_hash_table_remove (self->window_to_app, window);
|
|
|
|
|
2013-12-04 16:26:01 +00:00
|
|
|
_shell_app_remove_window (app, window);
|
2014-10-13 00:20:12 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (window, G_CALLBACK (on_wm_class_changed), self);
|
2014-10-13 00:20:22 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (window, G_CALLBACK (on_gtk_application_id_changed), self);
|
2021-11-16 19:52:11 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (window, G_CALLBACK (on_window_unmanaged), self);
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2010-04-20 18:47:45 +00:00
|
|
|
g_signal_emit (self, signals[TRACKED_WINDOWS_CHANGED], 0);
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
g_object_unref (app);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_window_tracker_on_window_removed (MetaWorkspace *workspace,
|
|
|
|
MetaWindow *window,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
disassociate_window (SHELL_WINDOW_TRACKER (user_data), window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-08-11 10:37:24 +00:00
|
|
|
load_initial_windows (ShellWindowTracker *tracker)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
|
|
|
MetaWorkspaceManager *workspace_manager =
|
|
|
|
meta_display_get_workspace_manager (display);
|
|
|
|
GList *workspaces;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
workspaces = meta_workspace_manager_get_workspaces (workspace_manager);
|
|
|
|
for (l = workspaces; l; l = l->next)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaWorkspace *workspace = l->data;
|
2009-10-15 23:28:29 +00:00
|
|
|
GList *windows = meta_workspace_list_windows (workspace);
|
|
|
|
GList *window_iter;
|
|
|
|
|
|
|
|
for (window_iter = windows; window_iter; window_iter = window_iter->next)
|
|
|
|
{
|
|
|
|
MetaWindow *window = window_iter->data;
|
2011-08-11 10:37:24 +00:00
|
|
|
track_window (tracker, window);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (windows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-01-03 07:55:38 +00:00
|
|
|
shell_window_tracker_on_n_workspaces_changed (MetaWorkspaceManager *workspace_manager,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
|
|
|
ShellWindowTracker *self = SHELL_WINDOW_TRACKER (user_data);
|
2018-01-03 07:55:38 +00:00
|
|
|
GList *workspaces;
|
|
|
|
GList *l;
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
workspaces = meta_workspace_manager_get_workspaces (workspace_manager);
|
|
|
|
for (l = workspaces; l; l = l->next)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaWorkspace *workspace = l->data;
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
/* This pair of disconnect/connect is idempotent if we were
|
|
|
|
* already connected, while ensuring we get connected for
|
|
|
|
* new workspaces.
|
|
|
|
*/
|
|
|
|
g_signal_handlers_disconnect_by_func (workspace,
|
|
|
|
shell_window_tracker_on_window_added,
|
|
|
|
self);
|
|
|
|
g_signal_handlers_disconnect_by_func (workspace,
|
|
|
|
shell_window_tracker_on_window_removed,
|
|
|
|
self);
|
|
|
|
|
|
|
|
g_signal_connect (workspace, "window-added",
|
|
|
|
G_CALLBACK (shell_window_tracker_on_window_added), self);
|
|
|
|
g_signal_connect (workspace, "window-removed",
|
|
|
|
G_CALLBACK (shell_window_tracker_on_window_removed), self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_window_tracking (ShellWindowTracker *self)
|
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
|
|
|
MetaWorkspaceManager *workspace_manager =
|
|
|
|
meta_display_get_workspace_manager (display);
|
2009-10-15 23:28:29 +00:00
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
g_signal_connect (workspace_manager, "notify::n-workspaces",
|
2009-10-15 23:28:29 +00:00
|
|
|
G_CALLBACK (shell_window_tracker_on_n_workspaces_changed), self);
|
|
|
|
g_signal_connect (display, "notify::focus-window",
|
|
|
|
G_CALLBACK (on_focus_window_changed), self);
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
shell_window_tracker_on_n_workspaces_changed (workspace_manager, NULL, self);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-22 22:00:36 +00:00
|
|
|
on_startup_sequence_changed (MetaStartupNotification *sn,
|
|
|
|
MetaStartupSequence *sequence,
|
|
|
|
ShellWindowTracker *self)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 18:07:44 +00:00
|
|
|
ShellApp *app;
|
|
|
|
|
2018-08-22 22:00:36 +00:00
|
|
|
app = shell_startup_sequence_get_app (sequence);
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 18:07:44 +00:00
|
|
|
if (app)
|
2010-10-06 21:30:30 +00:00
|
|
|
_shell_app_handle_startup_sequence (app, sequence);
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 18:07:44 +00:00
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
g_signal_emit (G_OBJECT (self), signals[STARTUP_SEQUENCE_CHANGED], 0, sequence);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_window_tracker_init (ShellWindowTracker *self)
|
|
|
|
{
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (shell_global_get ());
|
2018-08-22 22:00:36 +00:00
|
|
|
MetaStartupNotification *sn = meta_display_get_startup_notification (display);
|
2009-10-15 23:28:29 +00:00
|
|
|
|
|
|
|
self->window_to_app = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, (GDestroyNotify) g_object_unref);
|
|
|
|
|
|
|
|
|
2018-08-22 22:00:36 +00:00
|
|
|
g_signal_connect (sn, "changed",
|
2009-10-15 23:28:29 +00:00
|
|
|
G_CALLBACK (on_startup_sequence_changed), self);
|
|
|
|
|
|
|
|
load_initial_windows (self);
|
|
|
|
init_window_tracking (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_window_tracker_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
ShellWindowTracker *self = SHELL_WINDOW_TRACKER (object);
|
|
|
|
|
|
|
|
g_hash_table_destroy (self->window_to_app);
|
2010-12-21 02:06:03 +00:00
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
G_OBJECT_CLASS (shell_window_tracker_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-09-02 00:48:11 +00:00
|
|
|
* shell_window_tracker_get_window_app:
|
2011-08-11 10:37:24 +00:00
|
|
|
* @tracker: An app monitor instance
|
2009-10-15 23:28:29 +00:00
|
|
|
* @metawin: A #MetaWindow
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): Application associated with window
|
|
|
|
*/
|
|
|
|
ShellApp *
|
2011-08-11 10:37:24 +00:00
|
|
|
shell_window_tracker_get_window_app (ShellWindowTracker *tracker,
|
|
|
|
MetaWindow *metawin)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
|
|
|
ShellApp *app;
|
|
|
|
|
2011-08-11 10:37:24 +00:00
|
|
|
app = g_hash_table_lookup (tracker->window_to_app, metawin);
|
2009-10-15 23:28:29 +00:00
|
|
|
if (app)
|
|
|
|
g_object_ref (app);
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2010-02-03 23:42:43 +00:00
|
|
|
|
|
|
|
/**
|
2010-09-02 00:48:11 +00:00
|
|
|
* shell_window_tracker_get_app_from_pid:
|
2011-11-02 16:24:49 +00:00
|
|
|
* @tracker: A #ShellAppSystem
|
2010-02-03 23:42:43 +00:00
|
|
|
* @pid: A Unix process identifier
|
|
|
|
*
|
|
|
|
* Look up the application corresponding to a process.
|
|
|
|
*
|
2010-05-24 14:59:52 +00:00
|
|
|
* Returns: (transfer none): A #ShellApp, or %NULL if none
|
2010-02-03 23:42:43 +00:00
|
|
|
*/
|
|
|
|
ShellApp *
|
2011-11-02 16:24:49 +00:00
|
|
|
shell_window_tracker_get_app_from_pid (ShellWindowTracker *tracker,
|
2010-02-03 23:42:43 +00:00
|
|
|
int pid)
|
|
|
|
{
|
apps: Ensure running apps override new .desktop file data
This patch fixes the "apps vanish from alt-TAB bug".
If a "package system" rips away and possibly replaces .desktop files
at some random time, we have historically used inotify to detect this
and reread state (in a racy way, but...). In GNOME 2, this was
generally not too problematic because the menu widget was totally
separate from the list of windows - and the data they operate on was
disjoint as well.
In GNOME 3 we unify these, and this creates architectural problems
because the windows are tied to the app.
What this patch tries to do is, when rereading the application state,
if we have a running application, we keep that app around instead of
making a new instance. This ensures we preserve any state such as the
set of open windows.
This requires moving the running state into ShellAppSystem. Adjust
callers as necessary, and while we're at it drop the unused "contexts"
stuff.
This is just a somewhat quick band-aid; a REAL fix would require us
having low-level control over application installation. As long as
we're on top of random broken tar+wget wrappers, it will be gross.
A slight future improvement to this patch would add an explicit
"merge" between the old and new data. I think probably we always keep
around the ShellApp corresponding to a given ID, but replace its
GMenuTreeEntry.
https://bugzilla.gnome.org/show_bug.cgi?id=657990
2011-09-03 14:32:06 +00:00
|
|
|
GSList *running = shell_app_system_get_running (shell_app_system_get_default());
|
2010-05-24 14:59:52 +00:00
|
|
|
GSList *iter;
|
|
|
|
ShellApp *result = NULL;
|
|
|
|
|
|
|
|
for (iter = running; iter; iter = iter->next)
|
2010-02-03 23:42:43 +00:00
|
|
|
{
|
2010-05-24 14:59:52 +00:00
|
|
|
ShellApp *app = iter->data;
|
|
|
|
GSList *pids = shell_app_get_pids (app);
|
|
|
|
GSList *pids_iter;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (result != NULL)
|
|
|
|
break;
|
2010-02-03 23:42:43 +00:00
|
|
|
}
|
2010-05-24 14:59:52 +00:00
|
|
|
|
|
|
|
g_slist_free (running);
|
|
|
|
|
|
|
|
return result;
|
2010-02-03 23:42:43 +00:00
|
|
|
}
|
|
|
|
|
Major ShellApp API cleanup, startup notification, window focus handling
This patch combines several high level changes which are conceptually
independent but in practice rather intertwined.
* Add a "state" property to ShellApp which reflects whether it's
stopped, starting, or started. This will allow us to later clean
up all the callers that are using ".get_windows().length > 0" as
a proxy for this property
* Replace shell_app_launch with shell_app_activate and shell_app_open_new_window
A lot of code was calling .launch, but it's signficantly clearer
if we call this ".open_new_window()", and later if we gain the ability
to call into an application's menu, we can implement this correctly rather
than trying to update all .launch callers.
* Because ShellApp now has a "starting" state, rebase panel.js on top of
this so that when we get a startup-notification sequence for an app
and transition it to starting, it becomes the focus app, and panel.js
cleanly just tracks the focus app, rather than bouncing between SN
sequences. This removes display of non-app startup sequences, which
I consider an acceptable action in light of the committed changes
to startup-notification and GTK+.
https://bugzilla.gnome.org/show_bug.cgi?id=614755
2010-04-03 18:07:44 +00:00
|
|
|
static void
|
|
|
|
set_focus_app (ShellWindowTracker *tracker,
|
|
|
|
ShellApp *new_focus_app)
|
|
|
|
{
|
|
|
|
if (new_focus_app == tracker->focus_app)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tracker->focus_app != NULL)
|
|
|
|
g_object_unref (tracker->focus_app);
|
|
|
|
|
|
|
|
tracker->focus_app = new_focus_app;
|
|
|
|
|
|
|
|
if (tracker->focus_app != NULL)
|
|
|
|
g_object_ref (tracker->focus_app);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (tracker), "focus-app");
|
|
|
|
}
|
|
|
|
|
2010-02-25 21:11:14 +00:00
|
|
|
static void
|
|
|
|
on_focus_window_changed (MetaDisplay *display,
|
|
|
|
GParamSpec *spec,
|
|
|
|
ShellWindowTracker *tracker)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
2011-05-24 23:42:07 +00:00
|
|
|
update_focus_app (tracker);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_window_tracker_get_startup_sequences:
|
2012-04-06 14:34:52 +00:00
|
|
|
* @tracker:
|
2009-10-15 23:28:29 +00:00
|
|
|
*
|
2018-08-22 22:00:36 +00:00
|
|
|
* Returns: (transfer none) (element-type MetaStartupSequence): Currently active startup sequences
|
2009-10-15 23:28:29 +00:00
|
|
|
*/
|
|
|
|
GSList *
|
|
|
|
shell_window_tracker_get_startup_sequences (ShellWindowTracker *self)
|
|
|
|
{
|
|
|
|
ShellGlobal *global = shell_global_get ();
|
2018-01-03 07:55:38 +00:00
|
|
|
MetaDisplay *display = shell_global_get_display (global);
|
2018-08-22 22:00:36 +00:00
|
|
|
MetaStartupNotification *sn = meta_display_get_startup_notification (display);
|
2018-01-03 07:55:38 +00:00
|
|
|
|
2018-08-22 22:00:36 +00:00
|
|
|
return meta_startup_notification_get_sequences (sn);
|
2009-10-15 23:28:29 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 22:02:37 +00:00
|
|
|
static ShellApp *
|
2018-08-22 22:00:36 +00:00
|
|
|
shell_startup_sequence_get_app (MetaStartupSequence *sequence)
|
2010-02-24 16:29:44 +00:00
|
|
|
{
|
|
|
|
const char *appid;
|
2013-04-20 21:23:37 +00:00
|
|
|
char *basename;
|
2010-02-24 16:29:44 +00:00
|
|
|
ShellAppSystem *appsys;
|
|
|
|
ShellApp *app;
|
|
|
|
|
2018-08-22 22:00:36 +00:00
|
|
|
appid = meta_startup_sequence_get_application_id (sequence);
|
2010-02-24 16:29:44 +00:00
|
|
|
if (!appid)
|
|
|
|
return NULL;
|
|
|
|
|
2013-04-20 21:23:37 +00:00
|
|
|
basename = g_path_get_basename (appid);
|
2010-02-24 16:29:44 +00:00
|
|
|
appsys = shell_app_system_get_default ();
|
2013-04-20 21:23:37 +00:00
|
|
|
app = shell_app_system_lookup_app (appsys, basename);
|
|
|
|
g_free (basename);
|
2010-02-24 16:29:44 +00:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2009-10-15 23:28:29 +00:00
|
|
|
/**
|
|
|
|
* shell_window_tracker_get_default:
|
|
|
|
*
|
|
|
|
* Return Value: (transfer none): The global #ShellWindowTracker instance
|
|
|
|
*/
|
|
|
|
ShellWindowTracker *
|
2015-09-23 18:40:03 +00:00
|
|
|
shell_window_tracker_get_default (void)
|
2009-10-15 23:28:29 +00:00
|
|
|
{
|
|
|
|
static ShellWindowTracker *instance;
|
|
|
|
|
|
|
|
if (instance == NULL)
|
|
|
|
instance = g_object_new (SHELL_TYPE_WINDOW_TRACKER, NULL);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|