diff --git a/client.c b/client.c index faa7c919..7d188609 100644 --- a/client.c +++ b/client.c @@ -33,6 +33,8 @@ print_usage(const char *prog_name) printf("\n"); printf("Options:\n"); printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n" + " --maximized start in maximized mode\n" + " --fullscreen start in fullscreen mode\n" " --login-shell start shell as a login shell\n" " -s,--server-socket=PATH path to the server UNIX domain socket (default=$XDG_RUNTIME_DIR/foot-$XDG_SESSION_ID.sock)\n" " -l,--log-colorize=[never|always|auto] enable/disable colorization of log output on stderr\n" @@ -48,6 +50,8 @@ main(int argc, char *const *argv) static const struct option longopts[] = { {"term", required_argument, 0, 't'}, + {"maximized", no_argument, 0, 'm'}, + {"fullscreen", no_argument, 0, 'F'}, {"login-shell", no_argument, 0, 'L'}, {"server-socket", required_argument, 0, 's'}, {"log-colorize", optional_argument, NULL, 'l'}, @@ -60,6 +64,8 @@ main(int argc, char *const *argv) const char *server_socket_path = NULL; enum log_colorize log_colorize = LOG_COLORIZE_AUTO; bool login_shell = false; + bool maximized = false; + bool fullscreen = false; while (true) { int c = getopt_long(argc, argv, ":t:s:l::hv", longopts, NULL); @@ -75,6 +81,16 @@ main(int argc, char *const *argv) login_shell = true; break; + case ',': + maximized = true; + fullscreen = false; + break; + + case 'F': + fullscreen = true; + maximized = false; + break; + case 's': server_socket_path = optarg; break; @@ -177,6 +193,8 @@ main(int argc, char *const *argv) /* Calculate total length */ total_len += sizeof(cwd_len) + cwd_len; total_len += sizeof(term_len) + term_len; + total_len += sizeof(uint8_t); /* maximized */ + total_len += sizeof(uint8_t); /* fullscreen */ total_len += sizeof(uint8_t); /* login_shell */ total_len += sizeof(argc); @@ -207,6 +225,16 @@ main(int argc, char *const *argv) goto err; } + if (send(fd, &(uint8_t){maximized}, sizeof(uint8_t), 0) != sizeof(uint8_t)) { + LOG_ERRNO("failed to send maximized"); + goto err; + } + + if (send(fd, &(uint8_t){fullscreen}, sizeof(uint8_t), 0) != sizeof(uint8_t)) { + LOG_ERRNO("failed to send fullscreen"); + goto err; + } + if (send(fd, &(uint8_t){login_shell}, sizeof(uint8_t), 0) != sizeof(uint8_t)) { LOG_ERRNO("failed to send login-shell"); goto err; diff --git a/completions/zsh/_footclient b/completions/zsh/_footclient index 75a99b95..7f8c8009 100644 --- a/completions/zsh/_footclient +++ b/completions/zsh/_footclient @@ -3,6 +3,8 @@ _arguments \ -s \ '(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \ + '--maximized[start in maximized mode]' \ + '--fullscreen[start in fullscreen mode]' \ '--login-shell[start shell as a login shell]' \ '(-s --server-socket)'{-s,--server-socket}'[override the default path to the foot server socket (XDG_RUNTIME_DIR/foot.sock)]:server:_files' \ '(-l --log-colorize)'{-l,--log-colorize}'[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \ diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd index d6115906..a4de1089 100644 --- a/doc/footclient.1.scd +++ b/doc/footclient.1.scd @@ -15,6 +15,14 @@ execute (instead of the shell). *-t*,*--term*=_TERM_ Value to set the environment variable _TERM_ to. Default: _foot_. +*--maximized* + Start in maximized mode. If both *--maximized* and *--fullscreen* + are specified, the _last_ one takes precedence. + +*--fullscreen* + Start in fullscreen mode. If both *--maximized* and *--fullscreen* + are specified, the _last_ one takes precedence. + *--login-shell* Start a login shell, by prepending a '-' to argv[0]. diff --git a/main.c b/main.c index bf73c199..0d8dc139 100644 --- a/main.c +++ b/main.c @@ -360,8 +360,7 @@ main(int argc, char *const *argv) goto out; if (!as_server && (term = term_init( - &conf, fdm, wayl, conf.term, conf.login_shell, - "foot", cwd, argc, argv, + &conf, fdm, wayl, "foot", cwd, argc, argv, &term_shutdown_cb, &shutdown_ctx)) == NULL) { free(cwd); goto out; diff --git a/server.c b/server.c index 710e7e9d..42116f27 100644 --- a/server.c +++ b/server.c @@ -42,6 +42,7 @@ struct client { size_t idx; } buffer; + struct config conf; struct terminal *term; }; @@ -69,6 +70,11 @@ client_destroy(struct client *client) } free(client->buffer.data); + + /* TODO: clone server conf completely, so that we can just call + * conf_destroy() here */ + free(client->conf.term); + free(client); } @@ -218,6 +224,12 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) goto shutdown; } + CHECK_BUF(sizeof(uint8_t)); + const uint8_t maximized = *(const uint8_t *)p; p += sizeof(maximized); + + CHECK_BUF(sizeof(uint8_t)); + const uint8_t fullscreen = *(const uint8_t *)p; p += sizeof(fullscreen); + CHECK_BUF(sizeof(uint8_t)); const uint8_t login_shell = *(const uint8_t *)p; p += sizeof(login_shell); @@ -244,9 +256,18 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) #undef CHECK_BUF + client->conf = *server->conf; + client->conf.term = strlen(term_env) > 0 + ? strdup(term_env) : strdup(server->conf->term); + client->conf.login_shell = login_shell; + + if (maximized) + client->conf.startup_mode = STARTUP_MAXIMIZED; + else if (fullscreen) + client->conf.startup_mode = STARTUP_FULLSCREEN; + client->term = term_init( - server->conf, server->fdm, server->wayl, - strlen(term_env) > 0 ? term_env : server->conf->term, login_shell, + &client->conf, server->fdm, server->wayl, "footclient", cwd, argc, argv, &term_shutdown_handler, client); if (client->term == NULL) { diff --git a/terminal.c b/terminal.c index 41b0ccd9..73c5d943 100644 --- a/terminal.c +++ b/terminal.c @@ -616,8 +616,7 @@ load_fonts_from_conf(const struct terminal *term, const struct config *conf, struct terminal * term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, - const char *term_env, bool login_shell, const char *foot_exe, - const char *cwd, int argc, char *const *argv, + const char *foot_exe, const char *cwd, int argc, char *const *argv, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data) { int ptmx = -1; @@ -815,8 +814,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl, } /* Start the slave/client */ - if ((term->slave = slave_spawn(term->ptmx, argc, term->cwd, argv, term_env, conf->shell, login_shell)) == -1) + if ((term->slave = slave_spawn( + term->ptmx, argc, term->cwd, argv, + conf->term, conf->shell, conf->login_shell)) == -1) + { goto err; + } return term; diff --git a/terminal.h b/terminal.h index 3685c0d7..d7d4d705 100644 --- a/terminal.h +++ b/terminal.h @@ -430,8 +430,7 @@ struct terminal { struct config; struct terminal *term_init( const struct config *conf, struct fdm *fdm, struct wayland *wayl, - const char *term_env, bool login_shell, const char *foot_exe, - const char *cwd, int argc, char *const *argv, + const char *foot_exe, const char *cwd, int argc, char *const *argv, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data); bool term_shutdown(struct terminal *term);