⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x_hilinit.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
	    {	    for (j=0; j<numdev; j++)		{	        if ((d->dev_type==opendevs[j].type && 		    count[d->dev_type]==opendevs[j].pos) ||		    (opendevs[j].type == -1 &&		     strcmp (opendevs[j].path, d->dev_name) == 0))		    {		    d->hpflags |= OPEN_THIS_DEVICE;		    if (j==XKEYBOARD && hpKeyboard==NULL)			hpKeyboard = d;		    else if (j==XPOINTER && hpPointer==NULL)			hpPointer = d;		    else			d->hpflags |= MERGED_DEVICE;		    }		}	    count[d->dev_type]++;	    if (d->dev_type == MOUSE)		last_mouse = d;	    else if (d->dev_type == KEYBOARD)		last_keyboard = d;	    else if (d->x_type == KEYBOARD)		last_key_device = d;	    else if (d->x_type == MOUSE)		last_pointer = d;	    }	}/***************************************************************************** * * If the user didn't pick a keyboard and pointer, assign a default. * If present, defaults are the last keyboard and last mouse. * */    if (hpKeyboard==NULL)	{        if (last_keyboard != NULL)	    hpKeyboard = last_keyboard;	else if (last_key_device != NULL)	    hpKeyboard = last_key_device;	else	    FatalError ("Couldn't find a key device - X server terminating!\n");	hpKeyboard->hpflags |= OPEN_THIS_DEVICE;	hpKeyboard->hpflags &= ~MERGED_DEVICE;	}    if (hpPointer==NULL)	{        if (last_mouse != NULL)	    hpPointer = last_mouse;	else if (last_pointer != NULL)	    hpPointer = last_pointer;	else	    hpPointer = hpKeyboard;	hpPointer->hpflags |= OPEN_THIS_DEVICE;	hpPointer->hpflags &= ~MERGED_DEVICE;	}    if (hpPointer == hpKeyboard)	{	hpKeyboard->hpflags |= SECOND_LOGICAL_DEVICE;	l_devs[spare] = *hpKeyboard;	hpPointer = &l_devs[spare];	}/***************************************************************************** * * If tablet subsetting specified and the pointer is not a tablet, * force the last tablet (if there is one) to be the pointer.  * The tablet must also be accessible as an extension device. * */    if (tablet_width)	{	if (hpPointer->dev_type != TABLET)	    {				   	    for (i=MAX_LOGICAL_DEVS-1; i>=0; i--)	        if (l_devs[i].dev_type == TABLET)		    break;	    if (i>=0)		{	        hpPointer->hpflags &= ~OPEN_THIS_DEVICE;		hpPointer = &l_devs[i];	        hpPointer->hpflags |= OPEN_THIS_DEVICE;		l_devs[spare] = *hpPointer; /* will also be extension device */	        l_devs[spare].hpflags |= SECOND_LOGICAL_DEVICE;		}	    }	else	    {	    l_devs[spare] = *hpPointer; /* will also be an extension device */	    l_devs[spare].hpflags |= SECOND_LOGICAL_DEVICE;	    }	}/*********************************************************************** * * Now close all the devices that X was not instructed to use. * */    for (i=0; i<MAX_LOGICAL_DEVS; i++)	if (!(l_devs[i].hpflags & OPEN_THIS_DEVICE))	    close_device (&l_devs[i]);    }#endif /* __hpux *//*********************************************************************** * * Open the beeper device. * On s800 machines, this is /dev/hilkbd#, where # is 0...3. * On s300 and s700, this is /dev/rhil. * */#if defined(__hpux) || defined(hp9000)init_beeper()    {#if defined(__hp9000s300) || defined(__hp9000s700) || defined(hp300)    if ((beeper_fd = open(BEEPER_DEVICE,O_RDWR)) < 0) 	ErrorF ("Unable to open beeper device \"%s\".\n",BEEPER_DEVICE);#endif /*__hp9000s300 or __hp9000s700 */#if defined(__hp9000s800) && !defined(__hp9000s700)    int		len;    if (ldigit != '\0')	beeper_name[11] = ldigit;    else 	{        len = strlen (hpKeyboard->dev_name);	beeper_name[11] = hpKeyboard->dev_name[len-3];	}    if ((beeper_name[11] >= '0' && beeper_name[11] < '4') &&        (beeper_fd = open(beeper_name,O_RDWR)) < 0)	ErrorF ("Unable to open beeper device \"%s\".\n",beeper_name);#endif /*__hp9000s800 && !__hp9000s700 */    }#endif /* __hpux *//*********************************************************************** * * Initialize Domain input devices. * */#ifdef __apollostatic int init_apollo_devs (opendevs, numdev)    struct	opendevs opendevs [];    int		numdev;    {    if (!fdApollo)        fdApollo = MakeSMDStream();    strcpy (l_devs[0].dev_name, "Apollo_internal");    strcpy (l_devs[1].dev_name, "Apollo_internal");    l_devs[1].x_type = KEYBOARD;    l_devs[1].dev_type = KEYBOARD;    l_devs[1].hil_header.id = 0xdf;    l_devs[0].hil_header.num_keys = 113;    strcpy(l_devs[1].x_name,"FIRST_KEYBOARD");    l_devs[1].x_atom = MakeAtom ("KEYBOARD", 8, 0);    l_devs[1].file_ds = fdApollo;    l_devs[0].x_type = MOUSE;    l_devs[0].dev_type = MOUSE;    l_devs[0].hil_header.id = 0x68;    l_devs[0].hil_header.ax_num = 2;    l_devs[0].hil_header.p_button_count = 3;    l_devs[0].hil_header.v_button_count = 5;    l_devs[0].hil_header.size_x = screenInfo.screens[0]->width;    l_devs[0].hil_header.size_y = screenInfo.screens[0]->height;      strcpy(l_devs[0].x_name,"FIRST_MOUSE");    l_devs[0].x_atom = MakeAtom ("MOUSE", 5, 0);    l_devs[0].file_ds = fdApollo;    if (opendevs[XPOINTER].type == KEYBOARD)	{	l_devs[1].hpflags |= SECOND_LOGICAL_DEVICE;	l_devs[MAX_LOGICAL_DEVS-2] = l_devs[1];	l_devs[0].file_ds = -1;	hpPointer = &l_devs[MAX_LOGICAL_DEVS-2];	}    else if (hpPointer==NULL || open_device(hpPointer) < 0)	hpPointer = &l_devs[0];    else	{	l_devs[0].hil_header.id = 1;	l_devs[0].file_ds = -1;	}    if (hpKeyboard==NULL || open_device(hpKeyboard) < 0)	hpKeyboard = &l_devs[1];    }#endif /* __apollo *//**************************************************************************** * * open_device opens one of the input devices. * The dev_name is filled in by device_files(), or is the default. * If the open fails, it may be because the keyboard and pointer * are the same device, and the device is already open. * */open_device (d)    HPInputDevice	*d;    {    int		fd;#ifdef __apollo    if (!strcmp (d->dev_name, "Apollo_internal"))	fd = fdApollo;    else#endif /* __apollo */    fd = open (d->dev_name, O_RDWR | O_NDELAY);    if (fd < 0)         return (fd);    if (get_device_details (fd, d) < 0)	return (-1);    d->file_ds = fd;    BITSET(valid_inputs.input_mask, fd);    if (fd > valid_inputs.max_fd)	valid_inputs.max_fd = fd;#ifdef __hp_osf#ifdef SPECIAL_68K_OSF    if (d->dev_type != NULL_DEVICE &&        ioctl (d->file_ds, HILMAPQ, &hil_qd) < 0)	FatalError ("HILMAPQ failed for device %s\n",d->dev_name);#else    if (d->dev_type != NULL_DEVICE &&        ioctl (d->file_ds, HILMAPQ, &hil_qp->hil_evqueue.qnum) < 0)	{	FatalError ("HILMAPQ failed for device %s, file_ds=%d errno=%d\n",	    d->dev_name, d->file_ds, errno);	}#endif /* SPECIAL_68K_OSF */#endif /* __hp_osf */    return (fd);    }/**************************************************************************** * * Query the hil device for detailed information. * */static int get_device_details(file_ds, input_dev)    int file_ds;    HPInputDevice *input_dev;    {    int 	i, dev_status;    u_char	describe[11], iob;    struct	hil_desc_record		*hd;    int		hi_resol =0;    int 	lo_resol = 0;    int 	support_it = TRUE;#if defined(__hpux) || defined(__hp_osf) || defined(hp9000)    LatchKey(input_dev, CAPSCODE);    input_dev->led[NLOCK] = LockMask;    for (i=0; i<11; i++)	describe[i] = 0;    dev_status = ioctl (file_ds, HILID, &(describe[0]));    hd = &(input_dev->hil_header);    if (dev_status >= 0) 	{#ifdef hp9000	ioctl (file_ds, HILIOCHPUX, 0);#endif	hd->id  = describe[0];	if (hd->id >= 0xE0)			/* HP98203C - not supported */	    {	    close (file_ds);	    return (-1);	    }	else if (hd->id >= 0xA0 && hd->id < 0xC0) /* compressed keyboard      */	    {	    close (file_ds);	    return (-1);	    }	hd->flags = describe[1];	input_dev->hpflags |= DATA_IS_8_BITS;	hd->ax_num = (hd->flags & HIL_NUM_AXES);	/*	 *	 * if # of axes indicate it is a positional device	 * then gather resolution.		 * if 16 bits of information are reported, resolution is	 * in counts/ cm.  In this case, convert to counts/ meter.	 *	 */	if ( hd->ax_num) 	    {	    lo_resol =  describe[2];	    hi_resol =  describe[3];	    hd->resx = hd->resy = (hi_resol << 8) + lo_resol;	    if (hd->flags & HIL_16_BITS)		{		input_dev->hpflags |= DATA_IS_16_BITS;		hd->resx = hd->resy =  hd->resx * 100;		}	    /* If it is an absolute device, gather size */	    if (hd->flags & HIL_ABSOLUTE)		{		switch ( hd->ax_num) 		    {		    case 2:		        hd->size_y = (int)describe[6]|((int)describe[7] << 8);		    case 1:			 hd->size_x = (int)describe[4]|((int)describe[5] << 8);		    default:			 break;		    }		iob = describe[4 + hd->ax_num * 2];		}	    else		iob = describe[4];	    }	else 	    {	    iob = describe[2];	    hd->resx = hd->resy = 0;	    }		   	if (hd->flags & HIL_IOB)	    hd->iob=iob;	if (hd->iob & HILIOB_BUTTONS) 	   {	   hd->p_button_count = hd->iob & HILIOB_BUTTONS ;	   hd->v_button_count = hd->iob & HILIOB_BUTTONS ;	   /*	    * initialize structures for emulating 3 buttons	    * where we have 2, or 5 buttons where we have 3.	    */	    if (hd->p_button_count == 2)  	       hd->v_button_count = 3;  	    else if (hd->p_button_count == 3 || hd->p_button_count == 4)  	       hd->v_button_count = 5;  	   }        if (hd->iob & HAS_LEDS)	    {	    hd->num_leds = hd->iob & HILIOB_NPA;	    if (!hd->num_leds)	        hd->num_leds=1;	    }        get_device_type (input_dev, hd->id);	}    else	{	hd->size_x = hd->size_y = 0;	hd->ax_num = 2;	hd->p_button_count = 3;	hd->v_button_count = 3;	hd->min_kcode = 10;	hd->max_kcode = 135;	hd->num_keys = 109;	input_dev->hil_header.id = 0;        input_dev->dev_type = NULL_DEVICE;        input_dev->x_type = XOTHER;	strcpy (input_dev->x_name,"FIRST_NULL");	support_it = FALSE;	}#endif /* __hpux */    return ( support_it);    }/**************************************************************************** * * This routine determines the type of the input device. * dev_type is the actual type, x_type is what X considers it to be * (mouse or keyboard). * The 9-knob box and quadrature box have the same HIL id. * But if it doesn't have 3 axes, it's not a 9-knob box. * */get_device_type (dev, id)    HPInputDevice *dev;    int	id;    {    int		i;    int		dev_count;    for (i=0; devices[i].dev_type != NULL_DEVICE; i++)	if (id >= devices[i].lowid && id <= devices[i].highid)	    {    	    if (id == NINE_KNOB_ID && dev->hil_header.ax_num != 3)		i = QUAD_INDEX;	    dev->hil_header.min_kcode = devices[i].min_kcode;	    dev->hil_header.max_kcode = devices[i].max_kcode;	    dev->hil_header.num_keys = devices[i].num_keys;	    dev->dev_type = devices[i].dev_type;	    dev->x_type    = devices[i].x_type;	    dev_count = count [dev->dev_type];	    strcpy (dev->x_name, position[dev_count]);	    strcat (dev->x_name, "_");	    strcat (dev->x_name, devices[i].name);	    dev->x_atom = MakeAtom (devices[i].name, strlen(devices[i].name),0);	    break;	    }    }/**************************************************************************** * * This routine recalculates the device x_name. * The x_name is a string created by concatenating the device type and position. * The position may change if a device that was previously inaccessible * to X is made accessible. * */recalculate_x_name ()    {    int	i;    int	j;    for (i=0; i<NUM_DEV_TYPES; i++)	count[i] = 0;        for (i=0; i<MAX_LOGICAL_DEVS; i++)	for (j=0; j<MAX_LOGICAL_DEVS; j++)	    if (strcmp (l_devs[j].dev_name,"/dev/null") == 0)		continue;	    else if (strcmp (dev_names[i], l_devs[j].dev_name) == 0)		{		if (l_devs[j].file_ds != -1)		    {		    if (l_devs[j].hpflags & SECOND_LOGICAL_DEVICE)			continue;		    get_device_type (&l_devs[j], l_devs[j].hil_header.id);		    count [l_devs[j].dev_type]++;		    }		else if (open_device (&l_devs[j]) > 0)		    {		    count [l_devs[j].dev_type]++;		    close_device(&l_devs[j]);		    }		else 		    l_devs[j].x_name[0] = '\0';		break;		}    }/**************************************************************************** * * SetAutoRepeat (onoff) *  Enable or disable the auto repeat feature of the specified device. */static void SetAutoRepeat (d, onoff)    HPInputDevice	*d;    int onoff;    {#if defined(__hpux) || defined(__hp_osf) || defined(hp9000)    char ioctl_data[12];    int state = HILDKR;	    if (d->hpflags & IS_SERIAL_DEVICE)	return;    if (onoff)	state = d->repeat_rate;    if (d->file_ds != -1)	{	ioctl (d->file_ds, state, ioctl_data);	}#endif /*__hpux */    }/******************************************************************** * * If the file "/usr/lib/X11/X[display#]devices exists, this routine  * processes it. * It translates the strings in the file to a device type and relative * position on the HIL. * */struct	opendevs serial[MAX_DEVICES];static int device_files (fd, opendevs)    FILE	*fd;    struct	opendevs opendevs [];    {    char buf[MAXNAMLEN+1];    char devuse[MAXNAMLEN+1];    char path[MAXNAMLEN+1];    char pos[MAXNAMLEN+1];    char *fgets();    int	i;    int	other = XOTHER;    int	sother = XOTHER;    int parms;    while (fgets(buf,MAXNAMLEN+1,fd) != NULL)	{	buf[strlen(buf)-1] = '\0';	if (other == MAX_LOGICAL_DEVS)	    {	    ErrorF ("Too many X*devices entries. Ignoring \"%s\".\n",buf);	    continue;	    }	pos[0] = '\0';	path[0] = '\0';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -