Don't link with libgnutls-openssl, which is now GPLv3+.
[elinks.git] / src / terminal / event.h
blob9de3ce1e2be39072d9c6ace290c2b82cc39dae1f
1 #ifndef EL__TERMINAL_EVENT_H
2 #define EL__TERMINAL_EVENT_H
4 #include "terminal/kbd.h"
5 #include "terminal/mouse.h"
7 struct terminal;
9 /* Some constants for the strings inside of {struct terminal}. */
11 #define MAX_TERM_LEN 32 /* this must be multiple of 8! (alignment problems) */
12 #define MAX_CWD_LEN 256 /* this must be multiple of 8! (alignment problems) */
15 /** Type of an event received from a terminal. */
16 enum term_event_type {
17 EVENT_INIT,
18 EVENT_KBD,
19 EVENT_MOUSE,
20 EVENT_REDRAW,
21 EVENT_RESIZE,
22 EVENT_ABORT,
25 /** An event received from a terminal. This type can be changed
26 * without breaking interlink compatibility. */
27 struct term_event {
28 enum term_event_type ev;
30 union {
31 /** ::EVENT_MOUSE */
32 struct term_event_mouse mouse;
34 /** ::EVENT_KBD */
35 struct term_event_keyboard keyboard;
37 /** ::EVENT_INIT, ::EVENT_RESIZE, ::EVENT_REDRAW */
38 struct term_event_size {
39 int width, height;
40 } size;
41 } info;
44 /** An event transferred via the interlink socket. This is quite
45 * similar to struct term_event but has a different format for
46 * keyboard events. If you change this type, you can break interlink
47 * compatibility. */
48 struct interlink_event {
49 enum term_event_type ev;
51 union {
52 /* ::EVENT_MOUSE */
53 struct interlink_event_mouse mouse;
55 /* ::EVENT_KBD */
56 struct interlink_event_keyboard keyboard;
58 /* ::EVENT_INIT, ::EVENT_RESIZE, ::EVENT_REDRAW */
59 #define interlink_event_size term_event_size
60 struct interlink_event_size size;
61 } info;
64 static inline void
65 set_mouse_term_event(struct term_event *ev, int x, int y, unsigned int button)
67 memset(ev, 0, sizeof(*ev));
68 ev->ev = EVENT_MOUSE;
69 set_mouse(&ev->info.mouse, x, y, button);
72 static inline void
73 set_mouse_interlink_event(struct interlink_event *ev, int x, int y, unsigned int button)
75 memset(ev, 0, sizeof(*ev));
76 ev->ev = EVENT_MOUSE;
77 set_mouse(&ev->info.mouse, x, y, button);
80 static inline void
81 set_kbd_term_event(struct term_event *ev, int key,
82 term_event_modifier_T modifier)
84 memset(ev, 0, sizeof(*ev));
85 ev->ev = EVENT_KBD;
86 kbd_set(&ev->info.keyboard, key, modifier);
89 /** Initialize @c ev as an interlink keyboard event.
90 * @a key can be either an 8-bit byte or a value from enum
91 * term_event_special_key. In the latter case, this function negates
92 * the value, unless it is KBD_UNDEF. For example, key == KBD_ENTER
93 * results in ev->info.keyboard.key = -KBD_ENTER. This mapping keeps
94 * the interlink protocol compatible with ELinks 0.11. */
95 static inline void
96 set_kbd_interlink_event(struct interlink_event *ev, int key,
97 term_event_modifier_T modifier)
99 memset(ev, 0, sizeof(*ev));
100 ev->ev = EVENT_KBD;
101 if (key <= -0x100)
102 key = -key;
103 kbd_set(&ev->info.keyboard, key, modifier);
106 static inline void
107 set_abort_term_event(struct term_event *ev)
109 memset(ev, 0, sizeof(*ev));
110 ev->ev = EVENT_ABORT;
113 static inline void
114 set_wh_term_event(struct term_event *ev, enum term_event_type type, int width, int height)
116 memset(ev, 0, sizeof(*ev));
117 ev->ev = type;
118 ev->info.size.width = width;
119 ev->info.size.height = height;
122 #define set_init_term_event(ev, w, h) set_wh_term_event(ev, EVENT_INIT, w, h)
123 #define set_resize_term_event(ev, w, h) set_wh_term_event(ev, EVENT_RESIZE, w, h)
124 #define set_redraw_term_event(ev, w, h) set_wh_term_event(ev, EVENT_REDRAW, w, h)
126 static inline void
127 set_wh_interlink_event(struct interlink_event *ev, enum term_event_type type, int width, int height)
129 memset(ev, 0, sizeof(*ev));
130 ev->ev = type;
131 ev->info.size.width = width;
132 ev->info.size.height = height;
135 #define set_resize_interlink_event(ev, w, h) set_wh_interlink_event(ev, EVENT_RESIZE, w, h)
138 /** This holds the information used when handling the initial
139 * connection between a dumb and master terminal.
141 * XXX: We might be connecting to an older ELinks or an older ELinks is
142 * connecting to a newer ELinks master so for the sake of compatibility it
143 * would be unwise to just change the layout of the struct. If you do have to
144 * add new members add them at the bottom and use magic variables to
145 * distinguish them when decoding the terminal info. */
146 struct terminal_info {
147 struct interlink_event event; /**< The ::EVENT_INIT event */
148 unsigned char name[MAX_TERM_LEN]; /**< $TERM environment name */
149 unsigned char cwd[MAX_CWD_LEN]; /**< Current working directory */
150 int system_env; /**< System info (X, screen) */
151 int length; /**< Length of #data member */
152 int session_info; /**< Value depends on #magic */
153 int magic; /**< Identity of the connector */
155 /** In the master that is connected to all bytes after @c data
156 * will be interpreted as URI string information. */
157 unsigned char data[1];
160 /** The terminal_info.data member has to have size of one for
161 * portability but it can be empty/zero so when reading and writing it
162 * we need to ignore the byte. */
163 #define TERMINAL_INFO_SIZE offsetof(struct terminal_info, data)
165 /** We use magic numbers to signal the identity of the dump client terminal.
166 * Magic numbers are composed by the INTERLINK_MAGIC() macro. It is a negative
167 * magic to be able to distinguish the oldest format from the newer ones. */
168 #define INTERLINK_MAGIC(major, minor) -(((major) << 8) + (minor))
170 #define INTERLINK_NORMAL_MAGIC INTERLINK_MAGIC(1, 0)
171 #define INTERLINK_REMOTE_MAGIC INTERLINK_MAGIC(1, 1)
173 void term_send_event(struct terminal *, struct term_event *);
174 void in_term(struct terminal *);
176 /** @name For keyboard events handling
177 * @{ */
178 #define get_kbd_key(event) (kbd_get_key(&(event)->info.keyboard))
179 #define check_kbd_key(event, key) (kbd_key_is(&(event)->info.keyboard, (key)))
181 #define get_kbd_modifier(event) (kbd_get_modifier(&(event)->info.keyboard))
182 #define check_kbd_modifier(event, mod) (kbd_modifier_is(&(event)->info.keyboard, (mod)))
184 #define check_kbd_textinput_key(event) (get_kbd_key(event) >= ' ' && check_kbd_modifier(event, KBD_MOD_NONE))
185 #define check_kbd_label_key(event) (get_kbd_key(event) > ' ' && (check_kbd_modifier(event, KBD_MOD_NONE) || check_kbd_modifier(event, KBD_MOD_ALT)))
186 /** @} */
189 /** @name For mouse events handling
190 * @{ */
191 #define get_mouse_action(event) (mouse_get_action(&(event)->info.mouse))
192 #define check_mouse_action(event, value) (mouse_action_is(&(event)->info.mouse, (value)))
194 #define get_mouse_button(event) (mouse_get_button(&(event)->info.mouse))
195 #define check_mouse_button(event, value) (mouse_button_is(&(event)->info.mouse, (value)))
196 #define check_mouse_wheel(event) (mouse_wheeling(&(event)->info.mouse))
198 #define check_mouse_position(event, box) \
199 mouse_is_in_box(&(event)->info.mouse, box)
200 /** @} */
203 #endif /* EL__TERMINAL_EVENT_H */