compositor: choose tty from command line
authorTiago Vignatti <tiago.vignatti@intel.com>
Thu, 1 Sep 2011 19:58:17 +0000 (15:58 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 1 Sep 2011 20:07:07 +0000 (16:07 -0400)
This is a backend option, so you should use something like '-otty='.

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
compositor/compositor-drm.c
compositor/compositor-openwfd.c
compositor/compositor.h
compositor/tty.c

index e1e94bc..09e3dcc 100644 (file)
@@ -779,7 +779,7 @@ static const char default_seat[] = "seat0";
 
 static struct wlsc_compositor *
 drm_compositor_create(struct wl_display *display,
-                     int connector, const char *seat)
+                     int connector, const char *seat, int tty)
 {
        struct drm_compositor *ec;
        struct udev_enumerate *e;
@@ -856,7 +856,7 @@ drm_compositor_create(struct wl_display *display,
        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, vt_func);
+       ec->tty = tty_create(&ec->base, vt_func, tty);
 
        ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
        if (ec->udev_monitor == NULL) {
@@ -887,8 +887,9 @@ backend_init(struct wl_display *display, char *options)
        int connector = 0, i;
        const char *seat;
        char *p, *value;
+       int tty = 1;
 
-       static char * const tokens[] = { "connector", "seat", NULL };
+       static char * const tokens[] = { "connector", "seat", "tty", NULL };
 
        p = options;
        seat = default_seat;
@@ -900,8 +901,11 @@ backend_init(struct wl_display *display, char *options)
                case 1:
                        seat = value;
                        break;
+               case 2:
+                       tty = strtol(value, NULL, 0);
+                       break;
                }
        }
 
-       return drm_compositor_create(display, connector, seat);
+       return drm_compositor_create(display, connector, seat, tty);
 }
index 144e4ab..d275a60 100644 (file)
@@ -594,7 +594,7 @@ static const char default_seat[] = "seat0";
 
 static struct wlsc_compositor *
 wfd_compositor_create(struct wl_display *display,
-                     int connector, const char *seat)
+                     int connector, const char *seat, int tty)
 {
        struct wfd_compositor *ec;
        struct wl_event_loop *loop;
@@ -655,7 +655,7 @@ wfd_compositor_create(struct wl_display *display,
                wl_event_loop_add_fd(loop,
                                     wfdDeviceEventGetFD(ec->dev, ec->event),
                                     WL_EVENT_READABLE, on_wfd_event, ec);
-       ec->tty = tty_create(&ec->base, vt_func);
+       ec->tty = tty_create(&ec->base, vt_func, tty);
 
        return &ec->base;
 }
@@ -669,8 +669,9 @@ backend_init(struct wl_display *display, char *options)
        int connector = 0, i;
        const char *seat;
        char *p, *value;
+       int tty = 1;
 
-       static char * const tokens[] = { "connector", "seat", NULL };
+       static char * const tokens[] = { "connector", "seat", "tty", NULL };
        
        p = options;
        seat = default_seat;
@@ -682,8 +683,11 @@ backend_init(struct wl_display *display, char *options)
                case 1:
                        seat = value;
                        break;
+               case 2:
+                       tty = value;
+                       break;
                }
        }
 
-       return wfd_compositor_create(display, connector, seat);
+       return wfd_compositor_create(display, connector, seat, tty);
 }
index 6df15da..0efc873 100644 (file)
@@ -388,7 +388,8 @@ enum {
 typedef void (*tty_vt_func_t)(struct wlsc_compositor *compositor, int event);
 
 struct tty *
-tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func);
+tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func,
+          int tty_nr);
 
 void
 tty_destroy(struct tty *tty);
index e74f0eb..5ed921c 100644 (file)
@@ -89,22 +89,27 @@ on_tty_input(int fd, uint32_t mask, void *data)
 }
 
 struct tty *
-tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func)
+tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func,
+           int tty_nr)
 {
        struct termios raw_attributes;
        struct vt_mode mode = { 0 };
        int ret;
        struct tty *tty;
        struct wl_event_loop *loop;
+       char filename[16];
 
        tty = malloc(sizeof *tty);
        if (tty == NULL)
                return NULL;
 
+       snprintf(filename, sizeof filename, "/dev/tty%d", tty_nr);
+       fprintf(stderr, "compositor: using %s\n", filename);
+
        memset(tty, 0, sizeof *tty);
        tty->compositor = compositor;
        tty->vt_func = vt_func;
-       tty->fd = open("/dev/tty", O_RDWR | O_NOCTTY);
+       tty->fd = open(filename, O_RDWR | O_NOCTTY);
        if (tty->fd <= 0) {
                fprintf(stderr, "failed to open active tty: %m\n");
                return NULL;