summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/server-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux/server-client.c')
-rw-r--r--usr.bin/tmux/server-client.c109
1 files changed, 68 insertions, 41 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 0c5dc083ff2..16992d0525a 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.65 2012/01/29 02:22:11 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.66 2012/01/29 09:37:02 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,6 +27,8 @@
#include "tmux.h"
+void server_client_check_mouse(struct client *c,
+ struct window_pane *wp, struct mouse_event *mouse);
void server_client_handle_key(int, struct mouse_event *, void *);
void server_client_repeat_timer(int, short, void *);
void server_client_check_exit(struct client *);
@@ -262,6 +264,65 @@ server_client_status_timer(void)
}
}
+/* Check for mouse keys. */
+void
+server_client_check_mouse(
+ struct client *c, struct window_pane *wp, struct mouse_event *mouse)
+{
+ struct session *s = c->session;
+ struct options *oo = &s->options;
+ int statusat;
+
+ statusat = status_at_line(c);
+
+ /* Is this a window selection click on the status line? */
+ if (statusat != -1 && mouse->y == (u_int)statusat &&
+ options_get_number(oo, "mouse-select-window")) {
+ if (mouse->b == MOUSE_UP && c->last_mouse.b != MOUSE_UP) {
+ status_set_window_at(c, mouse->x);
+ return;
+ }
+ if (mouse->b & MOUSE_45) {
+ if ((mouse->b & MOUSE_BUTTON) == MOUSE_1) {
+ session_previous(c->session, 0);
+ server_redraw_session(s);
+ }
+ if ((mouse->b & MOUSE_BUTTON) == MOUSE_2) {
+ session_next(c->session, 0);
+ server_redraw_session(s);
+ }
+ return;
+ }
+ }
+
+ /*
+ * Not on status line - adjust mouse position if status line is at the
+ * top and limit if at the bottom. From here on a struct mouse
+ * represents the offset onto the window itself.
+ */
+ if (statusat == 0 &&mouse->y > 0)
+ mouse->y--;
+ else if (statusat > 0 && mouse->y >= (u_int)statusat)
+ mouse->y = statusat - 1;
+
+ /* Is this a pane selection? Allow down only in copy mode. */
+ if (options_get_number(oo, "mouse-select-pane") &&
+ ((!(mouse->b & MOUSE_DRAG) && mouse->b != MOUSE_UP) ||
+ wp->mode != &window_copy_mode)) {
+ window_set_active_at(wp->window, mouse->x, mouse->y);
+ server_redraw_window_borders(wp->window);
+ wp = wp->window->active; /* may have changed */
+ }
+
+ /* Check if trying to resize pane. */
+ if (options_get_number(oo, "mouse-resize-pane"))
+ layout_resize_pane_mouse(c, mouse);
+
+ /* Update last and pass through to client. */
+ memcpy(&c->last_mouse, mouse, sizeof c->last_mouse);
+ window_pane_mouse(wp, c->session, mouse);
+}
+
/* Handle data key input from client. */
void
server_client_handle_key(int key, struct mouse_event *mouse, void *data)
@@ -317,43 +378,7 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
if (key == KEYC_MOUSE) {
if (c->flags & CLIENT_READONLY)
return;
- if (options_get_number(oo, "mouse-select-pane") &&
- (!(options_get_number(oo, "status") &&
- mouse->y + 1 == c->tty.sy)) &&
- ((!(mouse->b & MOUSE_DRAG) && mouse->b != MOUSE_UP) ||
- wp->mode != &window_copy_mode)) {
- /*
- * Allow pane switching in copy mode only by mouse down
- * (click).
- */
- window_set_active_at(w, mouse->x, mouse->y);
- server_redraw_window_borders(w);
- wp = w->active;
- }
- if (mouse->y + 1 == c->tty.sy &&
- options_get_number(oo, "mouse-select-window") &&
- options_get_number(oo, "status")) {
- if (mouse->b == MOUSE_UP &&
- c->last_mouse.b != MOUSE_UP) {
- status_set_window_at(c, mouse->x);
- return;
- }
- if (mouse->b & MOUSE_45) {
- if ((mouse->b & MOUSE_BUTTON) == MOUSE_1) {
- session_previous(c->session, 0);
- server_redraw_session(s);
- }
- if ((mouse->b & MOUSE_BUTTON) == MOUSE_2) {
- session_next(c->session, 0);
- server_redraw_session(s);
- }
- return;
- }
- }
- if (options_get_number(oo, "mouse-resize-pane"))
- layout_resize_pane_mouse(c, mouse);
- memcpy(&c->last_mouse, mouse, sizeof c->last_mouse);
- window_pane_mouse(wp, c->session, mouse);
+ server_client_check_mouse(c, wp, mouse);
return;
}
@@ -472,7 +497,7 @@ server_client_reset_state(struct client *c)
struct screen *s = wp->screen;
struct options *oo = &c->session->options;
struct options *wo = &w->options;
- int status, mode;
+ int status, mode, o;
if (c->flags & CLIENT_SUSPENDED)
return;
@@ -482,8 +507,10 @@ server_client_reset_state(struct client *c)
status = options_get_number(oo, "status");
if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status)
tty_cursor(&c->tty, 0, 0);
- else
- tty_cursor(&c->tty, wp->xoff + s->cx, wp->yoff + s->cy);
+ else {
+ o = status && options_get_number (oo, "status-position") == 0;
+ tty_cursor(&c->tty, wp->xoff + s->cx, o + wp->yoff + s->cy);
+ }
/*
* Resizing panes with the mouse requires at least button mode to give