[gnome-shell] windowManager: Implement tile previews



commit 6d93c8b3fd5e2f852e4f79e558d9806ae132085a
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Sep 2 00:26:12 2013 +0200

    windowManager: Implement tile previews
    
    Mutter now delegates tile previews to compositor plugins, so
    add a simple implementation based on the UI previously provided
    by mutter.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665758

 data/theme/gnome-shell.css |   21 ++++++++++++++
 js/ui/windowManager.js     |   65 ++++++++++++++++++++++++++++++++++++++++++++
 src/gnome-shell-plugin.c   |   24 ++++++++++++++++
 src/shell-wm-private.h     |    6 ++++
 src/shell-wm.c             |   34 +++++++++++++++++++++++
 5 files changed, 150 insertions(+), 0 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index bb9ff54..613ae0c 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -1877,6 +1877,27 @@ StScrollBar StButton#vhandle:active {
     border-radius: 8px;
 }
 
+/* Tile previews */
+.tile-preview {
+    background-color: rgba(74, 144, 217, 0.35);
+    border: 1px solid #4a90d9; /* Adwaita selected bg color */
+}
+
+.tile-preview-left.on-primary {
+    /* keep in sync with -panel-corner-radius */
+    border-radius: 6px 0 0 0;
+}
+
+.tile-preview-right.on-primary {
+    /* keep in sync with -panel-corner-radius */
+    border-radius: 0 6px 0 0;
+}
+
+.tile-preview-left.tile-preview-right.on-primary {
+    /* keep in sync with -panel-corner-radius */
+    border-radius: 6px 6px 0 0;
+}
+
 /* Modal Dialogs */
 
 /* Dialog Subject Text Style */
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index cf80290..283d6a5 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -358,6 +358,55 @@ const WorkspaceTracker = new Lang.Class({
     }
 });
 
