[gnome-boxes] display-page: Use overlay toolbar only in fullscreen mode



commit d974f8ad1f30cd49fd1acc4320bf3e31862df40f
Author: Florian MÃllner <fmuellner gnome org>
Date:   Fri Dec 16 03:58:26 2011 +0100

    display-page: Use overlay toolbar only in fullscreen mode
    
    Triggering the autohidden toolbar is rather tricky when the window
    is not fullscreened and conflicts with the design patter of hiding
    the titlebar of maximized windows. So use a normal toolbar in windowed
    mode and only switch to the autohiding overlay toolbar when in
    fullscreen mode.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=666354

 src/app.vala          |    2 +-
 src/display-page.vala |   78 +++++++++++++++++++++++++++----------------------
 src/machine.vala      |   15 ++++++---
 src/topbar.vala       |    2 +-
 4 files changed, 55 insertions(+), 42 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 6dd4dff..82fb50b 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -292,7 +292,7 @@ private class Boxes.App: Boxes.UI {
         switch (ui_state) {
         case UIState.DISPLAY:
             box.set_layout_manager (new Clutter.FixedLayout ());
-            state.set_state ("display");
+            state.set_state (fullscreen ? "display-fullscreen" : "display");
             break;
 
         case UIState.CREDS:
diff --git a/src/display-page.vala b/src/display-page.vala
index bdc487f..40b24fc 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -68,8 +68,9 @@ private class Boxes.DisplayPage: GLib.Object {
     private Overlay overlay;
     private Boxes.App app;
     private EventBox event_box;
+    private Box box;
+    private DisplayToolbar overlay_toolbar;
     private DisplayToolbar toolbar;
-    private uint toolbar_show_id;
     private uint toolbar_hide_id;
     private ulong display_id;
     private ulong cursor_id;
@@ -81,27 +82,19 @@ private class Boxes.DisplayPage: GLib.Object {
         event_box.set_events (EventMask.POINTER_MOTION_MASK);
         event_box.above_child = true;
         event_box.event.connect ((event) => {
-            if (event.type == EventType.MOTION_NOTIFY) {
+            if (app.fullscreen && event.type == EventType.MOTION_NOTIFY) {
                 var y = event.motion.y;
 
                 if (y == 0) {
                     toolbar_event_stop ();
-                    set_toolbar_visible (true);
-                } else if (!app.fullscreen && y <= 5 && toolbar_show_id == 0) {
+                    set_overlay_toolbar_visible (true);
+                } else if (y > 5 && toolbar_hide_id == 0) {
                     toolbar_event_stop ();
-                    toolbar_show_id = Timeout.add (1000, () => {
-                        set_toolbar_visible (true);
-                        toolbar_show_id = 0;
+                    toolbar_hide_id = Timeout.add (app.duration, () => {
+                        set_overlay_toolbar_visible (false);
+                        toolbar_hide_id = 0;
                         return false;
                     });
-                } else if (y > 5) {
-                    toolbar_event_stop (true, false);
-                    if (toolbar_hide_id == 0)
-                        toolbar_hide_id = Timeout.add (app.duration, () => {
-                            set_toolbar_visible (false);
-                            toolbar_hide_id = 0;
-                            return false;
-                        });
                 }
             }
 
@@ -110,37 +103,52 @@ private class Boxes.DisplayPage: GLib.Object {
 
             return false;
         });
+
+        toolbar = new DisplayToolbar (app);
+
+        box = new Box (Orientation.VERTICAL, 0);
+        box.pack_start (toolbar, false, false, 0);
+        box.pack_start (event_box, true, true, 0);
+
         overlay = new Overlay ();
+        app.window.window_state_event.connect ((event) => {
+            toolbar.visible = !app.fullscreen;
+            set_overlay_toolbar_visible (false);
+            return false;
+        });
         overlay.margin = 0;
-        overlay.add (event_box);
+        overlay.add (box);
 
-        toolbar = new DisplayToolbar (app);
-        toolbar.set_valign (Gtk.Align.START);
+        overlay_toolbar = new DisplayToolbar (app);
+        overlay_toolbar.set_valign (Gtk.Align.START);
 
-        overlay.add_overlay (toolbar);
+        overlay.add_overlay (overlay_toolbar);
         overlay.show_all ();
     }
 
-    void set_toolbar_visible(bool visible) {
-        toolbar.visible = visible;
+    public void get_size (out int width, out int height) {
+        int tb_height;
+
+        app.window.get_size (out width, out height);
+
+        if (!app.fullscreen) {
+            toolbar.get_preferred_height (null, out tb_height);
+            height -= tb_height;
+        }
+    }
+
+    void set_overlay_toolbar_visible(bool visible) {
+        overlay_toolbar.visible = visible;
     }
 
     ~DisplayPage () {
         toolbar_event_stop ();
     }
 
-    private void toolbar_event_stop (bool show = true, bool hide = true) {
-        if (show) {
-            if (toolbar_show_id != 0)
-                GLib.Source.remove (toolbar_show_id);
-            toolbar_show_id = 0;
-        }
-
-        if (hide) {
-            if (toolbar_hide_id != 0)
-                GLib.Source.remove (toolbar_hide_id);
-            toolbar_hide_id = 0;
-        }
+    private void toolbar_event_stop () {
+        if (toolbar_hide_id != 0)
+            GLib.Source.remove (toolbar_hide_id);
+        toolbar_hide_id = 0;
     }
 
     public void show () {
@@ -149,8 +157,8 @@ private class Boxes.DisplayPage: GLib.Object {
 
     public void show_display (Boxes.Machine machine, Widget display) {
         remove_display ();
-        set_toolbar_visible (false);
-        toolbar.title = machine.name;
+        set_overlay_toolbar_visible (false);
+        overlay_toolbar.title = toolbar.title = machine.name;
         event_box.add (display);
         event_box.show_all ();
 
diff --git a/src/machine.vala b/src/machine.vala
index 6eee8e1..651ce3f 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -335,10 +335,15 @@ private class Boxes.MachineActor: Boxes.UI {
     }
 
     public override void ui_state_changed () {
+        int window_width, window_height;
         int width, height;
+        int x, y;
 
         yconstraint.enabled = false;
-        machine.app.window.get_size (out width, out height);
+        machine.app.display_page.get_size (out width, out height);
+        machine.app.window.get_size (out window_width, out window_height);
+        x = window_width - width;
+        y = window_height - height;
 
         switch (ui_state) {
         case UIState.CREDS:
@@ -353,14 +358,14 @@ private class Boxes.MachineActor: Boxes.UI {
                                     "width", (float) width,
                                     "height", (float) height);
                 actor.animate (Clutter.AnimationMode.LINEAR, machine.app.duration,
-                               "x", 0.0f,
-                               "y", 0.0f);
+                               "x", (float) x,
+                               "y", (float) y);
             } else {
                 if (display != null) {
                     // zoom in, back from properties
                     var anim = display.animate (Clutter.AnimationMode.LINEAR, machine.app.duration,
-                                                "x", 0.0f,
-                                                "y", 0.0f,
+                                                "x", (float) x,
+                                                "y", (float) y,
                                                 "width", (float) width,
                                                 "height", (float) height);
                     anim.completed.connect (() => {
diff --git a/src/topbar.vala b/src/topbar.vala
index 044d1a4..57dc934 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -146,7 +146,7 @@ private class Boxes.Topbar: Boxes.UI {
         notebook.show_all ();
 
         // FIXME: make it dynamic depending on topbar size..:
-        app.state.set_key (null, "display", gtk_actor, "y", AnimationMode.EASE_OUT_QUAD, -(float) height, 0, 0);
+        app.state.set_key (null, "display-fullscreen", gtk_actor, "y", AnimationMode.EASE_OUT_QUAD, -(float) height, 0, 0);
     }
 
     private void update_selection_label () {



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