Example #1
0
File: util.c Project: kjk/qemacs
void keytostr(char *buf, int buf_size, int key)
{
    int i;
    char buf1[32];
    
    for (i = 0; i < (int)(sizeof(keycodes)/sizeof(keycodes[0])); i++) {
        if (keycodes[i] == key) {
            pstrcpy(buf, buf_size, keystr[i]);
            return;
        }
    }
    if (key >= KEY_META(0) && key <= KEY_META(0xff)) {
        keytostr(buf1, sizeof(buf1), key & 0xff);
        snprintf(buf, buf_size, "M-%s", buf1);
    } else if (key >= KEY_CTRL('a') && key <= KEY_CTRL('z')) {
        snprintf(buf, buf_size, "C-%c", key + 'a' - 1);
    } else if (key >= KEY_F1 && key <= KEY_F20) {
        snprintf(buf, buf_size, "f%d", key - KEY_F1 + 1);
    } else if (key > 32 && key < 127 && buf_size >= 2) {
        buf[0] = key;
        buf[1] = '\0';
    } else {
        char *q;
        q = utf8_encode(buf1, key);
        *q = '\0';
        pstrcpy(buf, buf_size, buf1);
    }
}
Example #2
0
int strtokey(const char **pp)
{
    const char *p;
    int key;

    /* XXX: handle all cases */
    p = *pp;
    if (p[0] == 'C' && p[1] == '-') {
        /* control */
        p += 2;
        key = strtokey1(p);
        if (key >= 'a' && key <= 'z')
            key = KEY_CTRL(key);
    } else if (p[0] == 'M' && p[1] == '-') { 
        p += 2;
        key = strtokey1(p);
        if ((key >= 'a' && key <= 'z') ||
            key == KEY_BACKSPACE)
            key = KEY_META(key);
    } else {
        key = strtokey1(p);
    }
    while (*p != ' ' && *p != '\0')
        p++;
    *pp = p;
    return key;
}
Example #3
0
File: util.c Project: kjk/qemacs
int strtokey(const char **pp)
{
    const char *p;
    int key;

    p = *pp;
    if (p[0] == 'M' && p[1] == '-') {
        p += 2;
        key = KEY_META(strtokey1(&p));
    } else
    if (p[0] == 'C' && p[1] == '-' && p[0] == 'M' && p[1] == '-') {
        p += 4;
        key = KEY_META(KEY_CTRL(strtokey1(&p)));
    } else {
        key = strtokey1(&p);
    }
    *pp = p;
    return key;
}
Example #4
0
void keytostr(char *buf, int buf_size, int key)
{
    int i;
    char buf1[32];
    
    for(i=0;i<sizeof(keycodes)/sizeof(keycodes[0]);i++) {
        if (keycodes[i] == key) {
            pstrcpy(buf, buf_size, keystr[i]);
            return;
        }
    }
    if (key >= KEY_META(' ') && key <= KEY_META(127)) {
        keytostr(buf1, sizeof(buf1), key & 0xff);
        snprintf(buf, buf_size, "M-%s", buf1);
    } else if (key >= 1 && key <= 31) {
        snprintf(buf, buf_size, "C-%c", key + 'a' - 1);
    } else if (key >= KEY_F1 && key <= KEY_F12) {
        snprintf(buf, buf_size, "F%d", key - KEY_F1 + 1);
    } else {
        char *q;
        q = utf8_encode(buf, key);
        *q = '\0';
    }
}
Example #5
0
File: util.c Project: kjk/qemacs
int compose_keys(unsigned int *keys, int *nb_keys)
{
    unsigned int *keyp;

    if (*nb_keys < 2)
        return 0;

    /* compose KEY_ESC as META prefix */
    keyp = keys + *nb_keys - 2;
    if (keyp[0] == KEY_ESC) {
        if (keyp[1] <= 0xff) {
            keyp[0] = KEY_META(keyp[1]);
            --*nb_keys;
            return 1;
        }
    }
    return 0;
}
Example #6
0
File: shell.c Project: kjk/qemacs
void shell_key(void *opaque, int key)
{
    ShellState *s = opaque;
    char buf[10];
    const char *p;
    int len;

    if (key == KEY_CTRL('o')) {
        qe_ungrab_keys();
        unget_key(key);
        return;
    }
    p = buf;
    len = -1;
    switch (key) {
    case KEY_UP:        p = s->kcuu1; break;
    case KEY_DOWN:      p = s->kcud1; break;
    case KEY_RIGHT:     p = s->kcuf1; break;
    case KEY_LEFT:      p = s->kcub1; break;
    //case KEY_CTRL_UP:
    //case KEY_CTRL_DOWN:
    //case KEY_CTRL_RIGHT:
    //case KEY_CTRL_LEFT:
    //case KEY_CTRL_END:
    //case KEY_CTRL_HOME:
    //case KEY_CTRL_PAGEUP:
    //case KEY_CTRL_PAGEDOWN:
    case KEY_SHIFT_TAB: p = s->kcbt; break;
    case KEY_HOME:      p = s->khome; break;
    case KEY_INSERT:    p = s->kich1; break;
    case KEY_DELETE:    p = s->kdch1; break;
    case KEY_END:       p = s->kend; break;
    case KEY_PAGEUP:    p = s->kpp; break;
    case KEY_PAGEDOWN:  p = s->knp; break;
    case KEY_F1:        p = s->kf1; break;
    case KEY_F2:        p = s->kf2; break;
    case KEY_F3:        p = s->kf3; break;
    case KEY_F4:        p = s->kf4; break;
    case KEY_F5:        p = s->kf5; break;
    case KEY_F6:        p = s->kf6; break;
    case KEY_F7:        p = s->kf7; break;
    case KEY_F8:        p = s->kf8; break;
    case KEY_F9:        p = s->kf9; break;
    case KEY_F10:       p = s->kf10; break;
    case KEY_F11:       p = s->kf11; break;
    case KEY_F12:       p = s->kf12; break;
    case KEY_F13:       p = s->kf13; break;
    case KEY_F14:       p = s->kf14; break;
    case KEY_F15:       p = s->kf15; break;
    case KEY_F16:       p = s->kf16; break;
    case KEY_F17:       p = s->kf17; break;
    case KEY_F18:       p = s->kf18; break;
    case KEY_F19:       p = s->kf19; break;
    case KEY_F20:       p = s->kf20; break;
    default:
        if (key < 256) {
            buf[0] = key;
            len = 1;
        } else
        if (key >= KEY_META(0) && key <= KEY_META(255)) {
            buf[0] = '\033';
            buf[1] = key;
            len = 2;
        } else {
            p = NULL;
        }
        break;
    } 
    if (p)
        tty_write(s, p, len);
}
Example #7
0
void QEQtView::keyPressEvent (QKeyEvent *event)
{
    qDebug() << Q_FUNC_INFO << QKeySequence(event->key()).toString();

    QEKeyEvent ev;
    ev.type = QE_KEY_EVENT;
    ev.key = KEY_NONE;

    bool ctrl = event->modifiers() & Qt::ControlModifier;
    bool shift = event->modifiers() & Qt::ShiftModifier;
    bool meta = event->modifiers() & Qt::AltModifier;

    switch (event->key()) {
    // in the same order as qe.h
    case Qt::Key_Tab:
        ev.key = shift ? KEY_SHIFT_TAB : KEY_TAB;
        break;
    case Qt::Key_Return:
        ev.key = KEY_RET;
        break;
    case Qt::Key_Escape:
        ev.key = KEY_ESC;
        break;
    case Qt::Key_Space:
        ev.key = KEY_SPC;
        break;
    //case Qt::Key_????:
        //ev.key = KEY_DEL;
        //break;
    case Qt::Key_Backspace:
        ev.key = meta ? KEY_META(KEY_DEL) : KEY_DEL;
        break;
    case Qt::Key_Up:
        ev.key = ctrl ? KEY_CTRL_UP : KEY_UP;
        break;
    case Qt::Key_Down:
        ev.key = ctrl ? KEY_CTRL_DOWN : KEY_DOWN;
        break;
    case Qt::Key_Right:
        ev.key = ctrl ? KEY_CTRL_RIGHT: KEY_RIGHT;
        break;
    case Qt::Key_Left:
        ev.key = ctrl ? KEY_CTRL_LEFT : KEY_LEFT;
        break;
    case Qt::Key_End:
        ev.key = ctrl ? KEY_CTRL_END : KEY_END;
        break;
   case Qt::Key_Home:
        ev.key = ctrl ? KEY_CTRL_HOME : KEY_HOME;
        break;
   case Qt::Key_PageUp:
        ev.key = ctrl ? KEY_CTRL_PAGEUP : KEY_PAGEUP;
        break;
   case Qt::Key_PageDown:
        ev.key = ctrl ? KEY_CTRL_PAGEDOWN : KEY_PAGEDOWN;
        break;
   case Qt::Key_Insert:
        ev.key = KEY_INSERT;
        break;
   case Qt::Key_Delete:
        ev.key = KEY_DELETE;
        break;
   case Qt::Key_F1:
        ev.key = KEY_F1;
        break;
   case Qt::Key_F2:
        ev.key = KEY_F2;
        break;
   case Qt::Key_F3:
        ev.key = KEY_F3;
        break;
   case Qt::Key_F4:
        ev.key = KEY_F4;
        break;
   case Qt::Key_F5:
        ev.key = KEY_F5;
        break;
   case Qt::Key_F6:
        ev.key = KEY_F6;
        break;
   case Qt::Key_F7:
        ev.key = KEY_F7;
        break;
   case Qt::Key_F8:
        ev.key = KEY_F8;
        break;
   case Qt::Key_F9:
        ev.key = KEY_F9;
        break;
   case Qt::Key_F10:
        ev.key = KEY_F10;
        break;
   case Qt::Key_F11:
        ev.key = KEY_F11;
        break;
   case Qt::Key_F12:
        ev.key = KEY_F12;
        break;
   case Qt::Key_F13:
        ev.key = KEY_F13;
        break;
   case Qt::Key_F14:
        ev.key = KEY_F14;
        break;
   case Qt::Key_F15:
        ev.key = KEY_F15;
        break;
   case Qt::Key_F16:
        ev.key = KEY_F16;
        break;
   case Qt::Key_F17:
        ev.key = KEY_F17;
        break;
   case Qt::Key_F18:
        ev.key = KEY_F18;
        break;
   case Qt::Key_F19:
        ev.key = KEY_F19;
        break;
   case Qt::Key_F20:
        ev.key = KEY_F20;
        break;
    case Qt::Key_Control:
    case Qt::Key_Meta:
    case Qt::Key_Alt:
    case Qt::Key_AltGr:
    default:
        if (event->text().isEmpty()) {
            qDebug() << Q_FUNC_INFO << "empty key" << event->nativeScanCode();
            return;
        }

        int key = event->text().at(0).toLatin1();
        if (ctrl) {
            ev.key = KEY_CTRL(key);
        }
        else if (meta) {
            ev.key = KEY_META(' ') + key - ' ';
        }
        else {
            ev.key = key;
        }
        qDebug() << Q_FUNC_INFO << " other key" << event->nativeScanCode();
    }

    write(_ctx->events_wr, &ev, sizeof(QEEvent));
}
Example #8
0
static void do_toggle_hex(EditState *s)
{
    s->hex_mode = !s->hex_mode;
}

