[gnome-boxes/gnome-3-4] Always show topbar when mouse can be grabbed



commit 6c414086850e53a9f2f63bb9e2af8f9ecdfc5aa7
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Tue May 22 18:55:04 2012 +0200

    Always show topbar when mouse can be grabbed
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676307

 src/display-page.vala  |   73 ++++++++++++++++++++++++++++++++++++-----------
 src/display.vala       |    6 ++-
 src/machine.vala       |    4 +-
 src/spice-display.vala |   13 +++++++-
 4 files changed, 73 insertions(+), 23 deletions(-)
---
diff --git a/src/display-page.vala b/src/display-page.vala
index 987e2c3..dd1460c 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -75,6 +75,12 @@ private class Boxes.DisplayPage: GLib.Object {
     private ulong display_id;
     private ulong cursor_id;
 
+    private Boxes.Display display;
+    private bool can_grab_mouse { get { return display.can_grab_mouse; } }
+    private bool grabbed { get { return display.mouse_grabbed; } }
+    private ulong display_can_grab_id;
+    private ulong display_grabbed_id;
+
     public DisplayPage (Boxes.App app) {
         this.app = app;
 
@@ -112,8 +118,8 @@ private class Boxes.DisplayPage: GLib.Object {
 
         overlay = new Overlay ();
         app.window.window_state_event.connect ((event) => {
-            toolbar.visible = !app.fullscreen;
-            set_overlay_toolbar_visible (false);
+            update_toolbar_visible ();
+
             return false;
         });
         overlay.margin = 0;
@@ -137,7 +143,21 @@ private class Boxes.DisplayPage: GLib.Object {
         }
     }
 
-    void set_overlay_toolbar_visible(bool visible) {
+     private void update_toolbar_visible() {
+         if (app.fullscreen && !can_grab_mouse)
+             toolbar.visible = false;
+         else
+             toolbar.visible = true;
+
+         set_overlay_toolbar_visible (false);
+     }
+
+     private void set_overlay_toolbar_visible(bool visible) {
+        if (visible && toolbar.visible) {
+            debug ("toolbar is visible, don't show overlay toolbar");
+            return;
+        }
+
         overlay_toolbar.visible = visible;
     }
 
@@ -155,15 +175,24 @@ private class Boxes.DisplayPage: GLib.Object {
         app.notebook.page = Boxes.AppPage.DISPLAY;
     }
 
-    public void show_display (Boxes.Machine machine, Widget display) {
+    public void show_display (Boxes.Display display, Widget widget) {
         remove_display ();
+
+        this.display = display;
+        display_grabbed_id = display.notify["mouse-grabbed"].connect(() => {
+            update_title();
+        });
+        display_can_grab_id = display.notify["can-grab-mouse"].connect(() => {
+            update_toolbar_visible();
+        });
+
         set_overlay_toolbar_visible (false);
         overlay_toolbar.title = toolbar.title = machine.name;
-        display.set_events (display.get_events () & ~Gdk.EventMask.POINTER_MOTION_MASK);
-        event_box.add (display);
+        widget.set_events (widget.get_events () & ~Gdk.EventMask.POINTER_MOTION_MASK);
+        event_box.add (widget);
         event_box.show_all ();
 
-        display_id = display.event.connect ((event) => {
+        display_id = widget.event.connect ((event) => {
             switch (event.type) {
             case EventType.LEAVE_NOTIFY:
                 toolbar_event_stop ();
@@ -176,11 +205,11 @@ private class Boxes.DisplayPage: GLib.Object {
         });
 
         ulong draw_id = 0;
-        draw_id = display.draw.connect (() => {
-            display.disconnect (draw_id);
+        draw_id = widget.draw.connect (() => {
+            widget.disconnect (draw_id);
 
-            cursor_id = display.get_window ().notify["cursor"].connect (() => {
-                event_box.get_window ().set_cursor (display.get_window ().cursor);
+            cursor_id = widget.get_window ().notify["cursor"].connect (() => {
+                event_box.get_window ().set_cursor (widget.get_window ().cursor);
             });
 
             return false;
@@ -190,21 +219,31 @@ private class Boxes.DisplayPage: GLib.Object {
     }
 
     public Widget? remove_display () {
-        var display = event_box.get_child ();
+        if (display_grabbed_id != 0) {
+            display.disconnect (display_grabbed_id);
+            display_grabbed_id = 0;
+        }
+
+        if (display_can_grab_id != 0) {
+            display.disconnect (display_can_grab_id);
+            display_can_grab_id = 0;
+        }
+
+        var widget = event_box.get_child ();
 
         if (display_id != 0) {
-            display.disconnect (display_id);
+            widget.disconnect (display_id);
             display_id = 0;
         }
         if (cursor_id != 0) {
-            display.get_window ().disconnect (cursor_id);
+            widget.get_window ().disconnect (cursor_id);
             cursor_id = 0;
         }
 
-        if (display != null)
-            event_box.remove (display);
+        if (widget != null)
+            event_box.remove (widget);
 
-        return display;
+        return widget;
     }
 
 }
diff --git a/src/display.vala b/src/display.vala
index 8581475..e24396a 100644
--- a/src/display.vala
+++ b/src/display.vala
@@ -10,8 +10,10 @@ private abstract class Boxes.Display: GLib.Object, Boxes.IPropertiesProvider {
     public abstract string protocol { get; }
     public abstract string uri { owned get; }
 
-    public bool need_password { get; set; }
-    public bool need_username { get; set; }
+    public bool can_grab_mouse { get; protected set; }
+    public bool mouse_grabbed { get; protected set; }
+    public bool need_password { get; protected set; }
+    public bool need_username { get; protected set; }
     public string? password { get; set; }
     public string? username { get; set; }
 
diff --git a/src/machine.vala b/src/machine.vala
index fe2f0ce..c84c3d2 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -62,7 +62,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
                 Timeout.add (app.duration, () => {
                     try {
                         var widget = display.get_display (0);
-                        app.display_page.show_display (this, widget);
+                        app.display_page.show_display (display, widget);
                         widget.grab_focus ();
                     } catch (Boxes.Error error) {
                         warning (error.message);
@@ -404,7 +404,7 @@ private class Boxes.MachineActor: Boxes.UI {
                         display = null;
                         // FIXME: enable grabs
                         machine.display.set_enable_inputs (widget, true);
-                        machine.app.display_page.show_display (machine, widget);
+                        machine.app.display_page.show_display (machine.display, widget);
                     });
                 } else
                     machine.app.display_page.show ();
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 7a64e74..87a70bd 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -56,6 +56,9 @@ private class Boxes.SpiceDisplay: Boxes.Display, Boxes.IPropertiesProvider {
             if (display == null)
                 throw new Boxes.Error.INVALID ("invalid display");
 
+            display.mouse_grab.connect((status) => {
+                mouse_grabbed = status != 0;
+            });
             sync_config_with_display (display, display_saved_properties);
 
             display.scaling = true;
@@ -78,8 +81,14 @@ private class Boxes.SpiceDisplay: Boxes.Display, Boxes.IPropertiesProvider {
         // FIXME: vala does't want to put this in ctor..
         if (channel_new_id == 0)
             channel_new_id = session.channel_new.connect ((channel) => {
-                if (channel is Spice.MainChannel)
-                    channel.channel_event.connect (main_event);
+                if (channel is Spice.MainChannel) {
+                    var main = channel as Spice.MainChannel;
+                    main.channel_event.connect (main_event);
+                    main.notify["mouse-mode"].connect(() => {
+                        can_grab_mouse = main.mouse_mode != 2;
+                    });
+                    can_grab_mouse = main.mouse_mode != 2;
+                }
 
                 if (channel is Spice.DisplayChannel) {
                     var display = channel as DisplayChannel;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]