Merge pull request #842 from rdnetto/config-reloading
Implement support for reloading of config files.
This commit is contained in:
commit
a2d98ddde8
|
@ -19,6 +19,7 @@ class Client {
|
|||
public:
|
||||
static Client *inst();
|
||||
int main(int argc, char *argv[]);
|
||||
void reset();
|
||||
|
||||
Glib::RefPtr<Gtk::Application> gtk_app;
|
||||
Glib::RefPtr<Gdk::Display> gdk_display;
|
||||
|
|
|
@ -303,10 +303,9 @@ int waybar::Client::main(int argc, char *argv[]) {
|
|||
gtk_app->hold();
|
||||
gtk_app->run();
|
||||
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;
|
||||
}
|
||||
|
||||
void waybar::Client::reset() {
|
||||
gtk_app->quit();
|
||||
}
|
||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -8,6 +8,7 @@
|
|||
|
||||
std::mutex reap_mtx;
|
||||
std::list<pid_t> reap;
|
||||
volatile bool reload;
|
||||
|
||||
void* signalThread(void* args) {
|
||||
int err, signum;
|
||||
|
@ -70,12 +71,19 @@ void startSignalThread(void) {
|
|||
int main(int argc, char* argv[]) {
|
||||
try {
|
||||
auto client = waybar::Client::inst();
|
||||
|
||||
std::signal(SIGUSR1, [](int /*signal*/) {
|
||||
for (auto& bar : waybar::Client::inst()->bars) {
|
||||
bar->toggle();
|
||||
}
|
||||
});
|
||||
|
||||
std::signal(SIGUSR2, [](int /*signal*/) {
|
||||
spdlog::info("Reloading...");
|
||||
reload = true;
|
||||
waybar::Client::inst()->reset();
|
||||
});
|
||||
|
||||
for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
|
||||
std::signal(sig, [](int sig) {
|
||||
for (auto& bar : waybar::Client::inst()->bars) {
|
||||
|
@ -85,7 +93,12 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
startSignalThread();
|
||||
|
||||
auto ret = client->main(argc, argv);
|
||||
auto ret = 0;
|
||||
do {
|
||||
reload = false;
|
||||
ret = client->main(argc, argv);
|
||||
} while (reload);
|
||||
|
||||
delete client;
|
||||
return ret;
|
||||
} catch (const std::exception& e) {
|
||||
|
|
Loading…
Reference in New Issue