From fa9abd53328b8a1f6d1fcab39aa0fa0de3af99b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 10 Nov 2020 20:13:29 +0100 Subject: [PATCH 1/4] layer-surface: Add debugging when a surface goes away MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps tracing the order of events Signed-off-by: Guido Günther --- src/layersurface.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/layersurface.c b/src/layersurface.c index 0cde3c35..5cf177fc 100644 --- a/src/layersurface.c +++ b/src/layersurface.c @@ -109,6 +109,7 @@ layer_surface_closed (void *data, PhoshLayerSurfacePrivate *priv = phosh_layer_surface_get_instance_private (self); g_return_if_fail (priv->layer_surface == surface); + g_debug ("Destroying layer surface '%s'", priv->namespace); zwlr_layer_surface_v1_destroy (priv->layer_surface); priv->layer_surface = NULL; gtk_widget_destroy (GTK_WIDGET (self)); -- 2.26.2 From 3f15d7658ca9dfc2e21d660ccf5620fff1bd1b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 11 Nov 2020 14:05:06 +0100 Subject: [PATCH 2/4] lockscreen-manager: Explain purpose MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Guido Günther --- src/lockscreen-manager.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lockscreen-manager.c b/src/lockscreen-manager.c index dac21e86..52c58bb4 100644 --- a/src/lockscreen-manager.c +++ b/src/lockscreen-manager.c @@ -23,6 +23,10 @@ * SECTION:lockscreen-manager * @short_description: The singleton that manages screen locking * @Title: PhoshLockscreenManager + * + * The #PhoshLockscreenManager is responsible for putting the #PhoshLockscreen + * on the primary output and a #PhoshLockshield on other outputs when the session + * becomes idle or when invoked explicitly via phosh_lockscreen_manager_set_locked(). */ /* See https://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html#org.gnome.SessionManager.Presence:status */ -- 2.26.2 From e7c139c704231619ef28c93ae91bd5cc2fb82373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 10 Nov 2020 20:39:23 +0100 Subject: [PATCH 3/4] lockscreen-manager: No need to disconnect signals from lockscreen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're about to destroy the lockscreen object a couple of lines later Signed-off-by: Guido Günther --- src/lockscreen-manager.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lockscreen-manager.c b/src/lockscreen-manager.c index 52c58bb4..bfd3da24 100644 --- a/src/lockscreen-manager.c +++ b/src/lockscreen-manager.c @@ -79,7 +79,6 @@ lockscreen_unlock_cb (PhoshLockscreenManager *self, PhoshLockscreen *lockscreen) g_return_if_fail (PHOSH_IS_LOCKSCREEN (lockscreen)); g_return_if_fail (lockscreen == PHOSH_LOCKSCREEN (self->lockscreen)); - g_signal_handlers_disconnect_by_data (lockscreen, self); g_signal_handlers_disconnect_by_data (monitor_manager, self); g_clear_pointer (&self->lockscreen, phosh_cp_widget_destroy); @@ -265,10 +264,7 @@ phosh_lockscreen_manager_dispose (GObject *object) PhoshLockscreenManager *self = PHOSH_LOCKSCREEN_MANAGER (object); g_clear_pointer (&self->shields, g_ptr_array_unref); - if (self->lockscreen) { - g_signal_handlers_disconnect_by_data (self->lockscreen, self); - g_clear_pointer (&self->lockscreen, phosh_cp_widget_destroy); - } + g_clear_pointer (&self->lockscreen, phosh_cp_widget_destroy); g_clear_object (&self->settings); G_OBJECT_CLASS (phosh_lockscreen_manager_parent_class)->dispose (object); -- 2.26.2 From 3e5e2c4a7f12b1e7bfb6fb6ea3e36b28b887cba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Wed, 7 Oct 2020 16:25:36 +0200 Subject: [PATCH 4/4] lockscreen-manager: Move lock screen when output goes away MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We move the lock screen in case the monitor it's on goes away. Closes: #385 Signed-off-by: Guido Günther --- src/lockscreen-manager.c | 99 +++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 21 deletions(-) diff --git a/src/lockscreen-manager.c b/src/lockscreen-manager.c index bfd3da24..781d131b 100644 --- a/src/lockscreen-manager.c +++ b/src/lockscreen-manager.c @@ -80,6 +80,7 @@ lockscreen_unlock_cb (PhoshLockscreenManager *self, PhoshLockscreen *lockscreen) g_return_if_fail (lockscreen == PHOSH_LOCKSCREEN (self->lockscreen)); g_signal_handlers_disconnect_by_data (monitor_manager, self); + g_signal_handlers_disconnect_by_data (shell, self); g_clear_pointer (&self->lockscreen, phosh_cp_widget_destroy); /* Unlock all other outputs */ @@ -102,7 +103,7 @@ lockscreen_wakeup_output_cb (PhoshLockscreenManager *self, PhoshLockscreen *lock } -/* Lock a particular monitor bringing up a shield */ +/* Lock a non primary monitor bringing up a shield */ static void lock_monitor (PhoshLockscreenManager *self, PhoshMonitor *monitor) @@ -114,22 +115,44 @@ lock_monitor (PhoshLockscreenManager *self, phosh_wayland_get_zwlr_layer_shell_v1 (wl), monitor->wl_output); + g_object_set_data (G_OBJECT (shield), "phosh-monitor", monitor); + g_ptr_array_add (self->shields, shield); gtk_widget_show (shield); } +static void +remove_shield_by_monitor (PhoshLockscreenManager *self, + PhoshMonitor *monitor) +{ + for (int i = 0; i < self->shields->len; i++) { + PhoshMonitor *shield_monitor; + PhoshLockshield *shield = g_ptr_array_index (self->shields, i); + + shield_monitor = g_object_get_data (G_OBJECT (shield), "phosh-monitor"); + g_return_if_fail (PHOSH_IS_MONITOR (shield_monitor)); + if (shield_monitor == monitor) { + g_debug ("Removing shield %p", shield); + g_ptr_array_remove (self->shields, shield); + break; + } + } +} + + static void on_monitor_removed (PhoshLockscreenManager *self, PhoshMonitor *monitor, PhoshMonitorManager *monitormanager) { + + g_return_if_fail (PHOSH_IS_MONITOR (monitor)); g_return_if_fail (PHOSH_IS_LOCKSCREEN_MANAGER (self)); - g_debug ("Monitor removed"); - /* TODO: We just leave the widget dangling, it will be destroyed on - * unlock */ + g_debug ("Monitor '%s' removed", monitor->name); + remove_shield_by_monitor (self, monitor); } @@ -141,28 +164,67 @@ on_monitor_added (PhoshLockscreenManager *self, g_return_if_fail (PHOSH_IS_MONITOR (monitor)); g_return_if_fail (PHOSH_IS_LOCKSCREEN_MANAGER (self)); - g_debug ("Monitor added"); + g_debug ("Monitor '%s' added", monitor->name); lock_monitor (self, monitor); } static void -lockscreen_lock (PhoshLockscreenManager *self) +lock_primary_monitor (PhoshLockscreenManager *self) { PhoshMonitor *primary_monitor; PhoshWayland *wl = phosh_wayland_get_default (); PhoshShell *shell = phosh_shell_get_default (); - PhoshMonitorManager *monitor_manager = phosh_shell_get_monitor_manager (shell); - - g_return_if_fail (!self->locked); primary_monitor = phosh_shell_get_primary_monitor (shell); - g_return_if_fail (primary_monitor); /* Undo any transform on the primary display so the keypad becomes usable */ self->transform = phosh_shell_get_transform (shell); phosh_shell_set_transform (shell, PHOSH_MONITOR_TRANSFORM_NORMAL); + /* The primary output gets the clock, keypad, ... */ + self->lockscreen = PHOSH_LOCKSCREEN (phosh_lockscreen_new ( + phosh_wayland_get_zwlr_layer_shell_v1 (wl), + primary_monitor->wl_output)); + + g_object_connect ( + self->lockscreen, + "swapped-object-signal::lockscreen-unlock", G_CALLBACK (lockscreen_unlock_cb), self, + "swapped-object-signal::wakeup-output", G_CALLBACK (lockscreen_wakeup_output_cb), self, + NULL); + + gtk_widget_show (GTK_WIDGET (self->lockscreen)); + /* Old lockscreen gets remove due to `layer_surface_closed` */ +} + + +static void +on_primary_monitor_changed (PhoshLockscreenManager *self, + GParamSpec *pspec, + PhoshShell *shell) +{ + g_return_if_fail (PHOSH_IS_SHELL (shell)); + g_return_if_fail (PHOSH_IS_LOCKSCREEN_MANAGER (self)); + + g_debug ("primary monitor changed, need to move lockscreen"); + lock_primary_monitor (self); + /* We don't remove a shield that might exist to avoid the screen + content flickering in. The shield will be removed on unlock */ +} + + +static void +lockscreen_lock (PhoshLockscreenManager *self) +{ + PhoshMonitor *primary_monitor; + PhoshShell *shell = phosh_shell_get_default (); + PhoshMonitorManager *monitor_manager = phosh_shell_get_monitor_manager (shell); + + g_return_if_fail (!self->locked); + + primary_monitor = phosh_shell_get_primary_monitor (shell); + g_return_if_fail (primary_monitor); + /* Listen for monitor changes */ g_signal_connect_object (monitor_manager, "monitor-added", G_CALLBACK (on_monitor_added), @@ -174,12 +236,13 @@ lockscreen_lock (PhoshLockscreenManager *self) self, G_CONNECT_SWAPPED); - /* The primary output gets the clock, keypad, ... */ - self->lockscreen = PHOSH_LOCKSCREEN (phosh_lockscreen_new ( - phosh_wayland_get_zwlr_layer_shell_v1 (wl), - primary_monitor->wl_output)); - gtk_widget_show (GTK_WIDGET (self->lockscreen)); + g_signal_connect_object (shell, + "notify::primary-monitor", + G_CALLBACK (on_primary_monitor_changed), + self, + G_CONNECT_SWAPPED); + lock_primary_monitor (self); /* Lock all other outputs */ self->shields = g_ptr_array_new_with_free_func ((GDestroyNotify) (gtk_widget_destroy)); @@ -191,12 +254,6 @@ lockscreen_lock (PhoshLockscreenManager *self) lock_monitor (self, monitor); } - g_object_connect ( - self->lockscreen, - "swapped-object-signal::lockscreen-unlock", G_CALLBACK (lockscreen_unlock_cb), self, - "swapped-object-signal::wakeup-output", G_CALLBACK (lockscreen_wakeup_output_cb), self, - NULL); - self->locked = TRUE; self->active_time = g_get_monotonic_time (); g_object_notify_by_pspec (G_OBJECT (self), props[PHOSH_LOCKSCREEN_MANAGER_PROP_LOCKED]); -- 2.26.2