~ubuntu-branches/ubuntu/karmic/x11-xserver-utils/karmic

« back to all changes in this revision

Viewing changes to xtrap/xtrapchar.c

  • Committer: Bazaar Package Importer
  • Author(s): Brice Goglin, Julien Cristau, Brice Goglin
  • Date: 2007-08-17 09:58:34 UTC
  • Revision ID: james.westby@ubuntu.com-20070817095834-ywge2nyzj1s3rqnd
Tags: 7.3+1
[ Julien Cristau ]
* iceauth 1.0.2.
  + removes blank line in the manpage (closes: #25285).
* xmodmap 1.0.3.
  + manpage updated to state that -pm is the default (closes: #236198)
* xgamma 1.0.2.
  + the manpage now explains how to print the gamma value more clearly
    (closes: #296021).
* xsetroot 1.0.2.
* xrdb 1.0.4.
  + fixes manpage typo (closes: #276286).
* Add upstream URL to debian/copyright, and update it from xgamma's COPYING
  file.

[ Brice Goglin ]
* Add menu entries for xrefresh and xvidtune.
* sessreg 1.0.3.
* xset 1.0.3.
* Add myself to Uploaders, and remove Branden with his permission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/xtrap/xtrapchar.c,v 1.2 2001/11/19 15:33:41 tsi Exp $ */
 
2
/*
 
3
 * @DEC_COPYRIGHT@
 
4
 */
 
5
/*
 
6
 * HISTORY
 
7
 * Log: xtrapchar.c,v $
 
8
 * Revision 1.1.2.2  1993/12/14  12:37:15  Kenneth_Miller
 
9
 *      ANSI-standardize code and turn client build on
 
10
 *      [1993/12/09  20:15:33  Kenneth_Miller]
 
11
 *
 
12
 * EndLog$
 
13
 */
 
14
#if !defined(lint) && 0
 
15
static char *rcsid = "@(#)RCSfile: xtrapchar.c,v $ Revision: 1.1.2.2 $ (DEC) Date: 1993/12/14 12:37:15 $";
 
16
#endif
 
17
/*****************************************************************************
 
18
Copyright 1987, 1988, 1989, 1990, 1991, 1993 by Digital Equipment Corp., 
 
19
Maynard, MA
 
20
 
 
21
Permission to use, copy, modify, and distribute this software and its 
 
22
documentation for any purpose and without fee is hereby granted, 
 
23
provided that the above copyright notice appear in all copies and that
 
24
both that copyright notice and this permission notice appear in 
 
25
supporting documentation, and that the name of Digital not be
 
26
used in advertising or publicity pertaining to distribution of the
 
27
software without specific, written prior permission.  
 
28
 
 
29
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
30
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
31
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
32
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
33
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
34
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
35
SOFTWARE.
 
36
 
 
37
*****************************************************************************/
 
38
#define ProgName "xtrapchar"
 
39
/*
 
40
**++
 
41
**  FACILITY:  xtrapchar - Converts ANSI character sequences to X.
 
42
**
 
43
**  MODULE DESCRIPTION:
 
44
**
 
45
**      Parses ANSI character sequences including application program 
 
46
**      sequences to synthesize input events to X Window servers 
 
47
**      using the XTrap server extension.  Additionally, this main
 
48
**      module is designed to be used with the voice
 
49
**      recognition systems which will allow voice input into X Servers.
 
50
**
 
51
**  AUTHORS:
 
52
**
 
53
**      Kenneth B. Miller
 
54
**
 
55
**  CREATION DATE:  March 23, 1991
 
56
**
 
57
**  DESIGN ISSUES:
 
58
**
 
59
**      Accepts non-buffered Ascii characters as input and 
 
60
**      performs a table look-up to determine what the corresponding
 
61
**      X actions are to be performed.
 
62
**
 
63
**      Uses chparse() which was contributed to DECUS C by Roy
 
64
**      Lomicka and later revised by Martin Minow and myself.
 
65
**      Also, getopt() is used to parse the command
 
66
**      line arguments prior to calling XtAppInitialize().
 
67
**      Currently only the -v argument is supported to indicate
 
68
**      echoing of characters received for debugging
 
69
**      purposes.
 
70
**
 
71
**
 
72
**  CAVEAT:
 
73
**
 
74
**      This program has *only* been used with Digital Workstations
 
75
**      using the LK201 compatible keyboard.  Though reasonable
 
76
**      effort was done to maintain portability, no claims are made
 
77
**      as to the current level of portability to non-DEC servers
 
78
**      for this program.
 
79
**--
 
80
*/
 
81
#include <unistd.h>
 
82
#include <stdlib.h>
 
83
#include <ctype.h>
 
84
#include <X11/extensions/xtraplib.h>
 
85
#include <X11/extensions/xtraplibp.h>
 
86
#include <X11/keysym.h>
 
87
 
 
88
#include "chparse.h"
 
89
 
 
90
#ifndef vaxc
 
91
#define globalref extern
 
92
#endif
 
93
#ifdef Lynx
 
94
extern char *optarg;
 
95
extern int optind;
 
96
extern int opterr;
 
97
#endif
 
98
 
 
99
    /* Special private indicators */
 
100
#define BPRESS      '!'
 
101
#define BRELEASE    '"'
 
102
#define BCLICK      '#'
 
103
#define APRESS      '$'
 
104
#define ARELEASE    '%'
 
105
#define CPRESS      '('
 
106
#define CRELEASE    ')'
 
107
#define SPRESS      '+'
 
108
#define SRELEASE    '-'
 
109
#define DPRIVATE    '='
 
110
#define MNOTIFY     '>'
 
111
#define RMNOTIFY    '?'
 
112
 
 
113
#define NPARAM  8
 
114
#define NINTER  8
 
115
#define NUL     0x00
 
116
#define CAN     0x18
 
117
#define SUB     0x1A
 
118
#define ESC     0x1B
 
119
#define DEL     0x7F
 
120
#define SS3     0x8f
 
121
#define DCS     0x90
 
122
#define CSI     0x9B
 
123
#define ST      0x9C
 
124
#define OSC     0x9D
 
125
#define PM      0x9E
 
126
#define APC     0x9F
 
127
 
 
128
static BOOL     verbose_flag = FALSE;
 
129
static INT16    column = 0;
 
130
static int      state = NUL;    /* Parser state (n.z. if incomplete)    */
 
131
static  Window root;
 
132
static BOOL passive_shift; /* Cap's assumed?                       */
 
133
static BOOL passive_ctrl;  /* Control key assumed?                 */
 
134
static BOOL shift;         /* Cap's on?                            */
 
135
static BOOL ctrl;          /* Control key?                         */
 
136
static BOOL alt;           /* Alt key?                             */
 
137
KeyCode alt_code;
 
138
KeyCode ctrl_code;
 
139
KeyCode shift_code;
 
140
 
 
141
 
 
142
 
 
143
#define _AdjustCol(length) \
 
144
    if ((column += length) >= 79) \
 
145
    { \
 
146
        printf("\n"); \
 
147
        column = length; \
 
148
    }
 
149
 
 
150
static void KeyClick(XETC *tc, KeyCode keycode)
 
151
{
 
152
    if (passive_ctrl && !ctrl)
 
153
    {
 
154
        XESimulateXEventRequest(tc, KeyPress, ctrl_code, 0, 0, 0);
 
155
    }
 
156
    if (passive_shift && !shift)
 
157
    {
 
158
        XESimulateXEventRequest(tc, KeyPress, shift_code, 0, 0, 0);
 
159
    }
 
160
    XESimulateXEventRequest(tc, KeyPress, keycode, 0, 0, 0);
 
161
    XESimulateXEventRequest(tc, KeyRelease, keycode, 0, 0, 0);
 
162
    if (passive_shift && !shift)
 
163
    {
 
164
        XESimulateXEventRequest(tc, KeyRelease, shift_code, 0, 0, 0);
 
165
    }
 
166
    if (passive_ctrl && !ctrl)
 
167
    {
 
168
        XESimulateXEventRequest(tc, KeyRelease, ctrl_code, 0, 0, 0);
 
169
    }
 
170
    passive_ctrl = passive_shift = FALSE;   /* Action's been completed */
 
171
}
 
172
 
 
173
 
 
174
/*
 
175
**
 
176
** FORWARD DECLARATIONS
 
177
**
 
178
*/
 
179
static int get_csi_key ( XETC *tc , int private , int param [], 
 
180
    int nparam , int inter [], int ninter , int final );
 
181
static int get_ss3_key ( XETC *tc , int private , int param [], 
 
182
    int nparam , int inter [], int ninter , int final );
 
183
static void send_special ( XETC *tc , int private , int param [],
 
184
    int nparam , int inter [], int ninter , int final );
 
185
static KeyCode get_typical_char ( XETC *tc , CARD32 keysym);
 
186
static KeyCode get_keycode ( XETC *tc , KeySym keysym);
 
187
 
 
188
 
 
189
int
 
190
main(int argc, char *argv[])
 
191
{
 
192
    Widget appW;
 
193
    Display *dpy;
 
194
    XETrapGetCurRep   ret_cur;
 
195
    XETC    *tc;
 
196
    XtAppContext app;
 
197
    char *tmp = NULL;
 
198
    INT16 ch;
 
199
    INT16 i;
 
200
    KeyCode keycode;
 
201
    /* ESC & CSI Parsing variables */
 
202
    int max_delay  = 3;
 
203
    int rest_delay = 2;
 
204
    int private;        /* Sequence private char, 'X' if error  */
 
205
    int param[NPARAM];  /* numeric param, starting at param[1]  */
 
206
    int nparam;         /* Number of parameters                 */
 
207
    int inter[NINTER];  /* intermediate char, starting at [1]   */
 
208
    int ninter;         /* Number of intermediates              */
 
209
    int final;          /* Sequence terminator                  */
 
210
    int *popterr;
 
211
#ifndef vms
 
212
    popterr = &opterr;
 
213
#else
 
214
    popterr = XEgetopterr();
 
215
#endif
 
216
    *popterr = 0; /* don't complain about -d for display */
 
217
    while ((ch = getopt(argc, argv, "d:v")) != EOF)
 
218
    {
 
219
        switch(ch)
 
220
        {
 
221
            case 'v':
 
222
                verbose_flag = TRUE;
 
223
                break;
 
224
            case 'd':   /* -display, let's let the toolkit parse it */
 
225
                break;
 
226
            default:
 
227
                break;
 
228
        }
 
229
    }
 
230
    appW = XtAppInitialize(&app,"XTrap",(XrmOptionDescList)NULL,(Cardinal)0L,
 
231
        (int *)&argc, (String *)argv, NULL,(ArgList)&tmp,
 
232
        (Cardinal)0);
 
233
 
 
234
    dpy = XtDisplay(appW);
 
235
    if (verbose_flag)
 
236
    {
 
237
        printf("Display:  %s \n", DisplayString(dpy));
 
238
    }
 
239
    if ((tc = XECreateTC(dpy,0L, NULL)) == False)
 
240
    {
 
241
        fprintf(stderr,"%s: could not initialize XTrap extension\n", ProgName);
 
242
        exit (1L);
 
243
    }
 
244
    root = RootWindow(dpy,DefaultScreen(dpy));
 
245
    (void)XEStartTrapRequest(tc);
 
246
    alt_code   = XKeysymToKeycode(tc->dpy,XK_Alt_L);
 
247
    ctrl_code  = XKeysymToKeycode(tc->dpy,XK_Control_L);
 
248
    shift_code = XKeysymToKeycode(tc->dpy,XK_Shift_L);
 
249
 
 
250
 
 
251
 
 
252
    if (verbose_flag)
 
253
    {
 
254
        (void)XEGetCurrentRequest(tc,&ret_cur);
 
255
        XEPrintCurrent(stderr,&ret_cur);
 
256
    }
 
257
 
 
258
    column = 0; /* if displaying char's, don't go beyond 80 columns */
 
259
 
 
260
    while ((ch = chparse(max_delay, rest_delay, &state, &private, param, 
 
261
        &nparam, inter, &ninter, &final)) != -1)
 
262
    {
 
263
        if (ch == -2)
 
264
        {
 
265
            continue;   /* timeout condition */
 
266
        }
 
267
        if ((!ferror(stdin)) && (!feof(stdin)) && (state == 0))
 
268
        {   /* we got something */
 
269
            switch(ch)
 
270
            {
 
271
                case CSI:   /* Control Sequence */
 
272
                    keycode = get_csi_key(tc, private, param, nparam, inter,
 
273
                        ninter, final);
 
274
                    if (keycode)
 
275
                        KeyClick(tc, keycode);
 
276
                    break;
 
277
                case SS3:   /* Keypad stuff */
 
278
                    keycode = get_ss3_key(tc, private, param, nparam, inter,
 
279
                        ninter, final);
 
280
                    if (keycode)
 
281
                        KeyClick(tc, keycode);
 
282
                    break;
 
283
                case APC:   /* Application Cmd (Button's, Press, Release) */
 
284
                    send_special(tc, private, param, nparam, inter, ninter,
 
285
                        final);
 
286
                    break;
 
287
                case ESC:   /* Escape Sequence */
 
288
                    /* send ESCAPE */
 
289
                    if (!(keycode = XKeysymToKeycode(tc->dpy,XK_Escape)))
 
290
                    {   /* must be an LK201 keyboard */
 
291
                        BOOL orig_ctrl = ctrl;
 
292
                        /* 
 
293
                         * the following is kind of strange.  We need to
 
294
                         * have ctrl TRUE for get_typical_char() to 
 
295
                         * report the verbose message correctly.  We
 
296
                         * can't use passive_ctrl cause it resets it.
 
297
                         * Then, for KeyClick(), ctrl has to be FALSE
 
298
                         * and passive_ctrl has to be TRUE in order for
 
299
                         * us to get the desired <CTRL>[ to simulate
 
300
                         * an escape key.  Once it's all done, we need
 
301
                         * to return ctrl to whatever it was and clear
 
302
                         * the passive_ctrl.
 
303
                         */
 
304
                        ctrl = TRUE;                /* for get_typical_char */
 
305
                        keycode = get_typical_char(tc, (CARD32)'[');
 
306
                        ctrl         = FALSE;       /* for KeyClick */
 
307
                        passive_ctrl = TRUE;        /* for KeyClick */
 
308
                        KeyClick(tc, keycode);
 
309
                        passive_ctrl  = FALSE;      /* to continue */
 
310
                        ctrl          = orig_ctrl;  /* to continue */
 
311
                    }
 
312
                    else
 
313
                    {
 
314
                        KeyClick(tc, keycode);
 
315
                        if (verbose_flag)
 
316
                        {
 
317
                            _AdjustCol(strlen("<ESC>"));
 
318
                            printf("<ESC>");
 
319
                        }
 
320
                    }
 
321
                    /* send private (if valid) */
 
322
                    if (private != NUL && private != 'X' &&
 
323
                       (keycode = get_typical_char(tc, (CARD32)private)))
 
324
                        KeyClick(tc, keycode);
 
325
                    /* send addt'l parameters, if any */
 
326
                    for (i = 1; i <= nparam; i++)
 
327
                        if ((keycode = get_typical_char(tc, (CARD32)param[i])))
 
328
                            KeyClick(tc, keycode);
 
329
                    /* send intermediate's, if any */
 
330
                    for (i = 1; i <= ninter; i++)
 
331
                        if ((keycode = get_typical_char(tc, (CARD32)inter[i])))
 
332
                            KeyClick(tc, keycode);
 
333
                    /* send final character */
 
334
                    if ((keycode = get_typical_char(tc, (CARD32)final)))
 
335
                        KeyClick(tc, keycode);
 
336
                    break;
 
337
 
 
338
                case DCS:   /* We don't deal with these */
 
339
                case OSC:
 
340
                case PM:
 
341
                    if (verbose_flag)
 
342
                    {
 
343
                        printf("Ignoring the following: ");
 
344
                        dumpsequence(state, ch, private, param, nparam, 
 
345
                            inter, ninter, final, &column);
 
346
                    }
 
347
                    break;
 
348
                default:    /* typical character */
 
349
                    keycode = get_typical_char(tc, (CARD32)ch);
 
350
                    if (keycode)
 
351
                        KeyClick(tc, keycode);
 
352
                    break;
 
353
            }
 
354
        }
 
355
        else
 
356
        {   /* error? */
 
357
            if (ferror(stdin) || state != 0)
 
358
            {
 
359
                perror("Error occurred parsing input characters!\n");
 
360
            }
 
361
            break;
 
362
        }
 
363
    }
 
364
    /* Clean things up */
 
365
    XEFreeTC(tc);      
 
366
    (void)XCloseDisplay(dpy);
 
367
 
 
368
    exit(0L);
 
369
}
 
370
 
 
371
static int get_csi_key(tc, private, param, nparam, inter, ninter, final)
 
372
    XETC    *tc;
 
373
    int     private;
 
374
    int     param[], nparam;
 
375
    int     inter[], ninter;
 
376
    int     final;
 
377
{
 
378
    KeySym keysym = 0;
 
379
    switch(param[1])
 
380
    {
 
381
        case 0:
 
382
            switch ((char )final)
 
383
            {
 
384
                case 'A':    keysym = XK_Up;         break;
 
385
                case 'B':    keysym = XK_Down;       break;
 
386
                case 'C':    keysym = XK_Right;      break;
 
387
                case 'D':    keysym = XK_Left;       break;
 
388
                default:
 
389
                    dumpsequence(state, CSI, private, param, nparam, 
 
390
                        inter, ninter, final, &column);
 
391
                    break;
 
392
            }
 
393
            break;
 
394
        case 1:     keysym = XK_Find;       break;
 
395
        case 2:     keysym = XK_Insert;     break;
 
396
#ifdef DXK_Remove
 
397
        case 3:     keysym = DXK_Remove;    break;
 
398
#endif
 
399
        case 4:     keysym = XK_Select;     break;
 
400
        case 5:     keysym = XK_Prior;      break;
 
401
        case 6:     keysym = XK_Next;       break;
 
402
        case 17:    keysym = XK_F6;         break;
 
403
        case 18:    keysym = XK_F7;         break;
 
404
        case 19:    keysym = XK_F8;         break;
 
405
        case 20:    keysym = XK_F9;         break;
 
406
        case 21:    keysym = XK_F10;        break;
 
407
        case 23:    keysym = XK_F11;        break;
 
408
        case 24:    keysym = XK_F12;        break;
 
409
        case 25:    keysym = XK_F13;        break;
 
410
        case 26:    keysym = XK_F14;        break;
 
411
        case 28:    keysym = XK_Help;       break;
 
412
        case 29:    keysym = XK_Menu;       break;
 
413
        case 31:    keysym = XK_F17;        break;
 
414
        case 32:    keysym = XK_F18;        break;
 
415
        case 33:    keysym = XK_F19;        break;
 
416
        case 34:    keysym = XK_F20;        break;
 
417
        default:
 
418
            dumpsequence(state, CSI, private, param, nparam, 
 
419
                inter, ninter, final, &column);
 
420
    }
 
421
 
 
422
    return(get_keycode(tc, keysym));
 
423
}
 
424
 
 
425
    /*
 
426
     * XTrap special sequences:
 
427
     * ButtonPress:     <APC>=!X        (where 'X' is 'A', 'B', or 'C' 
 
428
     *                                  for MB1, MB2, MB3 respectively)
 
429
     * ButtonRelease:   <APC>="X        (where 'X' is 'A', 'B', or 'C' 
 
430
     *                                  for MB1, MB2, MB3 respectively)
 
431
     * ButtonClick:     <APC>=#X        (where 'X' is 'A', 'B', or 'C' 
 
432
     *                                  for MB1, MB2, MB3 respectively)
 
433
     * AltPress:        <APC>=$~
 
434
     * AltRelease:      <APC>=%~
 
435
     * CtrlPress:       <APC>=(~
 
436
     * CtrlRelease:     <APC>=)~
 
437
     * ShiftPress:      <APC>=+~
 
438
     * ShiftRelease:    <APC>=-~
 
439
     * MotionNotify:    <APC>>;X;Y~     (where 'X' is the X coord and 'Y'
 
440
     *                                  is the Y coord of the desired
 
441
     *                                  pointer position)
 
442
     * Relative MotionNotify:    
 
443
     *                  <APC>?;X;Y~     (where 'X' is the X coord and 'Y'
 
444
     *                                  is the Y coord of the desired
 
445
     *                                  pointer position)
 
446
     *
 
447
     */    
 
448
static void send_special(tc, private, param, nparam, inter, ninter, final)
 
449
    XETC    *tc;
 
450
    int     private;
 
451
    int     param[], nparam;
 
452
    int     inter[], ninter;
 
453
    int     final;
 
454
{
 
455
    switch(private)
 
456
    {
 
457
        case DPRIVATE:   /* default APC */
 
458
            if (ninter != 1)
 
459
            {   /* Not my sequence */
 
460
                dumpsequence(state, APC, private, param, nparam, 
 
461
                    inter, ninter, final, &column);
 
462
                return;
 
463
            }
 
464
            else
 
465
            {
 
466
                switch(inter[1])
 
467
                {
 
468
                    Window rid, wid;
 
469
                    int x, y, wx, wy;
 
470
                    unsigned int sm;
 
471
                    CARD8 detail;
 
472
        
 
473
                    case BPRESS:
 
474
                        detail = (final - 'A' + 1);
 
475
                        if ((Bool)XQueryPointer(tc->dpy,root,&rid,&wid,&x,
 
476
                            &y,&wx,&wy,&sm) == False)
 
477
                        {
 
478
                            fprintf(stderr, "\nPointer's not on screen 0!\n");
 
479
                        }
 
480
                        else
 
481
                        {
 
482
                            XESimulateXEventRequest(tc, ButtonPress, detail, 
 
483
                                x, y, 0);
 
484
                            if (verbose_flag)
 
485
                            {
 
486
                                _AdjustCol(strlen("<MB%d-Press> ")-1);
 
487
                                printf("<MB%d-Press> ", detail);
 
488
                            }
 
489
                        }
 
490
                        break;
 
491
                    case BRELEASE:
 
492
                        detail = (final - 'A' + 1);
 
493
                        if ((Bool)XQueryPointer(tc->dpy,root,&rid,&wid,&x,
 
494
                            &y,&wx,&wy,&sm) == False)
 
495
                        {
 
496
                            fprintf(stderr, "\nPointer's not on screen 0!\n");
 
497
                        }
 
498
                        else
 
499
                        {
 
500
                            XESimulateXEventRequest(tc, ButtonRelease, detail,
 
501
                                x,y,0);
 
502
                            if (verbose_flag)
 
503
                            {
 
504
                                _AdjustCol(strlen("<MB%d-Release> ")-1);
 
505
                                printf("<MB%d-Release> ", detail);
 
506
                            }
 
507
                        }
 
508
                        break;
 
509
                    case BCLICK:
 
510
                        detail = (final - 'A' + 1);
 
511
                        if (XQueryPointer(tc->dpy,root,&rid,&wid,&x,&y,
 
512
                            &wx,&wy,&sm)
 
513
                            == False)
 
514
                        {
 
515
                            fprintf(stderr, "\nPointer's not on screen 0!\n");
 
516
                        }
 
517
                        else
 
518
                        {
 
519
                            XESimulateXEventRequest(tc,ButtonPress,
 
520
                                detail,x,y,0);
 
521
                            XESimulateXEventRequest(tc,ButtonRelease,
 
522
                                detail,x,y,0);
 
523
                            if (verbose_flag)
 
524
                            {
 
525
                                _AdjustCol(strlen("<MB%d> ")-1);
 
526
                                printf("<MB%d> ", detail);
 
527
                            }
 
528
                        }
 
529
                        break;
 
530
                    case APRESS:
 
531
                        alt = TRUE;
 
532
                        XESimulateXEventRequest(tc,KeyPress,alt_code,0,0,0);
 
533
                        break;
 
534
                    case ARELEASE:
 
535
                        alt = FALSE;
 
536
                        XESimulateXEventRequest(tc,KeyRelease,alt_code,0,0,0);
 
537
                        break;
 
538
                    case SPRESS:
 
539
                        shift = TRUE;
 
540
                        XESimulateXEventRequest(tc,KeyPress,shift_code,0,0,0);
 
541
                        break;
 
542
                    case SRELEASE:
 
543
                        shift = FALSE;
 
544
                        XESimulateXEventRequest(tc,KeyRelease,shift_code,
 
545
                            0,0,0);
 
546
                        break;
 
547
                    case CPRESS:
 
548
                        ctrl = TRUE;
 
549
                        XESimulateXEventRequest(tc,KeyPress,ctrl_code,0,0,0);
 
550
                        break;
 
551
                    case CRELEASE:
 
552
                        ctrl = FALSE;
 
553
                        XESimulateXEventRequest(tc,KeyRelease,ctrl_code,0,0,0);
 
554
                        break;
 
555
                    default:
 
556
                        fprintf(stderr, "\nInvalid Sequence!\n");
 
557
                        dumpsequence(state, APC, private, param, nparam, 
 
558
                            inter, ninter, final, &column);
 
559
                }
 
560
            }
 
561
            break;
 
562
        case MNOTIFY:
 
563
            if (nparam != 3)
 
564
            {   /* Not my sequence */
 
565
                dumpsequence(state, APC, private, param, nparam, 
 
566
                    inter, ninter, final, &column);
 
567
                return;
 
568
            }
 
569
            else
 
570
            {
 
571
                int x, y;
 
572
 
 
573
                x = param[2];
 
574
                y = param[3];
 
575
                XESimulateXEventRequest(tc,MotionNotify,0,x,y,0);
 
576
                if (verbose_flag)
 
577
                {
 
578
                    _AdjustCol(strlen("<M %d,%d> ")+3);
 
579
                    printf("<M %d,%d> ",x,y);
 
580
                }
 
581
            }
 
582
            break;
 
583
        case RMNOTIFY:
 
584
            if (nparam != 3)
 
585
            {   /* Not my sequence */
 
586
                dumpsequence(state, APC, private, param, nparam, 
 
587
                    inter, ninter, final, &column);
 
588
                return;
 
589
            }
 
590
            else
 
591
            {
 
592
                Window rid, wid;
 
593
                int x, y, wx, wy;
 
594
                unsigned int sm;
 
595
 
 
596
                if (XQueryPointer(tc->dpy,root,&rid,&wid,&x,&y,&wx,&wy,&sm)
 
597
                    == False)
 
598
                {
 
599
                    fprintf(stderr, "\nPointer's not on screen 0!\n");
 
600
                }
 
601
                else
 
602
                {   /* We're ready to go */
 
603
                    x += param[2];
 
604
                    y += param[3];
 
605
                    XESimulateXEventRequest(tc,MotionNotify,0,x,y,0);
 
606
                    if (verbose_flag)
 
607
                    {
 
608
                        _AdjustCol(strlen("<RM ddd+sddd,dddd+sdddd> "));
 
609
                        printf("<RM %d+%d,%d+%d> ",x-param[2],param[3],
 
610
                            y-param[3],param[3]);
 
611
                    }
 
612
                }
 
613
                break;
 
614
            default:
 
615
                dumpsequence(state, APC, private, param, nparam, 
 
616
                    inter, ninter, final, &column);
 
617
                break;
 
618
        }
 
619
    }
 
620
}
 
621
 
 
622
static int get_ss3_key(tc, private, param, nparam, inter, ninter, final)
 
623
    XETC    *tc;
 
624
    int     private;
 
625
    int     param[], nparam;
 
626
    int     inter[], ninter;
 
627
    int     final;
 
628
{
 
629
    KeySym keysym = 0;
 
630
    switch(param[1])
 
631
    {
 
632
        case 0:
 
633
            switch ((char )final)
 
634
            {
 
635
                case 'A':    keysym = XK_Up;            break;
 
636
                case 'B':    keysym = XK_Down;          break;
 
637
                case 'C':    keysym = XK_Right;         break;
 
638
                case 'D':    keysym = XK_Left;          break;
 
639
                case 'p':    keysym = XK_KP_0;          break;
 
640
                case 'q':    keysym = XK_KP_1;          break;
 
641
                case 'r':    keysym = XK_KP_2;          break;
 
642
                case 's':    keysym = XK_KP_3;          break;
 
643
                case 't':    keysym = XK_KP_4;          break;
 
644
                case 'u':    keysym = XK_KP_5;          break;
 
645
                case 'v':    keysym = XK_KP_6;          break;
 
646
                case 'w':    keysym = XK_KP_7;          break;
 
647
                case 'x':    keysym = XK_KP_8;          break;
 
648
                case 'y':    keysym = XK_KP_9;          break;
 
649
                case 'm':    keysym = XK_KP_Subtract;   break;
 
650
                case 'l':    keysym = XK_KP_Separator;  break;
 
651
                case 'n':    keysym = XK_KP_Decimal;    break;
 
652
                case 'M':    keysym = XK_KP_Enter;      break;
 
653
                case 'P':    keysym = XK_KP_F1;         break;
 
654
                case 'Q':    keysym = XK_KP_F2;         break;
 
655
                case 'R':    keysym = XK_KP_F3;         break;
 
656
                case 'S':    keysym = XK_KP_F4;         break;
 
657
                default:
 
658
                    dumpsequence(state, SS3, private, param, nparam, 
 
659
                        inter, ninter, final, &column);
 
660
                    break;
 
661
            }
 
662
            break;
 
663
    }
 
664
 
 
665
    return(get_keycode(tc, keysym));
 
666
}
 
667
 
 
668
static KeyCode get_typical_char(tc, keysym)
 
669
    XETC    *tc;
 
670
    CARD32  keysym;
 
671
{
 
672
    if (iscntrl(keysym))
 
673
    {   
 
674
        switch(keysym)
 
675
        {
 
676
            case 0x09:  keysym = XK_Tab; break;
 
677
            case 0x0d:  keysym = XK_Return; break;
 
678
            case 0x7f:  keysym = XK_Delete; break;
 
679
            case ESC:   keysym = XK_Escape; break;
 
680
        }
 
681
    }
 
682
    passive_shift = (keysym >= XK_A && keysym <= XK_Z) ? TRUE : FALSE;
 
683
    switch(keysym)
 
684
    {   /* Special case shift's */
 
685
        case '!': case '"': case '@': case '#': case '$':
 
686
        case '%': case '^': case '&': case '*': case '(':
 
687
        case ')': case '_': case '+': case '{': case '}':
 
688
        case '|': case ':': case '>': case '?': case '~':
 
689
            passive_shift = TRUE;
 
690
    }
 
691
 
 
692
    if (keysym >= 1 && keysym <= 26)
 
693
    {
 
694
        passive_ctrl  = TRUE;
 
695
        keysym += 'a' - 1;
 
696
    }
 
697
    else
 
698
    {
 
699
        passive_ctrl = FALSE;
 
700
    }
 
701
 
 
702
    return(get_keycode(tc, keysym));
 
703
}
 
704
 
 
705
static KeyCode get_keycode(XETC *tc, KeySym keysym)
 
706
{
 
707
    char *keystr = (char *)XKeysymToString(keysym);
 
708
    KeyCode keycode;
 
709
 
 
710
    keystr = (keystr == NULL) ? "unknown" : keystr;
 
711
    if (verbose_flag)
 
712
    {
 
713
        if (shift || passive_shift)
 
714
        {
 
715
            _AdjustCol(strlen("<SHIFT>"));
 
716
            printf("<SHIFT>");
 
717
        }
 
718
        if (alt)
 
719
        {
 
720
            _AdjustCol(strlen("<ALT>"));
 
721
            printf("<ALT>");
 
722
        }
 
723
        if (ctrl || passive_ctrl)
 
724
        {
 
725
            _AdjustCol(strlen("<CTRL>"));
 
726
            printf("<CTRL>");
 
727
        }
 
728
        _AdjustCol(strlen(keystr)+1);
 
729
        printf("%s ", keystr);
 
730
    }
 
731
    if (!(keycode = XKeysymToKeycode(tc->dpy,keysym)))
 
732
    {
 
733
        fprintf(stderr,"\n[%s ('%%0x%04x') returns bad Keycode, ignored]\n",
 
734
            keystr, (unsigned int)keysym);
 
735
        column = 0;
 
736
    }
 
737
 
 
738
    return(keycode);
 
739
}