rewrite: update default dumb and smart prefixes
[elinks/elinks-j605.git] / src / terminal / mouse.h
blob3e650121dac33c97d0182d73f0a442e0f448f523
1 #ifndef EL__TERMINAL_MOUSE_H
2 #define EL__TERMINAL_MOUSE_H
4 struct interlink_event;
5 struct itrm;
7 /* The mouse reporting button byte looks like:
9 * -ss??bbb
10 * || |||
11 * || +++---> buttons:
12 * || 0 left
13 * || 1 middle
14 * || 2 right
15 * || 3 release OR wheel up [rxvt]
16 * || 4 wheel down [rxvt]
17 * ||
18 * ++--------> style:
19 * 1 normalclick (makes sure the whole thing is >= ' ')
20 * 2 doubleclick
21 * 3 mouse wheel move [xterm]
22 * then in bb is 0 for up and 1 for down
24 * What we translate it to:
25 * -da??bbb
26 * || |||
27 * || +++---> buttons:
28 * || 0 left
29 * || 1 middle
30 * || 2 right
31 * || 3 wheel up
32 * || 4 wheel down
33 * ||
34 * |+--------> action:
35 * | 0 press (B_DOWN)
36 * | 1 release (B_UP)
37 * |
38 * +---------> drag flag (valid only for B_UP)
40 * (TODO: doubleclick facility? --pasky)
42 * Let me introduce to the wonderful world of X terminals and their handling of
43 * mouse wheel now. First, one sad fact: reasonable mouse wheel reporting
44 * support has only xterm itself (from everything I tried) - it is relatively
45 * elegant, it shouldn't confuse existing applications too much and it is
46 * generally non-conflicting with the old behaviour.
48 * All other terminals are doing absolutely terrible things, making it hell on
49 * the hearth to support mouse wheels. rxvt will send the buttons as succeeding
50 * button numbers (3, 4) in normal sequences, but that has a little problem -
51 * button 3 is also alias for button release; welcome to the wonderful world of
52 * X11. But at least, rxvt will send only "press" sequence, but no release
53 * sequence (it really doesn't make sense for wheels anyway, does it?). That
54 * has the advantage that you can do some heuristic (see below) to at least
55 * partially pace with this terrible thing.
57 * But now, let's see another nice pair of wonderful terminals: aterm and
58 * Eterm. They emit same braindead sequence for wheel up/down as rxvt, but
59 * that's not all. Yes, you guessed it - they send even the release sequence
60 * (immediatelly after press sequence) for the wheels. So, you will see
61 * something like:
63 * old glasses - <button1 press> <release> <release> <release>
64 * new glasses - <button1 press> <wheelup press> <wheelup press> <wheelup press>
65 * smartglasses1-<button1 press> <release> <wheelup press> <wheelup press>
66 * smartglasses2-<button1 press> <release> <wheelup press> <release>
68 * But with smartglasses2, you will have a problem with rxvt when someone will
69 * move the wheel multiple times - only half of the times it will be recorded.
70 * Poof. No luck :-(.
72 * [smartglasses1]:
73 * When user presses some button and then moves the wheel, action for button
74 * release will be done and when he will release the button, action for the
75 * wheel will be done. That's unfortunately inevitable in order to work under
76 * rxvt :-(.
79 struct term_event_mouse {
80 int x, y;
81 unsigned int button;
83 #define interlink_event_mouse term_event_mouse
85 #define BM_BUTT 7
86 #define B_LEFT 0
87 #define B_MIDDLE 1
88 #define B_RIGHT 2
89 #define B_WHEEL_UP 3
90 #define B_WHEEL_DOWN 4
92 #define BM_ACT 32
93 #define B_DOWN 0
94 #define B_UP 32
96 #define BM_DRAG 64
97 #define B_DRAG 64
99 #define mouse_get_action(mouse_) ((mouse_)->button & BM_ACT)
100 #define mouse_action_is(mouse_, value) (mouse_get_action(mouse_) == (value))
102 #define mouse_get_button(mouse_) ((mouse_)->button & BM_BUTT)
103 #define mouse_button_is(mouse_, value) (mouse_get_button(mouse_) == (value))
104 #define mouse_wheeling(mouse_) (mouse_get_button(mouse_) >= B_WHEEL_UP)
106 #define mouse_is_in_box(mouse_, box) \
107 is_in_box(box, (mouse_)->x, (mouse_)->y)
109 #define set_mouse(mouse_, x_, y_, button_) do { \
110 (mouse_)->x = (x_); \
111 (mouse_)->y = (y_); \
112 (mouse_)->button = (button_); \
113 } while (0)
115 void send_mouse_init_sequence(int h);
116 void send_mouse_done_sequence(int h);
117 void disable_mouse(void);
118 void enable_mouse(void);
119 void toggle_mouse(void);
120 int decode_terminal_mouse_escape_sequence(struct itrm *itrm, struct interlink_event *ev, int el, int v);
123 #endif