source: neercs/trunk/src/input.c @ 4036

Last change on this file since 4036 was 4036, checked in by Jean-Yves Lamoureux, 11 years ago
  • Added 'ctrl-a ctrl-e' as a possible way to enter mini-command
  • Property svn:keywords set to Id
File size: 5.4 KB
RevLine 
[3968]1/*
[2495]2 *  neercs        console-based window manager
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                2008 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                2008 Pascal Terjan <pterjan@linuxfr.org>
6 *                All Rights Reserved
7 *
[3551]8 *  $Id: input.c 4036 2009-11-25 12:23:32Z jylam $
[2495]9 *
10 *  This program is free software. It comes without any warranty, to
11 *  the extent permitted by applicable law. You can redistribute it
12 *  and/or modify it under the terms of the Do What The Fuck You Want
13 *  To Public License, Version 2, as published by Sam Hocevar. See
14 *  http://sam.zoy.org/wtfpl/COPYING for more details.
15 */
16#include "config.h"
17#include <caca.h>
18#include <string.h>
19#include "neercs.h"
20
[3968]21struct kconv
22{
[2495]23    unsigned int key;
24    char *val;
25    int size;
26};
27
28struct kconv kconv[] = {
[3968]29    {CACA_KEY_UP, "\033OA", 3},
30    {CACA_KEY_DOWN, "\033OB", 3},
31    {CACA_KEY_RIGHT, "\033OC", 3},
32    {CACA_KEY_LEFT, "\033OD", 3},
33    {CACA_KEY_PAGEUP, "\033[5~", 4},
34    {CACA_KEY_PAGEDOWN, "\033[6~", 4},
35    {CACA_KEY_HOME, "\033[1~", 4},
36    {CACA_KEY_INSERT, "\033[2~", 4},
37    {CACA_KEY_DELETE, "\033[3~", 4},
38    {CACA_KEY_END, "\033[4~", 4},
39    {CACA_KEY_F1, "\033[11~", 5},
40    {CACA_KEY_F2, "\033[12~", 5},
41    {CACA_KEY_F3, "\033[13~", 5},
42    {CACA_KEY_F4, "\033[14~", 5},
43    {CACA_KEY_F5, "\033[15~", 5},
44    {CACA_KEY_F6, "\033[17~", 5},
45    {CACA_KEY_F7, "\033[18~", 5},
46    {CACA_KEY_F8, "\033[19~", 5},
47    {CACA_KEY_F9, "\033[20~", 5},
48    {CACA_KEY_F10, "\033[21~", 5},
49    {CACA_KEY_F11, "\033[23~", 5},
50    {CACA_KEY_F12, "\033[24~", 5},
[2495]51};
52
53
54
55void *convert_input_ansi(unsigned int *c, int *size)
56{
57    unsigned int i;
[3968]58    for (i = 0; i < sizeof(kconv) / sizeof(struct kconv); i++)
[2495]59    {
[3968]60        if (*c == kconv[i].key)
[2495]61        {
62            *size = kconv[i].size;
[3968]63            return kconv[i].val;
[2495]64        }
65    }
66
67    *size = 1;
68    return c;
69}
70
71
72
[3968]73int handle_command_input(struct screen_list *screen_list, unsigned int c)
[2495]74{
75    int refresh = 0;
[2639]76
[2641]77    debug("Key %x\n", c);
[3453]78    screen_list->changed = 1;
[2641]79
[3968]80    if (c >= '0' && c <= '9')
[2639]81    {
[3968]82        int n = c - 49;
83        if (n < screen_list->count)
84        {
[2639]85            screen_list->prevpty = screen_list->pty;
[3968]86            screen_list->pty = n == -1 ? 10 : n;
[2639]87            return 1;
[3968]88        }
89        else
90        {
[2639]91            return 0;
92        }
93    }
94
[3968]95    switch (c)
[2495]96    {
[3968]97    case 0x01:                 // CACA_KEY_CTRL_A:
[2495]98        screen_list->pty ^= screen_list->prevpty;
99        screen_list->prevpty ^= screen_list->pty;
100        screen_list->pty ^= screen_list->prevpty;
101        refresh = 1;
102        break;
103    case 'm':
[3968]104    case 0x0d:                 // CACA_KEY_CTRL_M:
[2495]105        screen_list->mini = !screen_list->mini;
106        refresh = 1;
107        break;
108    case 'n':
109    case ' ':
110    case '\0':
[3968]111    case 0x0e:                 // CACA_KEY_CTRL_N:
[2495]112        screen_list->prevpty = screen_list->pty;
113        screen_list->pty = (screen_list->pty + 1) % screen_list->count;
[3968]114        if (screen_list->pty != screen_list->prevpty)
115        {
116            screen_list->last_switch = get_us();
117            screen_list->cube.in_switch = 1;
118            screen_list->cube.side = 0;
119        }
[2495]120        refresh = 1;
121        break;
122    case 'p':
[3968]123    case 0x10:                 // CACA_KEY_CTRL_P:
[2495]124        screen_list->prevpty = screen_list->pty;
[3968]125        screen_list->pty =
126            (screen_list->pty + screen_list->count - 1) % screen_list->count;
127        if (screen_list->pty != screen_list->prevpty)
128        {
129            screen_list->last_switch = get_us();
130            screen_list->cube.in_switch = 1;
131            screen_list->cube.side = 1;
132        }
[2495]133        refresh = 1;
134        break;
135    case 'c':
[3968]136    case 0x03:                 // CACA_KEY_CTRL_C:
[2495]137        screen_list->prevpty = screen_list->pty;
138        screen_list->pty =
139            add_screen(screen_list,
140                       create_screen(screen_list->width,
141                                     screen_list->height,
142                                     screen_list->default_shell));
143        refresh = 1;
144        break;
145    case 'w':
[3968]146    case 0x17:                 // CACA_KEY_CTRL_W:
147        screen_list->wm_type = (screen_list->wm_type == (WM_MAX - 1) ?
148                                screen_list->wm_type = 0 :
149                                screen_list->wm_type + 1);
[2495]150        refresh = 1;
151        break;
[2626]152    case 'k':
[3968]153    case 0x0b:                 // CACA_KEY_CTRL_K:
154        add_recurrent(screen_list->recurrent_list, close_screen_recurrent,
155                      screen_list->cv);
[2495]156        refresh = 1;
157        break;
158    case 'x':
[3968]159    case 0x18:                 // CACA_KEY_CTRL_X:
[2495]160        memset(screen_list->lockpass, 0, 1024);
161        screen_list->locked = 1;
162        screen_list->lock_offset = 0;
163        refresh = 1;
164        break;
165    case 'h':
[2581]166    case '?':
[3968]167    case 0x08:                 // CACA_KEY_CTRL_H:
[2495]168        screen_list->help = !screen_list->help;
169        refresh = 1;
170        break;
[2641]171    case '"':
[3968]172    case 0x34:                 // CTRL+"
[2641]173        screen_list->cur_in_list = screen_list->pty;
174        screen_list->window_list = !screen_list->window_list;
175        refresh = 1;
176        break;
[2495]177    case 'd':
[3968]178    case 0x04:                 // CACA_KEY_CTRL_D:
[2588]179        detach(screen_list);
[2495]180        break;
[4026]181#ifdef USE_PYTHON
182    case 'e':
[4036]183    case 0x05:
184           
[4026]185        screen_list->python_command = 1;
[4033]186        screen_list->interpreter_props.x = 0;
187        screen_list->interpreter_props.y = 0;
[4026]188        break;
189#endif
[2495]190    }
191    return refresh;
192
193}
Note: See TracBrowser for help on using the repository browser.