1- #include < vector>
21#include " wayfire/debug.hpp"
32#include " wayfire/signal-definitions.hpp"
43#include < string>
54#include < wayfire/config/file.hpp>
65#include < wayfire/config-backend.hpp>
76#include < wayfire/plugin.hpp>
87#include < wayfire/core.hpp>
8+ #include < wayfire/util.hpp> // Added for wl_timer
99
1010#include < cstring>
1111#include < sys/inotify.h>
@@ -40,8 +40,25 @@ class dynamic_ini_config_t : public wf::config_backend_t
4040 private:
4141 struct wl_event_source *inotify_evtsrc = nullptr ;
4242 int inotify_fd = -1 ;
43+ wf::wl_timer<false > reload_timer;
44+ wf::option_wrapper_t <int > config_reload_delay;
4345
4446 public:
47+ /* *
48+ * Schedules a configuration reload after a delay.
49+ * If a reload is already scheduled, it will be reset.
50+ */
51+ void schedule_config_reload ()
52+ {
53+ uint32_t delay_ms = config_reload_delay;
54+ LOGD (" Scheduling configuration file reload in " , delay_ms, " ms" );
55+
56+ reload_timer.set_timeout (delay_ms, [this ] ()
57+ {
58+ this ->do_reload_config ();
59+ });
60+ }
61+
4562 void init (wl_display *display, config::config_manager_t & config,
4663 const std::string& cfg_file) override
4764 {
@@ -56,6 +73,8 @@ class dynamic_ini_config_t : public wf::config_backend_t
5673 config = wf::config::build_configuration (
5774 get_xml_dirs (), SYSCONFDIR " /wayfire/defaults.ini" , config_file);
5875
76+ // Load option after building the config, as the option is not present before that.
77+ config_reload_delay.load_option (" workarounds/config_reload_delay" );
5978 if (check_auto_reload_option ())
6079 {
6180 inotify_fd = inotify_init1 (IN_CLOEXEC);
@@ -111,10 +130,24 @@ class dynamic_ini_config_t : public wf::config_backend_t
111130 inotify_evtsrc = nullptr ;
112131 close (inotify_fd);
113132 inotify_fd = -1 ;
133+ reload_timer.disconnect ();
114134 }
115135
116136 return false ;
117137 }
138+
139+ /* *
140+ * Performs the actual configuration reload and emits the signal.
141+ * This is called by the wl_timer after the delay.
142+ */
143+ void do_reload_config ()
144+ {
145+ LOGD (" Reloading configuration file now!" );
146+ reload_config ();
147+ wf::reload_config_signal ev;
148+ wf::get_core ().emit (&ev);
149+ check_auto_reload_option (); // Re-check auto-reload option after config has been reloaded
150+ }
118151};
119152}
120153
@@ -170,14 +203,9 @@ static int handle_config_updated(int fd, uint32_t mask, void *data)
170203
171204 if (should_reload)
172205 {
173- LOGD (" Reloading configuration file" );
174-
175- reload_config ();
176- wf::reload_config_signal ev;
177- wf::get_core ().emit (&ev);
178-
206+ LOGD (" Detected configuration file change." );
179207 auto self = reinterpret_cast <wf::dynamic_ini_config_t *>(data);
180- self->check_auto_reload_option ();
208+ self->schedule_config_reload ();
181209 }
182210
183211 return 0 ;
0 commit comments