-
Notifications
You must be signed in to change notification settings - Fork 238
/
dialogs.js
825 lines (668 loc) · 26.6 KB
/
dialogs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
/*
* Copyright (c) 2011-2017 gnome-pomodoro contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Kamil Prusko <kamilprusko@gmail.com>
*
*/
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Signals = imports.signals;
const Atk = imports.gi.Atk;
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Meta = imports.gi.Meta;
const St = imports.gi.St;
const Pango = imports.gi.Pango;
const GrabHelper = imports.ui.grabHelper;
const Layout = imports.ui.layout;
const Lightbox = imports.ui.lightbox;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const Params = imports.misc.params;
const Extension = imports.misc.extensionUtils.getCurrentExtension();
const Config = Extension.imports.config;
const Timer = Extension.imports.timer;
const Utils = Extension.imports.utils;
const Gettext = imports.gettext.domain(Config.GETTEXT_PACKAGE);
const _ = Gettext.gettext;
const ngettext = Gettext.ngettext;
/* Time between user input events before making dialog modal.
* Value is a little higher than:
* - slow typing speed of 23 words per minute which translates
* to 523 miliseconds between key presses
* - moderate typing speed of 35 words per minute, 343 miliseconds.
*/
const IDLE_TIME_TO_PUSH_MODAL = 600;
const PUSH_MODAL_TIME_LIMIT = 1000;
const PUSH_MODAL_RATE = Clutter.get_default_frame_rate();
const MOTION_DISTANCE_TO_CLOSE = 20;
const IDLE_TIME_TO_OPEN = 60000;
const IDLE_TIME_TO_CLOSE = 600;
const MIN_DISPLAY_TIME = 500;
const FADE_IN_TIME = 200;
const FADE_IN_OPACITY = 0.45;
const FADE_OUT_TIME = 200;
const OPEN_WHEN_IDLE_MIN_REMAINING_TIME = 3.0;
// A single pass blur approximation, with hacky brightness param
const BLUR_FRAGMENT_SHADER = '\
uniform sampler2D tex; \
uniform float x_step, y_step, factor, brightness; \
\
const float[7] weights = float[7](0.1452444, 0.1314128, 0.1115940, 0.0831466, 0.0543562, 0.0311780, 0.0156902); \
const float[7] offsets = float[7](0.0000000, 2.4876390, 4.4711854, 6.4547903, 8.4384988, 10.4223371, 12.4063545); \
\
void main () { \
vec2 uv = vec2(cogl_tex_coord_in[0].st); \
vec2 pixel_size = vec2(x_step * factor, y_step * factor); \
vec4 color = vec4(0.0); \
color += weights[0] * texture2D(tex, uv); \
for (int i=1; i < 7; i++) { \
color += \
weights[i] * texture2D(tex, uv - pixel_size * offsets[i]) + \
weights[i] * texture2D(tex, uv + pixel_size * offsets[i]); \
} \
color.rgb *= 1.0 - (1.0 - sqrt(brightness)) * factor; \
cogl_color_out = color; \
}';
var State = {
OPENED: 0,
CLOSED: 1,
OPENING: 2,
CLOSING: 3
};
var BlurEffect = new Lang.Class({
Name: 'PmodoroBlurEffect',
Extends: Clutter.ShaderEffect,
_init: function(params) {
params = Params.parse(params, { orientation: Clutter.Orientation.HORIZONTAL,
brightness: 1.0,
factor: 1.0 });
this.parent({ shader_type: Clutter.ShaderType.FRAGMENT_SHADER });
this.orientation = params.orientation;
this.brightness = params.brightness;
this.factor = params.factor;
this.set_shader_source(BLUR_FRAGMENT_SHADER);
},
get brightness() {
return this._brightness;
},
set brightness(value) {
this.set_uniform_value('brightness', GObject.Float(value));
this._brightness = value;
},
get factor() {
return this._factor;
},
set factor(value) {
this.set_uniform_value('factor', GObject.Float(value));
this._factor = value;
},
vfunc_pre_paint: function() {
let res = this.parent();
let [success, width, height] = this.get_target_size();
if (success) {
// Actually we don't blur horizontally / vertically, but diagonally
if (this.orientation != Clutter.Orientation.HORIZONTAL) {
this.set_uniform_value('x_step', GObject.Float(1.0 / width));
this.set_uniform_value('y_step', GObject.Float(1.0 / height));
}
else {
this.set_uniform_value('x_step', - GObject.Float(1.0 / width));
this.set_uniform_value('y_step', GObject.Float(1.0 / height));
}
}
else {
this.set_uniform_value('x_step', GObject.Float(0.0));
this.set_uniform_value('y_step', GObject.Float(0.0));
}
return res;
}
});
var BlurredLightbox = new Lang.Class({
Name: 'PomodoroBlurredLightbox',
Extends: Lightbox.Lightbox,
_init: function(container, params) {
params.radialEffect = false;
this.parent(container, params);
if (Clutter.feature_available(Clutter.FeatureFlags.SHADERS_GLSL)) {
// TODO: Try consolidate these effects into one
this._blurXEffect = new BlurEffect({ orientation: Clutter.Orientation.HORIZONTAL,
brightness: this._fadeFactor,
factor: 0.0 });
this._blurYEffect = new BlurEffect({ orientation: Clutter.Orientation.VERTICAL,
brightness: this._fadeFactor,
factor: 0.0 });
// Clone the group that contains all of UI on the screen. This is the
// chrome, the windows, etc.
let uiGroupClone = new Clutter.Clone({ source: Main.layoutManager.uiGroup,
clip_to_allocation: true });
uiGroupClone.add_effect(this._blurXEffect);
uiGroupClone.add_effect(this._blurYEffect);
this.actor.add_actor(uiGroupClone);
this.actor.opacity = 255;
}
this.actor.add_style_class_name('extension-pomodoro-lightbox');
},
show: function(fadeInTime) {
fadeInTime = fadeInTime || 0;
if (this._blurXEffect) {
Tweener.removeTweens(this._blurXEffect);
Tweener.addTween(this._blurXEffect,
{ factor: 1.0,
time: fadeInTime,
transition: 'easeOutQuad',
onUpdate: Lang.bind(this, function() {
this._blurYEffect.factor = this._blurXEffect.factor;
}),
onComplete: Lang.bind(this, function() {
this.shown = true;
this.emit('shown');
})
});
} else {
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor,
{ opacity: 255 * this._fadeFactor,
time: fadeInTime,
transition: 'easeOutQuad',
onComplete: Lang.bind(this, function() {
this.shown = true;
this.emit('shown');
})
});
}
this.actor.show();
},
hide: function(fadeOutTime) {
fadeOutTime = fadeOutTime || 0;
this.shown = false;
if (this._blurXEffect) {
Tweener.removeTweens(this._blurXEffect);
Tweener.addTween(this._blurXEffect,
{ factor: 0.0,
time: fadeOutTime,
transition: 'easeOutQuad',
onUpdate: Lang.bind(this, function() {
this._blurYEffect.factor = this._blurXEffect.factor;
}),
onComplete: Lang.bind(this, function() {
this.actor.hide();
})
});
} else {
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor,
{ opacity: 0,
time: fadeOutTime,
transition: 'easeOutQuad',
onComplete: Lang.bind(this, function() {
this.actor.hide();
})
});
}
}
});
/**
* ModalDialog class based on ModalDialog from GNOME Shell. We need our own
* class to have more event signals, different fade in/out times, and different
* event blocking behavior.
*/
var ModalDialog = new Lang.Class({
Name: 'PomodoroModalDialog',
_init: function() {
this.state = State.CLOSED;
this._idleMonitor = Meta.IdleMonitor.get_core();
this._pushModalDelaySource = 0;
this._pushModalWatchId = 0;
this._pushModalSource = 0;
this._pushModalTries = 0;
this._monitorConstraint = new Layout.MonitorConstraint();
this._stageConstraint = new Clutter.BindConstraint({
source: global.stage,
coordinate: Clutter.BindCoordinate.ALL });
this.actor = new St.Widget({ style_class: 'extension-pomodoro-dialog',
accessible_role: Atk.Role.DIALOG,
layout_manager: new Clutter.BinLayout(),
visible: false,
opacity: 0 });
this.actor._delegate = this;
this.actor.add_constraint(this._stageConstraint);
this.actor.connect('destroy', Lang.bind(this, this._onActorDestroy));
// Modal dialogs are fixed width and grow vertically; set the request
// mode accordingly so wrapped labels are handled correctly during
// size requests.
this._layout = new St.Widget({ layout_manager: new Clutter.BinLayout() });
this._layout.add_constraint(this._monitorConstraint);
this.actor.add_actor(this._layout);
this._lightbox = new BlurredLightbox(this.actor,
{ fadeFactor: FADE_IN_OPACITY,
inhibitEvents: false });
this._lightbox.highlight(this._layout);
this._lightbox.actor.show();
this._grabHelper = new GrabHelper.GrabHelper(this.actor);
this._grabHelper.addActor(this._lightbox.actor);
global.stage.add_actor(this.actor);
global.focus_manager.add_group(this.actor);
},
get isOpened() {
return this.state == State.OPENED || this.state == State.OPENING;
},
_addMessageTray: function() {
let messageTray = Main.messageTray;
messageTray.actor.ref();
Main.layoutManager.removeChrome(messageTray.actor);
global.stage.add_child(messageTray.actor);
messageTray.actor.unref();
messageTray.bannerBlocked = false;
},
_removeMessageTray: function() {
let messageTray = Main.messageTray;
messageTray.actor.ref();
global.stage.remove_child(messageTray.actor);
Main.layoutManager.addChrome(messageTray.actor, { affectsInputRegion: false });
messageTray.actor.unref();
},
open: function(animate) {
if (this.state == State.OPENED || this.state == State.OPENING) {
return;
}
this.state = State.OPENING;
if (this._pushModalDelaySource == 0) {
this._pushModalDelaySource = Mainloop.timeout_add(
Math.max(MIN_DISPLAY_TIME - IDLE_TIME_TO_PUSH_MODAL, 0),
Lang.bind(this, this._onPushModalDelayTimeout));
}
this._monitorConstraint.index = global.screen.get_primary_monitor();
this.actor.raise_top();
this.actor.show();
Tweener.removeTweens(this.actor);
this._addMessageTray();
if (animate) {
this._lightbox.show(FADE_IN_TIME / 1000);
Tweener.addTween(this.actor,
{ opacity: 255,
time: FADE_IN_TIME / 1000,
transition: 'easeOutQuad',
onComplete: Lang.bind(this,
function() {
if (this.state == State.OPENING) {
this.state = State.OPENED;
this.emit('opened');
}
})
});
this.emit('opening');
}
else {
this._lightbox.show();
this.actor.opacity = 255;
this.state = State.OPENED;
this.emit('opening');
this.emit('opened');
}
},
close: function(animate) {
this._cancelOpenWhenIdle();
if (this.state == State.CLOSED || this.state == State.CLOSING) {
return;
}
this.state = State.CLOSING;
this.popModal();
Tweener.removeTweens(this.actor);
if (animate) {
this._lightbox.hide(FADE_OUT_TIME / 1000);
Tweener.addTween(this.actor,
{ opacity: 0,
time: FADE_OUT_TIME / 1000,
transition: 'easeOutQuad',
onComplete: Lang.bind(this,
function() {
if (this.state == State.CLOSING) {
this.state = State.CLOSED;
this.actor.hide();
this._removeMessageTray();
this.emit('closed');
}
})
});
this.emit('closing');
}
else {
this.actor.opacity = 0;
this.actor.hide();
this._lightbox.hide();
this.state = State.CLOSED;
this._removeMessageTray();
this.emit('closing');
this.emit('closed');
}
},
_onPushModalDelayTimeout: function() {
/* Don't become modal and block events just yet,
* wait until user becomes idle.
*/
if (this._pushModalWatchId == 0) {
this._pushModalWatchId = this._idleMonitor.add_idle_watch(IDLE_TIME_TO_PUSH_MODAL, Lang.bind(this,
function(monitor) {
if (this._pushModalWatchId) {
this._idleMonitor.remove_watch(this._pushModalWatchId);
this._pushModalWatchId = 0;
}
this.pushModal();
}
));
}
this._pushModalDelaySource = 0;
return GLib.SOURCE_REMOVE;
},
_pushModal: function() {
if (this.state == State.CLOSED || this.state == State.CLOSING) {
return false;
}
return this._grabHelper.grab({
actor: this._lightbox.actor,
focus: this._lightbox.actor,
onUngrab: Lang.bind(this, this._onUngrab)
});
},
_onPushModalTimeout: function() {
if (this.state == State.CLOSED || this.state == State.CLOSING) {
this._pushModalSource = 0;
return GLib.SOURCE_REMOVE;
}
this._pushModalTries += 1;
if (this._pushModal()) {
this._pushModalSource = 0;
return GLib.SOURCE_REMOVE; /* dialog finally opened */
}
if (this._pushModalTries > PUSH_MODAL_TIME_LIMIT * PUSH_MODAL_RATE) {
this.close(true);
this._pushModalSource = 0;
return GLib.SOURCE_REMOVE; /* dialog can't become modal */
}
return GLib.SOURCE_CONTINUE;
},
pushModal: function() {
if (this.state == State.CLOSED || this.state == State.CLOSING) {
return;
}
this._disconnectSignals();
this._lightbox.actor.reactive = true;
// this._grabHelper.ignoreRelease();
/* delay pushModal to ignore current events */
Mainloop.idle_add(Lang.bind(this,
function() {
this._pushModalTries = 1;
if (this._pushModal()) {
/* dialog became modal */
}
else {
this._pushModalSource = Mainloop.timeout_add(Math.floor(1000 / PUSH_MODAL_RATE),
Lang.bind(this, this._onPushModalTimeout));
}
return GLib.SOURCE_REMOVE;
}
));
},
/**
* Drop modal status without closing the dialog; this makes the
* dialog insensitive as well, so it needs to be followed shortly
* by either a close() or a pushModal()
*/
popModal: function() {
try {
if (this._grabHelper.isActorGrabbed(this._lightbox.actor))
{
this._grabHelper.ungrab({
actor: this._lightbox.actor
});
}
}
catch (error) {
Utils.logWarning(error.message);
}
this._disconnectSignals();
},
_disconnectSignals: function() {
if (this._pushModalDelaySource) {
Mainloop.source_remove(this._pushModalDelaySource);
this._pushModalDelaySource = 0;
}
if (this._pushModalSource) {
Mainloop.source_remove(this._pushModalSource);
this._pushModalSource = 0;
}
if (this._pushModalWatchId) {
this._idleMonitor.remove_watch(this._pushModalWatchId);
this._pushModalWatchId = 0;
}
},
_onUngrab: function() {
this.close(true);
},
_onActorDestroy: function() {
if (this._destroyed)
return;
this._destroyed = true;
this.close(false);
this.actor._delegate = null;
this.emit('destroy');
},
destroy: function() {
this.actor.destroy();
}
});
Signals.addSignalMethods(ModalDialog.prototype);
var PomodoroEndDialog = new Lang.Class({
Name: 'PomodoroEndDialog',
Extends: ModalDialog,
_init: function(timer) {
this.parent();
this.timer = timer;
this.description = _("It's time to take a break");
this._openWhenIdleWatchId = 0;
this._closeWhenActiveDelaySource = 0;
this._closeWhenActiveIdleWatchId = 0;
this._actorMappedId = 0;
this._timerUpdateId = 0;
this._eventId = 0;
this._timerLabel = new St.Label({ style_class: 'extension-pomodoro-dialog-timer' });
this._descriptionLabel = new St.Label({
style_class: 'extension-pomodoro-dialog-description',
text: this.description });
this._descriptionLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
this._descriptionLabel.clutter_text.line_wrap = true;
let box = new St.BoxLayout({ style_class: 'extension-pomodoro-dialog-box',
vertical: true });
box.add(this._timerLabel,
{ y_fill: false,
y_align: St.Align.START });
box.add(this._descriptionLabel,
{ y_fill: false,
y_align: St.Align.START });
this._layout.add_actor(box);
this._actorMappedId = this.actor.connect('notify::mapped', Lang.bind(this, this._onActorMappedChanged));
this.connect('closing', Lang.bind(this, this._onClosing));
this.connect('destroy', Lang.bind(this, this._onDestroy));
},
_onActorMappedChanged: function(actor) {
if (actor.mapped) {
if (!this._timerUpdateId) {
this._timerUpdateId = this.timer.connect('update', Lang.bind(this, this._onTimerUpdate));
this._onTimerUpdate();
}
}
else {
if (this._timerUpdateId) {
this.timer.disconnect(this._timerUpdateId);
this._timerUpdateId = 0;
}
}
},
_onTimerUpdate: function() {
if (this.timer.isBreak()) {
let remaining = Math.max(this.timer.getRemaining(), 0.0);
let minutes = Math.floor(remaining / 60);
let seconds = Math.floor(remaining % 60);
/* method may be called while label actor got destroyed */
if (this._timerLabel.clutter_text) {
this._timerLabel.clutter_text.set_text('%02d:%02d'.format(minutes, seconds));
}
}
},
_onClosing: function() {
this._cancelCloseWhenActive();
this._cancelOpenWhenIdle();
if (this._closeWhenActiveDelaySource) {
Mainloop.source_remove(this._closeWhenActiveDelaySource);
this._closeWhenActiveDelaySource = 0;
}
if (this._closeWhenActiveIdleWatchId) {
this._idleMonitor.remove_watch(this._closeWhenActiveIdleWatchId);
this._closeWhenActiveIdleWatchId = 0;
}
if (this._timerUpdateId) {
this.timer.disconnect(this._timerUpdateId);
this._timerUpdateId = 0;
}
},
_onDestroy: function() {
this._onClosing();
if (this._actorMappedId) {
this.actor.disconnect(this._actorMappedId);
this._actorMappedId = 0;
}
},
_onEvent: function(actor, event) {
let x, y, dx, dy, distance;
if (!event.get_device ()) {
return Clutter.EVENT_STOP;
}
switch (event.type())
{
case Clutter.EventType.ENTER:
case Clutter.EventType.LEAVE:
case Clutter.EventType.STAGE_STATE:
case Clutter.EventType.DESTROY_NOTIFY:
case Clutter.EventType.CLIENT_MESSAGE:
case Clutter.EventType.DELETE:
return Clutter.EVENT_PROPAGATE;
case Clutter.EventType.MOTION:
[x, y] = event.get_coords();
dx = this._eventX >= 0 ? x - this._eventX : 0;
dy = this._eventY >= 0 ? y - this._eventY : 0;
distance = dx * dx + dy * dy;
this._eventX = x;
this._eventY = y;
if (distance > MOTION_DISTANCE_TO_CLOSE * MOTION_DISTANCE_TO_CLOSE) {
this.close(true);
}
break;
case Clutter.EventType.KEY_PRESS:
switch (event.get_key_symbol())
{
case Clutter.KEY_AudioLowerVolume:
case Clutter.KEY_AudioRaiseVolume:
return Clutter.EVENT_PROPAGATE;
default:
this.close(true);
break;
}
break;
case Clutter.EventType.BUTTON_PRESS:
case Clutter.EventType.TOUCH_BEGIN:
this.close(true);
break;
}
return Clutter.EVENT_STOP;
},
/**
* Open the dialog and setup closing when user becomes active.
*/
open: function(animate) {
this.parent(animate);
/* Wait until user has a chance of seeing the dialog */
if (this._closeWhenActiveDelaySource == 0) {
this._closeWhenActiveDelaySource = Mainloop.timeout_add(MIN_DISPLAY_TIME, Lang.bind(this,
function() {
if (this._idleMonitor.get_idletime() < IDLE_TIME_TO_CLOSE) {
/* Wait until user becomes slightly idle */
this._closeWhenActiveIdleWatchId =
this._idleMonitor.add_idle_watch(IDLE_TIME_TO_CLOSE,
Lang.bind(this, this.closeWhenActive));
}
else {
this.closeWhenActive();
}
this._closeWhenActiveDelaySource = 0;
return GLib.SOURCE_REMOVE;
}));
}
},
_cancelOpenWhenIdle: function() {
if (this._openWhenIdleWatchId) {
this._idleMonitor.remove_watch(this._openWhenIdleWatchId);
this._openWhenIdleWatchId = 0;
}
},
openWhenIdle: function() {
if (this.state == State.OPEN || this.state == State.OPENING) {
return;
}
if (this._openWhenIdleWatchId == 0) {
this._openWhenIdleWatchId = this._idleMonitor.add_idle_watch(IDLE_TIME_TO_OPEN, Lang.bind(this,
function() {
let info = Utils.getFocusedWindowInfo();
if (info.isPlayer && info.isFullscreen)
{
/* dont reopen if playing a video */
return;
}
if (!this.timer.isBreak() ||
this.timer.getRemaining() < OPEN_WHEN_IDLE_MIN_REMAINING_TIME)
{
return;
}
this.open(true);
}
));
}
},
_cancelCloseWhenActive: function() {
if (this._eventId) {
this._lightbox.actor.disconnect(this._eventId);
this._eventId = 0;
}
},
// TODO: should be private
closeWhenActive: function() {
if (this.state == State.CLOSED || this.state == State.CLOSING) {
return;
}
if (this._eventId == 0) {
this._eventX = -1;
this._eventY = -1;
this._eventId = this._lightbox.actor.connect('event', Lang.bind(this, this._onEvent));
}
},
setDescription: function(text) {
this.description = text;
if (this._descriptionLabel.clutter_text) {
this._descriptionLabel.clutter_text.set_text(this.description);
}
}
});