Skip to content

Commit

Permalink
fix: allocate space for always visible scrollbar
Browse files Browse the repository at this point in the history
GTK does not allocate any additional space for scrollbars, leading to
always shown scrollbars to overlap the items in the history list.
To fix this, we manually allocate additional space when the the elements
'overflow' the screen and overlay-scrollbars are disabled.

Fixes #149
  • Loading branch information
FineFindus committed Jan 12, 2025
1 parent 1882053 commit 5433559
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ impl AppWindow {
history_item.upcast()
});

let gtk_settings = gtk::Settings::default().unwrap();
gtk_settings.connect_gtk_overlay_scrolling_notify(glib::clone!(
#[weak(rename_to = window)]
self,
move |settings| {
window.adjust_scrollbar_offset(settings);
}
));

self.history().connect_items_changed(glib::clone!(
#[weak(rename_to = window)]
self,
Expand All @@ -339,10 +348,30 @@ impl AppWindow {
let visible = items.n_items() > 1;
window.imp().history_list.set_visible(visible);
window.action_set_enabled("app.clear-history", visible);
window.adjust_scrollbar_offset(&gtk_settings);
}
));
}

fn adjust_scrollbar_offset(&self, settings: &gtk::Settings) {
// FIXME: remove this workaround once https://gitlab.gnome.org/GNOME/gtk/-/issues/6384 is fixed
// calculate how many history items fit into the list, before it begins scrolling
let screen_elements = self.imp().history_list.size(gtk::Orientation::Vertical) / 40;
// width has not been set yet
if screen_elements == 0 {
return;
}
let history_items = self.history().n_items();
let scrollbar_width =
if !settings.is_gtk_overlay_scrolling() && history_items >= screen_elements as u32 {
// size of the scrollbar
24
} else {
0
};
self.imp().history_list.set_margin_end(scrollbar_width);
}

/// Save the window size when closing the window
fn save_window_size(&self) -> Result<(), glib::BoolError> {
let imp = self.imp();
Expand Down

0 comments on commit 5433559

Please sign in to comment.