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

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