aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-04-01 16:40:51 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-04-01 16:40:51 +0000
commit4d52a870b493c17172766db3d0a76cd8f0c3204c (patch)
treee0109cf0143deee112f3c8cf5c6a27c649b508f1
parentdoc: foot.5: minor updates to 'tweaks' (diff)
conf: add app-id config option and --app-id command line option
-rw-r--r--CHANGELOG.md4
-rw-r--r--client.c35
-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.scd6
-rw-r--r--doc/foot.5.scd5
-rw-r--r--doc/footclient.1.scd6
-rw-r--r--main.c13
-rw-r--r--server.c16
-rw-r--r--wayland.c4
12 files changed, 84 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be5bb8f0..a655cd2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,10 @@
* **initial-window-mode** option to `footrc`, that lets you control
the initial mode for each newly spawned window: _windowed_,
_maximized_ or _fullscreen_.
+* **app-id** option to `footrc`, that sets the _app-id_ property on
+ the Wayland window.
+* `--app-id` command line option, that sets the _app-id_ property on
+ the Wayland window.
### Changed
diff --git a/client.c b/client.c
index 7d188609..a7ba7e30 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"
+ " -a,--app-id=ID window application ID (foot)\n"
" --maximized start in maximized mode\n"
" --fullscreen start in fullscreen mode\n"
" --login-shell start shell as a login shell\n"
@@ -49,18 +50,20 @@ main(int argc, char *const *argv)
const char *const prog_name = argv[0];
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'},
+ {"term", required_argument, NULL, 't'},
+ {"app-id", required_argument, NULL, 'a'},
+ {"maximized", no_argument, NULL, 'm'},
+ {"fullscreen", no_argument, NULL, 'F'},
+ {"login-shell", no_argument, NULL, 'L'},
+ {"server-socket", required_argument, NULL, 's'},
{"log-colorize", optional_argument, NULL, 'l'},
- {"version", no_argument, 0, 'v'},
- {"help", no_argument, 0, 'h'},
- {NULL, no_argument, 0, 0},
+ {"version", no_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, no_argument, NULL, 0},
};
const char *term = "";
+ const char *app_id = "";
const char *server_socket_path = NULL;
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
bool login_shell = false;
@@ -68,7 +71,7 @@ main(int argc, char *const *argv)
bool fullscreen = false;
while (true) {
- int c = getopt_long(argc, argv, ":t:s:l::hv", longopts, NULL);
+ int c = getopt_long(argc, argv, ":t:a:s:l::hv", longopts, NULL);
if (c == -1)
break;
@@ -77,6 +80,10 @@ main(int argc, char *const *argv)
term = optarg;
break;
+ case 'a':
+ app_id = optarg;
+ break;
+
case 'L':
login_shell = true;
break;
@@ -186,13 +193,14 @@ main(int argc, char *const *argv)
} while (errno == ERANGE);
}
const uint16_t cwd_len = strlen(cwd) + 1;
-
const uint16_t term_len = strlen(term) + 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(app_id_len) + app_id_len;
total_len += sizeof(uint8_t); /* maximized */
total_len += sizeof(uint8_t); /* fullscreen */
total_len += sizeof(uint8_t); /* login_shell */
@@ -225,6 +233,13 @@ main(int argc, char *const *argv)
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)
+ {
+ LOG_ERRNO("failed to send app-id to server");
+ goto err;
+ }
+
if (send(fd, &(uint8_t){maximized}, sizeof(uint8_t), 0) != sizeof(uint8_t)) {
LOG_ERRNO("failed to send maximized");
goto err;
diff --git a/completions/zsh/_foot b/completions/zsh/_foot
index 95e8d98e..8fcd21a4 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' \
+ '(-a --app-id)'{-a,-app-id}'[value to set the window\'s app-id to (foot)]' \
'--maximized[start in maximized mode]' \
'--fullscreen[start in fullscreen mode]' \
'--login-shell[start shell as a login shell]' \
diff --git a/completions/zsh/_footclient b/completions/zsh/_footclient
index 7f8c8009..d7d26db0 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' \
+ '(-a --app-id)'{-a,-app-id}'[value to set the window\'s app-id to (foot)]' \
'--maximized[start in maximized mode]' \
'--fullscreen[start in fullscreen mode]' \
'--login-shell[start shell as a login shell]' \
diff --git a/config.c b/config.c
index b33f5818..d73e8ec1 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, "app-id") == 0) {
+ free(conf->app_id);
+ conf->app_id = strdup(value);
+ }
+
else if (strcmp(key, "geometry") == 0) {
unsigned width, height;
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
@@ -827,6 +832,7 @@ config_load(struct config *conf, const char *conf_path)
*conf = (struct config) {
.term = strdup("foot"),
.shell = get_shell(),
+ .app_id = strdup("foot"),
.width = 700,
.height = 500,
.pad_x = 2,
@@ -960,6 +966,7 @@ config_free(struct config conf)
{
free(conf.term);
free(conf.shell);
+ 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 32e381eb..355468fc 100644
--- a/config.h
+++ b/config.h
@@ -10,6 +10,7 @@
struct config {
char *term;
char *shell;
+ char *app_id;
bool login_shell;
unsigned width;
unsigned height;
diff --git a/doc/foot.1.scd b/doc/foot.1.scd
index ccc0bd3c..7207d1c7 100644
--- a/doc/foot.1.scd
+++ b/doc/foot.1.scd
@@ -34,7 +34,11 @@ execute (instead of the shell).
Set initial window width and height. Default: *700x500*.
*-t*,*--term*=_TERM_
- Value to set the environment variable *TERM* to. Default: *foot*.
+ Value to set the environment variable *TERM* to. Default: _foot_.
+
+*-a*,*--app-id*=_ID_
+ Value to set the *app-id* property on the Wayland window
+ to. Default: _foot_.
*--maximized*
Start in maximized mode. If both *--maximized* and *--fullscreen*
diff --git a/doc/foot.5.scd b/doc/foot.5.scd
index b354a291..9a977da7 100644
--- a/doc/foot.5.scd
+++ b/doc/foot.5.scd
@@ -56,6 +56,11 @@ in this order:
*term*
Value to set the environment variable *TERM* to. 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
+ apply window management rules. Default: _foot_.
+
*scrollback*
Number of scrollback lines. Default: _1000_.
diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd
index a4de1089..c7b07466 100644
--- a/doc/footclient.1.scd
+++ b/doc/footclient.1.scd
@@ -13,7 +13,11 @@ execute (instead of the shell).
# OPTIONS
*-t*,*--term*=_TERM_
- Value to set the environment variable _TERM_ to. Default: _foot_.
+ Value to set the environment variable *TERM* to. Default: _foot_.
+
+*-a*,*--app-id*=_ID_
+ Value to set the *app-id* property on the Wayland window
+ to. Default: _foot_.
*--maximized*
Start in maximized mode. If both *--maximized* and *--fullscreen*
diff --git a/main.c b/main.c
index 06497cbe..add743d1 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"
+ " -a,--app-id=ID window application ID (foot)\n"
" --maximized start in maximized mode\n"
" --fullscreen start in fullscreen mode\n"
" --login-shell start shell as a login shell\n"
@@ -139,6 +140,7 @@ main(int argc, char *const *argv)
static const struct option longopts[] = {
{"config", required_argument, NULL, 'c'},
{"term", required_argument, NULL, 't'},
+ {"app-id", required_argument, NULL, 'a'},
{"login-shell", no_argument, NULL, 'L'},
{"font", required_argument, NULL, 'f'},
{"geometry", required_argument, NULL, 'g'},
@@ -157,6 +159,7 @@ main(int argc, char *const *argv)
const char *conf_path = NULL;
const char *conf_term = NULL;
+ const char *conf_app_id = NULL;
bool login_shell = false;
tll(char *) conf_fonts = tll_init();
int conf_width = -1;
@@ -173,7 +176,7 @@ main(int argc, char *const *argv)
bool log_syslog = true;
while (true) {
- int c = getopt_long(argc, argv, "c:t:Lf:g:s::Pp:l::Svh", longopts, NULL);
+ int c = getopt_long(argc, argv, "c:t:a:Lf:g:s::Pp:l::Svh", longopts, NULL);
if (c == -1)
break;
@@ -190,6 +193,10 @@ main(int argc, char *const *argv)
login_shell = true;
break;
+ case 'a':
+ conf_app_id = optarg;
+ break;
+
case 'f':
tll_free_and_free(conf_fonts, free);
for (char *font = strtok(optarg, ","); font != NULL; font = strtok(NULL, ",")) {
@@ -306,6 +313,10 @@ main(int argc, char *const *argv)
free(conf.term);
conf.term = strdup(conf_term);
}
+ if (conf_app_id != NULL) {
+ free(conf.app_id);
+ conf.app_id = strdup(conf_app_id);
+ }
if (login_shell)
conf.login_shell = true;
if (tll_length(conf_fonts) > 0) {
diff --git a/server.c b/server.c
index 42116f27..37c17477 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.app_id);
free(client);
}
@@ -224,6 +225,19 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
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);
+ const char *app_id = (const char *)p; p += app_id_len;
+ LOG_DBG("app-id = %.*s", app_id_len, app_id);
+
+ if (app_id_len != strlen(app_id) + 1) {
+ LOG_ERR("app-id length mismatch: indicated = %hu, actual = %zu",
+ app_id_len - 1, strlen(app_id));
+ goto shutdown;
+ }
+
CHECK_BUF(sizeof(uint8_t));
const uint8_t maximized = *(const uint8_t *)p; p += sizeof(maximized);
@@ -259,6 +273,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.app_id = strlen(app_id) > 0
+ ? strdup(app_id) : strdup(server->conf->app_id);
client->conf.login_shell = login_shell;
if (maximized)
diff --git a/wayland.c b/wayland.c
index 4a553cc6..06c02313 100644
--- a/wayland.c
+++ b/wayland.c
@@ -993,7 +993,7 @@ struct wl_window *
wayl_win_init(struct terminal *term)
{
struct wayland *wayl = term->wl;
- const struct config *conf = wayl->conf;
+ const struct config *conf = term->conf;
struct wl_window *win = calloc(1, sizeof(*win));
win->term = term;
@@ -1025,7 +1025,7 @@ wayl_win_init(struct terminal *term)
win->xdg_toplevel = xdg_surface_get_toplevel(win->xdg_surface);
xdg_toplevel_add_listener(win->xdg_toplevel, &xdg_toplevel_listener, win);
- xdg_toplevel_set_app_id(win->xdg_toplevel, "foot");
+ xdg_toplevel_set_app_id(win->xdg_toplevel, conf->app_id);
/* Request server-side decorations */
if (wayl->xdg_decoration_manager != NULL) {