Skip to content

Commit

Permalink
make glib loop play well with SIGINT/SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfdust committed Jun 27, 2024
1 parent 5f1be14 commit 1378b5d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/glib-main-loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
static gboolean on_wayland_fd_event(gint fd, GIOCondition condition,
gpointer user_data);

static int glib_signal_handler(gpointer raw_glib_loop)
{
wf::core_shutdown_signal ev;
Glib::RefPtr<Glib::MainLoop> g_loop = Glib::wrap((GMainLoop*)raw_glib_loop);
g_loop->quit();
wf::get_core().emit(&ev);
return G_SOURCE_REMOVE;
}

namespace wf
{
class glib_main_loop_t : public wf::plugin_interface_t
Expand Down Expand Up @@ -49,6 +58,9 @@ class glib_main_loop_t : public wf::plugin_interface_t
g_loop = Glib::MainLoop::create();
wf::get_core().connect(&glib_loop_run);
wf::get_core().connect(&glib_loop_quit);

g_unix_signal_add_full(G_PRIORITY_DEFAULT, SIGTERM, glib_signal_handler, g_loop.get(), NULL);
g_unix_signal_add_full(G_PRIORITY_DEFAULT, SIGINT, glib_signal_handler, g_loop.get(), NULL);
}

void handle_wayland_fd_in(GIOCondition flag)
Expand Down

0 comments on commit 1378b5d

Please sign in to comment.