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

Last change on this file since 3433 was 3433, checked in by Pascal Terjan, 11 years ago
  • Fix ansi values for F5-F12 keys
File size: 4.6 KB
Line 
1/*
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 *
8 *  $Id: input.c 2493 2008-06-27 17:55:06Z sam $
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
21struct kconv {
22    unsigned int key;
23    char *val;
24    int size;
25};
26
27struct kconv kconv[] = {
28    {CACA_KEY_UP,      "\x1b[A",   3},
29    {CACA_KEY_DOWN,    "\x1b[B",   3},
30    {CACA_KEY_RIGHT,   "\x1b[C",   3},
31    {CACA_KEY_LEFT,    "\x1b[D",   3},
32    {CACA_KEY_PAGEUP,  "\x1b[5~",  4},
33    {CACA_KEY_PAGEDOWN,"\x1b[6~",  4},
34    {CACA_KEY_HOME,    "\x1b[1~",  4},
35    {CACA_KEY_INSERT,  "\x1b[2~",  4},
36    {CACA_KEY_DELETE,  "\x1b[3~",  4},
37    {CACA_KEY_END,     "\x1b[4~",  4},
38    {CACA_KEY_F1,      "\x1b[11~", 5},
39    {CACA_KEY_F2,      "\x1b[12~", 5},
40    {CACA_KEY_F3,      "\x1b[13~", 5},
41    {CACA_KEY_F4,      "\x1b[14~", 5},
42    {CACA_KEY_F5,      "\x1b[15~", 5},
43    {CACA_KEY_F6,      "\x1b[17~", 5},
44    {CACA_KEY_F7,      "\x1b[18~", 5},
45    {CACA_KEY_F8,      "\x1b[19~", 5},
46    {CACA_KEY_F9,      "\x1b[20~", 5},
47    {CACA_KEY_F10,     "\x1b[21~", 5},
48    {CACA_KEY_F11,     "\x1b[23~", 5},
49    {CACA_KEY_F12,     "\x1b[24~", 5},
50};
51
52
53
54void *convert_input_ansi(unsigned int *c, int *size)
55{
56    unsigned int i;
57    for(i = 0; i < sizeof(kconv) / sizeof(struct kconv); i++)
58    {
59        if(*c==kconv[i].key)
60        {
61            *size = kconv[i].size;
62            return  kconv[i].val;
63        }
64    }
65
66    *size = 1;
67    return c;
68}
69
70
71
72int handle_command_input(struct screen_list*screen_list, unsigned int c)
73{
74    int refresh = 0;
75
76    debug("Key %x\n", c);
77
78    if(c >= '0' && c<='9')
79    {
80        int n = c-49;
81        if(n<screen_list->count) {
82            screen_list->prevpty = screen_list->pty;
83            screen_list->pty = n==-1?10:n;
84            return 1;
85        } else {
86            return 0;
87        }
88    }
89
90    switch(c)
91    {
92    case 0x01: //CACA_KEY_CTRL_A:
93        screen_list->pty ^= screen_list->prevpty;
94        screen_list->prevpty ^= screen_list->pty;
95        screen_list->pty ^= screen_list->prevpty;
96        refresh = 1;
97        break;
98    case 'm':
99    case 0x0d: //CACA_KEY_CTRL_M:
100        screen_list->mini = !screen_list->mini;
101        refresh = 1;
102        break;
103    case 'n':
104    case ' ':
105    case '\0':
106    case 0x0e: //CACA_KEY_CTRL_N:
107        screen_list->prevpty = screen_list->pty;
108        screen_list->pty = (screen_list->pty + 1) % screen_list->count;
109        refresh = 1;
110        break;
111    case 'p':
112    case 0x10: //CACA_KEY_CTRL_P:
113        screen_list->prevpty = screen_list->pty;
114        screen_list->pty = (screen_list->pty + screen_list->count - 1) % screen_list->count;
115        refresh = 1;
116        break;
117    case 'c':
118    case 0x03: //CACA_KEY_CTRL_C:
119        screen_list->prevpty = screen_list->pty;
120        screen_list->pty =
121            add_screen(screen_list,
122                       create_screen(screen_list->width,
123                                     screen_list->height,
124                                     screen_list->default_shell));
125        refresh = 1;
126        break;
127    case 'w':
128    case 0x17: //CACA_KEY_CTRL_W:
129        screen_list->wm_type = (screen_list->wm_type==(WM_MAX-1)?
130                                screen_list->wm_type=0:
131                                screen_list->wm_type+1);
132        refresh = 1;
133        break;
134    case 'k':
135    case 0x0b: //CACA_KEY_CTRL_K:
136        add_recurrent(screen_list->recurrent_list, close_screen_recurrent, screen_list->cv);
137        refresh = 1;
138        break;
139    case 'x':
140    case 0x18: //CACA_KEY_CTRL_X:
141        memset(screen_list->lockpass, 0, 1024);
142        screen_list->locked = 1;
143        screen_list->lock_offset = 0;
144        refresh = 1;
145        break;
146    case 'h':
147    case '?':
148    case 0x08: //CACA_KEY_CTRL_H:
149        screen_list->help = !screen_list->help;
150        refresh = 1;
151        break;
152    case '"':
153    case 0x34: //CTRL+"
154        screen_list->cur_in_list = screen_list->pty;
155        screen_list->window_list = !screen_list->window_list;
156        refresh = 1;
157        break;
158    case 'd':
159    case 0x04: //CACA_KEY_CTRL_D:
160        detach(screen_list);
161        break;
162    }
163    return refresh;
164
165}
Note: See TracBrowser for help on using the repository browser.