Commits

mathematicalcoffee committed f898e4c

added GNOME 3.6 support.

  • Participants
  • Parent commits 7844367

Comments (0)

Files changed (2)

File status-area-horizontal-spacing@mathematical.coffee.gmail.com/extension.js

  * StatusAreaHorizontalSpacing extension
  * v2.0
  *
- * This extension essentially modifies the "-natural-hpadding" 
+ * This extension essentially modifies the "-natural-hpadding"
  * attribute of panel-buttons (i.e. indicators in the status area)
  * so that they can be closer together.
  *
 /* Note: the gnome-shell class always overrides any you add in the extension.
  * So doing add_style_class(my_style_with_less_hpadding) doesn't work.
  * However set_style sets the inline style and that works.
+ *
+ * In GNOME 3.6 the actor with style class 'panel-button' is not the top-level
+ * actor; they are all nested into St.Bins.
+ *
+ * So we have to drill down to find the GenericConainer.
+ * However, we only recurse down one level to find the actor with style class
+ * 'panel-button' because otherwise we'll spend all day doing it.
  */
-function overrideStyle(container, actor) {
-    if (actor.has_style_class_name('panel-button')) {
-        if (actor._original_inline_style_ === undefined) {
-            actor._original_inline_style_ = actor.get_style();
+function overrideStyle(actor, secondTime) {
+    // it could be that the first child has the right style class name.
+    if (!actor.has_style_class_name ||
+            !actor.has_style_class_name('panel-button')) {
+        if (secondTime) {
+            // if we've already recursed once, then give up (we will only look
+            // one level down to find the 'panel-button' actor).
+            return;
         }
-        actor.set_style(styleLine + '; ' + (actor._original_inline_style_ || ''));
-        /* listen for the style being set externally so we can re-apply our style */
-        // TODO: somehow throttle the number of calls to this - add a timeout with
-        // a flag?
-        if (!actor._statusAreaHorizontalSpacingSignalID) {
-            actor._statusAreaHorizontalSpacingSignalID =
-                actor.connect('style-changed', function () {
-                    let currStyle = actor.get_style();
-                    if (currStyle && !currStyle.match(styleLine)) {
-                        // re-save the style (if it has in fact changed)
-                        actor._original_inline_style_ = currStyle;
-                        // have to do this or else the overrideStyle call will trigger
-                        // another call of this, firing an endless series of these signals.
-                        // TODO: a ._style_pending which prevents it rather than disconnect/connect?
-                        actor.disconnect(actor._statusAreaHorizontalSpacingSignalID);
-                        delete actor._statusAreaHorizontalSpacingSignalID;
-                        overrideStyle(container, actor);
-                    }
-                });
+        let child = actor.get_children();
+        if (child.length) {
+            overrideStyle(child[0], true);
         }
+        return;
+    }
+
+    if (actor._original_inline_style_ === undefined) {
+        actor._original_inline_style_ = actor.get_style();
+    }
+    actor.set_style(styleLine + '; ' + (actor._original_inline_style_ || ''));
+    /* listen for the style being set externally so we can re-apply our style */
+    // TODO: somehow throttle the number of calls to this - add a timeout with
+    // a flag?
+    if (!actor._statusAreaHorizontalSpacingSignalID) {
+        actor._statusAreaHorizontalSpacingSignalID =
+            actor.connect('style-changed', function () {
+                let currStyle = actor.get_style();
+                if (currStyle && !currStyle.match(styleLine)) {
+                    // re-save the style (if it has in fact changed)
+                    actor._original_inline_style_ = currStyle;
+                    // have to do this or else the overrideStyle call will trigger
+                    // another call of this, firing an endless series of these signals.
+                    // TODO: a ._style_pending which prevents it rather than disconnect/connect?
+                    actor.disconnect(actor._statusAreaHorizontalSpacingSignalID);
+                    delete actor._statusAreaHorizontalSpacingSignalID;
+                    overrideStyle(actor);
+                }
+            });
     }
 }
 
-function restoreOriginalStyle(actor) {
-    actor.disconnect(actor._statusAreaHorizontalSpacingSignalID);
-    delete actor._statusAreaHorizontalSpacingSignalID;
-    if (actor.has_style_class_name('panel-button') && actor._original_inline_style_ !== undefined) {
+// see the note in overrideStyle about us having to recurse down to the first
+// child of `actor` in order to find the container with style class name
+// 'panel-button' (applying our style to the parent container won't work).
+function restoreOriginalStyle(actor, secondTime) {
+    if (!actor.has_style_class_name ||
+            !actor.has_style_class_name('panel-button')) {
+        if (secondTime) {
+            // if we've already recursed once, then give up (we will only look
+            // one level down to find the 'panel-button' actor).
+            return;
+        }
+        let child = actor.get_children();
+        if (child.length) {
+            restoreOriginalStyle(child[0], true);
+        }
+        return;
+    }
+    if (actor._statusAreaHorizontalSpacingSignalID) {
+        actor.disconnect(actor._statusAreaHorizontalSpacingSignalID);
+        delete actor._statusAreaHorizontalSpacingSignalID;
+    }
+    if (actor._original_inline_style_ !== undefined) {
         actor.set_style(actor._original_inline_style_);
         delete actor._original_inline_style_;
     }
     /* set style for everything in _rightBox */
     let children = Main.panel._rightBox.get_children();
     for (let i = 0; i < children.length; ++i) {
-        overrideStyle(Main.panel._rightBox, children[i]);
+        overrideStyle(children[i]);
     }
 
     /* connect signal */
-    actorAddedID = Main.panel._rightBox.connect('actor-added', overrideStyle);
+    actorAddedID = Main.panel._rightBox.connect('actor-added',
+        function (container, actor) {
+            overrideStyle(actor);
+        }
+    );
 }
 
 /* Remove hpadding style from all existing actors & stop listening for more */

File status-area-horizontal-spacing@mathematical.coffee.gmail.com/metadata.json

 {
     "shell-version": [
-        "3.4"
+        "3.4",
+        "3.6"
         ],
     "uuid": "status-area-horizontal-spacing@mathematical.coffee.gmail.com",
     "name": "Status Area Horizontal Spacing",