fullscreen: Hide headerbar on idle

Closes #154
This commit is contained in:
Sophie Herold 2023-04-26 21:17:03 +02:00
parent fab6558285
commit a8693c50ef
5 changed files with 92 additions and 13 deletions

View file

@ -47,7 +47,7 @@ features = ["v2_74"]
[dependencies.adw]
package = "libadwaita"
version = "0.4.1"
features = ["v1_3"]
features = ["v1_4"]
[dependencies.gettext-rs]
version = "0.7.0"

View file

@ -68,11 +68,28 @@
</closure>
</binding>
<property name="content">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkHeaderBar" id="headerbar">
<property name="show-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>
<object class="AdwToolbarView" id="toolbar_view">
<binding name="top-bar-style">
<closure type="AdwToolbarStyle" function="top_bar_style">
<lookup name="fullscreened">LpWindow</lookup>
<lookup name="active">properties_button</lookup>
<lookup name="active">primary_menu</lookup>
</closure>
</binding>
<binding name="extend-content-to-top-edge">
<closure type="gboolean" function="extend_to_top">
<lookup name="fullscreened">LpWindow</lookup>
<lookup name="active">properties_button</lookup>
<lookup name="active">primary_menu</lookup>
</closure>
</binding>
<child type="top">
<object class="AdwHeaderBar" id="headerbar">
<property name="show-end-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>
<property name="show-start-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/>"
<style>
<class name="fullscreen-osd" />
</style>
<child type="start">
<object class="GtkButton">
<property name="icon-name">edit-copy-symbolic</property>
@ -88,7 +105,7 @@
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
<object class="GtkMenuButton" id="primary_menu">
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="primary">True</property>
@ -125,9 +142,12 @@
<property name="tooltip-text" translatable="yes">Image Properties</property>
</object>
</child>
<child>
<object class="GtkEventControllerMotion" id="headerbar_events" />
</child>
</object>
</child>
<child>
<property name="content">
<object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="AdwFlap" id="properties_flap">
@ -185,7 +205,7 @@
</object>
</property>
</object>
</child>
</property>
</object>
</property>
<child>

View file

@ -4,6 +4,10 @@ button.osd.circular {
min-height: 42px;
}
.fullscreen revealer:not(.raised) .fullscreen-osd {
background: rgba(0, 0, 0, 0.65);
}
shadow, border, outline {
background: none;
}

View file

@ -9,7 +9,7 @@ i18n = import('i18n')
gnome = import('gnome')
dependency('gtk4', version: '>=4.11.1')
dependency('libadwaita-1', version: '>=1.3.0')
dependency('libadwaita-1', version: '>=1.3.99')
dependency('gweather4', version: '>=4.0.0')
dependency('libheif', version: '>=1.14.2')
dependency('lcms2', version: '>=2.12.0')

View file

@ -72,7 +72,11 @@ mod imp {
// TemplateChild<T> wrapper, where T is the
// object type of the template child.
#[template_child]
pub(super) headerbar: TemplateChild<gtk::HeaderBar>,
pub(super) toolbar_view: TemplateChild<adw::ToolbarView>,
#[template_child]
pub(super) headerbar: TemplateChild<adw::HeaderBar>,
#[template_child]
pub(super) headerbar_events: TemplateChild<gtk::EventControllerMotion>,
#[template_child]
pub(super) properties_button: TemplateChild<gtk::ToggleButton>,
#[template_child]
@ -87,6 +91,7 @@ mod imp {
pub(super) properties_view: TemplateChild<LpPropertiesView>,
#[template_child]
pub(super) drop_target: TemplateChild<gtk::DropTarget>,
/// Motion controller for complete window
#[template_child]
pub(super) motion_controller: TemplateChild<gtk::EventControllerMotion>,
@ -300,6 +305,10 @@ mod imp {
}),
);
self.toolbar_view.connect_top_bar_style_notify(
glib::clone!(@weak obj => move |_| obj.on_top_bar_style_notify()),
);
self.image_view.connect_notify_local(
Some("current-page"),
glib::clone!(@weak obj => move |_, _| {
@ -590,6 +599,10 @@ impl LpWindow {
self.imp().image_view.clone()
}
pub fn headerbar(&self) -> adw::HeaderBar {
self.imp().headerbar.clone()
}
fn show_toast(&self, text: impl AsRef<str>, priority: adw::ToastPriority) {
let imp = self.imp();
@ -691,6 +704,12 @@ impl LpWindow {
self.image_view().controls_box_start().set_opacity(opacity);
self.image_view().controls_box_end().set_opacity(opacity);
if self.is_headerbar_flat() {
self.headerbar().set_opacity(opacity);
} else {
self.headerbar().set_opacity(1.);
}
if self.is_fullscreened() && hiding && opacity < 0.9 {
self.set_cursor(gdk::Cursor::from_name("none", None).as_ref());
} else {
@ -839,6 +858,7 @@ impl LpWindow {
.controls_box_end_events()
.contains_pointer()
&& self.is_showing_image()
&& (!self.is_headerbar_flat() || !self.imp().headerbar_events.contains_pointer())
}
#[template_callback]
@ -849,4 +869,39 @@ impl LpWindow {
}
self.queue_hide_controls();
}
fn is_headerbar_flat(&self) -> bool {
matches!(
self.imp().toolbar_view.top_bar_style(),
adw::ToolbarStyle::Flat
)
}
fn on_top_bar_style_notify(&self) {
if self.is_headerbar_flat() {
// Bring headerbar opacity in sync with controls
self.headerbar().set_opacity(self.controls_opacity());
} else {
self.headerbar().set_opacity(1.);
}
}
#[template_callback]
fn extend_to_top(&self, fullscreened: bool, show_properties: bool, show_menu: bool) -> bool {
fullscreened && !show_properties && !show_menu
}
#[template_callback]
fn top_bar_style(
&self,
fullscreened: bool,
show_properties: bool,
show_menu: bool,
) -> adw::ToolbarStyle {
if self.extend_to_top(fullscreened, show_properties, show_menu) {
adw::ToolbarStyle::Flat
} else {
adw::ToolbarStyle::Raised
}
}
}