Add a suspend helper function, and do not allow detaching or suspending

while already doing so.
This commit is contained in:
nicm 2017-04-19 14:00:28 +00:00
parent 689f4bfac2
commit 53fde21bb8
3 changed files with 21 additions and 7 deletions

View File

@ -67,9 +67,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
const char *cmd = args_get(args, 'E'); const char *cmd = args_get(args, 'E');
if (self->entry == &cmd_suspend_client_entry) { if (self->entry == &cmd_suspend_client_entry) {
tty_stop_tty(&c->tty); server_client_suspend(c);
c->flags |= CLIENT_SUSPENDED;
proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@ -49,7 +49,7 @@ static void server_client_dispatch_command(struct client *, struct imsg *);
static void server_client_dispatch_identify(struct client *, struct imsg *); static void server_client_dispatch_identify(struct client *, struct imsg *);
static void server_client_dispatch_shell(struct client *); static void server_client_dispatch_shell(struct client *);
/* Idenfity mode callback. */ /* Identify mode callback. */
static void static void
server_client_callback_identify(__unused int fd, __unused short events, void *data) server_client_callback_identify(__unused int fd, __unused short events, void *data)
{ {
@ -325,15 +325,30 @@ server_client_free(__unused int fd, __unused short events, void *arg)
} }
} }
/* Suspend a client. */
void
server_client_suspend(struct client *c)
{
struct session *s = c->session;
if (s == NULL || (c->flags & CLIENT_DETACHING))
return;
tty_stop_tty(&c->tty);
c->flags |= CLIENT_SUSPENDED;
proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
}
/* Detach a client. */ /* Detach a client. */
void void
server_client_detach(struct client *c, enum msgtype msgtype) server_client_detach(struct client *c, enum msgtype msgtype)
{ {
struct session *s = c->session; struct session *s = c->session;
if (s == NULL) if (s == NULL || (c->flags & CLIENT_DETACHING))
return; return;
c->flags |= CLIENT_DETACHING;
notify_client("client-detached", c); notify_client("client-detached", c);
proc_send_s(c->peer, msgtype, s->name); proc_send_s(c->peer, msgtype, s->name);
} }

3
tmux.h
View File

@ -1338,7 +1338,7 @@ struct client {
#define CLIENT_DEAD 0x200 #define CLIENT_DEAD 0x200
#define CLIENT_BORDERS 0x400 #define CLIENT_BORDERS 0x400
#define CLIENT_READONLY 0x800 #define CLIENT_READONLY 0x800
/* 0x1000 unused */ #define CLIENT_DETACHING 0x1000
#define CLIENT_CONTROL 0x2000 #define CLIENT_CONTROL 0x2000
#define CLIENT_CONTROLCONTROL 0x4000 #define CLIENT_CONTROLCONTROL 0x4000
#define CLIENT_FOCUSED 0x8000 #define CLIENT_FOCUSED 0x8000
@ -1838,6 +1838,7 @@ void server_client_create(int);
int server_client_open(struct client *, char **); int server_client_open(struct client *, char **);
void server_client_unref(struct client *); void server_client_unref(struct client *);
void server_client_lost(struct client *); void server_client_lost(struct client *);
void server_client_suspend(struct client *);
void server_client_detach(struct client *, enum msgtype); void server_client_detach(struct client *, enum msgtype);
void server_client_exec(struct client *, const char *); void server_client_exec(struct client *, const char *);
void server_client_loop(void); void server_client_loop(void);