compositor: Use a virtual destructor when shutting down
Backend can now rely on their destroy function getting called on shutdown, so reset tty etc there instead of handling SIGTERM twice.
This commit is contained in:
parent
50dc6989b8
commit
caa6442556
|
@ -42,9 +42,7 @@ struct drm_compositor {
|
|||
struct udev *udev;
|
||||
struct wl_event_source *drm_source;
|
||||
|
||||
struct wl_event_source *term_signal_source;
|
||||
|
||||
/* tty handling state */
|
||||
/* tty handling state */
|
||||
int tty_fd;
|
||||
uint32_t vt_active : 1;
|
||||
|
||||
|
@ -559,16 +557,6 @@ on_tty_input(int fd, uint32_t mask, void *data)
|
|||
tcflush(ec->tty_fd, TCIFLUSH);
|
||||
}
|
||||
|
||||
static void on_term_signal(int signal_number, void *data)
|
||||
{
|
||||
struct drm_compositor *ec = data;
|
||||
|
||||
if (tcsetattr(ec->tty_fd, TCSANOW, &ec->terminal_attributes) < 0)
|
||||
fprintf(stderr, "could not restore terminal to canonical mode\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int setup_tty(struct drm_compositor *ec, struct wl_event_loop *loop)
|
||||
{
|
||||
struct termios raw_attributes;
|
||||
|
@ -596,9 +584,6 @@ static int setup_tty(struct drm_compositor *ec, struct wl_event_loop *loop)
|
|||
if (tcsetattr(ec->tty_fd, TCSANOW, &raw_attributes) < 0)
|
||||
fprintf(stderr, "could not put terminal into raw mode: %m\n");
|
||||
|
||||
ec->term_signal_source =
|
||||
wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, ec);
|
||||
|
||||
ec->tty_input_source =
|
||||
wl_event_loop_add_fd(loop, ec->tty_fd,
|
||||
WL_EVENT_READABLE, on_tty_input, ec);
|
||||
|
@ -631,6 +616,18 @@ drm_authenticate(struct wlsc_compositor *c, uint32_t id)
|
|||
return drmAuthMagic(ec->base.drm.fd, id);
|
||||
}
|
||||
|
||||
static void
|
||||
drm_destroy(struct wlsc_compositor *ec)
|
||||
{
|
||||
struct drm_compositor *d = (struct drm_compositor *) ec;
|
||||
|
||||
if (tcsetattr(d->tty_fd, TCSANOW, &d->terminal_attributes) < 0)
|
||||
fprintf(stderr,
|
||||
"could not restore terminal to canonical mode\n");
|
||||
|
||||
free(ec);
|
||||
}
|
||||
|
||||
struct wlsc_compositor *
|
||||
drm_compositor_create(struct wl_display *display, int connector)
|
||||
{
|
||||
|
@ -691,6 +688,7 @@ drm_compositor_create(struct wl_display *display, int connector)
|
|||
wl_event_loop_add_fd(loop, ec->base.drm.fd,
|
||||
WL_EVENT_READABLE, on_drm_input, ec);
|
||||
setup_tty(ec, loop);
|
||||
ec->base.destroy = drm_destroy;
|
||||
ec->base.authenticate = drm_authenticate;
|
||||
ec->base.present = drm_compositor_present;
|
||||
ec->base.focus = 1;
|
||||
|
|
|
@ -507,6 +507,12 @@ wayland_compositor_handle_event(int fd, uint32_t mask, void *data)
|
|||
wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE);
|
||||
}
|
||||
|
||||
static void
|
||||
wayland_destroy(struct wlsc_compositor *ec)
|
||||
{
|
||||
free(ec);
|
||||
}
|
||||
|
||||
struct wlsc_compositor *
|
||||
wayland_compositor_create(struct wl_display *display, int width, int height)
|
||||
{
|
||||
|
@ -556,6 +562,7 @@ wayland_compositor_create(struct wl_display *display, int width, int height)
|
|||
if (c->parent.wl_source == NULL)
|
||||
return NULL;
|
||||
|
||||
c->base.destroy = wayland_destroy;
|
||||
c->base.authenticate = wayland_authenticate;
|
||||
c->base.present = wayland_compositor_present;
|
||||
|
||||
|
|
|
@ -643,6 +643,12 @@ x11_authenticate(struct wlsc_compositor *c, uint32_t id)
|
|||
return dri2_authenticate((struct x11_compositor *) c, id);
|
||||
}
|
||||
|
||||
static void
|
||||
x11_destroy(struct wlsc_compositor *ec)
|
||||
{
|
||||
free(ec);
|
||||
}
|
||||
|
||||
struct wlsc_compositor *
|
||||
x11_compositor_create(struct wl_display *display, int width, int height)
|
||||
{
|
||||
|
@ -686,6 +692,7 @@ x11_compositor_create(struct wl_display *display, int width, int height)
|
|||
WL_EVENT_READABLE,
|
||||
x11_compositor_handle_event, c);
|
||||
|
||||
c->base.destroy = x11_destroy;
|
||||
c->base.authenticate = x11_authenticate;
|
||||
c->base.present = x11_compositor_present;
|
||||
|
||||
|
|
|
@ -1452,5 +1452,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
wl_display_destroy(display);
|
||||
|
||||
ec->destroy(ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ struct wlsc_compositor {
|
|||
|
||||
uint32_t focus;
|
||||
|
||||
void (*destroy)(struct wlsc_compositor *ec);
|
||||
int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
|
||||
void (*present)(struct wlsc_compositor *c);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue