aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-04-01 17:59:47 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-04-01 17:59:47 +0000
commitec7a7684876c06764a583a1cefe2a93f6706e3ca (patch)
treea56aacfe68b35eadbf4025a5c366b36585fe7d82
parentcompletions: zsh: repair -a,--app-id completions (diff)
conf: add 'title' conf option and --title command line option
-rw-r--r--CHANGELOG.md3
-rw-r--r--client.c16
-rw-r--r--completions/zsh/_foot1
-rw-r--r--completions/zsh/_footclient1
-rw-r--r--config.c7
-rw-r--r--config.h1
-rw-r--r--doc/foot.1.scd3
-rw-r--r--doc/foot.5.scd3
-rw-r--r--doc/footclient.1.scd3
-rw-r--r--main.c11
-rw-r--r--server.c16
-rw-r--r--terminal.c2
12 files changed, 65 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a655cd2f..bea0660f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,8 @@
the Wayland window.
* `--app-id` command line option, that sets the _app-id_ property on
the Wayland window.
-
+* **title** option to `footrc`, that sets the initial window title.
+* `--title` command line option, that sets the initial window title.
### Changed
diff --git a/client.c b/client.c
index a7ba7e30..754f349b 100644
--- a/client.c
+++ b/client.c
@@ -33,6 +33,7 @@ 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"
+ " --title=TITLE initial window title (foot)\n"
" -a,--app-id=ID window application ID (foot)\n"
" --maximized start in maximized mode\n"
" --fullscreen start in fullscreen mode\n"
@@ -51,6 +52,7 @@ main(int argc, char *const *argv)
static const struct option longopts[] = {
{"term", required_argument, NULL, 't'},
+ {"title", required_argument, NULL, 'T'},
{"app-id", required_argument, NULL, 'a'},
{"maximized", no_argument, NULL, 'm'},
{"fullscreen", no_argument, NULL, 'F'},
@@ -63,6 +65,7 @@ main(int argc, char *const *argv)
};
const char *term = "";
+ const char *title = "";
const char *app_id = "";
const char *server_socket_path = NULL;
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
@@ -80,6 +83,10 @@ main(int argc, char *const *argv)
term = optarg;
break;
+ case 'T':
+ title = optarg;
+ break;
+
case 'a':
app_id = optarg;
break;
@@ -194,12 +201,14 @@ main(int argc, char *const *argv)
}
const uint16_t cwd_len = strlen(cwd) + 1;
const uint16_t term_len = strlen(term) + 1;
+ const uint16_t title_len = strlen(title) + 1;
const uint16_t app_id_len = strlen(app_id) + 1;
uint32_t total_len = 0;
/* Calculate total length */
total_len += sizeof(cwd_len) + cwd_len;
total_len += sizeof(term_len) + term_len;
+ total_len += sizeof(title_len) + title_len;
total_len += sizeof(app_id_len) + app_id_len;
total_len += sizeof(uint8_t); /* maximized */
total_len += sizeof(uint8_t); /* fullscreen */
@@ -233,6 +242,13 @@ main(int argc, char *const *argv)
goto err;
}
+ if (send(fd, &title_len, sizeof(title_len), 0) != sizeof(title_len) ||
+ send(fd, title, title_len, 0) != title_len)
+ {
+ LOG_ERRNO("failed to send title to server");
+ goto err;
+ }
+
if (send(fd, &app_id_len, sizeof(app_id_len), 0) != sizeof(app_id_len) ||
send(fd, app_id, app_id_len, 0) != app_id_len)
{
diff --git a/completions/zsh/_foot b/completions/zsh/_foot
index 86b83f37..1189aaa5 100644
--- a/completions/zsh/_foot
+++ b/completions/zsh/_foot
@@ -5,6 +5,7 @@ _arguments \
'(-c --config)'{-c,--config}'[path to configuration file (XDG_CONFIG_HOME/footrc)]:config:_files' \
'(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \
'(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
+ '--title[initial window title]:()' \
'(-a --app-id)'{-a,--app-id}'[value to set the app-id property on the Wayland window to (foot)]:()' \
'--maximized[start in maximized mode]' \
'--fullscreen[start in fullscreen mode]' \
diff --git a/completions/zsh/_footclient b/completions/zsh/_footclient
index a5865ce5..9da39a30 100644
--- a/completions/zsh/_footclient
+++ b/completions/zsh/_footclient
@@ -3,6 +3,7 @@
_arguments \
-s \
'(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
+ '--title[initial window title]:()' \
'(-a --app-id)'{-a,--app-id}'[value to set the app-id property on the Wayland window to (foot)]:()' \
'--maximized[start in maximized mode]' \
'--fullscreen[start in fullscreen mode]' \
diff --git a/config.c b/config.c
index d73e8ec1..a97b8a38 100644
--- a/config.c
+++ b/config.c
@@ -209,6 +209,11 @@ parse_section_main(const char *key, const char *value, struct config *conf,
conf->login_shell = str_to_bool(value);
}
+ else if (strcmp(key, "title") == 0) {
+ free(conf->title);
+ conf->title = strdup(value);
+ }
+
else if (strcmp(key, "app-id") == 0) {
free(conf->app_id);
conf->app_id = strdup(value);
@@ -832,6 +837,7 @@ config_load(struct config *conf, const char *conf_path)
*conf = (struct config) {
.term = strdup("foot"),
.shell = get_shell(),
+ .title = strdup("foot"),
.app_id = strdup("foot"),
.width = 700,
.height = 500,
@@ -966,6 +972,7 @@ config_free(struct config conf)
{
free(conf.term);
free(conf.shell);
+ free(conf.title);
free(conf.app_id);
tll_free_and_free(conf.fonts, free);
free(conf.server_socket_path);
diff --git a/config.h b/config.h
index 355468fc..969edea5 100644
--- a/config.h
+++ b/config.h
@@ -10,6 +10,7 @@
struct config {
char *term;
char *shell;
+ char *title;
char *app_id;
bool login_shell;
unsigned width;
diff --git a/doc/foot.1.scd b/doc/foot.1.scd
index 7207d1c7..84b27fd6 100644
--- a/doc/foot.1.scd
+++ b/doc/foot.1.scd
@@ -36,6 +36,9 @@ execute (instead of the shell).
*-t*,*--term*=_TERM_
Value to set the environment variable *TERM* to. Default: _foot_.
+*--title*=_TITLE:
+ Initial window title. Default: _foot_.
+
*-a*,*--app-id*=_ID_
Value to set the *app-id* property on the Wayland window
to. Default: _foot_.
diff --git a/doc/foot.5.scd b/doc/foot.5.scd
index 9a977da7..5088d2ce 100644
--- a/doc/foot.5.scd
+++ b/doc/foot.5.scd
@@ -56,6 +56,9 @@ in this order:
*term*
Value to set the environment variable *TERM* to. Default: _foot_.
+*title*
+ Initial window title. Default: _foot_.
+
*app-id*
Value to set the *app-id* property on the Wayland window to. The
compositor can use this value to e.g. group multiple windows, or
diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd
index c7b07466..25bb444c 100644
--- a/doc/footclient.1.scd
+++ b/doc/footclient.1.scd
@@ -15,6 +15,9 @@ execute (instead of the shell).
*-t*,*--term*=_TERM_
Value to set the environment variable *TERM* to. Default: _foot_.
+*--title*=_TITLE:
+ Initial window title. Default: _foot_.
+
*-a*,*--app-id*=_ID_
Value to set the *app-id* property on the Wayland window
to. Default: _foot_.
diff --git a/main.c b/main.c
index add743d1..39e90bbf 100644
--- a/main.c
+++ b/main.c
@@ -46,6 +46,7 @@ print_usage(const char *prog_name)
" -c,--config=PATH load configuration from PATH (XDG_CONFIG_HOME/footrc)\n"
" -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\n"
" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
+ " --title=TITLE initial window title (foot)\n"
" -a,--app-id=ID window application ID (foot)\n"
" --maximized start in maximized mode\n"
" --fullscreen start in fullscreen mode\n"
@@ -140,6 +141,7 @@ main(int argc, char *const *argv)
static const struct option longopts[] = {
{"config", required_argument, NULL, 'c'},
{"term", required_argument, NULL, 't'},
+ {"title", required_argument, NULL, 'T'},
{"app-id", required_argument, NULL, 'a'},
{"login-shell", no_argument, NULL, 'L'},
{"font", required_argument, NULL, 'f'},
@@ -159,6 +161,7 @@ main(int argc, char *const *argv)
const char *conf_path = NULL;
const char *conf_term = NULL;
+ const char *conf_title = NULL;
const char *conf_app_id = NULL;
bool login_shell = false;
tll(char *) conf_fonts = tll_init();
@@ -193,6 +196,10 @@ main(int argc, char *const *argv)
login_shell = true;
break;
+ case 'T':
+ conf_title = optarg;
+ break;
+
case 'a':
conf_app_id = optarg;
break;
@@ -313,6 +320,10 @@ main(int argc, char *const *argv)
free(conf.term);
conf.term = strdup(conf_term);
}
+ if (conf_title != NULL) {
+ free(conf.title);
+ conf.title = strdup(conf_title);
+ }
if (conf_app_id != NULL) {
free(conf.app_id);
conf.app_id = strdup(conf_app_id);
diff --git a/server.c b/server.c
index 37c17477..99c0e7ad 100644
--- a/server.c
+++ b/server.c
@@ -74,6 +74,7 @@ client_destroy(struct client *client)
/* TODO: clone server conf completely, so that we can just call
* conf_destroy() here */
free(client->conf.term);
+ free(client->conf.title);
free(client->conf.app_id);
free(client);
@@ -226,6 +227,19 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
}
CHECK_BUF(sizeof(uint16_t));
+ uint16_t title_len = *(uint16_t *)p; p += sizeof(title_len);
+
+ CHECK_BUF(title_len);
+ const char *title = (const char *)p; p += title_len;
+ LOG_DBG("app-id = %.*s", title_len, title);
+
+ if (title_len != strlen(title) + 1) {
+ LOG_ERR("title length mismatch: indicated = %hu, actual = %zu",
+ title_len - 1, strlen(title));
+ goto shutdown;
+ }
+
+ CHECK_BUF(sizeof(uint16_t));
uint16_t app_id_len = *(uint16_t *)p; p += sizeof(app_id_len);
CHECK_BUF(app_id_len);
@@ -273,6 +287,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
client->conf = *server->conf;
client->conf.term = strlen(term_env) > 0
? strdup(term_env) : strdup(server->conf->term);
+ client->conf.title = strlen(title) > 0
+ ? strdup(title) : strdup(server->conf->title);
client->conf.app_id = strlen(app_id) > 0
? strdup(app_id) : strdup(server->conf->app_id);
client->conf.login_shell = login_shell;
diff --git a/terminal.c b/terminal.c
index 14f1666a..c948c314 100644
--- a/terminal.c
+++ b/terminal.c
@@ -795,7 +795,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
if (!term_font_dpi_changed(term))
goto err;
- term_set_window_title(term, "foot");
+ term_set_window_title(term, conf->title);
/* Let the Wayland backend know we exist */
tll_push_back(wayl->terms, term);