2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-01 14:13:42 -04:00
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Meta = imports.gi.Meta;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
2012-11-30 10:16:48 -05:00
|
|
|
const SwitcherPopup = imports.ui.switcherPopup;
|
2011-02-07 11:29:34 -05:00
|
|
|
const Params = imports.misc.params;
|
2010-07-01 14:13:42 -04:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var POPUP_APPICON_SIZE = 96;
|
|
|
|
var POPUP_FADE_TIME = 0.1; // seconds
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var SortGroup = {
|
2011-02-07 11:29:34 -05:00
|
|
|
TOP: 0,
|
|
|
|
MIDDLE: 1,
|
|
|
|
BOTTOM: 2
|
|
|
|
};
|
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var CtrlAltTabManager = new Lang.Class({
|
2011-11-20 12:56:27 -05:00
|
|
|
Name: 'CtrlAltTabManager',
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2010-07-01 14:13:42 -04:00
|
|
|
this._items = [];
|
2012-12-04 13:46:47 -05:00
|
|
|
this.addGroup(global.window_group, _("Windows"),
|
2015-03-12 08:40:36 -04:00
|
|
|
'focus-windows-symbolic', { sortGroup: SortGroup.TOP,
|
2017-12-01 19:27:35 -05:00
|
|
|
focusCallback: this._focusWindows.bind(this) });
|
2010-07-01 14:13:42 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
addGroup(root, name, icon, params) {
|
2011-02-07 11:29:34 -05:00
|
|
|
let item = Params.parse(params, { sortGroup: SortGroup.MIDDLE,
|
|
|
|
proxy: root,
|
|
|
|
focusCallback: null });
|
|
|
|
|
|
|
|
item.root = root;
|
|
|
|
item.name = name;
|
|
|
|
item.iconName = icon;
|
|
|
|
|
|
|
|
this._items.push(item);
|
2017-10-30 20:38:18 -04:00
|
|
|
root.connect('destroy', () => { this.removeGroup(root); });
|
2012-12-04 14:02:15 -05:00
|
|
|
if (root instanceof St.Widget)
|
|
|
|
global.focus_manager.add_group(root);
|
2010-07-01 14:13:42 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
removeGroup(root) {
|
2012-12-04 14:02:15 -05:00
|
|
|
if (root instanceof St.Widget)
|
|
|
|
global.focus_manager.remove_group(root);
|
2010-07-01 14:13:42 -04:00
|
|
|
for (let i = 0; i < this._items.length; i++) {
|
|
|
|
if (this._items[i].root == root) {
|
|
|
|
this._items.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
focusGroup(item, timestamp) {
|
Rework window / actor focus handling
The duality of the Clutter's key focus and mutter's window focus has long been
a problem for us in lots of case, and caused us to create large and complicated
hacks to get around the issue, including GrabHelper's focus grab model.
Instead of doing this, tie basic focus management into the core of gnome-shell,
instead of requiring complex "application-level" management to get it done
right.
Do this by making sure that only one of an actor or window can be focused at
the same time, and apply the appropriate logic to drop one or the other,
reactively.
Modals are considered a special case, as we grab all keyboard events, but at
the X level, the client window still has focus. Make sure to not do any input
synchronization when we have a modal.
At the same time, remove the FOCUSED input mode, as it's no longer necessary.
https://bugzilla.gnome.org/show_bug.cgi?id=700735
2013-05-18 00:18:13 -04:00
|
|
|
if (item.focusCallback)
|
2012-12-04 13:45:52 -05:00
|
|
|
item.focusCallback(timestamp);
|
Rework window / actor focus handling
The duality of the Clutter's key focus and mutter's window focus has long been
a problem for us in lots of case, and caused us to create large and complicated
hacks to get around the issue, including GrabHelper's focus grab model.
Instead of doing this, tie basic focus management into the core of gnome-shell,
instead of requiring complex "application-level" management to get it done
right.
Do this by making sure that only one of an actor or window can be focused at
the same time, and apply the appropriate logic to drop one or the other,
reactively.
Modals are considered a special case, as we grab all keyboard events, but at
the X level, the client window still has focus. Make sure to not do any input
synchronization when we have a modal.
At the same time, remove the FOCUSED input mode, as it's no longer necessary.
https://bugzilla.gnome.org/show_bug.cgi?id=700735
2013-05-18 00:18:13 -04:00
|
|
|
else
|
2011-02-07 11:29:34 -05:00
|
|
|
item.root.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Sort the items into a consistent order; panel first, tray last,
|
|
|
|
// and everything else in between, sorted by X coordinate, so that
|
|
|
|
// they will have the same left-to-right ordering in the
|
|
|
|
// Ctrl-Alt-Tab dialog as they do onscreen.
|
2017-10-30 20:03:21 -04:00
|
|
|
_sortItems(a, b) {
|
2011-02-07 11:29:34 -05:00
|
|
|
if (a.sortGroup != b.sortGroup)
|
|
|
|
return a.sortGroup - b.sortGroup;
|
|
|
|
|
2012-12-04 13:48:08 -05:00
|
|
|
let ax, bx, y;
|
|
|
|
[ax, y] = a.proxy.get_transformed_position();
|
|
|
|
[bx, y] = b.proxy.get_transformed_position();
|
2011-02-07 11:29:34 -05:00
|
|
|
|
2012-12-04 13:48:08 -05:00
|
|
|
return ax - bx;
|
2010-07-01 14:13:42 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
popup(backward, binding, mask) {
|
2010-07-01 14:13:42 -04:00
|
|
|
// Start with the set of focus groups that are currently mapped
|
2017-10-30 20:38:18 -04:00
|
|
|
let items = this._items.filter(item => item.proxy.mapped);
|
2010-07-01 14:13:42 -04:00
|
|
|
|
|
|
|
// And add the windows metacity would show in its Ctrl-Alt-Tab list
|
2013-05-07 14:25:06 -04:00
|
|
|
if (Main.sessionMode.hasWindows && !Main.overview.visible) {
|
2018-01-03 02:55:38 -05:00
|
|
|
let display = global.display;
|
|
|
|
let workspaceManager = global.workspace_manager;
|
|
|
|
let activeWorkspace = workspaceManager.get_active_workspace();
|
|
|
|
let windows = display.get_tab_list(Meta.TabList.DOCKS,
|
|
|
|
activeWorkspace);
|
2011-02-07 11:29:34 -05:00
|
|
|
let windowTracker = Shell.WindowTracker.get_default();
|
|
|
|
let textureCache = St.TextureCache.get_default();
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2013-04-18 00:20:45 -04:00
|
|
|
let icon = null;
|
|
|
|
let iconName = null;
|
|
|
|
if (windows[i].get_window_type () == Meta.WindowType.DESKTOP) {
|
|
|
|
iconName = 'video-display-symbolic';
|
|
|
|
} else {
|
|
|
|
let app = windowTracker.get_window_app(windows[i]);
|
|
|
|
if (app)
|
|
|
|
icon = app.create_icon_texture(POPUP_APPICON_SIZE);
|
|
|
|
else
|
2015-01-12 15:21:39 -05:00
|
|
|
icon = textureCache.bind_cairo_surface_property(windows[i], 'icon');
|
2013-04-18 00:20:45 -04:00
|
|
|
}
|
|
|
|
|
2012-12-16 16:56:40 -05:00
|
|
|
items.push({ name: windows[i].title,
|
2013-03-08 08:18:06 -05:00
|
|
|
proxy: windows[i].get_compositor_private(),
|
2017-12-01 19:27:35 -05:00
|
|
|
focusCallback: function(timestamp) {
|
|
|
|
Main.activateWindow(this, timestamp);
|
|
|
|
}.bind(windows[i]),
|
2011-02-07 11:29:34 -05:00
|
|
|
iconActor: icon,
|
2013-04-18 00:20:45 -04:00
|
|
|
iconName: iconName,
|
2011-02-07 11:29:34 -05:00
|
|
|
sortGroup: SortGroup.MIDDLE });
|
|
|
|
}
|
2010-07-01 14:13:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!items.length)
|
|
|
|
return;
|
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
items.sort(this._sortItems.bind(this));
|
2011-09-17 17:09:47 -04:00
|
|
|
|
|
|
|
if (!this._popup) {
|
2012-11-30 10:16:48 -05:00
|
|
|
this._popup = new CtrlAltTabPopup(items);
|
|
|
|
this._popup.show(backward, binding, mask);
|
2011-09-17 17:09:47 -04:00
|
|
|
|
2018-06-28 11:34:01 -04:00
|
|
|
this._popup.connect('destroy',
|
|
|
|
() => {
|
|
|
|
this._popup = null;
|
|
|
|
});
|
2011-09-17 17:09:47 -04:00
|
|
|
}
|
2012-12-04 13:46:47 -05:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_focusWindows(timestamp) {
|
2018-01-03 02:55:38 -05:00
|
|
|
global.display.focus_default_window(timestamp);
|
2010-07-01 14:13:42 -04:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var CtrlAltTabPopup = new Lang.Class({
|
2011-11-20 12:56:27 -05:00
|
|
|
Name: 'CtrlAltTabPopup',
|
2012-11-30 10:16:48 -05:00
|
|
|
Extends: SwitcherPopup.SwitcherPopup,
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(items) {
|
2014-09-03 11:15:31 -04:00
|
|
|
this.parent(items);
|
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
this._switcherList = new CtrlAltTabSwitcher(this._items);
|
2010-07-01 14:13:42 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_keyPressHandler(keysym, action) {
|
2012-11-30 10:16:48 -05:00
|
|
|
if (action == Meta.KeyBindingAction.SWITCH_PANELS)
|
2014-08-12 11:55:22 -04:00
|
|
|
this._select(this._next());
|
2012-11-30 10:16:48 -05:00
|
|
|
else if (action == Meta.KeyBindingAction.SWITCH_PANELS_BACKWARD)
|
2014-08-12 11:55:22 -04:00
|
|
|
this._select(this._previous());
|
2012-11-30 10:16:48 -05:00
|
|
|
else if (keysym == Clutter.Left)
|
2010-07-01 14:13:42 -04:00
|
|
|
this._select(this._previous());
|
2012-11-30 10:16:48 -05:00
|
|
|
else if (keysym == Clutter.Right)
|
2010-07-01 14:13:42 -04:00
|
|
|
this._select(this._next());
|
2014-05-26 09:27:16 -04:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
2010-07-01 14:13:42 -04:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_finish(time) {
|
2012-12-04 13:45:52 -05:00
|
|
|
this.parent(time);
|
|
|
|
Main.ctrlAltTabManager.focusGroup(this._items[this._selectedIndex], time);
|
2010-07-01 14:13:42 -04:00
|
|
|
},
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-07-18 13:41:25 -04:00
|
|
|
var CtrlAltTabSwitcher = new Lang.Class({
|
2011-11-20 11:07:14 -05:00
|
|
|
Name: 'CtrlAltTabSwitcher',
|
2012-11-30 10:16:48 -05:00
|
|
|
Extends: SwitcherPopup.SwitcherList,
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_init(items) {
|
2011-11-20 11:07:14 -05:00
|
|
|
this.parent(true);
|
2010-07-01 14:13:42 -04:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
this._addIcon(items[i]);
|
|
|
|
},
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_addIcon(item) {
|
2010-07-01 14:13:42 -04:00
|
|
|
let box = new St.BoxLayout({ style_class: 'alt-tab-app',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
let icon = item.iconActor;
|
|
|
|
if (!icon) {
|
|
|
|
icon = new St.Icon({ icon_name: item.iconName,
|
|
|
|
icon_size: POPUP_APPICON_SIZE });
|
|
|
|
}
|
|
|
|
box.add(icon, { x_fill: false, y_fill: false } );
|
|
|
|
|
|
|
|
let text = new St.Label({ text: item.name });
|
|
|
|
box.add(text, { x_fill: false });
|
|
|
|
|
2011-03-08 13:33:57 -05:00
|
|
|
this.addItem(box, text);
|
2010-07-01 14:13:42 -04:00
|
|
|
}
|
2011-11-20 11:07:14 -05:00
|
|
|
});
|