static char *rcsid_events_c
= "$Header: events.c,v 10.4 86/12/17 20:36:45 swick Exp $";
* The Sun X drivers are a product of Sun Microsystems, Inc. and are provided
* for unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify these drivers without charge, but are not authorized
* to license or distribute them to anyone else except as part of a product or
* program developed by the user.
* THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
* INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A
* PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE
* The Sun X Drivers are provided with no support and without any obligation
* on the part of Sun Microsystems, Inc. to assist in their use, correction,
* modification or enhancement.
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X
* DRIVERS OR ANY PART THEREOF.
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
* Mountain View, California 94043
static char sccsid
[] = "@(#)events.c 2.1 86/01/28 Copyright 1986 Sun Micro";
* Copyright (c) 1986 by Sun Microsystems, Inc.
* Up events on regular keys
#include "../X/vsinput.h"
#include <sunwindow/win_input.h>
#define event_is_ascii(e) (e->ie_code >= ASCII_FIRST && e->ie_code <= ASCII_LAST)
#define event_is_meta(e) (e->ie_code >= META_FIRST && e->ie_code <= META_LAST)
#define VSE_LEFT_BUTTON 0
#define VSE_MIDDLE_BUTTON 1
#define VSE_RIGHT_BUTTON 2
extern DEVICE
*CurrentDevice
;
extern unsigned state_mask
;
extern struct kiockey sunkeymap
[];
* Convert from a Sun event to an X event
/* Map the coordinates */
/* Map the time stamps */
xe
->vse_time
= (se
->ie_time
.tv_usec
/10000 + se
->ie_time
.tv_sec
);
xe
->vse_direction
= (win_inputposevent(se
) ? VSE_KBTDOWN
: VSE_KBTUP
);
/* Sort out the event codes */
if (se
->ie_code
>= VKEY_FIRSTSHIFT
&& se
->ie_code
<= VKEY_LASTSHIFT
) {
* this makes ie_code between 0 and 0200 inclusive.
se
->ie_code
-= VKEY_FIRSTSHIFT
;
key
= SHIFTKEYS
+ se
->ie_code
;
} else if (se
->ie_code
>= 0 && se
->ie_code
< 0200)
key
= sunkeymap
[se
->ie_code
].kio_entry
;
xe
->vse_device
= VSE_DKB
;
xe
->vse_type
= VSE_BUTTON
;
* First deal with special keycodes
* The static count is keeping track of how many
* keys I have down for the given function.
* Only need to do this for shift and meta.
* On an up event I decrease the count. If it is
* not the last one up then I convert to a down event
* which really won't do anything. I should ignore
* the event, but this works.
* At odd times the sun keyboard gets confused and I
* miss an UP event. This may get you stuck in
* shift mode. I assume there is only 2 shift keys
* and only two meta keys. If count ever goes above
* 2 I make it 2 again, assuming I have missed an up
* event. If you get stuck in shifted mode, just his
* both shift keys and you should be fixed.
if (win_inputposevent(se
)) {
xe
->vse_direction
= VSE_KBTDOWN
;
if (win_inputposevent(se
)) {
xe
->vse_direction
= VSE_KBTDOWN
;
kludgekey
= RightKeys
[key
&0xf];
kludgekey
= LeftKeys
[key
&0xf];
kludgekey
= TopKeys
[key
&0xf];
kludgekey
= BotKeys
[key
&0xf];
* Now deal with regular keys.
* Note, I look up the key in the shift/ctrl/caps tables
* in case the keys are not quite like a lk201.
* I assume that a regular key shifted/ctrled/caped is also a
* regular key. This may be naive.
if (key
== '\033' /*ESC*/ )
else if (key
== '\006' /*ALT*/)
else if (key
== '\177' /*DEL*/)
else if(state_mask
& ControlMask
)
kludgekey
= LK201
[sunkeymap
[se
->ie_code
+00200].kio_entry
];
else if(state_mask
& ShiftMask
)
kludgekey
= LK201
[sunkeymap
[se
->ie_code
+00600].kio_entry
];
else if(state_mask
& ShiftLockMask
)
kludgekey
= LK201
[sunkeymap
[se
->ie_code
+00400].kio_entry
];
xe
->vse_key
= kludgekey
& 0377;
kludgekey
&= (~state_mask
)&(ControlMask
|ShiftMask
);
} else switch (se
->ie_code
) {
xe
->vse_device
= VSE_MOUSE
; /* XXX - should query shift state here but ... */
xe
->vse_type
= VSE_MMOTION
;
xe
->vse_key
= VSE_LEFT_BUTTON
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
xe
->vse_key
= VSE_MIDDLE_BUTTON
;
xe
->vse_key
= VSE_RIGHT_BUTTON
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
* Read pending input events
struct inputevent sunevents
[INPBUFSIZE
];
if ((n
= read(vsdev
, sunevents
, INPBUFSIZE
* sizeof sunevents
[0])) < 0
&& errno
!= EWOULDBLOCK
) {
/* XXX_DO_SOMETHING(); */
for (n
/= sizeof sunevents
[0], m
= 0; m
< n
; m
++) {
unsigned kludgekey
= ConvertEvent(&(sunevents
[m
]), &Xevent
);
if (Xevent
.vse_type
== VSE_MMOTION
) {
int dx
= Xevent
.vse_x
- CurrentDevice
->mouse
->x
;
int dy
= Xevent
.vse_y
- CurrentDevice
->mouse
->y
;
if (sunthreshold
<= (dx
> 0 ? dx
: -dx
) + (dy
> 0 ? dy
: -dy
)) {
Xevent
.vse_x
= CurrentDevice
->mouse
->x
+ dx
* sunaccel
;
Xevent
.vse_y
= CurrentDevice
->mouse
->y
+ dy
* sunaccel
;
SetCursorPosition((vsCursor
*) &Xevent
); /* XXX - tacky */
if (Xevent
.vse_type
== VSE_MMOTION
) {
register vsBox
*b
= CurrentDevice
->mbox
;
register vsCursor
*m
= CurrentDevice
->mouse
;
if (m
->y
>= b
->bottom
|| m
->y
< b
->top
||
m
->x
>= b
->right
|| m
->x
< b
->left
) {
} else if (Xevent
.vse_key
!= NOT_A_KEY
||
Xevent
.vse_device
!= VSE_MOUSE
) {
Deal_with_input(&Xevent
);
state_mask
&= ~kludgekey
;
register int ret
= LK201
[s
&0177];
* Convert from a Sun event to an X event
static unsigned lstate_mask
;
/* Map the coordinates */
/* Map the time stamps */
xe
->vse_time
= (se
->ie_time
.tv_usec
/10000 + se
->ie_time
.tv_sec
);
xe
->vse_direction
= (win_inputposevent(se
) ? VSE_KBTDOWN
: VSE_KBTUP
);
/* Sort out the event codes */
if (event_is_ascii(se
)) {
int key
= SunToXKeyCode(se
->ie_code
);
xe
->vse_key
= (key
& 0377);
xe
->vse_device
= VSE_DKB
;
xe
->vse_type
= VSE_BUTTON
;
lstate_mask
= (lstate_mask
& ~(ControlMask
|MetaMask
|ShiftMask
))
| (key
& (ControlMask
|MetaMask
|ShiftMask
));
} else if (event_is_meta(se
)) {
/* META keystroke - map to ASCII for now */
int key
= SunToXKeyCode(se
->ie_code
- META_FIRST
+ ASCII_FIRST
) | MetaMask
;
xe
->vse_key
= (key
& 0377);
xe
->vse_device
= VSE_DKB
;
xe
->vse_type
= VSE_BUTTON
;
lstate_mask
= (lstate_mask
& ~(ControlMask
|MetaMask
|ShiftMask
))
| (key
& (ControlMask
|MetaMask
|ShiftMask
));
} else switch (se
->ie_code
) {
xe
->vse_device
= VSE_MOUSE
; /* XXX - should query shift state here but ... */
xe
->vse_type
= VSE_MMOTION
;
xe
->vse_key
= VSE_LEFT_BUTTON
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
if (xe
->vse_direction
== VSE_KBTUP
)
lstate_mask
&= ~LeftMask
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
xe
->vse_key
= VSE_MIDDLE_BUTTON
;
if (xe
->vse_direction
== VSE_KBTUP
)
lstate_mask
&= ~MiddleMask
;
lstate_mask
|= MiddleMask
;
xe
->vse_key
= VSE_RIGHT_BUTTON
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
if (xe
->vse_direction
== VSE_KBTUP
)
lstate_mask
&= ~RightMask
;
lstate_mask
|= RightMask
;
xe
->vse_device
= VSE_MOUSE
;
xe
->vse_type
= VSE_BUTTON
;
if (xe
->vse_direction
== VSE_KBTUP
)
lstate_mask
&= ~ShiftLockMask
;
lstate_mask
|= ShiftLockMask
;
if (se
->ie_shiftmask
& SHIFTMASK
)
lstate_mask
|= ShiftMask
;
lstate_mask
&= ~ShiftMask
;
if (se
->ie_shiftmask
& CTRLMASK
)
lstate_mask
|= ControlMask
;
lstate_mask
&= ~ControlMask
;
if (se
->ie_shiftmask
& META_SHIFT_MASK
)
lstate_mask
&= ~MetaMask
;
* Read pending input events
struct inputevent sunevents
[INPBUFSIZE
];
if ((n
= read(vsdev
, sunevents
, INPBUFSIZE
* sizeof sunevents
[0])) < 0
&& errno
!= EWOULDBLOCK
) {
/* XXX_DO_SOMETHING(); */
for (n
/= sizeof sunevents
[0], m
= 0; m
< n
; m
++) {
mask
= ConvertEvent(&(sunevents
[m
]), &Xevent
);
if (Xevent
.vse_type
== VSE_MMOTION
) {
int dx
= Xevent
.vse_x
- CurrentDevice
->mouse
->x
;
int dy
= Xevent
.vse_y
- CurrentDevice
->mouse
->y
;
if (sunthreshold
<= (dx
> 0 ? dx
: -dx
) + (dy
> 0 ? dy
: -dy
)) {
Xevent
.vse_x
= CurrentDevice
->mouse
->x
+ dx
* sunaccel
;
Xevent
.vse_y
= CurrentDevice
->mouse
->y
+ dy
* sunaccel
;
SetCursorPosition((vsCursor
*) &Xevent
); /* XXX - tacky */
Sevent
.vse_device
= VSE_DKB
;
Sevent
.vse_x
= Xevent
.vse_x
;
Sevent
.vse_y
= Xevent
.vse_y
;
Sevent
.vse_time
= Xevent
.vse_time
;
if (last_mask
& ShiftMask
) {
Sevent
.vse_direction
= VSE_KBTDOWN
;
Sevent
.vse_direction
= VSE_KBTUP
;
Deal_with_input(&Sevent
);
if (last_mask
& ControlMask
) {
Sevent
.vse_direction
= VSE_KBTDOWN
;
Sevent
.vse_direction
= VSE_KBTUP
;
Deal_with_input(&Sevent
);
if (last_mask
& ShiftLockMask
) {
if (mask
& ShiftLockMask
)
Sevent
.vse_direction
= VSE_KBTDOWN
;
Sevent
.vse_direction
= VSE_KBTUP
;
Deal_with_input(&Sevent
);
if (last_mask
& MetaMask
) {
Sevent
.vse_direction
= VSE_KBTDOWN
;
Sevent
.vse_direction
= VSE_KBTUP
;
Deal_with_input(&Sevent
);
if (Xevent
.vse_type
== VSE_MMOTION
) {
register vsBox
*b
= CurrentDevice
->mbox
;
register vsCursor
*m
= CurrentDevice
->mouse
;
if (m
->y
>= b
->bottom
|| m
->y
< b
->top
||
m
->x
>= b
->right
|| m
->x
< b
->left
) {
} else if (Xevent
.vse_key
!= NOT_A_KEY
||
Xevent
.vse_device
!= VSE_MOUSE
)
Deal_with_input(&Xevent
);