client: add --maximized and --fullscreen

We now create a copy of the config for each client, and updates it
with the values passed from the client.

Since we're not actually cloning it (and e.g. strdup() all strings
etc) we can't call conf_destroy() to free it, but need to free just
the strings we've replaced.
This commit is contained in:
Daniel Eklöf 2020-03-27 21:14:49 +01:00
parent 728e23863c
commit 758fd9fd58
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 69 additions and 9 deletions

View file

@ -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;

View file

@ -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)' \

View file

@ -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].

3
main.c
View file

@ -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;

View file

@ -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) {

View file

@ -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;

View file

@ -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);