[gnome-shell] LayoutManager: add a ClutterConstraint for tracking monitor sizes



commit 3e94f6bc3cb3d15a1604b7a6e032064e240709a3
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Aug 14 15:37:12 2012 +0200

    LayoutManager: add a ClutterConstraint for tracking monitor sizes
    
    Instead of connecting manually to LayoutManager, or using ShellGenericContainer,
    make a ClutterConstraint subclass that can track automatically
    a specific monitor index, or the primary monitor.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681743

 js/ui/layout.js |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/layout.js b/js/ui/layout.js
index a4da201..266d22c 100644
--- a/js/ui/layout.js
+++ b/js/ui/layout.js
@@ -1,6 +1,7 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Clutter = imports.gi.Clutter;
+const GObject = imports.gi.GObject;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Meta = imports.gi.Meta;
@@ -17,6 +18,79 @@ const HOT_CORNER_ACTIVATION_TIMEOUT = 0.5;
 const STARTUP_ANIMATION_TIME = 0.2;
 const KEYBOARD_ANIMATION_TIME = 0.5;
 
+const MonitorConstraint = new Lang.Class({
+    Name: 'MonitorConstraint',
+    Extends: Clutter.Constraint,
+    Properties: {'primary': GObject.ParamSpec.boolean('primary', 
+                                                      'Primary', 'Track primary monitor',
+                                                      GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                                      false),
+                 'index': GObject.ParamSpec.int('index',
+                                                'Monitor index', 'Track specific monitor',
+                                                GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE,
+                                                -1, 64, -1)},
+
+    _init: function(props) {
+        this._primary = false;
+        this._index = -1;
+
+        this.parent(props);
+    },
+
+    get primary() {
+        return this._primary;
+    },
+
+    set primary(v) {
+        this._primary = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('primary');
+    },
+
+    get index() {
+        return this._index;
+    },
+
+    set index(v) {
+        this._index = v;
+        if (this.actor)
+            this.actor.queue_relayout();
+        this.notify('index');
+    },
+
+    vfunc_set_actor: function(actor) {
+        if (actor) {
+            if (!this._monitorsChangedId) {
+                this._monitorsChangedId = Main.layoutManager.connect('monitors-changed', Lang.bind(this, function() {
+                    this.actor.queue_relayout();
+                }));
+            }
+        } else {
+            if (this._monitorsChangedId)
+                Main.layoutManager.disconnect(this._monitorsChangedId);
+            this._monitorsChangedId = 0;
+        }
+
+        this.parent(actor);
+    },
+
+    vfunc_update_allocation: function(actor, actorBox) {
+        if (!this._primary && this._index < 0)
+            return;
+
+        let monitor;
+        if (this._primary) {
+            monitor = Main.layoutManager.primaryMonitor;
+        } else {
+            let index = Math.max(this._index, Main.layoutManager.monitors.length);
+            monitor = Main.layoutManager.monitors[index];
+        }
+
+        actorBox.init_rect(monitor.x, monitor.y, monitor.width, monitor.height);
+    }
+});
+
 const LayoutManager = new Lang.Class({
     Name: 'LayoutManager',
 



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