Skip to content

Commit

Permalink
Fix reset of int options on option destructor
Browse files Browse the repository at this point in the history
Int durations were set to 0 after adjusting an
int or animation option and susequently clicking
the back button or closing wcm. Fix this by
removing the changed signal handler on option
destructor. Thanks to ammen99 for the initial
idea and patch.
  • Loading branch information
soreau committed Jun 26, 2024
1 parent 6ab4136 commit ea14398
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/wcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "utils.hpp"

#include <filesystem>
#include <iostream>
#include <libevdev/libevdev.h>
#include <wayfire/config/compound-option.hpp>
#include <wayfire/config/types.hpp>
Expand Down Expand Up @@ -347,7 +348,7 @@ OptionWidget::OptionWidget(Option *option) : Gtk::Box(Gtk::ORIENTATION_HORIZONTA
auto spin_button = std::make_unique<Gtk::SpinButton>(
Gtk::Adjustment::create(value, option->data.min, option->data.max,
1));
spin_button->signal_value_changed().connect(
int_spinbutton_connection = spin_button->signal_value_changed().connect(
[=, widget = spin_button.get()]
{
option->set_save(widget->get_value_as_int());
Expand Down Expand Up @@ -423,7 +424,7 @@ OptionWidget::OptionWidget(Option *option) : Gtk::Box(Gtk::ORIENTATION_HORIZONTA
option->set_save(std::to_string(
length_widget->get_value_as_int()) + "ms " + easing_widget->get_active_text().c_str());
};
spin_button->signal_changed().connect(update_option_value);
animate_spinbutton_connection = spin_button->signal_changed().connect(update_option_value);
combo_box->signal_changed().connect(std::move(update_option_value));
reset_button.signal_clicked().connect([=, length_widget = spin_button.get(),
easing_widget = combo_box.get()]
Expand Down Expand Up @@ -641,6 +642,12 @@ OptionWidget::OptionWidget(Option *option) : Gtk::Box(Gtk::ORIENTATION_HORIZONTA
}
}

OptionWidget::~OptionWidget()
{
int_spinbutton_connection.disconnect();
animate_spinbutton_connection.disconnect();
}

AutostartDynamicList::AutostartWidget::AutostartWidget(Option *option) : Gtk::Box(
Gtk::ORIENTATION_HORIZONTAL, 10)
{
Expand Down Expand Up @@ -995,8 +1002,8 @@ OptionSubgroupWidget::OptionSubgroupWidget(Option *subgroup)
expander.add(expander_layout);
for (Option *option : subgroup->options)
{
option_widgets.emplace_back(option);
expander_layout.pack_start(option_widgets.back());
option_widgets.push_back(std::make_unique<OptionWidget>(option));
expander_layout.pack_start(*option_widgets.back());
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/wcm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include <array>
#include <gdk/gdkwayland.h>
#include <gtkmm.h>
#include <iostream>
#include <variant>
#include <vector>
#include <wayfire/config/file.hpp>
#include <wayfire/config/xml.hpp>
Expand Down Expand Up @@ -138,6 +136,8 @@ class OptionWidget : public Gtk::Box
Gtk::Label name_label;
std::vector<std::unique_ptr<Gtk::Widget>> widgets;
Gtk::Button reset_button;
sigc::connection int_spinbutton_connection;
sigc::connection animate_spinbutton_connection;

inline void pack_end(std::unique_ptr<Gtk::Widget> && widget, bool expand = false,
bool fill = false)
Expand All @@ -148,6 +148,7 @@ class OptionWidget : public Gtk::Box

public:
OptionWidget(Option *option);
~OptionWidget();
};

class DynamicListBase : public Gtk::Box
Expand Down Expand Up @@ -260,7 +261,7 @@ class OptionSubgroupWidget : public Gtk::Frame
{
Gtk::Expander expander;
Gtk::Box expander_layout = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 10);
std::vector<OptionWidget> option_widgets;
std::vector<std::unique_ptr<OptionWidget>> option_widgets;

public:
OptionSubgroupWidget(Option *subgroup);
Expand Down

0 comments on commit ea14398

Please sign in to comment.