Annotation of 43BSDTahoe/new/X/libapollo/events.c, revision 1.1

1.1     ! root        1:     /*
        !             2: 
        !             3:     Copyright 1986 by the University of Utah
        !             4: 
        !             5:     Permission to use, copy, modify, and distribute this
        !             6:     software and its documentation for any purpose and without
        !             7:     fee is hereby granted, provided that the above copyright
        !             8:     notice appear in all copies and that both that copyright
        !             9:     notice and this permission notice appear in supporting
        !            10:     documentation, and that the name of the University of Utah
        !            11:     not be used in advertising or publicity pertaining to 
        !            12:     distribution of the software without specific, written 
        !            13:     prior permission. The University of Utah makes no
        !            14:     representations about the suitability of this software for
        !            15:     any purpose.  It is provided "as is" without express or
        !            16:     implied warranty.
        !            17: 
        !            18:     */
        !            19: 
        !            20:    /*
        !            21: 
        !            22:     Copyright (C) 1986, Leonard N. Zubkoff   All Rights Reserved            */
        !            23: 
        !            24: 
        !            25: /*
        !            26:  *     ToDo:
        !            27:  *             Up events
        !            28:  *             Shiftlock support
        !            29:  */
        !            30: 
        !            31: #include       <stdio.h>
        !            32: #include       <sys/time.h>
        !            33: #include       <sys/errno.h>
        !            34: #include       <sys/wait.h>
        !            35: 
        !            36: #define do
        !            37: #define hidden     static
        !            38: #define visible
        !            39: #define procedure   void
        !            40: 
        !            41: #include    "Xapollo.h"
        !            42: #include "/sys/ins/ios.ins.c"
        !            43: #include "/sys/ins/io_traits.ins.c"
        !            44: #include "/sys/ins/trait.ins.c"
        !            45: #include "/sys/ins/kbd.ins.c"
        !            46: #include "/sys/ins/smdu.ins.c"
        !            47: #include "/sys/ins/tone.ins.c"
        !            48: #include "/sys/ins/ec2.ins.c"
        !            49: 
        !            50: 
        !            51: /* Should be qevent.h */
        !            52: #define        VSE_LEFT_BUTTON 0
        !            53: #define        VSE_MIDDLE_BUTTON       1
        !            54: #define        VSE_RIGHT_BUTTON        2
        !            55: 
        !            56: #define ShiftKeyCode 0256
        !            57: #define ControlKeyCode 0257
        !            58: #define LockKeyCode 0260
        !            59: #define MetaKeyCode 0261
        !            60: 
        !            61: #define SETSIZE (short)256
        !            62: 
        !            63: extern int errno;
        !            64: unsigned state_mask;
        !            65: extern DEVICE *CurrentDevice;
        !            66: extern int borrow_flag;
        !            67: static vsEvent xes, *xe;
        !            68: static status_$t stp;
        !            69: static ec2_$ptr_t ecs[2];
        !            70: static long ec_vlist[2];
        !            71: static gpr_$keyset_t KeySet;
        !            72: static boolean not_in_window;
        !            73: static gpr_$event_t EventType;
        !            74: static unsigned char EventData[1];
        !            75: static gpr_$position_t EventPosition;
        !            76: static boolean HavePreviewedData;
        !            77: static gpr_io_get_calls = 0;
        !            78: static ec2_$ptr_t GPREc;
        !            79: 
        !            80: 
        !            81: #include "lk201.h"
        !            82: 
        !            83: ProcessInput()
        !            84: {
        !            85: }
        !            86: 
        !            87: 
        !            88: /*
        !            89: 
        !            90:   This should be replaced by a tabular implementation of some kind.
        !            91: 
        !            92:  */
        !            93: int
        !            94: ApolloToXKey(c)
        !            95: unsigned char c;
        !            96: {
        !            97:     register int ret;
        !            98: 
        !            99:     state_mask = 0;
        !           100:     switch (c) {
        !           101:     case KBD_$R1:
        !           102:     case KBD_$R1U:
        !           103:         return(MetaKeyCode);
        !           104:     case KBD_$LD:
        !           105:     case KBD_$LDU:
        !           106:         return(ControlKeyCode);
        !           107:     case KBD_$LE:
        !           108:     case KBD_$LEU:
        !           109:         return(MetaKeyCode);
        !           110:     case KBD_$LF:
        !           111:     case KBD_$LFU:
        !           112:         return(ShiftKeyCode);
        !           113:     case KBD_$CR:
        !           114:         c = '\015';
        !           115:         break;
        !           116:     case KBD_$BS:
        !           117:         c = '\010';
        !           118:         break;
        !           119:     case KBD_$TAB:
        !           120:     case KBD_$STAB:
        !           121:     case KBD_$CTAB:
        !           122:         c = '\011';
        !           123:         break;
        !           124:     }
        !           125:     ret = LK201[c&0177];
        !           126:        state_mask = (state_mask & ~(ControlMask|MetaMask|ShiftMask|ShiftLockMask))
        !           127:            | (ret & (ControlMask|MetaMask|ShiftMask|ShiftLockMask));
        !           128:     return(ret);
        !           129: }
        !           130: 
        !           131: InputReader()
        !           132: {
        !           133:     gpr_$event_t prior_event;
        !           134:     int i;
        !           135:     boolean flag;
        !           136: 
        !           137:     HavePreviewedData = false;
        !           138: 
        !           139:     prior_event = gpr_$no_event;
        !           140:     while (1) {
        !           141:     if (!borrow_flag)
        !           142:         flag = gpr_$acquire_display( stp );
        !           143:     /* this needs to be replaced with a "real" timestamp */
        !           144:     xe->vse_time += 1;
        !           145:     if (EventType != gpr_$no_event) {
        !           146:         xe->vse_x = EventPosition.x_coord;
        !           147:         xe->vse_y = EventPosition.y_coord;
        !           148:         }
        !           149:     switch (EventType) {
        !           150:     case gpr_$no_event:
        !           151:         if ((prior_event == gpr_$locator_stop) ||
        !           152:             (prior_event == gpr_$locator)) {
        !           153:             Deal_with_movement(xe);
        !           154:            SetCursorPosition((vsCursor *) xe);
        !           155:             gpr_$set_cursor_position( EventPosition, stp);
        !           156:             }
        !           157:         if (!borrow_flag)
        !           158:             gpr_$release_display( stp );
        !           159:         return;
        !           160:     case gpr_$keystroke:
        !           161:        SetCursorPosition((vsCursor *) xe);
        !           162:         xe->vse_device = VSE_DKB;
        !           163:         xe->vse_type = VSE_BUTTON;
        !           164:         if ((EventData[0] == KBD_$R1U) ||
        !           165:             (EventData[0] == KBD_$LDU) ||
        !           166:             (EventData[0] == KBD_$LEU) ||
        !           167:             (EventData[0] == KBD_$LFU))
        !           168:              xe->vse_direction = VSE_KBTUP;
        !           169:         else
        !           170:             xe->vse_direction = VSE_KBTDOWN;
        !           171:         xe->vse_key = ApolloToXKey(EventData[0]);
        !           172:         handle_mask_down();
        !           173:         Deal_with_input(xe);
        !           174:         handle_mask_up();
        !           175:         break;
        !           176:     case gpr_$buttons:
        !           177:         xe->vse_device = VSE_MOUSE;
        !           178:         xe->vse_type = VSE_BUTTON;
        !           179:        SetCursorPosition((vsCursor *) xe);
        !           180:         switch (EventData[0]) {
        !           181:         case 'a':
        !           182:             xe->vse_key = VSE_LEFT_BUTTON;
        !           183:             xe->vse_direction = VSE_KBTDOWN;
        !           184:             break;
        !           185:         case 'b':
        !           186:             xe->vse_key = VSE_MIDDLE_BUTTON;
        !           187:             xe->vse_direction = VSE_KBTDOWN;
        !           188:             break;
        !           189:         case 'c':
        !           190:             xe->vse_key = VSE_RIGHT_BUTTON;
        !           191:             xe->vse_direction = VSE_KBTDOWN;
        !           192:             break;
        !           193:         case 'A':
        !           194:             xe->vse_key = VSE_LEFT_BUTTON;
        !           195:             xe->vse_direction = VSE_KBTUP;
        !           196:             break;
        !           197:         case 'B':
        !           198:             xe->vse_key = VSE_MIDDLE_BUTTON;
        !           199:             xe->vse_direction = VSE_KBTUP;
        !           200:             break;
        !           201:         case 'C':
        !           202:             xe->vse_key = VSE_RIGHT_BUTTON;
        !           203:             xe->vse_direction = VSE_KBTUP;
        !           204:             break;                       
        !           205:         }
        !           206:         Deal_with_input(xe);
        !           207:         break;
        !           208:     case gpr_$left_window:
        !           209:         gpr_$disable_input(gpr_$buttons, stp);
        !           210:         gpr_$disable_input(gpr_$keystroke, stp);
        !           211:         if (!borrow_flag)
        !           212:             gpr_$disable_input(gpr_$left_window, stp);
        !           213:         gpr_$disable_input(gpr_$locator_stop, stp);
        !           214:         gpr_$disable_input(gpr_$locator, stp);
        !           215:         if (!borrow_flag)
        !           216:             gpr_$force_release(i, stp);
        !           217:         break;
        !           218:     case gpr_$entered_window:
        !           219:         if (!borrow_flag)
        !           220:             flag = gpr_$acquire_display(stp);
        !           221:         gpr_$enable_input(gpr_$buttons, KeySet, stp);
        !           222:         gpr_$enable_input(gpr_$keystroke, KeySet, stp);
        !           223:         if (!borrow_flag) {
        !           224:             gpr_$enable_input(gpr_$left_window, 0L, stp);
        !           225:             gpr_$enable_input(gpr_$entered_window, 0L, stp);
        !           226:             }
        !           227:         gpr_$enable_input(gpr_$locator_stop, 0L, stp);
        !           228:         gpr_$enable_input(gpr_$locator, 0L, stp);
        !           229:         break;
        !           230:     case gpr_$locator:
        !           231:         xe->vse_device = VSE_MOUSE;
        !           232:         xe->vse_type = VSE_MMOTION;
        !           233:         break;      
        !           234:     case gpr_$locator_stop:
        !           235:         xe->vse_device = VSE_MOUSE;
        !           236:         xe->vse_type = VSE_MMOTION;
        !           237:         break;      
        !           238:     default:
        !           239:         fprintf(stderr,"Unrecognizable event--yecccch!!!!\n");
        !           240:         break;
        !           241:         }
        !           242:         prior_event = EventType;
        !           243:        gpr_$cond_event_wait(EventType, EventData[0], EventPosition, stp);
        !           244:     }
        !           245: 
        !           246: }
        !           247: 
        !           248: /* Turn off pseudo-shift/control keys
        !           249:  *  --destroys data field of event
        !           250:  */
        !           251: handle_mask_up()
        !           252: {
        !           253:     
        !           254:     if (state_mask & ControlMask) {
        !           255:         xe->vse_key = ControlKeyCode;
        !           256:         xe->vse_direction = VSE_KBTUP;
        !           257:         Deal_with_input(xe);
        !           258:         }
        !           259:     if (state_mask & ShiftMask) {
        !           260:         xe->vse_key = ShiftKeyCode;
        !           261:         xe->vse_direction = VSE_KBTUP;
        !           262:         Deal_with_input(xe);
        !           263:         }
        !           264: };
        !           265: 
        !           266: /* Turn on pseudo-shift/control keys
        !           267:  *  --preserves data field of event
        !           268:  */
        !           269: handle_mask_down()
        !           270: {
        !           271:     unsigned char data;
        !           272: 
        !           273:     data = xe->vse_key;
        !           274:     if (state_mask & ControlMask) {
        !           275:         xe->vse_key = ControlKeyCode;
        !           276:         xe->vse_direction = VSE_KBTDOWN;
        !           277:         Deal_with_input(xe);
        !           278:         }
        !           279:     if (state_mask & ShiftMask) {
        !           280:         xe->vse_key = ShiftKeyCode;
        !           281:         xe->vse_direction = VSE_KBTDOWN;
        !           282:         Deal_with_input(xe);
        !           283:         }
        !           284:     xe->vse_key = data;
        !           285: };
        !           286: 
        !           287: /* A rudimentary stream interface/type mgr for the keyboard and mouse
        !           288:  */
        !           289: 
        !           290: hidden int gpr_io_$get(hpp, optp, bp, buf_lenp, stp)
        !           291:        char **hpp;
        !           292:        ios_$put_get_opts_t *optp;
        !           293:        char *bp;
        !           294:        long *buf_lenp;
        !           295:        status_$t *stp;
        !           296: {
        !           297:        static char Buff[10];
        !           298:        static int BuffLen;
        !           299:        static boolean HaveBuff = false;
        !           300:        boolean NoWait = ((ios_$cond_opt & *optp) != 0);
        !           301:        boolean Preview = ((ios_$preview_opt & *optp) != 0);
        !           302:        status_$t Status;
        !           303:         boolean flag;
        !           304: 
        !           305:        if (! Preview) {
        !           306:                fprintf(stderr, "Gack!  Not preview in gpr_io_$get\n");
        !           307:                abort();
        !           308:        }
        !           309: 
        !           310:        if (HavePreviewedData) {
        !           311:                stp->all = status_$ok;
        !           312:                return(1);
        !           313:        }
        !           314: 
        !           315:        HavePreviewedData = false;
        !           316: 
        !           317: #ifdef PRE_SR9_5
        !           318:        if (NoWait) {
        !           319:                long ECValue = (long)ec2_$read(*GPREc);
        !           320:                static long PrevECValue = -1;
        !           321:                if (PrevECValue == ECValue)
        !           322:                        stp->all = ios_$get_conditional_failed;
        !           323:                else { 
        !           324:                 if (!borrow_flag)
        !           325:                     flag = gpr_$acquire_display(Status);
        !           326:                        gpr_$cond_event_wait(EventType, EventData[0], EventPosition, *stp);
        !           327:                 if (!borrow_flag)
        !           328:                     gpr_$release_display( Status );
        !           329:                        if (EventType == gpr_$no_event) {
        !           330:                                stp->all = ios_$get_conditional_failed;
        !           331:                                    PrevECValue = ECValue;
        !           332:                            }
        !           333:                        else
        !           334:                                PrevECValue = -1;
        !           335:                        }
        !           336:               }
        !           337:        else {
        !           338:         if (!borrow_flag)
        !           339:             flag = gpr_$acquire_display(Status);
        !           340:        gpr_$event_wait(EventType, EventData[0], EventPosition, *stp);
        !           341:         if (!borrow_flag)
        !           342:             gpr_$release_display( Status );
        !           343:            }
        !           344: #else 
        !           345:        if (NoWait) {
        !           346:                gpr_$cond_event_wait(EventType, EventData[0], EventPosition, *stp);
        !           347:                if (EventType == gpr_$no_event)
        !           348:                        stp->all = ios_$get_conditional_failed;
        !           349:            }
        !           350:        else
        !           351:                gpr_$event_wait(EventType, EventData[0], EventPosition, *stp);
        !           352: #endif
        !           353: 
        !           354:        if (stp->all != status_$ok)
        !           355:                return(0);
        !           356: 
        !           357:        HavePreviewedData = true;
        !           358:        return(1);
        !           359: }
        !           360: 
        !           361: int
        !           362: InitInput()
        !           363: {
        !           364:     boolean flag;
        !           365:     short i;
        !           366:     short KeyClass[256];
        !           367: 
        !           368:     for (i=0; i<255; i++) do KeyClass[i] = 0;
        !           369: 
        !           370:     KeyClass[KBD_$L_BOX_ARROW] = 1;
        !           371:     KeyClass[KBD_$L9] = 1;
        !           372:     KeyClass[KBD_$L9S] = 1;
        !           373:     KeyClass[KBD_$L9U] = 1;
        !           374:     KeyClass[KBD_$CMD] = 1;
        !           375:     lib_$init_set(KeySet,256);
        !           376:     for (i=0; i<256; i++) do
        !           377:         if (KeyClass[i] != 1) 
        !           378:            lib_$add_to_set(KeySet,256,i);
        !           379:     gpr_$enable_input(gpr_$keystroke,KeySet, stp);
        !           380:     gpr_$enable_input(gpr_$buttons, KeySet, stp);
        !           381:     if (!borrow_flag) {
        !           382:         gpr_$enable_input(gpr_$left_window, 0L, stp);
        !           383:         gpr_$enable_input(gpr_$entered_window, 0L, stp);
        !           384:         }
        !           385:     gpr_$enable_input(gpr_$locator_stop, 0L, stp);
        !           386:     gpr_$enable_input(gpr_$locator, 0L, stp);
        !           387:     smd_$set_quit_char( (char)KBD_$F8S, stp );
        !           388:     check_status(stp, "InitInput (Set quit char): ");
        !           389:     xe = &xes;
        !           390: }
        !           391: 
        !           392: hidden boolean gpr_io_$close(hpp, stp)
        !           393:        char **hpp;
        !           394:        status_$t *stp;
        !           395: {
        !           396:        stp->all = status_$ok;
        !           397:        return(false);
        !           398: }
        !           399: 
        !           400: 
        !           401: hidden ios_$conn_flag_set gpr_io_$inq_conn_flags(hpp, stp)
        !           402:        char **hpp;
        !           403:        status_$t *stp;
        !           404: {
        !           405:        stp->all = status_$ok;
        !           406:        return(ios_$cf_tty_mask | ios_$cf_vt_mask);
        !           407: }
        !           408: 
        !           409: 
        !           410: hidden procedure gpr_io_$get_ec(hpp, keyp, ecpp, stp)
        !           411:        char **hpp;
        !           412:        ios_$ec_key_t *keyp;
        !           413:        ec2_$ptr_t *ecpp;
        !           414:        status_$t *stp;
        !           415: {
        !           416:     long foo;
        !           417: 
        !           418:     foo = (long) ec2_$read( *GPREc );
        !           419:        *ecpp = GPREc;
        !           420:     stp->all = status_$ok;             
        !           421: }
        !           422: 
        !           423: #ifdef PRE_SR9_5
        !           424:   hidden long nilp[2] = {0, 0};
        !           425: #else
        !           426: #define nilp 0
        !           427: #endif
        !           428: 
        !           429: io_$epv gpr_io_$epv = {
        !           430:        nilp,
        !           431:        nilp,
        !           432:        nilp,
        !           433:        nilp,
        !           434:        gpr_io_$close,
        !           435:        gpr_io_$get_ec,
        !           436:        nilp,
        !           437:        nilp,
        !           438:        nilp,
        !           439:        gpr_io_$inq_conn_flags,
        !           440:        nilp,
        !           441:        gpr_io_$get,
        !           442:        nilp,
        !           443:        nilp,
        !           444:        nilp,
        !           445:        nilp,
        !           446:        nilp,
        !           447:        nilp,
        !           448:        nilp,
        !           449:        nilp,
        !           450:        nilp,
        !           451:        nilp,
        !           452:        nilp,
        !           453:        nilp,
        !           454:        nilp,
        !           455:        nilp,
        !           456:        nilp,
        !           457:        nilp,
        !           458:        nilp,
        !           459:        nilp,
        !           460:        nilp,
        !           461: };
        !           462: 
        !           463: int
        !           464: MakeGPRStream()
        !           465: {
        !           466:        status_$t Status;
        !           467:        static uid_$t gpr_io_$uid = {0x2f3e1e7a, 0x10003166};
        !           468:         boolean flag;
        !           469: 
        !           470: #ifdef PRE_SR9_5
        !           471:         flag = gpr_$acquire_display(stp);
        !           472: #endif
        !           473:        gpr_$get_ec(gpr_$input_ec,GPREc,Status);
        !           474:        check_status(Status, "MakeGPRStream");
        !           475: #ifdef PRE_SR9_5
        !           476:         gpr_$release_display( stp );
        !           477: #endif
        !           478:        trait_$mgr_dcl(gpr_io_$uid, io_$trait, trait_$kind_local, &gpr_io_$epv, Status);
        !           479:        return (ios_$connect("", (short) 0, gpr_io_$uid, (long) 0, &gpr_io_$epv, Status));
        !           480: }
        !           481: 
        !           482: /*
        !           483:    Universally used; returns -1 if an status is abnormal/error
        !           484:  */
        !           485: int
        !           486: check_status(status, name)
        !           487: status_$t status;        
        !           488: char *name;
        !           489: {
        !           490:     if (status.all != status_$ok) {
        !           491:         fprintf(stderr, "%s", name);
        !           492:         error_$print(status);   
        !           493:        return(-1);
        !           494:     }
        !           495:     return(0);
        !           496: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.