mirror of
https://github.com/elementary/gala.git
synced 2024-12-21 00:01:36 +03:00
Add cache cleaning
This commit is contained in:
parent
f3eefe7582
commit
4464446d9f
@ -215,6 +215,17 @@ namespace Gala
|
||||
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)
|
||||
{
|
||||
if (window == null)
|
||||
@ -503,13 +514,18 @@ namespace Gala
|
||||
|
||||
public override void destroy (WindowActor actor)
|
||||
{
|
||||
var window = actor.get_meta_window ();
|
||||
|
||||
if (!AnimationSettings.get_default ().enable_animations) {
|
||||
destroy_completed (actor);
|
||||
|
||||
// only NORMAL windows have icons
|
||||
if (window.window_type == WindowType.NORMAL)
|
||||
Utils.request_icon_cache_clean (get_all_xids ());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var window = actor.get_meta_window ();
|
||||
|
||||
actor.detach_animation ();
|
||||
|
||||
switch (window.window_type) {
|
||||
@ -529,6 +545,7 @@ namespace Gala
|
||||
|
||||
destroying.remove (actor);
|
||||
destroy_completed (actor);
|
||||
Utils.request_icon_cache_clean (get_all_xids ());
|
||||
});
|
||||
break;
|
||||
case WindowType.MODAL_DIALOG:
|
||||
|
@ -60,6 +60,8 @@ namespace Gala
|
||||
// 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> icon_pixbuf_cache;
|
||||
static uint cache_clear_timeout = 0;
|
||||
static Gee.ArrayList <uint32> tmp_xids;
|
||||
|
||||
static construct
|
||||
{
|
||||
@ -70,10 +72,44 @@ namespace Gala
|
||||
/**
|
||||
* 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> ();
|
||||
icon_pixbuf_cache = new Gee.HashMap<string, Gdk.Pixbuf> ();
|
||||
var list = xid_pixbuf_cache.keys.to_array ();
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user