From cbea949551aba48b5eb97374ac76bb24e99caa5a Mon Sep 17 00:00:00 2001 From: Copper Phosphate Date: Tue, 9 Apr 2024 21:12:42 +0200 Subject: [PATCH] fix: remove unmap signal override for improved compatiblity with gtk-layer-shell --- include/gtk-session-lock.h | 10 ++++++++++ src/api.c | 10 ++++++++++ src/custom-shell-surface.c | 6 ++++++ src/custom-shell-surface.h | 2 ++ src/gtk-wayland.c | 22 ---------------------- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/include/gtk-session-lock.h b/include/gtk-session-lock.h index 3a1efbb..39b26a3 100644 --- a/include/gtk-session-lock.h +++ b/include/gtk-session-lock.h @@ -121,6 +121,16 @@ void gtk_session_lock_lock_unlock_and_destroy (GtkSessionLockLock *lock); */ void gtk_session_lock_lock_new_surface (GtkSessionLockLock *lock, GtkWindow *gtk_window, GdkMonitor *monitor); +/** + * gtk_session_lock_unmap_lock_window: + * + * If the given window is a lock window, unmap the surface. This must be called + * before the window is unmapped (e.g. hidden). + * + * Since: 0.2 + */ +void gtk_session_lock_unmap_lock_window (GtkWindow *window); + G_END_DECLS #endif // GTK_SESSION_LOCK_H diff --git a/src/api.c b/src/api.c index 90b1334..27ae227 100644 --- a/src/api.c +++ b/src/api.c @@ -94,3 +94,13 @@ gtk_session_lock_get_lock_surface (GtkWindow *window) if (!lock_surface) return NULL; // Error message already shown in gtk_window_get_lock_surface return lock_surface->lock_surface; } + +void +gtk_session_lock_unmap_lock_window (GtkWindow *window) +{ + g_return_if_fail (window); + CustomShellSurface *shell_surface = gtk_window_get_custom_shell_surface (window); + if (!shell_surface) + return; + custom_shell_surface_unmap (shell_surface); +} diff --git a/src/custom-shell-surface.c b/src/custom-shell-surface.c index 99bfebc..f8f33d7 100644 --- a/src/custom-shell-surface.c +++ b/src/custom-shell-surface.c @@ -120,6 +120,12 @@ custom_shell_surface_needs_commit (CustomShellSurface *self) gdk_window_invalidate_rect (gdk_window, NULL, FALSE); } +void +custom_shell_surface_unmap (CustomShellSurface *self) +{ + self->virtual->unmap (self); +} + void custom_shell_surface_remap (CustomShellSurface *self) { diff --git a/src/custom-shell-surface.h b/src/custom-shell-surface.h index e6bbd12..667388e 100644 --- a/src/custom-shell-surface.h +++ b/src/custom-shell-surface.h @@ -58,6 +58,8 @@ GtkWindow *custom_shell_surface_get_gtk_window (CustomShellSurface *self); // Does nothing is the shell surface does not currently have a GdkWindow with a wl_surface void custom_shell_surface_needs_commit (CustomShellSurface *self); +void custom_shell_surface_unmap (CustomShellSurface *self); + // Unmap and remap a currently mapped shell surface void custom_shell_surface_remap (CustomShellSurface *self); diff --git a/src/gtk-wayland.c b/src/gtk-wayland.c index 9e683fe..aba6845 100644 --- a/src/gtk-wayland.c +++ b/src/gtk-wayland.c @@ -72,24 +72,6 @@ static const struct wl_registry_listener wl_registry_listener = { .global_remove = wl_registry_handle_global_remove, }; -// This callback must override the default unmap handler, so it can run first -// The custom surface's unmap method must be called before GtkWidget's unmap, or Wayland objects are destroyed in the wrong order -static void -gtk_wayland_override_on_window_unmap (GtkWindow *gtk_window, void *_data) -{ - (void)_data; - - CustomShellSurface *shell_surface = gtk_window_get_custom_shell_surface (gtk_window); - if (shell_surface) - shell_surface->virtual->unmap (shell_surface); - - // Call the super class's unmap handler - GValue args[1] = { G_VALUE_INIT }; - g_value_init_from_instance (&args[0], gtk_window); - g_signal_chain_from_overridden (args, NULL); - g_value_unset (&args[0]); -} - void gtk_wayland_init_if_needed () { @@ -108,9 +90,5 @@ gtk_wayland_init_if_needed () if (!lock_manager_global) g_warning ("It appears your Wayland compositor does not support the Session Lock protocol"); - gint unmap_signal_id = g_signal_lookup ("unmap", GTK_TYPE_WINDOW); - GClosure *unmap_closure = g_cclosure_new (G_CALLBACK (gtk_wayland_override_on_window_unmap), NULL, NULL); - g_signal_override_class_closure (unmap_signal_id, GTK_TYPE_WINDOW, unmap_closure); - has_initialized = TRUE; }