4 * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
20 #include <sys/ioctl.h>
32 static void server_client_free(int, short, void *);
33 static void server_client_check_pane_resize(struct window_pane
*);
34 static void server_client_check_pane_buffer(struct window_pane
*);
35 static void server_client_check_window_resize(struct window
*);
36 static key_code
server_client_check_mouse(struct client
*, struct key_event
*);
37 static void server_client_repeat_timer(int, short, void *);
38 static void server_client_click_timer(int, short, void *);
39 static void server_client_check_exit(struct client
*);
40 static void server_client_check_redraw(struct client
*);
41 static void server_client_check_modes(struct client
*);
42 static void server_client_set_title(struct client
*);
43 static void server_client_set_path(struct client
*);
44 static void server_client_reset_state(struct client
*);
45 static void server_client_update_latest(struct client
*);
47 static void server_client_dispatch(struct imsg
*, void *);
48 static void server_client_dispatch_command(struct client
*, struct imsg
*);
49 static void server_client_dispatch_identify(struct client
*, struct imsg
*);
50 static void server_client_dispatch_shell(struct client
*);
52 /* Compare client windows. */
54 server_client_window_cmp(struct client_window
*cw1
,
55 struct client_window
*cw2
)
57 if (cw1
->window
< cw2
->window
)
59 if (cw1
->window
> cw2
->window
)
63 RB_GENERATE(client_windows
, client_window
, entry
, server_client_window_cmp
);
65 /* Number of attached clients. */
67 server_client_how_many(void)
73 TAILQ_FOREACH(c
, &clients
, entry
) {
74 if (c
->session
!= NULL
&& (~c
->flags
& CLIENT_UNATTACHEDFLAGS
))
80 /* Overlay timer callback. */
82 server_client_overlay_timer(__unused
int fd
, __unused
short events
, void *data
)
84 server_client_clear_overlay(data
);
87 /* Set an overlay on client. */
89 server_client_set_overlay(struct client
*c
, u_int delay
,
90 overlay_check_cb checkcb
, overlay_mode_cb modecb
,
91 overlay_draw_cb drawcb
, overlay_key_cb keycb
, overlay_free_cb freecb
,
92 overlay_resize_cb resizecb
, void *data
)
96 if (c
->overlay_draw
!= NULL
)
97 server_client_clear_overlay(c
);
99 tv
.tv_sec
= delay
/ 1000;
100 tv
.tv_usec
= (delay
% 1000) * 1000L;
102 if (event_initialized(&c
->overlay_timer
))
103 evtimer_del(&c
->overlay_timer
);
104 evtimer_set(&c
->overlay_timer
, server_client_overlay_timer
, c
);
106 evtimer_add(&c
->overlay_timer
, &tv
);
108 c
->overlay_check
= checkcb
;
109 c
->overlay_mode
= modecb
;
110 c
->overlay_draw
= drawcb
;
111 c
->overlay_key
= keycb
;
112 c
->overlay_free
= freecb
;
113 c
->overlay_resize
= resizecb
;
114 c
->overlay_data
= data
;
116 if (c
->overlay_check
== NULL
)
117 c
->tty
.flags
|= TTY_FREEZE
;
118 if (c
->overlay_mode
== NULL
)
119 c
->tty
.flags
|= TTY_NOCURSOR
;
120 window_update_focus(c
->session
->curw
->window
);
121 server_redraw_client(c
);
124 /* Clear overlay mode on client. */
126 server_client_clear_overlay(struct client
*c
)
128 if (c
->overlay_draw
== NULL
)
131 if (event_initialized(&c
->overlay_timer
))
132 evtimer_del(&c
->overlay_timer
);
134 if (c
->overlay_free
!= NULL
)
135 c
->overlay_free(c
, c
->overlay_data
);
137 c
->overlay_check
= NULL
;
138 c
->overlay_mode
= NULL
;
139 c
->overlay_draw
= NULL
;
140 c
->overlay_key
= NULL
;
141 c
->overlay_free
= NULL
;
142 c
->overlay_data
= NULL
;
144 c
->tty
.flags
&= ~(TTY_FREEZE
|TTY_NOCURSOR
);
145 window_update_focus(c
->session
->curw
->window
);
146 server_redraw_client(c
);
150 * Given overlay position and dimensions, return parts of the input range which
154 server_client_overlay_range(u_int x
, u_int y
, u_int sx
, u_int sy
, u_int px
,
155 u_int py
, u_int nx
, struct overlay_ranges
*r
)
159 /* Return up to 2 ranges. */
163 /* Trivial case of no overlap in the y direction. */
164 if (py
< y
|| py
> y
+ sy
- 1) {
172 /* Visible bit to the left of the popup. */
183 /* Visible bit to the right of the popup. */
197 /* Check if this client is inside this server. */
199 server_client_check_nested(struct client
*c
)
201 struct environ_entry
*envent
;
202 struct window_pane
*wp
;
204 envent
= environ_find(c
->environ
, "TMUX");
205 if (envent
== NULL
|| *envent
->value
== '\0')
208 RB_FOREACH(wp
, window_pane_tree
, &all_window_panes
) {
209 if (strcmp(wp
->tty
, c
->ttyname
) == 0)
215 /* Set client key table. */
217 server_client_set_key_table(struct client
*c
, const char *name
)
220 name
= server_client_get_key_table(c
);
222 key_bindings_unref_table(c
->keytable
);
223 c
->keytable
= key_bindings_get_table(name
, 1);
224 c
->keytable
->references
++;
225 if (gettimeofday(&c
->keytable
->activity_time
, NULL
) != 0)
226 fatal("gettimeofday failed");
230 server_client_key_table_activity_diff(struct client
*c
)
234 timersub(&c
->activity_time
, &c
->keytable
->activity_time
, &diff
);
235 return ((diff
.tv_sec
* 1000ULL) + (diff
.tv_usec
/ 1000ULL));
238 /* Get default key table. */
240 server_client_get_key_table(struct client
*c
)
242 struct session
*s
= c
->session
;
248 name
= options_get_string(s
->options
, "key-table");
254 /* Is this table the default key table? */
256 server_client_is_default_key_table(struct client
*c
, struct key_table
*table
)
258 return (strcmp(table
->name
, server_client_get_key_table(c
)) == 0);
261 /* Create a new client. */
263 server_client_create(int fd
)
269 c
= xcalloc(1, sizeof *c
);
271 c
->peer
= proc_add_peer(server_proc
, fd
, server_client_dispatch
, c
);
273 if (gettimeofday(&c
->creation_time
, NULL
) != 0)
274 fatal("gettimeofday failed");
275 memcpy(&c
->activity_time
, &c
->creation_time
, sizeof c
->activity_time
);
277 c
->environ
= environ_create();
282 c
->queue
= cmdq_new();
283 RB_INIT(&c
->windows
);
290 c
->flags
|= CLIENT_FOCUSED
;
292 c
->keytable
= key_bindings_get_table("root", 1);
293 c
->keytable
->references
++;
295 evtimer_set(&c
->repeat_timer
, server_client_repeat_timer
, c
);
296 evtimer_set(&c
->click_timer
, server_client_click_timer
, c
);
298 TAILQ_INSERT_TAIL(&clients
, c
, entry
);
299 log_debug("new client %p", c
);
303 /* Open client terminal if needed. */
305 server_client_open(struct client
*c
, char **cause
)
307 const char *ttynam
= _PATH_TTY
;
309 if (c
->flags
& CLIENT_CONTROL
)
312 if (strcmp(c
->ttyname
, ttynam
) == 0||
313 ((isatty(STDIN_FILENO
) &&
314 (ttynam
= ttyname(STDIN_FILENO
)) != NULL
&&
315 strcmp(c
->ttyname
, ttynam
) == 0) ||
316 (isatty(STDOUT_FILENO
) &&
317 (ttynam
= ttyname(STDOUT_FILENO
)) != NULL
&&
318 strcmp(c
->ttyname
, ttynam
) == 0) ||
319 (isatty(STDERR_FILENO
) &&
320 (ttynam
= ttyname(STDERR_FILENO
)) != NULL
&&
321 strcmp(c
->ttyname
, ttynam
) == 0))) {
322 xasprintf(cause
, "can't use %s", c
->ttyname
);
326 if (!(c
->flags
& CLIENT_TERMINAL
)) {
327 *cause
= xstrdup("not a terminal");
331 if (tty_open(&c
->tty
, cause
) != 0)
337 /* Lost an attached client. */
339 server_client_attached_lost(struct client
*c
)
344 struct client
*found
;
346 log_debug("lost attached client %p", c
);
349 * By this point the session in the client has been cleared so walk all
350 * windows to find any with this client as the latest.
352 RB_FOREACH(w
, windows
, &windows
) {
357 TAILQ_FOREACH(loop
, &clients
, entry
) {
359 if (loop
== c
|| s
== NULL
|| s
->curw
->window
!= w
)
361 if (found
== NULL
|| timercmp(&loop
->activity_time
,
362 &found
->activity_time
, >))
366 server_client_update_latest(found
);
370 /* Set client session. */
372 server_client_set_session(struct client
*c
, struct session
*s
)
374 struct session
*old
= c
->session
;
376 if (s
!= NULL
&& c
->session
!= NULL
&& c
->session
!= s
)
377 c
->last_session
= c
->session
;
379 c
->last_session
= NULL
;
381 c
->flags
|= CLIENT_FOCUSED
;
383 if (old
!= NULL
&& old
->curw
!= NULL
)
384 window_update_focus(old
->curw
->window
);
387 window_update_focus(s
->curw
->window
);
388 session_update_activity(s
, NULL
);
389 gettimeofday(&s
->last_attached_time
, NULL
);
390 s
->curw
->flags
&= ~WINLINK_ALERTFLAGS
;
391 s
->curw
->window
->latest
= c
;
392 alerts_check_session(s
);
393 tty_update_client_offset(c
);
394 status_timer_start(c
);
395 notify_client("client-session-changed", c
);
396 server_redraw_client(c
);
399 server_check_unattached();
400 server_update_socket();
405 server_client_lost(struct client
*c
)
407 struct client_file
*cf
, *cf1
;
408 struct client_window
*cw
, *cw1
;
410 c
->flags
|= CLIENT_DEAD
;
412 server_client_clear_overlay(c
);
413 status_prompt_clear(c
);
414 status_message_clear(c
);
416 RB_FOREACH_SAFE(cf
, client_files
, &c
->files
, cf1
) {
420 RB_FOREACH_SAFE(cw
, client_windows
, &c
->windows
, cw1
) {
421 RB_REMOVE(client_windows
, &c
->windows
, cw
);
425 TAILQ_REMOVE(&clients
, c
, entry
);
426 log_debug("lost client %p", c
);
428 if (c
->flags
& CLIENT_ATTACHED
) {
429 server_client_attached_lost(c
);
430 notify_client("client-detached", c
);
433 if (c
->flags
& CLIENT_CONTROL
)
435 if (c
->flags
& CLIENT_TERMINAL
)
438 free(c
->clipboard_panes
);
442 tty_term_free_list(c
->term_caps
, c
->term_ncaps
);
447 free((void *)c
->cwd
);
449 evtimer_del(&c
->repeat_timer
);
450 evtimer_del(&c
->click_timer
);
452 key_bindings_unref_table(c
->keytable
);
454 free(c
->message_string
);
455 if (event_initialized(&c
->message_timer
))
456 evtimer_del(&c
->message_timer
);
458 free(c
->prompt_saved
);
459 free(c
->prompt_string
);
460 free(c
->prompt_buffer
);
462 format_lost_client(c
);
463 environ_free(c
->environ
);
465 proc_remove_peer(c
->peer
);
474 server_client_unref(c
);
476 server_add_accept(0); /* may be more file descriptors now */
479 server_check_unattached();
480 server_update_socket();
483 /* Remove reference from a client. */
485 server_client_unref(struct client
*c
)
487 log_debug("unref client %p (%d references)", c
, c
->references
);
490 if (c
->references
== 0)
491 event_once(-1, EV_TIMEOUT
, server_client_free
, c
, NULL
);
494 /* Free dead client. */
496 server_client_free(__unused
int fd
, __unused
short events
, void *arg
)
498 struct client
*c
= arg
;
500 log_debug("free client %p (%d references)", c
, c
->references
);
504 if (c
->references
== 0) {
505 free((void *)c
->name
);
510 /* Suspend a client. */
512 server_client_suspend(struct client
*c
)
514 struct session
*s
= c
->session
;
516 if (s
== NULL
|| (c
->flags
& CLIENT_UNATTACHEDFLAGS
))
519 tty_stop_tty(&c
->tty
);
520 c
->flags
|= CLIENT_SUSPENDED
;
521 proc_send(c
->peer
, MSG_SUSPEND
, -1, NULL
, 0);
524 /* Detach a client. */
526 server_client_detach(struct client
*c
, enum msgtype msgtype
)
528 struct session
*s
= c
->session
;
530 if (s
== NULL
|| (c
->flags
& CLIENT_NODETACHFLAGS
))
533 c
->flags
|= CLIENT_EXIT
;
535 c
->exit_type
= CLIENT_EXIT_DETACH
;
536 c
->exit_msgtype
= msgtype
;
537 c
->exit_session
= xstrdup(s
->name
);
540 /* Execute command to replace a client. */
542 server_client_exec(struct client
*c
, const char *cmd
)
544 struct session
*s
= c
->session
;
547 size_t cmdsize
, shellsize
;
551 cmdsize
= strlen(cmd
) + 1;
554 shell
= options_get_string(s
->options
, "default-shell");
556 shell
= options_get_string(global_s_options
, "default-shell");
557 if (!checkshell(shell
))
558 shell
= _PATH_BSHELL
;
559 shellsize
= strlen(shell
) + 1;
561 msg
= xmalloc(cmdsize
+ shellsize
);
562 memcpy(msg
, cmd
, cmdsize
);
563 memcpy(msg
+ cmdsize
, shell
, shellsize
);
565 proc_send(c
->peer
, MSG_EXEC
, -1, msg
, cmdsize
+ shellsize
);
569 /* Check for mouse keys. */
571 server_client_check_mouse(struct client
*c
, struct key_event
*event
)
573 struct mouse_event
*m
= &event
->m
;
574 struct session
*s
= c
->session
, *fs
;
576 struct window_pane
*wp
, *fwp
;
577 u_int x
, y
, b
, sx
, sy
, px
, py
;
581 struct style_range
*sr
;
590 TRIPLE
} type
= NOTYPE
;
597 BORDER
} where
= NOWHERE
;
599 log_debug("%s mouse %02x at %u,%u (last %u,%u) (%d)", c
->name
, m
->b
,
600 m
->x
, m
->y
, m
->lx
, m
->ly
, c
->tty
.mouse_drag_flag
);
602 /* What type of event is this? */
603 if (event
->key
== KEYC_DOUBLECLICK
) {
605 x
= m
->x
, y
= m
->y
, b
= m
->b
;
607 log_debug("double-click at %u,%u", x
, y
);
608 } else if ((m
->sgr_type
!= ' ' &&
609 MOUSE_DRAG(m
->sgr_b
) &&
610 MOUSE_RELEASE(m
->sgr_b
)) ||
611 (m
->sgr_type
== ' ' &&
613 MOUSE_RELEASE(m
->b
) &&
614 MOUSE_RELEASE(m
->lb
))) {
616 x
= m
->x
, y
= m
->y
, b
= 0;
617 log_debug("move at %u,%u", x
, y
);
618 } else if (MOUSE_DRAG(m
->b
)) {
620 if (c
->tty
.mouse_drag_flag
) {
621 x
= m
->x
, y
= m
->y
, b
= m
->b
;
622 if (x
== m
->lx
&& y
== m
->ly
)
623 return (KEYC_UNKNOWN
);
624 log_debug("drag update at %u,%u", x
, y
);
626 x
= m
->lx
, y
= m
->ly
, b
= m
->lb
;
627 log_debug("drag start at %u,%u", x
, y
);
629 } else if (MOUSE_WHEEL(m
->b
)) {
631 x
= m
->x
, y
= m
->y
, b
= m
->b
;
632 log_debug("wheel at %u,%u", x
, y
);
633 } else if (MOUSE_RELEASE(m
->b
)) {
635 x
= m
->x
, y
= m
->y
, b
= m
->lb
;
636 if (m
->sgr_type
== 'm')
638 log_debug("up at %u,%u", x
, y
);
640 if (c
->flags
& CLIENT_DOUBLECLICK
) {
641 evtimer_del(&c
->click_timer
);
642 c
->flags
&= ~CLIENT_DOUBLECLICK
;
643 if (m
->b
== c
->click_button
) {
645 x
= m
->x
, y
= m
->y
, b
= m
->b
;
646 log_debug("second-click at %u,%u", x
, y
);
647 c
->flags
|= CLIENT_TRIPLECLICK
;
649 } else if (c
->flags
& CLIENT_TRIPLECLICK
) {
650 evtimer_del(&c
->click_timer
);
651 c
->flags
&= ~CLIENT_TRIPLECLICK
;
652 if (m
->b
== c
->click_button
) {
654 x
= m
->x
, y
= m
->y
, b
= m
->b
;
655 log_debug("triple-click at %u,%u", x
, y
);
660 /* DOWN is the only remaining event type. */
661 if (type
== NOTYPE
) {
663 x
= m
->x
, y
= m
->y
, b
= m
->b
;
664 log_debug("down at %u,%u", x
, y
);
665 c
->flags
|= CLIENT_DOUBLECLICK
;
668 if (KEYC_CLICK_TIMEOUT
!= 0) {
669 memcpy(&c
->click_event
, m
, sizeof c
->click_event
);
670 c
->click_button
= m
->b
;
672 log_debug("click timer started");
673 tv
.tv_sec
= KEYC_CLICK_TIMEOUT
/ 1000;
674 tv
.tv_usec
= (KEYC_CLICK_TIMEOUT
% 1000) * 1000L;
675 evtimer_del(&c
->click_timer
);
676 evtimer_add(&c
->click_timer
, &tv
);
682 return (KEYC_UNKNOWN
);
684 /* Save the session. */
690 /* Is this on the status line? */
691 m
->statusat
= status_at_line(c
);
692 m
->statuslines
= status_line_size(c
);
693 if (m
->statusat
!= -1 &&
694 y
>= (u_int
)m
->statusat
&&
695 y
< m
->statusat
+ m
->statuslines
) {
696 sr
= status_get_range(c
, x
, y
- m
->statusat
);
698 where
= STATUS_DEFAULT
;
701 case STYLE_RANGE_NONE
:
702 return (KEYC_UNKNOWN
);
703 case STYLE_RANGE_LEFT
:
704 log_debug("mouse range: left");
707 case STYLE_RANGE_RIGHT
:
708 log_debug("mouse range: right");
709 where
= STATUS_RIGHT
;
711 case STYLE_RANGE_PANE
:
712 fwp
= window_pane_find_by_id(sr
->argument
);
714 return (KEYC_UNKNOWN
);
715 m
->wp
= sr
->argument
;
717 log_debug("mouse range: pane %%%u", m
->wp
);
720 case STYLE_RANGE_WINDOW
:
721 fwl
= winlink_find_by_index(&s
->windows
,
724 return (KEYC_UNKNOWN
);
725 m
->w
= fwl
->window
->id
;
727 log_debug("mouse range: window @%u", m
->w
);
730 case STYLE_RANGE_SESSION
:
731 fs
= session_find_by_id(sr
->argument
);
733 return (KEYC_UNKNOWN
);
736 log_debug("mouse range: session $%u", m
->s
);
739 case STYLE_RANGE_USER
:
746 /* Not on status line. Adjust position and check for border or pane. */
747 if (where
== NOWHERE
) {
749 if (m
->statusat
== 0 && y
>= m
->statuslines
)
750 py
= y
- m
->statuslines
;
751 else if (m
->statusat
> 0 && y
>= (u_int
)m
->statusat
)
752 py
= m
->statusat
- 1;
756 tty_window_offset(&c
->tty
, &m
->ox
, &m
->oy
, &sx
, &sy
);
757 log_debug("mouse window @%u at %u,%u (%ux%u)",
758 s
->curw
->window
->id
, m
->ox
, m
->oy
, sx
, sy
);
759 if (px
> sx
|| py
> sy
)
760 return (KEYC_UNKNOWN
);
764 /* Try the pane borders if not zoomed. */
765 if (~s
->curw
->window
->flags
& WINDOW_ZOOMED
) {
766 TAILQ_FOREACH(wp
, &s
->curw
->window
->panes
, entry
) {
767 if ((wp
->xoff
+ wp
->sx
== px
&&
768 wp
->yoff
<= 1 + py
&&
769 wp
->yoff
+ wp
->sy
>= py
) ||
770 (wp
->yoff
+ wp
->sy
== py
&&
771 wp
->xoff
<= 1 + px
&&
772 wp
->xoff
+ wp
->sx
>= px
))
779 /* Otherwise try inside the pane. */
780 if (where
== NOWHERE
) {
781 wp
= window_get_active_at(s
->curw
->window
, px
, py
);
785 return (KEYC_UNKNOWN
);
788 log_debug("mouse %u,%u on pane %%%u", x
, y
, wp
->id
);
789 else if (where
== BORDER
)
790 log_debug("mouse on pane %%%u border", wp
->id
);
792 m
->w
= wp
->window
->id
;
795 /* Stop dragging if needed. */
796 if (type
!= DRAG
&& type
!= WHEEL
&& c
->tty
.mouse_drag_flag
!= 0) {
797 if (c
->tty
.mouse_drag_release
!= NULL
)
798 c
->tty
.mouse_drag_release(c
, m
);
800 c
->tty
.mouse_drag_update
= NULL
;
801 c
->tty
.mouse_drag_release
= NULL
;
804 * End a mouse drag by passing a MouseDragEnd key corresponding
805 * to the button that started the drag.
807 switch (c
->tty
.mouse_drag_flag
- 1) {
810 key
= KEYC_MOUSEDRAGEND1_PANE
;
812 key
= KEYC_MOUSEDRAGEND1_STATUS
;
813 if (where
== STATUS_LEFT
)
814 key
= KEYC_MOUSEDRAGEND1_STATUS_LEFT
;
815 if (where
== STATUS_RIGHT
)
816 key
= KEYC_MOUSEDRAGEND1_STATUS_RIGHT
;
817 if (where
== STATUS_DEFAULT
)
818 key
= KEYC_MOUSEDRAGEND1_STATUS_DEFAULT
;
820 key
= KEYC_MOUSEDRAGEND1_BORDER
;
824 key
= KEYC_MOUSEDRAGEND2_PANE
;
826 key
= KEYC_MOUSEDRAGEND2_STATUS
;
827 if (where
== STATUS_LEFT
)
828 key
= KEYC_MOUSEDRAGEND2_STATUS_LEFT
;
829 if (where
== STATUS_RIGHT
)
830 key
= KEYC_MOUSEDRAGEND2_STATUS_RIGHT
;
831 if (where
== STATUS_DEFAULT
)
832 key
= KEYC_MOUSEDRAGEND2_STATUS_DEFAULT
;
834 key
= KEYC_MOUSEDRAGEND2_BORDER
;
838 key
= KEYC_MOUSEDRAGEND3_PANE
;
840 key
= KEYC_MOUSEDRAGEND3_STATUS
;
841 if (where
== STATUS_LEFT
)
842 key
= KEYC_MOUSEDRAGEND3_STATUS_LEFT
;
843 if (where
== STATUS_RIGHT
)
844 key
= KEYC_MOUSEDRAGEND3_STATUS_RIGHT
;
845 if (where
== STATUS_DEFAULT
)
846 key
= KEYC_MOUSEDRAGEND3_STATUS_DEFAULT
;
848 key
= KEYC_MOUSEDRAGEND3_BORDER
;
852 key
= KEYC_MOUSEDRAGEND6_PANE
;
854 key
= KEYC_MOUSEDRAGEND6_STATUS
;
855 if (where
== STATUS_LEFT
)
856 key
= KEYC_MOUSEDRAGEND6_STATUS_LEFT
;
857 if (where
== STATUS_RIGHT
)
858 key
= KEYC_MOUSEDRAGEND6_STATUS_RIGHT
;
859 if (where
== STATUS_DEFAULT
)
860 key
= KEYC_MOUSEDRAGEND6_STATUS_DEFAULT
;
862 key
= KEYC_MOUSEDRAGEND6_BORDER
;
866 key
= KEYC_MOUSEDRAGEND7_PANE
;
868 key
= KEYC_MOUSEDRAGEND7_STATUS
;
869 if (where
== STATUS_LEFT
)
870 key
= KEYC_MOUSEDRAGEND7_STATUS_LEFT
;
871 if (where
== STATUS_RIGHT
)
872 key
= KEYC_MOUSEDRAGEND7_STATUS_RIGHT
;
873 if (where
== STATUS_DEFAULT
)
874 key
= KEYC_MOUSEDRAGEND7_STATUS_DEFAULT
;
876 key
= KEYC_MOUSEDRAGEND7_BORDER
;
880 key
= KEYC_MOUSEDRAGEND8_PANE
;
882 key
= KEYC_MOUSEDRAGEND8_STATUS
;
883 if (where
== STATUS_LEFT
)
884 key
= KEYC_MOUSEDRAGEND8_STATUS_LEFT
;
885 if (where
== STATUS_RIGHT
)
886 key
= KEYC_MOUSEDRAGEND8_STATUS_RIGHT
;
887 if (where
== STATUS_DEFAULT
)
888 key
= KEYC_MOUSEDRAGEND8_STATUS_DEFAULT
;
890 key
= KEYC_MOUSEDRAGEND8_BORDER
;
894 key
= KEYC_MOUSEDRAGEND9_PANE
;
896 key
= KEYC_MOUSEDRAGEND9_STATUS
;
897 if (where
== STATUS_LEFT
)
898 key
= KEYC_MOUSEDRAGEND9_STATUS_LEFT
;
899 if (where
== STATUS_RIGHT
)
900 key
= KEYC_MOUSEDRAGEND9_STATUS_RIGHT
;
901 if (where
== STATUS_DEFAULT
)
902 key
= KEYC_MOUSEDRAGEND9_STATUS_DEFAULT
;
904 key
= KEYC_MOUSEDRAGEND9_BORDER
;
906 case MOUSE_BUTTON_10
:
908 key
= KEYC_MOUSEDRAGEND10_PANE
;
910 key
= KEYC_MOUSEDRAGEND10_STATUS
;
911 if (where
== STATUS_LEFT
)
912 key
= KEYC_MOUSEDRAGEND10_STATUS_LEFT
;
913 if (where
== STATUS_RIGHT
)
914 key
= KEYC_MOUSEDRAGEND10_STATUS_RIGHT
;
915 if (where
== STATUS_DEFAULT
)
916 key
= KEYC_MOUSEDRAGEND10_STATUS_DEFAULT
;
918 key
= KEYC_MOUSEDRAGEND10_BORDER
;
920 case MOUSE_BUTTON_11
:
922 key
= KEYC_MOUSEDRAGEND11_PANE
;
924 key
= KEYC_MOUSEDRAGEND11_STATUS
;
925 if (where
== STATUS_LEFT
)
926 key
= KEYC_MOUSEDRAGEND11_STATUS_LEFT
;
927 if (where
== STATUS_RIGHT
)
928 key
= KEYC_MOUSEDRAGEND11_STATUS_RIGHT
;
929 if (where
== STATUS_DEFAULT
)
930 key
= KEYC_MOUSEDRAGEND11_STATUS_DEFAULT
;
932 key
= KEYC_MOUSEDRAGEND11_BORDER
;
938 c
->tty
.mouse_drag_flag
= 0;
942 /* Convert to a key binding. */
949 key
= KEYC_MOUSEMOVE_PANE
;
951 key
= KEYC_MOUSEMOVE_STATUS
;
952 if (where
== STATUS_LEFT
)
953 key
= KEYC_MOUSEMOVE_STATUS_LEFT
;
954 if (where
== STATUS_RIGHT
)
955 key
= KEYC_MOUSEMOVE_STATUS_RIGHT
;
956 if (where
== STATUS_DEFAULT
)
957 key
= KEYC_MOUSEMOVE_STATUS_DEFAULT
;
959 key
= KEYC_MOUSEMOVE_BORDER
;
962 if (c
->tty
.mouse_drag_update
!= NULL
)
965 switch (MOUSE_BUTTONS(b
)) {
968 key
= KEYC_MOUSEDRAG1_PANE
;
970 key
= KEYC_MOUSEDRAG1_STATUS
;
971 if (where
== STATUS_LEFT
)
972 key
= KEYC_MOUSEDRAG1_STATUS_LEFT
;
973 if (where
== STATUS_RIGHT
)
974 key
= KEYC_MOUSEDRAG1_STATUS_RIGHT
;
975 if (where
== STATUS_DEFAULT
)
976 key
= KEYC_MOUSEDRAG1_STATUS_DEFAULT
;
978 key
= KEYC_MOUSEDRAG1_BORDER
;
982 key
= KEYC_MOUSEDRAG2_PANE
;
984 key
= KEYC_MOUSEDRAG2_STATUS
;
985 if (where
== STATUS_LEFT
)
986 key
= KEYC_MOUSEDRAG2_STATUS_LEFT
;
987 if (where
== STATUS_RIGHT
)
988 key
= KEYC_MOUSEDRAG2_STATUS_RIGHT
;
989 if (where
== STATUS_DEFAULT
)
990 key
= KEYC_MOUSEDRAG2_STATUS_DEFAULT
;
992 key
= KEYC_MOUSEDRAG2_BORDER
;
996 key
= KEYC_MOUSEDRAG3_PANE
;
998 key
= KEYC_MOUSEDRAG3_STATUS
;
999 if (where
== STATUS_LEFT
)
1000 key
= KEYC_MOUSEDRAG3_STATUS_LEFT
;
1001 if (where
== STATUS_RIGHT
)
1002 key
= KEYC_MOUSEDRAG3_STATUS_RIGHT
;
1003 if (where
== STATUS_DEFAULT
)
1004 key
= KEYC_MOUSEDRAG3_STATUS_DEFAULT
;
1005 if (where
== BORDER
)
1006 key
= KEYC_MOUSEDRAG3_BORDER
;
1008 case MOUSE_BUTTON_6
:
1010 key
= KEYC_MOUSEDRAG6_PANE
;
1011 if (where
== STATUS
)
1012 key
= KEYC_MOUSEDRAG6_STATUS
;
1013 if (where
== STATUS_LEFT
)
1014 key
= KEYC_MOUSEDRAG6_STATUS_LEFT
;
1015 if (where
== STATUS_RIGHT
)
1016 key
= KEYC_MOUSEDRAG6_STATUS_RIGHT
;
1017 if (where
== STATUS_DEFAULT
)
1018 key
= KEYC_MOUSEDRAG6_STATUS_DEFAULT
;
1019 if (where
== BORDER
)
1020 key
= KEYC_MOUSEDRAG6_BORDER
;
1022 case MOUSE_BUTTON_7
:
1024 key
= KEYC_MOUSEDRAG7_PANE
;
1025 if (where
== STATUS
)
1026 key
= KEYC_MOUSEDRAG7_STATUS
;
1027 if (where
== STATUS_LEFT
)
1028 key
= KEYC_MOUSEDRAG7_STATUS_LEFT
;
1029 if (where
== STATUS_RIGHT
)
1030 key
= KEYC_MOUSEDRAG7_STATUS_RIGHT
;
1031 if (where
== STATUS_DEFAULT
)
1032 key
= KEYC_MOUSEDRAG7_STATUS_DEFAULT
;
1033 if (where
== BORDER
)
1034 key
= KEYC_MOUSEDRAG7_BORDER
;
1036 case MOUSE_BUTTON_8
:
1038 key
= KEYC_MOUSEDRAG8_PANE
;
1039 if (where
== STATUS
)
1040 key
= KEYC_MOUSEDRAG8_STATUS
;
1041 if (where
== STATUS_LEFT
)
1042 key
= KEYC_MOUSEDRAG8_STATUS_LEFT
;
1043 if (where
== STATUS_RIGHT
)
1044 key
= KEYC_MOUSEDRAG8_STATUS_RIGHT
;
1045 if (where
== STATUS_DEFAULT
)
1046 key
= KEYC_MOUSEDRAG8_STATUS_DEFAULT
;
1047 if (where
== BORDER
)
1048 key
= KEYC_MOUSEDRAG8_BORDER
;
1050 case MOUSE_BUTTON_9
:
1052 key
= KEYC_MOUSEDRAG9_PANE
;
1053 if (where
== STATUS
)
1054 key
= KEYC_MOUSEDRAG9_STATUS
;
1055 if (where
== STATUS_LEFT
)
1056 key
= KEYC_MOUSEDRAG9_STATUS_LEFT
;
1057 if (where
== STATUS_RIGHT
)
1058 key
= KEYC_MOUSEDRAG9_STATUS_RIGHT
;
1059 if (where
== STATUS_DEFAULT
)
1060 key
= KEYC_MOUSEDRAG9_STATUS_DEFAULT
;
1061 if (where
== BORDER
)
1062 key
= KEYC_MOUSEDRAG9_BORDER
;
1064 case MOUSE_BUTTON_10
:
1066 key
= KEYC_MOUSEDRAG10_PANE
;
1067 if (where
== STATUS
)
1068 key
= KEYC_MOUSEDRAG10_STATUS
;
1069 if (where
== STATUS_LEFT
)
1070 key
= KEYC_MOUSEDRAG10_STATUS_LEFT
;
1071 if (where
== STATUS_RIGHT
)
1072 key
= KEYC_MOUSEDRAG10_STATUS_RIGHT
;
1073 if (where
== STATUS_DEFAULT
)
1074 key
= KEYC_MOUSEDRAG10_STATUS_DEFAULT
;
1075 if (where
== BORDER
)
1076 key
= KEYC_MOUSEDRAG10_BORDER
;
1078 case MOUSE_BUTTON_11
:
1080 key
= KEYC_MOUSEDRAG11_PANE
;
1081 if (where
== STATUS
)
1082 key
= KEYC_MOUSEDRAG11_STATUS
;
1083 if (where
== STATUS_LEFT
)
1084 key
= KEYC_MOUSEDRAG11_STATUS_LEFT
;
1085 if (where
== STATUS_RIGHT
)
1086 key
= KEYC_MOUSEDRAG11_STATUS_RIGHT
;
1087 if (where
== STATUS_DEFAULT
)
1088 key
= KEYC_MOUSEDRAG11_STATUS_DEFAULT
;
1089 if (where
== BORDER
)
1090 key
= KEYC_MOUSEDRAG11_BORDER
;
1096 * Begin a drag by setting the flag to a non-zero value that
1097 * corresponds to the mouse button in use.
1099 c
->tty
.mouse_drag_flag
= MOUSE_BUTTONS(b
) + 1;
1102 if (MOUSE_BUTTONS(b
) == MOUSE_WHEEL_UP
) {
1104 key
= KEYC_WHEELUP_PANE
;
1105 if (where
== STATUS
)
1106 key
= KEYC_WHEELUP_STATUS
;
1107 if (where
== STATUS_LEFT
)
1108 key
= KEYC_WHEELUP_STATUS_LEFT
;
1109 if (where
== STATUS_RIGHT
)
1110 key
= KEYC_WHEELUP_STATUS_RIGHT
;
1111 if (where
== STATUS_DEFAULT
)
1112 key
= KEYC_WHEELUP_STATUS_DEFAULT
;
1113 if (where
== BORDER
)
1114 key
= KEYC_WHEELUP_BORDER
;
1117 key
= KEYC_WHEELDOWN_PANE
;
1118 if (where
== STATUS
)
1119 key
= KEYC_WHEELDOWN_STATUS
;
1120 if (where
== STATUS_LEFT
)
1121 key
= KEYC_WHEELDOWN_STATUS_LEFT
;
1122 if (where
== STATUS_RIGHT
)
1123 key
= KEYC_WHEELDOWN_STATUS_RIGHT
;
1124 if (where
== STATUS_DEFAULT
)
1125 key
= KEYC_WHEELDOWN_STATUS_DEFAULT
;
1126 if (where
== BORDER
)
1127 key
= KEYC_WHEELDOWN_BORDER
;
1131 switch (MOUSE_BUTTONS(b
)) {
1132 case MOUSE_BUTTON_1
:
1134 key
= KEYC_MOUSEUP1_PANE
;
1135 if (where
== STATUS
)
1136 key
= KEYC_MOUSEUP1_STATUS
;
1137 if (where
== STATUS_LEFT
)
1138 key
= KEYC_MOUSEUP1_STATUS_LEFT
;
1139 if (where
== STATUS_RIGHT
)
1140 key
= KEYC_MOUSEUP1_STATUS_RIGHT
;
1141 if (where
== STATUS_DEFAULT
)
1142 key
= KEYC_MOUSEUP1_STATUS_DEFAULT
;
1143 if (where
== BORDER
)
1144 key
= KEYC_MOUSEUP1_BORDER
;
1146 case MOUSE_BUTTON_2
:
1148 key
= KEYC_MOUSEUP2_PANE
;
1149 if (where
== STATUS
)
1150 key
= KEYC_MOUSEUP2_STATUS
;
1151 if (where
== STATUS_LEFT
)
1152 key
= KEYC_MOUSEUP2_STATUS_LEFT
;
1153 if (where
== STATUS_RIGHT
)
1154 key
= KEYC_MOUSEUP2_STATUS_RIGHT
;
1155 if (where
== STATUS_DEFAULT
)
1156 key
= KEYC_MOUSEUP2_STATUS_DEFAULT
;
1157 if (where
== BORDER
)
1158 key
= KEYC_MOUSEUP2_BORDER
;
1160 case MOUSE_BUTTON_3
:
1162 key
= KEYC_MOUSEUP3_PANE
;
1163 if (where
== STATUS
)
1164 key
= KEYC_MOUSEUP3_STATUS
;
1165 if (where
== STATUS_LEFT
)
1166 key
= KEYC_MOUSEUP3_STATUS_LEFT
;
1167 if (where
== STATUS_RIGHT
)
1168 key
= KEYC_MOUSEUP3_STATUS_RIGHT
;
1169 if (where
== STATUS_DEFAULT
)
1170 key
= KEYC_MOUSEUP3_STATUS_DEFAULT
;
1171 if (where
== BORDER
)
1172 key
= KEYC_MOUSEUP3_BORDER
;
1174 case MOUSE_BUTTON_6
:
1176 key
= KEYC_MOUSEUP6_PANE
;
1177 if (where
== STATUS
)
1178 key
= KEYC_MOUSEUP6_STATUS
;
1179 if (where
== STATUS_LEFT
)
1180 key
= KEYC_MOUSEUP6_STATUS_LEFT
;
1181 if (where
== STATUS_RIGHT
)
1182 key
= KEYC_MOUSEUP6_STATUS_RIGHT
;
1183 if (where
== STATUS_DEFAULT
)
1184 key
= KEYC_MOUSEUP6_STATUS_DEFAULT
;
1185 if (where
== BORDER
)
1186 key
= KEYC_MOUSEUP6_BORDER
;
1188 case MOUSE_BUTTON_7
:
1190 key
= KEYC_MOUSEUP7_PANE
;
1191 if (where
== STATUS
)
1192 key
= KEYC_MOUSEUP7_STATUS
;
1193 if (where
== STATUS_LEFT
)
1194 key
= KEYC_MOUSEUP7_STATUS_LEFT
;
1195 if (where
== STATUS_RIGHT
)
1196 key
= KEYC_MOUSEUP7_STATUS_RIGHT
;
1197 if (where
== STATUS_DEFAULT
)
1198 key
= KEYC_MOUSEUP7_STATUS_DEFAULT
;
1199 if (where
== BORDER
)
1200 key
= KEYC_MOUSEUP7_BORDER
;
1202 case MOUSE_BUTTON_8
:
1204 key
= KEYC_MOUSEUP8_PANE
;
1205 if (where
== STATUS
)
1206 key
= KEYC_MOUSEUP8_STATUS
;
1207 if (where
== STATUS_LEFT
)
1208 key
= KEYC_MOUSEUP8_STATUS_LEFT
;
1209 if (where
== STATUS_RIGHT
)
1210 key
= KEYC_MOUSEUP8_STATUS_RIGHT
;
1211 if (where
== STATUS_DEFAULT
)
1212 key
= KEYC_MOUSEUP8_STATUS_DEFAULT
;
1213 if (where
== BORDER
)
1214 key
= KEYC_MOUSEUP8_BORDER
;
1216 case MOUSE_BUTTON_9
:
1218 key
= KEYC_MOUSEUP9_PANE
;
1219 if (where
== STATUS
)
1220 key
= KEYC_MOUSEUP9_STATUS
;
1221 if (where
== STATUS_LEFT
)
1222 key
= KEYC_MOUSEUP9_STATUS_LEFT
;
1223 if (where
== STATUS_RIGHT
)
1224 key
= KEYC_MOUSEUP9_STATUS_RIGHT
;
1225 if (where
== STATUS_DEFAULT
)
1226 key
= KEYC_MOUSEUP9_STATUS_DEFAULT
;
1227 if (where
== BORDER
)
1228 key
= KEYC_MOUSEUP9_BORDER
;
1230 case MOUSE_BUTTON_10
:
1232 key
= KEYC_MOUSEUP1_PANE
;
1233 if (where
== STATUS
)
1234 key
= KEYC_MOUSEUP1_STATUS
;
1235 if (where
== STATUS_LEFT
)
1236 key
= KEYC_MOUSEUP1_STATUS_LEFT
;
1237 if (where
== STATUS_RIGHT
)
1238 key
= KEYC_MOUSEUP1_STATUS_RIGHT
;
1239 if (where
== STATUS_DEFAULT
)
1240 key
= KEYC_MOUSEUP1_STATUS_DEFAULT
;
1241 if (where
== BORDER
)
1242 key
= KEYC_MOUSEUP1_BORDER
;
1244 case MOUSE_BUTTON_11
:
1246 key
= KEYC_MOUSEUP11_PANE
;
1247 if (where
== STATUS
)
1248 key
= KEYC_MOUSEUP11_STATUS
;
1249 if (where
== STATUS_LEFT
)
1250 key
= KEYC_MOUSEUP11_STATUS_LEFT
;
1251 if (where
== STATUS_RIGHT
)
1252 key
= KEYC_MOUSEUP11_STATUS_RIGHT
;
1253 if (where
== STATUS_DEFAULT
)
1254 key
= KEYC_MOUSEUP11_STATUS_DEFAULT
;
1255 if (where
== BORDER
)
1256 key
= KEYC_MOUSEUP11_BORDER
;
1261 switch (MOUSE_BUTTONS(b
)) {
1262 case MOUSE_BUTTON_1
:
1264 key
= KEYC_MOUSEDOWN1_PANE
;
1265 if (where
== STATUS
)
1266 key
= KEYC_MOUSEDOWN1_STATUS
;
1267 if (where
== STATUS_LEFT
)
1268 key
= KEYC_MOUSEDOWN1_STATUS_LEFT
;
1269 if (where
== STATUS_RIGHT
)
1270 key
= KEYC_MOUSEDOWN1_STATUS_RIGHT
;
1271 if (where
== STATUS_DEFAULT
)
1272 key
= KEYC_MOUSEDOWN1_STATUS_DEFAULT
;
1273 if (where
== BORDER
)
1274 key
= KEYC_MOUSEDOWN1_BORDER
;
1276 case MOUSE_BUTTON_2
:
1278 key
= KEYC_MOUSEDOWN2_PANE
;
1279 if (where
== STATUS
)
1280 key
= KEYC_MOUSEDOWN2_STATUS
;
1281 if (where
== STATUS_LEFT
)
1282 key
= KEYC_MOUSEDOWN2_STATUS_LEFT
;
1283 if (where
== STATUS_RIGHT
)
1284 key
= KEYC_MOUSEDOWN2_STATUS_RIGHT
;
1285 if (where
== STATUS_DEFAULT
)
1286 key
= KEYC_MOUSEDOWN2_STATUS_DEFAULT
;
1287 if (where
== BORDER
)
1288 key
= KEYC_MOUSEDOWN2_BORDER
;
1290 case MOUSE_BUTTON_3
:
1292 key
= KEYC_MOUSEDOWN3_PANE
;
1293 if (where
== STATUS
)
1294 key
= KEYC_MOUSEDOWN3_STATUS
;
1295 if (where
== STATUS_LEFT
)
1296 key
= KEYC_MOUSEDOWN3_STATUS_LEFT
;
1297 if (where
== STATUS_RIGHT
)
1298 key
= KEYC_MOUSEDOWN3_STATUS_RIGHT
;
1299 if (where
== STATUS_DEFAULT
)
1300 key
= KEYC_MOUSEDOWN3_STATUS_DEFAULT
;
1301 if (where
== BORDER
)
1302 key
= KEYC_MOUSEDOWN3_BORDER
;
1304 case MOUSE_BUTTON_6
:
1306 key
= KEYC_MOUSEDOWN6_PANE
;
1307 if (where
== STATUS
)
1308 key
= KEYC_MOUSEDOWN6_STATUS
;
1309 if (where
== STATUS_LEFT
)
1310 key
= KEYC_MOUSEDOWN6_STATUS_LEFT
;
1311 if (where
== STATUS_RIGHT
)
1312 key
= KEYC_MOUSEDOWN6_STATUS_RIGHT
;
1313 if (where
== STATUS_DEFAULT
)
1314 key
= KEYC_MOUSEDOWN6_STATUS_DEFAULT
;
1315 if (where
== BORDER
)
1316 key
= KEYC_MOUSEDOWN6_BORDER
;
1318 case MOUSE_BUTTON_7
:
1320 key
= KEYC_MOUSEDOWN7_PANE
;
1321 if (where
== STATUS
)
1322 key
= KEYC_MOUSEDOWN7_STATUS
;
1323 if (where
== STATUS_LEFT
)
1324 key
= KEYC_MOUSEDOWN7_STATUS_LEFT
;
1325 if (where
== STATUS_RIGHT
)
1326 key
= KEYC_MOUSEDOWN7_STATUS_RIGHT
;
1327 if (where
== STATUS_DEFAULT
)
1328 key
= KEYC_MOUSEDOWN7_STATUS_DEFAULT
;
1329 if (where
== BORDER
)
1330 key
= KEYC_MOUSEDOWN7_BORDER
;
1332 case MOUSE_BUTTON_8
:
1334 key
= KEYC_MOUSEDOWN8_PANE
;
1335 if (where
== STATUS
)
1336 key
= KEYC_MOUSEDOWN8_STATUS
;
1337 if (where
== STATUS_LEFT
)
1338 key
= KEYC_MOUSEDOWN8_STATUS_LEFT
;
1339 if (where
== STATUS_RIGHT
)
1340 key
= KEYC_MOUSEDOWN8_STATUS_RIGHT
;
1341 if (where
== STATUS_DEFAULT
)
1342 key
= KEYC_MOUSEDOWN8_STATUS_DEFAULT
;
1343 if (where
== BORDER
)
1344 key
= KEYC_MOUSEDOWN8_BORDER
;
1346 case MOUSE_BUTTON_9
:
1348 key
= KEYC_MOUSEDOWN9_PANE
;
1349 if (where
== STATUS
)
1350 key
= KEYC_MOUSEDOWN9_STATUS
;
1351 if (where
== STATUS_LEFT
)
1352 key
= KEYC_MOUSEDOWN9_STATUS_LEFT
;
1353 if (where
== STATUS_RIGHT
)
1354 key
= KEYC_MOUSEDOWN9_STATUS_RIGHT
;
1355 if (where
== STATUS_DEFAULT
)
1356 key
= KEYC_MOUSEDOWN9_STATUS_DEFAULT
;
1357 if (where
== BORDER
)
1358 key
= KEYC_MOUSEDOWN9_BORDER
;
1360 case MOUSE_BUTTON_10
:
1362 key
= KEYC_MOUSEDOWN10_PANE
;
1363 if (where
== STATUS
)
1364 key
= KEYC_MOUSEDOWN10_STATUS
;
1365 if (where
== STATUS_LEFT
)
1366 key
= KEYC_MOUSEDOWN10_STATUS_LEFT
;
1367 if (where
== STATUS_RIGHT
)
1368 key
= KEYC_MOUSEDOWN10_STATUS_RIGHT
;
1369 if (where
== STATUS_DEFAULT
)
1370 key
= KEYC_MOUSEDOWN10_STATUS_DEFAULT
;
1371 if (where
== BORDER
)
1372 key
= KEYC_MOUSEDOWN10_BORDER
;
1374 case MOUSE_BUTTON_11
:
1376 key
= KEYC_MOUSEDOWN11_PANE
;
1377 if (where
== STATUS
)
1378 key
= KEYC_MOUSEDOWN11_STATUS
;
1379 if (where
== STATUS_LEFT
)
1380 key
= KEYC_MOUSEDOWN11_STATUS_LEFT
;
1381 if (where
== STATUS_RIGHT
)
1382 key
= KEYC_MOUSEDOWN11_STATUS_RIGHT
;
1383 if (where
== STATUS_DEFAULT
)
1384 key
= KEYC_MOUSEDOWN11_STATUS_DEFAULT
;
1385 if (where
== BORDER
)
1386 key
= KEYC_MOUSEDOWN11_BORDER
;
1391 switch (MOUSE_BUTTONS(b
)) {
1392 case MOUSE_BUTTON_1
:
1394 key
= KEYC_SECONDCLICK1_PANE
;
1395 if (where
== STATUS
)
1396 key
= KEYC_SECONDCLICK1_STATUS
;
1397 if (where
== STATUS_LEFT
)
1398 key
= KEYC_SECONDCLICK1_STATUS_LEFT
;
1399 if (where
== STATUS_RIGHT
)
1400 key
= KEYC_SECONDCLICK1_STATUS_RIGHT
;
1401 if (where
== STATUS_DEFAULT
)
1402 key
= KEYC_SECONDCLICK1_STATUS_DEFAULT
;
1403 if (where
== BORDER
)
1404 key
= KEYC_SECONDCLICK1_BORDER
;
1406 case MOUSE_BUTTON_2
:
1408 key
= KEYC_SECONDCLICK2_PANE
;
1409 if (where
== STATUS
)
1410 key
= KEYC_SECONDCLICK2_STATUS
;
1411 if (where
== STATUS_LEFT
)
1412 key
= KEYC_SECONDCLICK2_STATUS_LEFT
;
1413 if (where
== STATUS_RIGHT
)
1414 key
= KEYC_SECONDCLICK2_STATUS_RIGHT
;
1415 if (where
== STATUS_DEFAULT
)
1416 key
= KEYC_SECONDCLICK2_STATUS_DEFAULT
;
1417 if (where
== BORDER
)
1418 key
= KEYC_SECONDCLICK2_BORDER
;
1420 case MOUSE_BUTTON_3
:
1422 key
= KEYC_SECONDCLICK3_PANE
;
1423 if (where
== STATUS
)
1424 key
= KEYC_SECONDCLICK3_STATUS
;
1425 if (where
== STATUS_LEFT
)
1426 key
= KEYC_SECONDCLICK3_STATUS_LEFT
;
1427 if (where
== STATUS_RIGHT
)
1428 key
= KEYC_SECONDCLICK3_STATUS_RIGHT
;
1429 if (where
== STATUS_DEFAULT
)
1430 key
= KEYC_SECONDCLICK3_STATUS_DEFAULT
;
1431 if (where
== BORDER
)
1432 key
= KEYC_SECONDCLICK3_BORDER
;
1434 case MOUSE_BUTTON_6
:
1436 key
= KEYC_SECONDCLICK6_PANE
;
1437 if (where
== STATUS
)
1438 key
= KEYC_SECONDCLICK6_STATUS
;
1439 if (where
== STATUS_LEFT
)
1440 key
= KEYC_SECONDCLICK6_STATUS_LEFT
;
1441 if (where
== STATUS_RIGHT
)
1442 key
= KEYC_SECONDCLICK6_STATUS_RIGHT
;
1443 if (where
== STATUS_DEFAULT
)
1444 key
= KEYC_SECONDCLICK6_STATUS_DEFAULT
;
1445 if (where
== BORDER
)
1446 key
= KEYC_SECONDCLICK6_BORDER
;
1448 case MOUSE_BUTTON_7
:
1450 key
= KEYC_SECONDCLICK7_PANE
;
1451 if (where
== STATUS
)
1452 key
= KEYC_SECONDCLICK7_STATUS
;
1453 if (where
== STATUS_LEFT
)
1454 key
= KEYC_SECONDCLICK7_STATUS_LEFT
;
1455 if (where
== STATUS_RIGHT
)
1456 key
= KEYC_SECONDCLICK7_STATUS_RIGHT
;
1457 if (where
== STATUS_DEFAULT
)
1458 key
= KEYC_SECONDCLICK7_STATUS_DEFAULT
;
1459 if (where
== BORDER
)
1460 key
= KEYC_SECONDCLICK7_BORDER
;
1462 case MOUSE_BUTTON_8
:
1464 key
= KEYC_SECONDCLICK8_PANE
;
1465 if (where
== STATUS
)
1466 key
= KEYC_SECONDCLICK8_STATUS
;
1467 if (where
== STATUS_LEFT
)
1468 key
= KEYC_SECONDCLICK8_STATUS_LEFT
;
1469 if (where
== STATUS_RIGHT
)
1470 key
= KEYC_SECONDCLICK8_STATUS_RIGHT
;
1471 if (where
== STATUS_DEFAULT
)
1472 key
= KEYC_SECONDCLICK8_STATUS_DEFAULT
;
1473 if (where
== BORDER
)
1474 key
= KEYC_SECONDCLICK8_BORDER
;
1476 case MOUSE_BUTTON_9
:
1478 key
= KEYC_SECONDCLICK9_PANE
;
1479 if (where
== STATUS
)
1480 key
= KEYC_SECONDCLICK9_STATUS
;
1481 if (where
== STATUS_LEFT
)
1482 key
= KEYC_SECONDCLICK9_STATUS_LEFT
;
1483 if (where
== STATUS_RIGHT
)
1484 key
= KEYC_SECONDCLICK9_STATUS_RIGHT
;
1485 if (where
== STATUS_DEFAULT
)
1486 key
= KEYC_SECONDCLICK9_STATUS_DEFAULT
;
1487 if (where
== BORDER
)
1488 key
= KEYC_SECONDCLICK9_BORDER
;
1490 case MOUSE_BUTTON_10
:
1492 key
= KEYC_SECONDCLICK10_PANE
;
1493 if (where
== STATUS
)
1494 key
= KEYC_SECONDCLICK10_STATUS
;
1495 if (where
== STATUS_LEFT
)
1496 key
= KEYC_SECONDCLICK10_STATUS_LEFT
;
1497 if (where
== STATUS_RIGHT
)
1498 key
= KEYC_SECONDCLICK10_STATUS_RIGHT
;
1499 if (where
== STATUS_DEFAULT
)
1500 key
= KEYC_SECONDCLICK10_STATUS_DEFAULT
;
1501 if (where
== BORDER
)
1502 key
= KEYC_SECONDCLICK10_BORDER
;
1504 case MOUSE_BUTTON_11
:
1506 key
= KEYC_SECONDCLICK11_PANE
;
1507 if (where
== STATUS
)
1508 key
= KEYC_SECONDCLICK11_STATUS
;
1509 if (where
== STATUS_LEFT
)
1510 key
= KEYC_SECONDCLICK11_STATUS_LEFT
;
1511 if (where
== STATUS_RIGHT
)
1512 key
= KEYC_SECONDCLICK11_STATUS_RIGHT
;
1513 if (where
== STATUS_DEFAULT
)
1514 key
= KEYC_SECONDCLICK11_STATUS_DEFAULT
;
1515 if (where
== BORDER
)
1516 key
= KEYC_SECONDCLICK11_BORDER
;
1521 switch (MOUSE_BUTTONS(b
)) {
1522 case MOUSE_BUTTON_1
:
1524 key
= KEYC_DOUBLECLICK1_PANE
;
1525 if (where
== STATUS
)
1526 key
= KEYC_DOUBLECLICK1_STATUS
;
1527 if (where
== STATUS_LEFT
)
1528 key
= KEYC_DOUBLECLICK1_STATUS_LEFT
;
1529 if (where
== STATUS_RIGHT
)
1530 key
= KEYC_DOUBLECLICK1_STATUS_RIGHT
;
1531 if (where
== STATUS_DEFAULT
)
1532 key
= KEYC_DOUBLECLICK1_STATUS_DEFAULT
;
1533 if (where
== BORDER
)
1534 key
= KEYC_DOUBLECLICK1_BORDER
;
1536 case MOUSE_BUTTON_2
:
1538 key
= KEYC_DOUBLECLICK2_PANE
;
1539 if (where
== STATUS
)
1540 key
= KEYC_DOUBLECLICK2_STATUS
;
1541 if (where
== STATUS_LEFT
)
1542 key
= KEYC_DOUBLECLICK2_STATUS_LEFT
;
1543 if (where
== STATUS_RIGHT
)
1544 key
= KEYC_DOUBLECLICK2_STATUS_RIGHT
;
1545 if (where
== STATUS_DEFAULT
)
1546 key
= KEYC_DOUBLECLICK2_STATUS_DEFAULT
;
1547 if (where
== BORDER
)
1548 key
= KEYC_DOUBLECLICK2_BORDER
;
1550 case MOUSE_BUTTON_3
:
1552 key
= KEYC_DOUBLECLICK3_PANE
;
1553 if (where
== STATUS
)
1554 key
= KEYC_DOUBLECLICK3_STATUS
;
1555 if (where
== STATUS_LEFT
)
1556 key
= KEYC_DOUBLECLICK3_STATUS_LEFT
;
1557 if (where
== STATUS_RIGHT
)
1558 key
= KEYC_DOUBLECLICK3_STATUS_RIGHT
;
1559 if (where
== STATUS_DEFAULT
)
1560 key
= KEYC_DOUBLECLICK3_STATUS_DEFAULT
;
1561 if (where
== BORDER
)
1562 key
= KEYC_DOUBLECLICK3_BORDER
;
1564 case MOUSE_BUTTON_6
:
1566 key
= KEYC_DOUBLECLICK6_PANE
;
1567 if (where
== STATUS
)
1568 key
= KEYC_DOUBLECLICK6_STATUS
;
1569 if (where
== STATUS_LEFT
)
1570 key
= KEYC_DOUBLECLICK6_STATUS_LEFT
;
1571 if (where
== STATUS_RIGHT
)
1572 key
= KEYC_DOUBLECLICK6_STATUS_RIGHT
;
1573 if (where
== STATUS_DEFAULT
)
1574 key
= KEYC_DOUBLECLICK6_STATUS_DEFAULT
;
1575 if (where
== BORDER
)
1576 key
= KEYC_DOUBLECLICK6_BORDER
;
1578 case MOUSE_BUTTON_7
:
1580 key
= KEYC_DOUBLECLICK7_PANE
;
1581 if (where
== STATUS
)
1582 key
= KEYC_DOUBLECLICK7_STATUS
;
1583 if (where
== STATUS_LEFT
)
1584 key
= KEYC_DOUBLECLICK7_STATUS_LEFT
;
1585 if (where
== STATUS_RIGHT
)
1586 key
= KEYC_DOUBLECLICK7_STATUS_RIGHT
;
1587 if (where
== STATUS_DEFAULT
)
1588 key
= KEYC_DOUBLECLICK7_STATUS_DEFAULT
;
1589 if (where
== BORDER
)
1590 key
= KEYC_DOUBLECLICK7_BORDER
;
1592 case MOUSE_BUTTON_8
:
1594 key
= KEYC_DOUBLECLICK8_PANE
;
1595 if (where
== STATUS
)
1596 key
= KEYC_DOUBLECLICK8_STATUS
;
1597 if (where
== STATUS_LEFT
)
1598 key
= KEYC_DOUBLECLICK8_STATUS_LEFT
;
1599 if (where
== STATUS_RIGHT
)
1600 key
= KEYC_DOUBLECLICK8_STATUS_RIGHT
;
1601 if (where
== STATUS_DEFAULT
)
1602 key
= KEYC_DOUBLECLICK8_STATUS_DEFAULT
;
1603 if (where
== BORDER
)
1604 key
= KEYC_DOUBLECLICK8_BORDER
;
1606 case MOUSE_BUTTON_9
:
1608 key
= KEYC_DOUBLECLICK9_PANE
;
1609 if (where
== STATUS
)
1610 key
= KEYC_DOUBLECLICK9_STATUS
;
1611 if (where
== STATUS_LEFT
)
1612 key
= KEYC_DOUBLECLICK9_STATUS_LEFT
;
1613 if (where
== STATUS_RIGHT
)
1614 key
= KEYC_DOUBLECLICK9_STATUS_RIGHT
;
1615 if (where
== STATUS_DEFAULT
)
1616 key
= KEYC_DOUBLECLICK9_STATUS_DEFAULT
;
1617 if (where
== BORDER
)
1618 key
= KEYC_DOUBLECLICK9_BORDER
;
1620 case MOUSE_BUTTON_10
:
1622 key
= KEYC_DOUBLECLICK10_PANE
;
1623 if (where
== STATUS
)
1624 key
= KEYC_DOUBLECLICK10_STATUS
;
1625 if (where
== STATUS_LEFT
)
1626 key
= KEYC_DOUBLECLICK10_STATUS_LEFT
;
1627 if (where
== STATUS_RIGHT
)
1628 key
= KEYC_DOUBLECLICK10_STATUS_RIGHT
;
1629 if (where
== STATUS_DEFAULT
)
1630 key
= KEYC_DOUBLECLICK10_STATUS_DEFAULT
;
1631 if (where
== BORDER
)
1632 key
= KEYC_DOUBLECLICK10_BORDER
;
1634 case MOUSE_BUTTON_11
:
1636 key
= KEYC_DOUBLECLICK11_PANE
;
1637 if (where
== STATUS
)
1638 key
= KEYC_DOUBLECLICK11_STATUS
;
1639 if (where
== STATUS_LEFT
)
1640 key
= KEYC_DOUBLECLICK11_STATUS_LEFT
;
1641 if (where
== STATUS_RIGHT
)
1642 key
= KEYC_DOUBLECLICK11_STATUS_RIGHT
;
1643 if (where
== STATUS_DEFAULT
)
1644 key
= KEYC_DOUBLECLICK11_STATUS_DEFAULT
;
1645 if (where
== BORDER
)
1646 key
= KEYC_DOUBLECLICK11_BORDER
;
1651 switch (MOUSE_BUTTONS(b
)) {
1652 case MOUSE_BUTTON_1
:
1654 key
= KEYC_TRIPLECLICK1_PANE
;
1655 if (where
== STATUS
)
1656 key
= KEYC_TRIPLECLICK1_STATUS
;
1657 if (where
== STATUS_LEFT
)
1658 key
= KEYC_TRIPLECLICK1_STATUS_LEFT
;
1659 if (where
== STATUS_RIGHT
)
1660 key
= KEYC_TRIPLECLICK1_STATUS_RIGHT
;
1661 if (where
== STATUS_DEFAULT
)
1662 key
= KEYC_TRIPLECLICK1_STATUS_DEFAULT
;
1663 if (where
== BORDER
)
1664 key
= KEYC_TRIPLECLICK1_BORDER
;
1666 case MOUSE_BUTTON_2
:
1668 key
= KEYC_TRIPLECLICK2_PANE
;
1669 if (where
== STATUS
)
1670 key
= KEYC_TRIPLECLICK2_STATUS
;
1671 if (where
== STATUS_LEFT
)
1672 key
= KEYC_TRIPLECLICK2_STATUS_LEFT
;
1673 if (where
== STATUS_RIGHT
)
1674 key
= KEYC_TRIPLECLICK2_STATUS_RIGHT
;
1675 if (where
== STATUS_DEFAULT
)
1676 key
= KEYC_TRIPLECLICK2_STATUS_DEFAULT
;
1677 if (where
== BORDER
)
1678 key
= KEYC_TRIPLECLICK2_BORDER
;
1680 case MOUSE_BUTTON_3
:
1682 key
= KEYC_TRIPLECLICK3_PANE
;
1683 if (where
== STATUS
)
1684 key
= KEYC_TRIPLECLICK3_STATUS
;
1685 if (where
== STATUS_LEFT
)
1686 key
= KEYC_TRIPLECLICK3_STATUS_LEFT
;
1687 if (where
== STATUS_RIGHT
)
1688 key
= KEYC_TRIPLECLICK3_STATUS_RIGHT
;
1689 if (where
== STATUS_DEFAULT
)
1690 key
= KEYC_TRIPLECLICK3_STATUS_DEFAULT
;
1691 if (where
== BORDER
)
1692 key
= KEYC_TRIPLECLICK3_BORDER
;
1694 case MOUSE_BUTTON_6
:
1696 key
= KEYC_TRIPLECLICK6_PANE
;
1697 if (where
== STATUS
)
1698 key
= KEYC_TRIPLECLICK6_STATUS
;
1699 if (where
== STATUS_LEFT
)
1700 key
= KEYC_TRIPLECLICK6_STATUS_LEFT
;
1701 if (where
== STATUS_RIGHT
)
1702 key
= KEYC_TRIPLECLICK6_STATUS_RIGHT
;
1703 if (where
== STATUS_DEFAULT
)
1704 key
= KEYC_TRIPLECLICK6_STATUS_DEFAULT
;
1705 if (where
== BORDER
)
1706 key
= KEYC_TRIPLECLICK6_BORDER
;
1708 case MOUSE_BUTTON_7
:
1710 key
= KEYC_TRIPLECLICK7_PANE
;
1711 if (where
== STATUS
)
1712 key
= KEYC_TRIPLECLICK7_STATUS
;
1713 if (where
== STATUS_LEFT
)
1714 key
= KEYC_TRIPLECLICK7_STATUS_LEFT
;
1715 if (where
== STATUS_RIGHT
)
1716 key
= KEYC_TRIPLECLICK7_STATUS_RIGHT
;
1717 if (where
== STATUS_DEFAULT
)
1718 key
= KEYC_TRIPLECLICK7_STATUS_DEFAULT
;
1719 if (where
== BORDER
)
1720 key
= KEYC_TRIPLECLICK7_BORDER
;
1722 case MOUSE_BUTTON_8
:
1724 key
= KEYC_TRIPLECLICK8_PANE
;
1725 if (where
== STATUS
)
1726 key
= KEYC_TRIPLECLICK8_STATUS
;
1727 if (where
== STATUS_LEFT
)
1728 key
= KEYC_TRIPLECLICK8_STATUS_LEFT
;
1729 if (where
== STATUS_RIGHT
)
1730 key
= KEYC_TRIPLECLICK8_STATUS_RIGHT
;
1731 if (where
== STATUS_DEFAULT
)
1732 key
= KEYC_TRIPLECLICK8_STATUS_DEFAULT
;
1733 if (where
== BORDER
)
1734 key
= KEYC_TRIPLECLICK8_BORDER
;
1736 case MOUSE_BUTTON_9
:
1738 key
= KEYC_TRIPLECLICK9_PANE
;
1739 if (where
== STATUS
)
1740 key
= KEYC_TRIPLECLICK9_STATUS
;
1741 if (where
== STATUS_LEFT
)
1742 key
= KEYC_TRIPLECLICK9_STATUS_LEFT
;
1743 if (where
== STATUS_RIGHT
)
1744 key
= KEYC_TRIPLECLICK9_STATUS_RIGHT
;
1745 if (where
== STATUS_DEFAULT
)
1746 key
= KEYC_TRIPLECLICK9_STATUS_DEFAULT
;
1747 if (where
== BORDER
)
1748 key
= KEYC_TRIPLECLICK9_BORDER
;
1750 case MOUSE_BUTTON_10
:
1752 key
= KEYC_TRIPLECLICK10_PANE
;
1753 if (where
== STATUS
)
1754 key
= KEYC_TRIPLECLICK10_STATUS
;
1755 if (where
== STATUS_LEFT
)
1756 key
= KEYC_TRIPLECLICK10_STATUS_LEFT
;
1757 if (where
== STATUS_RIGHT
)
1758 key
= KEYC_TRIPLECLICK10_STATUS_RIGHT
;
1759 if (where
== STATUS_DEFAULT
)
1760 key
= KEYC_TRIPLECLICK10_STATUS_DEFAULT
;
1761 if (where
== BORDER
)
1762 key
= KEYC_TRIPLECLICK10_BORDER
;
1764 case MOUSE_BUTTON_11
:
1766 key
= KEYC_TRIPLECLICK11_PANE
;
1767 if (where
== STATUS
)
1768 key
= KEYC_TRIPLECLICK11_STATUS
;
1769 if (where
== STATUS_LEFT
)
1770 key
= KEYC_TRIPLECLICK11_STATUS_LEFT
;
1771 if (where
== STATUS_RIGHT
)
1772 key
= KEYC_TRIPLECLICK11_STATUS_RIGHT
;
1773 if (where
== STATUS_DEFAULT
)
1774 key
= KEYC_TRIPLECLICK11_STATUS_DEFAULT
;
1775 if (where
== BORDER
)
1776 key
= KEYC_TRIPLECLICK11_BORDER
;
1781 if (key
== KEYC_UNKNOWN
)
1782 return (KEYC_UNKNOWN
);
1785 /* Apply modifiers if any. */
1786 if (b
& MOUSE_MASK_META
)
1788 if (b
& MOUSE_MASK_CTRL
)
1790 if (b
& MOUSE_MASK_SHIFT
)
1793 if (log_get_level() != 0)
1794 log_debug("mouse key is %s", key_string_lookup_key (key
, 1));
1798 /* Is this a bracket paste key? */
1800 server_client_is_bracket_paste(struct client
*c
, key_code key
)
1802 if (key
== KEYC_PASTE_START
) {
1803 c
->flags
|= CLIENT_BRACKETPASTING
;
1804 log_debug("%s: bracket paste on", c
->name
);
1808 if (key
== KEYC_PASTE_END
) {
1809 c
->flags
&= ~CLIENT_BRACKETPASTING
;
1810 log_debug("%s: bracket paste off", c
->name
);
1814 return !!(c
->flags
& CLIENT_BRACKETPASTING
);
1817 /* Is this fast enough to probably be a paste? */
1819 server_client_is_assume_paste(struct client
*c
)
1821 struct session
*s
= c
->session
;
1825 if (c
->flags
& CLIENT_BRACKETPASTING
)
1827 if ((t
= options_get_number(s
->options
, "assume-paste-time")) == 0)
1830 timersub(&c
->activity_time
, &c
->last_activity_time
, &tv
);
1831 if (tv
.tv_sec
== 0 && tv
.tv_usec
< t
* 1000) {
1832 if (c
->flags
& CLIENT_ASSUMEPASTING
)
1834 c
->flags
|= CLIENT_ASSUMEPASTING
;
1835 log_debug("%s: assume paste on", c
->name
);
1838 if (c
->flags
& CLIENT_ASSUMEPASTING
) {
1839 c
->flags
&= ~CLIENT_ASSUMEPASTING
;
1840 log_debug("%s: assume paste off", c
->name
);
1845 /* Has the latest client changed? */
1847 server_client_update_latest(struct client
*c
)
1851 if (c
->session
== NULL
)
1853 w
= c
->session
->curw
->window
;
1859 if (options_get_number(w
->options
, "window-size") == WINDOW_SIZE_LATEST
)
1860 recalculate_size(w
, 0);
1862 notify_client("client-active", c
);
1865 /* Get repeat time. */
1867 server_client_repeat_time(struct client
*c
, struct key_binding
*bd
)
1869 struct session
*s
= c
->session
;
1870 u_int repeat
, initial
;
1872 if (~bd
->flags
& KEY_BINDING_REPEAT
)
1874 repeat
= options_get_number(s
->options
, "repeat-time");
1877 if ((~c
->flags
& CLIENT_REPEAT
) || bd
->key
!= c
->last_key
) {
1878 initial
= options_get_number(s
->options
, "initial-repeat-time");
1886 * Handle data key input from client. This owns and can modify the key event it
1887 * is given and is responsible for freeing it.
1889 static enum cmd_retval
1890 server_client_key_callback(struct cmdq_item
*item
, void *data
)
1892 struct client
*c
= cmdq_get_client(item
);
1893 struct key_event
*event
= data
;
1894 key_code key
= event
->key
;
1895 struct mouse_event
*m
= &event
->m
;
1896 struct session
*s
= c
->session
;
1898 struct window_pane
*wp
;
1899 struct window_mode_entry
*wme
;
1901 struct key_table
*table
, *first
;
1902 struct key_binding
*bd
;
1904 uint64_t flags
, prefix_delay
;
1905 struct cmd_find_state fs
;
1906 key_code key0
, prefix
, prefix2
;
1908 /* Check the client is good to accept input. */
1909 if (s
== NULL
|| (c
->flags
& CLIENT_UNATTACHEDFLAGS
))
1913 /* Update the activity timer. */
1914 memcpy(&c
->last_activity_time
, &c
->activity_time
,
1915 sizeof c
->last_activity_time
);
1916 if (gettimeofday(&c
->activity_time
, NULL
) != 0)
1917 fatal("gettimeofday failed");
1918 session_update_activity(s
, &c
->activity_time
);
1920 /* Check for mouse keys. */
1922 if (key
== KEYC_MOUSE
|| key
== KEYC_DOUBLECLICK
) {
1923 if (c
->flags
& CLIENT_READONLY
)
1925 key
= server_client_check_mouse(c
, event
);
1926 if (key
== KEYC_UNKNOWN
)
1933 * Mouse drag is in progress, so fire the callback (now that
1934 * the mouse event is valid).
1936 if ((key
& KEYC_MASK_KEY
) == KEYC_DRAGGING
) {
1937 c
->tty
.mouse_drag_update(c
, m
);
1943 /* Find affected pane. */
1944 if (!KEYC_IS_MOUSE(key
) || cmd_find_from_mouse(&fs
, m
, 0) != 0)
1945 cmd_find_from_client(&fs
, c
, 0);
1948 /* Forward mouse keys if disabled. */
1949 if (KEYC_IS_MOUSE(key
) && !options_get_number(s
->options
, "mouse"))
1952 /* Forward if bracket pasting. */
1953 if (server_client_is_bracket_paste (c
, key
))
1956 /* Treat everything as a regular key when pasting is detected. */
1957 if (!KEYC_IS_MOUSE(key
) &&
1958 key
!= KEYC_FOCUS_IN
&&
1959 key
!= KEYC_FOCUS_OUT
&&
1960 (~key
& KEYC_SENT
) &&
1961 server_client_is_assume_paste(c
))
1965 * Work out the current key table. If the pane is in a mode, use
1966 * the mode table instead of the default key table.
1968 if (server_client_is_default_key_table(c
, c
->keytable
) &&
1970 (wme
= TAILQ_FIRST(&wp
->modes
)) != NULL
&&
1971 wme
->mode
->key_table
!= NULL
)
1972 table
= key_bindings_get_table(wme
->mode
->key_table(wme
), 1);
1974 table
= c
->keytable
;
1979 * The prefix always takes precedence and forces a switch to the prefix
1980 * table, unless we are already there.
1982 prefix
= (key_code
)options_get_number(s
->options
, "prefix");
1983 prefix2
= (key_code
)options_get_number(s
->options
, "prefix2");
1984 key0
= (key
& (KEYC_MASK_KEY
|KEYC_MASK_MODIFIERS
));
1985 if ((key0
== (prefix
& (KEYC_MASK_KEY
|KEYC_MASK_MODIFIERS
)) ||
1986 key0
== (prefix2
& (KEYC_MASK_KEY
|KEYC_MASK_MODIFIERS
))) &&
1987 strcmp(table
->name
, "prefix") != 0) {
1988 server_client_set_key_table(c
, "prefix");
1989 server_status_client(c
);
1995 /* Log key table. */
1997 log_debug("key table %s (no pane)", table
->name
);
1999 log_debug("key table %s (pane %%%u)", table
->name
, wp
->id
);
2000 if (c
->flags
& CLIENT_REPEAT
)
2001 log_debug("currently repeating");
2003 bd
= key_bindings_get(table
, key0
);
2006 * If prefix-timeout is enabled and we're in the prefix table, see if
2007 * the timeout has been exceeded. Revert to the root table if so.
2009 prefix_delay
= options_get_number(global_options
, "prefix-timeout");
2010 if (prefix_delay
> 0 &&
2011 strcmp(table
->name
, "prefix") == 0 &&
2012 server_client_key_table_activity_diff(c
) > prefix_delay
) {
2014 * If repeating is active and this is a repeating binding,
2015 * ignore the timeout.
2018 (c
->flags
& CLIENT_REPEAT
) &&
2019 (bd
->flags
& KEY_BINDING_REPEAT
)) {
2020 log_debug("prefix timeout ignored, repeat is active");
2022 log_debug("prefix timeout exceeded");
2023 server_client_set_key_table(c
, NULL
);
2024 first
= table
= c
->keytable
;
2025 server_status_client(c
);
2030 /* Try to see if there is a key binding in the current table. */
2033 * Key was matched in this table. If currently repeating but a
2034 * non-repeating binding was found, stop repeating and try
2035 * again in the root table.
2037 if ((c
->flags
& CLIENT_REPEAT
) &&
2038 (~bd
->flags
& KEY_BINDING_REPEAT
)) {
2039 log_debug("found in key table %s (not repeating)",
2041 server_client_set_key_table(c
, NULL
);
2042 first
= table
= c
->keytable
;
2043 c
->flags
&= ~CLIENT_REPEAT
;
2044 server_status_client(c
);
2047 log_debug("found in key table %s", table
->name
);
2050 * Take a reference to this table to make sure the key binding
2051 * doesn't disappear.
2053 table
->references
++;
2056 * If this is a repeating key, start the timer. Otherwise reset
2057 * the client back to the root table.
2059 repeat
= server_client_repeat_time(c
, bd
);
2061 c
->flags
|= CLIENT_REPEAT
;
2062 c
->last_key
= bd
->key
;
2064 tv
.tv_sec
= repeat
/ 1000;
2065 tv
.tv_usec
= (repeat
% 1000) * 1000L;
2066 evtimer_del(&c
->repeat_timer
);
2067 evtimer_add(&c
->repeat_timer
, &tv
);
2069 c
->flags
&= ~CLIENT_REPEAT
;
2070 server_client_set_key_table(c
, NULL
);
2072 server_status_client(c
);
2074 /* Execute the key binding. */
2075 key_bindings_dispatch(bd
, item
, c
, event
, &fs
);
2076 key_bindings_unref_table(table
);
2081 * No match, try the ANY key.
2083 if (key0
!= KEYC_ANY
) {
2089 * Binding movement keys is useless since we only turn them on when the
2090 * application requests, so don't let them exit the prefix table.
2092 if (key
== KEYC_MOUSEMOVE_PANE
||
2093 key
== KEYC_MOUSEMOVE_STATUS
||
2094 key
== KEYC_MOUSEMOVE_STATUS_LEFT
||
2095 key
== KEYC_MOUSEMOVE_STATUS_RIGHT
||
2096 key
== KEYC_MOUSEMOVE_STATUS_DEFAULT
||
2097 key
== KEYC_MOUSEMOVE_BORDER
)
2101 * No match in this table. If not in the root table or if repeating
2102 * switch the client back to the root table and try again.
2104 log_debug("not found in key table %s", table
->name
);
2105 if (!server_client_is_default_key_table(c
, table
) ||
2106 (c
->flags
& CLIENT_REPEAT
)) {
2107 log_debug("trying in root table");
2108 server_client_set_key_table(c
, NULL
);
2109 table
= c
->keytable
;
2110 if (c
->flags
& CLIENT_REPEAT
)
2112 c
->flags
&= ~CLIENT_REPEAT
;
2113 server_status_client(c
);
2118 * No match in the root table either. If this wasn't the first table
2119 * tried, don't pass the key to the pane.
2121 if (first
!= table
&& (~flags
& CLIENT_REPEAT
)) {
2122 server_client_set_key_table(c
, NULL
);
2123 server_status_client(c
);
2128 if (c
->flags
& CLIENT_READONLY
)
2131 window_pane_key(wp
, c
, s
, wl
, key
, m
);
2135 if (c
->flags
& CLIENT_READONLY
)
2137 if (event
->buf
!= NULL
)
2138 window_pane_paste(wp
, event
->buf
, event
->len
);
2143 if (s
!= NULL
&& key
!= KEYC_FOCUS_OUT
)
2144 server_client_update_latest(c
);
2147 return (CMD_RETURN_NORMAL
);
2150 /* Handle a key event. */
2152 server_client_handle_key(struct client
*c
, struct key_event
*event
)
2154 struct session
*s
= c
->session
;
2155 struct cmdq_item
*item
;
2157 /* Check the client is good to accept input. */
2158 if (s
== NULL
|| (c
->flags
& CLIENT_UNATTACHEDFLAGS
))
2162 * Key presses in overlay mode and the command prompt are a special
2163 * case. The queue might be blocked so they need to be processed
2164 * immediately rather than queued.
2166 if (~c
->flags
& CLIENT_READONLY
) {
2167 if (c
->message_string
!= NULL
) {
2168 if (c
->message_ignore_keys
)
2170 status_message_clear(c
);
2172 if (c
->overlay_key
!= NULL
) {
2173 switch (c
->overlay_key(c
, c
->overlay_data
, event
)) {
2177 server_client_clear_overlay(c
);
2181 server_client_clear_overlay(c
);
2182 if (c
->prompt_string
!= NULL
) {
2183 if (status_prompt_key(c
, event
->key
) == 0)
2189 * Add the key to the queue so it happens after any commands queued by
2192 item
= cmdq_get_callback(server_client_key_callback
, event
);
2193 cmdq_append(c
, item
);
2197 /* Client functions that need to happen every loop. */
2199 server_client_loop(void)
2203 struct window_pane
*wp
;
2205 /* Check for window resize. This is done before redrawing. */
2206 RB_FOREACH(w
, windows
, &windows
)
2207 server_client_check_window_resize(w
);
2209 /* Check clients. */
2210 TAILQ_FOREACH(c
, &clients
, entry
) {
2211 server_client_check_exit(c
);
2212 if (c
->session
!= NULL
) {
2213 server_client_check_modes(c
);
2214 server_client_check_redraw(c
);
2215 server_client_reset_state(c
);
2220 * Any windows will have been redrawn as part of clients, so clear
2223 RB_FOREACH(w
, windows
, &windows
) {
2224 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
2226 server_client_check_pane_resize(wp
);
2227 server_client_check_pane_buffer(wp
);
2229 wp
->flags
&= ~PANE_REDRAW
;
2231 check_window_name(w
);
2235 /* Check if window needs to be resized. */
2237 server_client_check_window_resize(struct window
*w
)
2241 if (~w
->flags
& WINDOW_RESIZE
)
2244 TAILQ_FOREACH(wl
, &w
->winlinks
, wentry
) {
2245 if (wl
->session
->attached
!= 0 && wl
->session
->curw
== wl
)
2251 log_debug("%s: resizing window @%u", __func__
, w
->id
);
2252 resize_window(w
, w
->new_sx
, w
->new_sy
, w
->new_xpixel
, w
->new_ypixel
);
2255 /* Resize timer event. */
2257 server_client_resize_timer(__unused
int fd
, __unused
short events
, void *data
)
2259 struct window_pane
*wp
= data
;
2261 log_debug("%s: %%%u resize timer expired", __func__
, wp
->id
);
2262 evtimer_del(&wp
->resize_timer
);
2265 /* Check if pane should be resized. */
2267 server_client_check_pane_resize(struct window_pane
*wp
)
2269 struct window_pane_resize
*r
;
2270 struct window_pane_resize
*r1
;
2271 struct window_pane_resize
*first
;
2272 struct window_pane_resize
*last
;
2273 struct timeval tv
= { .tv_usec
= 250000 };
2275 if (TAILQ_EMPTY(&wp
->resize_queue
))
2278 if (!event_initialized(&wp
->resize_timer
))
2279 evtimer_set(&wp
->resize_timer
, server_client_resize_timer
, wp
);
2280 if (evtimer_pending(&wp
->resize_timer
, NULL
))
2283 log_debug("%s: %%%u needs to be resized", __func__
, wp
->id
);
2284 TAILQ_FOREACH(r
, &wp
->resize_queue
, entry
) {
2285 log_debug("queued resize: %ux%u -> %ux%u", r
->osx
, r
->osy
,
2290 * There are three cases that matter:
2292 * - Only one resize. It can just be applied.
2294 * - Multiple resizes and the ending size is different from the
2295 * starting size. We can discard all resizes except the most recent.
2297 * - Multiple resizes and the ending size is the same as the starting
2298 * size. We must resize at least twice to force the application to
2299 * redraw. So apply the first and leave the last on the queue for
2302 first
= TAILQ_FIRST(&wp
->resize_queue
);
2303 last
= TAILQ_LAST(&wp
->resize_queue
, window_pane_resizes
);
2304 if (first
== last
) {
2305 /* Only one resize. */
2306 window_pane_send_resize(wp
, first
->sx
, first
->sy
);
2307 TAILQ_REMOVE(&wp
->resize_queue
, first
, entry
);
2309 } else if (last
->sx
!= first
->osx
|| last
->sy
!= first
->osy
) {
2310 /* Multiple resizes ending up with a different size. */
2311 window_pane_send_resize(wp
, last
->sx
, last
->sy
);
2312 TAILQ_FOREACH_SAFE(r
, &wp
->resize_queue
, entry
, r1
) {
2313 TAILQ_REMOVE(&wp
->resize_queue
, r
, entry
);
2318 * Multiple resizes ending up with the same size. There will
2319 * not be more than one to the same size in succession so we
2320 * can just use the last-but-one on the list and leave the last
2321 * for later. We reduce the time until the next check to avoid
2322 * a long delay between the resizes.
2324 r
= TAILQ_PREV(last
, window_pane_resizes
, entry
);
2325 window_pane_send_resize(wp
, r
->sx
, r
->sy
);
2326 TAILQ_FOREACH_SAFE(r
, &wp
->resize_queue
, entry
, r1
) {
2329 TAILQ_REMOVE(&wp
->resize_queue
, r
, entry
);
2334 evtimer_add(&wp
->resize_timer
, &tv
);
2337 /* Check pane buffer size. */
2339 server_client_check_pane_buffer(struct window_pane
*wp
)
2341 struct evbuffer
*evb
= wp
->event
->input
;
2344 struct window_pane_offset
*wpo
;
2346 u_int attached_clients
= 0;
2350 * Work out the minimum used size. This is the most that can be removed
2353 minimum
= wp
->offset
.used
;
2354 if (wp
->pipe_fd
!= -1 && wp
->pipe_offset
.used
< minimum
)
2355 minimum
= wp
->pipe_offset
.used
;
2356 TAILQ_FOREACH(c
, &clients
, entry
) {
2357 if (c
->session
== NULL
)
2361 if (~c
->flags
& CLIENT_CONTROL
) {
2365 wpo
= control_pane_offset(c
, wp
, &flag
);
2374 window_pane_get_new_data(wp
, wpo
, &new_size
);
2375 log_debug("%s: %s has %zu bytes used and %zu left for %%%u",
2376 __func__
, c
->name
, wpo
->used
- wp
->base_offset
, new_size
,
2378 if (wpo
->used
< minimum
)
2379 minimum
= wpo
->used
;
2381 if (attached_clients
== 0)
2383 minimum
-= wp
->base_offset
;
2387 /* Drain the buffer. */
2388 log_debug("%s: %%%u has %zu minimum (of %zu) bytes used", __func__
,
2389 wp
->id
, minimum
, EVBUFFER_LENGTH(evb
));
2390 evbuffer_drain(evb
, minimum
);
2393 * Adjust the base offset. If it would roll over, all the offsets into
2394 * the buffer need to be adjusted.
2396 if (wp
->base_offset
> SIZE_MAX
- minimum
) {
2397 log_debug("%s: %%%u base offset has wrapped", __func__
, wp
->id
);
2398 wp
->offset
.used
-= wp
->base_offset
;
2399 if (wp
->pipe_fd
!= -1)
2400 wp
->pipe_offset
.used
-= wp
->base_offset
;
2401 TAILQ_FOREACH(c
, &clients
, entry
) {
2402 if (c
->session
== NULL
|| (~c
->flags
& CLIENT_CONTROL
))
2404 wpo
= control_pane_offset(c
, wp
, &flag
);
2405 if (wpo
!= NULL
&& !flag
)
2406 wpo
->used
-= wp
->base_offset
;
2408 wp
->base_offset
= minimum
;
2410 wp
->base_offset
+= minimum
;
2414 * If there is data remaining, and there are no clients able to consume
2415 * it, do not read any more. This is true when there are attached
2416 * clients, all of which are control clients which are not able to
2417 * accept any more data.
2419 log_debug("%s: pane %%%u is %s", __func__
, wp
->id
, off
? "off" : "on");
2421 bufferevent_disable(wp
->event
, EV_READ
);
2423 bufferevent_enable(wp
->event
, EV_READ
);
2427 * Update cursor position and mode settings. The scroll region and attributes
2428 * are cleared when idle (waiting for an event) as this is the most likely time
2429 * a user may interrupt tmux, for example with ~^Z in ssh(1). This is a
2430 * compromise between excessive resets and likelihood of an interrupt.
2432 * tty_region/tty_reset/tty_update_mode already take care of not resetting
2433 * things that are already in their default state.
2436 server_client_reset_state(struct client
*c
)
2438 struct tty
*tty
= &c
->tty
;
2439 struct window
*w
= c
->session
->curw
->window
;
2440 struct window_pane
*wp
= server_client_get_pane(c
), *loop
;
2441 struct screen
*s
= NULL
;
2442 struct options
*oo
= c
->session
->options
;
2443 int mode
= 0, cursor
, flags
, n
;
2444 u_int cx
= 0, cy
= 0, ox
, oy
, sx
, sy
;
2446 if (c
->flags
& (CLIENT_CONTROL
|CLIENT_SUSPENDED
))
2449 /* Disable the block flag. */
2450 flags
= (tty
->flags
& TTY_BLOCK
);
2451 tty
->flags
&= ~TTY_BLOCK
;
2453 /* Get mode from overlay if any, else from screen. */
2454 if (c
->overlay_draw
!= NULL
) {
2455 if (c
->overlay_mode
!= NULL
)
2456 s
= c
->overlay_mode(c
, c
->overlay_data
, &cx
, &cy
);
2457 } else if (c
->prompt_string
== NULL
)
2460 s
= c
->status
.active
;
2463 if (log_get_level() != 0) {
2464 log_debug("%s: client %s mode %s", __func__
, c
->name
,
2465 screen_mode_to_string(mode
));
2468 /* Reset region and margin. */
2469 tty_region_off(tty
);
2470 tty_margin_off(tty
);
2472 /* Move cursor to pane cursor and offset. */
2473 if (c
->prompt_string
!= NULL
) {
2474 n
= options_get_number(oo
, "status-position");
2478 n
= status_line_size(c
);
2484 cx
= c
->prompt_cursor
;
2485 } else if (c
->overlay_draw
== NULL
) {
2487 tty_window_offset(tty
, &ox
, &oy
, &sx
, &sy
);
2488 if (wp
->xoff
+ s
->cx
>= ox
&& wp
->xoff
+ s
->cx
<= ox
+ sx
&&
2489 wp
->yoff
+ s
->cy
>= oy
&& wp
->yoff
+ s
->cy
<= oy
+ sy
) {
2492 cx
= wp
->xoff
+ s
->cx
- ox
;
2493 cy
= wp
->yoff
+ s
->cy
- oy
;
2495 if (status_at_line(c
) == 0)
2496 cy
+= status_line_size(c
);
2499 mode
&= ~MODE_CURSOR
;
2501 log_debug("%s: cursor to %u,%u", __func__
, cx
, cy
);
2502 tty_cursor(tty
, cx
, cy
);
2505 * Set mouse mode if requested. To support dragging, always use button
2508 if (options_get_number(oo
, "mouse")) {
2509 if (c
->overlay_draw
== NULL
) {
2510 mode
&= ~ALL_MOUSE_MODES
;
2511 TAILQ_FOREACH(loop
, &w
->panes
, entry
) {
2512 if (loop
->screen
->mode
& MODE_MOUSE_ALL
)
2513 mode
|= MODE_MOUSE_ALL
;
2516 if (~mode
& MODE_MOUSE_ALL
)
2517 mode
|= MODE_MOUSE_BUTTON
;
2520 /* Clear bracketed paste mode if at the prompt. */
2521 if (c
->overlay_draw
== NULL
&& c
->prompt_string
!= NULL
)
2522 mode
&= ~MODE_BRACKETPASTE
;
2524 /* Set the terminal mode and reset attributes. */
2525 tty_update_mode(tty
, mode
, s
);
2528 /* All writing must be done, send a sync end (if it was started). */
2530 tty
->flags
|= flags
;
2533 /* Repeat time callback. */
2535 server_client_repeat_timer(__unused
int fd
, __unused
short events
, void *data
)
2537 struct client
*c
= data
;
2539 if (c
->flags
& CLIENT_REPEAT
) {
2540 server_client_set_key_table(c
, NULL
);
2541 c
->flags
&= ~CLIENT_REPEAT
;
2542 server_status_client(c
);
2546 /* Double-click callback. */
2548 server_client_click_timer(__unused
int fd
, __unused
short events
, void *data
)
2550 struct client
*c
= data
;
2551 struct key_event
*event
;
2553 log_debug("click timer expired");
2555 if (c
->flags
& CLIENT_TRIPLECLICK
) {
2557 * Waiting for a third click that hasn't happened, so this must
2558 * have been a double click.
2560 event
= xcalloc(1, sizeof *event
);
2561 event
->key
= KEYC_DOUBLECLICK
;
2562 memcpy(&event
->m
, &c
->click_event
, sizeof event
->m
);
2563 if (!server_client_handle_key(c
, event
)) {
2568 c
->flags
&= ~(CLIENT_DOUBLECLICK
|CLIENT_TRIPLECLICK
);
2571 /* Check if client should be exited. */
2573 server_client_check_exit(struct client
*c
)
2575 struct client_file
*cf
;
2576 const char *name
= c
->exit_session
;
2580 if (c
->flags
& (CLIENT_DEAD
|CLIENT_EXITED
))
2582 if (~c
->flags
& CLIENT_EXIT
)
2585 if (c
->flags
& CLIENT_CONTROL
) {
2587 if (!control_all_done(c
))
2590 RB_FOREACH(cf
, client_files
, &c
->files
) {
2591 if (EVBUFFER_LENGTH(cf
->buffer
) != 0)
2594 c
->flags
|= CLIENT_EXITED
;
2596 switch (c
->exit_type
) {
2597 case CLIENT_EXIT_RETURN
:
2598 if (c
->exit_message
!= NULL
)
2599 msize
= strlen(c
->exit_message
) + 1;
2602 size
= (sizeof c
->retval
) + msize
;
2603 data
= xmalloc(size
);
2604 memcpy(data
, &c
->retval
, sizeof c
->retval
);
2605 if (c
->exit_message
!= NULL
)
2606 memcpy(data
+ sizeof c
->retval
, c
->exit_message
, msize
);
2607 proc_send(c
->peer
, MSG_EXIT
, -1, data
, size
);
2610 case CLIENT_EXIT_SHUTDOWN
:
2611 proc_send(c
->peer
, MSG_SHUTDOWN
, -1, NULL
, 0);
2613 case CLIENT_EXIT_DETACH
:
2614 proc_send(c
->peer
, c
->exit_msgtype
, -1, name
, strlen(name
) + 1);
2617 free(c
->exit_session
);
2618 free(c
->exit_message
);
2621 /* Redraw timer callback. */
2623 server_client_redraw_timer(__unused
int fd
, __unused
short events
,
2624 __unused
void *data
)
2626 log_debug("redraw timer fired");
2630 * Check if modes need to be updated. Only modes in the current window are
2631 * updated and it is done when the status line is redrawn.
2634 server_client_check_modes(struct client
*c
)
2636 struct window
*w
= c
->session
->curw
->window
;
2637 struct window_pane
*wp
;
2638 struct window_mode_entry
*wme
;
2640 if (c
->flags
& (CLIENT_CONTROL
|CLIENT_SUSPENDED
))
2642 if (~c
->flags
& CLIENT_REDRAWSTATUS
)
2644 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
2645 wme
= TAILQ_FIRST(&wp
->modes
);
2646 if (wme
!= NULL
&& wme
->mode
->update
!= NULL
)
2647 wme
->mode
->update(wme
);
2651 /* Check for client redraws. */
2653 server_client_check_redraw(struct client
*c
)
2655 struct session
*s
= c
->session
;
2656 struct tty
*tty
= &c
->tty
;
2657 struct window
*w
= c
->session
->curw
->window
;
2658 struct window_pane
*wp
;
2659 int needed
, tty_flags
, mode
= tty
->mode
;
2660 uint64_t client_flags
= 0;
2663 struct timeval tv
= { .tv_usec
= 1000 };
2664 static struct event ev
;
2667 if (c
->flags
& (CLIENT_CONTROL
|CLIENT_SUSPENDED
))
2669 if (c
->flags
& CLIENT_ALLREDRAWFLAGS
) {
2670 log_debug("%s: redraw%s%s%s%s%s", c
->name
,
2671 (c
->flags
& CLIENT_REDRAWWINDOW
) ? " window" : "",
2672 (c
->flags
& CLIENT_REDRAWSTATUS
) ? " status" : "",
2673 (c
->flags
& CLIENT_REDRAWBORDERS
) ? " borders" : "",
2674 (c
->flags
& CLIENT_REDRAWOVERLAY
) ? " overlay" : "",
2675 (c
->flags
& CLIENT_REDRAWPANES
) ? " panes" : "");
2679 * If there is outstanding data, defer the redraw until it has been
2680 * consumed. We can just add a timer to get out of the event loop and
2684 if (c
->flags
& CLIENT_ALLREDRAWFLAGS
)
2687 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
2688 if (wp
->flags
& PANE_REDRAW
) {
2694 client_flags
|= CLIENT_REDRAWPANES
;
2696 if (needed
&& (left
= EVBUFFER_LENGTH(tty
->out
)) != 0) {
2697 log_debug("%s: redraw deferred (%zu left)", c
->name
, left
);
2698 if (!evtimer_initialized(&ev
))
2699 evtimer_set(&ev
, server_client_redraw_timer
, NULL
);
2700 if (!evtimer_pending(&ev
, NULL
)) {
2701 log_debug("redraw timer started");
2702 evtimer_add(&ev
, &tv
);
2705 if (~c
->flags
& CLIENT_REDRAWWINDOW
) {
2706 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
2707 if (wp
->flags
& PANE_REDRAW
) {
2708 log_debug("%s: pane %%%u needs redraw",
2710 c
->redraw_panes
|= (1 << bit
);
2714 * If more that 64 panes, give up and
2715 * just redraw the window.
2717 client_flags
&= CLIENT_REDRAWPANES
;
2718 client_flags
|= CLIENT_REDRAWWINDOW
;
2722 if (c
->redraw_panes
!= 0)
2723 c
->flags
|= CLIENT_REDRAWPANES
;
2725 c
->flags
|= client_flags
;
2728 log_debug("%s: redraw needed", c
->name
);
2730 tty_flags
= tty
->flags
& (TTY_BLOCK
|TTY_FREEZE
|TTY_NOCURSOR
);
2731 tty
->flags
= (tty
->flags
& ~(TTY_BLOCK
|TTY_FREEZE
))|TTY_NOCURSOR
;
2733 if (~c
->flags
& CLIENT_REDRAWWINDOW
) {
2735 * If not redrawing the entire window, check whether each pane
2736 * needs to be redrawn.
2738 TAILQ_FOREACH(wp
, &w
->panes
, entry
) {
2740 if (wp
->flags
& PANE_REDRAW
)
2742 else if (c
->flags
& CLIENT_REDRAWPANES
)
2743 redraw
= !!(c
->redraw_panes
& (1 << bit
));
2747 log_debug("%s: redrawing pane %%%u", __func__
, wp
->id
);
2748 screen_redraw_pane(c
, wp
);
2750 c
->redraw_panes
= 0;
2751 c
->flags
&= ~CLIENT_REDRAWPANES
;
2754 if (c
->flags
& CLIENT_ALLREDRAWFLAGS
) {
2755 if (options_get_number(s
->options
, "set-titles")) {
2756 server_client_set_title(c
);
2757 server_client_set_path(c
);
2759 screen_redraw_screen(c
);
2762 tty
->flags
= (tty
->flags
& ~TTY_NOCURSOR
)|(tty_flags
& TTY_NOCURSOR
);
2763 tty_update_mode(tty
, mode
, NULL
);
2764 tty
->flags
= (tty
->flags
& ~(TTY_BLOCK
|TTY_FREEZE
|TTY_NOCURSOR
))|
2767 c
->flags
&= ~(CLIENT_ALLREDRAWFLAGS
|CLIENT_STATUSFORCE
);
2771 * We would have deferred the redraw unless the output buffer
2772 * was empty, so we can record how many bytes the redraw
2775 c
->redraw
= EVBUFFER_LENGTH(tty
->out
);
2776 log_debug("%s: redraw added %zu bytes", c
->name
, c
->redraw
);
2780 /* Set client title. */
2782 server_client_set_title(struct client
*c
)
2784 struct session
*s
= c
->session
;
2785 const char *template;
2787 struct format_tree
*ft
;
2789 template = options_get_string(s
->options
, "set-titles-string");
2791 ft
= format_create(c
, NULL
, FORMAT_NONE
, 0);
2792 format_defaults(ft
, c
, NULL
, NULL
, NULL
);
2794 title
= format_expand_time(ft
, template);
2795 if (c
->title
== NULL
|| strcmp(title
, c
->title
) != 0) {
2797 c
->title
= xstrdup(title
);
2798 tty_set_title(&c
->tty
, c
->title
);
2805 /* Set client path. */
2807 server_client_set_path(struct client
*c
)
2809 struct session
*s
= c
->session
;
2812 if (s
->curw
== NULL
)
2814 if (s
->curw
->window
->active
->base
.path
== NULL
)
2817 path
= s
->curw
->window
->active
->base
.path
;
2818 if (c
->path
== NULL
|| strcmp(path
, c
->path
) != 0) {
2820 c
->path
= xstrdup(path
);
2821 tty_set_path(&c
->tty
, c
->path
);
2825 /* Dispatch message from client. */
2827 server_client_dispatch(struct imsg
*imsg
, void *arg
)
2829 struct client
*c
= arg
;
2833 if (c
->flags
& CLIENT_DEAD
)
2837 server_client_lost(c
);
2841 datalen
= imsg
->hdr
.len
- IMSG_HEADER_SIZE
;
2843 switch (imsg
->hdr
.type
) {
2844 case MSG_IDENTIFY_CLIENTPID
:
2845 case MSG_IDENTIFY_CWD
:
2846 case MSG_IDENTIFY_ENVIRON
:
2847 case MSG_IDENTIFY_FEATURES
:
2848 case MSG_IDENTIFY_FLAGS
:
2849 case MSG_IDENTIFY_LONGFLAGS
:
2850 case MSG_IDENTIFY_STDIN
:
2851 case MSG_IDENTIFY_STDOUT
:
2852 case MSG_IDENTIFY_TERM
:
2853 case MSG_IDENTIFY_TERMINFO
:
2854 case MSG_IDENTIFY_TTYNAME
:
2855 case MSG_IDENTIFY_DONE
:
2856 server_client_dispatch_identify(c
, imsg
);
2859 server_client_dispatch_command(c
, imsg
);
2863 fatalx("bad MSG_RESIZE size");
2865 if (c
->flags
& CLIENT_CONTROL
)
2867 server_client_update_latest(c
);
2868 tty_resize(&c
->tty
);
2869 tty_repeat_requests(&c
->tty
);
2870 recalculate_sizes();
2871 if (c
->overlay_resize
== NULL
)
2872 server_client_clear_overlay(c
);
2874 c
->overlay_resize(c
, c
->overlay_data
);
2875 server_redraw_client(c
);
2876 if (c
->session
!= NULL
)
2877 notify_client("client-resized", c
);
2881 fatalx("bad MSG_EXITING size");
2882 server_client_set_session(c
, NULL
);
2883 recalculate_sizes();
2885 proc_send(c
->peer
, MSG_EXITED
, -1, NULL
, 0);
2890 fatalx("bad MSG_WAKEUP size");
2892 if (!(c
->flags
& CLIENT_SUSPENDED
))
2894 c
->flags
&= ~CLIENT_SUSPENDED
;
2896 if (c
->fd
== -1 || c
->session
== NULL
) /* exited already */
2900 if (gettimeofday(&c
->activity_time
, NULL
) != 0)
2901 fatal("gettimeofday failed");
2903 tty_start_tty(&c
->tty
);
2904 server_redraw_client(c
);
2905 recalculate_sizes();
2908 session_update_activity(s
, &c
->activity_time
);
2912 fatalx("bad MSG_SHELL size");
2914 server_client_dispatch_shell(c
);
2916 case MSG_WRITE_READY
:
2917 file_write_ready(&c
->files
, imsg
);
2920 file_read_data(&c
->files
, imsg
);
2923 file_read_done(&c
->files
, imsg
);
2928 /* Callback when command is not allowed. */
2929 static enum cmd_retval
2930 server_client_read_only(struct cmdq_item
*item
, __unused
void *data
)
2932 cmdq_error(item
, "client is read-only");
2933 return (CMD_RETURN_ERROR
);
2936 /* Callback when command is done. */
2937 static enum cmd_retval
2938 server_client_command_done(struct cmdq_item
*item
, __unused
void *data
)
2940 struct client
*c
= cmdq_get_client(item
);
2942 if (~c
->flags
& CLIENT_ATTACHED
)
2943 c
->flags
|= CLIENT_EXIT
;
2944 else if (~c
->flags
& CLIENT_EXIT
) {
2945 if (c
->flags
& CLIENT_CONTROL
)
2947 tty_send_requests(&c
->tty
);
2949 return (CMD_RETURN_NORMAL
);
2952 /* Handle command message. */
2954 server_client_dispatch_command(struct client
*c
, struct imsg
*imsg
)
2956 struct msg_command data
;
2960 char **argv
, *cause
;
2961 struct cmd_parse_result
*pr
;
2962 struct args_value
*values
;
2963 struct cmdq_item
*new_item
;
2965 if (c
->flags
& CLIENT_EXIT
)
2968 if (imsg
->hdr
.len
- IMSG_HEADER_SIZE
< sizeof data
)
2969 fatalx("bad MSG_COMMAND size");
2970 memcpy(&data
, imsg
->data
, sizeof data
);
2972 buf
= (char *)imsg
->data
+ sizeof data
;
2973 len
= imsg
->hdr
.len
- IMSG_HEADER_SIZE
- sizeof data
;
2974 if (len
> 0 && buf
[len
- 1] != '\0')
2975 fatalx("bad MSG_COMMAND string");
2978 if (cmd_unpack_argv(buf
, len
, argc
, &argv
) != 0) {
2979 cause
= xstrdup("command too long");
2985 argv
= xcalloc(1, sizeof *argv
);
2986 *argv
= xstrdup("new-session");
2989 values
= args_from_vector(argc
, argv
);
2990 pr
= cmd_parse_from_arguments(values
, argc
, NULL
);
2991 switch (pr
->status
) {
2992 case CMD_PARSE_ERROR
:
2995 case CMD_PARSE_SUCCESS
:
2998 args_free_values(values
, argc
);
3000 cmd_free_argv(argc
, argv
);
3002 if ((c
->flags
& CLIENT_READONLY
) &&
3003 !cmd_list_all_have(pr
->cmdlist
, CMD_READONLY
))
3004 new_item
= cmdq_get_callback(server_client_read_only
, NULL
);
3006 new_item
= cmdq_get_command(pr
->cmdlist
, NULL
);
3007 cmdq_append(c
, new_item
);
3008 cmdq_append(c
, cmdq_get_callback(server_client_command_done
, NULL
));
3010 cmd_list_free(pr
->cmdlist
);
3014 cmd_free_argv(argc
, argv
);
3016 cmdq_append(c
, cmdq_get_error(cause
));
3019 c
->flags
|= CLIENT_EXIT
;
3022 /* Handle identify message. */
3024 server_client_dispatch_identify(struct client
*c
, struct imsg
*imsg
)
3026 const char *data
, *home
;
3032 if (c
->flags
& CLIENT_IDENTIFIED
)
3033 fatalx("out-of-order identify message");
3036 datalen
= imsg
->hdr
.len
- IMSG_HEADER_SIZE
;
3038 switch (imsg
->hdr
.type
) {
3039 case MSG_IDENTIFY_FEATURES
:
3040 if (datalen
!= sizeof feat
)
3041 fatalx("bad MSG_IDENTIFY_FEATURES size");
3042 memcpy(&feat
, data
, sizeof feat
);
3043 c
->term_features
|= feat
;
3044 log_debug("client %p IDENTIFY_FEATURES %s", c
,
3045 tty_get_features(feat
));
3047 case MSG_IDENTIFY_FLAGS
:
3048 if (datalen
!= sizeof flags
)
3049 fatalx("bad MSG_IDENTIFY_FLAGS size");
3050 memcpy(&flags
, data
, sizeof flags
);
3052 log_debug("client %p IDENTIFY_FLAGS %#x", c
, flags
);
3054 case MSG_IDENTIFY_LONGFLAGS
:
3055 if (datalen
!= sizeof longflags
)
3056 fatalx("bad MSG_IDENTIFY_LONGFLAGS size");
3057 memcpy(&longflags
, data
, sizeof longflags
);
3058 c
->flags
|= longflags
;
3059 log_debug("client %p IDENTIFY_LONGFLAGS %#llx", c
,
3060 (unsigned long long)longflags
);
3062 case MSG_IDENTIFY_TERM
:
3063 if (datalen
== 0 || data
[datalen
- 1] != '\0')
3064 fatalx("bad MSG_IDENTIFY_TERM string");
3066 c
->term_name
= xstrdup("unknown");
3068 c
->term_name
= xstrdup(data
);
3069 log_debug("client %p IDENTIFY_TERM %s", c
, data
);
3071 case MSG_IDENTIFY_TERMINFO
:
3072 if (datalen
== 0 || data
[datalen
- 1] != '\0')
3073 fatalx("bad MSG_IDENTIFY_TERMINFO string");
3074 c
->term_caps
= xreallocarray(c
->term_caps
, c
->term_ncaps
+ 1,
3075 sizeof *c
->term_caps
);
3076 c
->term_caps
[c
->term_ncaps
++] = xstrdup(data
);
3077 log_debug("client %p IDENTIFY_TERMINFO %s", c
, data
);
3079 case MSG_IDENTIFY_TTYNAME
:
3080 if (datalen
== 0 || data
[datalen
- 1] != '\0')
3081 fatalx("bad MSG_IDENTIFY_TTYNAME string");
3082 c
->ttyname
= xstrdup(data
);
3083 log_debug("client %p IDENTIFY_TTYNAME %s", c
, data
);
3085 case MSG_IDENTIFY_CWD
:
3086 if (datalen
== 0 || data
[datalen
- 1] != '\0')
3087 fatalx("bad MSG_IDENTIFY_CWD string");
3088 if (access(data
, X_OK
) == 0)
3089 c
->cwd
= xstrdup(data
);
3090 else if ((home
= find_home()) != NULL
)
3091 c
->cwd
= xstrdup(home
);
3093 c
->cwd
= xstrdup("/");
3094 log_debug("client %p IDENTIFY_CWD %s", c
, data
);
3096 case MSG_IDENTIFY_STDIN
:
3098 fatalx("bad MSG_IDENTIFY_STDIN size");
3099 c
->fd
= imsg_get_fd(imsg
);
3100 log_debug("client %p IDENTIFY_STDIN %d", c
, c
->fd
);
3102 case MSG_IDENTIFY_STDOUT
:
3104 fatalx("bad MSG_IDENTIFY_STDOUT size");
3105 c
->out_fd
= imsg_get_fd(imsg
);
3106 log_debug("client %p IDENTIFY_STDOUT %d", c
, c
->out_fd
);
3108 case MSG_IDENTIFY_ENVIRON
:
3109 if (datalen
== 0 || data
[datalen
- 1] != '\0')
3110 fatalx("bad MSG_IDENTIFY_ENVIRON string");
3111 if (strchr(data
, '=') != NULL
)
3112 environ_put(c
->environ
, data
, 0);
3113 log_debug("client %p IDENTIFY_ENVIRON %s", c
, data
);
3115 case MSG_IDENTIFY_CLIENTPID
:
3116 if (datalen
!= sizeof c
->pid
)
3117 fatalx("bad MSG_IDENTIFY_CLIENTPID size");
3118 memcpy(&c
->pid
, data
, sizeof c
->pid
);
3119 log_debug("client %p IDENTIFY_CLIENTPID %ld", c
, (long)c
->pid
);
3125 if (imsg
->hdr
.type
!= MSG_IDENTIFY_DONE
)
3127 c
->flags
|= CLIENT_IDENTIFIED
;
3129 if (*c
->ttyname
!= '\0')
3130 name
= xstrdup(c
->ttyname
);
3132 xasprintf(&name
, "client-%ld", (long)c
->pid
);
3134 log_debug("client %p name is %s", c
, c
->name
);
3137 c
->fd
= open(c
->ttyname
, O_RDWR
|O_NOCTTY
);
3138 c
->out_fd
= dup(c
->fd
);
3141 if (c
->flags
& CLIENT_CONTROL
)
3143 else if (c
->fd
!= -1) {
3144 if (tty_init(&c
->tty
, c
) != 0) {
3148 tty_resize(&c
->tty
);
3149 c
->flags
|= CLIENT_TERMINAL
;
3156 * If this is the first client, load configuration files. Any later
3157 * clients are allowed to continue with their command even if the
3158 * config has not been loaded - they might have been run from inside it
3160 if ((~c
->flags
& CLIENT_EXIT
) &&
3162 c
== TAILQ_FIRST(&clients
))
3166 /* Handle shell message. */
3168 server_client_dispatch_shell(struct client
*c
)
3172 shell
= options_get_string(global_s_options
, "default-shell");
3173 if (!checkshell(shell
))
3174 shell
= _PATH_BSHELL
;
3175 proc_send(c
->peer
, MSG_SHELL
, -1, shell
, strlen(shell
) + 1);
3177 proc_kill_peer(c
->peer
);
3180 /* Get client working directory. */
3182 server_client_get_cwd(struct client
*c
, struct session
*s
)
3186 if (!cfg_finished
&& cfg_client
!= NULL
)
3187 return (cfg_client
->cwd
);
3188 if (c
!= NULL
&& c
->session
== NULL
&& c
->cwd
!= NULL
)
3190 if (s
!= NULL
&& s
->cwd
!= NULL
)
3192 if (c
!= NULL
&& (s
= c
->session
) != NULL
&& s
->cwd
!= NULL
)
3194 if ((home
= find_home()) != NULL
)
3199 /* Get control client flags. */
3201 server_client_control_flags(struct client
*c
, const char *next
)
3203 if (strcmp(next
, "pause-after") == 0) {
3205 return (CLIENT_CONTROL_PAUSEAFTER
);
3207 if (sscanf(next
, "pause-after=%u", &c
->pause_age
) == 1) {
3208 c
->pause_age
*= 1000;
3209 return (CLIENT_CONTROL_PAUSEAFTER
);
3211 if (strcmp(next
, "no-output") == 0)
3212 return (CLIENT_CONTROL_NOOUTPUT
);
3213 if (strcmp(next
, "wait-exit") == 0)
3214 return (CLIENT_CONTROL_WAITEXIT
);
3218 /* Set client flags. */
3220 server_client_set_flags(struct client
*c
, const char *flags
)
3222 char *s
, *copy
, *next
;
3226 s
= copy
= xstrdup(flags
);
3227 while ((next
= strsep(&s
, ",")) != NULL
) {
3228 not = (*next
== '!');
3232 if (c
->flags
& CLIENT_CONTROL
)
3233 flag
= server_client_control_flags(c
, next
);
3236 if (strcmp(next
, "read-only") == 0)
3237 flag
= CLIENT_READONLY
;
3238 else if (strcmp(next
, "ignore-size") == 0)
3239 flag
= CLIENT_IGNORESIZE
;
3240 else if (strcmp(next
, "active-pane") == 0)
3241 flag
= CLIENT_ACTIVEPANE
;
3245 log_debug("client %s set flag %s", c
->name
, next
);
3247 if (c
->flags
& CLIENT_READONLY
)
3248 flag
&= ~CLIENT_READONLY
;
3252 if (flag
== CLIENT_CONTROL_NOOUTPUT
)
3253 control_reset_offsets(c
);
3256 proc_send(c
->peer
, MSG_FLAGS
, -1, &c
->flags
, sizeof c
->flags
);
3259 /* Get client flags. This is only flags useful to show to users. */
3261 server_client_get_flags(struct client
*c
)
3267 if (c
->flags
& CLIENT_ATTACHED
)
3268 strlcat(s
, "attached,", sizeof s
);
3269 if (c
->flags
& CLIENT_FOCUSED
)
3270 strlcat(s
, "focused,", sizeof s
);
3271 if (c
->flags
& CLIENT_CONTROL
)
3272 strlcat(s
, "control-mode,", sizeof s
);
3273 if (c
->flags
& CLIENT_IGNORESIZE
)
3274 strlcat(s
, "ignore-size,", sizeof s
);
3275 if (c
->flags
& CLIENT_CONTROL_NOOUTPUT
)
3276 strlcat(s
, "no-output,", sizeof s
);
3277 if (c
->flags
& CLIENT_CONTROL_WAITEXIT
)
3278 strlcat(s
, "wait-exit,", sizeof s
);
3279 if (c
->flags
& CLIENT_CONTROL_PAUSEAFTER
) {
3280 xsnprintf(tmp
, sizeof tmp
, "pause-after=%u,",
3281 c
->pause_age
/ 1000);
3282 strlcat(s
, tmp
, sizeof s
);
3284 if (c
->flags
& CLIENT_READONLY
)
3285 strlcat(s
, "read-only,", sizeof s
);
3286 if (c
->flags
& CLIENT_ACTIVEPANE
)
3287 strlcat(s
, "active-pane,", sizeof s
);
3288 if (c
->flags
& CLIENT_SUSPENDED
)
3289 strlcat(s
, "suspended,", sizeof s
);
3290 if (c
->flags
& CLIENT_UTF8
)
3291 strlcat(s
, "UTF-8,", sizeof s
);
3293 s
[strlen(s
) - 1] = '\0';
3297 /* Get client window. */
3298 struct client_window
*
3299 server_client_get_client_window(struct client
*c
, u_int id
)
3301 struct client_window cw
= { .window
= id
};
3303 return (RB_FIND(client_windows
, &c
->windows
, &cw
));
3306 /* Add client window. */
3307 struct client_window
*
3308 server_client_add_client_window(struct client
*c
, u_int id
)
3310 struct client_window
*cw
;
3312 cw
= server_client_get_client_window(c
, id
);
3314 cw
= xcalloc(1, sizeof *cw
);
3316 RB_INSERT(client_windows
, &c
->windows
, cw
);
3321 /* Get client active pane. */
3322 struct window_pane
*
3323 server_client_get_pane(struct client
*c
)
3325 struct session
*s
= c
->session
;
3326 struct client_window
*cw
;
3331 if (~c
->flags
& CLIENT_ACTIVEPANE
)
3332 return (s
->curw
->window
->active
);
3333 cw
= server_client_get_client_window(c
, s
->curw
->window
->id
);
3335 return (s
->curw
->window
->active
);
3339 /* Set client active pane. */
3341 server_client_set_pane(struct client
*c
, struct window_pane
*wp
)
3343 struct session
*s
= c
->session
;
3344 struct client_window
*cw
;
3349 cw
= server_client_add_client_window(c
, s
->curw
->window
->id
);
3351 log_debug("%s pane now %%%u", c
->name
, wp
->id
);
3354 /* Remove pane from client lists. */
3356 server_client_remove_pane(struct window_pane
*wp
)
3359 struct window
*w
= wp
->window
;
3360 struct client_window
*cw
;
3362 TAILQ_FOREACH(c
, &clients
, entry
) {
3363 cw
= server_client_get_client_window(c
, w
->id
);
3364 if (cw
!= NULL
&& cw
->pane
== wp
) {
3365 RB_REMOVE(client_windows
, &c
->windows
, cw
);
3371 /* Print to a client. */
3373 server_client_print(struct client
*c
, int parse
, struct evbuffer
*evb
)
3375 void *data
= EVBUFFER_DATA(evb
);
3376 size_t size
= EVBUFFER_LENGTH(evb
);
3377 struct window_pane
*wp
;
3378 struct window_mode_entry
*wme
;
3379 char *sanitized
, *msg
, *line
;
3382 utf8_stravisx(&msg
, data
, size
,
3383 VIS_OCTAL
|VIS_CSTYLE
|VIS_NOSLASH
);
3384 log_debug("%s: %s", __func__
, msg
);
3386 msg
= EVBUFFER_DATA(evb
);
3387 if (msg
[size
- 1] != '\0')
3388 evbuffer_add(evb
, "", 1);
3394 if (c
->session
== NULL
|| (c
->flags
& CLIENT_CONTROL
)) {
3395 if (~c
->flags
& CLIENT_UTF8
) {
3396 sanitized
= utf8_sanitize(msg
);
3397 if (c
->flags
& CLIENT_CONTROL
)
3398 control_write(c
, "%s", sanitized
);
3400 file_print(c
, "%s\n", sanitized
);
3403 if (c
->flags
& CLIENT_CONTROL
)
3404 control_write(c
, "%s", msg
);
3406 file_print(c
, "%s\n", msg
);
3411 wp
= server_client_get_pane(c
);
3412 wme
= TAILQ_FIRST(&wp
->modes
);
3413 if (wme
== NULL
|| wme
->mode
!= &window_view_mode
)
3414 window_pane_set_mode(wp
, NULL
, &window_view_mode
, NULL
, NULL
);
3417 line
= evbuffer_readln(evb
, NULL
, EVBUFFER_EOL_LF
);
3419 window_copy_add(wp
, 1, "%s", line
);
3422 } while (line
!= NULL
);
3424 size
= EVBUFFER_LENGTH(evb
);
3426 line
= EVBUFFER_DATA(evb
);
3427 window_copy_add(wp
, 1, "%.*s", (int)size
, line
);
3430 window_copy_add(wp
, 0, "%s", msg
);