switcherPopup: Subclass St.Widget
This commit turns SwitcherPopup.SwitcherPopup into a St.Widget subclass, and gets rid of Shell.GenericContainer usage. Subclasses were adapted to that too. This class introduced a new challenge: it overrides show(). As per discussions, we now call this.visible = true inside show(). https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/153
This commit is contained in:
parent
e82c68accd
commit
a315e75e95
@ -80,8 +80,8 @@ var AppSwitcherPopup = new Lang.Class({
|
|||||||
this._items = this._switcherList.icons;
|
this._items = this._switcherList.icons;
|
||||||
},
|
},
|
||||||
|
|
||||||
_allocate(actor, box, flags) {
|
vfunc_allocate(box, flags) {
|
||||||
this.parent(actor, box, flags);
|
this.parent(box, flags);
|
||||||
|
|
||||||
// Allocate the thumbnails
|
// Allocate the thumbnails
|
||||||
// We try to avoid overflowing the screen so we base the resulting size on
|
// We try to avoid overflowing the screen so we base the resulting size on
|
||||||
@ -90,9 +90,9 @@ var AppSwitcherPopup = new Lang.Class({
|
|||||||
let childBox = this._switcherList.actor.get_allocation_box();
|
let childBox = this._switcherList.actor.get_allocation_box();
|
||||||
let primary = Main.layoutManager.primaryMonitor;
|
let primary = Main.layoutManager.primaryMonitor;
|
||||||
|
|
||||||
let leftPadding = this.actor.get_theme_node().get_padding(St.Side.LEFT);
|
let leftPadding = this.get_theme_node().get_padding(St.Side.LEFT);
|
||||||
let rightPadding = this.actor.get_theme_node().get_padding(St.Side.RIGHT);
|
let rightPadding = this.get_theme_node().get_padding(St.Side.RIGHT);
|
||||||
let bottomPadding = this.actor.get_theme_node().get_padding(St.Side.BOTTOM);
|
let bottomPadding = this.get_theme_node().get_padding(St.Side.BOTTOM);
|
||||||
let hPadding = leftPadding + rightPadding;
|
let hPadding = leftPadding + rightPadding;
|
||||||
|
|
||||||
let icon = this._items[this._selectedIndex].actor;
|
let icon = this._items[this._selectedIndex].actor;
|
||||||
@ -105,7 +105,7 @@ var AppSwitcherPopup = new Lang.Class({
|
|||||||
childBox.x1 = Math.max(primary.x + leftPadding, childBox.x1 - offset - hPadding);
|
childBox.x1 = Math.max(primary.x + leftPadding, childBox.x1 - offset - hPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
let spacing = this.actor.get_theme_node().get_length('spacing');
|
let spacing = this.get_theme_node().get_length('spacing');
|
||||||
|
|
||||||
childBox.x2 = childBox.x1 + childNaturalWidth;
|
childBox.x2 = childBox.x1 + childNaturalWidth;
|
||||||
if (childBox.x2 > primary.x + primary.width - rightPadding)
|
if (childBox.x2 > primary.x + primary.width - rightPadding)
|
||||||
@ -392,7 +392,7 @@ var AppSwitcherPopup = new Lang.Class({
|
|||||||
this._thumbnailsFocused = false;
|
this._thumbnailsFocused = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.actor.add_actor(this._thumbnails.actor);
|
this.add_actor(this._thumbnails.actor);
|
||||||
|
|
||||||
// Need to force an allocation so we can figure out whether we
|
// Need to force an allocation so we can figure out whether we
|
||||||
// need to scroll when selecting
|
// need to scroll when selecting
|
||||||
|
@ -39,23 +39,22 @@ function primaryModifier(mask) {
|
|||||||
|
|
||||||
var SwitcherPopup = new Lang.Class({
|
var SwitcherPopup = new Lang.Class({
|
||||||
Name: 'SwitcherPopup',
|
Name: 'SwitcherPopup',
|
||||||
|
Extends: St.Widget,
|
||||||
Abstract: true,
|
Abstract: true,
|
||||||
|
|
||||||
_init(items) {
|
_init(items) {
|
||||||
|
this.parent({ style_class: 'switcher-popup',
|
||||||
|
reactive: true,
|
||||||
|
visible: false });
|
||||||
|
|
||||||
this._switcherList = null;
|
this._switcherList = null;
|
||||||
|
|
||||||
this._items = items || [];
|
this._items = items || [];
|
||||||
this._selectedIndex = 0;
|
this._selectedIndex = 0;
|
||||||
|
|
||||||
this.actor = new Shell.GenericContainer({ style_class: 'switcher-popup',
|
this.connect('destroy', this._onDestroy.bind(this));
|
||||||
reactive: true,
|
|
||||||
visible: false });
|
|
||||||
this.actor.connect('get-preferred-width', this._getPreferredWidth.bind(this));
|
|
||||||
this.actor.connect('get-preferred-height', this._getPreferredHeight.bind(this));
|
|
||||||
this.actor.connect('allocate', this._allocate.bind(this));
|
|
||||||
this.actor.connect('destroy', this._onDestroy.bind(this));
|
|
||||||
|
|
||||||
Main.uiGroup.add_actor(this.actor);
|
Main.uiGroup.add_actor(this);
|
||||||
|
|
||||||
this._haveModal = false;
|
this._haveModal = false;
|
||||||
this._modifierMask = 0;
|
this._modifierMask = 0;
|
||||||
@ -69,26 +68,24 @@ var SwitcherPopup = new Lang.Class({
|
|||||||
this._disableHover();
|
this._disableHover();
|
||||||
},
|
},
|
||||||
|
|
||||||
_getPreferredWidth(actor, forHeight, alloc) {
|
vfunc_get_preferred_width(forHeight) {
|
||||||
let primary = Main.layoutManager.primaryMonitor;
|
let primary = Main.layoutManager.primaryMonitor;
|
||||||
|
return [primary.width, primary.width];
|
||||||
alloc.min_size = primary.width;
|
|
||||||
alloc.natural_size = primary.width;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_getPreferredHeight(actor, forWidth, alloc) {
|
vfunc_get_preferred_height(forWidth) {
|
||||||
let primary = Main.layoutManager.primaryMonitor;
|
let primary = Main.layoutManager.primaryMonitor;
|
||||||
|
return [primary.height, primary.height];
|
||||||
alloc.min_size = primary.height;
|
|
||||||
alloc.natural_size = primary.height;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_allocate(actor, box, flags) {
|
vfunc_allocate(box, flags) {
|
||||||
|
this.set_allocation(box, flags);
|
||||||
|
|
||||||
let childBox = new Clutter.ActorBox();
|
let childBox = new Clutter.ActorBox();
|
||||||
let primary = Main.layoutManager.primaryMonitor;
|
let primary = Main.layoutManager.primaryMonitor;
|
||||||
|
|
||||||
let leftPadding = this.actor.get_theme_node().get_padding(St.Side.LEFT);
|
let leftPadding = this.get_theme_node().get_padding(St.Side.LEFT);
|
||||||
let rightPadding = this.actor.get_theme_node().get_padding(St.Side.RIGHT);
|
let rightPadding = this.get_theme_node().get_padding(St.Side.RIGHT);
|
||||||
let hPadding = leftPadding + rightPadding;
|
let hPadding = leftPadding + rightPadding;
|
||||||
|
|
||||||
// Allocate the switcherList
|
// Allocate the switcherList
|
||||||
@ -115,31 +112,30 @@ var SwitcherPopup = new Lang.Class({
|
|||||||
if (this._items.length == 0)
|
if (this._items.length == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Main.pushModal(this.actor)) {
|
if (!Main.pushModal(this)) {
|
||||||
// Probably someone else has a pointer grab, try again with keyboard only
|
// Probably someone else has a pointer grab, try again with keyboard only
|
||||||
if (!Main.pushModal(this.actor, { options: Meta.ModalOptions.POINTER_ALREADY_GRABBED })) {
|
if (!Main.pushModal(this, { options: Meta.ModalOptions.POINTER_ALREADY_GRABBED }))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this._haveModal = true;
|
this._haveModal = true;
|
||||||
this._modifierMask = primaryModifier(mask);
|
this._modifierMask = primaryModifier(mask);
|
||||||
|
|
||||||
this.actor.connect('key-press-event', this._keyPressEvent.bind(this));
|
this.connect('key-press-event', this._keyPressEvent.bind(this));
|
||||||
this.actor.connect('key-release-event', this._keyReleaseEvent.bind(this));
|
this.connect('key-release-event', this._keyReleaseEvent.bind(this));
|
||||||
|
|
||||||
this.actor.connect('button-press-event', this._clickedOutside.bind(this));
|
this.connect('button-press-event', this._clickedOutside.bind(this));
|
||||||
this.actor.connect('scroll-event', this._scrollEvent.bind(this));
|
this.connect('scroll-event', this._scrollEvent.bind(this));
|
||||||
|
|
||||||
this.actor.add_actor(this._switcherList.actor);
|
this.add_actor(this._switcherList.actor);
|
||||||
this._switcherList.connect('item-activated', this._itemActivated.bind(this));
|
this._switcherList.connect('item-activated', this._itemActivated.bind(this));
|
||||||
this._switcherList.connect('item-entered', this._itemEntered.bind(this));
|
this._switcherList.connect('item-entered', this._itemEntered.bind(this));
|
||||||
this._switcherList.connect('item-removed', this._itemRemoved.bind(this));
|
this._switcherList.connect('item-removed', this._itemRemoved.bind(this));
|
||||||
|
|
||||||
// Need to force an allocation so we can figure out whether we
|
// Need to force an allocation so we can figure out whether we
|
||||||
// need to scroll when selecting
|
// need to scroll when selecting
|
||||||
this.actor.opacity = 0;
|
this.opacity = 0;
|
||||||
this.actor.show();
|
this.visible = true;
|
||||||
this.actor.get_allocation_box();
|
this.get_allocation_box();
|
||||||
|
|
||||||
this._initialSelection(backward, binding);
|
this._initialSelection(backward, binding);
|
||||||
|
|
||||||
@ -163,7 +159,7 @@ var SwitcherPopup = new Lang.Class({
|
|||||||
this._initialDelayTimeoutId = Mainloop.timeout_add(POPUP_DELAY_TIMEOUT,
|
this._initialDelayTimeoutId = Mainloop.timeout_add(POPUP_DELAY_TIMEOUT,
|
||||||
() => {
|
() => {
|
||||||
Main.osdWindowManager.hideAll();
|
Main.osdWindowManager.hideAll();
|
||||||
this.actor.opacity = 255;
|
this.opacity = 255;
|
||||||
this._initialDelayTimeoutId = 0;
|
this._initialDelayTimeoutId = 0;
|
||||||
return GLib.SOURCE_REMOVE;
|
return GLib.SOURCE_REMOVE;
|
||||||
});
|
});
|
||||||
@ -293,24 +289,25 @@ var SwitcherPopup = new Lang.Class({
|
|||||||
|
|
||||||
_popModal() {
|
_popModal() {
|
||||||
if (this._haveModal) {
|
if (this._haveModal) {
|
||||||
Main.popModal(this.actor);
|
Main.popModal(this);
|
||||||
this._haveModal = false;
|
this._haveModal = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fadeAndDestroy() {
|
fadeAndDestroy() {
|
||||||
this._popModal();
|
this._popModal();
|
||||||
if (this.actor.visible) {
|
if (this.visible) {
|
||||||
Tweener.addTween(this.actor,
|
Tweener.addTween(this,
|
||||||
{ opacity: 0,
|
{ opacity: 0,
|
||||||
time: POPUP_FADE_OUT_TIME,
|
time: POPUP_FADE_OUT_TIME,
|
||||||
transition: 'easeOutQuad',
|
transition: 'easeOutQuad',
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
this.actor.destroy();
|
this.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else
|
} else {
|
||||||
this.actor.destroy();
|
this.destroy();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_finish(timestamp) {
|
_finish(timestamp) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user