Skip to content

Setting initial window size on GTK sets the wrong size #929

@hjmallon

Description

@hjmallon

Describe the bug
I am using tao on weston with CentOS 9. Using the WindowBuilder with_inner_size doesn't seem to give the same inner_size.

Steps To Reproduce
I have attached an adjusted example from here to show this, just start it and press spacebar a few times.

Firstly it seems like inner_size and outer_size are always equal on Linux?

Expected behavior
with_inner_size(PhysicalSize::new(240, 240)) should make a window with a content area of 240x240. At the moment I get 240x277

Platform and Versions (please complete the following information):
OS: CentOS Stream 9, weston 8
Rustc: rustc 1.77.2

Additional context
It seems like I can work around this by setting the inner_size again after window decorations have been disabled.

// Copyright 2014-2021 The winit contributors
// Copyright 2021-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0

use tao::{
  dpi::LogicalSize,
  event::{ElementState, Event, KeyEvent, WindowEvent},
  event_loop::{ControlFlow, EventLoop},
  keyboard::KeyCode,
  window::WindowBuilder,
};

#[allow(clippy::single_match)]
fn main() {
  env_logger::init();
  let event_loop = EventLoop::new();

  let window = WindowBuilder::new()
    .with_title("Test")
    .build(&event_loop)
    .unwrap();

  let mut time = 0;

  event_loop.run(move |event, _, control_flow| {
    *control_flow = ControlFlow::Wait;

    match event {
      Event::WindowEvent { event, .. } => match event {
        WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
        WindowEvent::KeyboardInput {
          event:
            KeyEvent {
              physical_key: KeyCode::Space,
              state: ElementState::Released,
              ..
            },
          ..
        } => {
          println!("inner_size: {:?}, outer_size: {:?}, scale_factor: {}", window.inner_size(), window.outer_size(), window.scale_factor());

          if time == 0 {
            println!("window.set_inner_size(LogicalSize[width: 240, height: 240])");
            window.set_inner_size(LogicalSize{width: 240, height: 240});
          } else if time == 1 {
            println!("window.set_decorations(true)");
            window.set_decorations(true);
          } else if time == 2 {
            println!("window.set_inner_size(LogicalSize[width: 240, height: 240])");
            window.set_inner_size(LogicalSize{width: 240, height: 240});
          } else if time == 3 {
            println!("window.set_decorations(false)");
            window.set_decorations(false);
          } else if time == 4 {
            println!("window.set_inner_size(LogicalSize[width: 240, height: 240])");
            window.set_inner_size(LogicalSize{width: 240, height: 240});
          }

          time = time + 1
        }
        _ => ()
      },
      _ => (),
    };
  });
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions