The X11R4 and KDQUEMODE Challenge!

Peter M. Jansson petej at ssg0.pharmacia.com
Fri Nov 9 03:13:36 AEST 1990


After a lot of frustration and experimentation, I have been able to
figure out most of how the KDQUEMODE works  in AT&T SysV/386r3.2, but I
continue to have a problem.  The following test program works
correctly when invoked as:

	test -

but when invoked as:

	test

fails to see mouse input.  The program takes a single optional argument which
is the name of a file to use as the controlling terminal.  If you
supply "-" as the name of the file, the program uses stdin.  If you
supply no argument, the program allocates a new virtual terminal to
use.

This program reports the keyboard and mouse events as supplied by the
KDQUEMODE queue.  It exits upon the release of the "Q" key, or 30
seconds.

As long as the program is invoked as "test -", keyboard and mouse
events are reported as I expect.  When the program must open another
virtual terminal, the keyboard events are properly reported, but not
the mouse events.

Can someone PLEASE PLEASE PLEASE tell me the magic to make the mouse
events always happen?

The motivation for figuring this out is to get the X11R4 server
working on Intel and AT&T *Xes.

Replies via email welcomed.

	Pete. (petej at pharmacia.com)

-----------------Program test.c (Creative name, eh?) follows:-----------
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/at_ansi.h>
#include <sys/kd.h>
#include <sys/vt.h>
#include <sys/xque.h>
#include <fcntl.h>

#define KD_QSIZE	100
#define KB_SIG	SIGPOLL

int fd;
int mouse_fd;
int done = 0;

struct kd_quemode myq;
xqEventQueue *eq_ptr;

int alarm_handler();
int sig_handler();

main(argc, argv)
int argc;
char *argv[];
{
    int n;
    int ttyno;
    char vtname[20];
    int tmp_fd;

    if ((mouse_fd = open("/dev/mouse", O_RDWR)) < 0)
    {
	perror("/dev/mouse");
	exit(-1);
    }
    if (argc == 2)
	if (strcmp(argv[1], "-"))
	    fd = open(argv[1], O_RDWR);
	else
	    fd = 0;
    else
    {
	tmp_fd = open("/dev/console", O_RDWR);
	ioctl(tmp_fd, VT_OPENQRY, &ttyno);
	close(tmp_fd);
	sprintf(vtname, "/dev/vt%02d", ttyno);
	fd = open(vtname, O_RDWR);
	if (fd < 0)
	{
	    perror(vtname);
	    exit(-1);
	}
	printf("%s open on %d\n", vtname, fd);
    }
    myq.qsize = KD_QSIZE;
    myq.signo = KB_SIG;
    signal(SIGALRM, alarm_handler);
    alarm(30);
    signal(KB_SIG, sig_handler);
    ioctl(fd, KDQUEMODE, NULL);
    n = ioctl(fd, KDQUEMODE, &myq);
    if (n < 0)
    {
	perror("KDQUEMODE");
	exit(-1);
    }
    eq_ptr = (xqEventQueue *) myq.qaddr;
    while (!done)
    {
	prq(eq_ptr);
	if (!done)
	{
	    eq_ptr->xq_sigenable = 1;
	    pause();
	    eq_ptr->xq_sigenable = 0;
	}
    }
    ioctl(fd, KDQUEMODE, NULL);
}

prq(qaddr)
xqEventQueue *qaddr;
{
    xqEvent *ev_ptr;
    int i;
    
    ev_ptr = &qaddr->xq_events[0] + qaddr->xq_head;
    while (qaddr->xq_head != qaddr->xq_tail)
    {
	switch (ev_ptr->xq_type)
	{
	  case XQ_BUTTON:
	    printf("%03d: Mouse button: %d\n", qaddr->xq_head,
		   ev_ptr->xq_code);
	    break;
	  case XQ_MOTION:
	    printf("%03d: Mouse motion: x=%d, y=%d, button=%d\n",
		   qaddr->xq_head, ev_ptr->xq_x, ev_ptr->xq_y,
		   ev_ptr->xq_code);
	    break;
	  case XQ_KEY:
	    done = ev_ptr->xq_code == 0x90;
	    printf("%03d: Key %s: %02x\n", qaddr->xq_head,
		   ev_ptr->xq_code & 0x80 ? "Up" : "Dn",
		   ev_ptr->xq_code );
	    break;
	}
	ev_ptr++;
	qaddr->xq_head++;
	if (qaddr->xq_head >= qaddr->xq_size)
	{
	    ev_ptr = &qaddr->xq_events[0];
	    qaddr->xq_head = 0;
	}
    }
}

alarm_handler()
{
    ioctl(fd, KDQUEMODE, NULL);
    close(mouse_fd);
    close(0);
    exit(-1);
}

sig_handler()
{
    signal(KB_SIG, sig_handler);
}



More information about the Comp.unix.sysv386 mailing list