Skip to content

Commit

Permalink
Add a width property to the header
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamoca42 committed Sep 30, 2024
1 parent a25e54c commit acdd0ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/platform_impl/linux/wayland/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use gtk::{
pub struct WlHeader;

impl WlHeader {
pub fn setup(window: &ApplicationWindow, title: &str) {
pub fn setup(window: &ApplicationWindow, title: &str, min_width: i32) {
let header = HeaderBar::builder()
.show_close_button(true)
.decoration_layout("menu:minimize,maximize,close")
Expand All @@ -23,8 +23,8 @@ impl WlHeader {
let event_box_clone = event_box.clone();
glib::idle_add_local(move || {
let allocated_height = header_clone.allocated_height();
event_box_clone.set_height_request(allocated_height);
header_clone.set_height_request(allocated_height);
event_box_clone.set_size_request(min_width, allocated_height);
header_clone.set_size_request(min_width, allocated_height);
glib::ControlFlow::Break
});

Expand Down
16 changes: 9 additions & 7 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ impl Window {
}

let window = window_builder.build();
let win_scale_factor = window.scale_factor();
let min_inner_size = attributes
.inner_size_constraints
.min_size_physical::<i32>(win_scale_factor as f64);
let min_width = min_inner_size.width.max(1);
let min_height = min_inner_size.height.max(1);

if is_wayland {
WlHeader::setup(&window, &attributes.title);
WlHeader::setup(&window, &attributes.title, min_width);
}

let window_id = WindowId(window.id());
Expand All @@ -101,15 +107,14 @@ impl Window {
.insert(window_id);

// Set Width/Height & Resizable
let win_scale_factor = window.scale_factor();
let (width, height) = attributes
.inner_size
.map(|size| size.to_logical::<f64>(win_scale_factor as f64).into())
.unwrap_or((800, 600));

let window_clone = window.clone();
glib::idle_add_local(move || {
window_clone.set_default_size(1, 1);
window_clone.set_default_size(min_width, min_height);
window_clone.resize(width, height);
glib::ControlFlow::Break
});
Expand All @@ -129,12 +134,9 @@ impl Window {
// Set Min/Max Size
util::set_size_constraints(&window, attributes.inner_size_constraints);

let min_inner_size = attributes
.inner_size_constraints
.min_size_physical::<f64>(win_scale_factor as f64);
let default_vbox = if pl_attribs.default_vbox {
let box_ = gtk::Box::new(gtk::Orientation::Vertical, 0);
box_.set_size_request(min_inner_size.width as i32, min_inner_size.height as i32);
box_.set_size_request(min_width, min_height);
window.add(&box_);
Some(box_)
} else {
Expand Down

0 comments on commit acdd0ba

Please sign in to comment.