📄 x_threebut.c
字号:
/* $Header: /host/kaukau/disk2/X11R5/R5-hp300/mit/server/ddx/hpbsd/input/RCS/x_threebut.c,v 1.1 1992/09/30 03:14:10 root Exp $ *//******************************************************************* ** ** ********************************************************* ** * ** * File: ddx/hp/hp/x_threebut.c ** * ** * Contents: Routines for processing button presses and ** * emulating extra buttons when using HIL and serial ** * pointing devices. ** * ** * Created: 4/28/88 ** * ** * Last Change: 06/07/91 ** * ** * Last Release: 8.0 ** * ** * Revision: A.01.00 ** * ** * Author: --gms ** * ** * Copyright: (c) 1988 Hewlett-Packard Company ** * ** ********************************************************* ** ********************************************************************//********************************************************Copyright (c) 1988 by Hewlett-Packard CompanyCopyright (c) 1988 by the Massachusetts Institute of TechnologyPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Hewlett-Packard or M.I.T. not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.********************************************************/#define NEED_EVENTS#include <sys/types.h>#include <stdio.h>#if defined(__hp_osf) || defined(__apollo) || defined(hp9000)#include <sys/time.h>#else#include <time.h>#endif#ifdef __hp_osf#include <hp/hilioctl.h>#endif#include "X.h"#include "Xproto.h"#include "inputstr.h"#include "hildef.h"#include "XHPproto.h"#include "x_serialdrv.h"#define B1 0x01#define B2 0x02#define B3 0x04#define B4 0x08#define one_button_down(s) ((s==B1 || s==B2 || s==B3 || s==B4) ? 1 : 0)extern u_char buf[];extern u_char *pkt_ptr;extern int pending_index;extern int pending_bytes;extern HPInputDevice *hpPointer;extern int DeviceButtonPress, DeviceButtonRelease;extern InputInfo inputInfo;Bool button_latch_enabled = FALSE;u_char *button_map;u_char identity_map[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};u_char swapped_map1[] = {0,2,1,3,4,5,6,7,8,9,10,11,12,13,14,15};HPInputDevice *bd;struct dev_info *devinfo;#if defined(__hpux) || defined(__hp_osf) || defined(hp9000) struct timeval wait_time = {0, 100000}; /* wait 1/10 second */#endif /* __hpux */static int next_device_state ();static void generate_buttons (), put_button_event ();static void look_for_next ();/************************************************************************* * * This routine processes buttons from all input devices. * Devices with 2 buttons emulate a third by pressing both. * Devices with 3 buttons emulate 5 buttons by pressing two buttons at once. * Button chording is enabled by default for two button mice, disabled by * default for devices with three or more buttons. * This can be overridden via the X*pointerkeys file. * */voidprocess_button (ev, dev, hil_info, code, num_buttons) xEvent *ev; DeviceIntPtr dev; struct dev_info *hil_info; u_char code; u_char num_buttons; { int old_state; int curstate; extern u_char button_chording; if (dev==inputInfo.pointer) bd = hpPointer; /* logical device is X pointer */ else bd = hil_info->hil_dev; old_state = bd->button_state; if (num_buttons == 2 || num_buttons == 4) button_map = swapped_map1; else button_map = identity_map; devinfo = hil_info; curstate = next_device_state (dev, ev, code); if (curstate == ILLEGAL) { deallocate_event(ev); return; } bd->button_state = curstate; if (old_state == 0 && one_button_down(curstate) && ((num_buttons == 2 && button_chording != CHORDING_OFF) || button_chording == CHORDING_ON)) look_for_next (&ev, dev, hil_info, num_buttons, &code); put_button_event (dev, ev, hil_info, bd, code); }/*********************************************************************** * * look_for_next () * * If button chording is enabled, we look for a second button press within * 100ms of the first. * */#define CORE_EVENT 0 #define EXTENSION_EVENT 1 #define FIRST_EXTENSION_EVENT 64#define MAXNAMLEN 255#define MOTION_BITS 3#define NONDATA_BYTES 7static voidlook_for_next (ev, dev, hil_info, num_buttons, code) xEvent **ev; DeviceIntPtr dev; struct dev_info *hil_info; int num_buttons; u_char *code; { extern u_char button_latching; extern int data_cnt; u_char nxt_button; int i, curstate; int button_ds; /* file descriptor of device. */ xEvent *format_ev ();#ifdef __hp_osf extern HPInputDevice l_devs[MAX_LOGICAL_DEVS]; unsigned int curtime, start; char dev_name[MAXNAMLEN]; Bool evflag = FALSE; u_char *lbuf; extern HILQ *hil_qp; int j, head, tmp, index;#endif button_ds = hil_info->hil_dev->file_ds; if (pending_index<pending_bytes) /* already have next button */ nxt_button = hil_info->dev_data[pending_index++]; else {#if defined(__hp_osf) /* * OSF has a shared memory input events queue. We use select() to * wait 100ms, then check to see if a second button press is in the * queue. If we find another button event from the same device, we * remove it from the queue, otherwise we return. * */ head = hil_qp->hil_evqueue.head; lbuf = (u_char *) &hil_qp->hil_event[head].tstamp; start = ((*lbuf & 0x0ff) << 24) | ((*(lbuf+1) & 0x0ff) << 16) | ((*(lbuf+2) & 0x0ff) << 8) | ( *(lbuf+3) & 0x0ff); select (NULL,NULL,NULL,NULL, &wait_time); for (tmp = (hil_qp->hil_evqueue.head + 1) % hil_qp->hil_evqueue.size, curtime=start; tmp != hil_qp->hil_evqueue.tail && curtime < start + 10000; tmp = (tmp + 1) % hil_qp->hil_evqueue.size) { sprintf (dev_name, "/dev/hil%d", hil_qp->hil_event[tmp].dev); for (i=0; i<MAX_LOGICAL_DEVS; i++) if (strcmp (l_devs[i].dev_name, dev_name) == 0) break; if (i==MAX_LOGICAL_DEVS) FatalError ("Can't find input device %s\n",dev_name); lbuf = (u_char *) &hil_qp->hil_event[tmp].tstamp; curtime = ((*lbuf & 0x0ff) << 24) | ((*(lbuf+1) & 0x0ff) << 16) | ((*(lbuf+2) & 0x0ff) << 8) | ( *(lbuf+3) & 0x0ff); if (&l_devs[i] != hil_info->hil_dev) /* wrong device */ { continue; } if (!(hil_qp->hil_event[tmp].poll_hdr & SET1_KEY_MASK)) { continue; /* not a button event */ } if (! (hil_qp->hil_event[tmp].poll_hdr & MOTION_BITS)) index = 0; else if (l_devs[i].hil_header.flags & HIL_16_BITS) index = (hil_qp->hil_event[tmp].poll_hdr & MOTION_BITS) * 2; else index = hil_qp->hil_event[tmp].poll_hdr & MOTION_BITS; if (hil_qp->hil_event[tmp].dev_data[index] >= BUTTON_BASE && hil_qp->hil_event[tmp].dev_data[index] < PROXIMITY_IN) { hil_info->poll_hdr = hil_qp->hil_event[tmp].poll_hdr & HIL_POLL_HDR_BITS; pending_index = 0; pending_bytes = hil_qp->hil_event[tmp].size - NONDATA_BYTES; for (j=0; j < pending_bytes; j++) hil_info->dev_data[j] = hil_qp->hil_event[tmp].dev_data[j]; j = tmp; while (j > hil_qp->hil_evqueue.head) { hil_qp->hil_event[j] = hil_qp->hil_event[j-1]; j--; } hil_qp->hil_evqueue.head = (hil_qp->hil_evqueue.head + 1) % hil_qp->hil_evqueue.size; evflag = TRUE; break; } } if (!evflag) return;#endif /* __hp_osf */#if defined(__hpux) || defined(hp9000) /* * If data_cnt is > 0, the button has been read into a global buffer. * If not, select on the proper device and wait 100ms. * */ if (data_cnt != 0) { if (hil_info->hil_dev->hpflags & IS_SERIAL_DEVICE) { get_serial_event (hil_info); if (!(hil_info->poll_hdr & BUTTON_DATA)) return; hil_info->dev_data[pending_index] += BUTTON_BASE; } else { get_hil_event (button_ds, hil_info); if (!(hil_info->poll_hdr & SET1_KEY_MASK)) return; if (hil_info->poll_hdr & MOTION_MASK) { handle_motion_event (dev, hil_info->hil_dev, hil_info); hil_info->poll_hdr &= ~MOTION_MASK; } } } else { int mask = 1 << button_ds; if (select (button_ds+1, &mask, NULL, NULL, &wait_time) <= 0) return; else { pkt_ptr = buf; data_cnt = read (button_ds, buf, READ_SIZ); if (data_cnt <= 0) return; if (hil_info->hil_dev->hpflags & IS_SERIAL_DEVICE) { get_serial_event (hil_info);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -