Skip to content

Commit 05168ca

Browse files
authored
Port Lightbox and Flashspot to GObject (#13586)
The port requires renaming the show/hide methods of the Lightbox object. Update several other things while at it. Use connectObject, clean up some clutter deprecations, and use better comparison operators. Lightbox isn't really used in any spices, so this shouldn't have any real effect on them.
1 parent c4e61cf commit 05168ca

3 files changed

Lines changed: 75 additions & 82 deletions

File tree

js/ui/flashspot.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
22

33
const Clutter = imports.gi.Clutter;
4+
const GObject = imports.gi.GObject;
45
const Lightbox = imports.ui.lightbox;
56
const Main = imports.ui.main;
67

78
const FLASHSPOT_ANIMATION_TIME = 200; // seconds
89

9-
var Flashspot = class Flashspot extends Lightbox.Lightbox {
10-
constructor(area) {
11-
super(
10+
var Flashspot = GObject.registerClass(
11+
class Flashspot extends Lightbox.Lightbox {
12+
_init(area) {
13+
super._init(
1214
Main.uiGroup,
1315
{
1416
inhibitEvents: true,
@@ -17,20 +19,20 @@ var Flashspot = class Flashspot extends Lightbox.Lightbox {
1719
}
1820
);
1921

20-
this.actor.style_class = 'flashspot';
21-
this.actor.set_position(area.x, area.y);
22+
this.style_class = 'flashspot';
23+
this.set_position(area.x, area.y);
2224
if (area.time)
23-
this.animation_time = area.time;
25+
this.animationTime = area.time;
2426
else
25-
this.animation_time = FLASHSPOT_ANIMATION_TIME;
27+
this.animationTime = FLASHSPOT_ANIMATION_TIME;
2628
}
2729

2830
fire() {
29-
this.actor.show();
30-
this.actor.opacity = 255;
31-
this.actor.ease({
31+
this.show();
32+
this.opacity = 255;
33+
this.ease({
3234
opacity: 0,
33-
duration: this.animation_time,
35+
duration: this.animationTime,
3436
animationRequired: true,
3537
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
3638
onComplete: () => this._onFireShowComplete()
@@ -40,5 +42,5 @@ var Flashspot = class Flashspot extends Lightbox.Lightbox {
4042
_onFireShowComplete () {
4143
this.destroy();
4244
}
43-
};
45+
});
4446

js/ui/lightbox.js

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -110,116 +110,119 @@ var RadialShaderEffect = GObject.registerClass({
110110
* @container and will track any changes in its size. You can override
111111
* this by passing an explicit width and height in @params.
112112
*/
113-
var Lightbox = class Lightbox {
114-
constructor(container, params) {
115-
params = Params.parse(params, { inhibitEvents: false,
116-
width: null,
117-
height: null,
118-
fadeTime: null,
119-
radialEffect: false,
120-
});
113+
var Lightbox = GObject.registerClass(
114+
class Lightbox extends St.Bin {
115+
_init(container, params) {
116+
params = Params.parse(params, {
117+
inhibitEvents: false,
118+
width: null,
119+
height: null,
120+
fadeTime: null,
121+
radialEffect: false,
122+
});
123+
124+
super._init({
125+
reactive: params.inhibitEvents,
126+
width: params.width,
127+
height: params.height,
128+
visible: false,
129+
});
121130

122131
this._container = container;
123132
this._children = container.get_children();
124133
this._fadeTime = params.fadeTime;
125134
this._radialEffect = Clutter.feature_available(Clutter.FeatureFlags.SHADERS_GLSL) && params.radialEffect;
126135

127-
this.actor = new St.Bin({ reactive: params.inhibitEvents });
128-
129136
if (this._radialEffect)
130-
this.actor.add_effect(new RadialShaderEffect({ name: 'radial' }));
137+
this.add_effect(new RadialShaderEffect({ name: 'radial' }));
131138
else
132-
this.actor.set({ opacity: 0, style_class: 'lightbox', important: true });
139+
this.set({ opacity: 0, style_class: 'lightbox', important: true });
133140

134-
container.add_actor(this.actor);
135-
this.actor.raise_top();
136-
this.actor.hide();
141+
container.add_child(this);
142+
container.set_child_above_sibling(this, null);
137143

138-
this.actor.connect('destroy', this._onDestroy.bind(this));
144+
this.connect('destroy', this._onDestroy.bind(this));
139145

140-
if (params.width && params.height) {
141-
this.actor.width = params.width;
142-
this.actor.height = params.height;
143-
} else {
144-
this.actor.width = container.width;
145-
this.actor.height = container.height;
146-
let constraint = new Clutter.BindConstraint({ source: container,
147-
coordinate: Clutter.BindCoordinate.ALL });
148-
this.actor.add_constraint(constraint);
146+
if (!params.width || !params.height) {
147+
this.add_constraint(new Clutter.BindConstraint({
148+
source: container,
149+
coordinate: Clutter.BindCoordinate.ALL
150+
}));
149151
}
150152

151-
this._actorAddedSignalId = container.connect('actor-added', this._actorAdded.bind(this));
152-
this._actorRemovedSignalId = container.connect('actor-removed', this._actorRemoved.bind(this));
153+
container.connectObject(
154+
'actor-added', this._actorAdded.bind(this),
155+
'actor-removed', this._actorRemoved.bind(this), this);
153156

154157
this._highlighted = null;
155158
}
156159

157160
_actorAdded(container, newChild) {
158-
let children = this._container.get_children();
159-
let myIndex = children.indexOf(this.actor);
160-
let newChildIndex = children.indexOf(newChild);
161+
const children = this._container.get_children();
162+
const myIndex = children.indexOf(this);
163+
const newChildIndex = children.indexOf(newChild);
161164

162165
if (newChildIndex > myIndex) {
163166
// The child was added above the shade (presumably it was
164167
// made the new top-most child). Move it below the shade,
165168
// and add it to this._children as the new topmost actor.
166-
newChild.lower(this.actor);
169+
this._container.set_child_above_sibling(this, newChild);
167170
this._children.push(newChild);
168-
} else if (newChildIndex == 0) {
171+
} else if (newChildIndex === 0) {
169172
// Bottom of stack
170173
this._children.unshift(newChild);
171174
} else {
172175
// Somewhere else; insert it into the correct spot
173-
let prevChild = this._children.indexOf(children[newChildIndex - 1]);
174-
if (prevChild != -1) // paranoia
176+
const prevChild = this._children.indexOf(children[newChildIndex - 1]);
177+
if (prevChild !== -1) // paranoia
175178
this._children.splice(prevChild + 1, 0, newChild);
176179
}
177180
}
178181

179-
show() {
180-
this.actor.remove_all_transitions();
182+
lightOn() {
183+
this.remove_all_transitions();
181184

182185
if (this._radialEffect) {
183-
this.actor.ease_property(
186+
this.ease_property(
184187
'@effects.radial.brightness', VIGNETTE_BRIGHTNESS, {
185188
duration: this._fadeTime / 1000,
186189
mode: Clutter.AnimationMode.EASE_OUT_QUAD
187190
});
188-
this.actor.ease_property(
191+
this.ease_property(
189192
'@effects.radial.sharpness', VIGNETTE_SHARPNESS, {
190193
duration: this._fadeTime / 1000,
191194
mode: Clutter.AnimationMode.EASE_OUT_QUAD
192195
});
193196
} else {
194-
this.actor.opacity = 0;
195-
this.actor.ease({
197+
this.opacity = 0;
198+
this.ease({
196199
opacity: 255,
197200
duration: this._fadeTime / 1000,
198201
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
199202
});
200203
}
201-
this.actor.show();
204+
this.show();
202205
}
203206

204-
hide() {
205-
this.actor.remove_all_transitions();
207+
lightOff() {
208+
this.remove_all_transitions();
206209

207-
let onComplete = () => this.actor.hide();
210+
const onComplete = () => this.hide();
208211

209212
if (this._radialEffect) {
210-
this.actor.ease_property(
213+
this.ease_property(
211214
'@effects.radial.brightness', 1.0, {
212215
duration: this._fadeTime / 1000,
213216
mode: Clutter.AnimationMode.EASE_OUT_QUAD
214217
});
215-
this.actor.ease_property(
218+
this.ease_property(
216219
'@effects.radial.sharpness', 0.0, {
217220
duration: this._fadeTime / 1000,
218221
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
219222
onComplete
220223
});
221224
} else {
222-
this.actor.ease({
225+
this.ease({
223226
opacity: 0,
224227
duration: this._fadeTime / 1000,
225228
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
@@ -229,11 +232,11 @@ var Lightbox = class Lightbox {
229232
}
230233

231234
_actorRemoved(container, child) {
232-
let index = this._children.indexOf(child);
233-
if (index != -1) // paranoia
235+
const index = this._children.indexOf(child);
236+
if (index !== -1) // paranoia
234237
this._children.splice(index, 1);
235238

236-
if (child == this._highlighted)
239+
if (child === this._highlighted)
237240
this._highlighted = null;
238241
}
239242

@@ -246,7 +249,7 @@ var Lightbox = class Lightbox {
246249
* argument, all actors will be unhighlighted.
247250
*/
248251
highlight(window) {
249-
if (this._highlighted == window)
252+
if (this._highlighted === window)
250253
return;
251254

252255
// Walk this._children raising and lowering actors as needed.
@@ -255,38 +258,26 @@ var Lightbox = class Lightbox {
255258
// case we may need to indicate some *other* actor as the new
256259
// sibling of the to-be-lowered one.
257260

258-
let below = this.actor;
261+
let below = this;
259262
for (let i = this._children.length - 1; i >= 0; i--) {
260-
if (this._children[i] == window)
261-
this._children[i].raise_top();
262-
else if (this._children[i] == this._highlighted)
263-
this._children[i].lower(below);
263+
if (this._children[i] === window)
264+
this._container.set_child_above_sibling(this._children[i], null);
265+
else if (this._children[i] === this._highlighted)
266+
this._container.set_child_below_sibling(this._children[i], below);
264267
else
265268
below = this._children[i];
266269
}
267270

268271
this._highlighted = window;
269272
}
270273

271-
/**
272-
* destroy:
273-
*
274-
* Destroys the lightbox.
275-
*/
276-
destroy() {
277-
this.actor.destroy();
278-
}
279-
280274
/**
281275
* _onDestroy:
282276
*
283277
* This is called when the lightbox' actor is destroyed, either
284278
* by destroying its container or by explicitly calling this.destroy().
285279
*/
286280
_onDestroy() {
287-
this._container.disconnect(this._actorAddedSignalId);
288-
this._container.disconnect(this._actorRemovedSignalId);
289-
290281
this.highlight(null);
291282
}
292-
};
283+
});

js/ui/modalDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ var ModalDialog = GObject.registerClass({
197197

198198
this.dialogLayout.opacity = 255;
199199
if (this._lightbox)
200-
this._lightbox.show();
200+
this._lightbox.lightOn();
201201
this.opacity = 0;
202202
this.show();
203203
this.ease({

0 commit comments

Comments
 (0)