Skip to content

fix(linux): use gtk_window_set_geometry_hints instead of gdk_window_set_geometry_hints to enforce size limits#587

Open
axel10 wants to merge 1 commit into
leanflutter:mainfrom
axel10:main
Open

fix(linux): use gtk_window_set_geometry_hints instead of gdk_window_set_geometry_hints to enforce size limits#587
axel10 wants to merge 1 commit into
leanflutter:mainfrom
axel10:main

Conversation

@axel10

@axel10 axel10 commented Jul 11, 2026

Copy link
Copy Markdown

Description

This pull request fixes sizing constraint issues on Linux/GTK.

Previously, constraints such as:

  • setMinimumSize
  • setMaximumSize
  • setAspectRatio

were not taking effect correctly.

Problem

Currently, the Linux plugin implementation uses the low-level GDK function:

gdk_window_set_geometry_hints(
    get_gdk_window(self),
    &self->window_geometry,
    self->window_hints
);

This approach has two major flaws:

1. Silent Failure during Window Initialization

If size limits are configured before the window is realized (which is the standard practice during application setup),:

get_gdk_window(self)

(which calls gtk_widget_get_window) returns nullptr.

As a result, geometry hints are silently discarded and never applied.

2. GTK Layout Override

Since GTK maintains its own layout and window state abstraction, raw constraints sent to the underlying GdkWindow are often:

  • Overridden by GTK's layout loop.
  • Bypassed during resize operations.
  • Inconsistent with GTK's internal window state.

Solution

Replace gdk_window_set_geometry_hints with the high-level GTK API gtk_window_set_geometry_hints, targeting the GtkWindow directly:

gtk_window_set_geometry_hints(
    get_window(self),
    nullptr,
    &self->window_geometry,
    self->window_hints
);

When targeting the GtkWindow directly:

  • GTK registers and caches the constraints internally.
  • Constraints are automatically applied when the window is realized.
  • Size restrictions are properly enforced during GTK's resize/layout lifecycle.

This ensures that window sizing constraints work correctly and consistently on Linux/GTK.

Using `gdk_window_set_geometry_hints` on the lower-level `GdkWindow` causes
two major issues in GTK applications:
1. If window size limits (like `setMinimumSize` or `setMaximumSize`) are set
   before the window is realized (which is common during application startup),
   `get_gdk_window` returns `nullptr` and the sizing hints are silently ignored.
2. Even after realization, GTK's high-level layout cycle can bypass or override
   direct changes to the low-level `GdkWindow` hints.
This commit replaces `gdk_window_set_geometry_hints` with the GTK-level
`gtk_window_set_geometry_hints` on the `GtkWindow` directly. This allows GTK to
cache the constraints internally, applying them correctly upon window realization
and respecting them during GTK layout calculation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant