summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-02-06 22:55:32 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-02-06 22:55:32 +0000
commit892e10e5c056cf061b989c70bb4b030d0bfa8377 (patch)
tree21b583a7d02d6b87e586702ed583d0e615b565b9 /usr.bin/tmux
parent4859720892d211ccf40bae2f88188ca870a71b7f (diff)
Support attaching a client read-only with a new -r flag to the attach-session
command.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-attach-session.c9
-rw-r--r--usr.bin/tmux/cmd-detach-client.c4
-rw-r--r--usr.bin/tmux/key-bindings.c16
-rw-r--r--usr.bin/tmux/server-client.c27
-rw-r--r--usr.bin/tmux/tmux.18
-rw-r--r--usr.bin/tmux/tmux.h4
6 files changed, 48 insertions, 20 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c
index f49b865c7b3..8421e50e85c 100644
--- a/usr.bin/tmux/cmd-attach-session.c
+++ b/usr.bin/tmux/cmd-attach-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-attach-session.c,v 1.11 2009/12/03 22:50:09 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.12 2010/02/06 22:55:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,8 +28,8 @@ int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach",
- "[-d] " CMD_TARGET_SESSION_USAGE,
- CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "d",
+ "[-dr] " CMD_TARGET_SESSION_USAGE,
+ CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "dr",
cmd_target_init,
cmd_target_parse,
cmd_attach_session_exec,
@@ -89,6 +89,9 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
+ if (cmd_check_flag(data->chflags, 'r'))
+ ctx->cmdclient->flags |= CLIENT_READONLY;
+
if (cmd_check_flag(data->chflags, 'd'))
server_write_session(s, MSG_DETACH, NULL, 0);
diff --git a/usr.bin/tmux/cmd-detach-client.c b/usr.bin/tmux/cmd-detach-client.c
index 77a30d294fb..b3f523113bb 100644
--- a/usr.bin/tmux/cmd-detach-client.c
+++ b/usr.bin/tmux/cmd-detach-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-detach-client.c,v 1.4 2009/11/13 19:53:29 nicm Exp $ */
+/* $OpenBSD: cmd-detach-client.c,v 1.5 2010/02/06 22:55:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
CMD_TARGET_CLIENT_USAGE,
- 0, "",
+ CMD_READONLY, "",
cmd_target_init,
cmd_target_parse,
cmd_detach_client_exec,
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index bff573139ed..711106646c6 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.16 2009/12/10 09:16:52 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.17 2010/02/06 22:55:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -239,7 +239,9 @@ key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...)
void
key_bindings_dispatch(struct key_binding *bd, struct client *c)
{
- struct cmd_ctx ctx;
+ struct cmd_ctx ctx;
+ struct cmd *cmd;
+ int readonly;
ctx.msgdata = NULL;
ctx.curclient = c;
@@ -250,5 +252,15 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c)
ctx.cmdclient = NULL;
+ readonly = 1;
+ TAILQ_FOREACH(cmd, bd->cmdlist, qentry) {
+ if (!(cmd->entry->flags & CMD_READONLY))
+ readonly = 0;
+ }
+ if (!readonly && c->flags & CLIENT_READONLY) {
+ key_bindings_info(&ctx, "Client is read-only");
+ return;
+ }
+
cmd_list_exec(bd->cmdlist, &ctx);
}
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 331e4137211..45533c72ec1 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.29 2010/02/06 18:47:41 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.30 2010/02/06 22:55:31 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -271,6 +271,8 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
/* Special case: number keys jump to pane in identify mode. */
if (c->flags & CLIENT_IDENTIFY && key >= '0' && key <= '9') {
+ if (c->flags & CLIENT_READONLY)
+ return;
wp = window_pane_at_index(w, key - '0');
if (wp != NULL && window_pane_visible(wp))
window_set_active_pane(w, wp);
@@ -279,15 +281,20 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
}
/* Handle status line. */
- status_message_clear(c);
- server_clear_identify(c);
+ if (!(c->flags & CLIENT_READONLY)) {
+ status_message_clear(c);
+ server_clear_identify(c);
+ }
if (c->prompt_string != NULL) {
- status_prompt_key(c, key);
+ if (!(c->flags & CLIENT_READONLY))
+ status_prompt_key(c, key);
return;
}
/* Check for mouse keys. */
if (key == KEYC_MOUSE) {
+ if (c->flags & CLIENT_READONLY)
+ return;
if (options_get_number(oo, "mouse-select-pane")) {
window_set_active_at(w, mouse->x, mouse->y);
server_redraw_window_borders(w);
@@ -313,9 +320,10 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
c->flags |= CLIENT_PREFIX;
else {
/* Try as a non-prefix key binding. */
- if ((bd = key_bindings_lookup(key)) == NULL)
- window_pane_key(wp, c, key);
- else
+ if ((bd = key_bindings_lookup(key)) == NULL) {
+ if (!(c->flags & CLIENT_READONLY))
+ window_pane_key(wp, c, key);
+ } else
key_bindings_dispatch(bd, c);
}
return;
@@ -329,7 +337,7 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
c->flags &= ~CLIENT_REPEAT;
if (isprefix)
c->flags |= CLIENT_PREFIX;
- else
+ else if (!(c->flags & CLIENT_READONLY))
window_pane_key(wp, c, key);
}
return;
@@ -340,7 +348,7 @@ server_client_handle_key(int key, struct mouse_event *mouse, void *data)
c->flags &= ~CLIENT_REPEAT;
if (isprefix)
c->flags |= CLIENT_PREFIX;
- else
+ else if (!(c->flags & CLIENT_READONLY))
window_pane_key(wp, c, key);
return;
}
@@ -660,7 +668,6 @@ server_client_msg_command(struct client *c, struct msg_command_data *data)
{
struct cmd_ctx ctx;
struct cmd_list *cmdlist = NULL;
- struct cmd *cmd;
int argc;
char **argv, *cause;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index a5da4297f16..33885c47247 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.147 2010/02/06 17:35:01 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.148 2010/02/06 22:55:31 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -364,7 +364,7 @@ new-window ; split-window -d
The following commands are available:
.Bl -tag -width Ds
.It Xo Ic attach-session
-.Op Fl d
+.Op Fl dr
.Op Fl t Ar target-session
.Xc
.D1 (alias: Ic attach )
@@ -376,6 +376,10 @@ If used from inside, switch the current client.
If
.Fl d
is specified, any other clients attached to the session are detached.
+.Fl r
+signifies the client is read-only (only keys bound to the
+.Ic detach-client
+command have any effect)
.Pp
If no server is started,
.Ic attach-session
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index b7a5ad027ec..8be009b0ed0 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.204 2010/02/06 17:35:01 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.205 2010/02/06 22:55:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1094,6 +1094,7 @@ struct client {
#define CLIENT_IDENTIFY 0x100
#define CLIENT_DEAD 0x200
#define CLIENT_BORDERS 0x400
+#define CLIENT_READONLY 0x800
int flags;
struct event identify_timer;
@@ -1172,6 +1173,7 @@ struct cmd_entry {
#define CMD_ARG01 0x10
#define CMD_ARG2 0x20
#define CMD_ARG12 0x40
+#define CMD_READONLY 0x80
int flags;
const char *chflags;