Signal handling to exit and reconfigure the compositor

This commit is contained in:
Keith Bowes 2022-02-18 22:24:20 -05:00
parent 94e23a28f3
commit 357cd843dd
4 changed files with 29 additions and 9 deletions

View file

@ -1,10 +1,6 @@
#ifndef _WB_OUTPUT_H
#define _WB_OUTPUT_H
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200112L
#endif
#include <stdlib.h>
#include <time.h>

View file

@ -1,10 +1,6 @@
#ifndef _WB_SERVER_H
#define _WB_SERVER_H
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200112L
#endif
#include <stdio.h>
#include <wlr/backend.h>

View file

@ -13,6 +13,7 @@ project(
add_project_arguments(
'-Wno-unused-parameter',
'-D_POSIX_C_SOURCE=200112L',
'-DWL_HIDE_DEPRECATED', # Hide the deprecated parts of the Wayland API
'-DWLR_USE_UNSTABLE',
'-DPACKAGE_NAME="' + meson.project_name() + '"',

View file

@ -1,3 +1,4 @@
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
@ -20,6 +21,26 @@ bool show_help(char *name)
return true;
}
struct wb_server server = {0};
void signal_handler(int sig)
{
switch (sig)
{
case SIGINT:
case SIGTERM:
wl_display_terminate(server.wl_display);
break;
case SIGUSR1:
/* Openbox uses SIGUSR1 to restart. I'm not sure of the
* difference between restarting and reconfiguring.
*/
case SIGUSR2:
deinit_config(server.config);
init_config(&server);
break;
}
}
int main(int argc, char **argv) {
#ifdef USE_NLS
setlocale(LC_ALL, "");
@ -28,7 +49,6 @@ int main(int argc, char **argv) {
#endif
char *startup_cmd = NULL;
struct wb_server server = {0};
enum wlr_log_importance debuglevel = WLR_ERROR;
if (argc > 1) {
int i;
@ -88,6 +108,13 @@ int main(int argc, char **argv) {
}
}
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_handler = signal_handler;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
wl_display_run(server.wl_display);
wb_terminate(&server);