[gnome-shell/gnome-3-30] workspace: Confine caption width to workspace area



commit 3dffdab1ad5be8e0b4a624d4cbac7ba4a7947be4
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Sep 1 16:57:59 2018 +0000

    workspace: Confine caption width to workspace area
    
    When we started to only show a single caption at a time, we allowed
    title captions to be wider than their corresponding window preview.
    But while overlapping neighboring previews is fine, we shouldn't
    allow the captions to leak outside the workspace area itself and
    overlap unrelated elements like workspace switcher or dash.
    
    This partly reverts commit b3b30f239d.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/214
    
    
    (cherry picked from commit 6099e92df59c29f1f3f9ecd49af8caeecd787bfa)

 js/ui/workspace.js | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index 5aa9ba66c..b85b48b7a 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -465,6 +465,8 @@ var WindowOverlay = new Lang.Class({
         title.clutter_text.ellipsize = Pango.EllipsizeMode.END;
         windowClone.actor.label_actor = title;
 
+        this._maxTitleWidth = -1;
+
         this._updateCaptionId = metaWindow.connect('notify::title', w => {
             this.title.text = w.title;
             this.title.text = this._getCaption();
@@ -528,6 +530,13 @@ var WindowOverlay = new Lang.Class({
                 Math.max(this.borderSize, this.closeButton.width - this.closeButton._overlap)];
     },
 
+    setMaxChromeWidth(max) {
+        if (this._maxTitleWidth == max)
+            return;
+
+        this._maxTitleWidth = max;
+    },
+
     relayout(animate) {
         let button = this.closeButton;
         let title = this.title;
@@ -554,13 +563,26 @@ var WindowOverlay = new Lang.Class({
         else
             button.set_position(Math.floor(buttonX), Math.floor(buttonY));
 
-        let titleX = cloneX + (cloneWidth - title.width) / 2;
+        // Clutter.Actor.get_preferred_width() will return the fixed width if
+        // one is set, so we need to reset the width by calling set_width(-1),
+        // to forward the call down to StLabel.
+        // We also need to save and restore the current width, otherwise the
+        // animation starts from the wrong point.
+        let prevTitleWidth = title.width;
+        title.set_width(-1);
+
+        let [titleMinWidth, titleNatWidth] = title.get_preferred_width(-1);
+        let titleWidth = Math.max(titleMinWidth,
+                                  Math.min(titleNatWidth, this._maxTitleWidth));
+        title.width = prevTitleWidth;
+
+        let titleX = cloneX + (cloneWidth - titleWidth) / 2;
         let titleY = cloneY + cloneHeight - (title.height - this.borderSize) / 2;
 
         if (animate) {
-            this._animateOverlayActor(title, Math.floor(titleX), Math.floor(titleY), title.width);
+            this._animateOverlayActor(title, Math.floor(titleX), Math.floor(titleY), titleWidth);
         } else {
-            title.width = title.width;
+            title.width = titleWidth;
             title.set_position(Math.floor(titleX), Math.floor(titleY));
         }
 
@@ -1306,6 +1328,12 @@ var Workspace = new Lang.Class({
             let cloneHeight = clone.actor.height * scale;
             clone.slot = [x, y, cloneWidth, cloneHeight];
 
+            let cloneCenter = x + cloneWidth / 2;
+            let maxChromeWidth = 2 * Math.min(
+                cloneCenter - area.x,
+                area.x + area.width - cloneCenter);
+            overlay.setMaxChromeWidth(Math.round(maxChromeWidth));
+
             if (overlay && (initialPositioning || !clone.positioned))
                 overlay.hide();
 


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