2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported CtrlAltTabManager */
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2019-02-15 11:15:04 -05:00
|
|
|
const { Clutter, GObject, Meta, Shell, St } = imports.gi;
|
2010-07-01 14:13:42 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
2017-07-18 13:47:27 -04:00
|
|
|
var POPUP_APPICON_SIZE = 96;
|
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-10-30 21:19:44 -04:00
|
|
|
var CtrlAltTabManager = class CtrlAltTabManager {
|
|
|
|
constructor() {
|
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) });
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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);
|
2019-01-27 19:42:00 -05: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);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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 21:19:44 -04:00
|
|
|
}
|
2010-07-01 14:13:42 -04:00
|
|
|
|
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
|
2018-11-27 07:58:25 -05:00
|
|
|
item.root.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-02-07 11:29:34 -05:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2019-02-01 08:41:55 -05:00
|
|
|
let [ax] = a.proxy.get_transformed_position();
|
|
|
|
let [bx] = b.proxy.get_transformed_position();
|
2011-02-07 11:29:34 -05:00
|
|
|
|
2012-12-04 13:48:08 -05:00
|
|
|
return ax - bx;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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
|
2019-03-01 00:56:26 -05:00
|
|
|
icon = textureCache.bind_cairo_surface_property(windows[i],
|
|
|
|
'icon',
|
|
|
|
POPUP_APPICON_SIZE);
|
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
|
|
|
}
|
2017-10-30 21:19:44 -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
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2019-02-15 11:15:04 -05:00
|
|
|
var CtrlAltTabPopup = GObject.registerClass(
|
2017-10-30 21:19:44 -04:00
|
|
|
class CtrlAltTabPopup extends SwitcherPopup.SwitcherPopup {
|
2019-02-15 11:15:04 -05:00
|
|
|
_init(items) {
|
|
|
|
super._init(items);
|
2014-09-03 11:15:31 -04:00
|
|
|
|
2012-11-30 10:16:48 -05:00
|
|
|
this._switcherList = new CtrlAltTabSwitcher(this._items);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
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;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_finish(time) {
|
2017-10-30 21:19:44 -04:00
|
|
|
super._finish(time);
|
2012-12-04 13:45:52 -05:00
|
|
|
Main.ctrlAltTabManager.focusGroup(this._items[this._selectedIndex], time);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-02-15 11:15:04 -05:00
|
|
|
});
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2019-02-15 11:15:04 -05:00
|
|
|
var CtrlAltTabSwitcher = GObject.registerClass(
|
2017-10-30 21:19:44 -04:00
|
|
|
class CtrlAltTabSwitcher extends SwitcherPopup.SwitcherList {
|
2019-02-15 11:15:04 -05:00
|
|
|
_init(items) {
|
|
|
|
super._init(true);
|
2010-07-01 14:13:42 -04:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
this._addIcon(items[i]);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2010-07-01 14:13:42 -04:00
|
|
|
|
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 });
|
|
|
|
}
|
2019-10-21 14:44:00 -04:00
|
|
|
box.add_child(icon);
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2019-10-21 14:44:00 -04:00
|
|
|
let text = new St.Label({
|
|
|
|
text: item.name,
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
});
|
|
|
|
box.add_child(text);
|
2010-07-01 14:13:42 -04:00
|
|
|
|
2011-03-08 13:33:57 -05:00
|
|
|
this.addItem(box, text);
|
2010-07-01 14:13:42 -04:00
|
|
|
}
|
2019-02-15 11:15:04 -05:00
|
|
|
});
|