compositor-drm: Fix vt switching

Don't take input or render while switched away, drop and set master correctly.
dev
Kristian Høgsberg 14 years ago
parent 6c709a3e4f
commit 9396fc515b
  1. 22
      compositor/compositor-drm.c
  2. 9
      compositor/compositor.h
  3. 8
      compositor/tty.c

@ -627,6 +627,26 @@ drm_destroy(struct wlsc_compositor *ec)
free(d);
}
static void
vt_func(struct wlsc_compositor *compositor, int event)
{
struct drm_compositor *ec = (struct drm_compositor *) compositor;
switch (event) {
case TTY_ENTER_VT:
compositor->focus = 1;
drmSetMaster(ec->drm.fd);
compositor->state = WLSC_COMPOSITOR_ACTIVE;
wlsc_compositor_damage_all(compositor);
break;
case TTY_LEAVE_VT:
compositor->focus = 0;
compositor->state = WLSC_COMPOSITOR_SLEEPING;
drmDropMaster(ec->drm.fd);
break;
};
}
static struct wlsc_compositor *
drm_compositor_create(struct wl_display *display, int connector)
{
@ -699,7 +719,7 @@ drm_compositor_create(struct wl_display *display, int connector)
ec->drm_source =
wl_event_loop_add_fd(loop, ec->drm.fd,
WL_EVENT_READABLE, on_drm_input, ec);
ec->tty = tty_create(&ec->base);
ec->tty = tty_create(&ec->base, vt_func);
ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
if (ec->udev_monitor == NULL) {

@ -341,8 +341,15 @@ wlsc_switcher_init(struct wlsc_compositor *compositor);
void
evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
enum {
TTY_ENTER_VT,
TTY_LEAVE_VT
};
typedef void (*tty_vt_func_t)(struct wlsc_compositor *compositor, int event);
struct tty *
tty_create(struct wlsc_compositor *compositor);
tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func);
void
tty_destroy(struct tty *tty);

@ -41,6 +41,7 @@ struct tty {
struct wl_event_source *input_source;
struct wl_event_source *enter_vt_source;
struct wl_event_source *leave_vt_source;
tty_vt_func_t vt_func;
};
static int on_enter_vt(int signal_number, void *data)
@ -48,7 +49,7 @@ static int on_enter_vt(int signal_number, void *data)
struct tty *tty = data;
int ret;
fprintf(stderr, "enter vt\n");
tty->vt_func(tty->compositor, TTY_ENTER_VT);
ioctl(tty->fd, VT_RELDISP, VT_ACKACQ);
ret = ioctl(tty->fd, KDSETMODE, KD_GRAPHICS);
@ -70,6 +71,8 @@ on_leave_vt(int signal_number, void *data)
fprintf(stderr,
"failed to set KD_TEXT mode on console: %m\n");
tty->vt_func(tty->compositor, TTY_LEAVE_VT);
return 1;
}
@ -86,7 +89,7 @@ on_tty_input(int fd, uint32_t mask, void *data)
}
struct tty *
tty_create(struct wlsc_compositor *compositor)
tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func)
{
struct termios raw_attributes;
struct vt_mode mode = { 0 };
@ -100,6 +103,7 @@ tty_create(struct wlsc_compositor *compositor)
memset(tty, 0, sizeof *tty);
tty->compositor = compositor;
tty->vt_func = vt_func;
tty->fd = open("/dev/tty0", O_RDWR | O_NOCTTY);
if (tty->fd <= 0) {
fprintf(stderr, "failed to open active tty: %m\n");

Loading…
Cancel
Save