Skip to content

Commit

Permalink
Merge pull request #186 from alebastr/wl-surface-commit
Browse files Browse the repository at this point in the history
Commit surface directly instead of relying on gtk_window_invalidate_rect
wmww authored Sep 2, 2024
2 parents f05fe79 + b87c4f1 commit 191b7e7
Showing 6 changed files with 58 additions and 1 deletion.
13 changes: 13 additions & 0 deletions include/gtk-layer-shell.h
Original file line number Diff line number Diff line change
@@ -387,6 +387,19 @@ void gtk_layer_set_keyboard_interactivity (GtkWindow *window, gboolean interacti
*/
gboolean gtk_layer_get_keyboard_interactivity (GtkWindow *window);

/**
* gtk_layer_try_force_commit:
* @window: A layer surface.
*
* Commits a surface state if there's no pending commit scheduled by the GTK.
* You almost never need to call this; the only known case is when the surface is in a state
* where it does not receive frame callbacks and the regular deferred commit mechanism
* is unavailable.
*
* Since: 0.9
*/
void gtk_layer_try_force_commit (GtkWindow *window);

G_END_DECLS

#endif // GTK_LAYER_SHELL_H
9 changes: 9 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
@@ -265,3 +265,12 @@ gtk_layer_get_keyboard_mode (GtkWindow *window)
if (!layer_surface) return GTK_LAYER_SHELL_KEYBOARD_MODE_NONE; // Error message already shown in gtk_window_get_layer_surface
return layer_surface->keyboard_mode;
}

void
gtk_layer_try_force_commit (GtkWindow *window)
{
CustomShellSurface *shell_surface = gtk_window_get_custom_shell_surface (window);
if (!shell_surface)
return;
custom_shell_surface_force_commit (shell_surface);
}
19 changes: 19 additions & 0 deletions src/custom-shell-surface.c
Original file line number Diff line number Diff line change
@@ -124,6 +124,25 @@ custom_shell_surface_needs_commit (CustomShellSurface *self)
gdk_window_invalidate_rect (gdk_window, NULL, FALSE);
}

void
custom_shell_surface_force_commit (CustomShellSurface *self)
{
if (!self->private->gtk_window)
return;

GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (self->private->gtk_window));

if (!gdk_window || gdk_window_get_priv_pending_commit (gdk_window))
return;

struct wl_surface *wl_surface = gdk_wayland_window_get_wl_surface (gdk_window);

if (!wl_surface)
return;

wl_surface_commit (wl_surface);
}

void
custom_shell_surface_remap (CustomShellSurface *self)
{
6 changes: 5 additions & 1 deletion src/custom-shell-surface.h
Original file line number Diff line number Diff line change
@@ -59,10 +59,14 @@ CustomShellSurface *gtk_window_get_custom_shell_surface (GtkWindow *gtk_window);

GtkWindow *custom_shell_surface_get_gtk_window (CustomShellSurface *self);

// In theory this could commit once on next event loop, but for now it will just commit every time it is called
// Schedules commit on the next frame callback
// Does nothing is the shell surface does not currently have a GdkWindow with a wl_surface
void custom_shell_surface_needs_commit (CustomShellSurface *self);

// Attempts to commit the surface immediately
// Does nothing is the shell surface does not currently have a GdkWindow with a wl_surface
void custom_shell_surface_force_commit (CustomShellSurface *self);

// Unmap and remap a currently mapped shell surface
void custom_shell_surface_remap (CustomShellSurface *self);

9 changes: 9 additions & 0 deletions src/gtk-priv-access.c
Original file line number Diff line number Diff line change
@@ -208,3 +208,12 @@ gtk_window_get_priv_logical_geom (GtkWindow *gtk_window)
gdk_window_impl_wayland_priv_get_margin_bottom (window_impl);
return result;
}

gboolean
gdk_window_get_priv_pending_commit (GdkWindow *gdk_window)
{
GdkWindowImplWayland *window_impl = (GdkWindowImplWayland *)gdk_window_priv_get_impl (gdk_window);

return (gdk_window_impl_wayland_priv_get_pending_commit (window_impl) ||
gdk_window_impl_wayland_priv_get_pending_buffer_attached (window_impl));
}
3 changes: 3 additions & 0 deletions src/gtk-priv-access.h
Original file line number Diff line number Diff line change
@@ -34,4 +34,7 @@ void gdk_window_set_priv_mapped (GdkWindow *gdk_window);
// Gets the window geometry (area inside the window that excludes the shadow)
GdkRectangle gtk_window_get_priv_logical_geom (GtkWindow *widget);

// Checks if it is safe to commit wl_surface for the window directly
gboolean gdk_window_get_priv_pending_commit (GdkWindow *gdk_window);

#endif // GDK_WINDOW_HACK_H

0 comments on commit 191b7e7

Please sign in to comment.