source: trunk/tools/neercs/old/input.c @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

  • Property svn:keywords set to Id
File size: 5.6 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://www.wtfpl.net/ for more details.
13 */
14
15#if defined HAVE_CONFIG_H
16#   include "config.h"
17#endif
18
19#include <caca.h>
20#include <string.h>
21#include "neercs.h"
22
23struct kconv
24{
25    unsigned int key;
26    char *val;
27    int size;
28};
29
30struct kconv kconv[] = {
31    {CACA_KEY_UP, "\033OA", 3},
32    {CACA_KEY_DOWN, "\033OB", 3},
33    {CACA_KEY_RIGHT, "\033OC", 3},
34    {CACA_KEY_LEFT, "\033OD", 3},
35    {CACA_KEY_PAGEUP, "\033[5~", 4},
36    {CACA_KEY_PAGEDOWN, "\033[6~", 4},
37    {CACA_KEY_HOME, "\033[1~", 4},
38    {CACA_KEY_INSERT, "\033[2~", 4},
39    {CACA_KEY_DELETE, "\033[3~", 4},
40    {CACA_KEY_END, "\033[4~", 4},
41    {CACA_KEY_F1, "\033[11~", 5},
42    {CACA_KEY_F2, "\033[12~", 5},
43    {CACA_KEY_F3, "\033[13~", 5},
44    {CACA_KEY_F4, "\033[14~", 5},
45    {CACA_KEY_F5, "\033[15~", 5},
46    {CACA_KEY_F6, "\033[17~", 5},
47    {CACA_KEY_F7, "\033[18~", 5},
48    {CACA_KEY_F8, "\033[19~", 5},
49    {CACA_KEY_F9, "\033[20~", 5},
50    {CACA_KEY_F10, "\033[21~", 5},
51    {CACA_KEY_F11, "\033[23~", 5},
52    {CACA_KEY_F12, "\033[24~", 5},
53};
54
55
56
57void *convert_input_ansi(unsigned int *c, int *size)
58{
59    unsigned int i;
60    for (i = 0; i < sizeof(kconv) / sizeof(struct kconv); i++)
61    {
62        if (*c == kconv[i].key)
63        {
64            *size = kconv[i].size;
65            return kconv[i].val;
66        }
67    }
68
69    *size = 1;
70    return c;
71}
72
73
74
75int handle_command_input(struct screen_list *screen_list, unsigned int c)
76{
77    int refresh = 0;
78
79#if !defined _WIN32
80    debug("Key %x\n", c);
81    screen_list->changed = 1;
82
83    if (c >= '0' && c <= '9')
84    {
85        int n = c - 49;
86        if (n < screen_list->count)
87        {
88            screen_list->prevpty = screen_list->pty;
89            screen_list->pty = n == -1 ? 10 : n;
90            return 1;
91        }
92        else
93        {
94            return 0;
95        }
96    }
97
98    switch (c)
99    {
100    case 0x01:                 // CACA_KEY_CTRL_A:
101        screen_list->pty ^= screen_list->prevpty;
102        screen_list->prevpty ^= screen_list->pty;
103        screen_list->pty ^= screen_list->prevpty;
104        refresh = 1;
105        break;
106    case 'm':
107    case 0x0d:                 // CACA_KEY_CTRL_M:
108        screen_list->modals.mini = !screen_list->modals.mini;
109        refresh = 1;
110        break;
111    case 'n':
112    case ' ':
113    case '\0':
114    case 0x0e:                 // CACA_KEY_CTRL_N:
115        screen_list->prevpty = screen_list->pty;
116        screen_list->pty = (screen_list->pty + 1) % screen_list->count;
117        if (screen_list->pty != screen_list->prevpty)
118        {
119            screen_list->last_switch = get_us();
120            screen_list->cube.in_switch = 1;
121            screen_list->cube.side = 0;
122        }
123        refresh = 1;
124        break;
125    case 'p':
126    case 0x10:                 // CACA_KEY_CTRL_P:
127        screen_list->prevpty = screen_list->pty;
128        screen_list->pty =
129            (screen_list->pty + screen_list->count - 1) % screen_list->count;
130        if (screen_list->pty != screen_list->prevpty)
131        {
132            screen_list->last_switch = get_us();
133            screen_list->cube.in_switch = 1;
134            screen_list->cube.side = 1;
135        }
136        refresh = 1;
137        break;
138    case 'c':
139    case 0x03:                 // CACA_KEY_CTRL_C:
140        screen_list->prevpty = screen_list->pty;
141        screen_list->pty =
142            add_screen(screen_list,
143                       create_screen(screen_list->width,
144                                     screen_list->height,
145                                     screen_list->sys.default_shell));
146        refresh = 1;
147        break;
148    case 'w':
149    case 0x17:                 // CACA_KEY_CTRL_W:
150        screen_list->wm_type = (screen_list->wm_type == (WM_MAX - 1) ?
151                                screen_list->wm_type = 0 :
152                                screen_list->wm_type + 1);
153        refresh = 1;
154        break;
155    case 'k':
156    case 0x0b:                 // CACA_KEY_CTRL_K:
157        add_recurrent(screen_list->recurrent_list, close_screen_recurrent,
158                      screen_list->cv);
159        refresh = 1;
160        break;
161    case 'x':
162    case 0x18:                 // CACA_KEY_CTRL_X:
163        memset(screen_list->lock.lockpass, 0, 1024);
164        screen_list->lock.locked = 1;
165        screen_list->lock.lock_offset = 0;
166        refresh = 1;
167        break;
168    case 'h':
169    case 0x08:                 // CACA_KEY_CTRL_H:
170        dump_to_file(screen_list);
171        break;
172    case '?':
173        screen_list->modals.help = !screen_list->modals.help;
174        refresh = 1;
175        break;
176    case '"':
177    case 0x34:                 // CTRL+"
178        screen_list->modals.cur_in_list = screen_list->pty;
179        screen_list->modals.window_list = !screen_list->modals.window_list;
180        refresh = 1;
181        break;
182    case 'd':
183    case 0x04:                 // CACA_KEY_CTRL_D:
184        detach(screen_list);
185        break;
186#ifdef USE_PYTHON
187    case 'e':
188    case 0x05:
189        debug("py : command is %d, setting to 1 (at %p)\n", screen_list->modals.python_command, &screen_list->modals.python_command);
190        screen_list->modals.python_command = 1;
191        refresh = 1;
192        break;
193#endif
194    }
195#endif /* _WIN32 */
196    return refresh;
197
198}
Note: See TracBrowser for help on using the repository browser.