Implement support for reloading of config files.

Fixes #759.
This commit is contained in:
Renee D'Netto 2020-08-27 22:07:19 +10:00
parent 3c5fd4ba84
commit 943b6bc51b
3 changed files with 19 additions and 6 deletions

View File

@ -14,6 +14,7 @@ class Client {
public: public:
static Client *inst(); static Client *inst();
int main(int argc, char *argv[]); int main(int argc, char *argv[]);
void reset();
Glib::RefPtr<Gtk::Application> gtk_app; Glib::RefPtr<Gtk::Application> gtk_app;
Glib::RefPtr<Gdk::Display> gdk_display; Glib::RefPtr<Gdk::Display> gdk_display;

View File

@ -269,10 +269,9 @@ int waybar::Client::main(int argc, char *argv[]) {
gtk_app->hold(); gtk_app->hold();
gtk_app->run(); gtk_app->run();
bars.clear(); bars.clear();
zxdg_output_manager_v1_destroy(xdg_output_manager);
zwlr_layer_shell_v1_destroy(layer_shell);
zwp_idle_inhibit_manager_v1_destroy(idle_inhibit_manager);
wl_registry_destroy(registry);
wl_display_disconnect(wl_display);
return 0; return 0;
} }
void waybar::Client::reset() {
gtk_app->quit();
}

View File

@ -8,6 +8,7 @@
std::mutex reap_mtx; std::mutex reap_mtx;
std::list<pid_t> reap; std::list<pid_t> reap;
volatile bool reload;
void* signalThread(void* args) { void* signalThread(void* args) {
int err, signum; int err, signum;
@ -70,12 +71,19 @@ void startSignalThread(void) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
auto client = waybar::Client::inst(); auto client = waybar::Client::inst();
std::signal(SIGUSR1, [](int /*signal*/) { std::signal(SIGUSR1, [](int /*signal*/) {
for (auto& bar : waybar::Client::inst()->bars) { for (auto& bar : waybar::Client::inst()->bars) {
bar->toggle(); bar->toggle();
} }
}); });
std::signal(SIGUSR2, [](int /*signal*/) {
spdlog::info("Reloading...");
reload = true;
waybar::Client::inst()->reset();
});
for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) { for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
std::signal(sig, [](int sig) { std::signal(sig, [](int sig) {
for (auto& bar : waybar::Client::inst()->bars) { for (auto& bar : waybar::Client::inst()->bars) {
@ -85,7 +93,12 @@ int main(int argc, char* argv[]) {
} }
startSignalThread(); startSignalThread();
auto ret = client->main(argc, argv); auto ret = 0;
do {
reload = false;
ret = client->main(argc, argv);
} while (reload);
delete client; delete client;
return ret; return ret;
} catch (const std::exception& e) { } catch (const std::exception& e) {