[gnome-shell] Overview: Resize the window title labels on content change



commit 687e1eabeda7bf505cb8d4cf3960280941962509
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Oct 19 18:37:29 2012 +0200

    Overview: Resize the window title labels on content change
    
    Reposition the window overlay when the title changes, using the current
    transformed size of the window clone.
    Includes a test that changes title to a string of random length every 3 seconds.
    
    Based on a patch by Alex Hultman <alexhultman gmail com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=620874

 js/ui/workspace.js              |   33 ++++++++++++++++++++++++++++++---
 tests/interactive/test-title.js |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index 6175999..3005c8d 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -159,6 +159,24 @@ const WindowClone = new Lang.Class({
         this._selected = false;
     },
 
+    get slot() {
+        let x, y, w, h;
+
+        if (this.inDrag) {
+            x = this.dragOrigX;
+            y = this.dragOrigY;
+            w = this.actor.width * this.dragOrigScale;
+            h = this.actor.height * this.dragOrigScale;
+        } else {
+            x = this.actor.x;
+            y = this.actor.y;
+            w = this.actor.width * this.actor.scale_x;
+            h = this.actor.height * this.actor.scale_y;
+        }
+
+        return [x, y, w, h];
+    },
+
     setStackAbove: function (actor) {
         this._stackAbove = actor;
         if (this.inDrag || this._zooming)
@@ -435,6 +453,11 @@ const WindowOverlay = new Lang.Class({
         this._updateCaptionId = metaWindow.connect('notify::title',
             Lang.bind(this, function(w) {
                 this.title.text = w.title;
+                // we need this for the next call to get_preferred_width
+                // to return useful results
+                this.title.set_size(-1, -1);
+
+                this._repositionSelf();
             }));
 
         let button = new St.Button({ style_class: 'window-close' });
@@ -501,6 +524,11 @@ const WindowOverlay = new Lang.Class({
                 this.title.height + this.title._spacing];
     },
 
+    _repositionSelf: function() {
+        let [cloneX, cloneY, cloneWidth, cloneHeight] = this._windowClone.slot;
+        this.updatePositions(cloneX, cloneY, cloneWidth, cloneHeight, false);
+    },
+
     /**
      * @cloneX: x position of windowClone
      * @cloneY: y position of windowClone
@@ -538,9 +566,8 @@ const WindowOverlay = new Lang.Class({
         else
             button.set_position(Math.floor(buttonX), Math.floor(buttonY));
 
-        if (!title.fullWidth)
-            title.fullWidth = title.width;
-        let titleWidth = Math.min(title.fullWidth, cloneWidth);
+        let [titleMinWidth, titleNatWidth] = title.get_preferred_width(-1);
+        let titleWidth = Math.max(titleMinWidth, Math.min(titleNatWidth, cloneWidth));
 
         let titleX = cloneX + (cloneWidth - titleWidth) / 2;
         let titleY = cloneY + cloneHeight + title._spacing;
diff --git a/tests/interactive/test-title.js b/tests/interactive/test-title.js
new file mode 100755
index 0000000..54bbc91
--- /dev/null
+++ b/tests/interactive/test-title.js
@@ -0,0 +1,34 @@
+#!/usr/bin/env gjs
+
+const Gtk = imports.gi.Gtk;
+const Mainloop = imports.mainloop;
+
+function nextTitle() {
+    let length = Math.random() * 20;
+    let str = '';
+
+    for (let i = 0; i < length; i++) {
+        // 97 == 'a'
+        str += String.fromCharCode(97 + Math.random() * 26);
+    }
+
+    return str;
+}
+
+function main() {
+    Gtk.init(null);
+
+    let win = new Gtk.Window({ title: nextTitle() });
+    win.connect('destroy', Gtk.main_quit);
+    win.present();
+
+    Mainloop.timeout_add(5000, function() {
+        win.title = nextTitle();
+        return true;
+    });
+
+    Gtk.main();
+}
+
+main();
+



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