Update for review of d5a80d3063
This commit is contained in:
parent
858a82fcdd
commit
8293f3423a
@ -15,7 +15,6 @@
|
|||||||
#include "shell-app-monitor.h"
|
#include "shell-app-monitor.h"
|
||||||
#include "shell-app-system.h"
|
#include "shell-app-system.h"
|
||||||
#include "shell-global.h"
|
#include "shell-global.h"
|
||||||
#include "shell-wm.h"
|
|
||||||
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
@ -97,10 +96,10 @@ struct _ShellAppMonitor
|
|||||||
gboolean currently_idle;
|
gboolean currently_idle;
|
||||||
gboolean enable_monitoring;
|
gboolean enable_monitoring;
|
||||||
|
|
||||||
/* <char *,guint> */
|
/* <char * appid, guint window_count> */
|
||||||
GHashTable *running_appids;
|
GHashTable *running_appids;
|
||||||
|
|
||||||
/* <MetaWindow *, char *> */
|
/* <MetaWindow * window, char * appid> */
|
||||||
GHashTable *window_to_appid;
|
GHashTable *window_to_appid;
|
||||||
|
|
||||||
GHashTable *apps_by_wm_class; /* Seen apps by wm_class */
|
GHashTable *apps_by_wm_class; /* Seen apps by wm_class */
|
||||||
@ -240,6 +239,13 @@ get_wmclass_for_window (MetaWindow *window)
|
|||||||
return g_strdup (wm_class);
|
return g_strdup (wm_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_cleaned_wmclass_for_window:
|
||||||
|
*
|
||||||
|
* A "cleaned" wmclass is the WM_CLASS property of a window,
|
||||||
|
* after some transformations to turn it into a form
|
||||||
|
* somewhat more resilient to changes, such as lowercasing.
|
||||||
|
*/
|
||||||
static char *
|
static char *
|
||||||
get_cleaned_wmclass_for_window (MetaWindow *window)
|
get_cleaned_wmclass_for_window (MetaWindow *window)
|
||||||
{
|
{
|
||||||
@ -256,11 +262,18 @@ get_cleaned_wmclass_for_window (MetaWindow *window)
|
|||||||
cleaned_wmclass = g_utf8_strdown (wmclass, -1);
|
cleaned_wmclass = g_utf8_strdown (wmclass, -1);
|
||||||
g_free (wmclass);
|
g_free (wmclass);
|
||||||
/* This handles "Fedora Eclipse", probably others */
|
/* This handles "Fedora Eclipse", probably others */
|
||||||
wmclass = g_strdup (g_strdelimit (cleaned_wmclass, " ", '-'));
|
g_strdelimit (cleaned_wmclass, " ", '-');
|
||||||
|
wmclass = g_strdup (cleaned_wmclass);
|
||||||
g_free (cleaned_wmclass);
|
g_free (cleaned_wmclass);
|
||||||
return wmclass;
|
return wmclass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_appid_for_window:
|
||||||
|
*
|
||||||
|
* Returns a desktop file ID for an application, or %NULL if
|
||||||
|
* we're unable to determine one.
|
||||||
|
*/
|
||||||
static char *
|
static char *
|
||||||
get_appid_for_window (MetaWindow *window)
|
get_appid_for_window (MetaWindow *window)
|
||||||
{
|
{
|
||||||
@ -289,7 +302,7 @@ track_window (ShellAppMonitor *self,
|
|||||||
MetaWindow *window)
|
MetaWindow *window)
|
||||||
{
|
{
|
||||||
char *appid;
|
char *appid;
|
||||||
guint refcount;
|
guint window_count;
|
||||||
|
|
||||||
appid = get_appid_for_window (window);
|
appid = get_appid_for_window (window);
|
||||||
if (!appid)
|
if (!appid)
|
||||||
@ -297,11 +310,11 @@ track_window (ShellAppMonitor *self,
|
|||||||
|
|
||||||
g_hash_table_insert (self->window_to_appid, window, appid);
|
g_hash_table_insert (self->window_to_appid, window, appid);
|
||||||
|
|
||||||
refcount = GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
|
window_count = GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
|
||||||
|
|
||||||
refcount += 1;
|
window_count += 1;
|
||||||
g_hash_table_insert (self->running_appids, appid, GUINT_TO_POINTER (refcount));
|
g_hash_table_insert (self->running_appids, g_strdup (appid), GUINT_TO_POINTER (window_count));
|
||||||
if (refcount == 1)
|
if (window_count == 1)
|
||||||
g_signal_emit (self, signals[CHANGED], 0);
|
g_signal_emit (self, signals[CHANGED], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,18 +335,16 @@ shell_app_monitor_on_window_removed (MetaWorkspace *workspace,
|
|||||||
{
|
{
|
||||||
ShellAppMonitor *self = SHELL_APP_MONITOR (user_data);
|
ShellAppMonitor *self = SHELL_APP_MONITOR (user_data);
|
||||||
char *appid;
|
char *appid;
|
||||||
guint refcount;
|
guint window_count;
|
||||||
|
|
||||||
appid = get_appid_for_window (window);
|
appid = g_hash_table_lookup (self->window_to_appid, window);
|
||||||
if (!appid)
|
if (!appid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_hash_table_remove (self->window_to_appid, window);
|
window_count = GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
|
||||||
|
|
||||||
refcount = GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
|
window_count -= 1;
|
||||||
|
if (window_count == 0)
|
||||||
refcount -= 1;
|
|
||||||
if (refcount == 0)
|
|
||||||
{
|
{
|
||||||
g_hash_table_remove (self->running_appids, appid);
|
g_hash_table_remove (self->running_appids, appid);
|
||||||
g_free (appid);
|
g_free (appid);
|
||||||
@ -341,21 +352,28 @@ shell_app_monitor_on_window_removed (MetaWorkspace *workspace,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_hash_table_insert (self->running_appids, appid, GUINT_TO_POINTER (refcount));
|
g_hash_table_insert (self->running_appids, appid, GUINT_TO_POINTER (window_count));
|
||||||
}
|
}
|
||||||
|
g_hash_table_remove (self->window_to_appid, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_initial_windows (ShellAppMonitor *monitor)
|
load_initial_windows (ShellAppMonitor *monitor)
|
||||||
{
|
{
|
||||||
ShellGlobal *global = shell_global_get ();
|
GList *workspaces, *iter;
|
||||||
GList *windows = shell_global_get_windows (global);
|
MetaScreen *screen = shell_global_get_screen (shell_global_get ());
|
||||||
GList *iter;
|
workspaces = meta_screen_get_workspaces (screen);
|
||||||
|
|
||||||
for (iter = windows; iter; iter = iter->next)
|
for (iter = workspaces; iter; iter = iter->next)
|
||||||
{
|
{
|
||||||
MetaWindow *window = iter->data;
|
MetaWorkspace *workspace = iter->data;
|
||||||
track_window (monitor, window);
|
GList *windows = meta_workspace_list_windows (workspace);
|
||||||
|
GList *window_iter;
|
||||||
|
|
||||||
|
for (window_iter = windows; window_iter; window_iter = window_iter->next)
|
||||||
|
track_window (monitor, (MetaWindow*)window_iter->data);
|
||||||
|
|
||||||
|
g_list_free (windows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,6 +398,10 @@ shell_app_monitor_on_n_workspaces_changed (MetaScreen *screen,
|
|||||||
{
|
{
|
||||||
MetaWorkspace *workspace = iter->data;
|
MetaWorkspace *workspace = iter->data;
|
||||||
|
|
||||||
|
/* 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,
|
g_signal_handlers_disconnect_by_func (workspace,
|
||||||
shell_app_monitor_on_window_added,
|
shell_app_monitor_on_window_added,
|
||||||
self);
|
self);
|
||||||
@ -397,17 +419,11 @@ shell_app_monitor_on_n_workspaces_changed (MetaScreen *screen,
|
|||||||
static void
|
static void
|
||||||
init_window_monitoring (ShellAppMonitor *self)
|
init_window_monitoring (ShellAppMonitor *self)
|
||||||
{
|
{
|
||||||
MetaScreen *screen;
|
MetaScreen *screen = shell_global_get_screen (shell_global_get ());
|
||||||
|
|
||||||
g_object_get (shell_global_get (),
|
|
||||||
"screen", &screen,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
g_signal_connect (screen, "notify::n-workspaces",
|
g_signal_connect (screen, "notify::n-workspaces",
|
||||||
G_CALLBACK (shell_app_monitor_on_n_workspaces_changed), self);
|
G_CALLBACK (shell_app_monitor_on_n_workspaces_changed), self);
|
||||||
shell_app_monitor_on_n_workspaces_changed (screen, NULL, self);
|
shell_app_monitor_on_n_workspaces_changed (screen, NULL, self);
|
||||||
|
|
||||||
g_object_unref (screen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -418,6 +434,7 @@ shell_app_monitor_init (ShellAppMonitor *self)
|
|||||||
Display *xdisplay;
|
Display *xdisplay;
|
||||||
char *path;
|
char *path;
|
||||||
char *shell_config_dir;
|
char *shell_config_dir;
|
||||||
|
|
||||||
/* FIXME: should we create as many monitors as there are GdkScreens? */
|
/* FIXME: should we create as many monitors as there are GdkScreens? */
|
||||||
display = gdk_display_get_default();
|
display = gdk_display_get_default();
|
||||||
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
||||||
@ -545,7 +562,7 @@ update_app_info (ShellAppMonitor *monitor)
|
|||||||
{
|
{
|
||||||
char *wm_class;
|
char *wm_class;
|
||||||
ShellGlobal *global;
|
ShellGlobal *global;
|
||||||
GHashTable *app_active_times = NULL; /* GTime spent per activity */
|
GHashTable *app_active_times = NULL; /* last active time for an application */
|
||||||
MetaScreen *screen;
|
MetaScreen *screen;
|
||||||
MetaDisplay *display;
|
MetaDisplay *display;
|
||||||
MetaWindow *active;
|
MetaWindow *active;
|
||||||
|
@ -101,7 +101,7 @@ shell_global_get_property(GObject *object,
|
|||||||
g_value_set_object (value, mutter_plugin_get_overlay_group (global->plugin));
|
g_value_set_object (value, mutter_plugin_get_overlay_group (global->plugin));
|
||||||
break;
|
break;
|
||||||
case PROP_SCREEN:
|
case PROP_SCREEN:
|
||||||
g_value_set_object (value, mutter_plugin_get_screen (global->plugin));
|
g_value_set_object (value, shell_global_get_screen (global));
|
||||||
break;
|
break;
|
||||||
case PROP_SCREEN_WIDTH:
|
case PROP_SCREEN_WIDTH:
|
||||||
{
|
{
|
||||||
@ -608,6 +608,17 @@ shell_global_set_stage_input_region (ShellGlobal *global,
|
|||||||
shell_global_set_stage_input_mode (global, global->input_mode);
|
shell_global_set_stage_input_mode (global, global->input_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shell_global_get_screen:
|
||||||
|
*
|
||||||
|
* Return value: (transfer none): The default #MetaScreen
|
||||||
|
*/
|
||||||
|
MetaScreen *
|
||||||
|
shell_global_get_screen (ShellGlobal *global)
|
||||||
|
{
|
||||||
|
return mutter_plugin_get_screen (global->plugin);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shell_global_get_windows:
|
* shell_global_get_windows:
|
||||||
*
|
*
|
||||||
|
@ -48,6 +48,8 @@ ClutterActor *shell_get_event_related(ClutterEvent *event);
|
|||||||
|
|
||||||
ShellGlobal *shell_global_get (void);
|
ShellGlobal *shell_global_get (void);
|
||||||
|
|
||||||
|
MetaScreen *shell_global_get_screen (ShellGlobal *global);
|
||||||
|
|
||||||
void shell_global_grab_dbus_service (ShellGlobal *global);
|
void shell_global_grab_dbus_service (ShellGlobal *global);
|
||||||
|
|
||||||
void shell_global_start_task_panel (ShellGlobal *global);
|
void shell_global_start_task_panel (ShellGlobal *global);
|
||||||
|
Loading…
Reference in New Issue
Block a user