diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
index 0379bed..4f3d013 100644
--- a/src/widgets/mod.rs
+++ b/src/widgets/mod.rs
@@ -25,6 +25,7 @@ mod print;
mod print_preview;
mod properties_view;
mod sliding_view;
+mod window_title;
pub use drag_overlay::LpDragOverlay;
pub use image::LpImage;
@@ -34,3 +35,4 @@ pub use print::LpPrint;
pub use print_preview::LpPrintPreview;
pub use properties_view::LpPropertiesView;
pub use sliding_view::LpSlidingView;
+pub use window_title::LpWindowTitle;
diff --git a/src/widgets/window_title.rs b/src/widgets/window_title.rs
new file mode 100644
index 0000000..b55f7fa
--- /dev/null
+++ b/src/widgets/window_title.rs
@@ -0,0 +1,97 @@
+// Copyright (c) 2023 Sophie Herold
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+//! A window title
+//!
+//! This window title does not claim its complete width as natural width. This
+//! avoids the window to grow to a large file name title instead of just
+//! fittingly for the image size.
+
+use adw::prelude::*;
+use adw::subclass::prelude::*;
+
+use crate::deps::*;
+
+mod imp {
+ use super::*;
+
+ #[derive(Debug, Default, glib::Properties)]
+ #[properties(wrapper_type = super::LpWindowTitle)]
+ pub struct LpWindowTitle {
+ #[property(type = String, set = Self::set_title)]
+ _title: (),
+ window_title: adw::WindowTitle,
+ }
+
+ #[glib::object_subclass]
+ impl ObjectSubclass for LpWindowTitle {
+ const NAME: &'static str = "LpWindowTitle";
+ type Type = super::LpWindowTitle;
+ type ParentType = adw::Bin;
+ }
+
+ impl ObjectImpl for LpWindowTitle {
+ fn constructed(&self) {
+ self.parent_constructed();
+ let obj = self.obj();
+
+ obj.set_layout_manager(None::);
+ obj.set_child(Some(&self.window_title));
+ obj.set_hexpand(true);
+ }
+
+ fn properties() -> &'static [glib::ParamSpec] {
+ Self::derived_properties()
+ }
+
+ fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
+ self.derived_set_property(id, value, pspec)
+ }
+
+ fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
+ self.derived_property(id, pspec)
+ }
+ }
+ impl WidgetImpl for LpWindowTitle {
+ fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
+ let mut measure = self.window_title.measure(orientation, for_size);
+
+ if orientation == gtk::Orientation::Horizontal {
+ // Set natural size to minimal size
+ measure.1 = measure.0;
+ }
+
+ measure
+ }
+
+ fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
+ self.window_title.allocate(width, height, baseline, None);
+ }
+ }
+ impl BinImpl for LpWindowTitle {}
+
+ impl LpWindowTitle {
+ fn set_title(&self, title: String) {
+ self.window_title.set_title(&title);
+ }
+ }
+}
+
+glib::wrapper! {
+ pub struct LpWindowTitle(ObjectSubclass)
+ @extends gtk::Widget, adw::Bin;
+}
diff --git a/src/window.rs b/src/window.rs
index a9d7369..bc19872 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -52,6 +52,7 @@ const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000;
mod imp {
use super::*;
+ use crate::widgets::LpWindowTitle;
// To use composite templates, you need
// to use derive macro. Derive macros generate
@@ -78,6 +79,8 @@ mod imp {
#[template_child]
pub(super) headerbar: TemplateChild,
#[template_child]
+ pub(super) title: TemplateChild,
+ #[template_child]
pub(super) headerbar_events: TemplateChild,
#[template_child]
pub(super) properties_button: TemplateChild,
diff --git a/src/window.ui b/src/window.ui
index bea835b..cdb2e25 100644
--- a/src/window.ui
+++ b/src/window.ui
@@ -61,7 +61,6 @@
498360360
- Image Viewer