cleanup: Port GObject classes to JS6 classes
GJS added API for defining GObject classes with ES6 class syntax last cycle, use it to port the remaining Lang.Class classes to the new syntax. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/361
This commit is contained in:

committed by
Georges Basile Stavracas Neto

parent
bacfdbbb03
commit
e68dfed1f7
@ -3,7 +3,7 @@
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const Lang = imports.lang;
|
||||
const GObject = imports.gi.GObject;
|
||||
const Mainloop = imports.mainloop;
|
||||
const Meta = imports.gi.Meta;
|
||||
const Shell = imports.gi.Shell;
|
||||
@ -35,23 +35,21 @@ var MUTTER_SCHEMA = 'org.gnome.mutter';
|
||||
|
||||
/* A layout manager that requests size only for primary_actor, but then allocates
|
||||
all using a fixed layout */
|
||||
var PrimaryActorLayout = new Lang.Class({
|
||||
Name: 'PrimaryActorLayout',
|
||||
Extends: Clutter.FixedLayout,
|
||||
|
||||
var PrimaryActorLayout = GObject.registerClass(
|
||||
class PrimaryActorLayout extends Clutter.FixedLayout {
|
||||
_init(primaryActor) {
|
||||
this.parent();
|
||||
super._init();
|
||||
|
||||
this.primaryActor = primaryActor;
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_get_preferred_width(container, forHeight) {
|
||||
return this.primaryActor.get_preferred_width(forHeight);
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_get_preferred_height(container, forWidth) {
|
||||
return this.primaryActor.get_preferred_height(forWidth);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
var WindowClone = class {
|
||||
@ -608,12 +606,10 @@ var WorkspaceThumbnail = class {
|
||||
Signals.addSignalMethods(WorkspaceThumbnail.prototype);
|
||||
|
||||
|
||||
var ThumbnailsBox = new Lang.Class({
|
||||
Name: 'ThumbnailsBox',
|
||||
Extends: St.Widget,
|
||||
|
||||
var ThumbnailsBox = GObject.registerClass(
|
||||
class ThumbnailsBox extends St.Widget {
|
||||
_init() {
|
||||
this.parent({ reactive: true,
|
||||
super._init({ reactive: true,
|
||||
style_class: 'workspace-thumbnails',
|
||||
request_mode: Clutter.RequestMode.WIDTH_FOR_HEIGHT });
|
||||
|
||||
@ -683,7 +679,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
this._nWorkspacesNotifyId = 0;
|
||||
this._syncStackingId = 0;
|
||||
this._workareasChangedId = 0;
|
||||
},
|
||||
}
|
||||
|
||||
_updateSwitcherVisibility() {
|
||||
let workspaceManager = global.workspace_manager;
|
||||
@ -691,7 +687,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
this.visible =
|
||||
this._settings.get_boolean('dynamic-workspaces') ||
|
||||
workspaceManager.n_workspaces > 1;
|
||||
},
|
||||
}
|
||||
|
||||
_activateThumbnailAtPoint(stageX, stageY, time) {
|
||||
let [r, x, y] = this.transform_stage_point(stageX, stageY);
|
||||
@ -704,13 +700,13 @@ var ThumbnailsBox = new Lang.Class({
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_onButtonRelease(actor, event) {
|
||||
let [stageX, stageY] = event.get_coords();
|
||||
this._activateThumbnailAtPoint(stageX, stageY, event.get_time());
|
||||
return Clutter.EVENT_STOP;
|
||||
},
|
||||
}
|
||||
|
||||
_onTouchEvent(actor, event) {
|
||||
if (event.type() == Clutter.EventType.TOUCH_END &&
|
||||
@ -720,7 +716,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
}
|
||||
|
||||
return Clutter.EVENT_STOP;
|
||||
},
|
||||
}
|
||||
|
||||
_onDragBegin() {
|
||||
this._dragCancelled = false;
|
||||
@ -728,34 +724,34 @@ var ThumbnailsBox = new Lang.Class({
|
||||
dragMotion: this._onDragMotion.bind(this)
|
||||
};
|
||||
DND.addDragMonitor(this._dragMonitor);
|
||||
},
|
||||
}
|
||||
|
||||
_onDragEnd() {
|
||||
if (this._dragCancelled)
|
||||
return;
|
||||
|
||||
this._endDrag();
|
||||
},
|
||||
}
|
||||
|
||||
_onDragCancelled() {
|
||||
this._dragCancelled = true;
|
||||
this._endDrag();
|
||||
},
|
||||
}
|
||||
|
||||
_endDrag() {
|
||||
this._clearDragPlaceholder();
|
||||
DND.removeDragMonitor(this._dragMonitor);
|
||||
},
|
||||
}
|
||||
|
||||
_onDragMotion(dragEvent) {
|
||||
if (!this.contains(dragEvent.targetActor))
|
||||
this._onLeave();
|
||||
return DND.DragMotionResult.CONTINUE;
|
||||
},
|
||||
}
|
||||
|
||||
_onLeave() {
|
||||
this._clearDragPlaceholder();
|
||||
},
|
||||
}
|
||||
|
||||
_clearDragPlaceholder() {
|
||||
if (this._dropPlaceholderPos == -1)
|
||||
@ -763,7 +759,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
|
||||
this._dropPlaceholderPos = -1;
|
||||
this.queue_relayout();
|
||||
},
|
||||
}
|
||||
|
||||
// Draggable target interface
|
||||
handleDragOver(source, actor, x, y, time) {
|
||||
@ -818,7 +814,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
return source.realWindow ? DND.DragMotionResult.MOVE_DROP : DND.DragMotionResult.COPY_DROP;
|
||||
else
|
||||
return DND.DragMotionResult.CONTINUE;
|
||||
},
|
||||
}
|
||||
|
||||
acceptDrop(source, actor, x, y, time) {
|
||||
if (this._dropWorkspace != -1) {
|
||||
@ -865,7 +861,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_createThumbnails() {
|
||||
let workspaceManager = global.workspace_manager;
|
||||
@ -892,7 +888,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
this.addThumbnails(0, workspaceManager.n_workspaces);
|
||||
|
||||
this._updateSwitcherVisibility();
|
||||
},
|
||||
}
|
||||
|
||||
_destroyThumbnails() {
|
||||
if (this._thumbnails.length == 0)
|
||||
@ -917,7 +913,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
this._thumbnails[w].destroy();
|
||||
this._thumbnails = [];
|
||||
this._porthole = null;
|
||||
},
|
||||
}
|
||||
|
||||
_workspacesChanged() {
|
||||
let validThumbnails =
|
||||
@ -944,7 +940,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
}
|
||||
|
||||
this._updateSwitcherVisibility();
|
||||
},
|
||||
}
|
||||
|
||||
addThumbnails(start, count) {
|
||||
let workspaceManager = global.workspace_manager;
|
||||
@ -978,7 +974,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
|
||||
// Clear the splice index, we got the message
|
||||
this._spliceIndex = -1;
|
||||
},
|
||||
}
|
||||
|
||||
removeThumbnails(start, count) {
|
||||
let currentPos = 0;
|
||||
@ -997,36 +993,36 @@ var ThumbnailsBox = new Lang.Class({
|
||||
}
|
||||
|
||||
this._queueUpdateStates();
|
||||
},
|
||||
}
|
||||
|
||||
_syncStacking(overview, stackIndices) {
|
||||
for (let i = 0; i < this._thumbnails.length; i++)
|
||||
this._thumbnails[i].syncStacking(stackIndices);
|
||||
},
|
||||
}
|
||||
|
||||
set scale(scale) {
|
||||
this._scale = scale;
|
||||
this.queue_relayout();
|
||||
},
|
||||
}
|
||||
|
||||
get scale() {
|
||||
return this._scale;
|
||||
},
|
||||
}
|
||||
|
||||
set indicatorY(indicatorY) {
|
||||
this._indicatorY = indicatorY;
|
||||
this.queue_relayout();
|
||||
},
|
||||
}
|
||||
|
||||
get indicatorY() {
|
||||
return this._indicatorY;
|
||||
},
|
||||
}
|
||||
|
||||
_setThumbnailState(thumbnail, state) {
|
||||
this._stateCounts[thumbnail.state]--;
|
||||
thumbnail.state = state;
|
||||
this._stateCounts[thumbnail.state]++;
|
||||
},
|
||||
}
|
||||
|
||||
_iterateStateThumbnails(state, callback) {
|
||||
if (this._stateCounts[state] == 0)
|
||||
@ -1036,7 +1032,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
if (this._thumbnails[i].state == state)
|
||||
callback.call(this, this._thumbnails[i]);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_tweenScale() {
|
||||
Tweener.addTween(this,
|
||||
@ -1045,7 +1041,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
transition: 'easeOutQuad',
|
||||
onComplete: this._queueUpdateStates,
|
||||
onCompleteScope: this });
|
||||
},
|
||||
}
|
||||
|
||||
_updateStates() {
|
||||
this._stateUpdateQueued = false;
|
||||
@ -1114,7 +1110,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
_queueUpdateStates() {
|
||||
if (this._stateUpdateQueued)
|
||||
@ -1124,7 +1120,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
this._updateStates.bind(this));
|
||||
|
||||
this._stateUpdateQueued = true;
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_get_preferred_height(forWidth) {
|
||||
// Note that for getPreferredWidth/Height we cheat a bit and skip propagating
|
||||
@ -1144,7 +1140,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
let naturalHeight = totalSpacing + nWorkspaces * this._porthole.height * MAX_THUMBNAIL_SCALE;
|
||||
|
||||
return themeNode.adjust_preferred_height(totalSpacing, naturalHeight);
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_get_preferred_width(forHeight) {
|
||||
if (!this._ensurePorthole())
|
||||
@ -1167,7 +1163,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
let width = Math.round(this._porthole.width * scale);
|
||||
|
||||
return themeNode.adjust_preferred_width(width, width);
|
||||
},
|
||||
}
|
||||
|
||||
// The "porthole" is the portion of the screen that we show in the
|
||||
// workspaces
|
||||
@ -1179,7 +1175,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
this._porthole = Main.layoutManager.getWorkAreaForMonitor(Main.layoutManager.primaryIndex);
|
||||
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
vfunc_allocate(box, flags) {
|
||||
this.set_allocation(box, flags);
|
||||
@ -1321,7 +1317,7 @@ var ThumbnailsBox = new Lang.Class({
|
||||
childBox.y1 = indicatorY1 - indicatorTopFullBorder;
|
||||
childBox.y2 = (indicatorY2 ? indicatorY2 : (indicatorY1 + thumbnailHeight)) + indicatorBottomFullBorder;
|
||||
this._indicator.allocate(childBox, flags);
|
||||
},
|
||||
}
|
||||
|
||||
_activeWorkspaceChanged(wm, from, to, direction) {
|
||||
let thumbnail;
|
||||
|
Reference in New Issue
Block a user