[gnome-boxes] Start or resume VM if needed
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Start or resume VM if needed
- Date: Thu, 20 Oct 2011 10:06:07 +0000 (UTC)
commit 021c609787909d972a6cbe878f6660c671d52e15
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Thu Oct 20 00:11:50 2011 +0200
Start or resume VM if needed
src/app.vala | 7 +++++-
src/machine.vala | 56 ++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 52 insertions(+), 11 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 35a48ca..ba913fc 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -167,6 +167,11 @@ private class Boxes.App: Boxes.UI {
}
if (event.keyval == F12_KEY) {
+ if (current_item is Machine) {
+ var machine = current_item as Machine;
+
+ machine.connect_display = false;
+ }
ui_state = UIState.COLLECTION;
}
@@ -180,7 +185,7 @@ private class Boxes.App: Boxes.UI {
if (current_item is Machine) {
var machine = current_item as Machine;
- machine.connect_display ();
+ machine.connect_display = true;
ui_state = UIState.CREDS;
} else
diff --git a/src/machine.vala b/src/machine.vala
index 4c74bfe..66728dc 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -113,15 +113,46 @@ private class Boxes.Machine: Boxes.CollectionItem {
return true;
}
- public bool connect_display () {
- update_display ();
-
- if (display == null)
- return false;
+ private ulong started_id;
+ private bool _connect_display;
+ public bool connect_display {
+ get { return _connect_display; }
+ set {
+ if (_connect_display == value)
+ return;
- display.connect_it ();
+ if (value && state != DomainState.RUNNING) {
+ if (started_id != 0)
+ return;
+
+ if (state == DomainState.PAUSED) {
+ started_id = domain.resumed.connect (() => {
+ domain.disconnect (started_id);
+ started_id = 0;
+ connect_display = true;
+ });
+ try {
+ domain.resume ();
+ } catch (GLib.Error e) {
+ warning (e.message);
+ }
+ } else if (state != DomainState.RUNNING) {
+ started_id = domain.started.connect (() => {
+ domain.disconnect (started_id);
+ started_id = 0;
+ connect_display = true;
+ });
+ try {
+ domain.start (0);
+ } catch (GLib.Error e) {
+ warning (e.message);
+ }
+ }
+ }
- return true;
+ _connect_display = value;
+ update_display ();
+ }
}
private string get_screenshot_filename (string ext = "ppm") {
@@ -144,7 +175,7 @@ private class Boxes.Machine: Boxes.CollectionItem {
if (pixbuf == null)
pixbuf = draw_fallback_vm (width, height);
else
- pixbuf = draw_vm (pixbuf, width, height);
+ pixbuf = draw_vm (pixbuf, pixbuf.get_width (), pixbuf.get_height ());
try {
machine_actor.set_screenshot (pixbuf);
@@ -183,7 +214,7 @@ private class Boxes.Machine: Boxes.CollectionItem {
context.paint ();
context.identity_matrix ();
- context.scale (0.1875, 0.1875);
+ context.scale (0.1875 / 128 * width, 0.1875 / 96 * height);
var grid = new Cairo.Pattern.for_surface (new Cairo.ImageSurface.from_png (get_pixmap ("boxes-grid.png")));
grid.set_extend (Cairo.Extend.REPEAT);
context.set_source_rgba (1, 1, 1, 1);
@@ -235,12 +266,17 @@ private class Boxes.Machine: Boxes.CollectionItem {
}
if (type == "spice") {
+ if (display != null)
+ display.disconnect_it ();
display = new SpiceDisplay (ghost, int.parse (gport));
} else {
warning ("unsupported display of type " + type);
return;
}
+
+ if (connect_display)
+ display.connect_it ();
}
public override void ui_state_changed () {
@@ -290,7 +326,7 @@ private class Boxes.MachineActor: Boxes.UI {
if (event.keyval == Gdk.Key.KP_Enter ||
event.keyval == Gdk.Key.ISO_Enter ||
event.keyval == Gdk.Key.Return) {
- machine.connect_display ();
+ machine.connect_display = true;
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]