2009-04-13 10:55:41 -04:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Big = imports.gi.Big;
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2009-09-28 23:31:54 -04:00
|
|
|
const Gdk = imports.gi.Gdk;
|
2009-04-13 10:55:41 -04:00
|
|
|
const Lang = imports.lang;
|
2009-05-13 15:32:51 -04:00
|
|
|
const Meta = imports.gi.Meta;
|
2009-04-13 10:55:41 -04:00
|
|
|
const Pango = imports.gi.Pango;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
const AppIcon = imports.ui.appIcon;
|
2009-09-22 15:24:14 -04:00
|
|
|
const Lightbox = imports.ui.lightbox;
|
2009-04-13 10:55:41 -04:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
const POPUP_BG_COLOR = new Clutter.Color();
|
2009-09-26 12:08:16 -04:00
|
|
|
POPUP_BG_COLOR.from_pixel(0x00000080);
|
|
|
|
const POPUP_APPICON_BORDER_COLOR = new Clutter.Color();
|
|
|
|
POPUP_APPICON_BORDER_COLOR.from_pixel(0xffffffff);
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-09-29 17:04:46 -04:00
|
|
|
const POPUP_APPS_BOX_SPACING = 8;
|
2009-04-13 10:55:41 -04:00
|
|
|
const POPUP_ICON_SIZE = 48;
|
|
|
|
|
2009-09-21 13:44:42 -04:00
|
|
|
const POPUP_POINTER_SELECTION_THRESHOLD = 3;
|
|
|
|
|
2009-04-13 10:55:41 -04:00
|
|
|
function AltTabPopup() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
AltTabPopup.prototype = {
|
|
|
|
_init : function() {
|
2009-08-05 19:54:22 -04:00
|
|
|
this.actor = new Big.Box({ background_color : POPUP_BG_COLOR,
|
2009-09-29 17:04:46 -04:00
|
|
|
corner_radius: POPUP_APPS_BOX_SPACING,
|
|
|
|
padding: POPUP_APPS_BOX_SPACING,
|
|
|
|
spacing: POPUP_APPS_BOX_SPACING,
|
2009-09-15 11:11:32 -04:00
|
|
|
orientation: Big.BoxOrientation.VERTICAL,
|
|
|
|
reactive: true });
|
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-09-29 17:04:46 -04:00
|
|
|
this._appsBox = new Big.Box({ spacing: POPUP_APPS_BOX_SPACING,
|
|
|
|
orientation: Big.BoxOrientation.HORIZONTAL });
|
2009-04-13 10:55:41 -04:00
|
|
|
let gcenterbox = new Big.Box({ orientation: Big.BoxOrientation.HORIZONTAL,
|
|
|
|
x_align: Big.BoxAlignment.CENTER });
|
2009-09-29 17:04:46 -04:00
|
|
|
gcenterbox.append(this._appsBox, Big.BoxPackFlags.NONE);
|
2009-08-05 19:54:22 -04:00
|
|
|
this.actor.append(gcenterbox, Big.BoxPackFlags.NONE);
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
this._icons = [];
|
2009-09-23 12:18:18 -04:00
|
|
|
this._currentWindows = [];
|
2009-09-15 11:11:32 -04:00
|
|
|
this._haveModal = false;
|
2009-08-13 12:52:50 -04:00
|
|
|
this._selected = 0;
|
|
|
|
this._highlightedWindow = null;
|
|
|
|
this._toplevels = global.window_group.get_children();
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-08-05 19:54:22 -04:00
|
|
|
global.stage.add_actor(this.actor);
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
_addIcon : function(appIcon) {
|
|
|
|
appIcon.connect('activate', Lang.bind(this, this._appClicked));
|
|
|
|
appIcon.connect('activate-window', Lang.bind(this, this._windowClicked));
|
|
|
|
appIcon.connect('highlight-window', Lang.bind(this, this._windowHovered));
|
2009-09-21 13:04:30 -04:00
|
|
|
appIcon.connect('menu-popped-up', Lang.bind(this, this._menuPoppedUp));
|
|
|
|
appIcon.connect('menu-popped-down', Lang.bind(this, this._menuPoppedDown));
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-09-21 13:44:42 -04:00
|
|
|
appIcon.actor.connect('enter-event', Lang.bind(this, this._iconEntered));
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
// FIXME?
|
|
|
|
appIcon.actor.border = 2;
|
2009-09-26 12:08:16 -04:00
|
|
|
appIcon.highlight_border_color = POPUP_APPICON_BORDER_COLOR;
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
this._icons.push(appIcon);
|
2009-09-23 12:18:18 -04:00
|
|
|
this._currentWindows.push(appIcon.windows[0]);
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-09-29 17:04:46 -04:00
|
|
|
this._appsBox.append(appIcon.actor, Big.BoxPackFlags.NONE);
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
show : function(initialSelection) {
|
2009-09-15 11:11:32 -04:00
|
|
|
let appMonitor = Shell.AppMonitor.get_default();
|
|
|
|
let apps = appMonitor.get_running_apps ("");
|
|
|
|
|
|
|
|
if (!apps.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!Main.pushModal(this.actor))
|
|
|
|
return false;
|
|
|
|
this._haveModal = true;
|
|
|
|
|
|
|
|
this._keyPressEventId = global.stage.connect('key-press-event', Lang.bind(this, this._keyPressEvent));
|
|
|
|
this._keyReleaseEventId = global.stage.connect('key-release-event', Lang.bind(this, this._keyReleaseEvent));
|
|
|
|
|
2009-09-21 13:44:42 -04:00
|
|
|
this._motionEventId = this.actor.connect('motion-event', Lang.bind(this, this._mouseMoved));
|
|
|
|
this._mouseActive = false;
|
|
|
|
this._mouseMovement = 0;
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
// Contruct the AppIcons, sort by time, add to the popup
|
|
|
|
let icons = [];
|
|
|
|
for (let i = 0; i < apps.length; i++)
|
2009-09-29 08:13:28 -04:00
|
|
|
icons.push(new AppIcon.AppIcon(apps[i], AppIcon.MenuType.BELOW, false));
|
2009-09-26 10:56:41 -04:00
|
|
|
icons.sort(Lang.bind(this, this._sortAppIcon));
|
2009-08-13 12:52:50 -04:00
|
|
|
for (let i = 0; i < icons.length; i++)
|
|
|
|
this._addIcon(icons[i]);
|
2009-09-15 11:11:32 -04:00
|
|
|
|
2009-09-22 15:24:14 -04:00
|
|
|
// Need to specify explicit width and height because the
|
|
|
|
// window_group may not actually cover the whole screen
|
|
|
|
this._lightbox = new Lightbox.Lightbox(global.window_group,
|
|
|
|
global.screen_width,
|
|
|
|
global.screen_height);
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-08-05 19:54:22 -04:00
|
|
|
this.actor.show_all();
|
2009-08-25 15:23:53 -04:00
|
|
|
|
|
|
|
let primary = global.get_primary_monitor();
|
|
|
|
this.actor.x = primary.x + Math.floor((primary.width - this.actor.width) / 2);
|
|
|
|
this.actor.y = primary.y + Math.floor((primary.height - this.actor.height) / 2);
|
2009-04-13 10:55:41 -04:00
|
|
|
|
2009-09-15 11:11:32 -04:00
|
|
|
this._updateSelection(initialSelection);
|
2009-09-28 23:31:54 -04:00
|
|
|
|
|
|
|
// There's a race condition; if the user released Alt before
|
|
|
|
// we got the grab, then we won't be notified. (See
|
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=596695 for
|
|
|
|
// details.) So we check now. (Have to do this after calling
|
|
|
|
// _updateSelection.)
|
|
|
|
let [screen, x, y, mods] = Gdk.Display.get_default().get_pointer();
|
|
|
|
if (!(mods & Gdk.ModifierType.MOD1_MASK)) {
|
|
|
|
this._finish();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-15 11:11:32 -04:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2009-09-26 10:56:41 -04:00
|
|
|
_hasVisibleWindows : function(appIcon) {
|
|
|
|
for (let i = 0; i < appIcon.windows.length; i++) {
|
|
|
|
if (appIcon.windows[i].showing_on_its_workspace())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_sortAppIcon : function(appIcon1, appIcon2) {
|
|
|
|
let vis1 = this._hasVisibleWindows(appIcon1);
|
|
|
|
let vis2 = this._hasVisibleWindows(appIcon2);
|
|
|
|
|
|
|
|
if (vis1 && !vis2) {
|
|
|
|
return -1;
|
|
|
|
} else if (vis2 && !vis1) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
// The app's most-recently-used window is first
|
|
|
|
// in its list
|
|
|
|
return (appIcon2.windows[0].get_user_time() -
|
|
|
|
appIcon1.windows[0].get_user_time());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-09-15 11:11:32 -04:00
|
|
|
_keyPressEvent : function(actor, event) {
|
|
|
|
let keysym = event.get_key_symbol();
|
|
|
|
let backwards = (event.get_state() & Clutter.ModifierType.SHIFT_MASK);
|
|
|
|
|
|
|
|
if (keysym == Clutter.Tab)
|
|
|
|
this._updateSelection(backwards ? -1 : 1);
|
2009-09-23 12:27:23 -04:00
|
|
|
else if (keysym == Clutter.Left)
|
|
|
|
this._updateSelection(-1);
|
|
|
|
else if (keysym == Clutter.Right)
|
|
|
|
this._updateSelection(1);
|
2009-09-21 13:04:30 -04:00
|
|
|
else if (keysym == Clutter.grave)
|
|
|
|
this._updateWindowSelection(backwards ? -1 : 1);
|
2009-09-23 12:27:23 -04:00
|
|
|
else if (keysym == Clutter.Up)
|
|
|
|
this._updateWindowSelection(-1);
|
|
|
|
else if (keysym == Clutter.Down)
|
|
|
|
this._updateWindowSelection(1);
|
2009-09-15 11:11:32 -04:00
|
|
|
else if (keysym == Clutter.Escape)
|
|
|
|
this.destroy();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_keyReleaseEvent : function(actor, event) {
|
|
|
|
let keysym = event.get_key_symbol();
|
|
|
|
|
2009-09-28 23:31:54 -04:00
|
|
|
if (keysym == Clutter.Alt_L || keysym == Clutter.Alt_R)
|
|
|
|
this._finish();
|
2009-09-15 11:11:32 -04:00
|
|
|
|
|
|
|
return true;
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
_appClicked : function(icon) {
|
|
|
|
Main.activateWindow(icon.windows[0]);
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
|
|
|
_windowClicked : function(icon, window) {
|
|
|
|
if (window)
|
|
|
|
Main.activateWindow(window);
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
|
|
|
_windowHovered : function(icon, window) {
|
|
|
|
if (window)
|
|
|
|
this._highlightWindow(window);
|
|
|
|
},
|
|
|
|
|
2009-09-21 13:44:42 -04:00
|
|
|
_mouseMoved : function(actor, event) {
|
|
|
|
if (++this._mouseMovement < POPUP_POINTER_SELECTION_THRESHOLD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.actor.disconnect(this._motionEventId);
|
|
|
|
this._mouseActive = true;
|
|
|
|
|
|
|
|
actor = event.get_source();
|
|
|
|
while (actor) {
|
|
|
|
if (actor._delegate instanceof AppIcon.AppIcon) {
|
|
|
|
this._iconEntered(actor, event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
actor = actor.get_parent();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_iconEntered : function(actor, event) {
|
|
|
|
let index = this._icons.indexOf(actor._delegate);
|
|
|
|
if (this._mouseActive)
|
|
|
|
this._updateSelection(index - this._selected);
|
|
|
|
},
|
|
|
|
|
2009-09-28 23:31:54 -04:00
|
|
|
_finish : function() {
|
|
|
|
if (this._highlightedWindow)
|
|
|
|
Main.activateWindow(this._highlightedWindow);
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
2009-04-13 10:55:41 -04:00
|
|
|
destroy : function() {
|
2009-08-05 19:54:22 -04:00
|
|
|
this.actor.destroy();
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
2009-09-15 11:11:32 -04:00
|
|
|
_onDestroy : function() {
|
|
|
|
if (this._haveModal)
|
|
|
|
Main.popModal(this.actor);
|
|
|
|
|
|
|
|
if (this._lightbox)
|
|
|
|
this._lightbox.destroy();
|
|
|
|
|
|
|
|
if (this._keyPressEventId)
|
|
|
|
global.stage.disconnect(this._keyPressEventId);
|
|
|
|
if (this._keyReleaseEventId)
|
|
|
|
global.stage.disconnect(this._keyReleaseEventId);
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateSelection : function(delta) {
|
2009-08-13 12:52:50 -04:00
|
|
|
this._icons[this._selected].setHighlight(false);
|
2009-09-21 13:04:30 -04:00
|
|
|
if (delta != 0 && this._selectedMenu)
|
|
|
|
this._selectedMenu.popdown();
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
this._selected = (this._selected + this._icons.length + delta) % this._icons.length;
|
|
|
|
this._icons[this._selected].setHighlight(true);
|
2009-09-15 11:11:32 -04:00
|
|
|
|
2009-09-23 12:18:18 -04:00
|
|
|
this._highlightWindow(this._currentWindows[this._selected]);
|
2009-04-13 10:55:41 -04:00
|
|
|
},
|
|
|
|
|
2009-09-21 13:04:30 -04:00
|
|
|
_menuPoppedUp : function(icon, menu) {
|
|
|
|
this._selectedMenu = menu;
|
|
|
|
},
|
|
|
|
|
|
|
|
_menuPoppedDown : function(icon, menu) {
|
|
|
|
this._selectedMenu = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateWindowSelection : function(delta) {
|
|
|
|
let icon = this._icons[this._selected];
|
|
|
|
|
|
|
|
if (!this._selectedMenu)
|
|
|
|
icon.popupMenu();
|
|
|
|
if (!this._selectedMenu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let next = 0;
|
|
|
|
for (let i = 0; i < icon.windows.length; i++) {
|
|
|
|
if (icon.windows[i] == this._highlightedWindow) {
|
|
|
|
next = (i + icon.windows.length + delta) % icon.windows.length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._selectedMenu.selectWindow(icon.windows[next]);
|
|
|
|
},
|
|
|
|
|
2009-08-13 12:52:50 -04:00
|
|
|
_highlightWindow : function(metaWin) {
|
|
|
|
this._highlightedWindow = metaWin;
|
2009-09-23 12:18:18 -04:00
|
|
|
this._currentWindows[this._selected] = metaWin;
|
2009-08-13 12:52:50 -04:00
|
|
|
this._lightbox.highlight(this._highlightedWindow.get_compositor_private());
|
2009-04-13 10:55:41 -04:00
|
|
|
}
|
|
|
|
};
|