mirror of
https://github.com/tmux/tmux.git
synced 2025-03-24 14:58:47 +00:00
New lock-client and lock-session commands to lock an individual client or all
clients attached to a session respectively.
This commit is contained in:
parent
1764ef81ef
commit
8fa1858a2c
3
Makefile
3
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-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-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-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-next-layout.c cmd-next-window.c cmd-paste-buffer.c \
|
||||||
cmd-previous-layout.c cmd-previous-window.c cmd-refresh-client.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 \
|
cmd-rename-session.c cmd-rename-window.c cmd-resize-pane.c \
|
||||||
|
53
cmd-lock-client.c
Normal file
53
cmd-lock-client.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* $OpenBSD$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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 <sys/types.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
53
cmd-lock-session.c
Normal file
53
cmd-lock-session.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* $OpenBSD$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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 <sys/types.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
2
cmd.c
2
cmd.c
@ -61,7 +61,9 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
&cmd_list_sessions_entry,
|
&cmd_list_sessions_entry,
|
||||||
&cmd_list_windows_entry,
|
&cmd_list_windows_entry,
|
||||||
&cmd_load_buffer_entry,
|
&cmd_load_buffer_entry,
|
||||||
|
&cmd_lock_client_entry,
|
||||||
&cmd_lock_server_entry,
|
&cmd_lock_server_entry,
|
||||||
|
&cmd_lock_session_entry,
|
||||||
&cmd_move_window_entry,
|
&cmd_move_window_entry,
|
||||||
&cmd_new_session_entry,
|
&cmd_new_session_entry,
|
||||||
&cmd_new_window_entry,
|
&cmd_new_window_entry,
|
||||||
|
55
server-fn.c
55
server-fn.c
@ -157,10 +157,8 @@ server_status_window(struct window *w)
|
|||||||
void
|
void
|
||||||
server_lock(void)
|
server_lock(void)
|
||||||
{
|
{
|
||||||
struct client *c;
|
struct client *c;
|
||||||
const char *cmd;
|
u_int i;
|
||||||
struct msg_lock_data lockdata;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
c = ARRAY_ITEM(&clients, i);
|
c = ARRAY_ITEM(&clients, i);
|
||||||
@ -168,21 +166,46 @@ server_lock(void)
|
|||||||
continue;
|
continue;
|
||||||
if (c->flags & CLIENT_SUSPENDED)
|
if (c->flags & CLIENT_SUSPENDED)
|
||||||
continue;
|
continue;
|
||||||
|
server_lock_client(c);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
server_kill_window(struct window *w)
|
server_kill_window(struct window *w)
|
||||||
{
|
{
|
||||||
|
13
tmux.1
13
tmux.1
@ -392,6 +392,19 @@ List the syntax of all commands supported by
|
|||||||
.It Ic list-sessions
|
.It Ic list-sessions
|
||||||
.D1 (alias: Ic ls )
|
.D1 (alias: Ic ls )
|
||||||
List all sessions managed by the server.
|
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
|
.It Xo Ic new-session
|
||||||
.Op Fl d
|
.Op Fl d
|
||||||
.Op Fl n Ar window-name
|
.Op Fl n Ar window-name
|
||||||
|
4
tmux.h
4
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_sessions_entry;
|
||||||
extern const struct cmd_entry cmd_list_windows_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_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_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_move_window_entry;
|
||||||
extern const struct cmd_entry cmd_new_session_entry;
|
extern const struct cmd_entry cmd_new_session_entry;
|
||||||
extern const struct cmd_entry cmd_new_window_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_redraw_window(struct window *);
|
||||||
void server_status_window(struct window *);
|
void server_status_window(struct window *);
|
||||||
void server_lock(void);
|
void server_lock(void);
|
||||||
|
void server_lock_session(struct session *);
|
||||||
|
void server_lock_client(struct client *);
|
||||||
int server_unlock(const char *);
|
int server_unlock(const char *);
|
||||||
void server_kill_window(struct window *);
|
void server_kill_window(struct window *);
|
||||||
int server_link_window(
|
int server_link_window(
|
||||||
|
Loading…
Reference in New Issue
Block a user