[gnome-shell-extensions] native-window-placement: make placement strategy a setting



commit 1a00ee38fe9ce3addb797d8ca0f4c9ec4758fa62
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Thu May 12 19:32:50 2011 +0200

    native-window-placement: make placement strategy a setting
    
    Now it is possible to use GSettings to configure the placement
    strategy (natural KDE-like or default grid) and whether to consolidate
    the windows more tigthly, as well as the position of the window
    captions.

 extensions/native-window-placement/Makefile.am     |   11 ++++++
 extensions/native-window-placement/extension.js    |   33 +++++++++++++++-----
 ...tensions.native-window-placement.gschema.xml.in |   26 +++++++++++++++
 po/POTFILES.in                                     |    1 +
 4 files changed, 63 insertions(+), 8 deletions(-)
---
diff --git a/extensions/native-window-placement/Makefile.am b/extensions/native-window-placement/Makefile.am
index c53a614..6d86e1f 100644
--- a/extensions/native-window-placement/Makefile.am
+++ b/extensions/native-window-placement/Makefile.am
@@ -1,3 +1,14 @@
 EXTENSION_ID = native-window-placement
 
 include ../../extension.mk
+
+gschemas_in = org.gnome.shell.extensions.native-window-placement.gschema.xml.in
+
+ INTLTOOL_XML_NOMERGE_RULE@
+
+gsettings_SCHEMAS = $(gschemas_in:.xml.in=.xml)
+
+ GSETTINGS_RULES@
+
+CLEANFILES += $(gschemas_in:.xml.in=.valid) $(gsettings_SCHEMAS)
+EXTRA_DIST += $(gschemas_in)
diff --git a/extensions/native-window-placement/extension.js b/extensions/native-window-placement/extension.js
index 7ced09c..ce8a991 100644
--- a/extensions/native-window-placement/extension.js
+++ b/extensions/native-window-placement/extension.js
@@ -1,6 +1,7 @@
 // -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
 // import just everything from workspace.js:
 const Clutter = imports.gi.Clutter;
+const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Meta = imports.gi.Meta;
@@ -19,9 +20,12 @@ const Tweener = imports.ui.tweener;
 const Workspace = imports.ui.workspace;
 const WindowPositionFlags = Workspace.WindowPositionFlags;
 
+const WindowPlacementStrategy = {
+    NATURAL: 0,
+    GRID: 1,
+};
+
 // testing settings for natural window placement strategy:
-const WINDOW_PLACEMENT_STRATEGY = "natural"                         // window placement strategy: natural | grid
-const WINDOW_PLACEMENT_NATURAL_MORESCREEN = true;                   // activate mod4-directions-part that tries to use more screen real estate
 const WINDOW_PLACEMENT_NATURAL_FILLGAPS = true;                     // enlarge windows at the end to fill gaps         // not implemented yet
 const WINDOW_PLACEMENT_NATURAL_GRID_FALLBACK = true;                // fallback to grid mode if all windows have the same size and positions.     // not implemented yet
 const WINDOW_PLACEMENT_NATURAL_ACCURACY = 20;                       // accuracy of window translate moves  (KDE-default: 20)
