Annotation of uae/src/hotkeys.c, revision 1.1.1.1

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   *
                      4:   * Target-independent support for parsing hotkey sequences
                      5:   *
                      6:   * Copyright 2004 Richard Drummond
                      7:   *
                      8:   * Based on the hotkey handling previously found
                      9:   * in x11win.c and sdlgfx.c
                     10:   */
                     11: 
                     12: #include "sysconfig.h"
                     13: #include "sysdeps.h"
                     14: #include "options.h"
                     15: #include "inputdevice.h"
                     16: #include "hotkeys.h"
                     17: 
                     18: 
                     19: static struct uae_hotkeyseq *hotkey_table;
                     20: 
                     21: 
                     22: void set_default_hotkeys (struct uae_hotkeyseq *keys)
                     23: {
                     24:     hotkey_table = keys;
                     25:     reset_hotkeys ();
                     26: }
                     27: 
                     28: void reset_hotkeys (void) {
                     29:     struct uae_hotkeyseq *seq = hotkey_table;
                     30:     int i;
                     31: 
                     32:     if (!seq)
                     33:        return;
                     34: 
                     35:     while (seq->event) {
                     36:        for (i=0; i < HOTKEYSEQ_MAXKEYS; i++)
                     37:            seq->key_pressed[i] = 0;
                     38:        seq->complete = 0;
                     39:        seq++;
                     40:     }
                     41: }
                     42: 
                     43: int match_hotkey_sequence (int key, int state)
                     44: {
                     45:     struct uae_hotkeyseq *seq = hotkey_table;
                     46:     int event = 0;
                     47: 
                     48:     if (!seq)
                     49:        return 0;
                     50: 
                     51:     if (state) {
                     52:        /* Key down */
                     53:        while (seq->event != 0) {
                     54:            int i;
                     55:            /* Check whether key is the next key in this sequence */
                     56:            if (key == seq->keyseq[0])
                     57:                seq->key_pressed[0] = 1;
                     58:            for (i=1; i < HOTKEYSEQ_MAXKEYS; i++) {
                     59:                if ((seq->key_pressed[i-1] == 1) && (key == seq->keyseq[i])) {
                     60:                    seq->key_pressed[i] = 1;
                     61:                    /* Was it the final key in this sequence ? */
                     62:                    if ((i+1 == HOTKEYSEQ_MAXKEYS) || (seq->keyseq[i+1] == (uae_u16)-1)) {
                     63:                        /* Yes. Return the event */
                     64:                        event = seq->event;
                     65:                        seq->complete = 1;
                     66:                        break;
                     67:                    }
                     68:                }
                     69:            }
                     70:            seq++;
                     71:        }
                     72:     } else {
                     73:        /* key up */
                     74:        while (seq->event != 0) {
                     75:            int i, j;
                     76:            for (i = 0; i < HOTKEYSEQ_MAXKEYS; i++) {
                     77:                if ((key == seq->keyseq[i]) && (seq->key_pressed[i] == 1)) {
                     78:                    /* letting up a key - cancels any keys following it
                     79:                     * in the sequence that are pressed */
                     80:                    for (j=i; j < HOTKEYSEQ_MAXKEYS; j++)
                     81:                        seq->key_pressed[j] = 0;
                     82:                    /* if it was previously complete generate return the event
                     83:                     * (so that it can be used as a key-up event */
                     84:                    if (seq->complete) {
                     85:                        seq->complete = 0;
                     86:                        event = seq->event;
                     87:                    }
                     88:                }
                     89:            }
                     90:            seq++;
                     91:        }
                     92:     }
                     93:     return event;
                     94: }

unix.superglobalmegacorp.com

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