Merge pull request #842 from rdnetto/config-reloading
Implement support for reloading of config files.pull/964/head^2
commit
a2d98ddde8
|
@ -19,6 +19,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;
|
||||||
|
|
|
@ -303,10 +303,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();
|
||||||
|
}
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue