From 1fcd6e4f44fbfa0ef8171c6e6e86469e3ffe7a5c Mon Sep 17 00:00:00 2001 From: Luke Clifton Date: Sat, 2 Jan 2016 19:43:15 +0000 Subject: [PATCH] Added -l option to move clients to the bottom of the stack. This means it wont take control over the window size until it is the last remaining one, unless another client connects with the -l option set at a later time. --- abduco.1 | 5 +++++ abduco.c | 11 ++++++++--- client.c | 4 ++-- server.c | 16 +++++++++++++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/abduco.1 b/abduco.1 index e32092f..d983885 100644 --- a/abduco.1 +++ b/abduco.1 @@ -28,6 +28,7 @@ abduco - terminal session manager .IR detachkey ] .RB [ \-r ] .RB [ \-f ] +.RB [ \-l ] .RB \-A .RB name .RB command @@ -37,6 +38,7 @@ abduco - terminal session manager .RB [ \-e .IR detachkey ] .RB [ \-r ] +.RB [ \-l ] .RB \-a .RB name .br @@ -105,6 +107,9 @@ Try to connect to an existing session, upon failure create said session and atta .TP .BI \-a Attach to an existing session. +.TP +.BI \-l +Attach with the lowest priority, meaning this client will be the last to control the size. .SH EXAMPLE Start a new session (assuming .BR dvtm(1) diff --git a/abduco.c b/abduco.c index 6a2ba40..38ce165 100644 --- a/abduco.c +++ b/abduco.c @@ -77,7 +77,9 @@ typedef struct { char msg[BUFSIZ]; struct winsize ws; int i; - bool b; + struct { + bool ro, lp; + } attach; } u; } Packet; @@ -114,7 +116,7 @@ typedef struct { static Server server = { .running = true, .exit_status = -1, .host = "@localhost" }; static Client client; static struct termios orig_term, cur_term; -static bool has_term, alternate_buffer; +static bool has_term, alternate_buffer, low_priority; static struct sockaddr_un sockaddr = { .sun_family = AF_UNIX, @@ -582,7 +584,7 @@ int main(int argc, char *argv[]) { if (argc == 1) exit(list_session()); - while ((opt = getopt(argc, argv, "aAcne:frv")) != -1) { + while ((opt = getopt(argc, argv, "aAclne:frv")) != -1) { switch (opt) { case 'a': case 'A': @@ -603,6 +605,9 @@ int main(int argc, char *argv[]) { case 'r': client.readonly = true; break; + case 'l': + low_priority = true; + break; case 'v': puts("abduco-"VERSION" © 2013-2015 Marc André Tanner"); exit(EXIT_SUCCESS); diff --git a/client.c b/client.c index 51443d7..2e38400 100644 --- a/client.c +++ b/client.c @@ -62,8 +62,8 @@ static int client_mainloop(void) { client.need_resize = true; Packet pkt = { .type = MSG_ATTACH, - .u = { .b = client.readonly }, - .len = sizeof(pkt.u.b), + .u = { .attach = { .ro = client.readonly, .lp = low_priority } }, + .len = sizeof(pkt.u.attach), }; client_send_packet(&pkt); diff --git a/server.c b/server.c index c47db50..7868cb0 100644 --- a/server.c +++ b/server.c @@ -18,6 +18,18 @@ static void client_free(Client *c) { free(c); } +static void server_sink_client() { + if (!server.clients || !server.clients->next) + return; + Client *target = server.clients; + server.clients = target->next; + Client *dst = server.clients; + while (dst->next) + dst = dst->next; + target->next = NULL; + dst->next = target; +} + static void server_mark_socket_exec(bool exec, bool usr) { struct stat sb; if (stat(sockaddr.sun_path, &sb) == -1) @@ -201,7 +213,9 @@ static void server_mainloop(void) { server_write_pty(&client_packet); break; case MSG_ATTACH: - c->readonly = client_packet.u.b; + c->readonly = client_packet.u.attach.ro; + if (client_packet.u.attach.lp) + server_sink_client(); break; case MSG_RESIZE: c->state = STATE_ATTACHED;