3
3
* SPDX-FileCopyrightText: 2020, 2025 elementary, Inc. (https://elementary.io)
4
4
*/
5
5
6
- public class Gala.SessionLocker : Clutter . Actor {
6
+ public class Gala.SessionLocker : Object {
7
7
[DBus (name = "org.freedesktop.login1. Manager ")]
8
8
private interface LoginManager : Object {
9
9
public signal void prepare_for_sleep (bool about_to_suspend);
@@ -62,38 +62,54 @@ public class Gala.SessionLocker : Clutter.Actor {
62
62
private const string LOCK_PROHIBITED_KEY = " disable-lock-screen" ;
63
63
private const string LOCK_ON_SUSPEND_KEY = " lock-on-suspend" ;
64
64
65
- public signal void active_changed ();
65
+ public ScreenShield screen_shield { private get ; construct; }
66
+
67
+ public int64 activation_time { get ; private set ; default = 0 ; }
66
68
67
69
// Screensaver active but not necessarily locked
68
- public bool active { get ; private set ; default = false ; }
70
+ private bool _active = false ;
71
+ public bool active {
72
+ get {
73
+ return _active;
74
+ }
75
+ private set {
76
+ if (! connected_to_buses) {
77
+ return ;
78
+ }
69
79
70
- public bool is_locked { get ; private set ; default = false ; }
71
- public bool in_greeter { get ; private set ; default = false ; }
72
- public int64 activation_time { get ; private set ; default = 0 ; }
80
+ if (_active != value ) {
81
+ _active = value ;
82
+ notify_property (" active" );
83
+ }
73
84
74
- public WindowManager wm { get ; construct; }
85
+ try {
86
+ login_session. set_locked_hint (active);
87
+ } catch (Error e) {
88
+ warning (" Unable to set locked hint on login session: %s " , e. message);
89
+ }
75
90
76
- private ModalProxy ? modal_proxy;
91
+ sync_inhibitor ();
92
+ }
93
+ }
77
94
78
95
private LoginManager ? login_manager;
79
96
private LoginUserManager ? login_user_manager;
80
97
private LoginSessionManager ? login_session;
81
98
private SessionPresence ? session_presence;
82
-
83
99
private DisplayManagerSeat ? display_manager;
84
100
85
- private uint animate_id = 0 ;
86
-
87
101
private UnixInputStream ? inhibitor;
88
102
89
103
private GLib . Settings screensaver_settings;
90
104
private GLib . Settings lockdown_settings;
91
105
private GLib . Settings gala_settings;
92
106
93
107
private bool connected_to_buses = false ;
108
+ private bool is_locked = false ;
109
+ private bool in_greeter = false ;
94
110
95
- public SessionLocker (WindowManager wm ) {
96
- Object (wm : wm );
111
+ public SessionLocker (ScreenShield screen_shield ) {
112
+ Object (screen_shield : screen_shield );
97
113
}
98
114
99
115
construct {
@@ -106,30 +122,7 @@ public class Gala.SessionLocker : Clutter.Actor {
106
122
gala_settings = new GLib .Settings (" io.elementary.desktop.screensaver" );
107
123
lockdown_settings = new GLib .Settings (" org.gnome.desktop.lockdown" );
108
124
109
- visible = false ;
110
- reactive = true ;
111
-
112
- // Listen for keypresses or mouse movement
113
- key_press_event. connect ((event) = > {
114
- on_user_became_active ();
115
- return Clutter . EVENT_STOP ;
116
- });
117
-
118
- motion_event. connect ((event) = > {
119
- on_user_became_active ();
120
- return Clutter . EVENT_STOP ;
121
- });
122
-
123
- #if HAS_MUTTER47
124
- background_color = Cogl . Color . from_string (" black" );
125
- #else
126
- background_color = Clutter . Color . from_string (" black" );
127
- #endif
128
-
129
- expand_to_screen_size ();
130
-
131
- unowned var monitor_manager = wm. get_display (). get_context (). get_backend (). get_monitor_manager ();
132
- monitor_manager. monitors_changed. connect (expand_to_screen_size);
125
+ screen_shield. user_action. connect (on_user_became_active);
133
126
134
127
init_dbus_interfaces. begin ();
135
128
}
@@ -148,7 +141,7 @@ public class Gala.SessionLocker : Clutter.Actor {
148
141
// Listen for lock unlock events from logind
149
142
login_session. lock. connect (() = > @lock (false ));
150
143
login_session. unlock. connect (() = > {
151
- deactivate (false );
144
+ deactivate ();
152
145
in_greeter = false ;
153
146
});
154
147
@@ -186,13 +179,6 @@ public class Gala.SessionLocker : Clutter.Actor {
186
179
connected_to_buses = success;
187
180
}
188
181
189
- private void expand_to_screen_size () {
190
- int screen_width, screen_height;
191
- wm. get_display (). get_size (out screen_width, out screen_height);
192
- width = screen_width;
193
- height = screen_height;
194
- }
195
-
196
182
private void prepare_for_sleep (bool about_to_suspend ) {
197
183
if (! connected_to_buses) {
198
184
return ;
@@ -206,7 +192,6 @@ public class Gala.SessionLocker : Clutter.Actor {
206
192
} else {
207
193
debug (" resumed from suspend, waking screen" );
208
194
on_user_became_active ();
209
- expand_to_screen_size ();
210
195
}
211
196
}
212
197
@@ -264,7 +249,7 @@ public class Gala.SessionLocker : Clutter.Actor {
264
249
// User became active in some way, switch to the greeter if we're not there already
265
250
if (is_locked && ! in_greeter) {
266
251
debug (" user became active, switching to greeter" );
267
- cancel_animation ();
252
+ deactivate ();
268
253
try {
269
254
display_manager. switch_to_greeter ();
270
255
in_greeter = true ;
@@ -274,7 +259,7 @@ public class Gala.SessionLocker : Clutter.Actor {
274
259
// Otherwise, we're in screensaver mode, just deactivate
275
260
} else if (! is_locked) {
276
261
debug (" user became active in unlocked session, closing screensaver" );
277
- deactivate (false );
262
+ deactivate ();
278
263
}
279
264
}
280
265
@@ -315,104 +300,32 @@ public class Gala.SessionLocker : Clutter.Actor {
315
300
}
316
301
317
302
public void activate (bool animate , uint animation_time = LONG_ANIMATION_TIME ) {
318
- if (visible || ! connected_to_buses) {
303
+ if (active || ! connected_to_buses) {
319
304
return ;
320
305
}
321
306
322
- expand_to_screen_size ();
323
-
324
307
if (activation_time == 0 ) {
325
308
activation_time = GLib . get_monotonic_time ();
326
309
}
327
310
328
- wm. get_display (). get_cursor_tracker (). set_pointer_visible (false );
329
- visible = true ;
330
- grab_key_focus ();
331
- modal_proxy = wm. push_modal (this );
332
-
333
- if (Meta . Prefs . get_gnome_animations () && animate) {
334
- animate_and_lock (animation_time);
335
- } else {
336
- _set_active (true );
337
-
338
- opacity = 255 ;
339
-
340
- if (screensaver_settings. get_boolean (LOCK_ENABLED_KEY )) {
341
- @lock (false );
342
- }
343
- }
344
- }
345
-
346
- private void animate_and_lock (uint animation_time ) {
347
- opacity = 0 ;
348
- save_easing_state ();
349
- set_easing_mode (Clutter . AnimationMode . EASE_OUT_QUAD );
350
- set_easing_duration (animation_time);
351
- opacity = 255 ;
352
-
353
- animate_id = Timeout . add (animation_time, () = > {
354
- animate_id = 0 ;
355
-
356
- restore_easing_state ();
357
-
358
- _set_active (true );
311
+ screen_shield. activate (animate ? 0 : animation_time, () = > {
312
+ active = true ;
359
313
360
314
if (screensaver_settings. get_boolean (LOCK_ENABLED_KEY )) {
361
315
@lock (false );
362
316
}
363
-
364
- return GLib . Source . REMOVE ;
365
317
});
366
318
}
367
319
368
- private void cancel_animation () {
369
- if (animate_id != 0 ) {
370
- GLib . Source . remove (animate_id);
371
- animate_id = 0 ;
372
-
373
- restore_easing_state ();
374
- }
375
- }
376
-
377
- public void deactivate (bool animate ) {
320
+ public void deactivate () {
378
321
if (! connected_to_buses) {
379
322
return ;
380
323
}
381
324
382
- cancel_animation ();
325
+ screen_shield . deactivate ();
383
326
384
327
is_locked = false ;
385
-
386
- if (modal_proxy != null ) {
387
- wm. pop_modal (modal_proxy);
388
- modal_proxy = null ;
389
- }
390
-
391
- wm. get_display (). get_cursor_tracker (). set_pointer_visible (true );
392
- visible = false ;
393
-
394
328
activation_time = 0 ;
395
- _set_active (false );
396
- }
397
-
398
- private void _set_active (bool new_active ) {
399
- if (! connected_to_buses) {
400
- return ;
401
- }
402
-
403
- var prev_is_active = active;
404
- active = new_active;
405
-
406
- if (prev_is_active != active) {
407
- active_changed ();
408
- }
409
-
410
- try {
411
- login_session. set_locked_hint (active);
412
- } catch (Error e) {
413
- warning (" Unable to set locked hint on login session: %s " , e. message);
414
- }
415
-
416
- sync_inhibitor ();
329
+ active = false ;
417
330
}
418
331
}
0 commit comments