compositor: Generalize VT switching as a session_signal

Instead of a callback from the tty module, we now have a compositor level
signal that fires when our session is activated or deactivated.
parent 05ad1e4e
......@@ -84,6 +84,7 @@ struct drm_compositor {
uint32_t crtc_allocator;
uint32_t connector_allocator;
struct tty *tty;
struct wl_listener session_listener;
/* we need these parameters in order to not fail drmModeAddFB2()
* due to out of bounds dimensions, and then mistakenly set
......@@ -2307,15 +2308,15 @@ drm_compositor_set_modes(struct drm_compositor *compositor)
}
static void
vt_func(struct weston_compositor *compositor, int event)
session_notify(struct wl_listener *listener, void *data)
{
struct drm_compositor *ec = (struct drm_compositor *) compositor;
struct weston_compositor *compositor = data;
struct drm_compositor *ec = data;
struct drm_sprite *sprite;
struct drm_output *output;
switch (event) {
case TTY_ENTER_VT:
weston_log("entering VT\n");
if (ec->base.session_active) {
weston_log("activating session\n");
compositor->focus = 1;
if (weston_launcher_drm_set_master(ec->base.launcher,
ec->drm.fd, 1)) {
......@@ -2326,9 +2327,8 @@ vt_func(struct weston_compositor *compositor, int event)
drm_compositor_set_modes(ec);
weston_compositor_damage_all(compositor);
udev_input_enable(&ec->input, ec->udev);
break;
case TTY_LEAVE_VT:
weston_log("leaving VT\n");
} else {
weston_log("deactivating session\n");
udev_input_disable(&ec->input);
compositor->focus = 0;
......@@ -2360,8 +2360,6 @@ vt_func(struct weston_compositor *compositor, int event)
if (weston_launcher_drm_set_master(ec->base.launcher,
ec->drm.fd, 0) < 0)
weston_log("failed to drop master: %m\n");
break;
};
}
......@@ -2587,7 +2585,9 @@ drm_compositor_create(struct wl_display *display,
}
ec->base.wl_display = display;
ec->tty = tty_create(&ec->base, vt_func, tty);
ec->session_listener.notify = session_notify;
wl_signal_add(&ec->base.session_signal, &ec->session_listener);
ec->tty = tty_create(&ec->base, tty);
if (!ec->tty) {
weston_log("failed to initialize tty\n");
goto err_udev;
......
......@@ -53,6 +53,7 @@ struct fbdev_compositor {
struct tty *tty;
struct udev_input input;
int use_pixman;
struct wl_listener session_listener;
};
struct fbdev_screeninfo {
......@@ -804,13 +805,12 @@ fbdev_compositor_destroy(struct weston_compositor *base)
}
static void
vt_func(struct weston_compositor *base, int event)
session_notify(struct wl_listener *listener, void *data)
{
struct fbdev_compositor *compositor = to_fbdev_compositor(base);
struct fbdev_compositor *compositor = data;
struct weston_output *output;
switch (event) {
case TTY_ENTER_VT:
if (compositor->base.session_active) {
weston_log("entering VT\n");
compositor->base.focus = 1;
compositor->base.state = compositor->prev_state;
......@@ -822,8 +822,7 @@ vt_func(struct weston_compositor *base, int event)
weston_compositor_damage_all(&compositor->base);
udev_input_enable(&compositor->input, compositor->udev);
break;
case TTY_LEAVE_VT:
} else {
weston_log("leaving VT\n");
udev_input_disable(&compositor->input);
......@@ -846,8 +845,6 @@ vt_func(struct weston_compositor *base, int event)
&compositor->base.output_list, link) {
output->repaint_needed = 0;
}
break;
};
}
......@@ -901,7 +898,10 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
}
/* Set up the TTY. */
compositor->tty = tty_create(&compositor->base, vt_func, param->tty);
compositor->session_listener.notify = session_notify;
wl_signal_add(&compositor->base.session_signal,
&compositor->session_listener);
compositor->tty = tty_create(&compositor->base, param->tty);
if (!compositor->tty) {
weston_log("Failed to initialize tty.\n");
goto out_udev;
......
......@@ -87,6 +87,7 @@ struct rpi_compositor {
struct udev *udev;
struct tty *tty;
struct wl_listener session_listener;
int single_buffer;
};
......@@ -662,15 +663,14 @@ rpi_compositor_destroy(struct weston_compositor *base)
}
static void
vt_func(struct weston_compositor *base, int event)
session_notify(struct wl_listener *listener, void *data)
{
struct rpi_compositor *compositor = to_rpi_compositor(base);
struct rpi_compositor *compositor = data;
struct weston_seat *seat;
struct weston_output *output;
switch (event) {
case TTY_ENTER_VT:
weston_log("entering VT\n");
if (compositor->base.session_active) {
weston_log("activating session\n");
compositor->base.focus = 1;
compositor->base.state = compositor->prev_state;
weston_compositor_damage_all(&compositor->base);
......@@ -678,9 +678,8 @@ vt_func(struct weston_compositor *base, int event)
evdev_add_devices(compositor->udev, seat);
evdev_enable_udev_monitor(compositor->udev, seat);
}
break;
case TTY_LEAVE_VT:
weston_log("leaving VT\n");
} else {
weston_log("deactivating session\n");
wl_list_for_each(seat, &compositor->base.seat_list, link) {
evdev_disable_udev_monitor(seat);
evdev_remove_devices(seat);
......@@ -702,8 +701,6 @@ vt_func(struct weston_compositor *base, int event)
&compositor->base.output_list, link) {
output->repaint_needed = 0;
}
break;
};
}
......@@ -754,7 +751,10 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
goto out_compositor;
}
compositor->tty = tty_create(&compositor->base, vt_func, param->tty);
compositor->session_listener.notify = session_notify;
wl_signal_add(&compositor->base.session_signal,
&compositor ->session_listener);
compositor->tty = tty_create(&compositor->base, param->tty);
if (!compositor->tty) {
weston_log("Failed to initialize tty.\n");
goto out_udev;
......
......@@ -2908,6 +2908,8 @@ weston_compositor_init(struct weston_compositor *ec,
wl_signal_init(&ec->update_input_panel_signal);
wl_signal_init(&ec->seat_created_signal);
wl_signal_init(&ec->output_created_signal);
wl_signal_init(&ec->session_signal);
ec->session_active = 1;
ec->output_id_pool = 0;
......
......@@ -556,6 +556,9 @@ struct weston_compositor {
struct wl_event_loop *input_loop;
struct wl_event_source *input_loop_source;
struct wl_signal session_signal;
int session_active;
struct weston_layer fade_layer;
struct weston_layer cursor_layer;
......@@ -1139,11 +1142,8 @@ enum {
TTY_LEAVE_VT
};
typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
struct tty *
tty_create(struct weston_compositor *compositor,
tty_vt_func_t vt_func, int tty_nr);
tty_create(struct weston_compositor *compositor, int tty_nr);
void
tty_destroy(struct tty *tty);
......
......@@ -50,25 +50,28 @@ struct tty {
struct wl_event_source *input_source;
struct wl_event_source *vt_source;
tty_vt_func_t vt_func;
int vt, starting_vt, has_vt;
int vt, starting_vt;
int kb_mode;
};
static int vt_handler(int signal_number, void *data)
{
struct tty *tty = data;
struct weston_compositor *compositor = tty->compositor;
if (tty->has_vt) {
tty->vt_func(tty->compositor, TTY_LEAVE_VT);
tty->has_vt = 0;
if (compositor->session_active) {
compositor->session_active = 0;
wl_signal_emit(&tty->compositor->session_signal,
tty->compositor);
ioctl(tty->fd, VT_RELDISP, 1);
} else {
ioctl(tty->fd, VT_RELDISP, VT_ACKACQ);
tty->vt_func(tty->compositor, TTY_ENTER_VT);
tty->has_vt = 1;
compositor->session_active = 1;
wl_signal_emit(&tty->compositor->session_signal,
tty->compositor);
}
return 1;
......@@ -120,8 +123,7 @@ tty_activate_vt(struct tty *tty, int vt)
}
struct tty *
tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
int tty_nr)
tty_create(struct weston_compositor *compositor, int tty_nr)
{
struct termios raw_attributes;
struct vt_mode mode = { 0 };
......@@ -137,7 +139,6 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
return NULL;
tty->compositor = compositor;
tty->vt_func = vt_func;
tty->fd = weston_environment_get_fd("WESTON_TTY_FD");
if (tty->fd < 0)
......@@ -218,7 +219,6 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
goto err_kdkbmode;
}
tty->has_vt = 1;
mode.mode = VT_PROCESS;
mode.relsig = SIGUSR1;
mode.acqsig = SIGUSR1;
......@@ -271,7 +271,7 @@ void tty_reset(struct tty *tty)
if (ioctl(tty->fd, VT_SETMODE, &mode) < 0)
weston_log("could not reset vt handling\n");
if (tty->has_vt && tty->vt != tty->starting_vt) {
if (tty->compositor->session_active && tty->vt != tty->starting_vt) {
ioctl(tty->fd, VT_ACTIVATE, tty->starting_vt);
ioctl(tty->fd, VT_WAITACTIVE, tty->starting_vt);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment