修改重启实现方式
This commit is contained in:
21
src/wm.c
21
src/wm.c
@@ -49,11 +49,6 @@ static char **cmd_argv;
|
|||||||
/** A pipe that is used to asynchronously handle SIGCHLD */
|
/** A pipe that is used to asynchronously handle SIGCHLD */
|
||||||
static int sigchld_pipe[2];
|
static int sigchld_pipe[2];
|
||||||
|
|
||||||
static void wm_atexit(bool restart) {
|
|
||||||
wm.need_restart = restart;
|
|
||||||
wm_clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean restart_on_signal(gpointer data) {
|
static gboolean restart_on_signal(gpointer data) {
|
||||||
wm_restart();
|
wm_restart();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -272,6 +267,7 @@ void wm_clean(void) {
|
|||||||
xkb_free();
|
xkb_free();
|
||||||
xcb_ungrab_key(wm.xcb_conn, XCB_GRAB_ANY, wm.screen->root, modifier_any);
|
xcb_ungrab_key(wm.xcb_conn, XCB_GRAB_ANY, wm.screen->root, modifier_any);
|
||||||
xcb_key_symbols_free(wm.key_symbols);
|
xcb_key_symbols_free(wm.key_symbols);
|
||||||
|
xcb_aux_sync(wm.xcb_conn);
|
||||||
xcb_disconnect(wm.xcb_conn);
|
xcb_disconnect(wm.xcb_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,12 +321,14 @@ void wm_setup_keybindings(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wm_restart(void) {
|
void wm_restart(void) {
|
||||||
wm_atexit(true);
|
wm.need_restart = true;
|
||||||
execvp(cmd_argv[0], cmd_argv);
|
if (g_main_loop_is_running(wm.loop)) {
|
||||||
fatal("execv() failed: %s", strerror(errno));
|
g_main_loop_quit(wm.loop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_quit(void) {
|
void wm_quit(void) {
|
||||||
|
wm.need_restart = false;
|
||||||
if (g_main_loop_is_running(wm.loop)) {
|
if (g_main_loop_is_running(wm.loop)) {
|
||||||
g_main_loop_quit(wm.loop);
|
g_main_loop_quit(wm.loop);
|
||||||
}
|
}
|
||||||
@@ -374,7 +372,12 @@ int main(int argc, char *argv[]) {
|
|||||||
g_main_loop_unref(wm.loop);
|
g_main_loop_unref(wm.loop);
|
||||||
wm.loop = nullptr;
|
wm.loop = nullptr;
|
||||||
|
|
||||||
wm_atexit(false);
|
wm_clean();
|
||||||
|
|
||||||
|
if (wm.need_restart) {
|
||||||
|
execvp(cmd_argv[0], cmd_argv);
|
||||||
|
fatal("execv() failed: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user