Fix scale running onchange on scripted changes (fixes #482)

This commit is contained in:
elkowar 2022-08-29 12:43:01 +02:00
parent abb7315215
commit 3c57ca59bf
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
2 changed files with 16 additions and 2 deletions

View file

@ -8,6 +8,9 @@ All notable changes to eww will be listed here, starting at changes since versio
### Features
- Add support for output names in X11 to select `:monitor`.
### Notable fixes and other changes
- Scale now only runs the onchange command on changes caused by user-interaction
## 0.3.0 (26.05.2022)

View file

@ -224,11 +224,18 @@ pub(super) fn resolve_range_attrs(bargs: &mut BuilderArgs, gtk_widget: &gtk::Ran
gtk::Inhibit(false)
}));
// We keep track of the last value that has been set via gtk_widget.set_value (by a change in the value property).
// We do this so we can detect if the new value came from a scripted change or from a user input from within the value_changed handler
// and only run on_change when it's caused by manual user input
let last_set_value = Rc::new(RefCell::new(None));
let last_set_value_clone = last_set_value.clone();
def_widget!(bargs, _g, gtk_widget, {
// @prop value - the value
prop(value: as_f64) {
if !*is_being_dragged.borrow() {
gtk_widget.set_value(value)
*last_set_value.borrow_mut() = Some(value);
gtk_widget.set_value(value);
}
},
// @prop min - the minimum value
@ -240,8 +247,12 @@ pub(super) fn resolve_range_attrs(bargs: &mut BuilderArgs, gtk_widget: &gtk::Ran
prop(timeout: as_duration = Duration::from_millis(200), onchange: as_string) {
gtk_widget.set_sensitive(true);
gtk_widget.add_events(gdk::EventMask::PROPERTY_CHANGE_MASK);
let last_set_value = last_set_value_clone.clone();
connect_signal_handler!(gtk_widget, gtk_widget.connect_value_changed(move |gtk_widget| {
run_command(timeout, &onchange, &[gtk_widget.value()]);
let value = gtk_widget.value();
if last_set_value.borrow_mut().take() != Some(value) {
run_command(timeout, &onchange, &[value]);
}
}));
}
});