+const TilePreview = new Lang.Class({
+    Name: 'TilePreview',
+
+    _init: function() {
+        this.actor = new St.Widget({ visible: false });
+        global.window_group.add_actor(this.actor);
+
+        this._showing = false;
+    },
+
+    show: function(window, tileRect, monitorIndex) {
+        let windowActor = window.get_compositor_private();
+        if (!windowActor)
+            return;
+
+        global.window_group.set_child_below_sibling(this.actor, windowActor);
+
+        this._updateStyle(monitorIndex, tileRect);
+
+        this.actor.set_size(tileRect.width, tileRect.height);
+        this.actor.set_position(tileRect.x, tileRect.y);
+
+        this._showing = true;
+        this.actor.show();
+    },
+
+    hide: function() {
+        if (!this._showing)
+            return;
+
+        this._showing = false;
+        this.actor.hide();
+    },
+
+    _updateStyle: function(monitorIndex, tileRect) {
+        let monitor = Main.layoutManager.monitors[monitorIndex];
+
+        let styles = ['tile-preview'];
+        if (monitorIndex == Main.layoutManager.primaryIndex)
+            styles.push('on-primary');
+        if (tileRect.x == monitor.x)
+            styles.push('tile-preview-left');
+        if (tileRect.x + tileRect.width == monitor.x + monitor.width)
+            styles.push('tile-preview-right');
+
+        this.actor.style_class = styles.join(' ');
+    }
+});
+
 const WindowManager = new Lang.Class({
     Name: 'WindowManager',
 
@@ -388,6 +437,8 @@ const WindowManager = new Lang.Class({
         }));
 
         this._shellwm.connect('switch-workspace', Lang.bind(this, this._switchWorkspace));
+        this._shellwm.connect('show-tile-preview', Lang.bind(this, this._showTilePreview));
+        this._shellwm.connect('hide-tile-preview', Lang.bind(this, this._hideTilePreview));
         this._shellwm.connect('minimize', Lang.bind(this, this._minimizeWindow));
         this._shellwm.connect('maximize', Lang.bind(this, this._maximizeWindow));
         this._shellwm.connect('unmaximize', Lang.bind(this, this._unmaximizeWindow));
@@ -397,6 +448,8 @@ const WindowManager = new Lang.Class({
         this._shellwm.connect('confirm-display-change', Lang.bind(this, this._confirmDisplayChange));
 
         this._workspaceSwitcherPopup = null;
+        this._tilePreview = null;
+
         this.setCustomKeybindingHandler('switch-to-workspace-left',
                                         Shell.KeyBindingMode.NORMAL |
                                         Shell.KeyBindingMode.OVERVIEW,
@@ -1046,6 +1099,18 @@ const WindowManager = new Lang.Class({
         shellwm.completed_switch_workspace();
     },
 
+    _showTilePreview: function(shellwm, window, tileRect, monitorIndex) {
+        if (!this._tilePreview)
+            this._tilePreview = new TilePreview();
+        this._tilePreview.show(window, tileRect, monitorIndex);
+    },
+
+    _hideTilePreview: function(shellwm) {
+        if (!this._tilePreview)
+            return;
+        this._tilePreview.hide();
+    },
+
     _startAppSwitcher : function(display, screen, window, binding) {
         /* prevent a corner case where both popups show up at once */
         if (this._workspaceSwitcherPopup != null)
diff --git a/src/gnome-shell-plugin.c b/src/gnome-shell-plugin.c
index a114761..27c4cf6 100644
--- a/src/gnome-shell-plugin.c
+++ b/src/gnome-shell-plugin.c
@@ -68,6 +68,12 @@ static void gnome_shell_plugin_kill_window_effects   (MetaPlugin      *plugin,
                                                       MetaWindowActor *actor);
 static void gnome_shell_plugin_kill_switch_workspace (MetaPlugin      *plugin);
 
+static void gnome_shell_plugin_show_tile_preview (MetaPlugin      *plugin,
+                                                  MetaWindow      *window,
+                                                  MetaRectangle   *tile_rect,
+                                                  int              tile_monitor);
+static void gnome_shell_plugin_hide_tile_preview (MetaPlugin *plugin);
+
 
 static gboolean              gnome_shell_plugin_xevent_filter (MetaPlugin *plugin,
                                                                XEvent     *event);
@@ -132,6 +138,9 @@ gnome_shell_plugin_class_init (GnomeShellPluginClass *klass)
   plugin_class->kill_window_effects   = gnome_shell_plugin_kill_window_effects;
   plugin_class->kill_switch_workspace = gnome_shell_plugin_kill_switch_workspace;
 
+  plugin_class->show_tile_preview = gnome_shell_plugin_show_tile_preview;
+  plugin_class->hide_tile_preview = gnome_shell_plugin_hide_tile_preview;
+
   plugin_class->xevent_filter     = gnome_shell_plugin_xevent_filter;
   plugin_class->keybinding_filter = gnome_shell_plugin_keybinding_filter;
 
@@ -319,6 +328,21 @@ gnome_shell_plugin_kill_switch_workspace (MetaPlugin         *plugin)
   _shell_wm_kill_switch_workspace (get_shell_wm());
 }
 
+static void
+gnome_shell_plugin_show_tile_preview (MetaPlugin      *plugin,
+                                      MetaWindow      *window,
+                                      MetaRectangle   *tile_rect,
+                                      int              tile_monitor)
+{
+  _shell_wm_show_tile_preview (get_shell_wm (), window, tile_rect, tile_monitor);
+}
+
+static void
+gnome_shell_plugin_hide_tile_preview (MetaPlugin *plugin)
+{
+  _shell_wm_hide_tile_preview (get_shell_wm ());
+}
+
 static gboolean
 gnome_shell_plugin_xevent_filter (MetaPlugin *plugin,
                                   XEvent     *xev)
diff --git a/src/shell-wm-private.h b/src/shell-wm-private.h
index bc9d4c3..9df4ada 100644
--- a/src/shell-wm-private.h
+++ b/src/shell-wm-private.h
@@ -35,6 +35,12 @@ void _shell_wm_kill_window_effects   (ShellWM             *wm,
                                       MetaWindowActor     *actor);
 void _shell_wm_kill_switch_workspace (ShellWM             *wm);
 
+void _shell_wm_show_tile_preview     (ShellWM             *wm,
+                                      MetaWindow          *window,
+                                      MetaRectangle       *tile_rect,
+                                      int                  tile_monitor);
+void _shell_wm_hide_tile_preview     (ShellWM             *wm);
+
 gboolean _shell_wm_filter_keybinding (ShellWM             *wm,
                                       MetaKeyBinding      *binding);
 
diff --git a/src/shell-wm.c b/src/shell-wm.c
index 20f101e..f2c484d 100644
--- a/src/shell-wm.c
+++ b/src/shell-wm.c
@@ -26,6 +26,8 @@ enum
   SWITCH_WORKSPACE,
   KILL_SWITCH_WORKSPACE,
   KILL_WINDOW_EFFECTS,
+  SHOW_TILE_PREVIEW,
+  HIDE_TILE_PREVIEW,
   FILTER_KEYBINDING,
   CONFIRM_DISPLAY_CHANGE,
 
@@ -117,6 +119,22 @@ shell_wm_class_init (ShellWMClass *klass)
           NULL, NULL, NULL,
                  G_TYPE_NONE, 1,
                  META_TYPE_WINDOW_ACTOR);
+  shell_wm_signals[SHOW_TILE_PREVIEW] =
+    g_signal_new ("show-tile-preview",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL, NULL,
+                  G_TYPE_NONE, 3,
+                  META_TYPE_WINDOW,
+                  META_TYPE_RECTANGLE,
+                  G_TYPE_INT);
+  shell_wm_signals[HIDE_TILE_PREVIEW] =
+    g_signal_new ("hide-tile-preview",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE, 0);
   shell_wm_signals[FILTER_KEYBINDING] =
     g_signal_new ("filter-keybinding",
                   G_TYPE_FROM_CLASS (klass),
@@ -254,6 +272,22 @@ _shell_wm_kill_window_effects (ShellWM         *wm,
   g_signal_emit (wm, shell_wm_signals[KILL_WINDOW_EFFECTS], 0, actor);
 }
 
+void
+_shell_wm_show_tile_preview (ShellWM       *wm,
+                             MetaWindow    *window,
+                             MetaRectangle *tile_rect,
+                             int            tile_monitor)
+{
+  g_signal_emit (wm, shell_wm_signals[SHOW_TILE_PREVIEW], 0,
+                 window, tile_rect, tile_monitor);
+}
+
+void
+_shell_wm_hide_tile_preview (ShellWM *wm)
+{
+  g_signal_emit (wm, shell_wm_signals[HIDE_TILE_PREVIEW], 0);
+}
+
 
 void
 _shell_wm_minimize (ShellWM         *wm,


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