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,53 @@ 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+ }
7383
74- public WindowManager wm { get ; construct; }
84+ try {
85+ login_session. set_locked_hint (active);
86+ } catch (Error e) {
87+ warning (" Unable to set locked hint on login session: %s " , e. message);
88+ }
7589
76- private ModalProxy ? modal_proxy;
90+ sync_inhibitor ();
91+ }
92+ }
7793
7894 private LoginManager ? login_manager;
7995 private LoginUserManager ? login_user_manager;
8096 private LoginSessionManager ? login_session;
8197 private SessionPresence ? session_presence;
82-
8398 private DisplayManagerSeat ? display_manager;
8499
85- private uint animate_id = 0 ;
86-
87100 private UnixInputStream ? inhibitor;
88101
89102 private GLib . Settings screensaver_settings;
90103 private GLib . Settings lockdown_settings;
91104 private GLib . Settings gala_settings;
92105
93106 private bool connected_to_buses = false ;
107+ private bool is_locked = false ;
108+ private bool in_greeter = false ;
94109
95- public SessionLocker (WindowManager wm ) {
96- Object (wm : wm );
110+ public SessionLocker (ScreenShield screen_shield ) {
111+ Object (screen_shield : screen_shield );
97112 }
98113
99114 construct {
@@ -106,30 +121,7 @@ public class Gala.SessionLocker : Clutter.Actor {
106121 gala_settings = new GLib .Settings (" io.elementary.desktop.screensaver" );
107122 lockdown_settings = new GLib .Settings (" org.gnome.desktop.lockdown" );
108123
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);
124+ screen_shield. user_action. connect (on_user_became_active);
133125
134126 init_dbus_interfaces. begin ();
135127 }
@@ -148,7 +140,7 @@ public class Gala.SessionLocker : Clutter.Actor {
148140 // Listen for lock unlock events from logind
149141 login_session. lock. connect (() = > @lock (false ));
150142 login_session. unlock. connect (() = > {
151- deactivate (false );
143+ deactivate ();
152144 in_greeter = false ;
153145 });
154146
@@ -186,13 +178,6 @@ public class Gala.SessionLocker : Clutter.Actor {
186178 connected_to_buses = success;
187179 }
188180
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-
196181 private void prepare_for_sleep (bool about_to_suspend ) {
197182 if (! connected_to_buses) {
198183 return ;
@@ -206,7 +191,6 @@ public class Gala.SessionLocker : Clutter.Actor {
206191 } else {
207192 debug (" resumed from suspend, waking screen" );
208193 on_user_became_active ();
209- expand_to_screen_size ();
210194 }
211195 }
212196
@@ -264,7 +248,7 @@ public class Gala.SessionLocker : Clutter.Actor {
264248 // User became active in some way, switch to the greeter if we're not there already
265249 if (is_locked && ! in_greeter) {
266250 debug (" user became active, switching to greeter" );
267- cancel_animation ();
251+ deactivate ();
268252 try {
269253 display_manager. switch_to_greeter ();
270254 in_greeter = true ;
@@ -274,7 +258,7 @@ public class Gala.SessionLocker : Clutter.Actor {
274258 // Otherwise, we're in screensaver mode, just deactivate
275259 } else if (! is_locked) {
276260 debug (" user became active in unlocked session, closing screensaver" );
277- deactivate (false );
261+ deactivate ();
278262 }
279263 }
280264
@@ -315,104 +299,32 @@ public class Gala.SessionLocker : Clutter.Actor {
315299 }
316300
317301 public void activate (bool animate , uint animation_time = LONG_ANIMATION_TIME ) {
318- if (visible || ! connected_to_buses) {
302+ if (active || ! connected_to_buses) {
319303 return ;
320304 }
321305
322- expand_to_screen_size ();
323-
324306 if (activation_time == 0 ) {
325307 activation_time = GLib . get_monotonic_time ();
326308 }
327309
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 );
310+ screen_shield. activate (animate ? 0 : animation_time, () = > {
311+ active = true ;
359312
360313 if (screensaver_settings. get_boolean (LOCK_ENABLED_KEY )) {
361314 @lock (false );
362315 }
363-
364- return GLib . Source . REMOVE ;
365316 });
366317 }
367318
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 ) {
319+ public void deactivate () {
378320 if (! connected_to_buses) {
379321 return ;
380322 }
381323
382- cancel_animation ();
324+ screen_shield . deactivate ();
383325
384326 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-
394327 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 ();
328+ active = false ;
417329 }
418330}
0 commit comments