mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05: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
|
||||
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
|
||||
|
|
|
|||
35
client.c
35
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;
|
||||
|
|
|
|||
|
|
@ -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]' \
|
||||
|
|
|
|||
|
|
@ -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]' \
|
||||
|
|
|
|||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
|||
1
config.h
1
config.h
|
|
@ -10,6 +10,7 @@
|
|||
struct config {
|
||||
char *term;
|
||||
char *shell;
|
||||
char *app_id;
|
||||
bool login_shell;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
|
|
|||
|
|
@ -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*
|
||||
|
|
|
|||
|
|
@ -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_.
|
||||
|
||||
|
|
|
|||
|
|
@ -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*
|
||||
|
|
|
|||
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"
|
||||
" -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) {
|
||||
|
|
|
|||
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
|
||||
* 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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue