[gnome-boxes] Draw stopped machines as black screenshots
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Draw stopped machines as black screenshots
- Date: Fri, 31 Aug 2012 13:21:52 +0000 (UTC)
commit d134749e0f774163e0ab96d76f39b3c0fd235e6a
Author: Alexander Larsson <alexl redhat com>
Date: Thu Aug 30 22:23:24 2012 +0200
Draw stopped machines as black screenshots
Showing a random last-saved screenshot isn't right for stopped
VMs as this is not at all what will be seen when clicking on them,
and its hard to tell which VMs are turned off.
Later we want to also overlay OS logos if available.
https://bugzilla.gnome.org/show_bug.cgi?id=683067
src/libvirt-machine.vala | 3 ++-
src/machine.vala | 27 ++++++++++++++++++++++-----
2 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 91e569f..1af4e45 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -127,7 +127,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
update_domain_config ();
domain.updated.connect (update_domain_config);
- load_screenshot ();
+ if (state != MachineState.STOPPED)
+ load_screenshot ();
set_screenshot_enable (true);
set_stats_enable (true);
}
diff --git a/src/machine.vala b/src/machine.vala
index 43be6b8..31e6a38 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -31,13 +31,21 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
PAUSED
}
+ // The current screenshot without running status applied
+ private Gdk.Pixbuf? orig_pixbuf;
+
private MachineState _state;
public MachineState state { get { return _state; }
protected set {
_state = value;
debug ("State of '%s' changed to %s", name, state.to_string ());
- if (value != MachineState.RUNNING)
- load_screenshot ();
+ if (value == MachineState.STOPPED)
+ set_screenshot (null, false);
+ else {
+ // Update existing screenshot based on machine status
+ if (orig_pixbuf != null)
+ pixbuf = draw_vm (orig_pixbuf, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
+ }
}
}
@@ -252,13 +260,15 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
var small_screenshot = new Gdk.Pixbuf (Gdk.Colorspace.RGB, large_screenshot.has_alpha, 8, w, h);
large_screenshot.scale (small_screenshot, 0, 0, w, h, 0, 0, s, s, Gdk.InterpType.HYPER);
+ orig_pixbuf = small_screenshot;
pixbuf = draw_vm (small_screenshot, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT);
machine_actor.set_screenshot (large_screenshot); // high resolution
if (save)
save_pixbuf_as_screenshot (small_screenshot);
- } else if (pixbuf == null) {
- pixbuf = draw_fallback_vm ();
+ } else {
+ orig_pixbuf = null;
+ pixbuf = draw_stopped_vm ();
machine_actor.set_screenshot (pixbuf);
}
}
@@ -281,7 +291,8 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
} catch (GLib.Error error) {
}
// Save the screenshot first time and every 60 sec
- set_screenshot (large_screenshot, force_save || screenshot_counter++ % 12 == 0);
+ if (large_screenshot != null)
+ set_screenshot (large_screenshot, force_save || screenshot_counter++ % 12 == 0);
updating_screenshot = false;
}
@@ -318,6 +329,12 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
return Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
}
+ private static Gdk.Pixbuf draw_stopped_vm (int width = SCREENSHOT_WIDTH,
+ int height = SCREENSHOT_HEIGHT) {
+ var surface = new Cairo.ImageSurface (Cairo.Format.RGB24, width, height);
+ return Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
+ }
+
private static Gdk.Pixbuf? default_fallback = null;
private static Gdk.Pixbuf draw_fallback_vm (int width = SCREENSHOT_WIDTH,
int height = SCREENSHOT_HEIGHT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]