Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show window previews on mouse hover #574

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,79 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="preview_hover_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkListBox" id="preview_hover_listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">none</property>
<child>
<object class="GtkListBoxRow" id="preview_hover_listboxrow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid" id="preview_hover_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="column_spacing">32</property>
<child>
<object class="GtkLabel" id="preview_hover_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Show window previews on mouse hover</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="preview_hover_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkSwitch" id="preview_hover_switch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="height">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
Expand Down
145 changes: 122 additions & 23 deletions appIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ let recentlyClickedAppWindows = null;
let recentlyClickedAppIndex = 0;
let recentlyClickedAppMonitor = -1;

// Icon list might change over time, so we keep a global variable
let appIconsHoverList = null;

/**
* Extend AppIcon
*
Expand Down Expand Up @@ -315,17 +318,25 @@ var MyAppIcon = new Lang.Class({
else {
// Setting the max-height is s useful if part of the menu is
// scrollable so the minimum height is smaller than the natural height.
let monitor_index = Main.layoutManager.findIndexForActor(this.actor);
let workArea = Main.layoutManager.getWorkAreaForMonitor(monitor_index);
let workArea = Main.layoutManager.getWorkAreaForMonitor(this.monitorIndex);
let position = Utils.getPosition(this._dtdSettings);
this._isHorizontal = ( position == St.Side.TOP ||
position == St.Side.BOTTOM);
// If horizontal also remove the height of the dash
let additional_margin = this._isHorizontal && !this._dtdSettings.get_boolean('dock-fixed') ? Main.overview._dash.actor.height : 0;
let verticalMargins = this._menu.actor.margin_top + this._menu.actor.margin_bottom;
// Also set a max width to the menu, so long labels (long windows title) get truncated
let monitor = Main.layoutManager.monitors[this.monitorIndex];
let max_width = Math.round(monitor.width / 3);
this._menu.actor.style = ('max-height: ' + Math.round(workArea.height - additional_margin - verticalMargins) + 'px;' +
'max-width: 400px');
'max-width: ' + max_width + 'px');
}

// Close the window previews
if (this._previewMenu) {
this._previewMenu.cancelOpen();
if (this._previewMenu.isOpen)
this._previewMenu.close(~0);
}
}));
let id = Main.overview.connect('hiding', Lang.bind(this, function() {
Expand Down Expand Up @@ -397,6 +408,8 @@ var MyAppIcon = new Lang.Class({
// This variable keeps track of this
let shouldHideOverview = true;

let shouldClosePreview = true;

// We customize the action only when the application is already running
if (appIsRunning) {
switch (buttonAction) {
Expand Down Expand Up @@ -470,8 +483,11 @@ var MyAppIcon = new Lang.Class({
if (windows.length == 1 && !modifiers && button == 1) {
let w = windows[0];
Main.activateWindow(w);
} else
}
else {
this._windowPreviews();
shouldClosePreview = false;
}
}
else {
this.app.activate();
Expand Down Expand Up @@ -515,6 +531,9 @@ var MyAppIcon = new Lang.Class({
this.launchNewWindow();
}

if (this._previewMenu && this._previewMenu.isOpen && shouldClosePreview)
this._previewMenu.hoverClose(~0);

// Hide overview except when action mode requires it
if(shouldHideOverview) {
Main.overview.hide();
Expand All @@ -526,35 +545,115 @@ var MyAppIcon = new Lang.Class({
(!this._previewMenu || !this._previewMenu.isOpen);
},

_windowPreviews: function() {
if (!this._previewMenu) {
this._previewMenuManager = new PopupMenu.PopupMenuManager(this);
_createPreviewMenus: function() {
this._previewMenuManager = new PopupMenu.PopupMenuManager(this);

this._previewMenu = new WindowPreview.WindowPreviewMenu(this, this._dtdSettings);
this._previewMenu = new WindowPreview.WindowPreviewMenu(this, this._dtdSettings);

this._previewMenuManager.addMenu(this._previewMenu);
this._previewMenuManager.addMenu(this._previewMenu);
this._previewMenu.connect('open-state-changed', Lang.bind(this, function(menu, isPoppedUp) {
if (!isPoppedUp)
this._onMenuPoppedDown();
}));

this._previewMenu.connect('open-state-changed', Lang.bind(this, function(menu, isPoppedUp) {
if (!isPoppedUp)
this._onMenuPoppedDown();
}));
let id = Main.overview.connect('hiding', Lang.bind(this, function() {
this._previewMenu.close();
}));
this._previewMenu.actor.connect('destroy', function() {
Main.overview.disconnect(id);
});
let id = Main.overview.connect('hiding', Lang.bind(this, function() {
this._previewMenu.close();
}));
this._previewMenu.actor.connect('destroy', function() {
Main.overview.disconnect(id);
});
},

}
_windowPreviews: function() {
if (!this._previewMenu)
this._createPreviewMenus();

if (this._previewMenu.isOpen)
if (this._previewMenu.isOpen) {
this._previewMenu.close();
else
}
else {
this._previewMenu.fromHover = false;
this._previewMenu.popup();
this._previewMenu.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
}

return false;
},

enableHover: function(appIcons) {
appIconsHoverList = appIcons;
if (this._hoverIsEnabled)
return;
this._hoverIsEnabled = true;

if (!this._previewMenu)
this._createPreviewMenus();

this._signalsHandler.addWithLabel('preview-hover', [
this._previewMenu,
'menu-closed',
function(menu) {
// enter-event doesn't fire on an app icon when the popup menu from a previously
// hovered app icon is still open, so when a preview menu closes we need to
// see if a new app icon is hovered and open its preview menu now.
// also, for some reason actor doesn't report being hovered by get_hover()
// if the hover started when a popup was opened. So, look for the actor by mouse position.
let [x, y,] = global.get_pointer();
let hoveredActor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
let appIconToOpen;
appIconsHoverList.forEach(function (appIcon) {
if(appIcon.actor == hoveredActor) {
appIconToOpen = appIcon;
} else if(appIcon._previewMenu && appIcon._previewMenu.isOpen) {
appIcon._previewMenu.close();
}
});

if (appIconToOpen) {
appIconToOpen.actor.sync_hover();
if (appIconToOpen._previewMenu && appIconToOpen._previewMenu != menu)
appIconToOpen._previewMenu._onEnter();
}
return GLib.SOURCE_REMOVE;
}
]);

let windowPreviewMenuData = this._previewMenuManager._menus[this._previewMenuManager._findMenu(this._previewMenu)];
this._previewMenu.disconnect(windowPreviewMenuData.openStateChangeId);
windowPreviewMenuData.openStateChangeId = this._previewMenu.connect(
'open-state-changed',
Lang.bind(this._previewMenuManager, function(menu, open) {
if (menu.fromHover) {
if (open) {
if (this.activeMenu)
this.activeMenu.close(BoxPointer.PopupAnimation.FADE);

// don't grab here, we are grabbing in onLeave in windowPreview.js
// this._grabHelper.grab({
// actor: menu.actor,
// focus: menu.sourceActor,
// onUngrab: Lang.bind(this, this._closeMenu, menu)
// });
} else {
this._grabHelper.ungrab({ actor: menu.actor });
}
}
else
this._onMenuOpenState(menu, open);
})
);

this._previewMenu.enableHover();
},

disableHover: function() {
this._hoverIsEnabled = false;

this._signalsHandler.removeWithLabel('preview-hover');
if (this._previewMenu)
this._previewMenu.disableHover();
},

// Try to do the right thing when attempting to launch a new window of an app. In
// particular, if the application doens't allow to launch a new window, activate
// the existing window instead.
Expand Down Expand Up @@ -954,7 +1053,7 @@ const MyAppIconMenu = new Lang.Class({
separatorShown = true;
}

let item = new WindowPreview.WindowPreviewMenuItem(window);
let item = new WindowPreview.WindowPreviewMenuItem(window, this._source);
this._allWindowsMenuItem.menu.addMenuItem(item);
item.connect('activate', Lang.bind(this, function() {
this.emit('activate-window', window);
Expand Down
28 changes: 28 additions & 0 deletions dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ var MyDash = new Lang.Class({
Main.overview,
'item-drag-cancelled',
Lang.bind(this, this._onDragCancelled)
], [
this._dtdSettings,
'changed::show-previews-hover',
Lang.bind(this, this._togglePreviewHover)
]);
},

Expand Down Expand Up @@ -503,6 +507,27 @@ var MyDash = new Lang.Class({
return item;
},

_togglePreviewHover: function() {
if (this._dtdSettings.get_boolean('show-previews-hover'))
this._enableHover();
else
this._disableHover();
},

_enableHover: function() {
let appIcons = this.getAppIcons();
appIcons.forEach(function (appIcon) {
appIcon.enableHover(appIcons);
});
},

_disableHover: function() {
let appIcons = this.getAppIcons();
appIcons.forEach(function (appIcon) {
appIcon.disableHover();
});
},

/**
* Return an array with the "proper" appIcons currently in the dash
*/
Expand Down Expand Up @@ -857,6 +882,9 @@ var MyDash = new Lang.Class({

// This will update the size, and the corresponding number for each icon
this._updateNumberOverlay();

// Connect windows previews to hover events
this._togglePreviewHover();
},

_updateNumberOverlay: function() {
Expand Down
9 changes: 8 additions & 1 deletion docking.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ const DockedDash = new Lang.Class({
// sync hover after a popupmenu is closed
this.dash.connect('menu-closed', Lang.bind(this, function() {
this._box.sync_hover();
this._hoverChanged();
}));

// Load optional features that need to be activated for one dock only
Expand Down Expand Up @@ -684,7 +685,13 @@ const DockedDash = new Lang.Class({
},

_hoverChanged: function() {
if (!this._ignoreHover) {
let dontClose = false;
this.dash.getAppIcons().forEach(function(appIcon) {
if (appIcon._previewMenu && appIcon._previewMenu.isOpen)
dontClose = true;
});

if (!this._ignoreHover && !dontClose) {
// Skip if dock is not in autohide mode for instance because it is shown
// by intellihide.
if (this._autohideIsEnabled) {
Expand Down
5 changes: 5 additions & 0 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ const Settings = new Lang.Class({

}));

this._settings.bind('show-previews-hover',
this._builder.get_object('preview_hover_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);

// Appearance Panel

this._settings.bind('apply-custom-theme', this._builder.get_object('customize_theme'), 'sensitive', Gio.SettingsBindFlags.INVERT_BOOLEAN | Gio.SettingsBindFlags.GET);
Expand Down
5 changes: 5 additions & 0 deletions schemas/org.gnome.shell.extensions.dash-to-dock.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,10 @@
<summary>Enable unity7 like glossy backlit items</summary>
<description>Emulate the unity7 backlit glossy items behaviour</description>
</key>
<key name="show-previews-hover" type="b">
<default>false</default>
<summary>Show window previews on mouse hover</summary>
<description></description>
</key>
</schema>
</schemalist>
Loading