mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-13 08:21:03 -04:00
conf: add app-id config option and --app-id command line option
This commit is contained in:
parent
371dd65949
commit
4d52a870b4
12 changed files with 84 additions and 15 deletions
|
|
@ -15,6 +15,10 @@
|
||||||
* **initial-window-mode** option to `footrc`, that lets you control
|
* **initial-window-mode** option to `footrc`, that lets you control
|
||||||
the initial mode for each newly spawned window: _windowed_,
|
the initial mode for each newly spawned window: _windowed_,
|
||||||
_maximized_ or _fullscreen_.
|
_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
|
### Changed
|
||||||
|
|
|
||||||
35
client.c
35
client.c
|
|
@ -33,6 +33,7 @@ print_usage(const char *prog_name)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\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"
|
" --maximized start in maximized mode\n"
|
||||||
" --fullscreen start in fullscreen mode\n"
|
" --fullscreen start in fullscreen mode\n"
|
||||||
" --login-shell start shell as a login shell\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];
|
const char *const prog_name = argv[0];
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{"term", required_argument, 0, 't'},
|
{"term", required_argument, NULL, 't'},
|
||||||
{"maximized", no_argument, 0, 'm'},
|
{"app-id", required_argument, NULL, 'a'},
|
||||||
{"fullscreen", no_argument, 0, 'F'},
|
{"maximized", no_argument, NULL, 'm'},
|
||||||
{"login-shell", no_argument, 0, 'L'},
|
{"fullscreen", no_argument, NULL, 'F'},
|
||||||
{"server-socket", required_argument, 0, 's'},
|
{"login-shell", no_argument, NULL, 'L'},
|
||||||
|
{"server-socket", required_argument, NULL, 's'},
|
||||||
{"log-colorize", optional_argument, NULL, 'l'},
|
{"log-colorize", optional_argument, NULL, 'l'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{NULL, no_argument, 0, 0},
|
{NULL, no_argument, NULL, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *term = "";
|
const char *term = "";
|
||||||
|
const char *app_id = "";
|
||||||
const char *server_socket_path = NULL;
|
const char *server_socket_path = NULL;
|
||||||
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
|
enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
|
||||||
bool login_shell = false;
|
bool login_shell = false;
|
||||||
|
|
@ -68,7 +71,7 @@ main(int argc, char *const *argv)
|
||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
|
|
||||||
while (true) {
|
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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -77,6 +80,10 @@ main(int argc, char *const *argv)
|
||||||
term = optarg;
|
term = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
app_id = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'L':
|
case 'L':
|
||||||
login_shell = true;
|
login_shell = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -186,13 +193,14 @@ main(int argc, char *const *argv)
|
||||||
} while (errno == ERANGE);
|
} while (errno == ERANGE);
|
||||||
}
|
}
|
||||||
const uint16_t cwd_len = strlen(cwd) + 1;
|
const uint16_t cwd_len = strlen(cwd) + 1;
|
||||||
|
|
||||||
const uint16_t term_len = strlen(term) + 1;
|
const uint16_t term_len = strlen(term) + 1;
|
||||||
|
const uint16_t app_id_len = strlen(app_id) + 1;
|
||||||
uint32_t total_len = 0;
|
uint32_t total_len = 0;
|
||||||
|
|
||||||
/* Calculate total length */
|
/* Calculate total length */
|
||||||
total_len += sizeof(cwd_len) + cwd_len;
|
total_len += sizeof(cwd_len) + cwd_len;
|
||||||
total_len += sizeof(term_len) + term_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); /* maximized */
|
||||||
total_len += sizeof(uint8_t); /* fullscreen */
|
total_len += sizeof(uint8_t); /* fullscreen */
|
||||||
total_len += sizeof(uint8_t); /* login_shell */
|
total_len += sizeof(uint8_t); /* login_shell */
|
||||||
|
|
@ -225,6 +233,13 @@ main(int argc, char *const *argv)
|
||||||
goto err;
|
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)) {
|
if (send(fd, &(uint8_t){maximized}, sizeof(uint8_t), 0) != sizeof(uint8_t)) {
|
||||||
LOG_ERRNO("failed to send maximized");
|
LOG_ERRNO("failed to send maximized");
|
||||||
goto err;
|
goto err;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ _arguments \
|
||||||
'(-c --config)'{-c,--config}'[path to configuration file (XDG_CONFIG_HOME/footrc)]:config:_files' \
|
'(-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' \
|
'(-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' \
|
'(-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]' \
|
'--maximized[start in maximized mode]' \
|
||||||
'--fullscreen[start in fullscreen mode]' \
|
'--fullscreen[start in fullscreen mode]' \
|
||||||
'--login-shell[start shell as a login shell]' \
|
'--login-shell[start shell as a login shell]' \
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
_arguments \
|
_arguments \
|
||||||
-s \
|
-s \
|
||||||
'(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
|
'(-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]' \
|
'--maximized[start in maximized mode]' \
|
||||||
'--fullscreen[start in fullscreen mode]' \
|
'--fullscreen[start in fullscreen mode]' \
|
||||||
'--login-shell[start shell as a login shell]' \
|
'--login-shell[start shell as a login shell]' \
|
||||||
|
|
|
||||||
7
config.c
7
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);
|
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) {
|
else if (strcmp(key, "geometry") == 0) {
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
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) {
|
*conf = (struct config) {
|
||||||
.term = strdup("foot"),
|
.term = strdup("foot"),
|
||||||
.shell = get_shell(),
|
.shell = get_shell(),
|
||||||
|
.app_id = strdup("foot"),
|
||||||
.width = 700,
|
.width = 700,
|
||||||
.height = 500,
|
.height = 500,
|
||||||
.pad_x = 2,
|
.pad_x = 2,
|
||||||
|
|
@ -960,6 +966,7 @@ config_free(struct config conf)
|
||||||
{
|
{
|
||||||
free(conf.term);
|
free(conf.term);
|
||||||
free(conf.shell);
|
free(conf.shell);
|
||||||
|
free(conf.app_id);
|
||||||
tll_free_and_free(conf.fonts, free);
|
tll_free_and_free(conf.fonts, free);
|
||||||
free(conf.server_socket_path);
|
free(conf.server_socket_path);
|
||||||
|
|
||||||
|
|
|
||||||
1
config.h
1
config.h
|
|
@ -10,6 +10,7 @@
|
||||||
struct config {
|
struct config {
|
||||||
char *term;
|
char *term;
|
||||||
char *shell;
|
char *shell;
|
||||||
|
char *app_id;
|
||||||
bool login_shell;
|
bool login_shell;
|
||||||
unsigned width;
|
unsigned width;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,11 @@ execute (instead of the shell).
|
||||||
Set initial window width and height. Default: *700x500*.
|
Set initial window width and height. Default: *700x500*.
|
||||||
|
|
||||||
*-t*,*--term*=_TERM_
|
*-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*
|
*--maximized*
|
||||||
Start in maximized mode. If both *--maximized* and *--fullscreen*
|
Start in maximized mode. If both *--maximized* and *--fullscreen*
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,11 @@ in this order:
|
||||||
*term*
|
*term*
|
||||||
Value to set the environment variable *TERM* to. Default: _foot_.
|
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*
|
*scrollback*
|
||||||
Number of scrollback lines. Default: _1000_.
|
Number of scrollback lines. Default: _1000_.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,11 @@ execute (instead of the shell).
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
*-t*,*--term*=_TERM_
|
*-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*
|
*--maximized*
|
||||||
Start in maximized mode. If both *--maximized* and *--fullscreen*
|
Start in maximized mode. If both *--maximized* and *--fullscreen*
|
||||||
|
|
|
||||||
13
main.c
13
main.c
|
|
@ -46,6 +46,7 @@ print_usage(const char *prog_name)
|
||||||
" -c,--config=PATH load configuration from PATH (XDG_CONFIG_HOME/footrc)\n"
|
" -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"
|
" -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"
|
" -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"
|
" --maximized start in maximized mode\n"
|
||||||
" --fullscreen start in fullscreen mode\n"
|
" --fullscreen start in fullscreen mode\n"
|
||||||
" --login-shell start shell as a login shell\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[] = {
|
static const struct option longopts[] = {
|
||||||
{"config", required_argument, NULL, 'c'},
|
{"config", required_argument, NULL, 'c'},
|
||||||
{"term", required_argument, NULL, 't'},
|
{"term", required_argument, NULL, 't'},
|
||||||
|
{"app-id", required_argument, NULL, 'a'},
|
||||||
{"login-shell", no_argument, NULL, 'L'},
|
{"login-shell", no_argument, NULL, 'L'},
|
||||||
{"font", required_argument, NULL, 'f'},
|
{"font", required_argument, NULL, 'f'},
|
||||||
{"geometry", required_argument, NULL, 'g'},
|
{"geometry", required_argument, NULL, 'g'},
|
||||||
|
|
@ -157,6 +159,7 @@ main(int argc, char *const *argv)
|
||||||
|
|
||||||
const char *conf_path = NULL;
|
const char *conf_path = NULL;
|
||||||
const char *conf_term = NULL;
|
const char *conf_term = NULL;
|
||||||
|
const char *conf_app_id = NULL;
|
||||||
bool login_shell = false;
|
bool login_shell = false;
|
||||||
tll(char *) conf_fonts = tll_init();
|
tll(char *) conf_fonts = tll_init();
|
||||||
int conf_width = -1;
|
int conf_width = -1;
|
||||||
|
|
@ -173,7 +176,7 @@ main(int argc, char *const *argv)
|
||||||
bool log_syslog = true;
|
bool log_syslog = true;
|
||||||
|
|
||||||
while (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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -190,6 +193,10 @@ main(int argc, char *const *argv)
|
||||||
login_shell = true;
|
login_shell = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
conf_app_id = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
tll_free_and_free(conf_fonts, free);
|
tll_free_and_free(conf_fonts, free);
|
||||||
for (char *font = strtok(optarg, ","); font != NULL; font = strtok(NULL, ",")) {
|
for (char *font = strtok(optarg, ","); font != NULL; font = strtok(NULL, ",")) {
|
||||||
|
|
@ -306,6 +313,10 @@ main(int argc, char *const *argv)
|
||||||
free(conf.term);
|
free(conf.term);
|
||||||
conf.term = strdup(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)
|
if (login_shell)
|
||||||
conf.login_shell = true;
|
conf.login_shell = true;
|
||||||
if (tll_length(conf_fonts) > 0) {
|
if (tll_length(conf_fonts) > 0) {
|
||||||
|
|
|
||||||
16
server.c
16
server.c
|
|
@ -74,6 +74,7 @@ client_destroy(struct client *client)
|
||||||
/* TODO: clone server conf completely, so that we can just call
|
/* TODO: clone server conf completely, so that we can just call
|
||||||
* conf_destroy() here */
|
* conf_destroy() here */
|
||||||
free(client->conf.term);
|
free(client->conf.term);
|
||||||
|
free(client->conf.app_id);
|
||||||
|
|
||||||
free(client);
|
free(client);
|
||||||
}
|
}
|
||||||
|
|
@ -224,6 +225,19 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
|
||||||
goto shutdown;
|
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));
|
CHECK_BUF(sizeof(uint8_t));
|
||||||
const uint8_t maximized = *(const uint8_t *)p; p += sizeof(maximized);
|
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 = *server->conf;
|
||||||
client->conf.term = strlen(term_env) > 0
|
client->conf.term = strlen(term_env) > 0
|
||||||
? strdup(term_env) : strdup(server->conf->term);
|
? 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;
|
client->conf.login_shell = login_shell;
|
||||||
|
|
||||||
if (maximized)
|
if (maximized)
|
||||||
|
|
|
||||||
|
|
@ -993,7 +993,7 @@ struct wl_window *
|
||||||
wayl_win_init(struct terminal *term)
|
wayl_win_init(struct terminal *term)
|
||||||
{
|
{
|
||||||
struct wayland *wayl = term->wl;
|
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));
|
struct wl_window *win = calloc(1, sizeof(*win));
|
||||||
win->term = term;
|
win->term = term;
|
||||||
|
|
@ -1025,7 +1025,7 @@ wayl_win_init(struct terminal *term)
|
||||||
win->xdg_toplevel = xdg_surface_get_toplevel(win->xdg_surface);
|
win->xdg_toplevel = xdg_surface_get_toplevel(win->xdg_surface);
|
||||||
xdg_toplevel_add_listener(win->xdg_toplevel, &xdg_toplevel_listener, win);
|
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 */
|
/* Request server-side decorations */
|
||||||
if (wayl->xdg_decoration_manager != NULL) {
|
if (wayl->xdg_decoration_manager != NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue