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] [dependencies.adw]
package = "libadwaita" package = "libadwaita"
version = "0.4.1" version = "0.4.1"
features = ["v1_3"] features = ["v1_4"]
[dependencies.gettext-rs] [dependencies.gettext-rs]
version = "0.7.0" version = "0.7.0"

View file

@ -68,11 +68,28 @@
</closure> </closure>
</binding> </binding>
<property name="content"> <property name="content">
<object class="GtkBox"> <object class="AdwToolbarView" id="toolbar_view">
<property name="orientation">vertical</property> <binding name="top-bar-style">
<child> <closure type="AdwToolbarStyle" function="top_bar_style">
<object class="GtkHeaderBar" id="headerbar"> <lookup name="fullscreened">LpWindow</lookup>
<property name="show-title-buttons" bind-source="LpWindow" bind-property="fullscreened" bind-flags="sync-create|invert-boolean"/> <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"> <child type="start">
<object class="GtkButton"> <object class="GtkButton">
<property name="icon-name">edit-copy-symbolic</property> <property name="icon-name">edit-copy-symbolic</property>
@ -88,7 +105,7 @@
</object> </object>
</child> </child>
<child type="end"> <child type="end">
<object class="GtkMenuButton"> <object class="GtkMenuButton" id="primary_menu">
<property name="icon-name">open-menu-symbolic</property> <property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Main Menu</property> <property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="primary">True</property> <property name="primary">True</property>
@ -125,9 +142,12 @@
<property name="tooltip-text" translatable="yes">Image Properties</property> <property name="tooltip-text" translatable="yes">Image Properties</property>
</object> </object>
</child> </child>
<child>
<object class="GtkEventControllerMotion" id="headerbar_events" />
</child>
</object> </object>
</child> </child>
<child> <property name="content">
<object class="AdwToastOverlay" id="toast_overlay"> <object class="AdwToastOverlay" id="toast_overlay">
<property name="child"> <property name="child">
<object class="AdwFlap" id="properties_flap"> <object class="AdwFlap" id="properties_flap">
@ -185,14 +205,14 @@
</object> </object>
</property> </property>
</object> </object>
</child> </property>
</object> </object>
</property> </property>
<child> <child>
<object class="GtkEventControllerMotion" id="motion_controller"> <object class="GtkEventControllerMotion" id="motion_controller">
<signal name="motion" handler="on_motion_cb" swapped="yes"/> <signal name="motion" handler="on_motion_cb" swapped="yes"/>
<signal name="enter" handler="on_motion_cb" swapped="yes"/> <signal name="enter" handler="on_motion_cb" swapped="yes"/>
<signal name="leave" handler="on_motion_cb" swapped="yes"/> <signal name="leave" handler="on_motion_cb" swapped="yes"/>
</object> </object>
</child> </child>
</template> </template>

View file

@ -4,6 +4,10 @@ button.osd.circular {
min-height: 42px; min-height: 42px;
} }
.fullscreen revealer:not(.raised) .fullscreen-osd {
background: rgba(0, 0, 0, 0.65);
}
shadow, border, outline { shadow, border, outline {
background: none; background: none;
} }
@ -29,4 +33,4 @@ lpprintpreview {
background-color: rgb(240, 240, 240); background-color: rgb(240, 240, 240);
border-radius: 4px; border-radius: 4px;
box-shadow: 0 0 14px 1px black; box-shadow: 0 0 14px 1px black;
} }

View file

@ -9,7 +9,7 @@ i18n = import('i18n')
gnome = import('gnome') gnome = import('gnome')
dependency('gtk4', version: '>=4.11.1') 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('gweather4', version: '>=4.0.0')
dependency('libheif', version: '>=1.14.2') dependency('libheif', version: '>=1.14.2')
dependency('lcms2', version: '>=2.12.0') dependency('lcms2', version: '>=2.12.0')

View file

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