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.
dev
Kristian Høgsberg 11 years ago
parent 05ad1e4e8a
commit 61741a293c
  1. 22
      src/compositor-drm.c
  2. 18
      src/compositor-fbdev.c
  3. 22
      src/compositor-rpi.c
  4. 2
      src/compositor.c
  5. 8
      src/compositor.h
  6. 24
      src/tty.c

@ -84,6 +84,7 @@ struct drm_compositor {
uint32_t crtc_allocator; uint32_t crtc_allocator;
uint32_t connector_allocator; uint32_t connector_allocator;
struct tty *tty; struct tty *tty;
struct wl_listener session_listener;
/* we need these parameters in order to not fail drmModeAddFB2() /* we need these parameters in order to not fail drmModeAddFB2()
* due to out of bounds dimensions, and then mistakenly set * due to out of bounds dimensions, and then mistakenly set
@ -2307,15 +2308,15 @@ drm_compositor_set_modes(struct drm_compositor *compositor)
} }
static void 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_sprite *sprite;
struct drm_output *output; struct drm_output *output;
switch (event) { if (ec->base.session_active) {
case TTY_ENTER_VT: weston_log("activating session\n");
weston_log("entering VT\n");
compositor->focus = 1; compositor->focus = 1;
if (weston_launcher_drm_set_master(ec->base.launcher, if (weston_launcher_drm_set_master(ec->base.launcher,
ec->drm.fd, 1)) { ec->drm.fd, 1)) {
@ -2326,9 +2327,8 @@ vt_func(struct weston_compositor *compositor, int event)
drm_compositor_set_modes(ec); drm_compositor_set_modes(ec);
weston_compositor_damage_all(compositor); weston_compositor_damage_all(compositor);
udev_input_enable(&ec->input, ec->udev); udev_input_enable(&ec->input, ec->udev);
break; } else {
case TTY_LEAVE_VT: weston_log("deactivating session\n");
weston_log("leaving VT\n");
udev_input_disable(&ec->input); udev_input_disable(&ec->input);
compositor->focus = 0; compositor->focus = 0;
@ -2360,8 +2360,6 @@ vt_func(struct weston_compositor *compositor, int event)
if (weston_launcher_drm_set_master(ec->base.launcher, if (weston_launcher_drm_set_master(ec->base.launcher,
ec->drm.fd, 0) < 0) ec->drm.fd, 0) < 0)
weston_log("failed to drop master: %m\n"); 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->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) { if (!ec->tty) {
weston_log("failed to initialize tty\n"); weston_log("failed to initialize tty\n");
goto err_udev; goto err_udev;

@ -53,6 +53,7 @@ struct fbdev_compositor {
struct tty *tty; struct tty *tty;
struct udev_input input; struct udev_input input;
int use_pixman; int use_pixman;
struct wl_listener session_listener;
}; };
struct fbdev_screeninfo { struct fbdev_screeninfo {
@ -804,13 +805,12 @@ fbdev_compositor_destroy(struct weston_compositor *base)
} }
static void 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; struct weston_output *output;
switch (event) { if (compositor->base.session_active) {
case TTY_ENTER_VT:
weston_log("entering VT\n"); weston_log("entering VT\n");
compositor->base.focus = 1; compositor->base.focus = 1;
compositor->base.state = compositor->prev_state; compositor->base.state = compositor->prev_state;
@ -822,8 +822,7 @@ vt_func(struct weston_compositor *base, int event)
weston_compositor_damage_all(&compositor->base); weston_compositor_damage_all(&compositor->base);
udev_input_enable(&compositor->input, compositor->udev); udev_input_enable(&compositor->input, compositor->udev);
break; } else {
case TTY_LEAVE_VT:
weston_log("leaving VT\n"); weston_log("leaving VT\n");
udev_input_disable(&compositor->input); udev_input_disable(&compositor->input);
@ -846,8 +845,6 @@ vt_func(struct weston_compositor *base, int event)
&compositor->base.output_list, link) { &compositor->base.output_list, link) {
output->repaint_needed = 0; output->repaint_needed = 0;
} }
break;
}; };
} }
@ -901,7 +898,10 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[],
} }
/* Set up the TTY. */ /* 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) { if (!compositor->tty) {
weston_log("Failed to initialize tty.\n"); weston_log("Failed to initialize tty.\n");
goto out_udev; goto out_udev;

@ -87,6 +87,7 @@ struct rpi_compositor {
struct udev *udev; struct udev *udev;
struct tty *tty; struct tty *tty;
struct wl_listener session_listener;
int single_buffer; int single_buffer;
}; };
@ -662,15 +663,14 @@ rpi_compositor_destroy(struct weston_compositor *base)
} }
static void 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_seat *seat;
struct weston_output *output; struct weston_output *output;
switch (event) { if (compositor->base.session_active) {
case TTY_ENTER_VT: weston_log("activating session\n");
weston_log("entering VT\n");
compositor->base.focus = 1; compositor->base.focus = 1;
compositor->base.state = compositor->prev_state; compositor->base.state = compositor->prev_state;
weston_compositor_damage_all(&compositor->base); 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_add_devices(compositor->udev, seat);
evdev_enable_udev_monitor(compositor->udev, seat); evdev_enable_udev_monitor(compositor->udev, seat);
} }
break; } else {
case TTY_LEAVE_VT: weston_log("deactivating session\n");
weston_log("leaving VT\n");
wl_list_for_each(seat, &compositor->base.seat_list, link) { wl_list_for_each(seat, &compositor->base.seat_list, link) {
evdev_disable_udev_monitor(seat); evdev_disable_udev_monitor(seat);
evdev_remove_devices(seat); evdev_remove_devices(seat);
@ -702,8 +701,6 @@ vt_func(struct weston_compositor *base, int event)
&compositor->base.output_list, link) { &compositor->base.output_list, link) {
output->repaint_needed = 0; output->repaint_needed = 0;
} }
break;
}; };
} }
@ -754,7 +751,10 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[],
goto out_compositor; 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) { if (!compositor->tty) {
weston_log("Failed to initialize tty.\n"); weston_log("Failed to initialize tty.\n");
goto out_udev; 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->update_input_panel_signal);
wl_signal_init(&ec->seat_created_signal); wl_signal_init(&ec->seat_created_signal);
wl_signal_init(&ec->output_created_signal); wl_signal_init(&ec->output_created_signal);
wl_signal_init(&ec->session_signal);
ec->session_active = 1;
ec->output_id_pool = 0; ec->output_id_pool = 0;

@ -556,6 +556,9 @@ struct weston_compositor {
struct wl_event_loop *input_loop; struct wl_event_loop *input_loop;
struct wl_event_source *input_loop_source; struct wl_event_source *input_loop_source;
struct wl_signal session_signal;
int session_active;
struct weston_layer fade_layer; struct weston_layer fade_layer;
struct weston_layer cursor_layer; struct weston_layer cursor_layer;
@ -1139,11 +1142,8 @@ enum {
TTY_LEAVE_VT TTY_LEAVE_VT
}; };
typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event);
struct tty * struct tty *
tty_create(struct weston_compositor *compositor, tty_create(struct weston_compositor *compositor, int tty_nr);
tty_vt_func_t vt_func, int tty_nr);
void void
tty_destroy(struct tty *tty); tty_destroy(struct tty *tty);

@ -50,25 +50,28 @@ struct tty {
struct wl_event_source *input_source; struct wl_event_source *input_source;
struct wl_event_source *vt_source; struct wl_event_source *vt_source;
tty_vt_func_t vt_func; int vt, starting_vt;
int vt, starting_vt, has_vt;
int kb_mode; int kb_mode;
}; };
static int vt_handler(int signal_number, void *data) static int vt_handler(int signal_number, void *data)
{ {
struct tty *tty = data; struct tty *tty = data;
struct weston_compositor *compositor = tty->compositor;
if (tty->has_vt) { if (compositor->session_active) {
tty->vt_func(tty->compositor, TTY_LEAVE_VT); compositor->session_active = 0;
tty->has_vt = 0; wl_signal_emit(&tty->compositor->session_signal,
tty->compositor);
ioctl(tty->fd, VT_RELDISP, 1); ioctl(tty->fd, VT_RELDISP, 1);
} else { } else {
ioctl(tty->fd, VT_RELDISP, VT_ACKACQ); ioctl(tty->fd, VT_RELDISP, VT_ACKACQ);
tty->vt_func(tty->compositor, TTY_ENTER_VT); compositor->session_active = 1;
tty->has_vt = 1; wl_signal_emit(&tty->compositor->session_signal,
tty->compositor);
} }
return 1; return 1;
@ -120,8 +123,7 @@ tty_activate_vt(struct tty *tty, int vt)
} }
struct tty * struct tty *
tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func, tty_create(struct weston_compositor *compositor, int tty_nr)
int tty_nr)
{ {
struct termios raw_attributes; struct termios raw_attributes;
struct vt_mode mode = { 0 }; struct vt_mode mode = { 0 };
@ -137,7 +139,6 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
return NULL; return NULL;
tty->compositor = compositor; tty->compositor = compositor;
tty->vt_func = vt_func;
tty->fd = weston_environment_get_fd("WESTON_TTY_FD"); tty->fd = weston_environment_get_fd("WESTON_TTY_FD");
if (tty->fd < 0) if (tty->fd < 0)
@ -218,7 +219,6 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
goto err_kdkbmode; goto err_kdkbmode;
} }
tty->has_vt = 1;
mode.mode = VT_PROCESS; mode.mode = VT_PROCESS;
mode.relsig = SIGUSR1; mode.relsig = SIGUSR1;
mode.acqsig = SIGUSR1; mode.acqsig = SIGUSR1;
@ -271,7 +271,7 @@ void tty_reset(struct tty *tty)
if (ioctl(tty->fd, VT_SETMODE, &mode) < 0) if (ioctl(tty->fd, VT_SETMODE, &mode) < 0)
weston_log("could not reset vt handling\n"); 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_ACTIVATE, tty->starting_vt);
ioctl(tty->fd, VT_WAITACTIVE, tty->starting_vt); ioctl(tty->fd, VT_WAITACTIVE, tty->starting_vt);
} }

Loading…
Cancel
Save