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

fix(wayland): fix the wrong initial window inner size on GTK + Wayland. #1054

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

yuezk
Copy link

@yuezk yuezk commented Feb 9, 2025

Purpose

Fix the wrong initial window inner size on GTK + Wayland. Fixes #929

Related: #984

Troubleshooting

I write a minimal GTK app with a custom title bar using the gtk-rs crate to reproduce the issue. And found that the initial window inner size is correct on Wayland. So I assume the issue is related to the Tao's usage of GTK.

By bisecting the Tao's code in platform_impl::linux::Window::new() method, I found that the issue is related to the window.set_visible(attributes.visible); line. If I comment out this line, the initial window inner size is correct on Wayland.

Then I tried to add this line to the GTK app I wrote before, and found that the issue is reproduced. So I think the issue is related to the set_visible method call on window.

Below is the minimal code I used to reproduce the issue. Toggle the win.set_visible(true) to see the difference between the two.

use gtk::{prelude::*, HeaderBar};
use gtk::{Application, ApplicationWindow};

fn main() {
  let app = Application::builder()
    .application_id("org.example.HelloWorld")
    .build();

  app.connect_activate(|app| {
    // We create the main window.
    let win = ApplicationWindow::builder()
      .application(app)
      .default_width(240)
      .default_height(240)
      .title("Hello, World!")
      .build();

    // Toggle the code below to see the difference between the two.
    // win.set_visible(true);

    let headerbar = HeaderBar::builder()
      .title("HeaderBar example")
      .build();

    win.set_titlebar(Some(&headerbar));

    println!("window size before show_all: {:?}", win.size());
    win.show_all();

    println!("window size after show_all: {:?}", win.size());
  });

  app.run();
}

Solution

Looks like the set_visible call is unnecessary, because the show_all method will show the window. So, we can remove the set_visible call to fix the issue.

@yuezk yuezk requested a review from a team as a code owner February 9, 2025 03:58
Copy link
Contributor

github-actions bot commented Feb 9, 2025

Package Changes Through 8d39090

There are 1 changes which include tao with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tao 0.31.1 0.32.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@yuezk
Copy link
Author

yuezk commented Feb 9, 2025

A workaround is to set the initial window visible to false and call the show method after the window is created.

Set the initial visible to false will cause the window cannot be closed. #1055

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.

Setting initial window size on GTK sets the wrong size
1 participant