Added two-stroke mechanism for detaching

This commit is contained in:
Michael Krayer 2023-10-11 10:50:16 +02:00
parent 3c5aafc0fb
commit c80e8ff369
2 changed files with 13 additions and 5 deletions

View File

@ -63,6 +63,7 @@ static int client_mainloop(void) {
sigprocmask(SIG_BLOCK, &blockset, NULL);
client.need_resize = true;
client.await_command = false;
Packet pkt = {
.type = MSG_ATTACH,
.u.i = client.flags,
@ -121,15 +122,21 @@ static int client_mainloop(void) {
die("client-stdin");
if (len > 0) {
debug("client-stdin: %c\n", pkt.u.msg[0]);
if (client.await_command) {
client.await_command = false;
if (pkt.u.msg[0]=='d') {
pkt.type = MSG_DETACH;
pkt.len = 0;
client_send_packet(&pkt);
close(server.socket);
return -1;
}
}
pkt.len = len;
if (KEY_REDRAW && pkt.u.msg[0] == KEY_REDRAW) {
client.need_resize = true;
} else if (pkt.u.msg[0] == KEY_DETACH) {
pkt.type = MSG_DETACH;
pkt.len = 0;
client_send_packet(&pkt);
close(server.socket);
return -1;
client.await_command = true;
} else if (!(client.flags & CLIENT_READONLY)) {
client_send_packet(&pkt);
}

View File

@ -100,6 +100,7 @@ struct Client {
CLIENT_LOWPRIORITY = 1 << 1,
} flags;
Client *next;
bool await_command;
};
typedef struct {