From 8fa1858a2c02aafa31695a12fa40cd5dbdd53cd2 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 24 Sep 2009 14:17:09 +0000 Subject: [PATCH] New lock-client and lock-session commands to lock an individual client or all clients attached to a session respectively. --- Makefile | 3 ++- cmd-lock-client.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ cmd-lock-session.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ cmd.c | 2 ++ server-fn.c | 55 ++++++++++++++++++++++++++++++++-------------- tmux.1 | 13 +++++++++++ tmux.h | 4 ++++ 7 files changed, 166 insertions(+), 17 deletions(-) create mode 100644 cmd-lock-client.c create mode 100644 cmd-lock-session.c diff --git a/Makefile b/Makefile index f35149df..f6df7718 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \ cmd-last-window.c cmd-link-window.c cmd-list-buffers.c \ cmd-list-clients.c cmd-list-commands.c cmd-list-keys.c \ cmd-list-sessions.c cmd-list-windows.c cmd-list.c cmd-load-buffer.c \ - cmd-lock-server.c cmd-move-window.c cmd-new-session.c cmd-new-window.c \ + cmd-lock-server.c cmd-lock-client.c cmd-lock-session.c \ + cmd-move-window.c cmd-new-session.c cmd-new-window.c \ cmd-next-layout.c cmd-next-window.c cmd-paste-buffer.c \ cmd-previous-layout.c cmd-previous-window.c cmd-refresh-client.c \ cmd-rename-session.c cmd-rename-window.c cmd-resize-pane.c \ diff --git a/cmd-lock-client.c b/cmd-lock-client.c new file mode 100644 index 00000000..e855d32c --- /dev/null +++ b/cmd-lock-client.c @@ -0,0 +1,53 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2009 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "tmux.h" + +/* + * Lock a single client. + */ + +int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *); + +const struct cmd_entry cmd_lock_client_entry = { + "lock-client", "lockc", + CMD_TARGET_CLIENT_USAGE, + 0, 0, + cmd_target_init, + cmd_target_parse, + cmd_lock_client_exec, + cmd_target_free, + cmd_target_print +}; + +int +cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx) +{ + struct cmd_target_data *data = self->data; + struct client *c; + + if ((c = cmd_find_client(ctx, data->target)) == NULL) + return (-1); + + server_lock_client(c); + recalculate_sizes(); + + return (0); +} diff --git a/cmd-lock-session.c b/cmd-lock-session.c new file mode 100644 index 00000000..c0a6569c --- /dev/null +++ b/cmd-lock-session.c @@ -0,0 +1,53 @@ +/* $OpenBSD$ */ + +/* + * Copyright (c) 2009 Nicholas Marriott + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "tmux.h" + +/* + * Lock all clients attached to a session. + */ + +int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *); + +const struct cmd_entry cmd_lock_session_entry = { + "lock-session", "locks", + CMD_TARGET_SESSION_USAGE, + 0, 0, + cmd_target_init, + cmd_target_parse, + cmd_lock_session_exec, + cmd_target_free, + cmd_target_print +}; + +int +cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx) +{ + struct cmd_target_data *data = self->data; + struct session *s; + + if ((s = cmd_find_session(ctx, data->target)) == NULL) + return (-1); + + server_lock_session(s); + recalculate_sizes(); + + return (0); +} diff --git a/cmd.c b/cmd.c index d027cd9c..05294be1 100644 --- a/cmd.c +++ b/cmd.c @@ -61,7 +61,9 @@ const struct cmd_entry *cmd_table[] = { &cmd_list_sessions_entry, &cmd_list_windows_entry, &cmd_load_buffer_entry, + &cmd_lock_client_entry, &cmd_lock_server_entry, + &cmd_lock_session_entry, &cmd_move_window_entry, &cmd_new_session_entry, &cmd_new_window_entry, diff --git a/server-fn.c b/server-fn.c index b9be1794..6acca2bf 100644 --- a/server-fn.c +++ b/server-fn.c @@ -157,10 +157,8 @@ server_status_window(struct window *w) void server_lock(void) { - struct client *c; - const char *cmd; - struct msg_lock_data lockdata; - u_int i; + struct client *c; + u_int i; for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); @@ -168,21 +166,46 @@ server_lock(void) continue; if (c->flags & CLIENT_SUSPENDED) continue; - - cmd = options_get_string(&c->session->options, "lock-command"); - if (strlcpy(lockdata.cmd, - cmd, sizeof lockdata.cmd) >= sizeof lockdata.cmd) - continue; - - tty_stop_tty(&c->tty); - tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_SMCUP)); - tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_CLEAR)); - - c->flags |= CLIENT_SUSPENDED; - server_write_client(c, MSG_LOCK, &lockdata, sizeof lockdata); + server_lock_client(c); } } +void +server_lock_session(struct session *s) +{ + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session == NULL || c->session != s) + continue; + if (c->flags & CLIENT_SUSPENDED) + continue; + server_lock_client(c); + } +} + +void +server_lock_client(struct client *c) +{ + const char *cmd; + size_t cmdlen; + struct msg_lock_data lockdata; + + cmd = options_get_string(&c->session->options, "lock-command"); + cmdlen = strlcpy(lockdata.cmd, cmd, sizeof lockdata.cmd); + if (cmdlen >= sizeof lockdata.cmd) + return; + + tty_stop_tty(&c->tty); + tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_SMCUP)); + tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_CLEAR)); + + c->flags |= CLIENT_SUSPENDED; + server_write_client(c, MSG_LOCK, &lockdata, sizeof lockdata); +} + void server_kill_window(struct window *w) { diff --git a/tmux.1 b/tmux.1 index 542663d7..22351bfa 100644 --- a/tmux.1 +++ b/tmux.1 @@ -392,6 +392,19 @@ List the syntax of all commands supported by .It Ic list-sessions .D1 (alias: Ic ls ) List all sessions managed by the server. +.It Xo Ic lock-client +.Op Fl t Ar target-client +.Xc +Lock +.Ar target-client , +see the +.Ic lock-server +command. +.It Xo Ic lock-session +.Op Fl t Ar target-session +.Xc +Lock all clients attached to +.Ar target-session . .It Xo Ic new-session .Op Fl d .Op Fl n Ar window-name diff --git a/tmux.h b/tmux.h index 46117659..3c49ae30 100644 --- a/tmux.h +++ b/tmux.h @@ -1326,7 +1326,9 @@ extern const struct cmd_entry cmd_list_keys_entry; extern const struct cmd_entry cmd_list_sessions_entry; extern const struct cmd_entry cmd_list_windows_entry; extern const struct cmd_entry cmd_load_buffer_entry; +extern const struct cmd_entry cmd_lock_client_entry; extern const struct cmd_entry cmd_lock_server_entry; +extern const struct cmd_entry cmd_lock_session_entry; extern const struct cmd_entry cmd_move_window_entry; extern const struct cmd_entry cmd_new_session_entry; extern const struct cmd_entry cmd_new_window_entry; @@ -1457,6 +1459,8 @@ void server_status_session(struct session *); void server_redraw_window(struct window *); void server_status_window(struct window *); void server_lock(void); +void server_lock_session(struct session *); +void server_lock_client(struct client *); int server_unlock(const char *); void server_kill_window(struct window *); int server_link_window(