Add cache cleaning

This commit is contained in:
Tom Beckmann 2013-02-10 13:38:07 +01:00
parent f3eefe7582
commit 4464446d9f
2 changed files with 58 additions and 5 deletions

View File

@ -215,6 +215,17 @@ namespace Gala
Utils.set_input_area (get_screen (), InputArea.NONE); Utils.set_input_area (get_screen (), InputArea.NONE);
} }
public Gee.ArrayList<uint32> get_all_xids ()
{
var list = new Gee.ArrayList<uint32> ();
foreach (var workspace in get_screen ().get_workspaces ()) {
foreach (var window in workspace.list_windows ())
list.add ((uint32)window.get_xwindow ());
}
return list;
}
public void move_window (Window? window, MotionDirection direction) public void move_window (Window? window, MotionDirection direction)
{ {
if (window == null) if (window == null)
@ -503,13 +514,18 @@ namespace Gala
public override void destroy (WindowActor actor) public override void destroy (WindowActor actor)
{ {
var window = actor.get_meta_window ();
if (!AnimationSettings.get_default ().enable_animations) { if (!AnimationSettings.get_default ().enable_animations) {
destroy_completed (actor); destroy_completed (actor);
// only NORMAL windows have icons
if (window.window_type == WindowType.NORMAL)
Utils.request_icon_cache_clean (get_all_xids ());
return; return;
} }
var window = actor.get_meta_window ();
actor.detach_animation (); actor.detach_animation ();
switch (window.window_type) { switch (window.window_type) {
@ -529,6 +545,7 @@ namespace Gala
destroying.remove (actor); destroying.remove (actor);
destroy_completed (actor); destroy_completed (actor);
Utils.request_icon_cache_clean (get_all_xids ());
}); });
break; break;
case WindowType.MODAL_DIALOG: case WindowType.MODAL_DIALOG:

View File

@ -60,6 +60,8 @@ namespace Gala
// Cache xid:pixbuf and icon:pixbuf pairs to provide a faster way aquiring icons // Cache xid:pixbuf and icon:pixbuf pairs to provide a faster way aquiring icons
static Gee.HashMap<string, Gdk.Pixbuf> xid_pixbuf_cache; static Gee.HashMap<string, Gdk.Pixbuf> xid_pixbuf_cache;
static Gee.HashMap<string, Gdk.Pixbuf> icon_pixbuf_cache; static Gee.HashMap<string, Gdk.Pixbuf> icon_pixbuf_cache;
static uint cache_clear_timeout = 0;
static Gee.ArrayList <uint32> tmp_xids;
static construct static construct
{ {
@ -70,10 +72,44 @@ namespace Gala
/** /**
* Clean icon caches * Clean icon caches
*/ */
public static void clear_pixbuf_caches () public static void clean_icon_cache (Gee.ArrayList<uint32> xids)
{ {
xid_pixbuf_cache = new Gee.HashMap<string, Gdk.Pixbuf> (); var list = xid_pixbuf_cache.keys.to_array ();
icon_pixbuf_cache = new Gee.HashMap<string, Gdk.Pixbuf> (); var pixbuf_list = icon_pixbuf_cache.values.to_array ();
var icon_list = icon_pixbuf_cache.keys.to_array ();
for (var i = 0; i < list.length; i++) {
var xid_size = list[i];
var xid = (uint32)int64.parse (xid_size.split ("::")[0]);
if (!(xid in xids)) {
var pixbuf = xid_pixbuf_cache.get (xid_size);
for (var j = 0; j < pixbuf_list.length; j++) {
if (pixbuf_list[j] == pixbuf) {
xid_pixbuf_cache.unset (icon_list[j]);
}
}
xid_pixbuf_cache.unset (xid_size);
}
}
}
public static void request_icon_cache_clean (Gee.ArrayList<uint32> xids)
{
// even if we already have a request queued we always want the newest xid list
tmp_xids = xids;
if (cache_clear_timeout == 0) {
cache_clear_timeout = Timeout.add (3000, () => {
Idle.add (() => {
print ("Clear cache\n");
clean_icon_cache (tmp_xids);
cache_clear_timeout = 0;
return false;
});
return false;
});
}
} }
/** /**