[gnome-boxes] Allow drag to unfullscreen



commit 715d4f1ee7d37a7f979e13df8883cde66a85ca69
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Feb 20 12:24:29 2013 +0100

    Allow drag to unfullscreen
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686935

 src/display-page.vala |   61 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/src/display-page.vala b/src/display-page.vala
index 0b77ffc..80e6c1c 100644
--- a/src/display-page.vala
+++ b/src/display-page.vala
@@ -10,6 +10,7 @@ private class Boxes.DisplayToolbar: Gd.MainToolbar {
     private Gtk.Box rightbox;
 
     public DisplayToolbar (bool overlay) {
+        add_events (Gdk.EventMask.POINTER_MOTION_MASK);
         this.overlay = overlay;
         if (overlay)
             get_style_context ().add_class ("osd");
@@ -55,6 +56,66 @@ private class Boxes.DisplayToolbar: Gd.MainToolbar {
         button.get_style_context ().add_class ("image-button");
         return button;
     }
+
+    private bool button_down;
+    private int button_down_x;
+    private int button_down_y;
+    private uint button_down_button;
+
+    public override bool button_press_event (Gdk.EventButton event) {
+        var res = base.button_press_event (event);
+
+        // With the current GdkEvent bindings this is the only way to
+        // upcast a GdkEventButton to a GdkEvent (which we need for
+        // the triggerts_context_menu() method call.
+        // TODO: Fix this when vala bindings are corrected
+        Gdk.Event *base_event = (Gdk.Event *)(&event);
+
+        if (!res && !base_event->triggers_context_menu ()) {
+            button_down = true;
+            button_down_button = event.button;
+            button_down_x = (int)event.x;
+            button_down_y = (int)event.y;
+        }
+        return res;
+    }
+
+    public override bool button_release_event (Gdk.EventButton event) {
+        button_down = false;
+        return base.button_press_event (event);
+    }
+
+    public override bool motion_notify_event (Gdk.EventMotion event) {
+        if (button_down) {
+            double dx = event.x - button_down_x;
+            double dy = event.y - button_down_y;
+
+            // Break out when the dragged distance is 40 pixels
+            if (dx * dx + dy * dy > 40 * 40) {
+                button_down = false;
+                App.app.fullscreen = false;
+
+                var window = get_toplevel () as Gtk.Window;
+                int old_width;
+                window.get_size (out old_width, null);
+
+                ulong id = 0;
+                id = App.app.notify["fullscreen"].connect ( () => {
+                    int root_x, root_y, width;
+                    window.get_position (out root_x, out root_y);
+                    window.get_window ().get_geometry (null, null, out width, null);
+                    window.begin_move_drag ((int)button_down_button,
+                                            root_x + (int)((button_down_x / (double)old_width) * width),
+                                            root_y + button_down_y,
+                                            event.time);
+                    App.app.disconnect (id);
+                } );
+            }
+        }
+        if (base.motion_notify_event != null)
+            return base.motion_notify_event (event);
+        return false;
+    }
 }
 
 private class Boxes.DisplayPage: GLib.Object {


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