Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit surface directly instead of relying on gtk_window_invalidate_rect #186

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/gtk-layer-shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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)
{
Expand Down
6 changes: 5 additions & 1 deletion src/custom-shell-surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions src/gtk-priv-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Loading