2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-07-01 18:13:42 +00: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 15:16:48 +00:00
|
|
|
const SwitcherPopup = imports.ui.switcherPopup;
|
2011-02-07 16:29:34 +00:00
|
|
|
const Params = imports.misc.params;
|
2010-07-01 18:13:42 +00:00
|
|
|
const Tweener = imports.ui.tweener;
|
|
|
|
|
|
|
|
const POPUP_APPICON_SIZE = 96;
|
|
|
|
const POPUP_FADE_TIME = 0.1; // seconds
|
|
|
|
|
2011-02-07 16:29:34 +00:00
|
|
|
const SortGroup = {
|
|
|
|
TOP: 0,
|
|
|
|
MIDDLE: 1,
|
|
|
|
BOTTOM: 2
|
|
|
|
};
|
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const CtrlAltTabManager = new Lang.Class({
|
|
|
|
Name: 'CtrlAltTabManager',
|
2010-07-01 18:13:42 +00:00
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
this._items = [];
|
2012-12-04 18:46:47 +00:00
|
|
|
this.addGroup(global.window_group, _("Windows"),
|
|
|
|
'emblem-documents-symbolic', { sortGroup: SortGroup.TOP,
|
|
|
|
focusCallback: Lang.bind(this, this._focusWindows) });
|
2010-07-01 18:13:42 +00:00
|
|
|
},
|
|
|
|
|
2011-02-07 16:29:34 +00:00
|
|
|
addGroup: function(root, name, icon, params) {
|
|
|
|
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);
|
2010-07-01 18:13:42 +00:00
|
|
|
root.connect('destroy', Lang.bind(this, function() { this.removeGroup(root); }));
|
2012-12-04 19:02:15 +00:00
|
|
|
if (root instanceof St.Widget)
|
|
|
|
global.focus_manager.add_group(root);
|
2010-07-01 18:13:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeGroup: function(root) {
|
2012-12-04 19:02:15 +00:00
|
|
|
if (root instanceof St.Widget)
|
|
|
|
global.focus_manager.remove_group(root);
|
2010-07-01 18:13:42 +00:00
|
|
|
for (let i = 0; i < this._items.length; i++) {
|
|
|
|
if (this._items[i].root == root) {
|
|
|
|
this._items.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-12-04 18:45:52 +00:00
|
|
|
focusGroup: function(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 04:18:13 +00:00
|
|
|
if (item.focusCallback)
|
2012-12-04 18:45:52 +00: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 04:18:13 +00:00
|
|
|
else
|
2011-02-07 16:29:34 +00: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.
|
|
|
|
_sortItems: function(a, b) {
|
|
|
|
if (a.sortGroup != b.sortGroup)
|
|
|
|
return a.sortGroup - b.sortGroup;
|
|
|
|
|
2012-12-04 18:48:08 +00:00
|
|
|
let ax, bx, y;
|
|
|
|
[ax, y] = a.proxy.get_transformed_position();
|
|
|
|
[bx, y] = b.proxy.get_transformed_position();
|
2011-02-07 16:29:34 +00:00
|
|
|
|
2012-12-04 18:48:08 +00:00
|
|
|
return ax - bx;
|
2010-07-01 18:13:42 +00:00
|
|
|
},
|
|
|
|
|
2012-11-30 15:16:48 +00:00
|
|
|
popup: function(backward, binding, mask) {
|
2010-07-01 18:13:42 +00:00
|
|
|
// Start with the set of focus groups that are currently mapped
|
2011-02-07 16:29:34 +00:00
|
|
|
let items = this._items.filter(function (item) { return item.proxy.mapped; });
|
2010-07-01 18:13:42 +00:00
|
|
|
|
|
|
|
// And add the windows metacity would show in its Ctrl-Alt-Tab list
|
2013-05-07 18:25:06 +00:00
|
|
|
if (Main.sessionMode.hasWindows && !Main.overview.visible) {
|
2011-02-07 16:29:34 +00:00
|
|
|
let screen = global.screen;
|
|
|
|
let display = screen.get_display();
|
2014-06-03 12:52:18 +00:00
|
|
|
let windows = display.get_tab_list(Meta.TabList.DOCKS, screen.get_active_workspace ());
|
2011-02-07 16:29:34 +00:00
|
|
|
let windowTracker = Shell.WindowTracker.get_default();
|
|
|
|
let textureCache = St.TextureCache.get_default();
|
|
|
|
for (let i = 0; i < windows.length; i++) {
|
2013-04-18 04:20:45 +00: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
|
|
|
|
icon = textureCache.bind_pixbuf_property(windows[i], 'icon');
|
|
|
|
}
|
|
|
|
|
2012-12-16 21:56:40 +00:00
|
|
|
items.push({ name: windows[i].title,
|
2013-03-08 13:18:06 +00:00
|
|
|
proxy: windows[i].get_compositor_private(),
|
|
|
|
focusCallback: Lang.bind(windows[i],
|
|
|
|
function(timestamp) {
|
|
|
|
Main.activateWindow(this, timestamp);
|
|
|
|
}),
|
2011-02-07 16:29:34 +00:00
|
|
|
iconActor: icon,
|
2013-04-18 04:20:45 +00:00
|
|
|
iconName: iconName,
|
2011-02-07 16:29:34 +00:00
|
|
|
sortGroup: SortGroup.MIDDLE });
|
|
|
|
}
|
2010-07-01 18:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!items.length)
|
|
|
|
return;
|
|
|
|
|
2011-02-07 16:29:34 +00:00
|
|
|
items.sort(Lang.bind(this, this._sortItems));
|
2011-09-17 21:09:47 +00:00
|
|
|
|
|
|
|
if (!this._popup) {
|
2012-11-30 15:16:48 +00:00
|
|
|
this._popup = new CtrlAltTabPopup(items);
|
|
|
|
this._popup.show(backward, binding, mask);
|
2011-09-17 21:09:47 +00:00
|
|
|
|
|
|
|
this._popup.actor.connect('destroy',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._popup = null;
|
|
|
|
}));
|
|
|
|
}
|
2012-12-04 18:46:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_focusWindows: function(timestamp) {
|
|
|
|
global.screen.focus_default_window(timestamp);
|
2010-07-01 18:13:42 +00:00
|
|
|
}
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2010-07-01 18:13:42 +00:00
|
|
|
|
2011-11-20 17:56:27 +00:00
|
|
|
const CtrlAltTabPopup = new Lang.Class({
|
|
|
|
Name: 'CtrlAltTabPopup',
|
2012-11-30 15:16:48 +00:00
|
|
|
Extends: SwitcherPopup.SwitcherPopup,
|
2010-07-01 18:13:42 +00:00
|
|
|
|
2014-09-03 15:15:31 +00:00
|
|
|
_init: function(items) {
|
|
|
|
this.parent(items);
|
|
|
|
|
2012-11-30 15:16:48 +00:00
|
|
|
this._switcherList = new CtrlAltTabSwitcher(this._items);
|
2010-07-01 18:13:42 +00:00
|
|
|
},
|
|
|
|
|
2014-08-12 15:55:22 +00:00
|
|
|
_keyPressHandler: function(keysym, action) {
|
2012-11-30 15:16:48 +00:00
|
|
|
if (action == Meta.KeyBindingAction.SWITCH_PANELS)
|
2014-08-12 15:55:22 +00:00
|
|
|
this._select(this._next());
|
2012-11-30 15:16:48 +00:00
|
|
|
else if (action == Meta.KeyBindingAction.SWITCH_PANELS_BACKWARD)
|
2014-08-12 15:55:22 +00:00
|
|
|
this._select(this._previous());
|
2012-11-30 15:16:48 +00:00
|
|
|
else if (keysym == Clutter.Left)
|
2010-07-01 18:13:42 +00:00
|
|
|
this._select(this._previous());
|
2012-11-30 15:16:48 +00:00
|
|
|
else if (keysym == Clutter.Right)
|
2010-07-01 18:13:42 +00:00
|
|
|
this._select(this._next());
|
2014-05-26 13:27:16 +00:00
|
|
|
else
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
return Clutter.EVENT_STOP;
|
2010-07-01 18:13:42 +00:00
|
|
|
},
|
|
|
|
|
2012-12-04 18:45:52 +00:00
|
|
|
_finish : function(time) {
|
|
|
|
this.parent(time);
|
|
|
|
Main.ctrlAltTabManager.focusGroup(this._items[this._selectedIndex], time);
|
2010-07-01 18:13:42 +00:00
|
|
|
},
|
2011-11-20 17:56:27 +00:00
|
|
|
});
|
2010-07-01 18:13:42 +00:00
|
|
|
|
2011-11-20 16:07:14 +00:00
|
|
|
const CtrlAltTabSwitcher = new Lang.Class({
|
|
|
|
Name: 'CtrlAltTabSwitcher',
|
2012-11-30 15:16:48 +00:00
|
|
|
Extends: SwitcherPopup.SwitcherList,
|
2010-07-01 18:13:42 +00:00
|
|
|
|
|
|
|
_init : function(items) {
|
2011-11-20 16:07:14 +00:00
|
|
|
this.parent(true);
|
2010-07-01 18:13:42 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++)
|
|
|
|
this._addIcon(items[i]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_addIcon : function(item) {
|
|
|
|
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 18:33:57 +00:00
|
|
|
this.addItem(box, text);
|
2010-07-01 18:13:42 +00:00
|
|
|
}
|
2011-11-20 16:07:14 +00:00
|
|
|
});
|