summaryrefslogtreecommitdiffstats
path: root/input-keys.c
diff options
context:
space:
mode:
authornicm <nicm>2015-04-19 21:34:21 +0000
committernicm <nicm>2015-04-19 21:34:21 +0000
commitbf635e7741f7b881f67ec7e4a5caa02f7ff3d786 (patch)
treec2da2accbb948824e54043a1539b2e3ca9187168 /input-keys.c
parentee123c248951450100475717f5bd45f292d9bb4d (diff)
Rewrite of tmux mouse support which was a mess. Instead of having
options for "mouse-this" and "mouse-that", mouse events may be bound as keys and there is one option "mouse" that turns on mouse support entirely (set -g mouse on). See the new MOUSE SUPPORT section of the man page for description of the key names and new flags (-t= to specify the pane or window under mouse as a target, and send-keys -M to pass through a mouse event). The default builtin bindings for the mouse are: bind -n MouseDown1Pane select-pane -t=; send-keys -M bind -n MouseDown1Status select-window -t= bind -n MouseDrag1Pane copy-mode -M bind -n MouseDrag1Border resize-pane -M To get the effect of turning mode-mouse off, do: unbind -n MouseDrag1Pane unbind -temacs-copy MouseDrag1Pane The old mouse options are now gone, set-option -q may be used to suppress warnings if mixing configuration files.
Diffstat (limited to 'input-keys.c')
-rw-r--r--input-keys.c97
1 files changed, 49 insertions, 48 deletions
diff --git a/input-keys.c b/input-keys.c
index f2d010d8..ae00e4a9 100644
--- a/input-keys.c
+++ b/input-keys.c
@@ -31,6 +31,8 @@
* direction with output).
*/
+void input_key_mouse(struct window_pane *, struct mouse_event *);
+
struct input_key_ent {
int key;
const char *data;
@@ -135,7 +137,7 @@ const struct input_key_ent input_keys[] = {
/* Translate a key code into an output key sequence. */
void
-input_key(struct window_pane *wp, int key)
+input_key(struct window_pane *wp, int key, struct mouse_event *m)
{
const struct input_key_ent *ike;
u_int i;
@@ -143,7 +145,14 @@ input_key(struct window_pane *wp, int key)
char *out;
u_char ch;
- log_debug("writing key 0x%x", key);
+ log_debug("writing key 0x%x (%s)", key, key_string_lookup_key(key));
+
+ /* If this is a mouse key, pass off to mouse function. */
+ if (KEYC_IS_MOUSE(key)) {
+ if (m != NULL && m->wp != -1 && (u_int)m->wp == wp->id)
+ input_key_mouse(wp, m);
+ return;
+ }
/*
* If this is a normal 7-bit key, just send it, with a leading escape
@@ -200,55 +209,47 @@ input_key(struct window_pane *wp, int key)
/* Translate mouse and output. */
void
-input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
+input_key_mouse(struct window_pane *wp, struct mouse_event *m)
{
- char buf[40];
- size_t len;
- struct paste_buffer *pb;
- int event;
-
- if (wp->screen->mode & ALL_MOUSE_MODES) {
- /*
- * Use the SGR (1006) extension only if the application
- * requested it and the underlying terminal also sent the event
- * in this format (this is because an old style mouse release
- * event cannot be converted into the new SGR format, since the
- * released button is unknown). Otherwise pretend that tmux
- * doesn't speak this extension, and fall back to the UTF-8
- * (1005) extension if the application requested, or to the
- * legacy format.
- */
- if (m->sgr && (wp->screen->mode & MODE_MOUSE_SGR)) {
- len = xsnprintf(buf, sizeof buf, "\033[<%u;%u;%u%c",
- m->sgr_xb, m->x + 1, m->y + 1,
- m->sgr_rel ? 'm' : 'M');
- } else if (wp->screen->mode & MODE_MOUSE_UTF8) {
- len = xsnprintf(buf, sizeof buf, "\033[M");
- len += utf8_split2(m->xb + 32, &buf[len]);
- len += utf8_split2(m->x + 33, &buf[len]);
- len += utf8_split2(m->y + 33, &buf[len]);
- } else {
- if (m->xb > 223)
- return;
- len = xsnprintf(buf, sizeof buf, "\033[M");
- buf[len++] = m->xb + 32;
- buf[len++] = m->x + 33;
- buf[len++] = m->y + 33;
- }
- bufferevent_write(wp->event, buf, len);
+ char buf[40];
+ size_t len;
+ u_int x, y;
+
+ if ((wp->screen->mode & ALL_MOUSE_MODES) == 0)
+ return;
+ if (!window_pane_visible(wp))
+ return;
+ if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
return;
- }
- if (options_get_number(&wp->window->options, "mode-mouse") != 1)
+ /* If this pane is not in button mode, discard motion events. */
+ if (!(wp->screen->mode & MODE_MOUSE_BUTTON) && (m->b & MOUSE_MASK_DRAG))
return;
- event = m->event & (MOUSE_EVENT_CLICK|MOUSE_EVENT_WHEEL);
- if (wp->mode == NULL && m->button == 1 && event == MOUSE_EVENT_CLICK) {
- pb = paste_get_top();
- if (pb != NULL)
- paste_send_pane(pb, wp, "\r", 1);
- } else if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
- window_copy_init_from_pane(wp);
- if (wp->mode->mouse != NULL)
- wp->mode->mouse(wp, s, m);
+
+ /*
+ * Use the SGR (1006) extension only if the application requested it
+ * and the underlying terminal also sent the event in this format (this
+ * is because an old style mouse release event cannot be converted into
+ * the new SGR format, since the released button is unknown). Otherwise
+ * pretend that tmux doesn't speak this extension, and fall back to the
+ * UTF-8 (1005) extension if the application requested, or to the
+ * legacy format.
+ */
+ if (m->sgr_type != ' ' && (wp->screen->mode & MODE_MOUSE_SGR)) {
+ len = xsnprintf(buf, sizeof buf, "\033[<%u;%u;%u%c",
+ m->sgr_b, x + 1, y + 1, m->sgr_type);
+ } else if (wp->screen->mode & MODE_MOUSE_UTF8) {
+ len = xsnprintf(buf, sizeof buf, "\033[M");
+ len += utf8_split2(m->b + 32, &buf[len]);
+ len += utf8_split2(x + 33, &buf[len]);
+ len += utf8_split2(y + 33, &buf[len]);
+ } else {
+ if (m->b > 223)
+ return;
+ len = xsnprintf(buf, sizeof buf, "\033[M");
+ buf[len++] = m->b + 32;
+ buf[len++] = x + 33;
+ buf[len++] = y + 33;
}
+ bufferevent_write(wp->event, buf, len);
}
f='#n86'>86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354