mirror of
https://github.com/cage-kiosk/cage.git
synced 2026-02-05 04:06:24 -05:00
Merge a500d11f0f into dcd64ae48b
This commit is contained in:
commit
0ca2f6a92f
7 changed files with 86 additions and 0 deletions
19
cage.c
19
cage.c
|
|
@ -54,6 +54,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "idle_inhibit_v1.h"
|
#include "idle_inhibit_v1.h"
|
||||||
|
#include "notify.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "seat.h"
|
#include "seat.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
@ -235,6 +236,16 @@ handle_signal(int signal, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
handle_alive_timer(void *data)
|
||||||
|
{
|
||||||
|
struct cg_server *server = data;
|
||||||
|
|
||||||
|
notify_set_state(CAGE_ALIVE);
|
||||||
|
wl_event_source_timer_update(server->alive_source, CAGE_ALIVE_PERIOD_MS);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(FILE *file, const char *cage)
|
usage(FILE *file, const char *cage)
|
||||||
{
|
{
|
||||||
|
|
@ -326,6 +337,7 @@ main(int argc, char *argv[])
|
||||||
struct wl_event_loop *event_loop = wl_display_get_event_loop(server.wl_display);
|
struct wl_event_loop *event_loop = wl_display_get_event_loop(server.wl_display);
|
||||||
struct wl_event_source *sigint_source = wl_event_loop_add_signal(event_loop, SIGINT, handle_signal, &server);
|
struct wl_event_source *sigint_source = wl_event_loop_add_signal(event_loop, SIGINT, handle_signal, &server);
|
||||||
struct wl_event_source *sigterm_source = wl_event_loop_add_signal(event_loop, SIGTERM, handle_signal, &server);
|
struct wl_event_source *sigterm_source = wl_event_loop_add_signal(event_loop, SIGTERM, handle_signal, &server);
|
||||||
|
server.alive_source = wl_event_loop_add_timer(event_loop, handle_alive_timer, &server);
|
||||||
|
|
||||||
server.backend = wlr_backend_autocreate(event_loop, &server.session);
|
server.backend = wlr_backend_autocreate(event_loop, &server.session);
|
||||||
if (!server.backend) {
|
if (!server.backend) {
|
||||||
|
|
@ -625,8 +637,14 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
seat_center_cursor(server.seat);
|
seat_center_cursor(server.seat);
|
||||||
|
|
||||||
|
notify_set_state(CAGE_READY);
|
||||||
|
wl_event_source_timer_update(server.alive_source, CAGE_ALIVE_PERIOD_MS);
|
||||||
|
|
||||||
wl_display_run(server.wl_display);
|
wl_display_run(server.wl_display);
|
||||||
|
|
||||||
|
notify_set_state(CAGE_STOPPING);
|
||||||
|
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
if (xwayland) {
|
if (xwayland) {
|
||||||
wl_list_remove(&server.new_xwayland_surface.link);
|
wl_list_remove(&server.new_xwayland_surface.link);
|
||||||
|
|
@ -660,6 +678,7 @@ end:
|
||||||
|
|
||||||
wl_event_source_remove(sigint_source);
|
wl_event_source_remove(sigint_source);
|
||||||
wl_event_source_remove(sigterm_source);
|
wl_event_source_remove(sigterm_source);
|
||||||
|
wl_event_source_remove(server.alive_source);
|
||||||
if (sigchld_source) {
|
if (sigchld_source) {
|
||||||
wl_event_source_remove(sigchld_source);
|
wl_event_source_remove(sigchld_source);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define CG_CONFIG_H
|
#define CG_CONFIG_H
|
||||||
|
|
||||||
#mesondefine CAGE_HAS_XWAYLAND
|
#mesondefine CAGE_HAS_XWAYLAND
|
||||||
|
#mesondefine CAGE_HAS_SYSTEMD
|
||||||
|
|
||||||
#mesondefine CAGE_VERSION
|
#mesondefine CAGE_VERSION
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ wlroots = dependency('wlroots-0.19', fallback: ['wlroots', 'wlroots'])
|
||||||
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
|
wayland_protos = dependency('wayland-protocols', version: '>=1.14')
|
||||||
wayland_server = dependency('wayland-server')
|
wayland_server = dependency('wayland-server')
|
||||||
xkbcommon = dependency('xkbcommon')
|
xkbcommon = dependency('xkbcommon')
|
||||||
|
systemd = dependency('libsystemd', required: get_option('systemd'))
|
||||||
math = cc.find_library('m')
|
math = cc.find_library('m')
|
||||||
|
|
||||||
wl_protocol_dir = wayland_protos.get_variable('pkgdatadir')
|
wl_protocol_dir = wayland_protos.get_variable('pkgdatadir')
|
||||||
|
|
@ -82,6 +83,7 @@ endif
|
||||||
|
|
||||||
conf_data = configuration_data()
|
conf_data = configuration_data()
|
||||||
conf_data.set10('CAGE_HAS_XWAYLAND', have_xwayland)
|
conf_data.set10('CAGE_HAS_XWAYLAND', have_xwayland)
|
||||||
|
conf_data.set10('CAGE_HAS_SYSTEMD', systemd.found())
|
||||||
conf_data.set_quoted('CAGE_VERSION', version)
|
conf_data.set_quoted('CAGE_VERSION', version)
|
||||||
|
|
||||||
scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-pages'))
|
scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-pages'))
|
||||||
|
|
@ -136,6 +138,10 @@ if conf_data.get('CAGE_HAS_XWAYLAND', 0) == 1
|
||||||
cage_headers += 'xwayland.h'
|
cage_headers += 'xwayland.h'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if conf_data.get('CAGE_HAS_SYSTEMD', 0) == 1
|
||||||
|
cage_sources += 'notify_systemd.c'
|
||||||
|
endif
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
meson.project_name(),
|
meson.project_name(),
|
||||||
cage_sources + cage_headers,
|
cage_sources + cage_headers,
|
||||||
|
|
@ -144,6 +150,7 @@ executable(
|
||||||
wayland_server,
|
wayland_server,
|
||||||
wlroots,
|
wlroots,
|
||||||
xkbcommon,
|
xkbcommon,
|
||||||
|
systemd,
|
||||||
math,
|
math,
|
||||||
],
|
],
|
||||||
install: true,
|
install: true,
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
|
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
|
||||||
|
option('systemd', type: 'feature', value: 'disabled', description: 'Notify status to systemd')
|
||||||
|
|
|
||||||
24
notify.h
Normal file
24
notify.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef CG_NOTIFY_H
|
||||||
|
#define CG_NOTIFY_H
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#define CAGE_ALIVE_PERIOD_MS (20000)
|
||||||
|
|
||||||
|
enum cg_notify_state {
|
||||||
|
CAGE_READY,
|
||||||
|
CAGE_ALIVE,
|
||||||
|
CAGE_STOPPING,
|
||||||
|
};
|
||||||
|
|
||||||
|
#if !CAGE_HAS_SYSTEMD
|
||||||
|
static inline void
|
||||||
|
notify_set_state(enum cg_notify_state state)
|
||||||
|
{
|
||||||
|
/* Nothing */
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void notify_set_state(enum cg_notify_state state);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
33
notify_systemd.c
Normal file
33
notify_systemd.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Cage: A Wayland kiosk.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018-2020 Jente Hidskes
|
||||||
|
*
|
||||||
|
* See the LICENSE file accompanying this file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <systemd/sd-daemon.h>
|
||||||
|
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_set_state(enum cg_notify_state state)
|
||||||
|
{
|
||||||
|
const char *sd_state;
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case CAGE_READY:
|
||||||
|
sd_state = "READY=1";
|
||||||
|
break;
|
||||||
|
case CAGE_ALIVE:
|
||||||
|
sd_state = "WATCHDOG=1";
|
||||||
|
break;
|
||||||
|
case CAGE_STOPPING:
|
||||||
|
sd_state = "STOPPING=1";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sd_notify(0, sd_state);
|
||||||
|
}
|
||||||
1
server.h
1
server.h
|
|
@ -75,6 +75,7 @@ struct cg_server {
|
||||||
bool return_app_code;
|
bool return_app_code;
|
||||||
bool terminated;
|
bool terminated;
|
||||||
enum wlr_log_importance log_level;
|
enum wlr_log_importance log_level;
|
||||||
|
struct wl_event_source *alive_source;
|
||||||
};
|
};
|
||||||
|
|
||||||
void server_terminate(struct cg_server *server);
|
void server_terminate(struct cg_server *server);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue