[AppWell] Allow popup menu to be persistent, and support direct window selection
When the user click+hold+release over the icon, the effect we want is for the menu to stick around. Also, allow the user to mouse over the actual windows and select them directly. If the user mouses over a window, reflect that in the menu.
This commit is contained in:
@ -489,6 +489,12 @@ WellMenu.prototype = {
|
||||
_init: function(source) {
|
||||
this._source = source;
|
||||
|
||||
// Holds the WindowClone objects for our windows, used in the button release
|
||||
// callback to find the window actor we released over
|
||||
this._cachedWindowClones = [];
|
||||
|
||||
// Whether or not we successfully picked a window
|
||||
this.didActivateWindow = false;
|
||||
|
||||
this.actor = new Shell.GenericContainer({ reactive: true });
|
||||
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
||||
@ -508,6 +514,14 @@ WellMenu.prototype = {
|
||||
this._windowContainer.connect('activate', Lang.bind(this, this._onWindowActivate));
|
||||
this.actor.add_actor(this._windowContainer);
|
||||
|
||||
// Stay popped up on release over application icon
|
||||
this._windowContainer.set_persistent_source(this._source.actor);
|
||||
|
||||
// Intercept events while the menu has the pointer grab to do window-related effects
|
||||
this._windowContainer.connect('enter-event', Lang.bind(this, this._onMenuEnter));
|
||||
this._windowContainer.connect('leave-event', Lang.bind(this, this._onMenuLeave));
|
||||
this._windowContainer.connect('button-release-event', Lang.bind(this, this._onMenuRelease));
|
||||
|
||||
this._arrow = new Shell.DrawingArea();
|
||||
this._arrow.connect('redraw', Lang.bind(this, function (area, texture) {
|
||||
Shell.draw_box_pointer(texture, WELL_MENU_BORDER_COLOR, WELL_MENU_BACKGROUND_COLOR);
|
||||
@ -559,6 +573,8 @@ WellMenu.prototype = {
|
||||
_redisplay: function() {
|
||||
this._windowContainer.remove_all();
|
||||
|
||||
this.didActivateWindow = false;
|
||||
|
||||
let windows = this._source.windows;
|
||||
|
||||
this._windowContainer.show();
|
||||
@ -595,7 +611,10 @@ WellMenu.prototype = {
|
||||
|
||||
_appendWindows: function (windows, iconsDiffer) {
|
||||
for (let i = 0; i < windows.length; i++) {
|
||||
let window = windows[i];
|
||||
let metaWindow = windows[i];
|
||||
|
||||
this._cachedWindowClones.push(Main.overview.lookupCloneForWindow(metaWindow));
|
||||
|
||||
/* Use padding here rather than spacing in the box above so that
|
||||
* we have a larger reactive area.
|
||||
*/
|
||||
@ -604,16 +623,16 @@ WellMenu.prototype = {
|
||||
padding_bottom: 4,
|
||||
spacing: 4,
|
||||
reactive: true });
|
||||
box._window = window;
|
||||
box._window = metaWindow;
|
||||
let vCenter;
|
||||
if (iconsDiffer) {
|
||||
vCenter = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
||||
let icon = Shell.TextureCache.get_default().bind_pixbuf_property(window, "mini-icon");
|
||||
let icon = Shell.TextureCache.get_default().bind_pixbuf_property(metaWindow, "mini-icon");
|
||||
vCenter.append(icon, Big.BoxPackFlags.NONE);
|
||||
box.append(vCenter, Big.BoxPackFlags.NONE);
|
||||
}
|
||||
vCenter = new Big.Box({ y_align: Big.BoxAlignment.CENTER });
|
||||
let label = new Clutter.Text({ text: window.title,
|
||||
let label = new Clutter.Text({ text: metaWindow.title,
|
||||
font_name: WELL_MENU_FONT,
|
||||
ellipsize: Pango.EllipsizeMode.END,
|
||||
color: WELL_MENU_COLOR });
|
||||
@ -639,22 +658,68 @@ WellMenu.prototype = {
|
||||
this.actor.show();
|
||||
},
|
||||
|
||||
_onWindowUnselected: function (actor, child) {
|
||||
child.background_color = TRANSPARENT_COLOR;
|
||||
_findWindowCloneForActor: function (actor) {
|
||||
for (let i = 0; i < this._cachedWindowClones.length; i++) {
|
||||
let clone = this._cachedWindowClones[i];
|
||||
if (clone.actor == actor) {
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
this.emit('highlight-window', null);
|
||||
// This function is called while the menu has a pointer grab; what we want
|
||||
// to do is see if the mouse was released over a window clone actor
|
||||
_onMenuRelease: function (actor, event) {
|
||||
let clone = this._findWindowCloneForActor(event.get_source());
|
||||
if (clone) {
|
||||
this.didActivateWindow = true;
|
||||
Main.overview.activateWindow(clone.metaWindow, event.get_time());
|
||||
}
|
||||
},
|
||||
|
||||
_setHighlightWindow: function (metaWindow) {
|
||||
let children = this._windowContainer.get_children();
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
let child = children[i];
|
||||
let menuMetaWindow = child._window;
|
||||
if (metaWindow != null && menuMetaWindow == metaWindow) {
|
||||
child.background_color = WELL_MENU_SELECTED_COLOR;
|
||||
} else {
|
||||
child.background_color = TRANSPARENT_COLOR;
|
||||
}
|
||||
}
|
||||
this.emit('highlight-window', metaWindow);
|
||||
},
|
||||
|
||||
// Called while menu has a pointer grab
|
||||
_onMenuEnter: function (actor, event) {
|
||||
let clone = this._findWindowCloneForActor(event.get_source());
|
||||
if (clone) {
|
||||
this._setHighlightWindow(clone.metaWindow);
|
||||
}
|
||||
},
|
||||
|
||||
// Called while menu has a pointer grab
|
||||
_onMenuLeave: function (actor, event) {
|
||||
let clone = this._findWindowCloneForActor(event.get_source());
|
||||
if (clone) {
|
||||
this._setHighlightWindow(null);
|
||||
}
|
||||
},
|
||||
|
||||
_onWindowUnselected: function (actor, child) {
|
||||
this._setHighlightWindow(null);
|
||||
},
|
||||
|
||||
_onWindowSelected: function (actor, child) {
|
||||
child.background_color = WELL_MENU_SELECTED_COLOR;
|
||||
|
||||
let window = child._window;
|
||||
this.emit('highlight-window', window);
|
||||
this._setHighlightWindow(child._window);
|
||||
},
|
||||
|
||||
_onWindowActivate: function (actor, child) {
|
||||
let window = child._window;
|
||||
Main.overview.activateWindow(window, Clutter.get_current_event_time());
|
||||
let metaWindow = child._window;
|
||||
this.didActivateWindow = true;
|
||||
Main.overview.activateWindow(metaWindow, Clutter.get_current_event_time());
|
||||
},
|
||||
|
||||
_onPopdown: function () {
|
||||
@ -793,15 +858,22 @@ RunningWellItem.prototype = {
|
||||
|
||||
if (this._menu == null) {
|
||||
this._menu = new WellMenu(this);
|
||||
this._menu.connect('highlight-window', Lang.bind(this, function (menu, window) {
|
||||
Main.overview.setHighlightWindow(window);
|
||||
this._menu.connect('highlight-window', Lang.bind(this, function (menu, metaWindow) {
|
||||
Main.overview.setHighlightWindow(metaWindow);
|
||||
}));
|
||||
this._menu.connect('popup', Lang.bind(this, function (menu, isPoppedUp) {
|
||||
let id;
|
||||
|
||||
// If we successfully picked a window, don't reset the workspace
|
||||
// state, since that causes visual noise. The workspace gets
|
||||
// recreated each time we enter the overview
|
||||
if (!isPoppedUp && menu.didActivateWindow)
|
||||
return;
|
||||
if (isPoppedUp)
|
||||
id = this.appInfo.get_id();
|
||||
else
|
||||
id = null;
|
||||
|
||||
Main.overview.setApplicationWindowSelection(id);
|
||||
}));
|
||||
}
|
||||
|
Reference in New Issue
Block a user