33 * SPDX-FileCopyrightText: 2020, 2025 elementary, Inc. (https://elementary.io)
44 */
55
6- public class Gala.SessionLocker : Clutter . Actor {
6+ public class Gala.SessionLocker : Object {
77 [DBus (name = "org.freedesktop.login1. Manager ")]
88 private interface LoginManager : Object {
99 public signal void prepare_for_sleep (bool about_to_suspend);
@@ -62,38 +62,54 @@ public class Gala.SessionLocker : Clutter.Actor {
6262 private const string LOCK_PROHIBITED_KEY = " disable-lock-screen" ;
6363 private const string LOCK_ON_SUSPEND_KEY = " lock-on-suspend" ;
6464
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 ; }
6668
6769 // 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+ }
6979
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+ }
7384
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+ }
7590
76- private ModalProxy ? modal_proxy;
91+ sync_inhibitor ();
92+ }
93+ }
7794
7895 private LoginManager ? login_manager;
7996 private LoginUserManager ? login_user_manager;
8097 private LoginSessionManager ? login_session;
8198 private SessionPresence ? session_presence;
82-
8399 private DisplayManagerSeat ? display_manager;
84100
85- private uint animate_id = 0 ;
86-
87101 private UnixInputStream ? inhibitor;
88102
89103 private GLib . Settings screensaver_settings;
90104 private GLib . Settings lockdown_settings;
91105 private GLib . Settings gala_settings;
92106
93107 private bool connected_to_buses = false ;
108+ private bool is_locked = false ;
109+ private bool in_greeter = false ;
94110
95- public SessionLocker (WindowManager wm ) {
96- Object (wm : wm );
111+ public SessionLocker (ScreenShield screen_shield ) {
112+ Object (screen_shield : screen_shield );
97113 }
98114
99115 construct {
@@ -106,30 +122,7 @@ public class Gala.SessionLocker : Clutter.Actor {
106122 gala_settings = new GLib .Settings (" io.elementary.desktop.screensaver" );
107123 lockdown_settings = new GLib .Settings (" org.gnome.desktop.lockdown" );
108124
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);
133126
134127 init_dbus_interfaces. begin ();
135128 }
@@ -148,7 +141,7 @@ public class Gala.SessionLocker : Clutter.Actor {
148141 // Listen for lock unlock events from logind
149142 login_session. lock. connect (() = > @lock (false ));
150143 login_session. unlock. connect (() = > {
151- deactivate (false );
144+ deactivate ();
152145 in_greeter = false ;
153146 });
154147
@@ -186,13 +179,6 @@ public class Gala.SessionLocker : Clutter.Actor {
186179 connected_to_buses = success;
187180 }
188181
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-
196182 private void prepare_for_sleep (bool about_to_suspend ) {
197183 if (! connected_to_buses) {
198184 return ;
@@ -206,7 +192,6 @@ public class Gala.SessionLocker : Clutter.Actor {
206192 } else {
207193 debug (" resumed from suspend, waking screen" );
208194 on_user_became_active ();
209- expand_to_screen_size ();
210195 }
211196 }
212197
@@ -264,7 +249,7 @@ public class Gala.SessionLocker : Clutter.Actor {
264249 // User became active in some way, switch to the greeter if we're not there already
265250 if (is_locked && ! in_greeter) {
266251 debug (" user became active, switching to greeter" );
267- cancel_animation ();
252+ deactivate ();
268253 try {
269254 display_manager. switch_to_greeter ();
270255 in_greeter = true ;
@@ -274,7 +259,7 @@ public class Gala.SessionLocker : Clutter.Actor {
274259 // Otherwise, we're in screensaver mode, just deactivate
275260 } else if (! is_locked) {
276261 debug (" user became active in unlocked session, closing screensaver" );
277- deactivate (false );
262+ deactivate ();
278263 }
279264 }
280265
@@ -315,104 +300,32 @@ public class Gala.SessionLocker : Clutter.Actor {
315300 }
316301
317302 public void activate (bool animate , uint animation_time = LONG_ANIMATION_TIME ) {
318- if (visible || ! connected_to_buses) {
303+ if (active || ! connected_to_buses) {
319304 return ;
320305 }
321306
322- expand_to_screen_size ();
323-
324307 if (activation_time == 0 ) {
325308 activation_time = GLib . get_monotonic_time ();
326309 }
327310
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 ;
359313
360314 if (screensaver_settings. get_boolean (LOCK_ENABLED_KEY )) {
361315 @lock (false );
362316 }
363-
364- return GLib . Source . REMOVE ;
365317 });
366318 }
367319
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 () {
378321 if (! connected_to_buses) {
379322 return ;
380323 }
381324
382- cancel_animation ();
325+ screen_shield . deactivate ();
383326
384327 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-
394328 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 ;
417330 }
418331}
0 commit comments