/* specific hex commands */
static CmdDef hex_commands[] = {
    CMD1( KEY_CTRL_LEFT, KEY_NONE,
          "decrease-width", do_incr_width, -1)
    CMD1( KEY_CTRL_RIGHT, KEY_NONE,
          "increase-width", do_incr_width, 1)
    CMD2( KEY_NONE, KEY_NONE,
          "set-width", do_set_width, ESi,
          "ui{Width: }")
    CMD3( KEY_META('g'), KEY_NONE,
          "goto-byte", do_goto, ESsi, 'b',
          "us{Goto byte: }"
          "v")
    CMD0( KEY_NONE, KEY_NONE,
          "toggle-hex", do_toggle_hex)
    CMD_DEF_END,
};

static int ascii_mode_init(EditState *s, ModeSavedData *saved_data)
{
    QEFont *font;
    QEStyleDef style;
    int num_width;
    int ret;
Example #9
0
static CmdDef org_commands[] = {
    /* Motion */
    CMD2( KEY_CTRLC(KEY_CTRL('n')), KEY_NONE,   /* C-c C-n */
          "outline-next-visible-heading", do_outline_next_vsible_heading, ES, "")
    CMD2( KEY_CTRLC(KEY_CTRL('p')), KEY_NONE,   /* C-c C-p */
          "outline-previous-visible-heading", do_outline_previous_vsible_heading, ES, "")
    CMD2( KEY_CTRLC(KEY_CTRL('u')), KEY_NONE,   /* C-c C-u */
          "outline-up-heading", do_outline_up_heading, ES, "")
    CMD2( KEY_CTRLC(KEY_CTRL('b')), KEY_NONE,   /* C-c C-b */
          "org-backward-same-level", do_org_backward_same_level, ES, "")
    CMD2( KEY_CTRLC(KEY_CTRL('f')), KEY_NONE,   /* C-c C-f */
          "org-forward-same-level", do_org_forward_same_level, ES, "")
    CMD2( KEY_CTRLC(KEY_CTRL('j')), KEY_NONE,   /* C-c C-j */
          "org-goto", do_org_goto, ESs,
          "s{select location to jump to: }[orgjump]|orgjump|")
    CMD3( KEY_META('h'), KEY_NONE,   /* M-h */
          "org-mark-element", do_org_mark_element, ESi, 0, "v")
    CMD3( KEY_CTRLC('@'), KEY_NONE,   /* C-c @ */
          "org-mark-subtree", do_org_mark_element, ESi, 1, "v")
    /* Editing */
    CMD2( KEY_CTRLC(KEY_CTRL('t')), KEY_NONE,   /* C-c C-t */
          "org-todo", do_org_todo, ES, "*")
    CMD3( KEY_NONE, KEY_NONE,    /* indirect through M-RET */
          "org-insert-heading", do_org_insert_heading, ESi, 0, "*v")
    CMD3( KEY_NONE, KEY_NONE,    /* actually M-S-RET and C-c C-x M */
          "org-insert-todo-heading", do_org_insert_heading, ESi, 1, "*v")
    CMD3( KEY_CTRL('j'), KEY_NONE,    /* actually C-RET */
          "org-insert-heading-respect-content", do_org_insert_heading, ESi, 2, "*v")
    CMD3( KEY_NONE, KEY_NONE,    /* actually C-S-RET */
          "org-insert-todo-heading-respect-content", do_org_insert_heading, ESi, 3, "*v")
    CMD3( KEY_NONE, KEY_NONE,