[gnome-shell/overlay-design02] Revert inadvertent commits for future rebasing
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-shell/overlay-design02] Revert inadvertent commits for future rebasing
- Date: Thu, 4 Jun 2009 17:42:25 -0400 (EDT)
commit 4a7c328c334f0ec74876bc9541f9ae41f45b3236
Author: Colin Walters <walters verbum org>
Date: Thu Jun 4 17:42:03 2009 -0400
Revert inadvertent commits for future rebasing
---
js/ui/appDisplay.js | 191 +++++++++++++++++++++++++++++------
src/shell-app-monitor.c | 258 ++++++++++-------------------------------------
src/shell-app-monitor.h | 5 +-
src/shell-app-system.c | 32 ------
src/shell-app-system.h | 4 +-
5 files changed, 218 insertions(+), 272 deletions(-)
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 266e8bc..5901ded 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -15,8 +15,6 @@ const Main = imports.ui.main;
const ENTERED_MENU_COLOR = new Clutter.Color();
ENTERED_MENU_COLOR.from_pixel(0x00ff0022);
-const APP_ICON_SIZE = 48;
-const APP_ITEM_SIZE = 64;
const MENU_ICON_SIZE = 24;
const MENU_SPACING = 15;
@@ -58,33 +56,28 @@ function AppDisplayItem(appInfo, availableWidth) {
}
AppDisplayItem.prototype = {
- _init : function(appInfo) {
- this._appInfo = appInfo;
+ __proto__: GenericDisplay.GenericDisplayItem.prototype,
- this.actor = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
- spacing: 6 });
+ _init : function(appInfo, availableWidth) {
+ GenericDisplay.GenericDisplayItem.prototype._init.call(this, availableWidth);
+ this._appInfo = appInfo;
let name = appInfo.get_name();
+ let description = appInfo.get_description();
+
let iconTheme = Gtk.IconTheme.get_default();
let gicon = appInfo.get_icon();
let texCache = Shell.TextureCache.get_default();
let icon;
if (gicon == null)
- icon = new Clutter.Texture({ width: APP_ICON_SIZE,
- height: APP_ICON_SIZE
+ icon = new Clutter.Texture({ width: GenericDisplay.ITEM_DISPLAY_ICON_SIZE,
+ height: GenericDisplay.ITEM_DISPLAY_ICON_SIZE
});
else
- icon = texCache.load_gicon(gicon, APP_ICON_SIZE);
-
- this.actor.add_actor(icon);
- let title = new Clutter.Text({ color: GenericDisplay.ITEM_DISPLAY_NAME_COLOR,
- font_name: "Sans bold 14px",
- ellipsize: Pango.EllipsizeMode.END,
- text: name
- });
- this.actor.add_actor(title);
+ icon = texCache.load_gicon(gicon, GenericDisplay.ITEM_DISPLAY_ICON_SIZE);
+ this._setItemInfo(name, description, icon);
},
//// Public methods ////
@@ -99,6 +92,33 @@ AppDisplayItem.prototype = {
// Opens an application represented by this display item.
launch : function() {
this._appInfo.launch([], Main.createAppLaunchContext());
+ },
+
+ //// Protected method overrides ////
+
+ // Ensures the preview icon is created.
+ _ensurePreviewIconCreated : function() {
+ if (!this._showPreview || this._previewIcon)
+ return;
+
+ let previewIconPath = null;
+
+ if (this._gicon != null) {
+ let iconTheme = Gtk.IconTheme.get_default();
+ let previewIconInfo = iconTheme.lookup_by_gicon(this._gicon, GenericDisplay.PREVIEW_ICON_SIZE, Gtk.IconLookupFlags.NO_SVG);
+ if (previewIconInfo)
+ previewIconPath = previewIconInfo.get_filename();
+ }
+
+ if (previewIconPath) {
+ try {
+ this._previewIcon = new Clutter.Texture({ width: GenericDisplay.PREVIEW_ICON_SIZE, height: GenericDisplay.PREVIEW_ICON_SIZE});
+ this._previewIcon.set_from_file(previewIconPath);
+ } catch (e) {
+ // we can get an error here if the file path doesn't exist on the system
+ log('Error loading AppDisplayItem preview icon ' + e);
+ }
+ }
}
};
@@ -182,7 +202,9 @@ MenuItem.prototype = {
}
Signals.addSignalMethods(MenuItem.prototype);
-/* Displays favorite and running applications.
+/* This class represents a display containing a collection of application items.
+ * The applications are sorted based on their popularity by default, and based on
+ * their name if some search filter is applied.
*
* width - width available for the display
* height - height available for the display
@@ -192,32 +214,135 @@ function AppDisplay(width, height, numberOfColumns, columnGap) {
}
AppDisplay.prototype = {
- _init : function(width, height) {
- this._favorites = []
- this._menuDisplays = [];
+ __proto__: GenericDisplay.GenericDisplay.prototype,
+
+ _init : function(width, height, numberOfColumns, columnGap) {
+ GenericDisplay.GenericDisplay.prototype._init.call(this, width, height, numberOfColumns, columnGap);
- this.actor = new Tidy.Grid({ width: width, height: height });
+ this._menus = [];
+ this._menuDisplays = [];
// map<itemId, array of category names>
this._appCategories = {};
- this._appMonitor = Shell.AppMonitor.get_default();
- this._appSystem = Shell.AppSystem.get_default();
+ this._appMonitor = new Shell.AppMonitor();
+ this._appSystem = new Shell.AppSystem();
this._appsStale = true;
this._appSystem.connect('changed', Lang.bind(this, function(appSys) {
- // This is a change in the set of known applications
this._appsStale = true;
+ // We still need to determine what events other than search can trigger
+ // a change in the set of applications that are being shown while the
+ // user in in the overlay mode, however let's redisplay just in case.
this._redisplay(false);
+ this._redisplayMenus();
}));
this._appMonitor.connect('changed', Lang.bind(this, function(monitor) {
- // A change in running applications
this._redisplay(false);
}));
// Load the GAppInfos now so it doesn't slow down the first
// transition into the overlay
this._refreshCache();
- this._redisplay(true);
+
+ this._focusInMenus = true;
+ this._activeMenuIndex = -1;
+ this._activeMenu = null;
+ this._activeMenuApps = null;
+ this._menuDisplay = new Big.Box({ orientation: Big.BoxOrientation.VERTICAL,
+ spacing: MENU_SPACING
+ });
+ this._redisplayMenus();
+
+ this.connect('expanded', Lang.bind(this, function (self) {
+ this._filterReset();
+ }));
+ },
+
+ moveRight: function() {
+ if (this._expanded && this._focusInMenu) {
+ this._focusInMenu = false;
+ this._activeMenu.setState(MENU_ENTERED);
+ this.selectFirstItem();
+ }
+ },
+
+ moveLeft: function() {
+ if (this._expanded && !this._focusInMenu) {
+ this._activeMenu.setState(MENU_SELECTED);
+ this.unsetSelected();
+ this._focusInMenu = true;
+ }
+ },
+
+ // Override genericDisplay.js
+ getSideArea: function() {
+ return this._menuDisplay;
+ },
+
+ selectUp: function() {
+ if (!(this._expanded && this._focusInMenu))
+ return GenericDisplay.GenericDisplay.prototype.selectUp.call(this);
+ this._selectMenuIndex(this._activeMenuIndex - 1);
+ return true;
+ },
+
+ selectDown: function() {
+ if (!(this._expanded && this._focusInMenu))
+ return GenericDisplay.GenericDisplay.prototype.selectDown.call(this);
+ this._selectMenuIndex(this._activeMenuIndex+1);
+ return true;
+ },
+
+ // Protected overrides
+
+ _filterActive: function() {
+ return !!this._search || this._activeMenuIndex >= 0;
+ },
+
+ _filterReset: function() {
+ GenericDisplay.GenericDisplay.prototype._filterReset.call(this);
+ if (this._activeMenu != null)
+ this._activeMenu.setState(MENU_UNSELECTED);
+ this._activeMenuIndex = -1;
+ this._activeMenu = null;
+ this._focusInMenu = true;
+ },
+
+ //// Private ////
+
+ _emitStateChange: function() {
+ this.emit('state-changed');
+ },
+
+ _selectMenuIndex: function(index) {
+ if (index < 0 || index >= this._menus.length)
+ return;
+ this._menuDisplays[index].setState(MENU_SELECTED);
+ },
+
+ _redisplayMenus: function() {
+ this._menuDisplay.remove_all();
+ for (let i = 0; i < this._menus.length; i++) {
+ let menu = this._menus[i];
+ let display = new MenuItem(menu.name, menu.id, menu.icon);
+ this._menuDisplays.push(display);
+ let menuIndex = i;
+ display.connect('state-changed', Lang.bind(this, function (display) {
+ let activated = display.getState() != MENU_UNSELECTED;
+ if (!activated && display == this._activeMenu) {
+ this._activeMenuIndex = -1;
+ this._activeMenu = null;
+ } else if (activated) {
+ if (display != this._activeMenu && this._activeMenu != null)
+ this._activeMenu.setState(MENU_UNSELECTED);
+ this._activeMenuIndex = menuIndex;
+ this._activeMenu = display;
+ this._activeMenuApps = this._appSystem.get_applications_for_menu(menu.id);
+ }
+ this._redisplay();
+ }));
+ this._menuDisplay.append(display.actor, 0);
+ }
},
_addApp: function(appId) {
@@ -232,6 +357,9 @@ AppDisplay.prototype = {
}
},
+ //// Protected method overrides ////
+
+ // Gets information about all applications by calling Gio.app_info_get_all().
_refreshCache : function() {
let me = this;
if (!this._appsStale)
@@ -264,11 +392,14 @@ AppDisplay.prototype = {
},
// Sets the list of the displayed items based on the most used apps.
- _redisplay : function() {
+ _setDefaultList : function() {
// Ask or more app than we need, since the list of recently used apps
// might contain an app we don't have a desktop file for
- var running = this._appMonitor.get_running_app_guesses();
- for (let i = 0; i < running.length; i++) {
+ var apps = this._appMonitor.get_most_used_apps (0, Math.round(MAX_ITEMS * 1.5));
+ this._matchedItems = [];
+ for (let i = 0; i < apps.length; i++) {
+ if (this._matchedItems.length > MAX_ITEMS)
+ break;
let appId = apps[i] + ".desktop";
let appInfo = this._allItems[appId];
if (appInfo) {
diff --git a/src/shell-app-monitor.c b/src/shell-app-monitor.c
index 4a29fae..5005540 100644
--- a/src/shell-app-monitor.c
+++ b/src/shell-app-monitor.c
@@ -14,10 +14,8 @@
#include "shell-app-monitor.h"
#include "shell-global.h"
-#include "shell-wm.h"
#include "display.h"
-#include "window.h"
/* This file includes modified code from
* desktop-data-engine/engine-dbus/hippo-application-monitor.c
@@ -95,9 +93,6 @@ struct _ShellAppMonitor
gboolean currently_idle;
gboolean enable_monitoring;
- /* <char *,guint> */
- GHashTable *running_appids;
-
GHashTable *apps_by_wm_class; /* Seen apps by wm_class */
GHashTable *popularities; /* One AppPopularity struct list per activity */
int upload_apps_burst_count;
@@ -196,160 +191,6 @@ destroy_popularity (gpointer key,
g_slist_free (list);
}
-static char *
-get_wmclass_for_window (MetaWindow *window)
-{
- static gboolean patterns_initialized = FALSE;
- const char *wm_class;
- char *title;
- int i;
-
- wm_class = meta_window_get_wm_class (window);
- g_object_get (window, "title", &title, NULL);
-
- if (!patterns_initialized) /* Generate match patterns once for all */
- {
- patterns_initialized = TRUE;
- for (i = 0; title_patterns[i].app_id; i++)
- {
- title_patterns[i].regex = g_regex_new (title_patterns[i].pattern,
- 0, 0, NULL);
- }
- }
-
- /* Match window title patterns to identifiers for non-standard apps */
- if (title)
- {
- for (i = 0; title_patterns[i].app_id; i++)
- {
- if (g_regex_match (title_patterns[i].regex, title, 0, NULL))
- {
- /* Set a pseudo WM class, handled like true ones */
- wm_class = title_patterns[i].app_id;
- break;
- }
- }
- }
-
- g_free (title);
- return g_strdup (wm_class);
-}
-
-static char *
-wmclass_to_appid (const char *wmclass)
-{
- if (!wmclass)
- return NULL;
- return g_utf8_strdown (wmclass, -1);
-}
-
-static char *
-get_appid_for_window (MetaWindow *window)
-{
- char *wmclass;
- char *appid;
-
- if (meta_window_get_window_type (window) != META_WINDOW_NORMAL)
- return NULL;
-
- wmclass = get_wmclass_for_window (window);
- appid = wmclass_to_appid (wmclass);
- g_free (wmclass);
- return appid;
-}
-
-static void
-shell_app_monitor_on_window_added (MetaWorkspace *workspace,
- MetaWindow *window,
- gpointer user_data)
-{
- ShellAppMonitor *self = SHELL_APP_MONITOR (user_data);
- char *appid;
- guint refcount;
-
- appid = get_appid_for_window (window);
- if (!appid)
- return;
-
- refcount = GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
-
- refcount += 1;
- g_hash_table_insert (self->running_appids, appid, GUINT_TO_POINTER (refcount));
- if (refcount == 1)
- g_signal_emit (self, signals[CHANGED], 0);
-}
-
-static void
-shell_app_monitor_on_window_removed (MetaWorkspace *workspace,
- MetaWindow *window,
- gpointer user_data)
-{
- ShellAppMonitor *self = SHELL_APP_MONITOR (user_data);
- char *appid;
- guint refcount;
-
- appid = get_appid_for_window (window);
- if (!appid)
- return;
-
- refcount = GPOINTER_TO_UINT (g_hash_table_lookup (self->running_appids, appid));
-
- refcount -= 1;
- if (refcount == 0)
- {
- g_hash_table_remove (self->running_appids, appid);
- g_free (appid);
- g_signal_emit (self, signals[CHANGED], 0);
- }
- else
- {
- g_hash_table_insert (self->running_appids, appid, GUINT_TO_POINTER (refcount));
- }
-}
-
-static void
-shell_app_monitor_on_n_workspaces_changed (MetaScreen *screen,
- gpointer user_data)
-{
- ShellAppMonitor *self = SHELL_APP_MONITOR (user_data);
- GList *workspaces, *iter;
-
- workspaces = meta_screen_get_workspaces (screen);
-
- for (iter = workspaces; iter; iter = iter->next)
- {
- MetaWorkspace *workspace = iter->data;
-
- g_signal_handlers_disconnect_by_func (workspace,
- shell_app_monitor_on_window_added,
- self);
- g_signal_handlers_disconnect_by_func (workspace,
- shell_app_monitor_on_window_removed,
- self);
-
- g_signal_connect (workspace, "window-added",
- G_CALLBACK (shell_app_monitor_on_window_added), self);
- g_signal_connect (workspace, "window-removed",
- G_CALLBACK (shell_app_monitor_on_window_removed), self);
- }
-}
-
-static void
-init_window_monitoring (ShellAppMonitor *self)
-{
- MetaScreen *screen;
-
- g_object_get (shell_global_get (),
- "screen", &screen,
- NULL);
-
- g_signal_connect (screen, "notify::n-workspaces",
- G_CALLBACK (shell_app_monitor_on_n_workspaces_changed), self);
- shell_app_monitor_on_n_workspaces_changed (screen, self);
-
- g_object_unref (screen);
-}
-
static void
shell_app_monitor_init (ShellAppMonitor *self)
{
@@ -358,6 +199,7 @@ shell_app_monitor_init (ShellAppMonitor *self)
Display *xdisplay;
char *path;
char *shell_config_dir;
+
/* FIXME: should we create as many monitors as there are GdkScreens? */
display = gdk_display_get_default();
xdisplay = GDK_DISPLAY_XDISPLAY (display);
@@ -381,11 +223,6 @@ shell_app_monitor_init (ShellAppMonitor *self)
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
- self->running_appids = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
-
- init_window_monitoring (self);
-
g_object_get (shell_global_get(), "configdir", &shell_config_dir, NULL),
path = g_build_filename (shell_config_dir, DATA_FILENAME, NULL);
g_free (shell_config_dir);
@@ -424,22 +261,6 @@ shell_app_monitor_finalize (GObject *object)
}
/**
- * shell_app_monitor_get_default:
- *
- * Return Value: (transfer none): The global #ShellAppMonitor instance
- */
-ShellAppMonitor *
-shell_app_monitor_get_default ()
-{
- static ShellAppMonitor *instance;
-
- if (instance == NULL)
- instance = g_object_new (SHELL_TYPE_APP_MONITOR, NULL);
-
- return instance;
-}
-
-/**
* shell_app_monitor_get_most_used_apps:
*
* Get a list of desktop identifiers representing the most popular applications
@@ -478,35 +299,16 @@ shell_app_monitor_get_most_used_apps (ShellAppMonitor *monitor,
return list;
}
-/**
- * shell_app_monitor_get_running_app_guesses:
- *
- * Get a list heuristically-determined application identifiers for
- * applications which are presently running. The returned identifiers
- * are only approximate and may need further refinement or analysis.
- *
- * @monitor: An app monitor instance
- *
- * Returns: (element-type utf8) (transfer container): List of application desktop
- * identifiers, in low case
- */
-GList *
-shell_app_monitor_get_running_app_guesses (ShellAppMonitor *monitor)
-{
- return g_hash_table_get_keys (monitor->running_appids);
-}
-
+/* Find the active window in order to collect stats */
void
-update_app_info (ShellAppMonitor *monitor)
+get_active_app_properties (ShellAppMonitor *monitor,
+ char **wm_class,
+ char **title)
{
ShellGlobal *global;
MetaScreen *screen;
MetaDisplay *display;
MetaWindow *active;
- char *wm_class;
- GHashTable *app_active_times = NULL; /* GTime spent per activity */
- int activity;
- guint32 timestamp;
global = shell_global_get ();
g_object_get (global, "screen", &screen, NULL);
@@ -515,10 +317,56 @@ update_app_info (ShellAppMonitor *monitor)
active = meta_display_get_focus_window (display);
- if (!active)
+ if (wm_class)
+ *wm_class = NULL;
+ if (title)
+ *title = NULL;
+
+ if (active == NULL)
return;
- wm_class = get_wmclass_for_window (active);
+ *wm_class = g_strdup (meta_window_get_wm_class (active));
+ *title = g_strdup (meta_window_get_description (active));
+}
+
+void
+update_app_info (ShellAppMonitor *monitor)
+{
+ char *wm_class;
+ char *title;
+ GHashTable *app_active_times = NULL; /* GTime spent per activity */
+ static gboolean first_time = TRUE;
+ int activity;
+ guint32 timestamp;
+ int i;
+
+ if (first_time) /* Generate match patterns once for all */
+ {
+ first_time = FALSE;
+ for (i = 0; title_patterns[i].app_id; i++)
+ {
+ title_patterns[i].regex = g_regex_new (title_patterns[i].pattern,
+ 0, 0, NULL);
+ }
+ }
+
+ get_active_app_properties (monitor, &wm_class, &title);
+
+ /* Match window title patterns to identifiers for non-standard apps */
+ if (title)
+ {
+ for (i = 0; title_patterns[i].app_id; i++)
+ {
+ if ( g_regex_match (title_patterns[i].regex, title, 0, NULL) )
+ {
+ /* Set a pseudo WM class, handled like true ones */
+ g_free (wm_class);
+ wm_class = g_strdup(title_patterns[i].app_id);
+ break;
+ }
+ }
+ g_free (title);
+ }
if (!wm_class)
return;
diff --git a/src/shell-app-monitor.h b/src/shell-app-monitor.h
index 97e35ee..7a808f1 100644
--- a/src/shell-app-monitor.h
+++ b/src/shell-app-monitor.h
@@ -33,7 +33,7 @@ struct _ShellAppMonitorClass
GType shell_app_monitor_get_type (void) G_GNUC_CONST;
-ShellAppMonitor* shell_app_monitor_get_default(void);
+ShellAppMonitor* shell_app_monitor_new(void);
/* Get the most popular applications for a given activity */
GSList *shell_app_monitor_get_most_used_apps (ShellAppMonitor *monitor,
@@ -41,7 +41,8 @@ GSList *shell_app_monitor_get_most_used_apps (ShellAppMonitor *monitor,
gint number);
/* Get whatever's running right now */
-GList *shell_app_monitor_get_running_app_guesses (ShellAppMonitor *monitor);
+GSList *shell_app_monitor_get_running_apps (ShellAppMonitor *monitor,
+ int activity);
G_END_DECLS
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index 8edb955..8829389 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -26,8 +26,6 @@ struct _ShellAppSystemPrivate {
GSList *cached_app_menus; /* ShellAppMenuEntry */
GSList *cached_setting_ids; /* utf8 */
-
- GSList *cached_favorites; /* utf8 */
};
static void shell_app_system_finalize (GObject *object);
@@ -117,22 +115,6 @@ shell_app_system_finalize (GObject *object)
G_OBJECT_CLASS (shell_app_system_parent_class)->finalize(object);
}
-/**
- * shell_app_system_get_default:
- *
- * Return Value: (transfer none): The global #ShellAppSystem singleton
- */
-ShellAppSystem *
-shell_app_system_get_default ()
-{
- static ShellAppSystem *instance = NULL;
-
- if (instance == NULL)
- instance = g_object_new (SHELL_TYPE_APP_SYSTEM, NULL);
-
- return instance;
-}
-
static void
reread_directories (ShellAppSystem *self, GSList **cache, GMenuTree *tree)
{
@@ -312,17 +294,3 @@ shell_app_system_get_all_settings (ShellAppSystem *monitor)
{
return monitor->priv->cached_setting_ids;
}
-
-/**
- * shell_app_system_get_favorites:
- *
- * Return the list of applications which have been explicitly added to the
- * favorites.
- *
- * Return value: (transfer none) (element-type utf8): List of favorite application ids
- */
-GSList *
-shell_app_system_get_favorites (ShellAppSystem *system)
-{
- return monitor->priv->cached_favorites;
-}
diff --git a/src/shell-app-system.h b/src/shell-app-system.h
index c74cb78..cbd2d2e 100644
--- a/src/shell-app-system.h
+++ b/src/shell-app-system.h
@@ -29,7 +29,7 @@ struct _ShellAppSystemClass
};
GType shell_app_system_get_type (void) G_GNUC_CONST;
-ShellAppSystem* shell_app_system_get_default(void);
+ShellAppSystem* shell_app_system_new(void);
GSList *shell_app_system_get_applications_for_menu (ShellAppSystem *system, const char *menu);
@@ -47,6 +47,4 @@ GSList *shell_app_system_get_menus (ShellAppSystem *system);
GSList *shell_app_system_get_all_settings (ShellAppSystem *system);
-GSList *shell_app_system_get_favorites (ShellAppSystem *system);
-
#endif /* __SHELL_APP_SYSTEM_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]