2011-07-09 09:42:33 +00:00
|
|
|
/* $Id$ */
|
2007-11-27 19:23:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2008-08-28 17:45:30 +00:00
|
|
|
#include <sys/time.h>
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2012-03-18 01:55:45 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
2007-11-27 19:23:34 +00:00
|
|
|
#include <string.h>
|
2009-07-28 22:37:02 +00:00
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
2007-11-27 19:23:34 +00:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2009-10-28 22:57:55 +00:00
|
|
|
/*
|
2013-02-15 02:38:15 +00:00
|
|
|
* Handle keys input from the outside terminal. tty_default_*_keys[] are a base
|
|
|
|
* table of supported keys which are looked up in terminfo(5) and translated
|
|
|
|
* into a ternary tree.
|
2009-10-28 22:57:55 +00:00
|
|
|
*/
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
void tty_keys_add1(struct tty_key **, const char *, int);
|
|
|
|
void tty_keys_add(struct tty *, const char *, int);
|
|
|
|
void tty_keys_free1(struct tty_key *);
|
|
|
|
struct tty_key *tty_keys_find1(
|
2009-12-04 22:14:47 +00:00
|
|
|
struct tty_key *, const char *, size_t, size_t *);
|
2009-11-08 23:32:39 +00:00
|
|
|
struct tty_key *tty_keys_find(struct tty *, const char *, size_t, size_t *);
|
|
|
|
void tty_keys_callback(int, short, void *);
|
2012-05-22 21:04:25 +00:00
|
|
|
int tty_keys_mouse(struct tty *, const char *, size_t, size_t *);
|
2012-03-18 01:55:45 +00:00
|
|
|
int tty_keys_device(struct tty *, const char *, size_t, size_t *);
|
2009-01-09 16:45:58 +00:00
|
|
|
|
2013-02-15 02:16:41 +00:00
|
|
|
/* Default raw keys. */
|
|
|
|
struct tty_default_key_raw {
|
2009-01-09 23:57:42 +00:00
|
|
|
const char *string;
|
|
|
|
int key;
|
2009-01-09 16:45:58 +00:00
|
|
|
};
|
2013-02-15 02:16:41 +00:00
|
|
|
const struct tty_default_key_raw tty_default_raw_keys[] = {
|
2008-07-23 23:44:50 +00:00
|
|
|
/*
|
2009-10-28 22:56:50 +00:00
|
|
|
* Numeric keypad. Just use the vt100 escape sequences here and always
|
|
|
|
* put the terminal into keypad_xmit mode. Translation of numbers
|
|
|
|
* mode/applications mode is done in input-keys.c.
|
2008-07-23 23:44:50 +00:00
|
|
|
*/
|
2013-02-15 02:16:41 +00:00
|
|
|
{ "\033Oo", KEYC_KP_SLASH },
|
|
|
|
{ "\033Oj", KEYC_KP_STAR },
|
|
|
|
{ "\033Om", KEYC_KP_MINUS },
|
|
|
|
{ "\033Ow", KEYC_KP_SEVEN },
|
|
|
|
{ "\033Ox", KEYC_KP_EIGHT },
|
|
|
|
{ "\033Oy", KEYC_KP_NINE },
|
|
|
|
{ "\033Ok", KEYC_KP_PLUS },
|
|
|
|
{ "\033Ot", KEYC_KP_FOUR },
|
|
|
|
{ "\033Ou", KEYC_KP_FIVE },
|
|
|
|
{ "\033Ov", KEYC_KP_SIX },
|
|
|
|
{ "\033Oq", KEYC_KP_ONE },
|
|
|
|
{ "\033Or", KEYC_KP_TWO },
|
|
|
|
{ "\033Os", KEYC_KP_THREE },
|
|
|
|
{ "\033OM", KEYC_KP_ENTER },
|
|
|
|
{ "\033Op", KEYC_KP_ZERO },
|
|
|
|
{ "\033On", KEYC_KP_PERIOD },
|
2009-10-28 23:01:44 +00:00
|
|
|
|
2009-12-18 18:57:00 +00:00
|
|
|
/* Arrow keys. */
|
2013-02-15 02:16:41 +00:00
|
|
|
{ "\033OA", KEYC_UP },
|
|
|
|
{ "\033OB", KEYC_DOWN },
|
|
|
|
{ "\033OC", KEYC_RIGHT },
|
|
|
|
{ "\033OD", KEYC_LEFT },
|
2009-12-18 18:57:00 +00:00
|
|
|
|
2013-02-15 02:16:41 +00:00
|
|
|
{ "\033[A", KEYC_UP },
|
|
|
|
{ "\033[B", KEYC_DOWN },
|
|
|
|
{ "\033[C", KEYC_RIGHT },
|
|
|
|
{ "\033[D", KEYC_LEFT },
|
2009-11-13 16:56:15 +00:00
|
|
|
|
|
|
|
/* rxvt-style arrow + modifier keys. */
|
2013-02-15 02:16:41 +00:00
|
|
|
{ "\033Oa", KEYC_UP|KEYC_CTRL },
|
|
|
|
{ "\033Ob", KEYC_DOWN|KEYC_CTRL },
|
|
|
|
{ "\033Oc", KEYC_RIGHT|KEYC_CTRL },
|
|
|
|
{ "\033Od", KEYC_LEFT|KEYC_CTRL },
|
|
|
|
|
|
|
|
{ "\033[a", KEYC_UP|KEYC_SHIFT },
|
|
|
|
{ "\033[b", KEYC_DOWN|KEYC_SHIFT },
|
|
|
|
{ "\033[c", KEYC_RIGHT|KEYC_SHIFT },
|
|
|
|
{ "\033[d", KEYC_LEFT|KEYC_SHIFT },
|
|
|
|
|
|
|
|
/* rxvt-style function + modifier keys (C = ^, S = $, C-S = @). */
|
|
|
|
{ "\033[11^", KEYC_F1|KEYC_CTRL },
|
|
|
|
{ "\033[12^", KEYC_F2|KEYC_CTRL },
|
|
|
|
{ "\033[13^", KEYC_F3|KEYC_CTRL },
|
|
|
|
{ "\033[14^", KEYC_F4|KEYC_CTRL },
|
|
|
|
{ "\033[15^", KEYC_F5|KEYC_CTRL },
|
|
|
|
{ "\033[17^", KEYC_F6|KEYC_CTRL },
|
|
|
|
{ "\033[18^", KEYC_F7|KEYC_CTRL },
|
|
|
|
{ "\033[19^", KEYC_F8|KEYC_CTRL },
|
|
|
|
{ "\033[20^", KEYC_F9|KEYC_CTRL },
|
|
|
|
{ "\033[21^", KEYC_F10|KEYC_CTRL },
|
|
|
|
{ "\033[23^", KEYC_F11|KEYC_CTRL },
|
|
|
|
{ "\033[24^", KEYC_F12|KEYC_CTRL },
|
|
|
|
{ "\033[25^", KEYC_F13|KEYC_CTRL },
|
|
|
|
{ "\033[26^", KEYC_F14|KEYC_CTRL },
|
|
|
|
{ "\033[28^", KEYC_F15|KEYC_CTRL },
|
|
|
|
{ "\033[29^", KEYC_F16|KEYC_CTRL },
|
|
|
|
{ "\033[31^", KEYC_F17|KEYC_CTRL },
|
|
|
|
{ "\033[32^", KEYC_F18|KEYC_CTRL },
|
|
|
|
{ "\033[33^", KEYC_F19|KEYC_CTRL },
|
|
|
|
{ "\033[34^", KEYC_F20|KEYC_CTRL },
|
|
|
|
{ "\033[2^", KEYC_IC|KEYC_CTRL },
|
|
|
|
{ "\033[3^", KEYC_DC|KEYC_CTRL },
|
|
|
|
{ "\033[7^", KEYC_HOME|KEYC_CTRL },
|
|
|
|
{ "\033[8^", KEYC_END|KEYC_CTRL },
|
|
|
|
{ "\033[6^", KEYC_NPAGE|KEYC_CTRL },
|
|
|
|
{ "\033[5^", KEYC_PPAGE|KEYC_CTRL },
|
|
|
|
|
|
|
|
{ "\033[11$", KEYC_F1|KEYC_SHIFT },
|
|
|
|
{ "\033[12$", KEYC_F2|KEYC_SHIFT },
|
|
|
|
{ "\033[13$", KEYC_F3|KEYC_SHIFT },
|
|
|
|
{ "\033[14$", KEYC_F4|KEYC_SHIFT },
|
|
|
|
{ "\033[15$", KEYC_F5|KEYC_SHIFT },
|
|
|
|
{ "\033[17$", KEYC_F6|KEYC_SHIFT },
|
|
|
|
{ "\033[18$", KEYC_F7|KEYC_SHIFT },
|
|
|
|
{ "\033[19$", KEYC_F8|KEYC_SHIFT },
|
|
|
|
{ "\033[20$", KEYC_F9|KEYC_SHIFT },
|
|
|
|
{ "\033[21$", KEYC_F10|KEYC_SHIFT },
|
|
|
|
{ "\033[23$", KEYC_F11|KEYC_SHIFT },
|
|
|
|
{ "\033[24$", KEYC_F12|KEYC_SHIFT },
|
|
|
|
{ "\033[25$", KEYC_F13|KEYC_SHIFT },
|
|
|
|
{ "\033[26$", KEYC_F14|KEYC_SHIFT },
|
|
|
|
{ "\033[28$", KEYC_F15|KEYC_SHIFT },
|
|
|
|
{ "\033[29$", KEYC_F16|KEYC_SHIFT },
|
|
|
|
{ "\033[31$", KEYC_F17|KEYC_SHIFT },
|
|
|
|
{ "\033[32$", KEYC_F18|KEYC_SHIFT },
|
|
|
|
{ "\033[33$", KEYC_F19|KEYC_SHIFT },
|
|
|
|
{ "\033[34$", KEYC_F20|KEYC_SHIFT },
|
|
|
|
{ "\033[2$", KEYC_IC|KEYC_SHIFT },
|
|
|
|
{ "\033[3$", KEYC_DC|KEYC_SHIFT },
|
|
|
|
{ "\033[7$", KEYC_HOME|KEYC_SHIFT },
|
|
|
|
{ "\033[8$", KEYC_END|KEYC_SHIFT },
|
|
|
|
{ "\033[6$", KEYC_NPAGE|KEYC_SHIFT },
|
|
|
|
{ "\033[5$", KEYC_PPAGE|KEYC_SHIFT },
|
|
|
|
|
|
|
|
{ "\033[11@", KEYC_F1|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[12@", KEYC_F2|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[13@", KEYC_F3|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[14@", KEYC_F4|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[15@", KEYC_F5|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[17@", KEYC_F6|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[18@", KEYC_F7|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[19@", KEYC_F8|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[20@", KEYC_F9|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[21@", KEYC_F10|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[23@", KEYC_F11|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[24@", KEYC_F12|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[25@", KEYC_F13|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[26@", KEYC_F14|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[28@", KEYC_F15|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[29@", KEYC_F16|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[31@", KEYC_F17|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[32@", KEYC_F18|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[33@", KEYC_F19|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[34@", KEYC_F20|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[2@", KEYC_IC|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[3@", KEYC_DC|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[7@", KEYC_HOME|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[8@", KEYC_END|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[6@", KEYC_NPAGE|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
{ "\033[5@", KEYC_PPAGE|KEYC_CTRL|KEYC_SHIFT },
|
|
|
|
};
|
2009-12-18 18:57:00 +00:00
|
|
|
|
2013-02-15 02:16:41 +00:00
|
|
|
/* Default terminfo(5) keys. */
|
|
|
|
struct tty_default_key_code {
|
|
|
|
enum tty_code_code code;
|
|
|
|
int key;
|
|
|
|
};
|
|
|
|
const struct tty_default_key_code tty_default_code_keys[] = {
|
2009-12-18 18:57:00 +00:00
|
|
|
/* Function keys. */
|
2013-02-15 02:16:41 +00:00
|
|
|
{ TTYC_KF1, KEYC_F1 },
|
|
|
|
{ TTYC_KF2, KEYC_F2 },
|
|
|
|
{ TTYC_KF3, KEYC_F3 },
|
|
|
|
{ TTYC_KF4, KEYC_F4 },
|
|
|
|
{ TTYC_KF5, KEYC_F5 },
|
|
|
|
{ TTYC_KF6, KEYC_F6 },
|
|
|
|
{ TTYC_KF7, KEYC_F7 },
|
|
|
|
{ TTYC_KF8, KEYC_F8 },
|
|
|
|
{ TTYC_KF9, KEYC_F9 },
|
|
|
|
{ TTYC_KF10, KEYC_F10 },
|
|
|
|
{ TTYC_KF11, KEYC_F11 },
|
|
|
|
{ TTYC_KF12, KEYC_F12 },
|
|
|
|
{ TTYC_KF13, KEYC_F13 },
|
|
|
|
{ TTYC_KF14, KEYC_F14 },
|
|
|
|
{ TTYC_KF15, KEYC_F15 },
|
|
|
|
{ TTYC_KF16, KEYC_F16 },
|
|
|
|
{ TTYC_KF17, KEYC_F17 },
|
|
|
|
{ TTYC_KF18, KEYC_F18 },
|
|
|
|
{ TTYC_KF19, KEYC_F19 },
|
|
|
|
{ TTYC_KF20, KEYC_F20 },
|
|
|
|
{ TTYC_KICH1, KEYC_IC },
|
|
|
|
{ TTYC_KDCH1, KEYC_DC },
|
|
|
|
{ TTYC_KHOME, KEYC_HOME },
|
|
|
|
{ TTYC_KEND, KEYC_END },
|
|
|
|
{ TTYC_KNP, KEYC_NPAGE },
|
|
|
|
{ TTYC_KPP, KEYC_PPAGE },
|
|
|
|
{ TTYC_KCBT, KEYC_BTAB },
|
2009-12-18 18:57:00 +00:00
|
|
|
|
|
|
|
/* Arrow keys from terminfo. */
|
2013-02-15 02:16:41 +00:00
|
|
|
{ TTYC_KCUU1, KEYC_UP },
|
|
|
|
{ TTYC_KCUD1, KEYC_DOWN },
|
|
|
|
{ TTYC_KCUB1, KEYC_LEFT },
|
|
|
|
{ TTYC_KCUF1, KEYC_RIGHT },
|
2009-12-18 18:57:00 +00:00
|
|
|
|
|
|
|
/* Key and modifier capabilities. */
|
2013-02-15 02:16:41 +00:00
|
|
|
{ TTYC_KDC2, KEYC_DC|KEYC_SHIFT },
|
|
|
|
{ TTYC_KDC3, KEYC_DC|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KDC4, KEYC_DC|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KDC5, KEYC_DC|KEYC_CTRL },
|
|
|
|
{ TTYC_KDC6, KEYC_DC|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KDC7, KEYC_DC|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KDN2, KEYC_DOWN|KEYC_SHIFT },
|
|
|
|
{ TTYC_KDN3, KEYC_DOWN|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KDN4, KEYC_DOWN|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KDN5, KEYC_DOWN|KEYC_CTRL },
|
|
|
|
{ TTYC_KDN6, KEYC_DOWN|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KDN7, KEYC_DOWN|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KEND2, KEYC_END|KEYC_SHIFT },
|
|
|
|
{ TTYC_KEND3, KEYC_END|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KEND4, KEYC_END|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KEND5, KEYC_END|KEYC_CTRL },
|
|
|
|
{ TTYC_KEND6, KEYC_END|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KEND7, KEYC_END|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KHOM2, KEYC_HOME|KEYC_SHIFT },
|
|
|
|
{ TTYC_KHOM3, KEYC_HOME|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KHOM4, KEYC_HOME|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KHOM5, KEYC_HOME|KEYC_CTRL },
|
|
|
|
{ TTYC_KHOM6, KEYC_HOME|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KHOM7, KEYC_HOME|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KIC2, KEYC_IC|KEYC_SHIFT },
|
|
|
|
{ TTYC_KIC3, KEYC_IC|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KIC4, KEYC_IC|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KIC5, KEYC_IC|KEYC_CTRL },
|
|
|
|
{ TTYC_KIC6, KEYC_IC|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KIC7, KEYC_IC|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KLFT2, KEYC_LEFT|KEYC_SHIFT },
|
|
|
|
{ TTYC_KLFT3, KEYC_LEFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KLFT4, KEYC_LEFT|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KLFT5, KEYC_LEFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KLFT6, KEYC_LEFT|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KLFT7, KEYC_LEFT|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KNXT2, KEYC_NPAGE|KEYC_SHIFT },
|
|
|
|
{ TTYC_KNXT3, KEYC_NPAGE|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KNXT4, KEYC_NPAGE|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KNXT5, KEYC_NPAGE|KEYC_CTRL },
|
|
|
|
{ TTYC_KNXT6, KEYC_NPAGE|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KNXT7, KEYC_NPAGE|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KPRV2, KEYC_PPAGE|KEYC_SHIFT },
|
|
|
|
{ TTYC_KPRV3, KEYC_PPAGE|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KPRV4, KEYC_PPAGE|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KPRV5, KEYC_PPAGE|KEYC_CTRL },
|
|
|
|
{ TTYC_KPRV6, KEYC_PPAGE|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KPRV7, KEYC_PPAGE|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KRIT2, KEYC_RIGHT|KEYC_SHIFT },
|
|
|
|
{ TTYC_KRIT3, KEYC_RIGHT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KRIT4, KEYC_RIGHT|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KRIT5, KEYC_RIGHT|KEYC_CTRL },
|
|
|
|
{ TTYC_KRIT6, KEYC_RIGHT|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KRIT7, KEYC_RIGHT|KEYC_ESCAPE|KEYC_CTRL },
|
|
|
|
{ TTYC_KUP2, KEYC_UP|KEYC_SHIFT },
|
|
|
|
{ TTYC_KUP3, KEYC_UP|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KUP4, KEYC_UP|KEYC_SHIFT|KEYC_ESCAPE },
|
|
|
|
{ TTYC_KUP5, KEYC_UP|KEYC_CTRL },
|
|
|
|
{ TTYC_KUP6, KEYC_UP|KEYC_SHIFT|KEYC_CTRL },
|
|
|
|
{ TTYC_KUP7, KEYC_UP|KEYC_ESCAPE|KEYC_CTRL },
|
2007-11-27 19:23:34 +00:00
|
|
|
};
|
|
|
|
|
2013-02-15 02:16:41 +00:00
|
|
|
/* Add key to tree. */
|
2009-11-08 23:32:39 +00:00
|
|
|
void
|
|
|
|
tty_keys_add(struct tty *tty, const char *s, int key)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2009-12-18 18:57:00 +00:00
|
|
|
struct tty_key *tk;
|
|
|
|
size_t size;
|
|
|
|
const char *keystr;
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2009-12-18 18:57:00 +00:00
|
|
|
keystr = key_string_lookup_key(key);
|
|
|
|
if ((tk = tty_keys_find(tty, s, strlen(s), &size)) == NULL) {
|
|
|
|
log_debug("new key %s: 0x%x (%s)", s, key, keystr);
|
2009-11-08 23:32:39 +00:00
|
|
|
tty_keys_add1(&tty->key_tree, s, key);
|
2009-12-18 18:57:00 +00:00
|
|
|
} else {
|
|
|
|
log_debug("replacing key %s: 0x%x (%s)", s, key, keystr);
|
|
|
|
tk->key = key;
|
2009-11-08 23:32:39 +00:00
|
|
|
}
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Add next node to the tree. */
|
2007-11-27 19:23:34 +00:00
|
|
|
void
|
2009-11-08 23:32:39 +00:00
|
|
|
tty_keys_add1(struct tty_key **tkp, const char *s, int key)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2009-11-08 23:32:39 +00:00
|
|
|
struct tty_key *tk;
|
2009-01-09 16:45:58 +00:00
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Allocate a tree entry if there isn't one already. */
|
|
|
|
tk = *tkp;
|
|
|
|
if (tk == NULL) {
|
|
|
|
tk = *tkp = xcalloc(1, sizeof *tk);
|
|
|
|
tk->ch = *s;
|
|
|
|
tk->key = KEYC_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the next entry. */
|
|
|
|
if (*s == tk->ch) {
|
|
|
|
/* Move forward in string. */
|
|
|
|
s++;
|
2009-01-10 01:51:22 +00:00
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* If this is the end of the string, no more is necessary. */
|
|
|
|
if (*s == '\0') {
|
|
|
|
tk->key = key;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the child tree for the next character. */
|
|
|
|
tkp = &tk->next;
|
2009-12-04 22:14:47 +00:00
|
|
|
} else {
|
2009-11-08 23:32:39 +00:00
|
|
|
if (*s < tk->ch)
|
|
|
|
tkp = &tk->left;
|
|
|
|
else if (*s > tk->ch)
|
|
|
|
tkp = &tk->right;
|
2009-05-04 18:05:23 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* And recurse to add it. */
|
|
|
|
tty_keys_add1(tkp, s, key);
|
2009-01-09 16:45:58 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Initialise a key tree from the table. */
|
2009-01-09 16:45:58 +00:00
|
|
|
void
|
2013-02-15 02:16:41 +00:00
|
|
|
tty_keys_build(struct tty *tty)
|
2009-01-09 16:45:58 +00:00
|
|
|
{
|
2013-02-15 02:16:41 +00:00
|
|
|
const struct tty_default_key_raw *tdkr;
|
|
|
|
const struct tty_default_key_code *tdkc;
|
|
|
|
u_int i;
|
|
|
|
const char *s;
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2013-02-15 02:16:41 +00:00
|
|
|
if (tty->key_tree != NULL)
|
2013-02-15 02:18:38 +00:00
|
|
|
tty_keys_free (tty);
|
2009-11-08 23:32:39 +00:00
|
|
|
tty->key_tree = NULL;
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2013-02-15 02:16:41 +00:00
|
|
|
for (i = 0; i < nitems(tty_default_raw_keys); i++) {
|
|
|
|
tdkr = &tty_default_raw_keys[i];
|
|
|
|
|
|
|
|
s = tdkr->string;
|
2013-02-16 13:21:14 +00:00
|
|
|
if (*s != '\0')
|
|
|
|
tty_keys_add(tty, s, tdkr->key);
|
2013-02-15 02:16:41 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < nitems(tty_default_code_keys); i++) {
|
|
|
|
tdkc = &tty_default_code_keys[i];
|
|
|
|
|
|
|
|
s = tty_term_string(tty->term, tdkc->code);
|
2013-02-16 13:29:40 +00:00
|
|
|
if (*s != '\0')
|
2013-02-16 13:21:14 +00:00
|
|
|
tty_keys_add(tty, s, tdkc->key);
|
2013-02-15 02:16:41 +00:00
|
|
|
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2013-02-16 13:21:14 +00:00
|
|
|
|
|
|
|
tty_keys_add(tty, "abc", 'x');
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Free the entire key tree. */
|
2007-11-27 19:23:34 +00:00
|
|
|
void
|
|
|
|
tty_keys_free(struct tty *tty)
|
|
|
|
{
|
2009-11-08 23:32:39 +00:00
|
|
|
tty_keys_free1(tty->key_tree);
|
|
|
|
}
|
2009-05-04 17:58:27 +00:00
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Free a single key. */
|
|
|
|
void
|
|
|
|
tty_keys_free1(struct tty_key *tk)
|
|
|
|
{
|
|
|
|
if (tk->next != NULL)
|
|
|
|
tty_keys_free1(tk->next);
|
|
|
|
if (tk->left != NULL)
|
|
|
|
tty_keys_free1(tk->left);
|
|
|
|
if (tk->right != NULL)
|
|
|
|
tty_keys_free1(tk->right);
|
2012-07-11 19:34:16 +00:00
|
|
|
free(tk);
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Lookup a key in the tree. */
|
2008-06-25 07:30:08 +00:00
|
|
|
struct tty_key *
|
2009-11-08 23:32:39 +00:00
|
|
|
tty_keys_find(struct tty *tty, const char *buf, size_t len, size_t *size)
|
2008-06-25 07:30:08 +00:00
|
|
|
{
|
2009-11-08 23:32:39 +00:00
|
|
|
*size = 0;
|
|
|
|
return (tty_keys_find1(tty->key_tree, buf, len, size));
|
|
|
|
}
|
2008-06-25 07:30:08 +00:00
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Find the next node. */
|
|
|
|
struct tty_key *
|
|
|
|
tty_keys_find1(struct tty_key *tk, const char *buf, size_t len, size_t *size)
|
|
|
|
{
|
|
|
|
/* If the node is NULL, this is the end of the tree. No match. */
|
|
|
|
if (tk == NULL)
|
2008-06-25 07:30:08 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Pick the next in the sequence. */
|
|
|
|
if (tk->ch == *buf) {
|
|
|
|
/* Move forward in the string. */
|
|
|
|
buf++; len--;
|
|
|
|
(*size)++;
|
2008-06-25 07:30:08 +00:00
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* At the end of the string, return the current node. */
|
2010-03-15 20:44:51 +00:00
|
|
|
if (len == 0 || (tk->next == NULL && tk->key != KEYC_NONE))
|
2008-06-25 07:30:08 +00:00
|
|
|
return (tk);
|
2009-11-08 23:32:39 +00:00
|
|
|
|
|
|
|
/* Move into the next tree for the following character. */
|
|
|
|
tk = tk->next;
|
|
|
|
} else {
|
|
|
|
if (*buf < tk->ch)
|
|
|
|
tk = tk->left;
|
|
|
|
else if (*buf > tk->ch)
|
|
|
|
tk = tk->right;
|
2008-06-25 07:30:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Move to the next in the tree. */
|
|
|
|
return (tty_keys_find1(tk, buf, len, size));
|
2008-06-25 07:30:08 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/*
|
|
|
|
* Process at least one key in the buffer and invoke tty->key_callback. Return
|
2009-11-28 14:44:00 +00:00
|
|
|
* 0 if there are no further keys, or 1 if there could be more in the buffer.
|
2009-11-08 23:32:39 +00:00
|
|
|
*/
|
2007-11-27 19:23:34 +00:00
|
|
|
int
|
2009-11-08 23:26:56 +00:00
|
|
|
tty_keys_next(struct tty *tty)
|
2007-11-27 19:23:34 +00:00
|
|
|
{
|
2012-05-22 21:04:25 +00:00
|
|
|
struct tty_key *tk;
|
|
|
|
struct timeval tv;
|
|
|
|
const char *buf;
|
|
|
|
size_t len, size;
|
|
|
|
cc_t bspace;
|
|
|
|
int key, delay;
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Get key buffer. */
|
2009-11-08 22:58:38 +00:00
|
|
|
buf = EVBUFFER_DATA(tty->event->input);
|
|
|
|
len = EVBUFFER_LENGTH(tty->event->input);
|
2009-01-09 16:45:58 +00:00
|
|
|
if (len == 0)
|
2009-11-08 23:26:56 +00:00
|
|
|
return (0);
|
2009-01-09 16:45:58 +00:00
|
|
|
log_debug("keys are %zu (%.*s)", len, (int) len, buf);
|
2007-11-27 19:23:34 +00:00
|
|
|
|
2012-03-18 01:55:45 +00:00
|
|
|
/* Is this device attributes response? */
|
|
|
|
switch (tty_keys_device(tty, buf, len, &size)) {
|
|
|
|
case 0: /* yes */
|
|
|
|
key = KEYC_NONE;
|
2013-02-16 13:21:14 +00:00
|
|
|
goto complete_key;
|
2012-03-18 01:55:45 +00:00
|
|
|
case -1: /* no, or not valid */
|
|
|
|
break;
|
|
|
|
case 1: /* partial */
|
|
|
|
goto partial_key;
|
|
|
|
}
|
|
|
|
|
2009-12-02 15:07:28 +00:00
|
|
|
/* Is this a mouse key press? */
|
2012-05-22 21:04:25 +00:00
|
|
|
switch (tty_keys_mouse(tty, buf, len, &size)) {
|
2009-11-28 14:44:00 +00:00
|
|
|
case 0: /* yes */
|
|
|
|
key = KEYC_MOUSE;
|
2013-02-16 13:21:14 +00:00
|
|
|
goto complete_key;
|
2009-11-28 14:44:00 +00:00
|
|
|
case -1: /* no, or not valid */
|
2009-11-28 14:51:37 +00:00
|
|
|
break;
|
2009-11-28 14:44:00 +00:00
|
|
|
case 1: /* partial */
|
|
|
|
goto partial_key;
|
2009-01-09 16:45:58 +00:00
|
|
|
}
|
2009-05-04 17:58:27 +00:00
|
|
|
|
2009-12-02 15:07:28 +00:00
|
|
|
/* Try to parse a key with an xterm-style modifier. */
|
2009-12-02 15:06:35 +00:00
|
|
|
switch (xterm_keys_find(buf, len, &size, &key)) {
|
|
|
|
case 0: /* found */
|
2013-02-16 13:21:14 +00:00
|
|
|
key = KEYC_NONE;
|
|
|
|
goto complete_key;
|
2009-12-02 15:06:35 +00:00
|
|
|
case -1: /* not found */
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
goto partial_key;
|
2009-10-28 23:03:51 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 15:07:28 +00:00
|
|
|
/* Look for matching key string and return if found. */
|
2013-02-16 13:21:14 +00:00
|
|
|
tk = tty_keys_find(tty, buf, len, &size);
|
2009-12-02 15:07:28 +00:00
|
|
|
if (tk != NULL) {
|
2013-02-16 13:21:14 +00:00
|
|
|
if (tk->next != NULL)
|
|
|
|
goto partial_key;
|
2009-12-02 15:07:28 +00:00
|
|
|
key = tk->key;
|
2013-02-16 13:21:14 +00:00
|
|
|
goto complete_key;
|
2009-12-02 15:07:28 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Is this a meta key? */
|
|
|
|
if (len >= 2 && buf[0] == '\033') {
|
|
|
|
if (buf[1] != '\033') {
|
|
|
|
key = buf[1] | KEYC_ESCAPE;
|
|
|
|
size = 2;
|
|
|
|
goto complete_key;
|
|
|
|
}
|
2008-06-25 07:30:08 +00:00
|
|
|
|
2009-03-02 16:55:23 +00:00
|
|
|
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
|
|
|
if (tk != NULL) {
|
2009-11-08 23:32:39 +00:00
|
|
|
size++; /* include escape */
|
2013-02-16 13:21:14 +00:00
|
|
|
if (tk->next != NULL)
|
|
|
|
goto partial_key;
|
|
|
|
key = tk->key;
|
|
|
|
if (key != KEYC_NONE)
|
|
|
|
key |= KEYC_ESCAPE;
|
|
|
|
goto complete_key;
|
2009-03-02 16:55:23 +00:00
|
|
|
}
|
2008-06-25 07:30:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
first_key:
|
|
|
|
/* No key found, take first. */
|
|
|
|
key = (u_char) *buf;
|
|
|
|
size = 1;
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2009-11-08 23:26:56 +00:00
|
|
|
/*
|
2013-02-16 13:21:14 +00:00
|
|
|
* Check for backspace key using termios VERASE - the terminfo
|
|
|
|
* kbs entry is extremely unreliable, so cannot be safely
|
|
|
|
* used. termios should have a better idea.
|
2009-11-08 23:26:56 +00:00
|
|
|
*/
|
2013-02-16 13:21:14 +00:00
|
|
|
bspace = tty->tio.c_cc[VERASE];
|
|
|
|
if (bspace != _POSIX_VDISABLE && key == bspace)
|
|
|
|
key = KEYC_BSPACE;
|
2009-05-04 17:58:27 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
goto complete_key;
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
partial_key:
|
|
|
|
log_debug("partial key %.*s", (int) len, buf);
|
|
|
|
|
|
|
|
/* If timer is going, check for expiration. */
|
|
|
|
if (tty->flags & TTY_TIMER) {
|
|
|
|
if (evtimer_initialized(&tty->key_timer) &&
|
|
|
|
!evtimer_pending(&tty->key_timer, NULL))
|
|
|
|
goto first_key;
|
2012-04-24 16:17:57 +00:00
|
|
|
return (0);
|
2013-02-16 13:21:14 +00:00
|
|
|
}
|
2012-04-24 16:17:57 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Get the time period. */
|
2009-12-16 01:09:01 +00:00
|
|
|
delay = options_get_number(&global_options, "escape-time");
|
|
|
|
tv.tv_sec = delay / 1000;
|
|
|
|
tv.tv_usec = (delay % 1000) * 1000L;
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Start the timer. */
|
2012-03-18 01:59:34 +00:00
|
|
|
if (event_initialized(&tty->key_timer))
|
|
|
|
evtimer_del(&tty->key_timer);
|
2009-11-08 23:26:56 +00:00
|
|
|
evtimer_set(&tty->key_timer, tty_keys_callback, tty);
|
|
|
|
evtimer_add(&tty->key_timer, &tv);
|
2009-12-04 22:14:47 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
tty->flags |= TTY_TIMER;
|
2009-11-08 23:26:56 +00:00
|
|
|
return (0);
|
2009-03-02 16:55:23 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
complete_key:
|
|
|
|
log_debug("complete key %.*s %#x", (int) size, buf, key);
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Remove data from buffer. */
|
|
|
|
evbuffer_drain(tty->event->input, size);
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Remove key timer. */
|
2012-03-18 01:59:34 +00:00
|
|
|
if (event_initialized(&tty->key_timer))
|
|
|
|
evtimer_del(&tty->key_timer);
|
2013-02-16 13:21:14 +00:00
|
|
|
tty->flags &= ~TTY_TIMER;
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
/* Fire the key. */
|
2012-03-18 01:55:45 +00:00
|
|
|
if (key != KEYC_NONE)
|
2012-05-22 21:05:30 +00:00
|
|
|
server_client_handle_key(tty->client, key);
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2009-11-08 23:26:56 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-11-08 23:32:39 +00:00
|
|
|
/* Key timer callback. */
|
2009-11-28 14:50:37 +00:00
|
|
|
/* ARGSUSED */
|
2009-11-08 23:26:56 +00:00
|
|
|
void
|
|
|
|
tty_keys_callback(unused int fd, unused short events, void *data)
|
|
|
|
{
|
|
|
|
struct tty *tty = data;
|
|
|
|
|
2013-02-16 13:21:14 +00:00
|
|
|
if (tty->flags & TTY_TIMER) {
|
|
|
|
while (tty_keys_next(tty))
|
|
|
|
;
|
|
|
|
}
|
2007-11-27 19:23:34 +00:00
|
|
|
}
|
2009-01-12 22:48:00 +00:00
|
|
|
|
2009-12-04 22:14:47 +00:00
|
|
|
/*
|
2009-11-28 14:44:00 +00:00
|
|
|
* Handle mouse key input. Returns 0 for success, -1 for failure, 1 for partial
|
|
|
|
* (probably a mouse sequence but need more data).
|
|
|
|
*/
|
2009-01-28 19:52:21 +00:00
|
|
|
int
|
2012-05-22 21:04:25 +00:00
|
|
|
tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
|
2009-01-28 19:52:21 +00:00
|
|
|
{
|
2012-05-22 21:05:30 +00:00
|
|
|
struct mouse_event *m = &tty->mouse;
|
2012-05-22 21:04:25 +00:00
|
|
|
struct utf8_data utf8data;
|
2012-10-26 14:35:42 +00:00
|
|
|
u_int i, value, x, y, b;
|
2011-01-07 14:34:45 +00:00
|
|
|
|
2009-01-28 19:52:21 +00:00
|
|
|
/*
|
2011-01-07 14:34:45 +00:00
|
|
|
* Standard mouse sequences are \033[M followed by three characters
|
|
|
|
* indicating buttons, X and Y, all based at 32 with 1,1 top-left.
|
|
|
|
*
|
|
|
|
* UTF-8 mouse sequences are similar but the three are expressed as
|
|
|
|
* UTF-8 characters.
|
2009-01-28 19:52:21 +00:00
|
|
|
*/
|
|
|
|
|
2009-11-28 14:44:00 +00:00
|
|
|
*size = 0;
|
2012-10-26 14:35:42 +00:00
|
|
|
x = y = b = 0;
|
2009-11-28 14:44:00 +00:00
|
|
|
|
2011-01-07 14:34:45 +00:00
|
|
|
/* First three bytes are always \033[M. */
|
2009-11-28 14:44:00 +00:00
|
|
|
if (buf[0] != '\033')
|
|
|
|
return (-1);
|
|
|
|
if (len == 1)
|
|
|
|
return (1);
|
|
|
|
if (buf[1] != '[')
|
|
|
|
return (-1);
|
|
|
|
if (len == 2)
|
|
|
|
return (1);
|
|
|
|
if (buf[2] != 'M')
|
|
|
|
return (-1);
|
|
|
|
if (len == 3)
|
|
|
|
return (1);
|
|
|
|
|
2011-01-07 14:34:45 +00:00
|
|
|
/* Read the three inputs. */
|
|
|
|
*size = 3;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
if (len < *size)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
if (tty->mode & MODE_MOUSE_UTF8) {
|
|
|
|
if (utf8_open(&utf8data, buf[*size])) {
|
|
|
|
if (utf8data.size != 2)
|
|
|
|
return (-1);
|
|
|
|
(*size)++;
|
|
|
|
if (len < *size)
|
|
|
|
return (1);
|
|
|
|
utf8_append(&utf8data, buf[*size]);
|
|
|
|
value = utf8_combine(&utf8data);
|
|
|
|
} else
|
2011-03-04 20:36:59 +00:00
|
|
|
value = (unsigned char)buf[*size];
|
2011-01-07 14:34:45 +00:00
|
|
|
(*size)++;
|
|
|
|
} else {
|
2011-03-04 20:36:59 +00:00
|
|
|
value = (unsigned char)buf[*size];
|
2011-01-07 14:34:45 +00:00
|
|
|
(*size)++;
|
|
|
|
}
|
2009-05-04 17:58:27 +00:00
|
|
|
|
2011-01-07 14:34:45 +00:00
|
|
|
if (i == 0)
|
2012-10-26 14:35:42 +00:00
|
|
|
b = value;
|
2011-01-07 14:34:45 +00:00
|
|
|
else if (i == 1)
|
2012-10-26 14:35:42 +00:00
|
|
|
x = value;
|
2011-01-07 14:34:45 +00:00
|
|
|
else
|
2012-10-26 14:35:42 +00:00
|
|
|
y = value;
|
2011-01-07 14:34:45 +00:00
|
|
|
}
|
|
|
|
log_debug("mouse input: %.*s", (int) *size, buf);
|
2009-11-08 23:32:39 +00:00
|
|
|
|
2011-01-07 14:34:45 +00:00
|
|
|
/* Check and return the mouse input. */
|
2012-10-26 14:35:42 +00:00
|
|
|
if (b < 32 || x < 33 || y < 33)
|
2009-11-28 14:44:00 +00:00
|
|
|
return (-1);
|
2012-10-26 14:35:42 +00:00
|
|
|
b -= 32;
|
|
|
|
x -= 33;
|
|
|
|
y -= 33;
|
|
|
|
log_debug("mouse position: x=%u y=%u b=%u", x, y, b);
|
|
|
|
|
|
|
|
/* Fill in mouse structure. */
|
|
|
|
if (~m->event & MOUSE_EVENT_WHEEL) {
|
|
|
|
m->lx = m->x;
|
|
|
|
m->ly = m->y;
|
|
|
|
}
|
|
|
|
m->xb = b;
|
|
|
|
if (b & 64) { /* wheel button */
|
|
|
|
b &= 3;
|
|
|
|
if (b == 0)
|
|
|
|
m->wheel = MOUSE_WHEEL_UP;
|
|
|
|
else if (b == 1)
|
|
|
|
m->wheel = MOUSE_WHEEL_DOWN;
|
|
|
|
m->event = MOUSE_EVENT_WHEEL;
|
|
|
|
} else if ((b & 3) == 3) {
|
|
|
|
if (~m->event & MOUSE_EVENT_DRAG && x == m->x && y == m->y) {
|
|
|
|
m->event = MOUSE_EVENT_CLICK;
|
|
|
|
} else
|
|
|
|
m->event = MOUSE_EVENT_DRAG;
|
|
|
|
m->event |= MOUSE_EVENT_UP;
|
|
|
|
} else {
|
|
|
|
if (b & 32) /* drag motion */
|
|
|
|
m->event = MOUSE_EVENT_DRAG;
|
|
|
|
else {
|
|
|
|
if (m->event & MOUSE_EVENT_UP && x == m->x && y == m->y)
|
|
|
|
m->clicks = (m->clicks + 1) % 3;
|
|
|
|
else
|
|
|
|
m->clicks = 0;
|
|
|
|
m->sx = x;
|
|
|
|
m->sy = y;
|
|
|
|
m->event = MOUSE_EVENT_DOWN;
|
|
|
|
}
|
|
|
|
m->button = (b & 3);
|
|
|
|
}
|
|
|
|
m->x = x;
|
|
|
|
m->y = y;
|
|
|
|
|
2009-11-28 14:44:00 +00:00
|
|
|
return (0);
|
2009-01-28 19:52:21 +00:00
|
|
|
}
|
2012-03-18 01:55:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle device attributes input. Returns 0 for success, -1 for failure, 1 for
|
|
|
|
* partial.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
tty_keys_device(struct tty *tty, const char *buf, size_t len, size_t *size)
|
|
|
|
{
|
2012-11-22 14:41:11 +00:00
|
|
|
u_int i, class;
|
2012-03-18 01:55:45 +00:00
|
|
|
char tmp[64], *endptr;
|
|
|
|
|
|
|
|
/*
|
2012-03-29 21:09:19 +00:00
|
|
|
* Primary device attributes are \033[?a;b and secondary are
|
2012-11-22 14:41:11 +00:00
|
|
|
* \033[>a;b;c.
|
2012-03-18 01:55:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
*size = 0;
|
|
|
|
|
2012-11-22 14:41:11 +00:00
|
|
|
/* First three bytes are always \033[?. */
|
2012-03-18 01:55:45 +00:00
|
|
|
if (buf[0] != '\033')
|
|
|
|
return (-1);
|
|
|
|
if (len == 1)
|
|
|
|
return (1);
|
|
|
|
if (buf[1] != '[')
|
|
|
|
return (-1);
|
|
|
|
if (len == 2)
|
|
|
|
return (1);
|
2012-03-29 21:09:19 +00:00
|
|
|
if (buf[2] != '>' && buf[2] != '?')
|
2012-03-18 01:55:45 +00:00
|
|
|
return (-1);
|
|
|
|
if (len == 3)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* Copy the rest up to a 'c'. */
|
|
|
|
for (i = 0; i < (sizeof tmp) - 1 && buf[3 + i] != 'c'; i++) {
|
|
|
|
if (3 + i == len)
|
|
|
|
return (1);
|
|
|
|
tmp[i] = buf[3 + i];
|
|
|
|
}
|
|
|
|
if (i == (sizeof tmp) - 1)
|
|
|
|
return (-1);
|
|
|
|
tmp[i] = '\0';
|
|
|
|
*size = 4 + i;
|
|
|
|
|
2012-11-22 14:41:11 +00:00
|
|
|
/* Only primary is of interest. */
|
|
|
|
if (buf[2] != '?')
|
2012-03-29 21:09:19 +00:00
|
|
|
return (0);
|
|
|
|
|
2012-11-22 14:41:11 +00:00
|
|
|
/* Convert service class. */
|
|
|
|
class = strtoul(tmp, &endptr, 10);
|
|
|
|
if (*endptr != ';')
|
|
|
|
class = 0;
|
|
|
|
|
|
|
|
log_debug("received service class %u", class);
|
|
|
|
tty_set_class(tty, class);
|
2012-03-18 01:55:45 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|