diff --git a/cmd-lock-client.c b/cmd-lock-client.c new file mode 100644 index 00000000..4575ee88 --- /dev/null +++ b/cmd-lock-client.c @@ -0,0 +1,53 @@ +/* $Id: cmd-lock-client.c,v 1.1 2009-09-25 17:51:39 tcunha Exp $ */ + +/* + * 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..9ebace79 --- /dev/null +++ b/cmd-lock-session.c @@ -0,0 +1,53 @@ +/* $Id: cmd-lock-session.c,v 1.1 2009-09-25 17:51:39 tcunha Exp $ */ + +/* + * 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 4bbc0d51..3e2f29f5 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.117 2009-09-23 15:00:08 tcunha Exp $ */ +/* $Id: cmd.c,v 1.118 2009-09-25 17:51:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -60,7 +60,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 fa9bd649..441d293b 100644 --- a/server-fn.c +++ b/server-fn.c @@ -1,4 +1,4 @@ -/* $Id: server-fn.c,v 1.90 2009-09-23 15:00:08 tcunha Exp $ */ +/* $Id: server-fn.c,v 1.91 2009-09-25 17:51:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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 dbb8b88c..254091ac 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.173 2009-09-23 15:18:56 tcunha Exp $ +.\" $Id: tmux.1,v 1.174 2009-09-25 17:51:39 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 23 2009 $ +.Dd $Mdocdate: September 24 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -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 46194a43..7ee303db 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.455 2009-09-25 17:45:46 tcunha Exp $ */ +/* $Id: tmux.h,v 1.456 2009-09-25 17:51:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1324,7 +1324,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; @@ -1455,6 +1457,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(