@@ -105,6 +109,18 @@ Rect.prototype = {
 
 // Put your extension initialization code here
 function main() {
+    let settings = new Gio.Settings({ schema: 'org.gnome.shell.extensions.native-window-placement' });
+    let placementStrategy = settings.get_enum('strategy');
+    settings.connect('changed::strategy', function() {
+        placementStrategy = settings.get_enum('strategy');
+        // we don't update immediately, we wait for a relayout
+        // (and hope for the best)
+    });
+    let useMoreScreen = settings.get_boolean('use-more-screen');
+    settings.connect('changed::use-more-screen', function() {
+        useMoreScreen = settings.get_boolean('use-more-screen');
+    });
+
     /**
      * _calculateWindowTransformationsNatural:
      * @clones: Array of #MetaWindow
@@ -182,7 +198,7 @@ function main() {
                         rects[j].translate(diff[0], diff[1]);
 
 
-                        if (WINDOW_PLACEMENT_NATURAL_MORESCREEN) {
+                        if (useMoreScreen) {
                             // Try to keep the bounding rect the same aspect as the screen so that more
                             // screen real estate is utilised. We do this by splitting the screen into nine
                             // equal sections, if the window center is in any of the corner sections pull the
@@ -316,12 +332,14 @@ function main() {
 	let targets = [];
         let scales = [];
 
-        switch (WINDOW_PLACEMENT_STRATEGY) {
-        case "natural":
+        switch (placementStrategy) {
+        case WindowPlacementStrategy.NATURAL:
             [clones, targets] = this._calculateWindowTransformationsNatural(clones);
             break;
-        case "grid":
         default:
+            log ('Invalid window placement strategy');
+            placementStrategy = WindowPlacementStrategy.GRID;
+        case WindowPlacementStrategy.GRID:
             [clones, targets] = this._calculateWindowTransformationsGrid(clones);
             break;
         }
@@ -384,8 +402,7 @@ function main() {
     }
 
     /// position window titles on top of windows in overlay ////
-
-    if ( PLACE_WINDOW_CAPTIONS_ON_TOP )  {
+    if (settings.get_boolean('window-captions-on-top'))  {
 	Workspace.WindowOverlay.prototype._init = function(windowClone, parentActor) {
             let metaWindow = windowClone.metaWindow;
 
diff --git a/extensions/native-window-placement/org.gnome.shell.extensions.native-window-placement.gschema.xml.in b/extensions/native-window-placement/org.gnome.shell.extensions.native-window-placement.gschema.xml.in
new file mode 100644
index 0000000..873bfd7
--- /dev/null
+++ b/extensions/native-window-placement/org.gnome.shell.extensions.native-window-placement.gschema.xml.in
@@ -0,0 +1,26 @@
+<schemalist gettext-domain="gnome-shell-extensions">
+  <enum id="org.gnome.shell.extensions.native-window-placement.strategy">
+    <value nick="natural" value="0" />
+    <value nick="grid" value="1" />
+  </enum>
+  <schema id="org.gnome.shell.extensions.native-window-placement" path="/org/gnome/shell/extensions/native-window-placement/">
+    <key name="strategy" enum="org.gnome.shell.extensions.native-window-placement.strategy">
+      <default>'natural'</default>
+      <_summary>Window placement strategy</_summary>
+      <_description>The algorithm used to layout thumbnails in the overview. 'grid' to use the default grid based algorithm,
+      'natural' to use another one that reflects more the position and size of the actual window</_description>
+    </key>
+    <key name="use-more-screen" type="b">
+      <default>true</default>
+      <_summary>Use more screen for windows</_summary>
+      <_description>Try to use more screen for placing window thumbnails by adapting to screen aspect ratio, and consolidating
+      them further to reduce the bounding box. This setting applies only with the natural placement strategy.</_description>
+    </key>
+    <key name="window-captions-on-top" type="b">
+      <default>true</default>
+      <_summary>Place window captions on top</_summary>
+      <_description>If true, place window captions on top the respective thumbnail, overriding shell default of placing it at
+      the bottom. Changing this setting requires restarting the shell to have any effect.</_description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5a3b485..5efb104 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ extensions/auto-move-windows/org.gnome.shell.extensions.auto-move-windows.gschem
 extensions/dock/extension.js
 extensions/example/extension.js
 extensions/gajim/extension.js
+extensions/native-window-placement/org.gnome.shell.extensions.native-window-placement.gschema.xml.in
 extensions/user-theme/org.gnome.shell.extensions.user-theme.gschema.xml.in
 extensions/windowsNavigator/extension.js
 extensions/xrandr-indicator/extension.js



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