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

Last change on this file since 1656 was 1656, checked in by sam, 10 years ago

neercs: start porting the old code to Windows; this breaks the Visual Studio
build until further fixes are made.

  • 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://sam.zoy.org/wtfpl/COPYING 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    debug("Key %x\n", c);
80    screen_list->changed = 1;
81
82    if (c >= '0' && c <= '9')
83    {
84        int n = c - 49;
85        if (n < screen_list->count)
86        {
87            screen_list->prevpty = screen_list->pty;
88            screen_list->pty = n == -1 ? 10 : n;
89            return 1;
90        }
91        else
92        {
93            return 0;
94        }
95    }
96
97    switch (c)
98    {
99    case 0x01:                 // CACA_KEY_CTRL_A:
100        screen_list->pty ^= screen_list->prevpty;
101        screen_list->prevpty ^= screen_list->pty;
102        screen_list->pty ^= screen_list->prevpty;
103        refresh = 1;
104        break;
105    case 'm':
106    case 0x0d:                 // CACA_KEY_CTRL_M:
107        screen_list->modals.mini = !screen_list->modals.mini;
108        refresh = 1;
109        break;
110    case 'n':
111    case ' ':
112    case '\0':
113    case 0x0e:                 // CACA_KEY_CTRL_N:
114        screen_list->prevpty = screen_list->pty;
115        screen_list->pty = (screen_list->pty + 1) % screen_list->count;
116        if (screen_list->pty != screen_list->prevpty)
117        {
118            screen_list->last_switch = get_us();
119            screen_list->cube.in_switch = 1;
120            screen_list->cube.side = 0;
121        }
122        refresh = 1;
123        break;
124    case 'p':
125    case 0x10:                 // CACA_KEY_CTRL_P:
126        screen_list->prevpty = screen_list->pty;
127        screen_list->pty =
128            (screen_list->pty + screen_list->count - 1) % screen_list->count;
129        if (screen_list->pty != screen_list->prevpty)
130        {
131            screen_list->last_switch = get_us();
132            screen_list->cube.in_switch = 1;
133            screen_list->cube.side = 1;
134        }
135        refresh = 1;
136        break;
137    case 'c':
138    case 0x03:                 // CACA_KEY_CTRL_C:
139        screen_list->prevpty = screen_list->pty;
140        screen_list->pty =
141            add_screen(screen_list,
142                       create_screen(screen_list->width,
143                                     screen_list->height,
144                                     screen_list->sys.default_shell));
145        refresh = 1;
146        break;
147    case 'w':
148    case 0x17:                 // CACA_KEY_CTRL_W:
149        screen_list->wm_type = (screen_list->wm_type == (WM_MAX - 1) ?
150                                screen_list->wm_type = 0 :
151                                screen_list->wm_type + 1);
152        refresh = 1;
153        break;
154    case 'k':
155    case 0x0b:                 // CACA_KEY_CTRL_K:
156        add_recurrent(screen_list->recurrent_list, close_screen_recurrent,
157                      screen_list->cv);
158        refresh = 1;
159        break;
160    case 'x':
161    case 0x18:                 // CACA_KEY_CTRL_X:
162        memset(screen_list->lock.lockpass, 0, 1024);
163        screen_list->lock.locked = 1;
164        screen_list->lock.lock_offset = 0;
165        refresh = 1;
166        break;
167    case 'h':
168    case 0x08:                 // CACA_KEY_CTRL_H:
169        dump_to_file(screen_list);
170        break;
171    case '?':
172        screen_list->modals.help = !screen_list->modals.help;
173        refresh = 1;
174        break;
175    case '"':
176    case 0x34:                 // CTRL+"
177        screen_list->modals.cur_in_list = screen_list->pty;
178        screen_list->modals.window_list = !screen_list->modals.window_list;
179        refresh = 1;
180        break;
181    case 'd':
182    case 0x04:                 // CACA_KEY_CTRL_D:
183        detach(screen_list);
184        break;
185#ifdef USE_PYTHON
186    case 'e':
187    case 0x05:
188        debug("py : command is %d, setting to 1 (at %p)\n", screen_list->modals.python_command, &screen_list->modals.python_command);
189        screen_list->modals.python_command = 1;
190        refresh = 1;
191        break;
192#endif
193    }
194    return refresh;
195
196}
Note: See TracBrowser for help on using the repository browser.