Skip to content

Commit

Permalink
fix: remove unmap signal override for improved compatiblity with gtk-…
Browse files Browse the repository at this point in the history
…layer-shell
  • Loading branch information
Cu3PO42 committed Apr 9, 2024
1 parent 38dea59 commit cbea949
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
10 changes: 10 additions & 0 deletions include/gtk-session-lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions src/custom-shell-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/custom-shell-surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 0 additions & 22 deletions src/gtk-wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand All @@ -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;
}

0 comments on commit cbea949

Please sign in to comment.