From 8b2b65bbbc82c8d63cfa70bc055723ad9708027f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 13 Nov 2023 19:10:15 -0600 Subject: [PATCH 01/50] terminfo: add terminator to conditional in Sync I'm not sure if this is _strictly_ necessary, but according to the terminfo specification [1] a conditional string should be terminated with `%;`. [1]: https://man7.org/linux/man-pages/man5/terminfo.5.html --- foot.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foot.info b/foot.info index 4f95bf7b..89601996 100644 --- a/foot.info +++ b/foot.info @@ -40,7 +40,7 @@ RV=\E[>c, Se=\E[ q, Ss=\E[%p1%d q, - Sync=\E[?2026%?%p1%{1}%-%tl%eh, + Sync=\E[?2026%?%p1%{1}%-%tl%eh%;, TS=\E]2;, XM=\E[?1006;1004;1000%?%p1%{1}%=%th%el%;, XR=\E[>0q, From 242767d373d375a209e75b5a812116d7e1c9bfe0 Mon Sep 17 00:00:00 2001 From: eugenrh Date: Wed, 8 Nov 2023 17:43:44 +0000 Subject: [PATCH 02/50] theme: electrophoretic A theme for grayscale electrophoretic displays (e-ink), which aims to maximize the contrast between the text and the white background. --- themes/electrophoretic | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 themes/electrophoretic diff --git a/themes/electrophoretic b/themes/electrophoretic new file mode 100644 index 00000000..d2b67434 --- /dev/null +++ b/themes/electrophoretic @@ -0,0 +1,35 @@ +# -*- conf -*- +# Electrophoretic +# Theme for electrophoretic displays (like e-ink) which usually supports +# 16 levels of grays. This theme aims to maximize the contrast between the +# text and the white background. +# author: Eugen Rahaian + +[cursor] +color=ffffff 515151 + +[colors] +background= ffffff +foreground= 000000 + +# The colors are sorted based on their luminance, so we can more easily assign +# them a gray level. +# grayscale order: black_0 blue_4 red_1 magenta_5 green_2 cyan_6 yellow_3 white_7 +regular0= ffffff +regular4= 616161 +regular1= 515151 +regular5= 414141 +regular2= 313131 +regular6= 212121 +regular3= 111111 +regular7= 000000 +# Here, we also stay away from the white background by reusing the dark gray levels +# from above, with small variations +bright0= 818181 +bright4= 717171 +bright1= 616161 +bright5= 515151 +bright2= 414141 +bright6= 313131 +bright3= 212121 +bright7= 111111 From 3b3477d65786a743a2c2336dffb5935f3cb66334 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Wed, 6 Dec 2023 16:23:18 +0000 Subject: [PATCH 03/50] appstream: update releases list --- org.codeberg.dnkl.foot.metainfo.xml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/org.codeberg.dnkl.foot.metainfo.xml b/org.codeberg.dnkl.foot.metainfo.xml index 1c0b7985..dcb71afd 100644 --- a/org.codeberg.dnkl.foot.metainfo.xml +++ b/org.codeberg.dnkl.foot.metainfo.xml @@ -33,10 +33,16 @@ - - - - + + + + + + + + + + org.codeberg.dnkl.foot.desktop https://codeberg.org/dnkl/foot From 05e6fd969a22b16eeb807481c079228230fb8427 Mon Sep 17 00:00:00 2001 From: Sivecano Date: Fri, 29 Dec 2023 13:37:07 +0100 Subject: [PATCH 04/50] support numpad in unicode mode --- CHANGELOG.md | 3 +++ unicode-mode.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e561921c..2762d4d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,9 @@ ## Unreleased ### Added + +* Unicode input mode now accepts input from the numpad as well, numlock is ignored. + ### Changed * config: ARGB color values now default to opaque, rather than diff --git a/unicode-mode.c b/unicode-mode.c index a69601ec..6290de61 100644 --- a/unicode-mode.c +++ b/unicode-mode.c @@ -90,6 +90,8 @@ unicode_mode_input(struct seat *seat, struct terminal *term, /* 0-9, a-f, A-F */ if (sym >= XKB_KEY_0 && sym <= XKB_KEY_9) digit = sym - XKB_KEY_0; + else if (sym >= XKB_KEY_KP_0 && sym <= XKB_KEY_KP_9) + digit = sym - XKB_KEY_KP_0; else if (sym >= XKB_KEY_a && sym <= XKB_KEY_f) digit = 0xa + (sym - XKB_KEY_a); else if (sym >= XKB_KEY_A && sym <= XKB_KEY_F) From e5f5a74e811e76779ab97091c334d929d9efcfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 3 Jan 2024 13:31:35 +0100 Subject: [PATCH 05/50] changelog: formatting --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2762d4d8..a8f6e059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,7 +52,9 @@ ## Unreleased ### Added -* Unicode input mode now accepts input from the numpad as well, numlock is ignored. +* Unicode input mode now accepts input from the numpad as well, + numlock is ignored. + ### Changed From 14472cdbd953d5f6891f54098e5d706e45bb0c68 Mon Sep 17 00:00:00 2001 From: LmbMaxim Date: Tue, 12 Dec 2023 12:58:44 +0300 Subject: [PATCH 06/50] Add poimandres theme --- themes/poimandres | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 themes/poimandres diff --git a/themes/poimandres b/themes/poimandres new file mode 100644 index 00000000..d8a6b0a7 --- /dev/null +++ b/themes/poimandres @@ -0,0 +1,30 @@ +# Based on Poimandres color theme for kitti terminal emulator +# https://github.com/ubmit/poimandres-kitty + +[cursor] +color=1b1e28 ffffff + +[colors] +foreground=a6accd +background=1b1e28 + +regular0=1b1e28 +regular1=d0679d +regular2=5de4c7 +regular3=fffac2 +regular4=89ddff +regular5=fcc5e9 +regular6=add7ff +regular7=ffffff + +bright0=a6accd +bright1=d0679d +bright2=5de4c7 +bright3=fffac2 +bright4=add7ff +bright5=fae4fc +bright6=89ddff +bright7=ffffff + +selection-background=28344a +selection-foreground=a6accd From 66f25bb4346eab9b7914213343d22ee67c57724f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 3 Jan 2024 14:07:15 +0100 Subject: [PATCH 07/50] slave: chdir to / after spawning the client application With this patch, the terminal process now changes PWD to / after spawning the client application. This ensures the terminal process itself does not "lock" a directory. For example, we may keep a mount point from being unmounted. Closes #1528 --- CHANGELOG.md | 5 +++++ slave.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f6e059..f25814b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,8 +61,13 @@ * config: ARGB color values now default to opaque, rather than transparent, when the alpha component has been left out ([#1526][1526]). +* The `foot` process now changes CWD to `/` after spawning the shell + process. This ensures the terminal itself does not "lock" a + directory; for example, preventing a mount point from being + unmounted ([#1528][1528]). [1526]: https://codeberg.org/dnkl/foot/issues/1526 +[1528]: https://codeberg.org/dnkl/foot/issues/1528 ### Deprecated diff --git a/slave.c b/slave.c index ecfce7e6..1184d0c2 100644 --- a/slave.c +++ b/slave.c @@ -401,6 +401,14 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, break; default: { + + /* + * Don't stay in CWD, since it may be an ephemeral path. For + * example, it may be a mount point of, say, a thumb drive. Us + * keeping it open will prevent the user from unmounting it. + */ + chdir("/"); + close(fork_pipe[1]); /* Close write end */ LOG_DBG("slave has PID %d", pid); From 0ca46338986becfbbc24160083a9620e8f29a7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 5 Jan 2024 08:12:32 +0100 Subject: [PATCH 08/50] slave: ignore return value of chdir() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not critical. Fixes ../slave.c: In function ‘slave_spawn’: ../slave.c:410:9: error: ignoring return value of ‘chdir’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 410 | chdir("/"); | ^~~~~~~~~~ --- slave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slave.c b/slave.c index 1184d0c2..0cf64fa0 100644 --- a/slave.c +++ b/slave.c @@ -407,7 +407,7 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, * example, it may be a mount point of, say, a thumb drive. Us * keeping it open will prevent the user from unmounting it. */ - chdir("/"); + (void)!!chdir("/"); close(fork_pipe[1]); /* Close write end */ LOG_DBG("slave has PID %d", pid); From a2283c822971cc22db01a6702408aa69e0510448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 9 Jan 2024 16:47:41 +0100 Subject: [PATCH 09/50] wayland: surface_scale_explicit_width_height(): dont assert width/height are valid for scale, take 2 764248bb0d846f65c20931024c1f4adca57aae29 modified wayl_surface_scale_explicit_width_height() to not assert the surface size is valid for the given scaling factor. This, since that function is only used when scaling a mouse pointer surface. However, that commit only updated the code path run when fractional scaling is available (i.e. when the compositor implements the fractional-scale-v1 protocol). The legacy code path, that does integer scaling, was still asserting the surface width/height were divisible with the scaling factor. For the same reasons this isn't true with fractional scaling available, it's not true with integer scaling. Fix by skipping the assertions. This patch also converts the assertions to more verbose BUG() calls, that prints more information on the numbers involved. Closes #1573 --- CHANGELOG.md | 4 ++++ wayland.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f25814b8..6c4f998d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,8 +77,12 @@ * config: improved validation of color values. * config: double close of file descriptor, resulting in a chain of errors ultimately leading to a startup failure ([#1531][1531]). +* Crash when using a desktop scaling factor > 1, on compositors that + implements neither the `fractional-scale-v1`, nor the + `cursor-shape-v1` Wayland protocols ([#1573][1573]). [1531]: https://codeberg.org/dnkl/foot/issues/1531 +[1573]: https://codeberg.org/dnkl/foot/issues/1573 ### Security diff --git a/wayland.c b/wayland.c index a87bf45d..34050d18 100644 --- a/wayland.c +++ b/wayland.c @@ -2024,10 +2024,19 @@ surface_scale_explicit_width_height( "(width=%d, height=%d)", scale, width, height); xassert(scale == floorf(scale)); - const int iscale = (int)floorf(scale); - xassert(width % iscale == 0); - xassert(height % iscale == 0); + + if (verify) { + if (width % iscale != 0) { + BUG("width=%d is not valid with scaling factor %.2f (%d %% %d != 0)", + width, scale, width, iscale); + } + + if (height % iscale != 0) { + BUG("height=%d is not valid with scaling factor %.2f (%d %% %d != 0)", + height, scale, height, iscale); + } + } wl_surface_set_buffer_scale(surf->surf, iscale); } From 208008d717567f1a3a096d5775356a67d8dd6517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 10 Jan 2024 16:41:03 +0100 Subject: [PATCH 10/50] config: fix cloning of env_vars tllist When cloning a config struct, the env_vars tllist wasn't correctly copied. We did correctly iterate and duplicate all old entries, but we did *not* reset the list in the cloned struct before doing so. This meant the list contained entries shared with the original list, causing double free:s in --server mode. --- CHANGELOG.md | 2 ++ config.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4f998d..d7f41bb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,8 @@ * Crash when using a desktop scaling factor > 1, on compositors that implements neither the `fractional-scale-v1`, nor the `cursor-shape-v1` Wayland protocols ([#1573][1573]). +* Crash in `--server` mode when one or more environment variables are + set in `[environment]`. [1531]: https://codeberg.org/dnkl/foot/issues/1531 [1573]: https://codeberg.org/dnkl/foot/issues/1573 diff --git a/config.c b/config.c index e5cd6723..de15add3 100644 --- a/config.c +++ b/config.c @@ -3393,6 +3393,8 @@ config_clone(const struct config *old) key_binding_list_clone(&conf->bindings.url, &old->bindings.url); key_binding_list_clone(&conf->bindings.mouse, &old->bindings.mouse); + conf->env_vars.length = 0; + conf->env_vars.head = conf->env_vars.tail = NULL; tll_foreach(old->env_vars, it) { struct env_var copy = { .name = xstrdup(it->item.name), From 9da7152f834384a354710fcc8f99a6f83e5dfc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 9 Jan 2024 16:50:47 +0100 Subject: [PATCH 11/50] slave: don't skip setting environment variables when using a custom environment When launching footclient with -E,--client-environment the environment variables that should be set by foot, wasn't. Those variables are: * TERM * COLORTERM * PWD * SHELL and all variables defined by the user in the [environment] section in foot.ini. In the same way, we did not *unset* TERM_PROGRAM and TERM_PROGRAM_VERSION. This patch fixes it by "cloning" the custom environment, making it mutable, and then adding/removing the variables above from it. Instead of calling setenv()/unsetenv() directly, we add the wrapper functions add_to_env() and del_from_env(). When *not* using a custom environment, they simply call setenv()/unsetenv(). When we *are* using a custom environment, add_to_env() first loops all existing variables, looking for a match. If a match is found, it's updated with the new value. If it's not found, a new entry is added. del_from_env() loops all entries, and removes it when a match is found. If no match is found, nothing is done. The mutable environment is allocated on the heap, but never free:d. We don't need to free it, since it's only allocated after forking, in the child process. Closes #1568 --- CHANGELOG.md | 3 ++ doc/foot.1.scd | 21 +++++++-- doc/footclient.1.scd | 23 ++++++++++ server.c | 3 +- slave.c | 103 ++++++++++++++++++++++++++++++++++++++----- slave.h | 2 +- terminal.c | 2 +- terminal.h | 2 +- 8 files changed, 141 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7f41bb5..01309223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,9 +82,12 @@ `cursor-shape-v1` Wayland protocols ([#1573][1573]). * Crash in `--server` mode when one or more environment variables are set in `[environment]`. +* Environment variables normally set by foot lost with `footclient + -E,--client-environment` ([#1568][1568]). [1531]: https://codeberg.org/dnkl/foot/issues/1531 [1573]: https://codeberg.org/dnkl/foot/issues/1573 +[1568]: https://codeberg.org/dnkl/foot/issues/1568 ### Security diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 3da6fd7e..385f9721 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -554,16 +554,31 @@ In all other cases, the exit code is that of the client application set according to either the *--term* command-line option or the *term* config option in *foot.ini*(5). -*PWD* - Current working directory (at the time of launching foot) - *COLORTERM* This variable is set to *truecolor*, to indicate to client applications that 24-bit RGB colors are supported. +*PWD* + Current working directory (at the time of launching foot) + +*SHELL* + Set to the launched shell, if the shell is valid (it is listed in + */etc/shells*). + In addition to the variables listed above, custom environment variables may be defined in *foot.ini*(5). +## Variables *unset* in the child process + +*TERM_PROGRAM* +*TERM_PROGRAM_VERSION* + These environment variables are set by certain other terminal + emulators. We unset them, to prevent applications from + misdetecting foot. + +In addition to the variables listed above, custom environment +variables to unset may be defined in *foot.ini*(5). + # BUGS Please report bugs to https://codeberg.org/dnkl/foot/issues diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd index 7d89b9ed..365689af 100644 --- a/doc/footclient.1.scd +++ b/doc/footclient.1.scd @@ -73,6 +73,11 @@ terminal has terminated. The child process in the new terminal instance will use footclient's environment, instead of the server's. + Environment variables listed in the *Variables set in the child + process* section will be overwritten by the foot server. For + example, the new terminal will use *TERM* from the configuration, + not footclient's environment. + *-d*,*--log-level*={*info*,*warning*,*error*,*none*} Log level, used both for log output on stderr as well as syslog. Default: _warning_. @@ -163,9 +168,27 @@ fallback to the less specific path, with the following priority: This variable is set to *truecolor*, to indicate to client applications that 24-bit RGB colors are supported. +*PWD* + Current working directory (at the time of launching foot) + +*SHELL* + Set to the launched shell, if the shell is valid (it is listed in + */etc/shells*). + In addition to the variables listed above, custom environment variables may be defined in *foot.ini*(5). +## Variables *unset* in the child process + +*TERM_PROGRAM* +*TERM_PROGRAM_VERSION* + These environment variables are set by certain other terminal + emulators. We unset them, to prevent applications from + misdetecting foot. + +In addition to the variables listed above, custom environment +variables to unset may be defined in *foot.ini*(5). + # SEE ALSO *foot*(1) diff --git a/server.c b/server.c index ca55b8f3..7cc87152 100644 --- a/server.c +++ b/server.c @@ -332,7 +332,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) instance->terminal = term_init( conf != NULL ? conf : server->conf, server->fdm, server->reaper, server->wayl, "footclient", cwd, token, - cdata.argc, argv, envp, &term_shutdown_handler, instance); + cdata.argc, argv, (const char *const *)envp, + &term_shutdown_handler, instance); if (instance->terminal == NULL) { LOG_ERR("failed to instantiate new terminal"); diff --git a/slave.c b/slave.c index 0cf64fa0..fa53c515 100644 --- a/slave.c +++ b/slave.c @@ -25,6 +25,11 @@ extern char **environ; +struct environ { + size_t count; + char **envp; +}; + #if defined(__FreeBSD__) static char * find_file_in_path(const char *file) @@ -303,9 +308,69 @@ err: _exit(errno); } +static bool +env_matches_var_name(const char *e, const char *name) +{ + const size_t e_len = strlen(e); + const size_t name_len = strlen(name); + + if (e_len <= name_len) + return false; + if (memcmp(e, name, name_len) != 0) + return false; + if (e[name_len] != '=') + return false; + return true; +} + +static void +add_to_env(struct environ *env, const char *name, const char *value) +{ + if (env->envp == NULL) + setenv(name, value, 1); + else { + char *e = xasprintf("%s=%s", name, value); + + /* Search for existing variable. If found, replace it with the + new value */ + for (size_t i = 0; i < env->count; i++) { + if (env_matches_var_name(env->envp[i], name)) { + free(env->envp[i]); + env->envp[i] = e; + return; + } + } + + /* If the variable does not already exist, add it */ + env->envp = xrealloc(env->envp, (env->count + 2) * sizeof(env->envp[0])); + env->envp[env->count++] = e; + env->envp[env->count] = NULL; + } +} + +static void +del_from_env(struct environ *env, const char *name) +{ + if (env->envp == NULL) + unsetenv(name); + else { + for (size_t i = 0; i < env->count; i++) { + if (env_matches_var_name(env->envp[i], name)) { + free(env->envp[i]); + memmove(&env->envp[i], + &env->envp[i + 1], + (env->count - i) * sizeof(env->envp[0])); + env->count--; + xassert(env->envp[env->count] == NULL); + break; + } + } + } +} + pid_t slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, - char *const *envp, const env_var_list_t *extra_env_vars, + const char *const *envp, const env_var_list_t *extra_env_vars, const char *term_env, const char *conf_shell, bool login_shell, const user_notifications_t *notifications) { @@ -350,15 +415,30 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, _exit(errno_copy); } - setenv("TERM", term_env, 1); - setenv("COLORTERM", "truecolor", 1); - setenv("PWD", cwd, 1); + /* Create a mutable copy of the environment */ + struct environ custom_env = {0}; + if (envp != NULL) { + for (const char *const *e = envp; *e != NULL; e++) + custom_env.count++; - unsetenv("TERM_PROGRAM"); - unsetenv("TERM_PROGRAM_VERSION"); + custom_env.envp = xcalloc( + custom_env.count + 1, sizeof(custom_env.envp[0])); + + size_t i = 0; + for (const char *const *e = envp; *e != NULL; e++, i++) + custom_env.envp[i] = xstrdup(*e); + xassert(custom_env.envp[custom_env.count] == NULL); + } + + add_to_env(&custom_env, "TERM", term_env); + add_to_env(&custom_env, "COLORTERM", "truecolor"); + add_to_env(&custom_env, "PWD", cwd); + + del_from_env(&custom_env, "TERM_PROGRAM"); + del_from_env(&custom_env, "TERM_PROGRAM_VERSION"); #if defined(FOOT_TERMINFO_PATH) - setenv("TERMINFO", FOOT_TERMINFO_PATH, 1); + add_to_env(&custom_envp, "TERMINFO", FOOT_TERMINFO_PATH); #endif if (extra_env_vars != NULL) { @@ -367,9 +447,9 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, const char *value = it->item.value; if (strlen(value) == 0) - unsetenv(name); + del_from_env(&custom_env, name); else - setenv(name, value, 1); + add_to_env(&custom_env, name, value); } } @@ -393,9 +473,10 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, } if (is_valid_shell(shell_argv[0])) - setenv("SHELL", shell_argv[0], 1); + add_to_env(&custom_env, "SHELL", shell_argv[0]); - slave_exec(ptmx, shell_argv, envp != NULL ? envp : environ, + slave_exec(ptmx, shell_argv, + custom_env.envp != NULL ? custom_env.envp : environ, fork_pipe[1], login_shell, notifications); BUG("Unexpected return from slave_exec()"); break; diff --git a/slave.h b/slave.h index b1c08f14..26d93abb 100644 --- a/slave.h +++ b/slave.h @@ -7,7 +7,7 @@ #include "user-notification.h" pid_t slave_spawn( - int ptmx, int argc, const char *cwd, char *const *argv, char *const *envp, + int ptmx, int argc, const char *cwd, char *const *argv, const char *const *envp, const env_var_list_t *extra_env_vars, const char *term_env, const char *conf_shell, bool login_shell, const user_notifications_t *notifications); diff --git a/terminal.c b/terminal.c index efbbded1..5332ada0 100644 --- a/terminal.c +++ b/terminal.c @@ -1061,7 +1061,7 @@ static void fdm_client_terminated( struct terminal * term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, struct wayland *wayl, const char *foot_exe, const char *cwd, - const char *token, int argc, char *const *argv, char *const *envp, + const char *token, int argc, char *const *argv, const char *const *envp, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data) { int ptmx = -1; diff --git a/terminal.h b/terminal.h index a8b65198..ddd4f1ea 100644 --- a/terminal.h +++ b/terminal.h @@ -728,7 +728,7 @@ struct config; struct terminal *term_init( const struct config *conf, struct fdm *fdm, struct reaper *reaper, struct wayland *wayl, const char *foot_exe, const char *cwd, - const char *token, int argc, char *const *argv, char *const *envp, + const char *token, int argc, char *const *argv, const char *const *envp, void (*shutdown_cb)(void *data, int exit_code), void *shutdown_data); bool term_shutdown(struct terminal *term); From 8073ad352b6f6034a648b1a4331d9ccabbddbf82 Mon Sep 17 00:00:00 2001 From: Artturin Date: Tue, 16 Jan 2024 22:40:35 +0200 Subject: [PATCH 12/50] slave: fix typo ``` ../slave.c: In function 'slave_spawn': ../slave.c:441:21: error: 'custom_envp' undeclared (first use in this function); did you mean 'custom_env'? 441 | add_to_env(&custom_envp, "TERMINFO", FOOT_TERMINFO_PATH); | ^~~~~~~~~~~ | custom_env ../slave.c:441:21: note: each undeclared identifier is reported only once for each function it appears in ``` --- slave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slave.c b/slave.c index fa53c515..47d1c392 100644 --- a/slave.c +++ b/slave.c @@ -438,7 +438,7 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv, del_from_env(&custom_env, "TERM_PROGRAM_VERSION"); #if defined(FOOT_TERMINFO_PATH) - add_to_env(&custom_envp, "TERMINFO", FOOT_TERMINFO_PATH); + add_to_env(&custom_env, "TERMINFO", FOOT_TERMINFO_PATH); #endif if (extra_env_vars != NULL) { From 6ed1c28d2c5209c0149ff222ec2f96369bab7308 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Tue, 23 Jan 2024 20:33:46 +0000 Subject: [PATCH 13/50] terminal: simplify some string-related code in reload_fonts() --- terminal.c | 36 ++++++++---------------------------- xmalloc.c | 2 -- xmalloc.h | 12 ++++++++++++ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/terminal.c b/terminal.c index 5332ada0..5d0dc01d 100644 --- a/terminal.c +++ b/terminal.c @@ -939,11 +939,7 @@ reload_fonts(struct terminal *term, bool resize_grid) snprintf(size, sizeof(size), ":size=%.2f", term->font_sizes[i][j].pt_size * scale); - size_t len = strlen(font->pattern) + strlen(size) + 1; - names[i][j] = xmalloc(len); - - strcpy(names[i][j], font->pattern); - strcat(names[i][j], size); + names[i][j] = xstrjoin(font->pattern, size); } } @@ -966,30 +962,14 @@ reload_fonts(struct terminal *term, bool resize_grid) const char **names_bold_italic = (const char **)(custom_bold_italic ? names[3] : names[0]); const bool use_dpi = term->font_is_sized_by_dpi; + char *dpi = xasprintf("dpi=%.2f", use_dpi ? term->font_dpi : 96.); - char *attrs[4] = {NULL}; - int attr_len[4] = {-1, -1, -1, -1}; /* -1, so that +1 (below) results in 0 */ - - for (size_t i = 0; i < 2; i++) { - attr_len[0] = snprintf( - attrs[0], attr_len[0] + 1, "dpi=%.2f", - use_dpi ? term->font_dpi : 96); - attr_len[1] = snprintf( - attrs[1], attr_len[1] + 1, "dpi=%.2f:%s", - use_dpi ? term->font_dpi : 96, !custom_bold ? "weight=bold" : ""); - attr_len[2] = snprintf( - attrs[2], attr_len[2] + 1, "dpi=%.2f:%s", - use_dpi ? term->font_dpi : 96, !custom_italic ? "slant=italic" : ""); - attr_len[3] = snprintf( - attrs[3], attr_len[3] + 1, "dpi=%.2f:%s", - use_dpi ? term->font_dpi : 96, !custom_bold_italic ? "weight=bold:slant=italic" : ""); - - if (i > 0) - continue; - - for (size_t i = 0; i < 4; i++) - attrs[i] = xmalloc(attr_len[i] + 1); - } + char *attrs[4] = { + [0] = dpi, /* Takes ownership */ + [1] = xstrjoin(dpi, !custom_bold ? ":weight=bold" : ""), + [2] = xstrjoin(dpi, !custom_italic ? ":slant=italic" : ""), + [3] = xstrjoin(dpi, !custom_bold_italic ? ":weight=bold:slant=italic" : ""), + }; struct fcft_font *fonts[4]; struct font_load_data data[4] = { diff --git a/xmalloc.c b/xmalloc.c index 5d1fc997..ded7f4e3 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -1,8 +1,6 @@ #include -#include #include #include -#include #include "xmalloc.h" #include "debug.h" diff --git a/xmalloc.h b/xmalloc.h index 8a3098b8..74282f8f 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -16,3 +17,14 @@ char *xstrndup(const char *str, size_t n) XSTRDUP; char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC; char *xvasprintf(const char *format, va_list va) VPRINTF(1) XMALLOC; char32_t *xc32dup(const char32_t *str) XSTRDUP; + +static inline char * +xstrjoin(const char *s1, const char *s2) +{ + size_t n1 = strlen(s1); + size_t n2 = strlen(s2); + char *joined = xmalloc(n1 + n2 + 1); + memcpy(joined, s1, n1); + memcpy(joined + n1, s2, n2 + 1); + return joined; +} From 4ee4f47065d7e1a77a18d3b029f94ccab8ddb3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 22 Jan 2024 16:39:26 +0100 Subject: [PATCH 14/50] input: kitty: update to latest version of the spec Starting with kitty 0.32.0, the modifier bits during modifier key events behave differently, compared to before. Or, rather, they have now been spec:ed; before, behavior was different on e.g. MacOS, and Linux. The new behavior is this: On key press, the modifier bits in the kitty key event *includes* the pressed modifier key. On key release, the modifier bits in the kitty key event does *not* include the released modifier key. In other words, The modifier bits reflects the state *after* the key event. This is the exact opposite of what foot did before this patch. The patch is really pretty small: in order to include the key in the modifier set, we simulate a key press to update the XKB state, using xkb_state_uppate_key(). For key pressed, we simulate an XKB_KEY_DOWN event, and for key releases we simulate an XKB_KEY_UP event. Then we re-retrieve the modifers, both the full set, and the consumed set. Closes #1561 --- CHANGELOG.md | 5 ++++ input.c | 80 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01309223..cb62594e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,9 +65,14 @@ process. This ensures the terminal itself does not "lock" a directory; for example, preventing a mount point from being unmounted ([#1528][1528]). +* Kitty keyboard protocol: updated behavior of modifiers bits during + modifier key events, to match the (new [#6913][kitty-6913]) behavior + in kitty >= 0.32.0 ([#1561][1561]). [1526]: https://codeberg.org/dnkl/foot/issues/1526 [1528]: https://codeberg.org/dnkl/foot/issues/1528 +[1561]: https://codeberg.org/dnkl/foot/issues/1561 +[kitty-6913]: https://github.com/kovidgoyal/kitty/issues/6913 ### Deprecated diff --git a/input.c b/input.c index e3613a90..ba118e67 100644 --- a/input.c +++ b/input.c @@ -1135,19 +1135,77 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, if (!disambiguate && !report_all_as_escapes && pressed) return legacy_kbd_protocol(seat, term, ctx); - const xkb_mod_mask_t mods = ctx->mods & seat->kbd.kitty_significant; - const xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods2( - seat->kbd.xkb_state, ctx->key, XKB_CONSUMED_MODE_GTK) & seat->kbd.kitty_significant; - const xkb_mod_mask_t effective = mods & ~consumed; - const xkb_mod_mask_t caps_num = - (seat->kbd.mod_caps != XKB_MOD_INVALID ? 1 << seat->kbd.mod_caps : 0) | - (seat->kbd.mod_num != XKB_MOD_INVALID ? 1 << seat->kbd.mod_num : 0); - const xkb_keysym_t sym = ctx->sym; const uint32_t *utf32 = ctx->utf32; const uint8_t *const utf8 = ctx->utf8.buf; const size_t count = ctx->utf8.count; + /* Lookup sym in the pre-defined keysym table */ + const struct kitty_key_data *info = bsearch( + &sym, kitty_keymap, ALEN(kitty_keymap), sizeof(kitty_keymap[0]), + &kitty_search); + xassert(info == NULL || info->sym == sym); + + xkb_mod_mask_t mods = 0; + xkb_mod_mask_t consumed = 0; + + if (info != NULL && info->is_modifier) { + /* + * Special-case modifier keys. + * + * Normally, the "current" XKB state reflects the state + * *before* the current key event. In other words, the + * modifiers for key events that affect the modifier state + * (e.g. one of the control keys, or shift keys etc) does + * *not* include the key itself. + * + * Put another way, if you press "control", the modifier set + * is empty in the key press event, but contains "ctrl" in the + * release event. + * + * The kitty protocol mandates the modifier list contain the + * key itself, in *both* the press and release event. + * + * We handle this by updating the XKB state to *include* the + * current key, retrieve the set of modifiers (including the + * set of consumed modifiers), and then revert the XKB update. + */ + xkb_state_update_key( + seat->kbd.xkb_state, ctx->key, pressed ? XKB_KEY_DOWN : XKB_KEY_UP); + + get_current_modifiers(seat, &mods, NULL, ctx->key); + consumed = xkb_state_key_get_consumed_mods2( + seat->kbd.xkb_state, ctx->key, XKB_CONSUMED_MODE_GTK); + +#if 0 + /* + * TODO: according to the XKB docs, state updates should + * always be in pairs: each press should be followed by a + * release. However, doing this just breaks the xkb state. + * + * *Not* pairing the above press/release with a corresponding + * release/press appears to do exactly what we want. + */ + xkb_state_update_key( + seat->kbd.xkb_state, ctx->key, pressed ? XKB_KEY_UP : XKB_KEY_DOWN); +#endif + } else { + mods = ctx->mods; + + /* Re-retrieve the consumed modifiers using the GTK mode, to + better match kitty. */ + consumed = xkb_state_key_get_consumed_mods2( + seat->kbd.xkb_state, ctx->key, XKB_CONSUMED_MODE_GTK); + } + + mods &= seat->kbd.kitty_significant; + consumed &= seat->kbd.kitty_significant; + + const xkb_mod_mask_t effective = mods & ~consumed; + const xkb_mod_mask_t caps_num = + (seat->kbd.mod_caps != XKB_MOD_INVALID ? 1 << seat->kbd.mod_caps : 0) | + (seat->kbd.mod_num != XKB_MOD_INVALID ? 1 << seat->kbd.mod_num : 0); + bool is_text = count > 0 && utf32 != NULL && (effective & ~caps_num) == 0; for (size_t i = 0; utf32[i] != U'\0'; i++) { if (!iswprint(utf32[i])) { @@ -1159,12 +1217,6 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, const bool report_associated_text = (flags & KITTY_KBD_REPORT_ASSOCIATED) && is_text && !released; - /* Lookup sym in the pre-defined keysym table */ - const struct kitty_key_data *info = bsearch( - &sym, kitty_keymap, ALEN(kitty_keymap), sizeof(kitty_keymap[0]), - &kitty_search); - xassert(info == NULL || info->sym == sym); - if (composing) { /* We never emit anything while composing, *except* modifiers * (and only in report-all-keys-as-escape-codes mode) */ From 7e3da3007bb2459900d2c88d3ec11aecd1956849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?= Date: Tue, 9 Jan 2024 22:51:17 -0600 Subject: [PATCH 15/50] wayland: use wl_compositor version 6 when available --- terminal.c | 25 ++++++++++++++++++------- terminal.h | 1 + wayland.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- wayland.h | 3 +++ 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/terminal.c b/terminal.c index 5d0dc01d..7a51257d 100644 --- a/terminal.c +++ b/terminal.c @@ -2071,6 +2071,12 @@ term_fractional_scaling(const struct terminal *term) return term->wl->fractional_scale_manager != NULL && term->window->scale > 0.; } +bool +term_preferred_buffer_scale(const struct terminal *term) +{ + return term->wl->has_wl_compositor_v6; +} + bool term_update_scale(struct terminal *term) { @@ -2081,6 +2087,9 @@ term_update_scale(struct terminal *term) * the scale in the following order: * * - “preferred” scale, from the fractional-scale-v1 protocol + * - "preferred" scale, from wl_compositor version 6. + NOTE: if the compositor advertises version 6 we must use 1.0 + until wl_surface.preferred_buffer_scale is sent * - scaling factor of output we most recently were mapped on * - if we're not mapped, use the last known scaling factor * - if we're not mapped, and we don't have a last known scaling @@ -2090,13 +2099,15 @@ term_update_scale(struct terminal *term) */ const float new_scale = (term_fractional_scaling(term) ? win->scale - : tll_length(win->on_outputs) > 0 - ? tll_back(win->on_outputs)->scale - : term->scale_before_unmap > 0. - ? term->scale_before_unmap - : tll_length(term->wl->monitors) > 0 - ? tll_front(term->wl->monitors).scale - : 1.); + : term_preferred_buffer_scale(term) + ? win->preferred_buffer_scale + : tll_length(win->on_outputs) > 0 + ? tll_back(win->on_outputs)->scale + : term->scale_before_unmap > 0. + ? term->scale_before_unmap + : tll_length(term->wl->monitors) > 0 + ? tll_front(term->wl->monitors).scale + : 1.); if (new_scale == term->scale) return false; diff --git a/terminal.h b/terminal.h index ddd4f1ea..0dca0f48 100644 --- a/terminal.h +++ b/terminal.h @@ -743,6 +743,7 @@ bool term_paste_data_to_slave( struct terminal *term, const void *data, size_t len); bool term_fractional_scaling(const struct terminal *term); +bool term_preferred_buffer_scale(const struct terminal *term); bool term_update_scale(struct terminal *term); bool term_font_size_increase(struct terminal *term); bool term_font_size_decrease(struct terminal *term); diff --git a/wayland.c b/wayland.c index 34050d18..24d70235 100644 --- a/wayland.c +++ b/wayland.c @@ -705,9 +705,37 @@ surface_leave(void *data, struct wl_surface *wl_surface, LOG_WARN("unmapped from unknown output"); } +#if defined(WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION) +static void +surface_preferred_buffer_scale(void *data, struct wl_surface *surface, + int32_t scale) +{ + struct wl_window *win = data; + + if (win->preferred_buffer_scale == scale) + return; + + LOG_DBG("wl_surface preferred scale: %d -> %d", win->preferred_buffer_scale, scale); + + win->preferred_buffer_scale = scale; + update_term_for_output_change(win->term); +} + +static void +surface_preferred_buffer_transform(void *data, struct wl_surface *surface, + uint32_t transform) +{ + +} +#endif + static const struct wl_surface_listener surface_listener = { .enter = &surface_enter, .leave = &surface_leave, +#if defined(WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION) + .preferred_buffer_scale = &surface_preferred_buffer_scale, + .preferred_buffer_transform = &surface_preferred_buffer_transform, +#endif }; static void @@ -1057,8 +1085,14 @@ handle_global(void *data, struct wl_registry *registry, if (!verify_iface_version(interface, version, required)) return; +#if defined (WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION) + const uint32_t preferred = WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION; + wayl->has_wl_compositor_v6 = version >= WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION; +#else + const uint32_t preferred = required; +#endif wayl->compositor = wl_registry_bind( - wayl->registry, name, &wl_compositor_interface, required); + wayl->registry, name, &wl_compositor_interface, min(version, preferred)); } else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { @@ -1700,6 +1734,10 @@ wayl_win_init(struct terminal *term, const char *token) win->fractional_scale, &fractional_scale_listener, win); } + if (wayl->has_wl_compositor_v6) { + win->preferred_buffer_scale = 1; + } + win->xdg_surface = xdg_wm_base_get_xdg_surface(wayl->shell, win->surface.surf); xdg_surface_add_listener(win->xdg_surface, &xdg_surface_listener, win); @@ -2020,8 +2058,11 @@ surface_scale_explicit_width_height( wp_viewport_set_destination( surf->viewport, roundf(width / scale), roundf(height / scale)); } else { - LOG_DBG("scaling by a factor of %.2f using legacy mode " - "(width=%d, height=%d)", scale, width, height); + const char *mode = term_preferred_buffer_scale(win->term) + ? "wl_surface.preferred_buffer_scale" + : "legacy mode"; + LOG_DBG("scaling by a factor of %.2f using %s " + "(width=%d, height=%d)" , scale, mode, width, height); xassert(scale == floorf(scale)); const int iscale = (int)floorf(scale); diff --git a/wayland.h b/wayland.h index 67aadec2..145e480d 100644 --- a/wayland.h +++ b/wayland.h @@ -363,6 +363,7 @@ struct wl_window { bool unmapped; float scale; + int preferred_buffer_scale; struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; @@ -429,6 +430,8 @@ struct wayland { struct wl_subcompositor *sub_compositor; struct wl_shm *shm; + bool has_wl_compositor_v6; + struct zxdg_output_manager_v1 *xdg_output_manager; struct xdg_wm_base *shell; From 43e27a88434756d6de44a2dde4dbd342ccb387f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 24 Jan 2024 19:59:30 +0100 Subject: [PATCH 16/50] wayland: 'mode' is unused when LOG_ENABLE_DBG is not set --- wayland.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wayland.c b/wayland.c index 24d70235..25037c8a 100644 --- a/wayland.c +++ b/wayland.c @@ -2058,7 +2058,7 @@ surface_scale_explicit_width_height( wp_viewport_set_destination( surf->viewport, roundf(width / scale), roundf(height / scale)); } else { - const char *mode = term_preferred_buffer_scale(win->term) + const char *mode UNUSED = term_preferred_buffer_scale(win->term) ? "wl_surface.preferred_buffer_scale" : "legacy mode"; LOG_DBG("scaling by a factor of %.2f using %s " From 91b22ae21acd0b3171814b47b0dead027f8da779 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Thu, 25 Jan 2024 07:03:50 +0000 Subject: [PATCH 17/50] Replace unchecked allocations with calls to xmalloc.h functions --- char32.c | 4 ++-- config.c | 2 +- render.c | 2 +- server.c | 2 +- shm.c | 2 +- spawn.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/char32.c b/char32.c index e25db3f1..97c599d9 100644 --- a/char32.c +++ b/char32.c @@ -129,11 +129,11 @@ UNITTEST UNITTEST { - char32_t *c = c32dup(U"foobar"); + char32_t *c = xc32dup(U"foobar"); xassert(c32cmp(c, U"foobar") == 0); free(c); - c = c32dup(U""); + c = xc32dup(U""); xassert(c32cmp(c, U"") == 0); free(c); } diff --git a/config.c b/config.c index de15add3..f964f7c1 100644 --- a/config.c +++ b/config.c @@ -3213,7 +3213,7 @@ config_load(struct config *conf, const char *conf_path, ret = false; } else { conf->fonts[0].count = 1; - conf->fonts[0].arr = malloc(sizeof(font)); + conf->fonts[0].arr = xmalloc(sizeof(font)); conf->fonts[0].arr[0] = font; } } diff --git a/render.c b/render.c index d679b5e8..a522c24c 100644 --- a/render.c +++ b/render.c @@ -1460,7 +1460,7 @@ render_ime_preedit_for_seat(struct terminal *term, struct seat *seat, * from grid), and mark all cells as dirty. This ensures they are * re-rendered when the pre-edit text is modified or removed. */ - struct cell *real_cells = malloc(cells_used * sizeof(real_cells[0])); + struct cell *real_cells = xmalloc(cells_used * sizeof(real_cells[0])); for (int i = 0; i < cells_used; i++) { xassert(col_idx + i < term->cols); real_cells[i] = row->cells[col_idx + i]; diff --git a/server.c b/server.c index 7cc87152..068ca057 100644 --- a/server.c +++ b/server.c @@ -301,7 +301,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) #undef CHECK_BUF_AND_NULL #undef CHECK_BUF - struct terminal_instance *instance = malloc(sizeof(struct terminal_instance)); + struct terminal_instance *instance = xmalloc(sizeof(struct terminal_instance)); const bool need_to_clone_conf = tll_length(overrides)> 0 || diff --git a/shm.c b/shm.c index 171459f6..87bd33a7 100644 --- a/shm.c +++ b/shm.c @@ -489,7 +489,7 @@ get_new_buffers(struct buffer_chain *chain, size_t count, else tll_push_front(chain->bufs, buf); - buf->public.dirty = malloc( + buf->public.dirty = xmalloc( chain->pix_instances * sizeof(buf->public.dirty[0])); for (size_t j = 0; j < chain->pix_instances; j++) diff --git a/spawn.c b/spawn.c index 90b892f3..6935a29a 100644 --- a/spawn.c +++ b/spawn.c @@ -145,7 +145,7 @@ spawn_expand_template(const struct config_spawn_template *template, expanded[len] = '\0'; \ } while (0) - *argv = malloc((*argc + 1) * sizeof((*argv)[0])); + *argv = xmalloc((*argc + 1) * sizeof((*argv)[0])); /* Expand the provided keys */ for (size_t i = 0; i < *argc; i++) { From 44c0cf594b4674e92b9dd1646d7a2d43c401e5d8 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Thu, 25 Jan 2024 01:07:53 +0000 Subject: [PATCH 18/50] csi: simplify handling of Set/Reset Mode (SM/RM) sequences --- csi.c | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/csi.c b/csi.c index b83fc9b3..04f03b05 100644 --- a/csi.c +++ b/csi.c @@ -1081,44 +1081,29 @@ csi_dispatch(struct terminal *term, uint8_t final) break; case 'h': - /* Set mode */ - switch (vt_param_get(term, 0, 0)) { - case 2: /* Keyboard Action Mode - AM */ - LOG_WARN("unimplemented: keyboard action mode (AM)"); - break; - - case 4: /* Insert Mode - IRM */ - term->insert_mode = true; + case 'l': { + /* Set/Reset Mode (SM/RM) */ + int param = vt_param_get(term, 0, 0); + bool sm = final == 'h'; + if (param == 4) { + /* Insertion Replacement Mode (IRM) */ + term->insert_mode = sm; term_update_ascii_printer(term); break; + } - case 12: /* Send/receive Mode - SRM */ - LOG_WARN("unimplemented: send/receive mode (SRM)"); - break; - - case 20: /* Automatic Newline Mode - LNM */ - /* TODO: would be easy to implemented; when active - * term_linefeed() would _also_ do a - * term_carriage_return() */ - LOG_WARN("unimplemented: automatic newline mode (LNM)"); - break; - } - break; - - case 'l': - /* Reset mode */ - switch (vt_param_get(term, 0, 0)) { - case 4: /* Insert Mode - IRM */ - term->insert_mode = false; - term_update_ascii_printer(term); - break; - - case 2: /* Keyboard Action Mode - AM */ - case 12: /* Send/receive Mode - SRM */ - case 20: /* Automatic Newline Mode - LNM */ - break; + /* + * ECMA-48 defines modes 1-22, all of which were optional + * (§7.1; "may have one state only") and are considered + * deprecated (§7.1) in the latest (5th) edition. xterm only + * documents modes 2, 4, 12 and 20, the last of which was + * outright removed (§8.3.106) in 5th edition ECMA-48. + */ + if (sm) { + LOG_WARN("SM with unimplemented mode: %d", param); } break; + } case 'r': { int start = vt_param_get(term, 0, 1); From e0f3703ae6c4084f9275cfc78d87e5604cc27a10 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Wed, 24 Jan 2024 23:17:28 +0000 Subject: [PATCH 19/50] util: add streq() function and use in place of strcmp(...) == 0 --- client.c | 8 +- config.c | 220 ++++++++++++++++++++++---------------------- cursor-shape.c | 2 +- input.c | 6 +- log.c | 2 +- main.c | 8 +- osc.c | 4 +- render.c | 4 +- selection.c | 4 +- slave.c | 3 +- terminal.c | 2 +- tests/test-config.c | 24 +++-- uri.c | 6 +- url-mode.c | 4 +- util.h | 8 ++ wayland.c | 32 +++---- 16 files changed, 172 insertions(+), 165 deletions(-) diff --git a/client.c b/client.c index 8456dfd8..8576531f 100644 --- a/client.c +++ b/client.c @@ -315,11 +315,11 @@ main(int argc, char *const *argv) } case 'l': - if (optarg == NULL || strcmp(optarg, "auto") == 0) + if (optarg == NULL || streq(optarg, "auto")) log_colorize = LOG_COLORIZE_AUTO; - else if (strcmp(optarg, "never") == 0) + else if (streq(optarg, "never")) log_colorize = LOG_COLORIZE_NEVER; - else if (strcmp(optarg, "always") == 0) + else if (streq(optarg, "always")) log_colorize = LOG_COLORIZE_ALWAYS; else { fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg); @@ -419,7 +419,7 @@ main(int argc, char *const *argv) if (resolved_path_cwd != NULL && resolved_path_pwd != NULL && - strcmp(resolved_path_cwd, resolved_path_pwd) == 0) + streq(resolved_path_cwd, resolved_path_pwd)) { /* * The resolved path of $PWD matches the resolved path of diff --git a/config.c b/config.c index f964f7c1..ed021569 100644 --- a/config.c +++ b/config.c @@ -824,7 +824,7 @@ parse_section_main(struct context *ctx) const char *value = ctx->value; bool errors_are_fatal = ctx->errors_are_fatal; - if (strcmp(key, "include") == 0) { + if (streq(key, "include")) { char *_include_path = NULL; const char *include_path = NULL; @@ -864,25 +864,25 @@ parse_section_main(struct context *ctx) return ret; } - else if (strcmp(key, "term") == 0) + else if (streq(key, "term")) return value_to_str(ctx, &conf->term); - else if (strcmp(key, "shell") == 0) + else if (streq(key, "shell")) return value_to_str(ctx, &conf->shell); - else if (strcmp(key, "login-shell") == 0) + else if (streq(key, "login-shell")) return value_to_bool(ctx, &conf->login_shell); - else if (strcmp(key, "title") == 0) + else if (streq(key, "title")) return value_to_str(ctx, &conf->title); - else if (strcmp(key, "locked-title") == 0) + else if (streq(key, "locked-title")) return value_to_bool(ctx, &conf->locked_title); - else if (strcmp(key, "app-id") == 0) + else if (streq(key, "app-id")) return value_to_str(ctx, &conf->app_id); - else if (strcmp(key, "initial-window-size-pixels") == 0) { + else if (streq(key, "initial-window-size-pixels")) { if (!value_to_dimensions(ctx, &conf->size.width, &conf->size.height)) return false; @@ -890,7 +890,7 @@ parse_section_main(struct context *ctx) return true; } - else if (strcmp(key, "initial-window-size-chars") == 0) { + else if (streq(key, "initial-window-size-chars")) { if (!value_to_dimensions(ctx, &conf->size.width, &conf->size.height)) return false; @@ -898,7 +898,7 @@ parse_section_main(struct context *ctx) return true; } - else if (strcmp(key, "pad") == 0) { + else if (streq(key, "pad")) { unsigned x, y; char mode[16] = {0}; @@ -918,11 +918,11 @@ parse_section_main(struct context *ctx) return true; } - else if (strcmp(key, "resize-delay-ms") == 0) + else if (streq(key, "resize-delay-ms")) return value_to_uint16(ctx, 10, &conf->resize_delay_ms); - else if (strcmp(key, "bold-text-in-bright") == 0) { - if (strcmp(value, "palette-based") == 0) { + else if (streq(key, "bold-text-in-bright")) { + if (streq(value, "palette-based")) { conf->bold_in_bright.enabled = true; conf->bold_in_bright.palette_based = true; } else { @@ -933,7 +933,7 @@ parse_section_main(struct context *ctx) return true; } - else if (strcmp(key, "initial-window-mode") == 0) { + else if (streq(key, "initial-window-mode")) { _Static_assert(sizeof(conf->startup_mode) == sizeof(int), "enum is not 32-bit"); @@ -943,16 +943,16 @@ parse_section_main(struct context *ctx) (int *)&conf->startup_mode); } - else if (strcmp(key, "font") == 0 || - strcmp(key, "font-bold") == 0 || - strcmp(key, "font-italic") == 0 || - strcmp(key, "font-bold-italic") == 0) + else if (streq(key, "font") || + streq(key, "font-bold") || + streq(key, "font-italic") || + streq(key, "font-bold-italic")) { size_t idx = - strcmp(key, "font") == 0 ? 0 : - strcmp(key, "font-bold") == 0 ? 1 : - strcmp(key, "font-italic") == 0 ? 2 : 3; + streq(key, "font") ? 0 : + streq(key, "font-bold") ? 1 : + streq(key, "font-italic") ? 2 : 3; struct config_font_list new_list = value_to_fonts(ctx); if (new_list.arr == NULL) @@ -963,7 +963,7 @@ parse_section_main(struct context *ctx) return true; } - else if (strcmp(key, "font-size-adjustment") == 0) { + else if (streq(key, "font-size-adjustment")) { const size_t len = strlen(ctx->value); if (len >= 1 && ctx->value[len - 1] == '%') { errno = 0; @@ -988,44 +988,44 @@ parse_section_main(struct context *ctx) } } - else if (strcmp(key, "line-height") == 0) + else if (streq(key, "line-height")) return value_to_pt_or_px(ctx, &conf->line_height); - else if (strcmp(key, "letter-spacing") == 0) + else if (streq(key, "letter-spacing")) return value_to_pt_or_px(ctx, &conf->letter_spacing); - else if (strcmp(key, "horizontal-letter-offset") == 0) + else if (streq(key, "horizontal-letter-offset")) return value_to_pt_or_px(ctx, &conf->horizontal_letter_offset); - else if (strcmp(key, "vertical-letter-offset") == 0) + else if (streq(key, "vertical-letter-offset")) return value_to_pt_or_px(ctx, &conf->vertical_letter_offset); - else if (strcmp(key, "underline-offset") == 0) { + else if (streq(key, "underline-offset")) { if (!value_to_pt_or_px(ctx, &conf->underline_offset)) return false; conf->use_custom_underline_offset = true; return true; } - else if (strcmp(key, "underline-thickness") == 0) + else if (streq(key, "underline-thickness")) return value_to_pt_or_px(ctx, &conf->underline_thickness); - else if (strcmp(key, "dpi-aware") == 0) + else if (streq(key, "dpi-aware")) return value_to_bool(ctx, &conf->dpi_aware); - else if (strcmp(key, "workers") == 0) + else if (streq(key, "workers")) return value_to_uint16(ctx, 10, &conf->render_worker_count); - else if (strcmp(key, "word-delimiters") == 0) + else if (streq(key, "word-delimiters")) return value_to_wchars(ctx, &conf->word_delimiters); - else if (strcmp(key, "notify") == 0) + else if (streq(key, "notify")) return value_to_spawn_template(ctx, &conf->notify); - else if (strcmp(key, "notify-focus-inhibit") == 0) + else if (streq(key, "notify-focus-inhibit")) return value_to_bool(ctx, &conf->notify_focus_inhibit); - else if (strcmp(key, "selection-target") == 0) { + else if (streq(key, "selection-target")) { _Static_assert(sizeof(conf->selection_target) == sizeof(int), "enum is not 32-bit"); @@ -1035,14 +1035,14 @@ parse_section_main(struct context *ctx) (int *)&conf->selection_target); } - else if (strcmp(key, "box-drawings-uses-font-glyphs") == 0) + else if (streq(key, "box-drawings-uses-font-glyphs")) return value_to_bool(ctx, &conf->box_drawings_uses_font_glyphs); - else if (strcmp(key, "utmp-helper") == 0) { + else if (streq(key, "utmp-helper")) { if (!value_to_str(ctx, &conf->utmp_helper_path)) return false; - if (strcmp(conf->utmp_helper_path, "none") == 0) { + if (streq(conf->utmp_helper_path, "none")) { free(conf->utmp_helper_path); conf->utmp_helper_path = NULL; } @@ -1062,15 +1062,15 @@ parse_section_bell(struct context *ctx) struct config *conf = ctx->conf; const char *key = ctx->key; - if (strcmp(key, "urgent") == 0) + if (streq(key, "urgent")) return value_to_bool(ctx, &conf->bell.urgent); - else if (strcmp(key, "notify") == 0) + else if (streq(key, "notify")) return value_to_bool(ctx, &conf->bell.notify); - else if (strcmp(key, "visual") == 0) + else if (streq(key, "visual")) return value_to_bool(ctx, &conf->bell.flash); - else if (strcmp(key, "command") == 0) + else if (streq(key, "command")) return value_to_spawn_template(ctx, &conf->bell.command); - else if (strcmp(key, "command-focused") == 0) + else if (streq(key, "command-focused")) return value_to_bool(ctx, &conf->bell.command_focused); else { LOG_CONTEXTUAL_ERR("not a valid option: %s", key); @@ -1085,10 +1085,10 @@ parse_section_scrollback(struct context *ctx) const char *key = ctx->key; const char *value = ctx->value; - if (strcmp(key, "lines") == 0) + if (streq(key, "lines")) return value_to_uint32(ctx, 10, &conf->scrollback.lines); - else if (strcmp(key, "indicator-position") == 0) { + else if (streq(key, "indicator-position")) { _Static_assert( sizeof(conf->scrollback.indicator.position) == sizeof(int), "enum is not 32-bit"); @@ -1099,12 +1099,12 @@ parse_section_scrollback(struct context *ctx) (int *)&conf->scrollback.indicator.position); } - else if (strcmp(key, "indicator-format") == 0) { - if (strcmp(value, "percentage") == 0) { + else if (streq(key, "indicator-format")) { + if (streq(value, "percentage")) { conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE; return true; - } else if (strcmp(value, "line") == 0) { + } else if (streq(value, "line")) { conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; return true; @@ -1112,7 +1112,7 @@ parse_section_scrollback(struct context *ctx) return value_to_wchars(ctx, &conf->scrollback.indicator.text); } - else if (strcmp(key, "multiplier") == 0) + else if (streq(key, "multiplier")) return value_to_float(ctx, &conf->scrollback.multiplier); else { @@ -1128,13 +1128,13 @@ parse_section_url(struct context *ctx) const char *key = ctx->key; const char *value = ctx->value; - if (strcmp(key, "launch") == 0) + if (streq(key, "launch")) return value_to_spawn_template(ctx, &conf->url.launch); - else if (strcmp(key, "label-letters") == 0) + else if (streq(key, "label-letters")) return value_to_wchars(ctx, &conf->url.label_letters); - else if (strcmp(key, "osc8-underline") == 0) { + else if (streq(key, "osc8-underline")) { _Static_assert(sizeof(conf->url.osc8_underline) == sizeof(int), "enum is not 32-bit"); @@ -1144,7 +1144,7 @@ parse_section_url(struct context *ctx) (int *)&conf->url.osc8_underline); } - else if (strcmp(key, "protocols") == 0) { + else if (streq(key, "protocols")) { for (size_t i = 0; i < conf->url.prot_count; i++) free(conf->url.protocols[i]); free(conf->url.protocols); @@ -1196,7 +1196,7 @@ parse_section_url(struct context *ctx) return true; } - else if (strcmp(key, "uri-characters") == 0) { + else if (streq(key, "uri-characters")) { if (!value_to_wchars(ctx, &conf->url.uri_characters)) return false; @@ -1251,13 +1251,13 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "flash") == 0) color = &conf->colors.flash; - else if (strcmp(key, "foreground") == 0) color = &conf->colors.fg; - else if (strcmp(key, "background") == 0) color = &conf->colors.bg; - else if (strcmp(key, "selection-foreground") == 0) color = &conf->colors.selection_fg; - else if (strcmp(key, "selection-background") == 0) color = &conf->colors.selection_bg; + else if (streq(key, "flash")) color = &conf->colors.flash; + else if (streq(key, "foreground")) color = &conf->colors.fg; + else if (streq(key, "background")) color = &conf->colors.bg; + else if (streq(key, "selection-foreground")) color = &conf->colors.selection_fg; + else if (streq(key, "selection-background")) color = &conf->colors.selection_bg; - else if (strcmp(key, "jump-labels") == 0) { + else if (streq(key, "jump-labels")) { if (!value_to_two_colors( ctx, &conf->colors.jump_label.fg, @@ -1271,7 +1271,7 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "scrollback-indicator") == 0) { + else if (streq(key, "scrollback-indicator")) { if (!value_to_two_colors( ctx, &conf->colors.scrollback_indicator.fg, @@ -1285,7 +1285,7 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "search-box-no-match") == 0) { + else if (streq(key, "search-box-no-match")) { if (!value_to_two_colors( ctx, &conf->colors.search_box.no_match.fg, @@ -1299,7 +1299,7 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "search-box-match") == 0) { + else if (streq(key, "search-box-match")) { if (!value_to_two_colors( ctx, &conf->colors.search_box.match.fg, @@ -1313,7 +1313,7 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "urls") == 0) { + else if (streq(key, "urls")) { if (!value_to_color(ctx, &conf->colors.url, false)) return false; @@ -1321,7 +1321,7 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "alpha") == 0) { + else if (streq(key, "alpha")) { float alpha; if (!value_to_float(ctx, &alpha)) return false; @@ -1335,7 +1335,7 @@ parse_section_colors(struct context *ctx) return true; } - else if (strcmp(key, "flash-alpha") == 0) { + else if (streq(key, "flash-alpha")) { float alpha; if (!value_to_float(ctx, &alpha)) return false; @@ -1369,7 +1369,7 @@ parse_section_cursor(struct context *ctx) struct config *conf = ctx->conf; const char *key = ctx->key; - if (strcmp(key, "style") == 0) { + if (streq(key, "style")) { _Static_assert(sizeof(conf->cursor.style) == sizeof(int), "enum is not 32-bit"); @@ -1379,10 +1379,10 @@ parse_section_cursor(struct context *ctx) (int *)&conf->cursor.style); } - else if (strcmp(key, "blink") == 0) + else if (streq(key, "blink")) return value_to_bool(ctx, &conf->cursor.blink); - else if (strcmp(key, "color") == 0) { + else if (streq(key, "color")) { if (!value_to_two_colors( ctx, &conf->cursor.color.text, @@ -1397,10 +1397,10 @@ parse_section_cursor(struct context *ctx) return true; } - else if (strcmp(key, "beam-thickness") == 0) + else if (streq(key, "beam-thickness")) return value_to_pt_or_px(ctx, &conf->cursor.beam_thickness); - else if (strcmp(key, "underline-thickness") == 0) + else if (streq(key, "underline-thickness")) return value_to_pt_or_px(ctx, &conf->cursor.underline_thickness); else { @@ -1415,10 +1415,10 @@ parse_section_mouse(struct context *ctx) struct config *conf = ctx->conf; const char *key = ctx->key; - if (strcmp(key, "hide-when-typing") == 0) + if (streq(key, "hide-when-typing")) return value_to_bool(ctx, &conf->mouse.hide_when_typing); - else if (strcmp(key, "alternate-scroll-mode") == 0) + else if (streq(key, "alternate-scroll-mode")) return value_to_bool(ctx, &conf->mouse.alternate_scroll_mode); else { @@ -1433,7 +1433,7 @@ parse_section_csd(struct context *ctx) struct config *conf = ctx->conf; const char *key = ctx->key; - if (strcmp(key, "preferred") == 0) { + if (streq(key, "preferred")) { _Static_assert(sizeof(conf->csd.preferred) == sizeof(int), "enum is not 32-bit"); @@ -1443,7 +1443,7 @@ parse_section_csd(struct context *ctx) (int *)&conf->csd.preferred); } - else if (strcmp(key, "font") == 0) { + else if (streq(key, "font")) { struct config_font_list new_list = value_to_fonts(ctx); if (new_list.arr == NULL) return false; @@ -1453,7 +1453,7 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "color") == 0) { + else if (streq(key, "color")) { uint32_t color; if (!value_to_color(ctx, &color, true)) return false; @@ -1463,13 +1463,13 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "size") == 0) + else if (streq(key, "size")) return value_to_uint16(ctx, 10, &conf->csd.title_height); - else if (strcmp(key, "button-width") == 0) + else if (streq(key, "button-width")) return value_to_uint16(ctx, 10, &conf->csd.button_width); - else if (strcmp(key, "button-color") == 0) { + else if (streq(key, "button-color")) { if (!value_to_color(ctx, &conf->csd.color.buttons, true)) return false; @@ -1477,7 +1477,7 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "button-minimize-color") == 0) { + else if (streq(key, "button-minimize-color")) { if (!value_to_color(ctx, &conf->csd.color.minimize, true)) return false; @@ -1485,7 +1485,7 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "button-maximize-color") == 0) { + else if (streq(key, "button-maximize-color")) { if (!value_to_color(ctx, &conf->csd.color.maximize, true)) return false; @@ -1493,7 +1493,7 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "button-close-color") == 0) { + else if (streq(key, "button-close-color")) { if (!value_to_color(ctx, &conf->csd.color.quit, true)) return false; @@ -1501,7 +1501,7 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "border-color") == 0) { + else if (streq(key, "border-color")) { if (!value_to_color(ctx, &conf->csd.color.border, true)) return false; @@ -1509,13 +1509,13 @@ parse_section_csd(struct context *ctx) return true; } - else if (strcmp(key, "border-width") == 0) + else if (streq(key, "border-width")) return value_to_uint16(ctx, 10, &conf->csd.border_width_visible); - else if (strcmp(key, "hide-when-maximized") == 0) + else if (streq(key, "hide-when-maximized")) return value_to_bool(ctx, &conf->csd.hide_when_maximized); - else if (strcmp(key, "double-click-to-maximize") == 0) + else if (streq(key, "double-click-to-maximize")) return value_to_bool(ctx, &conf->csd.double_click_to_maximize); else { @@ -1574,13 +1574,13 @@ parse_modifiers(struct context *ctx, const char *text, size_t len, key != NULL; key = strtok_r(NULL, "+", &tok_ctx)) { - if (strcmp(key, XKB_MOD_NAME_SHIFT) == 0) + if (streq(key, XKB_MOD_NAME_SHIFT)) modifiers->shift = true; - else if (strcmp(key, XKB_MOD_NAME_CTRL) == 0) + else if (streq(key, XKB_MOD_NAME_CTRL)) modifiers->ctrl = true; - else if (strcmp(key, XKB_MOD_NAME_ALT) == 0) + else if (streq(key, XKB_MOD_NAME_ALT)) modifiers->alt = true; - else if (strcmp(key, XKB_MOD_NAME_LOGO) == 0) + else if (streq(key, XKB_MOD_NAME_LOGO)) modifiers->super = true; else { LOG_CONTEXTUAL_ERR("not a valid modifier name: %s", key); @@ -1698,7 +1698,7 @@ static int mouse_button_name_to_code(const char *name) { for (size_t i = 0; i < ALEN(button_map); i++) { - if (strcmp(button_map[i].name, name) == 0) + if (streq(button_map[i].name, name)) return button_map[i].code; } return -1; @@ -1947,7 +1947,7 @@ parse_key_binding_section(struct context *ctx, if (action_map[action] == NULL) continue; - if (strcmp(ctx->key, action_map[action]) != 0) + if (!streq(ctx->key, action_map[action])) continue; if (!value_to_key_combos(ctx, action, &aux, bindings, KEY_BINDING)) { @@ -2248,7 +2248,7 @@ parse_section_mouse_bindings(struct context *ctx) const char *key = ctx->key; const char *value = ctx->value; - if (strcmp(key, "selection-override-modifiers") == 0) { + if (streq(key, "selection-override-modifiers")) { if (!parse_modifiers( ctx, ctx->value, strlen(value), &conf->mouse.selection_override_modifiers)) @@ -2275,7 +2275,7 @@ parse_section_mouse_bindings(struct context *ctx) if (binding_action_map[action] == NULL) continue; - if (strcmp(key, binding_action_map[action]) != 0) + if (!streq(key, binding_action_map[action])) continue; if (!value_to_key_combos( @@ -2376,7 +2376,7 @@ parse_section_environment(struct context *ctx) /* Check for pre-existing env variable */ tll_foreach(conf->env_vars, it) { - if (strcmp(it->item.name, key) == 0) + if (streq(it->item.name, key)) return value_to_str(ctx, &it->item.value); } @@ -2398,7 +2398,7 @@ parse_section_tweak(struct context *ctx) struct config *conf = ctx->conf; const char *key = ctx->key; - if (strcmp(key, "scaling-filter") == 0) { + if (streq(key, "scaling-filter")) { static const char *filters[] = { [FCFT_SCALING_FILTER_NONE] = "none", [FCFT_SCALING_FILTER_NEAREST] = "nearest", @@ -2414,13 +2414,13 @@ parse_section_tweak(struct context *ctx) return value_to_enum(ctx, filters, (int *)&conf->tweak.fcft_filter); } - else if (strcmp(key, "overflowing-glyphs") == 0) + else if (streq(key, "overflowing-glyphs")) return value_to_bool(ctx, &conf->tweak.overflowing_glyphs); - else if (strcmp(key, "damage-whole-window") == 0) + else if (streq(key, "damage-whole-window")) return value_to_bool(ctx, &conf->tweak.damage_whole_window); - else if (strcmp(key, "grapheme-shaping") == 0) { + else if (streq(key, "grapheme-shaping")) { if (!value_to_bool(ctx, &conf->tweak.grapheme_shaping)) return false; @@ -2443,7 +2443,7 @@ parse_section_tweak(struct context *ctx) return true; } - else if (strcmp(key, "grapheme-width-method") == 0) { + else if (streq(key, "grapheme-width-method")) { _Static_assert(sizeof(conf->tweak.grapheme_width_method) == sizeof(int), "enum is not 32-bit"); @@ -2453,7 +2453,7 @@ parse_section_tweak(struct context *ctx) (int *)&conf->tweak.grapheme_width_method); } - else if (strcmp(key, "render-timer") == 0) { + else if (streq(key, "render-timer")) { _Static_assert(sizeof(conf->tweak.render_timer) == sizeof(int), "enum is not 32-bit"); @@ -2463,7 +2463,7 @@ parse_section_tweak(struct context *ctx) (int *)&conf->tweak.render_timer); } - else if (strcmp(key, "delayed-render-lower") == 0) { + else if (streq(key, "delayed-render-lower")) { uint32_t ns; if (!value_to_uint32(ctx, 10, &ns)) return false; @@ -2477,7 +2477,7 @@ parse_section_tweak(struct context *ctx) return true; } - else if (strcmp(key, "delayed-render-upper") == 0) { + else if (streq(key, "delayed-render-upper")) { uint32_t ns; if (!value_to_uint32(ctx, 10, &ns)) return false; @@ -2491,7 +2491,7 @@ parse_section_tweak(struct context *ctx) return true; } - else if (strcmp(key, "max-shm-pool-size-mb") == 0) { + else if (streq(key, "max-shm-pool-size-mb")) { uint32_t mb; if (!value_to_uint32(ctx, 10, &mb)) return false; @@ -2500,19 +2500,19 @@ parse_section_tweak(struct context *ctx) return true; } - else if (strcmp(key, "box-drawing-base-thickness") == 0) + else if (streq(key, "box-drawing-base-thickness")) return value_to_float(ctx, &conf->tweak.box_drawing_base_thickness); - else if (strcmp(key, "box-drawing-solid-shades") == 0) + else if (streq(key, "box-drawing-solid-shades")) return value_to_bool(ctx, &conf->tweak.box_drawing_solid_shades); - else if (strcmp(key, "font-monospace-warn") == 0) + else if (streq(key, "font-monospace-warn")) return value_to_bool(ctx, &conf->tweak.font_monospace_warn); - else if (strcmp(key, "sixel") == 0) + else if (streq(key, "sixel")) return value_to_bool(ctx, &conf->tweak.sixel); - else if (strcmp(key, "bold-text-in-bright-amount") == 0) + else if (streq(key, "bold-text-in-bright-amount")) return value_to_float(ctx, &conf->bold_in_bright.amount); else { @@ -2526,7 +2526,7 @@ parse_section_touch(struct context *ctx) { struct config *conf = ctx->conf; const char *key = ctx->key; - if (strcmp(key, "long-press-delay") == 0) + if (streq(key, "long-press-delay")) return value_to_uint32(ctx, 10, &conf->touch.long_press_delay); else { @@ -2649,7 +2649,7 @@ static enum section str_to_section(const char *str) { for (enum section section = SECTION_MAIN; section < SECTION_COUNT; ++section) { - if (strcmp(str, section_info[section].name) == 0) + if (streq(str, section_info[section].name)) return section; } return SECTION_COUNT; diff --git a/cursor-shape.c b/cursor-shape.c index a5402928..131e6f1a 100644 --- a/cursor-shape.c +++ b/cursor-shape.c @@ -101,7 +101,7 @@ cursor_string_to_server_shape(const char *xcursor) for (size_t i = 0; i < ALEN(table); i++) { for (size_t j = 0; j < ALEN(table[i]); j++) { - if (table[i][j] != NULL && strcmp(xcursor, table[i][j]) == 0) { + if (table[i][j] != NULL && streq(xcursor, table[i][j])) { return i; } } diff --git a/input.c b/input.c index ba118e67..25addf9b 100644 --- a/input.c +++ b/input.c @@ -854,7 +854,7 @@ UNITTEST const struct key_data *info = keymap_lookup(&term, XKB_KEY_ISO_Left_Tab, MOD_SHIFT | MOD_CTRL); xassert(info != NULL); - xassert(strcmp(info->seq, "\033[27;6;9~") == 0); + xassert(streq(info->seq, "\033[27;6;9~")); } UNITTEST @@ -865,12 +865,12 @@ UNITTEST const struct key_data *info = keymap_lookup(&term, XKB_KEY_Return, MOD_ALT); xassert(info != NULL); - xassert(strcmp(info->seq, "\033\r") == 0); + xassert(streq(info->seq, "\033\r")); term.modify_other_keys_2 = true; info = keymap_lookup(&term, XKB_KEY_Return, MOD_ALT); xassert(info != NULL); - xassert(strcmp(info->seq, "\033[27;3;13~") == 0); + xassert(streq(info->seq, "\033[27;3;13~")); } void diff --git a/log.c b/log.c index 360ca1c0..c13b4179 100644 --- a/log.c +++ b/log.c @@ -199,7 +199,7 @@ log_level_from_string(const char *str) return -1; for (int i = 0, n = map_len(); i < n; i++) - if (strcmp(str, log_level_map[i].name) == 0) + if (streq(str, log_level_map[i].name)) return i; return -1; diff --git a/main.c b/main.c index f7cf8354..98db9c38 100644 --- a/main.c +++ b/main.c @@ -351,11 +351,11 @@ main(int argc, char *const *argv) } case 'l': - if (optarg == NULL || strcmp(optarg, "auto") == 0) + if (optarg == NULL || streq(optarg, "auto")) log_colorize = LOG_COLORIZE_AUTO; - else if (strcmp(optarg, "never") == 0) + else if (streq(optarg, "never")) log_colorize = LOG_COLORIZE_NEVER; - else if (strcmp(optarg, "always") == 0) + else if (streq(optarg, "always")) log_colorize = LOG_COLORIZE_ALWAYS; else { fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg); @@ -538,7 +538,7 @@ main(int argc, char *const *argv) if (resolved_path_cwd != NULL && resolved_path_pwd != NULL && - strcmp(resolved_path_cwd, resolved_path_pwd) == 0) + streq(resolved_path_cwd, resolved_path_pwd)) { /* * The resolved path of $PWD matches the resolved path of diff --git a/osc.c b/osc.c index 45d114de..ba08964c 100644 --- a/osc.c +++ b/osc.c @@ -426,7 +426,7 @@ osc_set_pwd(struct terminal *term, char *string) return; } - if (strcmp(scheme, "file") == 0 && hostname_is_localhost(host)) { + if (streq(scheme, "file") && hostname_is_localhost(host)) { LOG_DBG("OSC7: pwd: %s", path); free(term->cwd); term->cwd = path; @@ -483,7 +483,7 @@ osc_uri(struct terminal *term, char *string) const char *value = operator + 1; - if (strcmp(key, "id") == 0) + if (streq(key, "id")) id = sdbm_hash(value); } diff --git a/render.c b/render.c index a522c24c..fcd21472 100644 --- a/render.c +++ b/render.c @@ -4559,8 +4559,8 @@ render_xcursor_set(struct seat *seat, struct terminal *term, if (seat->pointer.shape == shape && !(shape == CURSOR_SHAPE_CUSTOM && - strcmp(seat->pointer.last_custom_xcursor, - term->mouse_user_cursor) != 0)) + !streq(seat->pointer.last_custom_xcursor, + term->mouse_user_cursor))) { return true; } diff --git a/selection.c b/selection.c index 50e41637..9e9bbb10 100644 --- a/selection.c +++ b/selection.c @@ -2080,7 +2080,7 @@ decode_one_uri(struct clipboard_receive *ctx, char *uri, size_t len) ctx->cb(" ", 1, ctx->user); ctx->add_space = true; - if (strcmp(scheme, "file") == 0 && hostname_is_localhost(host)) { + if (streq(scheme, "file") && hostname_is_localhost(host)) { if (ctx->quote_paths) ctx->cb("'", 1, ctx->user); @@ -2534,7 +2534,7 @@ select_mime_type_for_offer(const char *_mime_type, if (mime_type_map[i] == NULL) continue; - if (strcmp(_mime_type, mime_type_map[i]) == 0) { + if (streq(_mime_type, mime_type_map[i])) { mime_type = i; break; } diff --git a/slave.c b/slave.c index 47d1c392..bcd864e1 100644 --- a/slave.c +++ b/slave.c @@ -21,6 +21,7 @@ #include "macros.h" #include "terminal.h" #include "tokenize.h" +#include "util.h" #include "xmalloc.h" extern char **environ; @@ -121,7 +122,7 @@ is_valid_shell(const char *shell) if (line[0] == '#') continue; - if (strcmp(line, shell) == 0) { + if (streq(line, shell)) { fclose(f); return true; } diff --git a/terminal.c b/terminal.c index 7a51257d..787eaf2d 100644 --- a/terminal.c +++ b/terminal.c @@ -3243,7 +3243,7 @@ term_set_window_title(struct terminal *term, const char *title) if (term->conf->locked_title && term->window_title_has_been_set) return; - if (term->window_title != NULL && strcmp(term->window_title, title) == 0) + if (term->window_title != NULL && streq(term->window_title, title)) return; free(term->window_title); diff --git a/tests/test-config.c b/tests/test-config.c index 95abf1a4..182dd4f6 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -60,7 +60,7 @@ test_string(struct context *ctx, bool (*parse_fun)(struct context *ctx), BUG("[%s].%s=%s: failed to parse", ctx->section, ctx->key, ctx->value); } - if (strcmp(*ptr, input[i].value) != 0) { + if (!streq(*ptr, input[i].value)) { BUG("[%s].%s=%s: set value (%s) not the expected one (%s)", ctx->section, ctx->key, ctx->value, *ptr, input[i].value); @@ -357,9 +357,7 @@ test_spawn_template(struct context *ctx, bool (*parse_fun)(struct context *ctx), BUG("[%s].%s=%s: argv is NULL", ctx->section, ctx->key, ctx->value); for (size_t i = 0; i < ALEN(args); i++) { - if (ptr->argv.args[i] == NULL || - strcmp(ptr->argv.args[i], args[i]) != 0) - { + if (ptr->argv.args[i] == NULL || !streq(ptr->argv.args[i], args[i])) { BUG("[%s].%s=%s: set value not the expected one: " "mismatch of arg #%zu: expected=\"%s\", got=\"%s\"", ctx->section, ctx->key, ctx->value, i, @@ -879,7 +877,7 @@ test_key_binding(struct context *ctx, bool (*parse_fun)(struct context *ctx), for (size_t i = 0; i < ALEN(args); i++) { if (binding->aux.pipe.args[i] == NULL || - strcmp(binding->aux.pipe.args[i], args[i]) != 0) + !streq(binding->aux.pipe.args[i], args[i])) { BUG("[%s].%s=%s: pipe argv not the expected one: " "mismatch of arg #%zu: expected=\"%s\", got=\"%s\"", @@ -1258,26 +1256,26 @@ test_section_environment(void) ctx.value = "bar"; xassert(parse_section_environment(&ctx)); xassert(tll_length(conf.env_vars) == 1); - xassert(strcmp(tll_front(conf.env_vars).name, "FOO") == 0); - xassert(strcmp(tll_front(conf.env_vars).value, "bar") == 0); + xassert(streq(tll_front(conf.env_vars).name, "FOO")); + xassert(streq(tll_front(conf.env_vars).value, "bar")); /* Add a second variable */ ctx.key = "BAR"; ctx.value = "123"; xassert(parse_section_environment(&ctx)); xassert(tll_length(conf.env_vars) == 2); - xassert(strcmp(tll_back(conf.env_vars).name, "BAR") == 0); - xassert(strcmp(tll_back(conf.env_vars).value, "123") == 0); + xassert(streq(tll_back(conf.env_vars).name, "BAR")); + xassert(streq(tll_back(conf.env_vars).value, "123")); /* Replace the *value* of the first variable */ ctx.key = "FOO"; ctx.value = "456"; xassert(parse_section_environment(&ctx)); xassert(tll_length(conf.env_vars) == 2); - xassert(strcmp(tll_front(conf.env_vars).name, "FOO") == 0); - xassert(strcmp(tll_front(conf.env_vars).value, "456") == 0); - xassert(strcmp(tll_back(conf.env_vars).name, "BAR") == 0); - xassert(strcmp(tll_back(conf.env_vars).value, "123") == 0); + xassert(streq(tll_front(conf.env_vars).name, "FOO")); + xassert(streq(tll_front(conf.env_vars).value, "456")); + xassert(streq(tll_back(conf.env_vars).name, "BAR")); + xassert(streq(tll_back(conf.env_vars).value, "123")); config_free(&conf); } diff --git a/uri.c b/uri.c index 7214a479..4de4bd88 100644 --- a/uri.c +++ b/uri.c @@ -250,7 +250,7 @@ hostname_is_localhost(const char *hostname) this_host[0] = '\0'; return (hostname != NULL && ( - strcmp(hostname, "") == 0 || - strcmp(hostname, "localhost") == 0 || - strcmp(hostname, this_host) == 0)); + streq(hostname, "") || + streq(hostname, "localhost") || + streq(hostname, this_host))); } diff --git a/url-mode.c b/url-mode.c index 76e2869d..1b28f8e0 100644 --- a/url-mode.c +++ b/url-mode.c @@ -685,7 +685,7 @@ urls_assign_key_combos(const struct config *conf, url_list_t *urls) break; if (it->item.id == it2->item.id && - strcmp(it->item.url, it2->item.url) == 0) + streq(it->item.url, it2->item.url)) { id_already_seen = true; break; @@ -704,7 +704,7 @@ urls_assign_key_combos(const struct config *conf, url_list_t *urls) if (&it->item == &it2->item) break; - if (strcmp(it->item.url, it2->item.url) == 0) { + if (streq(it->item.url, it2->item.url)) { it->item.key = xc32dup(it2->item.key); url_already_seen = true; break; diff --git a/util.h b/util.h index 683dbd4a..3746e269 100644 --- a/util.h +++ b/util.h @@ -1,12 +1,20 @@ #pragma once +#include #include +#include #include #define ALEN(v) (sizeof(v) / sizeof((v)[0])) #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) +static inline bool +streq(const char *a, const char *b) +{ + return strcmp(a, b) == 0; +} + static inline const char * thrd_err_as_string(int thrd_err) { diff --git a/wayland.c b/wayland.c index 25037c8a..0ef0bdfd 100644 --- a/wayland.c +++ b/wayland.c @@ -1080,7 +1080,7 @@ handle_global(void *data, struct wl_registry *registry, LOG_DBG("global: 0x%08x, interface=%s, version=%u", name, interface, version); struct wayland *wayl = data; - if (strcmp(interface, wl_compositor_interface.name) == 0) { + if (streq(interface, wl_compositor_interface.name)) { const uint32_t required = 4; if (!verify_iface_version(interface, version, required)) return; @@ -1095,7 +1095,7 @@ handle_global(void *data, struct wl_registry *registry, wayl->registry, name, &wl_compositor_interface, min(version, preferred)); } - else if (strcmp(interface, wl_subcompositor_interface.name) == 0) { + else if (streq(interface, wl_subcompositor_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1104,7 +1104,7 @@ handle_global(void *data, struct wl_registry *registry, wayl->registry, name, &wl_subcompositor_interface, required); } - else if (strcmp(interface, wl_shm_interface.name) == 0) { + else if (streq(interface, wl_shm_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1114,7 +1114,7 @@ handle_global(void *data, struct wl_registry *registry, wl_shm_add_listener(wayl->shm, &shm_listener, wayl); } - else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { + else if (streq(interface, xdg_wm_base_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1139,7 +1139,7 @@ handle_global(void *data, struct wl_registry *registry, xdg_wm_base_add_listener(wayl->shell, &xdg_wm_base_listener, wayl); } - else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) { + else if (streq(interface, zxdg_decoration_manager_v1_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1148,7 +1148,7 @@ handle_global(void *data, struct wl_registry *registry, wayl->registry, name, &zxdg_decoration_manager_v1_interface, required); } - else if (strcmp(interface, wl_seat_interface.name) == 0) { + else if (streq(interface, wl_seat_interface.name)) { const uint32_t required = 5; if (!verify_iface_version(interface, version, required)) return; @@ -1188,7 +1188,7 @@ handle_global(void *data, struct wl_registry *registry, wl_seat_add_listener(wl_seat, &seat_listener, seat); } - else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { + else if (streq(interface, zxdg_output_manager_v1_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1205,7 +1205,7 @@ handle_global(void *data, struct wl_registry *registry, } } - else if (strcmp(interface, wl_output_interface.name) == 0) { + else if (streq(interface, wl_output_interface.name)) { const uint32_t required = 2; if (!verify_iface_version(interface, version, required)) return; @@ -1237,7 +1237,7 @@ handle_global(void *data, struct wl_registry *registry, } } - else if (strcmp(interface, wl_data_device_manager_interface.name) == 0) { + else if (streq(interface, wl_data_device_manager_interface.name)) { const uint32_t required = 3; if (!verify_iface_version(interface, version, required)) return; @@ -1249,7 +1249,7 @@ handle_global(void *data, struct wl_registry *registry, seat_add_data_device(&it->item); } - else if (strcmp(interface, zwp_primary_selection_device_manager_v1_interface.name) == 0) { + else if (streq(interface, zwp_primary_selection_device_manager_v1_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1262,7 +1262,7 @@ handle_global(void *data, struct wl_registry *registry, seat_add_primary_selection(&it->item); } - else if (strcmp(interface, wp_presentation_interface.name) == 0) { + else if (streq(interface, wp_presentation_interface.name)) { if (wayl->presentation_timings) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) @@ -1275,7 +1275,7 @@ handle_global(void *data, struct wl_registry *registry, } } - else if (strcmp(interface, xdg_activation_v1_interface.name) == 0) { + else if (streq(interface, xdg_activation_v1_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1284,7 +1284,7 @@ handle_global(void *data, struct wl_registry *registry, wayl->registry, name, &xdg_activation_v1_interface, required); } - else if (strcmp(interface, wp_viewporter_interface.name) == 0) { + else if (streq(interface, wp_viewporter_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1293,7 +1293,7 @@ handle_global(void *data, struct wl_registry *registry, wayl->registry, name, &wp_viewporter_interface, required); } - else if (strcmp(interface, wp_fractional_scale_manager_v1_interface.name) == 0) { + else if (streq(interface, wp_fractional_scale_manager_v1_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1303,7 +1303,7 @@ handle_global(void *data, struct wl_registry *registry, &wp_fractional_scale_manager_v1_interface, required); } - else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) { + else if (streq(interface, wp_cursor_shape_manager_v1_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; @@ -1313,7 +1313,7 @@ handle_global(void *data, struct wl_registry *registry, } #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED - else if (strcmp(interface, zwp_text_input_manager_v3_interface.name) == 0) { + else if (streq(interface, zwp_text_input_manager_v3_interface.name)) { const uint32_t required = 1; if (!verify_iface_version(interface, version, required)) return; From 21a8d832ce12217ddd493cdcaefdc457128f2ada Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Wed, 17 Jan 2024 15:00:14 -0500 Subject: [PATCH 20/50] feature: add resize-by-cells option to constrain window sizes... ...to multiples of the cell size, and preserve grid size when changing fonts or display scales in floating windows. --- CHANGELOG.md | 4 +++ config.c | 4 +++ config.h | 3 ++ doc/foot.ini.5.scd | 15 ++++++++ render.c | 87 ++++++++++++++++++++++++++++------------------ render.h | 11 ++++-- terminal.c | 5 +-- wayland.c | 46 +++++++++++++++--------- 8 files changed, 120 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb62594e..14e95557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ * Unicode input mode now accepts input from the numpad as well, numlock is ignored. +* A new `resize-by-cells` option, enabled by default, allows the size + of floating windows to be constrained to multiples of the cell size. ### Changed @@ -68,6 +70,8 @@ * Kitty keyboard protocol: updated behavior of modifiers bits during modifier key events, to match the (new [#6913][kitty-6913]) behavior in kitty >= 0.32.0 ([#1561][1561]). +* When changing font sizes or display scales in floating windows, the + window will be resized as needed to preserve the same grid size. [1526]: https://codeberg.org/dnkl/foot/issues/1526 [1528]: https://codeberg.org/dnkl/foot/issues/1528 diff --git a/config.c b/config.c index ed021569..ae3255e6 100644 --- a/config.c +++ b/config.c @@ -921,6 +921,9 @@ parse_section_main(struct context *ctx) else if (streq(key, "resize-delay-ms")) return value_to_uint16(ctx, 10, &conf->resize_delay_ms); + else if (streq(key, "resize-by-cells")) + return value_to_bool(ctx, &conf->resize_by_cells); + else if (streq(key, "bold-text-in-bright")) { if (streq(value, "palette-based")) { conf->bold_in_bright.enabled = true; @@ -2990,6 +2993,7 @@ config_load(struct config *conf, const char *conf_path, }, .pad_x = 0, .pad_y = 0, + .resize_by_cells = true, .resize_delay_ms = 100, .bold_in_bright = { .enabled = false, diff --git a/config.h b/config.h index 3c5b3df7..cc4094c4 100644 --- a/config.h +++ b/config.h @@ -128,6 +128,9 @@ struct config { unsigned pad_x; unsigned pad_y; bool center; + + bool resize_by_cells; + uint16_t resize_delay_ms; struct { diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index e276d186..1c87db53 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -252,6 +252,21 @@ empty string to be set, but it must be quoted: *KEY=""*) Default: _100_. +*resize-by-cells* + Boolean. + + When set to *yes*, the window size will be constrained to multiples + of the cell size (plus any configured padding). When set to *no*, + the window size will be unconstrained, and padding may be adjusted + as necessary to accommodate window sizes that are not multiples of + the cell size. + + This option only applies to floating windows. Sizes of maxmized, tiled + or fullscreen windows will not be constrained to multiples of the cell + size. + + Default: _yes_ + *initial-window-size-pixels* Initial window width and height in _pixels_ (subject to output scaling), in the form _WIDTHxHEIGHT_. The height _includes_ the diff --git a/render.c b/render.c index fcd21472..5d2ec6bc 100644 --- a/render.c +++ b/render.c @@ -3912,9 +3912,25 @@ send_dimensions_to_client(struct terminal *term) } } +static void +set_size_from_grid(struct terminal *term, int *width, int *height, int cols, int rows) +{ + /* Nominal grid dimensions */ + *width = cols * term->cell_width; + *height = rows * term->cell_height; + + /* Include any configured padding */ + *width += 2 * term->conf->pad_x * term->scale; + *height += 2 * term->conf->pad_y * term->scale; + + /* Round to multiples of scale */ + *width = round(term->scale * round(*width / term->scale)); + *height = round(term->scale * round(*height / term->scale)); +} + /* Move to terminal.c? */ -static bool -maybe_resize(struct terminal *term, int width, int height, bool force) +bool +render_resize(struct terminal *term, int width, int height, uint8_t opts) { if (term->shutdown.in_progress) return false; @@ -3925,21 +3941,29 @@ maybe_resize(struct terminal *term, int width, int height, bool force) if (term->cell_width == 0 && term->cell_height == 0) return false; + const bool is_floating = + !term->window->is_maximized && + !term->window->is_fullscreen && + !term->window->is_tiled; + + /* Convert logical size to physical size */ const float scale = term->scale; width = round(width * scale); height = round(height * scale); + /* If the grid should be kept, the size should be overridden */ + if (is_floating && (opts & RESIZE_KEEP_GRID)) { + set_size_from_grid(term, &width, &height, term->cols, term->rows); + } + if (width == 0 && height == 0) { - /* - * The compositor is letting us choose the size - * - * If we have a "last" used size - use that. Otherwise, use - * the size from the user configuration. - */ + /* The compositor is letting us choose the size */ if (term->stashed_width != 0 && term->stashed_height != 0) { + /* If a default size is requested, prefer the "last used" size */ width = term->stashed_width; height = term->stashed_height; } else { + /* Otherwise, use a user-configured size */ switch (term->conf->size.type) { case CONF_SIZE_PX: width = term->conf->size.width; @@ -3959,15 +3983,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) break; case CONF_SIZE_CELLS: - width = term->conf->size.width * term->cell_width; - height = term->conf->size.height * term->cell_height; - - width += 2 * term->conf->pad_x * scale; - height += 2 * term->conf->pad_y * scale; - - /* Ensure width/height is a valid multiple of scale */ - width = roundf(scale * roundf(width / scale)); - height = roundf(scale * roundf(height / scale)); + set_size_from_grid(term, &width, &height, + term->conf->size.width, term->conf->size.height); break; } } @@ -3990,8 +4007,25 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int pad_x = min(max_pad_x, scale * term->conf->pad_x); const int pad_y = min(max_pad_y, scale * term->conf->pad_y); - if (!force && width == term->width && height == term->height && scale == term->scale) + if (is_floating && + (opts & RESIZE_BY_CELLS) && + term->conf->resize_by_cells) + { + /* If resizing in cell increments, restrict the width and height */ + width = ((width - 2 * pad_x) / term->cell_width) * term->cell_width + 2 * pad_x; + width = max(min_width, roundf(scale * roundf(width / scale))); + + height = ((height - 2 * pad_y) / term->cell_height) * term->cell_height + 2 * pad_y; + height = max(min_height, roundf(scale * roundf(height / scale))); + } + + if (!(opts & RESIZE_FORCE) && + width == term->width && + height == term->height && + scale == term->scale) + { return false; + } /* Cancel an application initiated "Synchronized Update" */ term_disable_app_sync_updates(term); @@ -4225,10 +4259,7 @@ damage_view: /* Signal TIOCSWINSZ */ send_dimensions_to_client(term); - if (!term->window->is_maximized && - !term->window->is_fullscreen && - !term->window->is_tiled) - { + if (is_floating) { /* Stash current size, to enable us to restore it when we're * being un-maximized/fullscreened/tiled */ term->stashed_width = term->width; @@ -4291,18 +4322,6 @@ damage_view: return true; } -bool -render_resize(struct terminal *term, int width, int height) -{ - return maybe_resize(term, width, height, false); -} - -bool -render_resize_force(struct terminal *term, int width, int height) -{ - return maybe_resize(term, width, height, true); -} - static void xcursor_callback( void *data, struct wl_callback *wl_callback, uint32_t callback_data); static const struct wl_callback_listener xcursor_listener = { diff --git a/render.h b/render.h index f038ffb0..78ebae40 100644 --- a/render.h +++ b/render.h @@ -10,8 +10,15 @@ struct renderer; struct renderer *render_init(struct fdm *fdm, struct wayland *wayl); void render_destroy(struct renderer *renderer); -bool render_resize(struct terminal *term, int width, int height); -bool render_resize_force(struct terminal *term, int width, int height); +enum resize_options { + RESIZE_NORMAL = 0, + RESIZE_FORCE = 1 << 0, + RESIZE_BY_CELLS = 1 << 1, + RESIZE_KEEP_GRID = 1 << 2, +}; + +bool render_resize( + struct terminal *term, int width, int height, uint8_t resize_options); void render_refresh(struct terminal *term); void render_refresh_csd(struct terminal *term); diff --git a/terminal.c b/terminal.c index 787eaf2d..b0120c6a 100644 --- a/terminal.c +++ b/terminal.c @@ -784,10 +784,11 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4], * render_resize() after this function */ if (resize_grid) { /* Use force, since cell-width/height may have changed */ - render_resize_force( + render_resize( term, (int)roundf(term->width / term->scale), - (int)roundf(term->height / term->scale)); + (int)roundf(term->height / term->scale), + RESIZE_FORCE | RESIZE_KEEP_GRID); } return true; } diff --git a/wayland.c b/wayland.c index 0ef0bdfd..271f950e 100644 --- a/wayland.c +++ b/wayland.c @@ -392,8 +392,6 @@ static void update_term_for_output_change(struct terminal *term) { const float old_scale = term->scale; - const float logical_width = term->width / term->scale; - const float logical_height = term->height / term->scale; /* Note: order matters! term_update_scale() must come first */ bool scale_updated = term_update_scale(term); @@ -402,24 +400,37 @@ update_term_for_output_change(struct terminal *term) csd_reload_font(term->window, old_scale); + uint8_t resize_opts = RESIZE_KEEP_GRID; + if (fonts_updated) { /* * If the fonts have been updated, the cell dimensions have * changed. This requires a “forced” resize, since the surface * buffer dimensions may not have been updated (in which case - * render_size() normally shortcuts and returns early). + * render_resize() normally shortcuts and returns early). */ - render_resize_force(term, (int)roundf(logical_width), (int)roundf(logical_height)); + resize_opts |= RESIZE_FORCE; + } else if (!scale_updated) { + /* No need to resize if neither scale nor fonts have changed */ + return; + } else if (term->conf->dpi_aware) { + /* + * If fonts are sized according to DPI, it is possible for the cell + * size to remain the same when display scale changes. This will not + * change the surface buffer dimensions, but will change the logical + * size of the window. To ensure that the compositor is made aware of + * the proper logical size, force a resize rather than allowing + * render_resize() to shortcut the notification if the buffer + * dimensions remain the same. + */ + resize_opts |= RESIZE_FORCE; } - else if (scale_updated) { - /* - * A scale update means the surface buffer dimensions have - * been updated, even though the window logical dimensions - * haven’t changed. - */ - render_resize(term, (int)roundf(logical_width), (int)roundf(logical_height)); - } + render_resize( + term, + (int)roundf(term->width / term->scale), + (int)roundf(term->height / term->scale), + resize_opts); } static void @@ -976,6 +987,8 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, xdg_surface_ack_configure(xdg_surface, serial); + enum resize_options opts = RESIZE_BY_CELLS; + #if 1 /* * TODO: decide if we should do the last “forced” call when ending @@ -989,13 +1002,12 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, * Note: if we also disable content centering while resizing, then * the last, forced, resize *is* necessary. */ - bool resized = was_resizing && !win->is_resizing - ? render_resize_force(term, new_width, new_height) - : render_resize(term, new_width, new_height); -#else - bool resized = render_resize(term, new_width, new_height); + if (was_resizing && !win->is_resizing) + opts |= RESIZE_FORCE; #endif + bool resized = render_resize(term, new_width, new_height, opts); + if (win->configure.is_activated) term_visual_focus_in(term); else From 4730ff8d080e82fad0554dfcb957dfc82f6568b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 6 May 2023 11:39:38 +0200 Subject: [PATCH 21/50] input/config: support *all* modifier names That is, allow custom modifiers (i.e. other than ctrl/shift/alt etc) in key bindings. This is done by no longer validating/translating modifier names to booleans for a pre-configured set of modifiers (ctrl, shift, alt, super). Instead, we keep the modifier *names* in a list, in the key binding struct. When a keymap is loaded, and we "convert" the key binding, _then_ we do modifier translation. For invalid modifier names, we print an error, and then ignore it. I.e. we no longer fail to load a config due to invalid modifier names. We also need to update how we determine the set of significant modifiers. Any modifier not in this list will be ignored when matching key bindings. Before this patch, we hardcoded this to shift/alt/ctrl/super. Now, to handle custom modifiers as well, we simply treat *all* modifiers defined by the current layout as significant. Typically, the only unwanted modifiers are "locked" modifiers. We are already filtering these out. --- config.c | 363 +++++++++++++++++++++++++------------------- config.h | 13 +- input.c | 33 ++-- key-binding.c | 24 ++- tests/test-config.c | 40 +++-- wayland.h | 5 +- 6 files changed, 291 insertions(+), 187 deletions(-) diff --git a/config.c b/config.c index ae3255e6..e3d531c2 100644 --- a/config.c +++ b/config.c @@ -1544,6 +1544,7 @@ static void free_key_binding(struct config_key_binding *binding) { free_binding_aux(&binding->aux); + tll_free_and_free(binding->modifiers, free); } static void NOINLINE @@ -1559,43 +1560,26 @@ free_key_binding_list(struct config_key_binding_list *bindings) bindings->count = 0; } -static bool NOINLINE -parse_modifiers(struct context *ctx, const char *text, size_t len, - struct config_key_modifiers *modifiers) +static void NOINLINE +parse_modifiers(const char *text, size_t len, config_modifier_list_t *modifiers) { - bool ret = false; - - *modifiers = (struct config_key_modifiers){0}; + tll_free_and_free(*modifiers, free); /* Handle "none" separately because e.g. none+shift is nonsense */ if (strncmp(text, "none", len) == 0) - return true; + return; char *copy = xstrndup(text, len); - for (char *tok_ctx = NULL, *key = strtok_r(copy, "+", &tok_ctx); + for (char *ctx = NULL, *key = strtok_r(copy, "+", &ctx); key != NULL; - key = strtok_r(NULL, "+", &tok_ctx)) + key = strtok_r(NULL, "+", &ctx)) { - if (streq(key, XKB_MOD_NAME_SHIFT)) - modifiers->shift = true; - else if (streq(key, XKB_MOD_NAME_CTRL)) - modifiers->ctrl = true; - else if (streq(key, XKB_MOD_NAME_ALT)) - modifiers->alt = true; - else if (streq(key, XKB_MOD_NAME_LOGO)) - modifiers->super = true; - else { - LOG_CONTEXTUAL_ERR("not a valid modifier name: %s", key); - goto out; - } + tll_push_back(*modifiers, xstrdup(key)); } - ret = true; - -out: free(copy); - return ret; + tll_sort(*modifiers, strcmp); } static int NOINLINE @@ -1731,6 +1715,7 @@ value_to_key_combos(struct context *ctx, int action, /* Count number of combinations */ size_t combo_count = 1; + size_t used_combos = 0; /* For error handling */ for (const char *p = strchr(ctx->value, ' '); p != NULL; p = strchr(p + 1, ' ')) @@ -1746,7 +1731,7 @@ value_to_key_combos(struct context *ctx, int action, for (char *tok_ctx = NULL, *combo = strtok_r(copy, " ", &tok_ctx); combo != NULL; combo = strtok_r(NULL, " ", &tok_ctx), - idx++) + idx++, used_combos++) { struct config_key_binding *new_combo = &new_combos[idx]; new_combo->action = action; @@ -1757,6 +1742,7 @@ value_to_key_combos(struct context *ctx, int action, new_combo->aux.master_copy = idx == 0; new_combo->aux.pipe = *argv; #endif + memset(&new_combo->modifiers, 0, sizeof(new_combo->modifiers)); new_combo->path = ctx->path; new_combo->lineno = ctx->lineno; @@ -1765,11 +1751,9 @@ value_to_key_combos(struct context *ctx, int action, if (key == NULL) { /* No modifiers */ key = combo; - new_combo->modifiers = (struct config_key_modifiers){0}; } else { *key = '\0'; - if (!parse_modifiers(ctx, combo, key - combo, &new_combo->modifiers)) - goto err; + parse_modifiers(combo, key - combo, &new_combo->modifiers); key++; /* Skip past the '+' */ } @@ -1779,6 +1763,7 @@ value_to_key_combos(struct context *ctx, int action, new_combo->k.sym = xkb_keysym_from_name(key, 0); if (new_combo->k.sym == XKB_KEY_NoSymbol) { LOG_CONTEXTUAL_ERR("not a valid XKB key name: %s", key); + free_key_binding(new_combo); goto err; } break; @@ -1799,6 +1784,7 @@ value_to_key_combos(struct context *ctx, int action, LOG_CONTEXTUAL_ERRNO("invalid click count: %s", _count); else LOG_CONTEXTUAL_ERR("invalid click count: %s", _count); + free_key_binding(new_combo); goto err; } @@ -1808,6 +1794,7 @@ value_to_key_combos(struct context *ctx, int action, new_combo->m.button = mouse_button_name_to_code(key); if (new_combo->m.button < 0) { LOG_CONTEXTUAL_ERR("invalid mouse button name: %s", key); + free_key_binding(new_combo); goto err; } @@ -1838,41 +1825,89 @@ value_to_key_combos(struct context *ctx, int action, return true; err: + for (size_t i = 0; i < used_combos; i++) + free_key_binding(&new_combos[i]); free(copy); return false; } static bool -modifiers_equal(const struct config_key_modifiers *mods1, - const struct config_key_modifiers *mods2) +modifiers_equal(const config_modifier_list_t *mods1, + const config_modifier_list_t *mods2) { - bool shift = mods1->shift == mods2->shift; - bool alt = mods1->alt == mods2->alt; - bool ctrl = mods1->ctrl == mods2->ctrl; - bool super = mods1->super == mods2->super; - return shift && alt && ctrl && super; + if (tll_length(*mods1) != tll_length(*mods2)) + return false; + + size_t count = 0; + tll_foreach(*mods1, it1) { + size_t skip = count; + tll_foreach(*mods2, it2) { + if (skip > 0) { + skip--; + continue; + } + + if (strcmp(it1->item, it2->item) != 0) + return false; + break; + } + + count++; + } + + return true; + /* + * bool shift = mods1->shift == mods2->shift; + * bool alt = mods1->alt == mods2->alt; + * bool ctrl = mods1->ctrl == mods2->ctrl; + * bool super = mods1->super == mods2->super; + * return shift && alt && ctrl && super; + */ +} + +UNITTEST +{ + config_modifier_list_t mods1 = tll_init(); + config_modifier_list_t mods2 = tll_init(); + + tll_push_back(mods1, xstrdup("foo")); + tll_push_back(mods1, xstrdup("bar")); + + tll_push_back(mods2, xstrdup("foo")); + xassert(!modifiers_equal(&mods1, &mods2)); + + tll_push_back(mods2, xstrdup("zoo")); + xassert(!modifiers_equal(&mods1, &mods2)); + + free(tll_pop_back(mods2)); + tll_push_back(mods2, xstrdup("bar")); + xassert(modifiers_equal(&mods1, &mods2)); + + tll_free_and_free(mods1, free); + tll_free_and_free(mods2, free); } static bool -modifiers_disjoint(const struct config_key_modifiers *mods1, - const struct config_key_modifiers *mods2) +modifiers_disjoint(const config_modifier_list_t *mods1, + const config_modifier_list_t *mods2) { - bool shift = mods1->shift && mods2->shift; - bool alt = mods1->alt && mods2->alt; - bool ctrl = mods1->ctrl && mods2->ctrl; - bool super = mods1->super && mods2->super; - return !(shift || alt || ctrl || super); + return !modifiers_equal(mods1, mods2); } static char * NOINLINE -modifiers_to_str(const struct config_key_modifiers *mods) +modifiers_to_str(const config_modifier_list_t *mods) { - char *ret = xasprintf( - "%s%s%s%s", - mods->ctrl ? XKB_MOD_NAME_CTRL "+" : "", - mods->alt ? XKB_MOD_NAME_ALT "+": "", - mods->super ? XKB_MOD_NAME_LOGO "+": "", - mods->shift ? XKB_MOD_NAME_SHIFT "+": ""); + size_t len = tll_length(*mods); /* ‘+’ , and NULL terminator */ + tll_foreach(*mods, it) + len += strlen(it->item); + + char *ret = xmalloc(len); + size_t idx = 0; + tll_foreach(*mods, it) { + idx += snprintf(&ret[idx], len - idx, "%s", it->item); + ret[idx++] = '+'; + } + ret[--idx] = '\0'; return ret; } @@ -2014,10 +2049,13 @@ UNITTEST xassert(bindings.arr[0].action == TEST_ACTION_FOO); xassert(bindings.arr[1].action == TEST_ACTION_BAR); xassert(bindings.arr[1].k.sym == XKB_KEY_g); - xassert(bindings.arr[1].modifiers.ctrl); + xassert(tll_length(bindings.arr[1].modifiers) == 1); + xassert(strcmp(tll_front(bindings.arr[1].modifiers), XKB_MOD_NAME_CTRL) == 0); xassert(bindings.arr[2].action == TEST_ACTION_BAR); xassert(bindings.arr[2].k.sym == XKB_KEY_x); - xassert(bindings.arr[2].modifiers.ctrl && bindings.arr[2].modifiers.shift); + xassert(tll_length(bindings.arr[2].modifiers) == 2); + xassert(strcmp(tll_front(bindings.arr[2].modifiers), XKB_MOD_NAME_CTRL) == 0); + xassert(strcmp(tll_back(bindings.arr[2].modifiers), XKB_MOD_NAME_SHIFT) == 0); /* * REPLACE foo with foo=Mod+v Shift+q @@ -2033,10 +2071,12 @@ UNITTEST xassert(bindings.arr[1].action == TEST_ACTION_BAR); xassert(bindings.arr[2].action == TEST_ACTION_FOO); xassert(bindings.arr[2].k.sym == XKB_KEY_v); - xassert(bindings.arr[2].modifiers.alt); + xassert(tll_length(bindings.arr[2].modifiers) == 1); + xassert(strcmp(tll_front(bindings.arr[2].modifiers), XKB_MOD_NAME_ALT) == 0); xassert(bindings.arr[3].action == TEST_ACTION_FOO); xassert(bindings.arr[3].k.sym == XKB_KEY_q); - xassert(bindings.arr[3].modifiers.shift); + xassert(tll_length(bindings.arr[3].modifiers) == 1); + xassert(strcmp(tll_front(bindings.arr[3].modifiers), XKB_MOD_NAME_SHIFT) == 0); /* * REMOVE bar @@ -2103,7 +2143,7 @@ resolve_key_binding_collisions(struct config *conf, const char *section_name, struct config_key_binding *binding1 = &bindings->arr[i]; xassert(binding1->action != BIND_ACTION_NONE); - const struct config_key_modifiers *mods1 = &binding1->modifiers; + const config_modifier_list_t *mods1 = &binding1->modifiers; /* Does our modifiers collide with the selection override mods? */ if (type == MOUSE_BINDING && @@ -2127,7 +2167,7 @@ resolve_key_binding_collisions(struct config *conf, const char *section_name, continue; } - const struct config_key_modifiers *mods2 = &binding2->modifiers; + const config_modifier_list_t *mods2 = &binding2->modifiers; bool mods_equal = modifiers_equal(mods1, mods2); bool sym_equal; @@ -2252,13 +2292,9 @@ parse_section_mouse_bindings(struct context *ctx) const char *value = ctx->value; if (streq(key, "selection-override-modifiers")) { - if (!parse_modifiers( - ctx, ctx->value, strlen(value), - &conf->mouse.selection_override_modifiers)) - { - LOG_CONTEXTUAL_ERR("%s: invalid modifiers '%s'", key, ctx->value); - return false; - } + parse_modifiers( + ctx->value, strlen(value), + &conf->mouse.selection_override_modifiers); return true; } @@ -2830,37 +2866,38 @@ get_server_socket_path(void) return xasprintf("%s/foot-%s.sock", xdg_runtime, wayland_display); } -#define m_none {0} -#define m_alt {.alt = true} -#define m_ctrl {.ctrl = true} -#define m_shift {.shift = true} -#define m_ctrl_shift {.ctrl = true, .shift = true} -#define m_ctrl_shift_alt {.ctrl = true, .shift = true, .alt = true} +static config_modifier_list_t +m(const char *text) +{ + config_modifier_list_t ret = tll_init(); + parse_modifiers(text, strlen(text), &ret); + return ret; +} static void add_default_key_bindings(struct config *conf) { - static const struct config_key_binding bindings[] = { - {BIND_ACTION_SCROLLBACK_UP_PAGE, m_shift, {{XKB_KEY_Prior}}}, - {BIND_ACTION_SCROLLBACK_DOWN_PAGE, m_shift, {{XKB_KEY_Next}}}, - {BIND_ACTION_CLIPBOARD_COPY, m_ctrl_shift, {{XKB_KEY_c}}}, - {BIND_ACTION_CLIPBOARD_COPY, m_none, {{XKB_KEY_XF86Copy}}}, - {BIND_ACTION_CLIPBOARD_PASTE, m_ctrl_shift, {{XKB_KEY_v}}}, - {BIND_ACTION_CLIPBOARD_PASTE, m_none, {{XKB_KEY_XF86Paste}}}, - {BIND_ACTION_PRIMARY_PASTE, m_shift, {{XKB_KEY_Insert}}}, - {BIND_ACTION_SEARCH_START, m_ctrl_shift, {{XKB_KEY_r}}}, - {BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_plus}}}, - {BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_equal}}}, - {BIND_ACTION_FONT_SIZE_UP, m_ctrl, {{XKB_KEY_KP_Add}}}, - {BIND_ACTION_FONT_SIZE_DOWN, m_ctrl, {{XKB_KEY_minus}}}, - {BIND_ACTION_FONT_SIZE_DOWN, m_ctrl, {{XKB_KEY_KP_Subtract}}}, - {BIND_ACTION_FONT_SIZE_RESET, m_ctrl, {{XKB_KEY_0}}}, - {BIND_ACTION_FONT_SIZE_RESET, m_ctrl, {{XKB_KEY_KP_0}}}, - {BIND_ACTION_SPAWN_TERMINAL, m_ctrl_shift, {{XKB_KEY_n}}}, - {BIND_ACTION_SHOW_URLS_LAUNCH, m_ctrl_shift, {{XKB_KEY_o}}}, - {BIND_ACTION_UNICODE_INPUT, m_ctrl_shift, {{XKB_KEY_u}}}, - {BIND_ACTION_PROMPT_PREV, m_ctrl_shift, {{XKB_KEY_z}}}, - {BIND_ACTION_PROMPT_NEXT, m_ctrl_shift, {{XKB_KEY_x}}}, + const struct config_key_binding bindings[] = { + {BIND_ACTION_SCROLLBACK_UP_PAGE, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Prior}}}, + {BIND_ACTION_SCROLLBACK_DOWN_PAGE, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Next}}}, + {BIND_ACTION_CLIPBOARD_COPY, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_c}}}, + {BIND_ACTION_CLIPBOARD_COPY, m("none"), {{XKB_KEY_XF86Copy}}}, + {BIND_ACTION_CLIPBOARD_PASTE, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_v}}}, + {BIND_ACTION_CLIPBOARD_PASTE, m("none"), {{XKB_KEY_XF86Paste}}}, + {BIND_ACTION_PRIMARY_PASTE, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Insert}}}, + {BIND_ACTION_SEARCH_START, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_r}}}, + {BIND_ACTION_FONT_SIZE_UP, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_plus}}}, + {BIND_ACTION_FONT_SIZE_UP, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_equal}}}, + {BIND_ACTION_FONT_SIZE_UP, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_KP_Add}}}, + {BIND_ACTION_FONT_SIZE_DOWN, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_minus}}}, + {BIND_ACTION_FONT_SIZE_DOWN, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_KP_Subtract}}}, + {BIND_ACTION_FONT_SIZE_RESET, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_0}}}, + {BIND_ACTION_FONT_SIZE_RESET, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_KP_0}}}, + {BIND_ACTION_SPAWN_TERMINAL, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_n}}}, + {BIND_ACTION_SHOW_URLS_LAUNCH, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_o}}}, + {BIND_ACTION_UNICODE_INPUT, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_u}}}, + {BIND_ACTION_PROMPT_PREV, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_z}}}, + {BIND_ACTION_PROMPT_NEXT, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_x}}}, }; conf->bindings.key.count = ALEN(bindings); @@ -2872,46 +2909,47 @@ add_default_key_bindings(struct config *conf) static void add_default_search_bindings(struct config *conf) { - static const struct config_key_binding bindings[] = { - {BIND_ACTION_SEARCH_SCROLLBACK_UP_PAGE, m_shift, {{XKB_KEY_Prior}}}, - {BIND_ACTION_SEARCH_SCROLLBACK_DOWN_PAGE, m_shift, {{XKB_KEY_Next}}}, - {BIND_ACTION_SEARCH_CANCEL, m_ctrl, {{XKB_KEY_c}}}, - {BIND_ACTION_SEARCH_CANCEL, m_ctrl, {{XKB_KEY_g}}}, - {BIND_ACTION_SEARCH_CANCEL, m_none, {{XKB_KEY_Escape}}}, - {BIND_ACTION_SEARCH_COMMIT, m_none, {{XKB_KEY_Return}}}, - {BIND_ACTION_SEARCH_FIND_PREV, m_ctrl, {{XKB_KEY_r}}}, - {BIND_ACTION_SEARCH_FIND_NEXT, m_ctrl, {{XKB_KEY_s}}}, - {BIND_ACTION_SEARCH_EDIT_LEFT, m_none, {{XKB_KEY_Left}}}, - {BIND_ACTION_SEARCH_EDIT_LEFT, m_ctrl, {{XKB_KEY_b}}}, - {BIND_ACTION_SEARCH_EDIT_LEFT_WORD, m_ctrl, {{XKB_KEY_Left}}}, - {BIND_ACTION_SEARCH_EDIT_LEFT_WORD, m_alt, {{XKB_KEY_b}}}, - {BIND_ACTION_SEARCH_EDIT_RIGHT, m_none, {{XKB_KEY_Right}}}, - {BIND_ACTION_SEARCH_EDIT_RIGHT, m_ctrl, {{XKB_KEY_f}}}, - {BIND_ACTION_SEARCH_EDIT_RIGHT_WORD, m_ctrl, {{XKB_KEY_Right}}}, - {BIND_ACTION_SEARCH_EDIT_RIGHT_WORD, m_alt, {{XKB_KEY_f}}}, - {BIND_ACTION_SEARCH_EDIT_HOME, m_none, {{XKB_KEY_Home}}}, - {BIND_ACTION_SEARCH_EDIT_HOME, m_ctrl, {{XKB_KEY_a}}}, - {BIND_ACTION_SEARCH_EDIT_END, m_none, {{XKB_KEY_End}}}, - {BIND_ACTION_SEARCH_EDIT_END, m_ctrl, {{XKB_KEY_e}}}, - {BIND_ACTION_SEARCH_DELETE_PREV, m_none, {{XKB_KEY_BackSpace}}}, - {BIND_ACTION_SEARCH_DELETE_PREV_WORD, m_ctrl, {{XKB_KEY_BackSpace}}}, - {BIND_ACTION_SEARCH_DELETE_PREV_WORD, m_alt, {{XKB_KEY_BackSpace}}}, - {BIND_ACTION_SEARCH_DELETE_NEXT, m_none, {{XKB_KEY_Delete}}}, - {BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m_ctrl, {{XKB_KEY_Delete}}}, - {BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m_alt, {{XKB_KEY_d}}}, - {BIND_ACTION_SEARCH_EXTEND_CHAR, m_shift, {{XKB_KEY_Right}}}, - {BIND_ACTION_SEARCH_EXTEND_WORD, m_ctrl, {{XKB_KEY_w}}}, - {BIND_ACTION_SEARCH_EXTEND_WORD, m_ctrl_shift, {{XKB_KEY_Right}}}, - {BIND_ACTION_SEARCH_EXTEND_WORD_WS, m_ctrl_shift, {{XKB_KEY_w}}}, - {BIND_ACTION_SEARCH_EXTEND_LINE_DOWN, m_shift, {{XKB_KEY_Down}}}, - {BIND_ACTION_SEARCH_EXTEND_BACKWARD_CHAR, m_shift, {{XKB_KEY_Left}}}, - {BIND_ACTION_SEARCH_EXTEND_BACKWARD_WORD, m_ctrl_shift, {{XKB_KEY_Left}}}, - {BIND_ACTION_SEARCH_EXTEND_LINE_UP, m_shift, {{XKB_KEY_Up}}}, - {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_ctrl, {{XKB_KEY_v}}}, - {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_ctrl_shift, {{XKB_KEY_v}}}, - {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_ctrl, {{XKB_KEY_y}}}, - {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m_none, {{XKB_KEY_XF86Paste}}}, - {BIND_ACTION_SEARCH_PRIMARY_PASTE, m_shift, {{XKB_KEY_Insert}}}, + const struct config_key_binding bindings[] = { + {BIND_ACTION_SEARCH_SCROLLBACK_UP_PAGE, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Prior}}}, + {BIND_ACTION_SEARCH_SCROLLBACK_DOWN_PAGE, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Next}}}, + {BIND_ACTION_SEARCH_CANCEL, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_c}}}, + {BIND_ACTION_SEARCH_CANCEL, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_g}}}, + {BIND_ACTION_SEARCH_CANCEL, m("none"), {{XKB_KEY_Escape}}}, + {BIND_ACTION_SEARCH_COMMIT, m("none"), {{XKB_KEY_Return}}}, + {BIND_ACTION_SEARCH_FIND_PREV, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_r}}}, + {BIND_ACTION_SEARCH_FIND_NEXT, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_s}}}, + {BIND_ACTION_SEARCH_EDIT_LEFT, m("none"), {{XKB_KEY_Left}}}, + {BIND_ACTION_SEARCH_EDIT_LEFT, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_b}}}, + {BIND_ACTION_SEARCH_EDIT_LEFT_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_Left}}}, + {BIND_ACTION_SEARCH_EDIT_LEFT_WORD, m(XKB_MOD_NAME_ALT), {{XKB_KEY_b}}}, + {BIND_ACTION_SEARCH_EDIT_RIGHT, m("none"), {{XKB_KEY_Right}}}, + {BIND_ACTION_SEARCH_EDIT_RIGHT, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_f}}}, + {BIND_ACTION_SEARCH_EDIT_RIGHT_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_Right}}}, + {BIND_ACTION_SEARCH_EDIT_RIGHT_WORD, m(XKB_MOD_NAME_ALT), {{XKB_KEY_f}}}, + {BIND_ACTION_SEARCH_EDIT_HOME, m("none"), {{XKB_KEY_Home}}}, + {BIND_ACTION_SEARCH_EDIT_HOME, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_a}}}, + {BIND_ACTION_SEARCH_EDIT_END, m("none"), {{XKB_KEY_End}}}, + {BIND_ACTION_SEARCH_EDIT_END, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_e}}}, + {BIND_ACTION_SEARCH_DELETE_PREV, m("none"), {{XKB_KEY_BackSpace}}}, + {BIND_ACTION_SEARCH_DELETE_PREV_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_BackSpace}}}, + {BIND_ACTION_SEARCH_DELETE_PREV_WORD, m(XKB_MOD_NAME_ALT), {{XKB_KEY_BackSpace}}}, + {BIND_ACTION_SEARCH_DELETE_NEXT, m("none"), {{XKB_KEY_Delete}}}, + {BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_Delete}}}, + {BIND_ACTION_SEARCH_DELETE_NEXT_WORD, m(XKB_MOD_NAME_ALT), {{XKB_KEY_d}}}, + {BIND_ACTION_SEARCH_EXTEND_CHAR, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Right}}}, + {BIND_ACTION_SEARCH_EXTEND_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_w}}}, + {BIND_ACTION_SEARCH_EXTEND_WORD, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_Right}}}, + {BIND_ACTION_SEARCH_EXTEND_WORD, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_w}}}, + {BIND_ACTION_SEARCH_EXTEND_WORD_WS, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_w}}}, + {BIND_ACTION_SEARCH_EXTEND_LINE_DOWN, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Down}}}, + {BIND_ACTION_SEARCH_EXTEND_BACKWARD_CHAR, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Left}}}, + {BIND_ACTION_SEARCH_EXTEND_BACKWARD_WORD, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_Left}}}, + {BIND_ACTION_SEARCH_EXTEND_LINE_UP, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Up}}}, + {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_v}}}, + {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m(XKB_MOD_NAME_CTRL "+" XKB_MOD_NAME_SHIFT), {{XKB_KEY_v}}}, + {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_y}}}, + {BIND_ACTION_SEARCH_CLIPBOARD_PASTE, m("none"), {{XKB_KEY_XF86Paste}}}, + {BIND_ACTION_SEARCH_PRIMARY_PASTE, m(XKB_MOD_NAME_SHIFT), {{XKB_KEY_Insert}}}, }; conf->bindings.search.count = ALEN(bindings); @@ -2922,12 +2960,12 @@ add_default_search_bindings(struct config *conf) static void add_default_url_bindings(struct config *conf) { - static const struct config_key_binding bindings[] = { - {BIND_ACTION_URL_CANCEL, m_ctrl, {{XKB_KEY_c}}}, - {BIND_ACTION_URL_CANCEL, m_ctrl, {{XKB_KEY_g}}}, - {BIND_ACTION_URL_CANCEL, m_ctrl, {{XKB_KEY_d}}}, - {BIND_ACTION_URL_CANCEL, m_none, {{XKB_KEY_Escape}}}, - {BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL, m_none, {{XKB_KEY_t}}}, + const struct config_key_binding bindings[] = { + {BIND_ACTION_URL_CANCEL, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_c}}}, + {BIND_ACTION_URL_CANCEL, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_g}}}, + {BIND_ACTION_URL_CANCEL, m(XKB_MOD_NAME_CTRL), {{XKB_KEY_d}}}, + {BIND_ACTION_URL_CANCEL, m("none"), {{XKB_KEY_Escape}}}, + {BIND_ACTION_URL_TOGGLE_URL_ON_JUMP_LABEL, m("none"), {{XKB_KEY_t}}}, }; conf->bindings.url.count = ALEN(bindings); @@ -2938,18 +2976,18 @@ add_default_url_bindings(struct config *conf) static void add_default_mouse_bindings(struct config *conf) { - static const struct config_key_binding bindings[] = { - {BIND_ACTION_SCROLLBACK_UP_MOUSE, m_none, {.m = {BTN_BACK, 1}}}, - {BIND_ACTION_SCROLLBACK_DOWN_MOUSE, m_none, {.m = {BTN_FORWARD, 1}}}, - {BIND_ACTION_PRIMARY_PASTE, m_none, {.m = {BTN_MIDDLE, 1}}}, - {BIND_ACTION_SELECT_BEGIN, m_none, {.m = {BTN_LEFT, 1}}}, - {BIND_ACTION_SELECT_BEGIN_BLOCK, m_ctrl, {.m = {BTN_LEFT, 1}}}, - {BIND_ACTION_SELECT_EXTEND, m_none, {.m = {BTN_RIGHT, 1}}}, - {BIND_ACTION_SELECT_EXTEND_CHAR_WISE, m_ctrl, {.m = {BTN_RIGHT, 1}}}, - {BIND_ACTION_SELECT_WORD, m_none, {.m = {BTN_LEFT, 2}}}, - {BIND_ACTION_SELECT_WORD_WS, m_ctrl, {.m = {BTN_LEFT, 2}}}, - {BIND_ACTION_SELECT_QUOTE, m_none, {.m = {BTN_LEFT, 3}}}, - {BIND_ACTION_SELECT_ROW, m_none, {.m = {BTN_LEFT, 4}}}, + const struct config_key_binding bindings[] = { + {BIND_ACTION_SCROLLBACK_UP_MOUSE, m("none"), {.m = {BTN_BACK, 1}}}, + {BIND_ACTION_SCROLLBACK_DOWN_MOUSE, m("none"), {.m = {BTN_FORWARD, 1}}}, + {BIND_ACTION_PRIMARY_PASTE, m("none"), {.m = {BTN_MIDDLE, 1}}}, + {BIND_ACTION_SELECT_BEGIN, m("none"), {.m = {BTN_LEFT, 1}}}, + {BIND_ACTION_SELECT_BEGIN_BLOCK, m(XKB_MOD_NAME_CTRL), {.m = {BTN_LEFT, 1}}}, + {BIND_ACTION_SELECT_EXTEND, m("none"), {.m = {BTN_RIGHT, 1}}}, + {BIND_ACTION_SELECT_EXTEND_CHAR_WISE, m(XKB_MOD_NAME_CTRL), {.m = {BTN_RIGHT, 1}}}, + {BIND_ACTION_SELECT_WORD, m("none"), {.m = {BTN_LEFT, 2}}}, + {BIND_ACTION_SELECT_WORD_WS, m(XKB_MOD_NAME_CTRL), {.m = {BTN_LEFT, 2}}}, + {BIND_ACTION_SELECT_QUOTE, m("none"), {.m = {BTN_LEFT, 3}}}, + {BIND_ACTION_SELECT_ROW, m("none"), {.m = {BTN_LEFT, 4}}}, }; conf->bindings.mouse.count = ALEN(bindings); @@ -3064,12 +3102,7 @@ config_load(struct config *conf, const char *conf_path, .mouse = { .hide_when_typing = false, .alternate_scroll_mode = true, - .selection_override_modifiers = { - .shift = true, - .alt = false, - .ctrl = false, - .super = false, - }, + .selection_override_modifiers = tll_init(), }, .csd = { .preferred = CONF_CSD_PREFER_SERVER, @@ -3125,6 +3158,7 @@ config_load(struct config *conf, const char *conf_path, }; memcpy(conf->colors.table, default_color_table, sizeof(default_color_table)); + parse_modifiers(XKB_MOD_NAME_SHIFT, 5, &conf->mouse.selection_override_modifiers); tokenize_cmdline("notify-send -a ${app-id} -i ${app-id} ${title} ${body}", &conf->notify.argv.args); @@ -3324,6 +3358,9 @@ key_binding_list_clone(struct config_key_binding_list *dst, struct config_key_binding *new = &dst->arr[i]; *new = *old; + memset(&new->modifiers, 0, sizeof(new->modifiers)); + tll_foreach(old->modifiers, it) + tll_push_back(new->modifiers, xstrdup(it->item)); switch (old->aux.type) { case BINDING_AUX_NONE: @@ -3399,6 +3436,11 @@ config_clone(const struct config *old) conf->env_vars.length = 0; conf->env_vars.head = conf->env_vars.tail = NULL; + + memset(&conf->mouse.selection_override_modifiers, 0, sizeof(conf->mouse.selection_override_modifiers)); + tll_foreach(old->mouse.selection_override_modifiers, it) + tll_push_back(conf->mouse.selection_override_modifiers, xstrdup(it->item)); + tll_foreach(old->env_vars, it) { struct env_var copy = { .name = xstrdup(it->item.name), @@ -3431,13 +3473,13 @@ UNITTEST bool ret = config_load(&original, "/dev/null", ¬s, &overrides, false, false); xassert(ret); - struct config *clone = config_clone(&original); - xassert(clone != NULL); - xassert(clone != &original); + //struct config *clone = config_clone(&original); + //xassert(clone != NULL); + //xassert(clone != &original); config_free(&original); - config_free(clone); - free(clone); + //config_free(clone); + //free(clone); fcft_fini(); @@ -3473,6 +3515,7 @@ config_free(struct config *conf) free_key_binding_list(&conf->bindings.search); free_key_binding_list(&conf->bindings.url); free_key_binding_list(&conf->bindings.mouse); + tll_free_and_free(conf->mouse.selection_override_modifiers, free); tll_foreach(conf->env_vars, it) { free(it->item.name); @@ -3603,6 +3646,7 @@ check_if_font_is_monospaced(const char *pattern, return is_monospaced; } +#if 0 xkb_mod_mask_t conf_modifiers_to_mask(const struct seat *seat, const struct config_key_modifiers *modifiers) @@ -3618,3 +3662,4 @@ conf_modifiers_to_mask(const struct seat *seat, mods |= modifiers->super << seat->kbd.mod_super; return mods; } +#endif diff --git a/config.h b/config.h index cc4094c4..39f169f9 100644 --- a/config.h +++ b/config.h @@ -38,12 +38,14 @@ struct config_font { }; DEFINE_LIST(struct config_font); +#if 0 struct config_key_modifiers { bool shift; bool alt; bool ctrl; bool super; }; +#endif struct argv { char **args; @@ -74,9 +76,12 @@ enum key_binding_type { MOUSE_BINDING, }; +typedef tll(char *) config_modifier_list_t; + struct config_key_binding { int action; /* One of the varios bind_action_* enums from wayland.h */ - struct config_key_modifiers modifiers; + //struct config_key_modifiers modifiers; + config_modifier_list_t modifiers; union { /* Key bindings */ struct { @@ -263,7 +268,8 @@ struct config { struct { bool hide_when_typing; bool alternate_scroll_mode; - struct config_key_modifiers selection_override_modifiers; + //struct config_key_modifiers selection_override_modifiers; + config_modifier_list_t selection_override_modifiers; } mouse; struct { @@ -375,10 +381,11 @@ struct config *config_clone(const struct config *old); bool config_font_parse(const char *pattern, struct config_font *font); void config_font_list_destroy(struct config_font_list *font_list); +#if 0 struct seat; xkb_mod_mask_t conf_modifiers_to_mask( const struct seat *seat, const struct config_key_modifiers *modifiers); - +#endif bool check_if_font_is_monospaced( const char *pattern, user_notifications_t *notifications); diff --git a/input.c b/input.c index 25addf9b..97c95a92 100644 --- a/input.c +++ b/input.c @@ -579,22 +579,33 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, seat->kbd.mod_caps = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_CAPS); seat->kbd.mod_num = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_MOD_NAME_NUM); - seat->kbd.bind_significant = 0; + /* Significant modifiers in the legacy keyboard protocol */ + seat->kbd.legacy_significant = 0; if (seat->kbd.mod_shift != XKB_MOD_INVALID) - seat->kbd.bind_significant |= 1 << seat->kbd.mod_shift; + seat->kbd.legacy_significant |= 1 << seat->kbd.mod_shift; if (seat->kbd.mod_alt != XKB_MOD_INVALID) - seat->kbd.bind_significant |= 1 << seat->kbd.mod_alt; + seat->kbd.legacy_significant |= 1 << seat->kbd.mod_alt; if (seat->kbd.mod_ctrl != XKB_MOD_INVALID) - seat->kbd.bind_significant |= 1 << seat->kbd.mod_ctrl; + seat->kbd.legacy_significant |= 1 << seat->kbd.mod_ctrl; if (seat->kbd.mod_super != XKB_MOD_INVALID) - seat->kbd.bind_significant |= 1 << seat->kbd.mod_super; + seat->kbd.legacy_significant |= 1 << seat->kbd.mod_super; - seat->kbd.kitty_significant = seat->kbd.bind_significant; + /* Significant modifiers in the kitty keyboard protocol */ + seat->kbd.kitty_significant = seat->kbd.legacy_significant; if (seat->kbd.mod_caps != XKB_MOD_INVALID) seat->kbd.kitty_significant |= 1 << seat->kbd.mod_caps; if (seat->kbd.mod_num != XKB_MOD_INVALID) seat->kbd.kitty_significant |= 1 << seat->kbd.mod_num; + /* Significant modifiers when handling shortcuts - use all available */ + seat->kbd.bind_significant = 0; + const xkb_mod_index_t mod_count = xkb_keymap_num_mods(seat->kbd.xkb_keymap); + for (xkb_mod_index_t i = 0; i < mod_count; i++) { + LOG_DBG("significant modifier: %s", + xkb_keymap_mod_get_name(seat->kbd.xkb_keymap, i)); + seat->kbd.bind_significant |= 1 << i; + } + seat->kbd.key_arrow_up = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "UP"); seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN"); } @@ -985,7 +996,7 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, /* Any modifiers, besides shift active? */ const xkb_mod_mask_t shift_mask = 1 << seat->kbd.mod_shift; - if ((ctx->mods & ~shift_mask & seat->kbd.bind_significant) != 0) + if ((ctx->mods & ~shift_mask & seat->kbd.legacy_significant) != 0) modify_other_keys2_in_effect = true; else { @@ -1527,7 +1538,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, #if 0 for (size_t i = 0; i < 32; i++) { - if (mods & (1 << i)) { + if (mods & (1u << i)) { LOG_INFO("%s", xkb_keymap_mod_get_name(seat->kbd.xkb_keymap, i)); } } @@ -1555,6 +1566,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, bind->mods == (bind_mods & ~bind_consumed) && execute_binding(seat, term, bind, serial, 1)) { + LOG_WARN("matched translated symbol"); goto maybe_repeat; } @@ -1566,6 +1578,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (bind->k.sym == raw_syms[i] && execute_binding(seat, term, bind, serial, 1)) { + LOG_WARN("matched untranslated symbol"); goto maybe_repeat; } } @@ -1575,6 +1588,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (code->item == key && execute_binding(seat, term, bind, serial, 1)) { + LOG_WARN("matched raw key code"); goto maybe_repeat; } } @@ -2293,8 +2307,7 @@ static const struct key_binding * continue; } - const struct config_key_modifiers no_mods = {0}; - if (memcmp(&binding->modifiers, &no_mods, sizeof(no_mods)) != 0) { + if (tll_length(binding->modifiers) > 0) { /* Binding has modifiers */ continue; } diff --git a/key-binding.c b/key-binding.c index 1dffd3ee..a7738da8 100644 --- a/key-binding.c +++ b/key-binding.c @@ -404,6 +404,24 @@ sort_binding_list(key_binding_list_t *list) tll_sort(*list, key_cmp); } +static xkb_mod_mask_t +mods_to_mask(const struct seat *seat, const config_modifier_list_t *mods) +{ + xkb_mod_mask_t mask = 0; + tll_foreach(*mods, it) { + xkb_mod_index_t idx = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, it->item); + + if (idx == XKB_MOD_INVALID) { + LOG_ERR("%s: invalid modifier name", it->item); + continue; + } + + mask |= 1 << idx; + } + + return mask; +} + static void NOINLINE convert_key_binding(struct key_set *set, const struct config_key_binding *conf_binding, @@ -411,7 +429,7 @@ convert_key_binding(struct key_set *set, { const struct seat *seat = set->seat; - xkb_mod_mask_t mods = conf_modifiers_to_mask(seat, &conf_binding->modifiers); + xkb_mod_mask_t mods = mods_to_mask(seat, &conf_binding->modifiers); xkb_keysym_t sym = maybe_repair_key_combo(seat, conf_binding->k.sym, mods); struct key_binding binding = { @@ -469,7 +487,7 @@ convert_mouse_binding(struct key_set *set, .type = MOUSE_BINDING, .action = conf_binding->action, .aux = &conf_binding->aux, - .mods = conf_modifiers_to_mask(set->seat, &conf_binding->modifiers), + .mods = mods_to_mask(set->seat, &conf_binding->modifiers), .m = { .button = conf_binding->m.button, .count = conf_binding->m.count, @@ -509,7 +527,7 @@ load_keymap(struct key_set *set) convert_url_bindings(set); convert_mouse_bindings(set); - set->public.selection_overrides = conf_modifiers_to_mask( + set->public.selection_overrides = mods_to_mask( set->seat, &set->conf->mouse.selection_override_modifiers); } diff --git a/tests/test-config.c b/tests/test-config.c index 182dd4f6..b54dd23e 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -787,6 +787,17 @@ test_section_csd(void) config_free(&conf); } +static bool +have_modifier(const config_modifier_list_t *mods, const char *mod) +{ + tll_foreach(*mods, it) { + if (strcmp(it->item, mod) == 0) + return true; + } + + return false; +} + static void test_key_binding(struct context *ctx, bool (*parse_fun)(struct context *ctx), int action, int max_action, const char *const *map, @@ -904,17 +915,19 @@ test_key_binding(struct context *ctx, bool (*parse_fun)(struct context *ctx), ctx->section, ctx->key, ctx->value, binding->action, action); } - if (binding->modifiers.ctrl != ctrl || - binding->modifiers.alt != alt || - binding->modifiers.shift != shift || - binding->modifiers.super != super) + bool have_ctrl = have_modifier(&binding->modifiers, XKB_MOD_NAME_CTRL); + bool have_alt = have_modifier(&binding->modifiers, XKB_MOD_NAME_ALT); + bool have_shift = have_modifier(&binding->modifiers, XKB_MOD_NAME_SHIFT); + bool have_super = have_modifier(&binding->modifiers, XKB_MOD_NAME_LOGO); + + if (have_ctrl != ctrl || have_alt != alt || + have_shift != shift || have_super != super) { BUG("[%s].%s=%s: modifier mismatch:\n" " have: ctrl=%d, alt=%d, shift=%d, super=%d\n" " expected: ctrl=%d, alt=%d, shift=%d, super=%d", ctx->section, ctx->key, ctx->value, - binding->modifiers.ctrl, binding->modifiers.alt, - binding->modifiers.shift, binding->modifiers.super, + have_ctrl, have_alt, have_shift, have_super, ctrl, alt, shift, super); } @@ -970,14 +983,17 @@ _test_binding_collisions(struct context *ctx, bindings.arr[0] = (struct config_key_binding){ .action = (test_mode == FAIL_DIFFERENT_ACTION ? max_action - 1 : max_action), - .modifiers = {.ctrl = true}, + .modifiers = tll_init(), .path = "unittest", }; + tll_push_back(bindings.arr[0].modifiers, xstrdup(XKB_MOD_NAME_CTRL)); + bindings.arr[1] = (struct config_key_binding){ .action = max_action, - .modifiers = {.ctrl = true}, + .modifiers = tll_init(), .path = "unittest", }; + tll_push_back(bindings.arr[1].modifiers, xstrdup(XKB_MOD_NAME_CTRL)); switch (type) { case KEY_BINDING: @@ -998,7 +1014,8 @@ _test_binding_collisions(struct context *ctx, break; case FAIL_MOUSE_OVERRIDE: - ctx->conf->mouse.selection_override_modifiers.ctrl = true; + tll_free_and_free(ctx->conf->mouse.selection_override_modifiers, free); + tll_push_back(ctx->conf->mouse.selection_override_modifiers, xstrdup(XKB_MOD_NAME_CTRL)); break; case FAIL_DIFFERENT_ARGV: @@ -1237,10 +1254,13 @@ test_section_text_bindings(void) ctx.key = "\\y"; xassert(!parse_section_text_bindings(&ctx)); +#if 0 + /* Invalid modifier and key names are detected later, when a + * layout is applied */ ctx.key = "abcd"; ctx.value = "InvalidMod+y"; xassert(!parse_section_text_bindings(&ctx)); - +#endif config_free(&conf); } diff --git a/wayland.h b/wayland.h index 145e480d..3551dd60 100644 --- a/wayland.h +++ b/wayland.h @@ -128,8 +128,9 @@ struct seat { xkb_mod_index_t mod_caps; xkb_mod_index_t mod_num; - xkb_mod_mask_t bind_significant; - xkb_mod_mask_t kitty_significant; + xkb_mod_mask_t bind_significant; /* Significant modifiers for shortcut handling */ + xkb_mod_mask_t legacy_significant; /* Significant modifiers for the legacy keyboard protocol */ + xkb_mod_mask_t kitty_significant; /* Significant modifiers for the kitty keyboard protocol */ xkb_keycode_t key_arrow_up; xkb_keycode_t key_arrow_down; From 0aefc2c65de8cca39ddbf9d8c12f1a4d4206b42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 10:41:01 +0100 Subject: [PATCH 22/50] input: remove the concept of "significant" modifiers For the purpose of matching key bindings, "significant" modifiers are no more. We're really only interested in filtering out "locked" modifiers. We're already doing this, so there's no need to *also* match against a set of "significant" modifiers. Furthermore, we *never* want to consider locked keys (e.g. when emitting escapes to the client application), thus we can filter those out already when retrieving the set of active modifiers. The exception is the kitty keyboard protocol, which has support for CapsLock and NumLock. Since we're already re-retrieving the "consumed" modifiers (using the GTK style, rather than normal "XKB" style, to better match the kitty terminal), we might as well re-retrieve the effective modifiers as well. --- input.c | 52 +++++++++++++++++++++------------------------------- input.h | 2 +- search.c | 9 ++------- search.h | 1 - terminal.c | 2 +- url-mode.c | 12 +++--------- url-mode.h | 1 - wayland.h | 1 - 8 files changed, 28 insertions(+), 52 deletions(-) diff --git a/input.c b/input.c index 97c95a92..dc0eec93 100644 --- a/input.c +++ b/input.c @@ -597,15 +597,6 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, if (seat->kbd.mod_num != XKB_MOD_INVALID) seat->kbd.kitty_significant |= 1 << seat->kbd.mod_num; - /* Significant modifiers when handling shortcuts - use all available */ - seat->kbd.bind_significant = 0; - const xkb_mod_index_t mod_count = xkb_keymap_num_mods(seat->kbd.xkb_keymap); - for (xkb_mod_index_t i = 0; i < mod_count; i++) { - LOG_DBG("significant modifier: %s", - xkb_keymap_mod_get_name(seat->kbd.xkb_keymap, i)); - seat->kbd.bind_significant |= 1 << i; - } - seat->kbd.key_arrow_up = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "UP"); seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN"); } @@ -887,7 +878,8 @@ UNITTEST void get_current_modifiers(const struct seat *seat, xkb_mod_mask_t *effective, - xkb_mod_mask_t *consumed, uint32_t key) + xkb_mod_mask_t *consumed, uint32_t key, + bool filter_locked) { if (unlikely(seat->kbd.xkb_state == NULL)) { if (effective != NULL) @@ -897,24 +889,27 @@ get_current_modifiers(const struct seat *seat, } else { + const xkb_mod_mask_t locked = + xkb_state_serialize_mods(seat->kbd.xkb_state, XKB_STATE_MODS_LOCKED); + if (effective != NULL) { *effective = xkb_state_serialize_mods( seat->kbd.xkb_state, XKB_STATE_MODS_EFFECTIVE); + + if (filter_locked) + *effective &= ~locked; } if (consumed != NULL) { *consumed = xkb_state_key_get_consumed_mods2( seat->kbd.xkb_state, key, XKB_CONSUMED_MODE_XKB); + + if (filter_locked) + *consumed &= ~locked; } } } -static xkb_mod_mask_t -get_locked_modifiers(const struct seat *seat) -{ - return xkb_state_serialize_mods(seat->kbd.xkb_state, XKB_STATE_MODS_LOCKED); -} - struct kbd_ctx { xkb_layout_index_t layout; xkb_keycode_t key; @@ -1184,7 +1179,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, xkb_state_update_key( seat->kbd.xkb_state, ctx->key, pressed ? XKB_KEY_DOWN : XKB_KEY_UP); - get_current_modifiers(seat, &mods, NULL, ctx->key); + get_current_modifiers(seat, &mods, NULL, ctx->key, false); consumed = xkb_state_key_get_consumed_mods2( seat->kbd.xkb_state, ctx->key, XKB_CONSUMED_MODE_GTK); @@ -1201,7 +1196,9 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, seat->kbd.xkb_state, ctx->key, pressed ? XKB_KEY_UP : XKB_KEY_DOWN); #endif } else { - mods = ctx->mods; + /* Same as ctx->mods, but without locked modifiers being + filtered out */ + get_current_modifiers(seat, &mods, NULL, ctx->key, false); /* Re-retrieve the consumed modifiers using the GTK mode, to better match kitty. */ @@ -1490,13 +1487,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, const bool composed = compose_status == XKB_COMPOSE_COMPOSED; xkb_mod_mask_t mods, consumed; - get_current_modifiers(seat, &mods, &consumed, key); - - const xkb_mod_mask_t locked = get_locked_modifiers(seat); - const xkb_mod_mask_t bind_mods - = mods & seat->kbd.bind_significant & ~locked; - const xkb_mod_mask_t bind_consumed = - consumed & seat->kbd.bind_significant & ~locked; + get_current_modifiers(seat, &mods, &consumed, key, true); xkb_layout_index_t layout_idx = xkb_state_key_get_layout(seat->kbd.xkb_state, key); @@ -1520,7 +1511,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, start_repeater(seat, key); search_input( - seat, term, bindings, key, sym, mods, consumed, locked, + seat, term, bindings, key, sym, mods, consumed, raw_syms, raw_count, serial); return; } @@ -1530,7 +1521,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, start_repeater(seat, key); urls_input( - seat, term, bindings, key, sym, mods, consumed, locked, + seat, term, bindings, key, sym, mods, consumed, raw_syms, raw_count, serial); return; } @@ -1563,14 +1554,14 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, /* Match translated symbol */ if (bind->k.sym == sym && - bind->mods == (bind_mods & ~bind_consumed) && + bind->mods == (mods & ~consumed) && execute_binding(seat, term, bind, serial, 1)) { LOG_WARN("matched translated symbol"); goto maybe_repeat; } - if (bind->mods != bind_mods || bind_mods != (mods & ~locked)) + if (bind->mods != mods) continue; /* Match untranslated symbols */ @@ -2253,8 +2244,7 @@ static const struct key_binding * xassert(bindings != NULL); xkb_mod_mask_t mods; - get_current_modifiers(seat, &mods, NULL, 0); - mods &= seat->kbd.bind_significant; + get_current_modifiers(seat, &mods, NULL, 0, true); /* Ignore selection override modifiers when * matching modifiers */ diff --git a/input.h b/input.h index 906008d5..001d116f 100644 --- a/input.h +++ b/input.h @@ -33,6 +33,6 @@ void input_repeat(struct seat *seat, uint32_t key); void get_current_modifiers(const struct seat *seat, xkb_mod_mask_t *effective, xkb_mod_mask_t *consumed, - uint32_t key); + uint32_t key, bool filter_locked); enum cursor_shape xcursor_for_csd_border(struct terminal *term, int x, int y); diff --git a/search.c b/search.c index 55388577..10541884 100644 --- a/search.c +++ b/search.c @@ -1374,17 +1374,12 @@ void search_input(struct seat *seat, struct terminal *term, const struct key_binding_set *bindings, uint32_t key, xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed, - xkb_mod_mask_t locked, const xkb_keysym_t *raw_syms, size_t raw_count, uint32_t serial) { LOG_DBG("search: input: sym=%d/0x%x, mods=0x%08x, consumed=0x%08x", sym, sym, mods, consumed); - const xkb_mod_mask_t bind_mods = - mods & seat->kbd.bind_significant & ~locked; - const xkb_mod_mask_t bind_consumed = - consumed & seat->kbd.bind_significant & ~locked; enum xkb_compose_status compose_status = seat->kbd.xkb_compose_state != NULL ? xkb_compose_state_get_status(seat->kbd.xkb_compose_state) : XKB_COMPOSE_NOTHING; @@ -1399,7 +1394,7 @@ search_input(struct seat *seat, struct terminal *term, /* Match translated symbol */ if (bind->k.sym == sym && - bind->mods == (bind_mods & ~bind_consumed)) { + bind->mods == (mods & ~consumed)) { if (execute_binding(seat, term, bind, serial, &update_search_result, &search_direction, @@ -1410,7 +1405,7 @@ search_input(struct seat *seat, struct terminal *term, return; } - if (bind->mods != bind_mods || bind_mods != (mods & ~locked)) + if (bind->mods != mods) continue; /* Match untranslated symbols */ diff --git a/search.h b/search.h index d5d4162b..ee8ecd76 100644 --- a/search.h +++ b/search.h @@ -11,7 +11,6 @@ void search_input( struct seat *seat, struct terminal *term, const struct key_binding_set *bindings, uint32_t key, xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed, - xkb_mod_mask_t locked, const xkb_keysym_t *raw_syms, size_t raw_count, uint32_t serial); void search_add_chars(struct terminal *term, const char *text, size_t len); diff --git a/terminal.c b/terminal.c index b0120c6a..f63aaaa7 100644 --- a/terminal.c +++ b/terminal.c @@ -3039,7 +3039,7 @@ term_mouse_grabbed(const struct terminal *term, const struct seat *seat) */ xkb_mod_mask_t mods; - get_current_modifiers(seat, &mods, NULL, 0); + get_current_modifiers(seat, &mods, NULL, 0, true); const struct key_binding_set *bindings = key_binding_for(term->wl->key_binding_manager, term->conf, seat); diff --git a/url-mode.c b/url-mode.c index 1b28f8e0..07499794 100644 --- a/url-mode.c +++ b/url-mode.c @@ -145,28 +145,22 @@ void urls_input(struct seat *seat, struct terminal *term, const struct key_binding_set *bindings, uint32_t key, xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed, - xkb_mod_mask_t locked, const xkb_keysym_t *raw_syms, size_t raw_count, uint32_t serial) { - const xkb_mod_mask_t bind_mods = - mods & seat->kbd.bind_significant & ~locked; - const xkb_mod_mask_t bind_consumed = - consumed & seat->kbd.bind_significant & ~locked; - /* Key bindings */ tll_foreach(bindings->url, it) { const struct key_binding *bind = &it->item; /* Match translated symbol */ if (bind->k.sym == sym && - bind->mods == (bind_mods & ~bind_consumed)) + bind->mods == (mods & ~consumed)) { execute_binding(seat, term, bind, serial); return; } - if (bind->mods != bind_mods || bind_mods != (mods & ~locked)) + if (bind->mods != mods) continue; for (size_t i = 0; i < raw_count; i++) { @@ -196,7 +190,7 @@ urls_input(struct seat *seat, struct terminal *term, return; } - if (mods & ~consumed & ~locked) + if (mods & ~consumed) return; char32_t wc = xkb_state_key_get_utf32(seat->kbd.xkb_state, key); diff --git a/url-mode.h b/url-mode.h index abfcb57b..eefe07c0 100644 --- a/url-mode.h +++ b/url-mode.h @@ -23,6 +23,5 @@ void urls_reset(struct terminal *term); void urls_input(struct seat *seat, struct terminal *term, const struct key_binding_set *bindings, uint32_t key, xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed, - xkb_mod_mask_t locked, const xkb_keysym_t *raw_syms, size_t raw_count, uint32_t serial); diff --git a/wayland.h b/wayland.h index 3551dd60..733ebd3f 100644 --- a/wayland.h +++ b/wayland.h @@ -128,7 +128,6 @@ struct seat { xkb_mod_index_t mod_caps; xkb_mod_index_t mod_num; - xkb_mod_mask_t bind_significant; /* Significant modifiers for shortcut handling */ xkb_mod_mask_t legacy_significant; /* Significant modifiers for the legacy keyboard protocol */ xkb_mod_mask_t kitty_significant; /* Significant modifiers for the kitty keyboard protocol */ From 1685f38ee65972f3768896445afb53d0a6886689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 11:10:36 +0100 Subject: [PATCH 23/50] changelog: custom modifiers in key bindings --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e95557..2233fd9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,10 @@ numlock is ignored. * A new `resize-by-cells` option, enabled by default, allows the size of floating windows to be constrained to multiples of the cell size. +* Support for custom (i.e. other than ctrl/shift/alt/super) modifiers + in key bindings ([#1348][1348]). + +[1348]: https://codeberg.org/dnkl/foot/issues/1348 ### Changed From f8e875a7cddaac91818b98993d17a96d09a5b4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 10:35:30 +0100 Subject: [PATCH 24/50] term: move row->prompt_marker into new struct, row->shell_integration --- grid.c | 10 +++++----- input.c | 4 ++-- osc.c | 2 +- terminal.c | 2 +- terminal.h | 5 +++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/grid.c b/grid.c index ea103c65..19322cbf 100644 --- a/grid.c +++ b/grid.c @@ -231,7 +231,7 @@ grid_snapshot(const struct grid *grid) clone_row->cells = xmalloc(grid->num_cols * sizeof(clone_row->cells[0])); clone_row->linebreak = row->linebreak; clone_row->dirty = row->dirty; - clone_row->prompt_marker = row->prompt_marker; + clone_row->shell_integration = row->shell_integration; for (int c = 0; c < grid->num_cols; c++) clone_row->cells[c] = row->cells[c]; @@ -366,7 +366,7 @@ grid_row_alloc(int cols, bool initialize) row->dirty = false; row->linebreak = false; row->extra = NULL; - row->prompt_marker = false; + row->shell_integration.prompt_marker = false; if (initialize) { row->cells = xcalloc(cols, sizeof(row->cells[0])); @@ -425,7 +425,7 @@ grid_resize_without_reflow( new_row->dirty = old_row->dirty; new_row->linebreak = false; - new_row->prompt_marker = old_row->prompt_marker; + new_row->shell_integration = old_row->shell_integration; if (new_cols > old_cols) { /* Clear "new" columns */ @@ -587,7 +587,7 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row, /* Scrollback is full, need to reuse a row */ grid_row_reset_extra(new_row); new_row->linebreak = false; - new_row->prompt_marker = false; + new_row->shell_integration.prompt_marker = false; tll_foreach(old_grid->sixel_images, it) { if (it->item.pos.row == *row_idx) { @@ -920,7 +920,7 @@ grid_resize_and_reflow( xassert(from + amount <= old_cols); if (from == 0) - new_row->prompt_marker = old_row->prompt_marker; + new_row->shell_integration = old_row->shell_integration; memcpy( &new_row->cells[new_col_idx], &old_row->cells[from], diff --git a/input.c b/input.c index dc0eec93..5cdf513f 100644 --- a/input.c +++ b/input.c @@ -377,7 +377,7 @@ execute_binding(struct seat *seat, struct terminal *term, const struct row *row = grid->rows[r_abs]; xassert(row != NULL); - if (!row->prompt_marker) + if (!row->shell_integration.prompt_marker) continue; grid->view = r_abs; @@ -409,7 +409,7 @@ execute_binding(struct seat *seat, struct terminal *term, const struct row *row = grid->rows[r_abs]; xassert(row != NULL); - if (!row->prompt_marker) { + if (!row->shell_integration.prompt_marker) { if (r_abs == grid->offset + term->rows - 1) { /* We’ve reached the bottom of the scrollback */ break; diff --git a/osc.c b/osc.c index ba08964c..a54946ff 100644 --- a/osc.c +++ b/osc.c @@ -893,7 +893,7 @@ osc_dispatch(struct terminal *term) term->grid->cursor.point.row, term->grid->cursor.point.col); - term->grid->cur_row->prompt_marker = true; + term->grid->cur_row->shell_integration.prompt_marker = true; break; case 'B': diff --git a/terminal.c b/terminal.c index f63aaaa7..33666e6a 100644 --- a/terminal.c +++ b/terminal.c @@ -1825,7 +1825,7 @@ erase_line(struct terminal *term, struct row *row) { erase_cell_range(term, row, 0, term->cols - 1); row->linebreak = false; - row->prompt_marker = false; + row->shell_integration.prompt_marker = false; } void diff --git a/terminal.h b/terminal.h index 0dca0f48..76b52566 100644 --- a/terminal.h +++ b/terminal.h @@ -121,8 +121,9 @@ struct row { bool dirty; bool linebreak; - /* Shell integration */ - bool prompt_marker; + struct { + bool prompt_marker; + } shell_integration; }; struct sixel { From e9607de5ae2eaf1a57924bb282a660150eca6eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 10:46:46 +0100 Subject: [PATCH 25/50] osc: store column of FTCS_COMMAND_{EXECUTED,FINISHED} in row struct --- grid.c | 4 ++++ osc.c | 10 ++++++++-- terminal.c | 2 ++ terminal.h | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/grid.c b/grid.c index 19322cbf..f14580ad 100644 --- a/grid.c +++ b/grid.c @@ -367,6 +367,8 @@ grid_row_alloc(int cols, bool initialize) row->linebreak = false; row->extra = NULL; row->shell_integration.prompt_marker = false; + row->shell_integration.cmd_start = -1; + row->shell_integration.cmd_end = -1; if (initialize) { row->cells = xcalloc(cols, sizeof(row->cells[0])); @@ -588,6 +590,8 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row, grid_row_reset_extra(new_row); new_row->linebreak = false; new_row->shell_integration.prompt_marker = false; + new_row->shell_integration.cmd_start = -1; + new_row->shell_integration.cmd_end = -1; tll_foreach(old_grid->sixel_images, it) { if (it->item.pos.row == *row_idx) { diff --git a/osc.c b/osc.c index a54946ff..5da8666f 100644 --- a/osc.c +++ b/osc.c @@ -901,11 +901,17 @@ osc_dispatch(struct terminal *term) break; case 'C': - LOG_DBG("FTCS_COMMAND_EXECUTED"); + LOG_DBG("FTCS_COMMAND_EXECUTED: %dx%d", + term->grid->cursor.point.row, + term->grid->cursor.point.col); + term->grid->cur_row->shell_integration.cmd_start = term->grid->cursor.point.col; break; case 'D': - LOG_DBG("FTCS_COMMAND_FINISHED"); + LOG_DBG("FTCS_COMMAND_FINISHED: %dx%d", + term->grid->cursor.point.row, + term->grid->cursor.point.col); + term->grid->cur_row->shell_integration.cmd_end = term->grid->cursor.point.col; break; } break; diff --git a/terminal.c b/terminal.c index 33666e6a..4152724a 100644 --- a/terminal.c +++ b/terminal.c @@ -1826,6 +1826,8 @@ erase_line(struct terminal *term, struct row *row) erase_cell_range(term, row, 0, term->cols - 1); row->linebreak = false; row->shell_integration.prompt_marker = false; + row->shell_integration.cmd_start = -1; + row->shell_integration.cmd_end = -1; } void diff --git a/terminal.h b/terminal.h index 76b52566..1e3a724e 100644 --- a/terminal.h +++ b/terminal.h @@ -123,6 +123,8 @@ struct row { struct { bool prompt_marker; + int cmd_start; /* Column, -1 if unset */ + int cmd_end; /* Column, -1 if unset */ } shell_integration; }; From 1c70a84fde80405e0b6658722af8bc3fb54f225d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 11:45:23 +0100 Subject: [PATCH 26/50] config: add pipe-command-output key-binding --- config.c | 1 + input.c | 7 +++- key-binding.h | 1 + terminal.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++--- terminal.h | 2 ++ 5 files changed, 99 insertions(+), 5 deletions(-) diff --git a/config.c b/config.c index e3d531c2..3728826f 100644 --- a/config.c +++ b/config.c @@ -111,6 +111,7 @@ static const char *const binding_action_map[] = { [BIND_ACTION_PIPE_SCROLLBACK] = "pipe-scrollback", [BIND_ACTION_PIPE_VIEW] = "pipe-visible", [BIND_ACTION_PIPE_SELECTED] = "pipe-selected", + [BIND_ACTION_PIPE_COMMAND_OUTPUT] = "pipe-command-output", [BIND_ACTION_SHOW_URLS_COPY] = "show-urls-copy", [BIND_ACTION_SHOW_URLS_LAUNCH] = "show-urls-launch", [BIND_ACTION_SHOW_URLS_PERSISTENT] = "show-urls-persistent", diff --git a/input.c b/input.c index 5cdf513f..166ad70b 100644 --- a/input.c +++ b/input.c @@ -227,7 +227,8 @@ execute_binding(struct seat *seat, struct terminal *term, break; /* FALLTHROUGH */ case BIND_ACTION_PIPE_VIEW: - case BIND_ACTION_PIPE_SELECTED: { + case BIND_ACTION_PIPE_SELECTED: + case BIND_ACTION_PIPE_COMMAND_OUTPUT: { if (binding->aux->type != BINDING_AUX_PIPE) return true; @@ -269,6 +270,10 @@ execute_binding(struct seat *seat, struct terminal *term, len = text != NULL ? strlen(text) : 0; break; + case BIND_ACTION_PIPE_COMMAND_OUTPUT: + success = term_command_output_to_text(term, &text, &len); + break; + default: BUG("Unhandled action type"); success = false; diff --git a/key-binding.h b/key-binding.h index 050c80a6..ba841efa 100644 --- a/key-binding.h +++ b/key-binding.h @@ -32,6 +32,7 @@ enum bind_action_normal { BIND_ACTION_PIPE_SCROLLBACK, BIND_ACTION_PIPE_VIEW, BIND_ACTION_PIPE_SELECTED, + BIND_ACTION_PIPE_COMMAND_OUTPUT, BIND_ACTION_SHOW_URLS_COPY, BIND_ACTION_SHOW_URLS_LAUNCH, BIND_ACTION_SHOW_URLS_PERSISTENT, diff --git a/terminal.c b/terminal.c index 4152724a..a328783f 100644 --- a/terminal.c +++ b/terminal.c @@ -3613,7 +3613,7 @@ term_surface_kind(const struct terminal *term, const struct wl_surface *surface) static bool rows_to_text(const struct terminal *term, int start, int end, - char **text, size_t *len) + int col_start, int col_end, char **text, size_t *len) { struct extraction_context *ctx = extract_begin(SELECTION_NONE, true); if (ctx == NULL) @@ -3626,15 +3626,20 @@ rows_to_text(const struct terminal *term, int start, int end, const struct row *row = term->grid->rows[r]; xassert(row != NULL); - for (int c = 0; c < term->cols; c++) + const int c_end = r == end ? col_end : term->cols; + + for (int c = col_start; c < c_end; c++) { if (!extract_one(term, row, &row->cells[c], c, ctx)) goto out; + } if (r == end) break; r++; r &= grid_rows - 1; + + col_start = 0; } out: @@ -3666,7 +3671,7 @@ term_scrollback_to_text(const struct terminal *term, char **text, size_t *len) end += term->grid->num_rows; } - return rows_to_text(term, start, end, text, len); + return rows_to_text(term, start, end, 0, term->cols, text, len); } bool @@ -3674,7 +3679,87 @@ term_view_to_text(const struct terminal *term, char **text, size_t *len) { int start = grid_row_absolute_in_view(term->grid, 0); int end = grid_row_absolute_in_view(term->grid, term->rows - 1); - return rows_to_text(term, start, end, text, len); + return rows_to_text(term, start, end, 0, term->cols, text, len); +} + +bool +term_command_output_to_text(const struct terminal *term, char **text, size_t *len) +{ + int start_row = -1; + int end_row = -1; + int start_col = -1; + int end_col = -1; + + const struct grid *grid = term->grid; + const int sb_end = grid_row_absolute(grid, term->rows - 1); + int r = (sb_end - 1 + grid->num_rows) & (grid->num_rows - 1); + + while (start_row < 0 && r != sb_end) { + const struct row *row = grid->rows[r]; + if (row == NULL) + break; + + if (row->shell_integration.cmd_end >= 0) { + end_row = r; + end_col = row->shell_integration.cmd_end; + } + + if (end_row >= 0 && row->shell_integration.cmd_start >= 0) { + start_row = r; + start_col = row->shell_integration.cmd_start; + } + + r = (r - 1 + grid->num_rows) & (grid->num_rows - 1); + } + + if (start_row < 0) + return false; + + bool ret = rows_to_text(term, start_row, end_row, start_col, end_col, text, len); + if (!ret) + return false; + + /* + * If the FTCS_COMMAND_FINISHED marker was emitted at the *first* + * column, then the *entire* previous line is part of the command + * output. *Including* the newline, if any. + * + * Since rows_to_text() doesn’t extract the column + * FTCS_COMMAND_FINISHED was emitted at (that would be wrong - + * FTCS_COMMAND_FINISHED is emitted *after* the command output, + * not at its last character), the extraction logic will not see + * the last newline (this is true for all non-line-wise selection + * types), and the extracted text will *not* end with a newline. + * + * Here we try to compensate for that. Note that if ‘end_col’ is + * not 0, then the command output only covers a partial row, and + * thus we do *not* want to append a newline. + */ + + if (end_col > 0) { + /* Command output covers partial row - don’t append newline */ + return true; + } + + int next_to_last_row = (end_row - 1 + grid->num_rows) & (grid->num_rows - 1); + const struct row *row = grid->rows[next_to_last_row]; + + /* Add newline if last row has a hard linebreak */ + if (row->linebreak) { + char *new_text = xrealloc(*text, *len + 1 + 1); + + if (new_text == NULL) { + /* Ignore failure - use text as is (without inserting newline) */ + return true; + } + + *text = new_text; + (*len)++; + (*text)[*len - 1] = '\n'; + (*text)[*len] = '\0'; + } + + return true; } bool diff --git a/terminal.h b/terminal.h index 1e3a724e..35127e3c 100644 --- a/terminal.h +++ b/terminal.h @@ -847,6 +847,8 @@ bool term_scrollback_to_text( const struct terminal *term, char **text, size_t *len); bool term_view_to_text( const struct terminal *term, char **text, size_t *len); +bool term_command_output_to_text( + const struct terminal *term, char **text, size_t *len); bool term_ime_is_enabled(const struct terminal *term); void term_ime_enable(struct terminal *term); From f2a8368759f5968eff460ca2f30d600cbcc26839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 11:45:51 +0100 Subject: [PATCH 27/50] foot.ini: add pipe-command-output key binding --- foot.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/foot.ini b/foot.ini index 55eb42de..42a71e58 100644 --- a/foot.ini +++ b/foot.ini @@ -158,6 +158,7 @@ # pipe-visible=[sh -c "xurls | fuzzel | xargs -r firefox"] none # pipe-scrollback=[sh -c "xurls | fuzzel | xargs -r firefox"] none # pipe-selected=[xargs -r firefox] none +# pipe-command-output=[sh -c "cat - > /tmp/foot-cmd-out.txt"] none # Write output of last command to /tmp/foot-cmd-out.txt (requires shell integration) # show-urls-launch=Control+Shift+o # show-urls-copy=none # show-urls-persistent=none From 0fed2451eae01922c8fcbb40ab35b32ac3d655a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 11:50:43 +0100 Subject: [PATCH 28/50] doc: foot.ini: document pipe-command-output --- doc/foot.ini.5.scd | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 1c87db53..14999a8b 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -844,11 +844,12 @@ e.g. *search-start=none*. *fullscreen* Toggles the fullscreen state. Default: _none_. -*pipe-visible*, *pipe-scrollback*, *pipe-selected* - Pipes the currently visible text, the entire scrollback, or the - currently selected text to an external tool. The syntax for this - option is a bit special; the first part of the value is the - command to execute enclosed in "[]", followed by the binding(s). +*pipe-visible*, *pipe-scrollback*, *pipe-selected*, *pipe-command-output* + Pipes the currently visible text, the entire scrollback, the + currently selected text, or the last command's output to an + external tool. The syntax for this option is a bit special; the + first part of the value is the command to execute enclosed in + "[]", followed by the binding(s). You can configure multiple pipes as long as the command strings are different and the key bindings are unique. @@ -856,10 +857,17 @@ e.g. *search-start=none*. Note that the command is *not* automatically run inside a shell; use *sh -c "command line"* if you need that. - Example: - *pipe-visible=[sh -c "xurls | uniq | tac | fuzzel | xargs -r + Example #1: + + # Extract currently visible URLs, let user choose one (via + fuzzel), then launch firefox with the selected URL++ +*pipe-visible=[sh -c "xurls | uniq | tac | fuzzel | xargs -r firefox"] Control+Print* + Example #2: + # Write scrollback content to /tmp/foot-scrollback.txt++ +*pipe-scrollback=[sh -c "cat - > /tmp/foot-scrollback.txt"] + Control+Shift+Print* Default: _none_ *show-urls-launch* From d7dbb91e65d375e2ea496ea7a921bfcd9e3d8c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 11:51:27 +0100 Subject: [PATCH 29/50] changelog: pipe-command-output --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2233fd9e..55ac7e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ of floating windows to be constrained to multiples of the cell size. * Support for custom (i.e. other than ctrl/shift/alt/super) modifiers in key bindings ([#1348][1348]). +* `pipe-command-output` key binding. [1348]: https://codeberg.org/dnkl/foot/issues/1348 From 1393942de38fa6ece726fd861cc15e2a5a369fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 12:17:55 +0100 Subject: [PATCH 30/50] readme, doc/foot.1: document shell-integration:command-output tracking --- README.md | 36 ++++++++++++++++++++++++++++++++++++ doc/foot.1.scd | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/README.md b/README.md index b1cfb37d..c1be7476 100644 --- a/README.md +++ b/README.md @@ -359,6 +359,42 @@ See the [wiki](https://codeberg.org/dnkl/foot/wiki#user-content-jumping-between-prompts) for details, and examples for other shells. +### Piping last command’s output + +The key binding `pipe-command-output` can pipe the last command’s +output to an application of your choice (similar to the other `pipe-*` +key bindings): + +```ini +[key-bindings] +pipe-command-output=[sh -c "f=$(mktemp); cat - > $f; footclient emacsclient -nw $f; rm $f"] Control+Shift+g +``` + +When pressing ctrl+shift+g, the last +command’s output is written to a temporary file, then an emacsclient +is started in a new footclient instance. The temporary file is removed +after the footclient instance has closed. + +For this to work, the shell must emit an OSC-133;C (`\E]133;C\E\\`) +sequence before command output starts, and an OSC-133;D +(`\E]133;D\E\\`) when the command output ends. + +In fish, one way to do this is to add `preexec` and `postexec` hooks: + +```fish +function foot_cmd_start --on-event fish_preexec + echo -en "\e]133;C\e\\" +end + +function foot_cmd_end --on-event fish_postexec + echo -en "\e]133;D\e\\" +end +``` + +See the +[wiki](https://codeberg.org/dnkl/foot/wiki#user-content-piping-last-commands-output) +for details, and examples for other shells + ## Alt/meta diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 385f9721..8e2fb313 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -424,6 +424,38 @@ See the wiki (https://codeberg.org/dnkl/foot/wiki#user-content-jumping-between-prompts) for details, and examples for other shells. +## Piping last command’s output + +The key binding *pipe-command-output* can pipe the last command’s +output to an application of your choice (similar to the other +*pipe-\** key bindings): + + *\[key-bindings\]++ +pipe-command-output=[sh -c "f=$(mktemp); cat - > $f; footclient emacsclient -nw $f; rm $f"] Control+Shift+g* + +When pressing *ctrl*+*shift*+*g*, the last command’s output is written +to a temporary file, then an emacsclient is started in a new +footclient instance. The temporary file is removed after the +footclient instance has closed. + +For this to work, the shell must emit an OSC-133;C (*\\E]133;C\\E\\\\*) +sequence before command output starts, and an OSC-133;D +(*\\E]133;D\\E\\\\*) when the command output ends. + +In fish, one way to do this is to add _preexec_ and _postexec_ hooks: + + *function foot_cmd_start --on-event fish_preexec + echo -en "\\e]133;C\\e\\\\" + end* + + *function foot_cmd_end --on-event fish_postexec + echo -en "\\e]133;D\\e\\\\" + end* + +See the wiki +(https://codeberg.org/dnkl/foot/wiki#user-content-piping-last-commands-output) +for details, and examples for other shells + # TERMINFO Client applications use the terminfo identifier specified by the From d5308a0493bb69167aacf54a8eb98f2e92a046dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 13:06:24 +0100 Subject: [PATCH 31/50] =?UTF-8?q?term:=20command=5Foutput=5Fto=5Ftext():?= =?UTF-8?q?=20don=E2=80=99t=20skip=20FTCS=5FCOMMAND=5FFINISHED=20on=20last?= =?UTF-8?q?=20row?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terminal.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/terminal.c b/terminal.c index a328783f..5d6c956d 100644 --- a/terminal.c +++ b/terminal.c @@ -3692,9 +3692,10 @@ term_command_output_to_text(const struct terminal *term, char **text, size_t *le const struct grid *grid = term->grid; const int sb_end = grid_row_absolute(grid, term->rows - 1); - int r = (sb_end - 1 + grid->num_rows) & (grid->num_rows - 1); + const int sb_start = (sb_end + 1) & (grid->num_rows - 1); + int r = sb_end; - while (start_row < 0 && r != sb_end) { + while (start_row < 0) { const struct row *row = grid->rows[r]; if (row == NULL) break; @@ -3709,6 +3710,9 @@ term_command_output_to_text(const struct terminal *term, char **text, size_t *le start_col = row->shell_integration.cmd_start; } + if (r == sb_start) + break; + r = (r - 1 + grid->num_rows) & (grid->num_rows - 1); } From 110a6dd6f080686f85df9dff16fbb06fe2f57a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 13:49:38 +0100 Subject: [PATCH 32/50] grid: resize without reflow: truncate shell_integration.cmd_{start,end} This ensures the cmd start/end columns are valid in the new grid. --- grid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grid.c b/grid.c index f14580ad..e0e357dc 100644 --- a/grid.c +++ b/grid.c @@ -427,7 +427,9 @@ grid_resize_without_reflow( new_row->dirty = old_row->dirty; new_row->linebreak = false; - new_row->shell_integration = old_row->shell_integration; + new_row->shell_integration.prompt_marker = old_row->shell_integration.prompt_marker; + new_row->shell_integration.cmd_start = min(old_row->shell_integration.cmd_start, new_cols - 1); + new_row->shell_integration.cmd_end = min(old_row->shell_integration.cmd_end, new_cols - 1); if (new_cols > old_cols) { /* Clear "new" columns */ From 231e6eb3f10c80ce6fb151d44814504c3ce00e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Dec 2022 13:50:30 +0100 Subject: [PATCH 33/50] grid: resize with reflow: reflow FTCS_COMMAND_{EXECUTED,FINISHED} --- grid.c | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/grid.c b/grid.c index e0e357dc..e7cdedc5 100644 --- a/grid.c +++ b/grid.c @@ -1,5 +1,6 @@ #include "grid.h" +#include #include #include @@ -837,35 +838,26 @@ grid_resize_and_reflow( int end; bool tp_break = false; bool uri_break = false; + bool ftcs_break = false; - /* - * Set end-coordinate for this chunk, by finding the next - * point-of-interest on this row. - * - * If there are no more tracking points, or URI ranges, - * the end-coordinate will be at the end of the row, - */ - if (range != range_terminator) { - int uri_col = (range->start >= start ? range->start : range->end) + 1; + /* Figure out where to end this chunk */ + { + const int uri_col = range != range_terminator + ? ((range->start >= start ? range->start : range->end) + 1) + : INT_MAX; + const int tp_col = tp != NULL ? tp->col + 1 : INT_MAX; + const int ftcs_col = old_row->shell_integration.cmd_start >= start + ? old_row->shell_integration.cmd_start + 1 + : old_row->shell_integration.cmd_end >= start + ? old_row->shell_integration.cmd_end + 1 + : INT_MAX; - if (tp != NULL) { - int tp_col = tp->col + 1; - end = min(tp_col, uri_col); + end = min(col_count, min(min(tp_col, uri_col), ftcs_col)); - tp_break = end == tp_col; - uri_break = end == uri_col; - LOG_DBG("tp+uri break at %d (%d, %d)", end, tp_col, uri_col); - } else { - end = uri_col; - uri_break = true; - LOG_DBG("uri break at %d", end); - } - } else if (tp != NULL) { - end = tp->col + 1; - tp_break = true; - LOG_DBG("TP break at %d", end); - } else - end = col_count; + uri_break = end == uri_col; + tp_break = end == tp_col; + ftcs_break = end == ftcs_col; + } int cols = end - start; xassert(cols > 0); @@ -926,7 +918,7 @@ grid_resize_and_reflow( xassert(from + amount <= old_cols); if (from == 0) - new_row->shell_integration = old_row->shell_integration; + new_row->shell_integration.prompt_marker = old_row->shell_integration.prompt_marker; memcpy( &new_row->cells[new_col_idx], &old_row->cells[from], @@ -985,6 +977,16 @@ grid_resize_and_reflow( } } + if (ftcs_break) { + xassert(old_row->shell_integration.cmd_start == start + cols - 1 || + old_row->shell_integration.cmd_end == start + cols - 1); + + if (old_row->shell_integration.cmd_start == start + cols - 1) + new_row->shell_integration.cmd_start = new_col_idx - 1; + if (old_row->shell_integration.cmd_end == start + cols - 1) + new_row->shell_integration.cmd_end = new_col_idx - 1; + } + left -= cols; start += cols; } From 84e681f02873a1848dd2de681de49c602e982a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 12:14:48 +0100 Subject: [PATCH 34/50] readme: add "Piping last command's output" to index --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c1be7476..f54070ea 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ The fast, lightweight and minimalistic Wayland terminal emulator. 1. [Shell integration](#shell-integration) 1. [Current working directory](#current-working-directory) 1. [Jumping between prompts](#jumping-between-prompts) + 1. [Piping last command's output](#piping-last-command-s-output) 1. [Alt/meta](#alt-meta) 1. [Backspace](#backspace) 1. [Keypad](#keypad) From d6939dd6340afd0dd2bc83c235fa192e9dc25ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 12:26:00 +0100 Subject: [PATCH 35/50] readme: shell integration: fix wiki link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f54070ea..1d073dfb 100644 --- a/README.md +++ b/README.md @@ -393,7 +393,7 @@ end ``` See the -[wiki](https://codeberg.org/dnkl/foot/wiki#user-content-piping-last-commands-output) +[wiki](https://codeberg.org/dnkl/foot/wiki#user-content-piping-last-command-s-output) for details, and examples for other shells From 7999975016a57cc0a2c2e20bc55f29de32df7044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 12:36:45 +0100 Subject: [PATCH 36/50] Don't use fancy Unicode quotes, stick to ASCII --- CHANGELOG.md | 98 +++++++++++++++++------------------ INSTALL.md | 32 ++++++------ README.md | 34 ++++++------ box-drawing.c | 2 +- commands.c | 2 +- config.c | 10 ++-- config.h | 2 +- csi.c | 8 +-- dcs.c | 8 +-- doc/foot.1.scd | 22 ++++---- grid.c | 32 ++++++------ input.c | 62 +++++++++++----------- input.h | 4 +- key-binding.c | 36 ++++++------- kitty-keymap.h | 2 +- main.c | 2 +- notify.c | 2 +- osc.c | 6 +-- pgo/full-headless-cage.sh | 2 +- pgo/full-headless-sway.sh | 4 +- pgo/pgo.sh | 4 +- render.c | 106 +++++++++++++++++++------------------- selection.c | 38 +++++++------- shm.c | 8 +-- shm.h | 4 +- sixel.c | 16 +++--- terminal.c | 50 +++++++++--------- terminal.h | 12 ++--- url-mode.c | 20 +++---- vt.c | 20 +++---- wayland.c | 8 +-- 31 files changed, 328 insertions(+), 328 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55ac7e5c..096d43a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -378,7 +378,7 @@ * Kitty keyboard protocol: F3 is now encoded as `CSI 13~` instead of `CSI R`. The kitty keyboard protocol originally allowed F3 to be encoded as `CSI R`, but this was removed from the specification - since `CSI R` conflicts with the _”Cursor Position Report”_. + since `CSI R` conflicts with the _"Cursor Position Report"_. * `[main].utempter` renamed to `[main].utmp-helper`. The old option name is still recognized, but will log a deprecation warning. * Meson option `default-utempter-path` renamed to @@ -386,9 +386,9 @@ * Opaque sixels now retain the background opacity (when current background color is the **default** background color) ([#1360][1360]). -* Text cursor’s vertical position after emitting a sixel, when sixel +* Text cursor's vertical position after emitting a sixel, when sixel scrolling is **enabled** (the default) has been updated to match - XTerm’s, and the VT382’s behavior: the cursor is positioned **on** + XTerm's, and the VT382's behavior: the cursor is positioned **on** the last sixel row, rather than _after_ it. This allows printing sixels on the last row without scrolling up, but also means applications may have to explicitly emit a newline to ensure the @@ -484,8 +484,8 @@ ([#1188][1188]). * Bracketed paste terminfo entries (`BD`, `BE`, `PE` and `PS`, added to ncurses in 2022-12-24). Vim makes use of these. -* “Report version” terminfo entries (`XR`/`xr`). -* “Report DA2” terminfo entries (`RV`/`rv`). +* "Report version" terminfo entries (`XR`/`xr`). +* "Report DA2" terminfo entries (`RV`/`rv`). * `XF` terminfo capability (focus in/out events available). * `$TERM_PROGRAM` and `$TERM_PROGRAM_VERSION` environment variables unset in the slave process. @@ -538,12 +538,12 @@ * Crash when interactively resizing the window with a very large scrollback. * Crash when a sixel image exceeds the current sixel max height. -* Crash after reverse-scrolling (`CSI Ps T`) in the ‘normal’ +* Crash after reverse-scrolling (`CSI Ps T`) in the 'normal' (non-alternate) screen ([#1190][1190]). * Background transparency being applied to the text "behind" the cursor. Only applies to block cursor using inversed fg/bg colors. ([#1205][1205]). -* Crash when monitor’s physical size is "too small" ([#1209][1209]). +* Crash when monitor's physical size is "too small" ([#1209][1209]). * Line-height adjustment when incrementing/decrementing the font size with a user-set line-height ([#1218][1218]). * Scaling factor not being correctly applied when converting pt-or-px @@ -614,7 +614,7 @@ * Crash on buggy compositors (GNOME) that sometimes send pointer-enter events with a NULL surface. Foot now ignores these events, and the subsequent motion and leave events. -* Regression: “random” selected empty cells being highlighted as +* Regression: "random" selected empty cells being highlighted as selected when they should not. * Crash when either resizing the terminal window, or scrolling in the scrollback history ([#1074][1074]) @@ -654,7 +654,7 @@ ### Changed -* Use `$HOME` instead of `getpwuid()` to retrieve the user’s home +* Use `$HOME` instead of `getpwuid()` to retrieve the user's home directory when searching for `foot.ini`. * HT, VT and FF are no longer stripped when pasting in non-bracketed mode ([#1084][1084]). @@ -718,7 +718,7 @@ ### Added * Workaround for Sway bug [#6960][sway-6960]: scrollback search and - the OSC-555 (“flash”) escape sequence leaves dimmed (search) and + the OSC-555 ("flash") escape sequence leaves dimmed (search) and yellow (flash) artifacts ([#1046][1046]). * `Control+Shift+v` and `XF86Paste` have been added to the default set of key bindings that paste from the clipboard into the scrollback @@ -731,7 +731,7 @@ ### Changed -* Scrollback search’s `extend-to-word-boundary` no longer stops at +* Scrollback search's `extend-to-word-boundary` no longer stops at space-to-word boundaries, making selection extension feel more natural. @@ -772,7 +772,7 @@ ([#950][950]). * footclient: `-E,--client-environment` command line option. When used, the child process in the new terminal instance inherits the - environment from the footclient process instead of the server’s + environment from the footclient process instead of the server's ([#1004][1004]). * `[csd].hide-when-maximized=yes|no` option ([#1019][1019]). * Scrollback search mode now highlights all matches. @@ -828,7 +828,7 @@ * Build: missing `wayland_client` dependency in `test-config` ([#918][918]). -* “(null)” being logged as font-name (for some fonts) when warning +* "(null)" being logged as font-name (for some fonts) when warning about a non-monospaced primary font. * Rare crash when the window is resized while a mouse selection is ongoing ([#922][922]). @@ -850,7 +850,7 @@ ([#1009][1009]). * Window geometry when CSDs are enabled and CSD border width set to a non-zero value. This fixes window snapping in e.g. GNOME. -* Window size “jumping” when starting an interactive resize when CSDs +* Window size "jumping" when starting an interactive resize when CSDs are enabled, and CSD border width set to a non-zero value. * Key binding overrides on the command line having no effect with `footclient` instances ([#931][931]). @@ -916,15 +916,15 @@ * PaperColorDark and PaperColorLight themes renamed to paper-color-dark and paper-color-light, for consistency with other theme names. -* `[scrollback].multiplier` is now applied in “alternate scroll” mode, +* `[scrollback].multiplier` is now applied in "alternate scroll" mode, where scroll events are translated to fake arrow key presses on the alt screen ([#859](https://codeberg.org/dnkl/foot/issues/859)). -* The width of the block cursor’s outline in an unfocused window is - now scaled by the output scaling factor (“desktop - scaling”). Previously, it was always 1px. -* Foot will now try to change the locale to either “C.UTF-8” or - “en_US.UTF-8” if started with a non-UTF8 locale. If this fails, foot - will start, but only to display a window with an error (user’s shell +* The width of the block cursor's outline in an unfocused window is + now scaled by the output scaling factor ("desktop + scaling"). Previously, it was always 1px. +* Foot will now try to change the locale to either "C.UTF-8" or + "en_US.UTF-8" if started with a non-UTF8 locale. If this fails, foot + will start, but only to display a window with an error (user's shell is not executed). * `gettimeofday()` has been replaced with `clock_gettime()`, due to it being marked as obsolete by POSIX. @@ -952,7 +952,7 @@ ### Fixed -* Font size adjustment (“zooming”) when font is configured with a +* Font size adjustment ("zooming") when font is configured with a **pixelsize**, and `dpi-aware=no` ([#842](https://codeberg.org/dnkl/foot/issues/842)). * Key presses triggering keyboard layout switches also emitting CSI @@ -1026,7 +1026,7 @@ * Initial support for the [Kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/). Modes supported: - [Disambiguate escape codes](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) (mode `0b1`) -* “Window menu” (compositor provided) on right clicks on the CSD title +* "Window menu" (compositor provided) on right clicks on the CSD title bar. @@ -1063,7 +1063,7 @@ ### Fixed -* Regression: `letter-spacing` resulting in a “not a valid option” +* Regression: `letter-spacing` resulting in a "not a valid option" error ([#795](https://codeberg.org/dnkl/foot/issues/795)). * Regression: bad section name in configuration error messages. * Regression: `pipe-*` key bindings not being parsed correctly, @@ -1098,7 +1098,7 @@ * `[csd].border-width` and `[csd].border-color`, allowing you to configure the width and color of the CSD border. * Support for `XTMODKEYS` with `Pp=4` and `Pv=2` (_modifyOtherKeys=2_). -* `[colors].dim0-7` options, allowing you to configure custom “dim” +* `[colors].dim0-7` options, allowing you to configure custom "dim" colors ([#776](https://codeberg.org/dnkl/foot/issues/776)). @@ -1114,9 +1114,9 @@ due to the compositor not implementing a recent enough version of the `wl_seat` interface ([#779](https://codeberg.org/dnkl/foot/issues/779)). * Boolean options in `foot.ini` are now limited to - “yes|true|on|1|no|false|off|0”, Previously, anything that did not - match “yes|true|on”, or a number greater than 0, was treated as - “false”. + "yes|true|on|1|no|false|off|0", Previously, anything that did not + match "yes|true|on", or a number greater than 0, was treated as + "false". * `[scrollback].multiplier` is no longer applied when the alternate screen is in use ([#787](https://codeberg.org/dnkl/foot/issues/787)). @@ -1131,7 +1131,7 @@ ### Fixed -* ‘Sticky’ modifiers in input handling; when determining modifier +* 'Sticky' modifiers in input handling; when determining modifier state, foot was looking at **depressed** modifiers, not **effective** modifiers, like it should. * Fix crashes after enabling CSD at runtime when `csd.size` is 0. @@ -1139,7 +1139,7 @@ ([#752](https://codeberg.org/dnkl/foot/issues/752)). * Clipboard occasionally ceasing to work, until window has been re-focused ([#753](https://codeberg.org/dnkl/foot/issues/753)). -* Don’t propagate window title updates to the Wayland compositor +* Don't propagate window title updates to the Wayland compositor unless the new title is different from the old title. @@ -1159,7 +1159,7 @@ ### Changed * PGO helper scripts no longer set `LC_CTYPE=en_US.UTF-8`. But, note - that “full” PGO builds still **require** a UTF-8 locale; you need + that "full" PGO builds still **require** a UTF-8 locale; you need to set one manually in your build script ([#728](https://codeberg.org/dnkl/foot/issues/728)). @@ -1187,11 +1187,11 @@ definitions when `-Dterminfo=enabled`. * `-Dcustom-terminfo-install-location` no longer accepts `no` as a special value, to disable exporting `TERMINFO`. To achieve the same - result, simply don’t set it at all. If it _is_ set, `TERMINFO` is + result, simply don't set it at all. If it _is_ set, `TERMINFO` is still exported, like before. * The default install location for the terminfo definitions have been changed back to `${datadir}/terminfo`. -* `dpi-aware=auto`: fonts are now scaled using the monitor’s DPI only +* `dpi-aware=auto`: fonts are now scaled using the monitor's DPI only when **all** monitors have a scaling factor of one ([#714](https://codeberg.org/dnkl/foot/issues/714)). * fcft >= 3.0.0 in now required. @@ -1240,12 +1240,12 @@ terminating the client application) from 4 to 60 seconds. * When terminating the client application, foot now sends `SIGTERM` immediately after closing the PTY, instead of waiting 2 seconds. -* Foot now sends `SIGTERM`/`SIGKILL` to the client application’s process group, - instead of just to the client application’s process. +* Foot now sends `SIGTERM`/`SIGKILL` to the client application's process group, + instead of just to the client application's process. * `kmous` terminfo capability from `\E[M` to `\E[<`. * pt-or-px values (`letter-spacing`, etc) and the line thickness (`tweak.box-drawing-base-thickness`) in box drawing characters are - now translated to pixel values using the monitor’s scaling factor + now translated to pixel values using the monitor's scaling factor when `dpi-aware=no`, or `dpi-aware=auto` and the scaling factor is larger than 1 ([#680](https://codeberg.org/dnkl/foot/issues/680)). * Spawning a new terminal with a working directory that does not exist @@ -1255,7 +1255,7 @@ ### Removed * `km`/`smm`/`rmm` from terminfo; foot prefixes Alt-key combinations - with `ESC`, and not by setting the 8:th “meta” bit, regardless of + with `ESC`, and not by setting the 8:th "meta" bit, regardless of `smm`/`rmm`. While this _can_ be disabled by, resetting private mode 1036, the terminfo should reflect the **default** behavior ([#670](https://codeberg.org/dnkl/foot/issues/670)). @@ -1422,10 +1422,10 @@ For full support, the following is required: If `tweak.grapheme-shaping` has **not** been enabled, foot will neither use libutf8proc to do grapheme cluster segmentation, nor will -it use fcft’s grapheme shaping capabilities to shape combining +it use fcft's grapheme shaping capabilities to shape combining characters. -This feature is _experimental_ mostly due to the “wcwidth” problem; +This feature is _experimental_ mostly due to the "wcwidth" problem; how many cells should foot allocate for a grapheme cluster? While the answer may seem simple, the problem is that, whatever the answer is, the client application **must** come up with the **same** @@ -1503,9 +1503,9 @@ supported. * Point values in `line-height`, `letter-spacing`, `horizontal-letter-offset` and `vertical-letter-offset` are now rounded, not truncated, when translated to pixel values. -* Foot’s exit code is now -26/230 when foot itself failed to launch +* Foot's exit code is now -26/230 when foot itself failed to launch (due to invalid command line options, client application/shell not - found etc). Footclient’s exit code is -36/220 when it itself fails + found etc). Footclient's exit code is -36/220 when it itself fails to launch (e.g. bad command line option) and -26/230 when the foot server failed to instantiate a new window ([#466](https://codeberg.org/dnkl/foot/issues/466)). @@ -1558,7 +1558,7 @@ supported. resulting in PGO build failures. * Wrong colors in the 256-color cube ([#479](https://codeberg.org/dnkl/foot/issues/479)). -* Memory leak triggered by “opening” an OSC-8 URI and then resetting +* Memory leak triggered by "opening" an OSC-8 URI and then resetting the terminal without closing the URI ([#495](https://codeberg.org/dnkl/foot/issues/495)). * Assertion when emitting a sixel occupying the entire scrollback @@ -1567,7 +1567,7 @@ supported. invisible) for certain combinations of fonts and font sizes ([#503](https://codeberg.org/dnkl/foot/issues/503)). * Sixels with transparent bottom border being resized below the size - specified in _”Set Raster Attributes”_. + specified in _"Set Raster Attributes"_. * Fonts sometimes not being reloaded with the correct scaling factor when `dpi-aware=no`, or `dpi-aware=auto` with monitor(s) with a scaling factor > 1 ([#509](https://codeberg.org/dnkl/foot/issues/509)). @@ -1763,7 +1763,7 @@ supported. background color for empty pixels instead of the default background color ([#391](https://codeberg.org/dnkl/foot/issues/391)). * Sixel decoding optimized; up to 100% faster in some cases. -* Reported sixel “max geometry” from current window size, to the +* Reported sixel "max geometry" from current window size, to the configured maximum size (defaulting to 10000x10000). @@ -1862,7 +1862,7 @@ supported. * Pasting URIs from the clipboard when the source has not newline-terminated the last URI ([#291](https://codeberg.org/dnkl/foot/issues/291)). -* Sixel “current geometry” query response not being bounded by the +* Sixel "current geometry" query response not being bounded by the current window dimensions (fixes `lsix` output) * Crash on keyboard input when repeat rate was zero (i.e. no repeat). * Wrong button encoding of mouse buttons 6 and 7 in mouse events. @@ -1939,7 +1939,7 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See and `CSI ? 737769 l` disables it. This can be used to e.g. enable/disable IME when entering/leaving insert mode in vim. * `dpi-aware` option to `foot.ini`. The default, `auto`, sizes fonts - using the monitor’s DPI when output scaling has been + using the monitor's DPI when output scaling has been **disabled**. If output scaling has been **enabled**, fonts are sized using the scaling factor. DPI-only font sizing can be forced by setting `dpi-aware=yes`. Setting `dpi-aware=no` forces font @@ -2019,7 +2019,7 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See `\E[38:2...m`) can now be used _without_ the color space ID parameter. * SGR 21 no longer disables **bold**. According to ECMA-48, SGR 21 is - _”double underline_”. Foot does not (yet) implement that, but that’s + _"double underline_". Foot does not (yet) implement that, but that's no reason to implement a non-standard behavior. * `DECRQM` now returns actual state of the requested mode, instead of always returning `2`. @@ -2067,7 +2067,7 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See ([#194](https://codeberg.org/dnkl/foot/issues/194)). * Single-width characters with double-width glyphs are now allowed to overflow into neighboring cells by default. Set - **tweak.allow-overflowing-double-width-glyphs** to ‘no’ to disable + **tweak.allow-overflowing-double-width-glyphs** to 'no' to disable this. ### Fixed @@ -2271,7 +2271,7 @@ means foot can be PGO:d in e.g. sandboxed build scripts. See binding has consumed it. * Input events from getting mixed with paste data ([#101](https://codeberg.org/dnkl/foot/issues/101)). -* Missing DPI values for “some” monitors on Gnome +* Missing DPI values for "some" monitors on Gnome ([#118](https://codeberg.org/dnkl/foot/issues/118)). * Handling of multi-column composed characters while reflowing. * Escape sequences sent for key combinations with `Return`, that did diff --git a/INSTALL.md b/INSTALL.md index 22ea8067..7df8d0b8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -94,24 +94,24 @@ A note on terminfo; the terminfo database exposes terminal capabilities to the applications running inside the terminal. As such, it is important that the terminfo used reflects the actual terminal. Using the `xterm-256color` terminfo will, in many cases, -work, but I still recommend using foot’s own terminfo. There are two +work, but I still recommend using foot's own terminfo. There are two reasons for this: -* foot’s terminfo contains a couple of non-standard capabilities, +* foot's terminfo contains a couple of non-standard capabilities, used by e.g. tmux. * New capabilities added to the `xterm-256color` terminfo could potentially break foot. -* There may be future additions or changes to foot’s terminfo. +* There may be future additions or changes to foot's terminfo. -As of ncurses 2021-07-31, ncurses includes a version of foot’s +As of ncurses 2021-07-31, ncurses includes a version of foot's terminfo. **The recommendation is to use those**, and only install the -terminfo definitions from this git repo if the system’s ncurses +terminfo definitions from this git repo if the system's ncurses predates 2021-07-31. -But, note that the foot terminfo definitions in ncurses’ lack the +But, note that the foot terminfo definitions in ncurses' lack the non-standard capabilities. This mostly affects tmux; without them, `terminal-overrides` must be configured to enable truecolor -support. For this reason, it _is_ possible to install “our” terminfo +support. For this reason, it _is_ possible to install "our" terminfo definitions as well, either in a non-default location, or under a different name. @@ -124,10 +124,10 @@ details. Installing them under a different name generally works well, but will break applications that check if `$TERM == foot`. -Hence the recommendation to simply use ncurses’ terminfo definitions +Hence the recommendation to simply use ncurses' terminfo definitions if available. -If packaging “our” terminfo definitions, I recommend doing that as a +If packaging "our" terminfo definitions, I recommend doing that as a separate package, to allow them to be installed on remote systems without having to install foot itself. @@ -176,9 +176,9 @@ meson ... -Ddefault-terminfo=foot -Dterminfo-base-name=foot-extra ``` (or just leave out `-Ddefault-terminfo`, since it defaults to `foot` anyway). -Finally, `-Dcustom-terminfo-install-location` enables foot’s terminfo -to co-exist with ncurses’ version, without changing the terminfo -names. The idea is that you install foot’s terminfo to a non-standard +Finally, `-Dcustom-terminfo-install-location` enables foot's terminfo +to co-exist with ncurses' version, without changing the terminfo +names. The idea is that you install foot's terminfo to a non-standard location, for example `/usr/share/foot/terminfo`. Use `-Dcustom-terminfo-install-location` to tell foot where the terminfo is. Foot will set the environment variable `TERMINFO` to this value @@ -194,7 +194,7 @@ in the meson build. It does **not** change the default value of `TERM`, and it does **not** disable `TERMINFO`, if `-Dcustom-terminfo-install-location` has been set. Use this if packaging the terminfo definitions in a separate package (and the -build script isn’t shared with the ‘foot’ package). +build script isn't shared with the 'foot' package). Example: @@ -269,7 +269,7 @@ reason there are a number of helper scripts available. scripts in the `pgo` directory to do a complete PGO build. This script is intended to be used when doing manual builds. -Note that all “full” PGO builds (which `auto` will prefer, if +Note that all "full" PGO builds (which `auto` will prefer, if possible) **require** `LC_CTYPE` to be set to an UTF-8 locale. This is **not** done automatically. @@ -370,7 +370,7 @@ fail. The snippet above then creates an (empty) temporary file. Then, it runs a script that generates random escape sequences (if you cat -`${tmp_file}` in a terminal, you’ll see random colored characters all +`${tmp_file}` in a terminal, you'll see random colored characters all over the screen). Finally, we feed the randomly generated escape sequences to the PGO helper. This is what generates the profiling data used in the next step. @@ -450,7 +450,7 @@ sed 's/@default_terminfo@/foot/g' foot.info | \ tic -o -x -e foot,foot-direct - ``` -Where _”output-directory”_ **must** match the value passed to +Where _"output-directory"_ **must** match the value passed to `-Dcustom-terminfo-install-location` in the foot build. If `-Dcustom-terminfo-install-location` has not been set, `-o ` can simply be omitted. diff --git a/README.md b/README.md index 1d073dfb..5c8d3878 100644 --- a/README.md +++ b/README.md @@ -303,10 +303,10 @@ Foot supports URL detection. But, unlike many other terminal emulators, where URLs are highlighted when they are hovered and opened by clicking on them, foot uses a keyboard driven approach. -Pressing ctrl+shift+o enters _“URL -mode”_, where all currently visible URLs are underlined, and is -associated with a _“jump-label”_. The jump-label indicates the _key -sequence_ (e.g. **”AF”**) to use to activate the URL. +Pressing ctrl+shift+o enters _"URL +mode"_, where all currently visible URLs are underlined, and is +associated with a _"jump-label"_. The jump-label indicates the _key +sequence_ (e.g. **"AF"**) to use to activate the URL. The key binding can, of course, be customized, like all other key bindings in foot. See `show-urls-launch` and `show-urls-copy` in the @@ -329,7 +329,7 @@ the jump label key sequences can be configured. New foot terminal instances (bound to ctrl+shift+n by default) will open in -the current working directory, **if** the shell in the “parent” +the current working directory, **if** the shell in the "parent" terminal reports directory changes. This is done with the OSC-7 escape sequence. Most shells can be @@ -360,9 +360,9 @@ See the [wiki](https://codeberg.org/dnkl/foot/wiki#user-content-jumping-between-prompts) for details, and examples for other shells. -### Piping last command’s output +### Piping last command's output -The key binding `pipe-command-output` can pipe the last command’s +The key binding `pipe-command-output` can pipe the last command's output to an application of your choice (similar to the other `pipe-*` key bindings): @@ -372,7 +372,7 @@ pipe-command-output=[sh -c "f=$(mktemp); cat - > $f; footclient emacsclient -nw ``` When pressing ctrl+shift+g, the last -command’s output is written to a temporary file, then an emacsclient +command's output is written to a temporary file, then an emacsclient is started in a new footclient instance. The temporary file is removed after the footclient instance has closed. @@ -472,19 +472,19 @@ multiplied. For this reason, and because of the new _fractional scaling_ protocol (see below for details), and because this is how Wayland applications are expected to behave, foot >= 1.15 will default to scaling fonts -using the compositor’s scaling factor, and **not** the monitor +using the compositor's scaling factor, and **not** the monitor DPI. This means the (assuming the monitors are at the same viewing distance) the font size will appear to change when you move the foot window across different monitors, **unless** you have configured the -monitors’ scaling factors correctly in the compositor. +monitors' scaling factors correctly in the compositor. This can be changed by setting the `dpi-aware` option to `yes` in `foot.ini`. When enabled, fonts will **not** be sized using the -scaling factor, but will instead be sized using the monitor’s +scaling factor, but will instead be sized using the monitor's DPI. When the foot window is moved across monitors, the font size is -updated for the current monitor’s DPI. +updated for the current monitor's DPI. This means that, assuming the monitors are **at the same viewing distance**, the font size will appear to be the same, at all times. @@ -574,7 +574,7 @@ emulator actually responded to. Starting with version 1.7.0, foot also implements `XTVERSION`, to which it will reply with `\EP>|foot(version)\E\\`. Version is -e.g. “1.8.2” for a regular release, or “1.8.2-36-g7db8e06f” for a git +e.g. "1.8.2" for a regular release, or "1.8.2-36-g7db8e06f" for a git build. @@ -587,9 +587,9 @@ It allows querying the terminal for terminfo capabilities. Applications using this feature do not need to use the classic, file-based, terminfo definition. For example, if all applications used this feature, you would no longer have to install -foot’s terminfo on remote hosts you SSH into. +foot's terminfo on remote hosts you SSH into. -XTerm’s implementation (as of XTerm-370) only supports querying key +XTerm's implementation (as of XTerm-370) only supports querying key (as in keyboard keys) capabilities, and three custom capabilities: * `TN` - terminal name @@ -601,7 +601,7 @@ Kitty has extended this, and also supports querying all integer and string capabilities. Foot supports this, and extends it even further, to also include -boolean capabilities. This means foot’s entire terminfo can be queried +boolean capabilities. This means foot's entire terminfo can be queried via `XTGETTCAP`. Note that both Kitty and foot handles **responses** to @@ -613,7 +613,7 @@ capability/value pairs. There are a couple of issues with this: * The success/fail flag in the beginning of the response is always `1` (success), unless the very **first** queried capability is invalid. * XTerm will not respond **at all** to an invalid capability, unless - it’s the first one in the `XTGETTCAP` query. + it's the first one in the `XTGETTCAP` query. * XTerm will end the response at the first invalid capability. In other words, if you send a large multi-capability query, you will diff --git a/box-drawing.c b/box-drawing.c index cf351b31..d1ce1af0 100644 --- a/box-drawing.c +++ b/box-drawing.c @@ -2098,7 +2098,7 @@ draw_braille(struct buf *buf, char32_t wc) if (x_px_left >= 1) { x_spacing++; x_px_left--; } if (y_px_left >= 3) { y_spacing++; y_px_left -= 3; } - /* Fourth, margins (“spacing”, but on the sides) */ + /* Fourth, margins ("spacing", but on the sides) */ if (x_px_left >= 2) { x_margin++; x_px_left -= 2; } if (y_px_left >= 2) { y_margin++; y_px_left -= 2; } diff --git a/commands.c b/commands.c index 7b93f044..a3e48458 100644 --- a/commands.c +++ b/commands.c @@ -23,7 +23,7 @@ cmd_scrollback_up(struct terminal *term, int rows) const int grid_rows = grid->num_rows; /* The view row number in scrollback relative coordinates. This is - * the maximum number of rows we’re allowed to scroll */ + * the maximum number of rows we're allowed to scroll */ int sb_start = grid_sb_start_ignore_uninitialized(grid, term->rows); int view_sb_rel = grid_row_abs_to_sb_precalc_sb_start(grid, sb_start, view); diff --git a/config.c b/config.c index 3728826f..4945485e 100644 --- a/config.c +++ b/config.c @@ -540,7 +540,7 @@ value_to_str(struct context *ctx, char **res) * * - key="value" OK * - key=abc "quote" def NOT OK - * - key=’value’ OK + * - key='value' OK * * Finally, we support escaping the quote character, and the * escape character itself: @@ -1898,7 +1898,7 @@ modifiers_disjoint(const config_modifier_list_t *mods1, static char * NOINLINE modifiers_to_str(const config_modifier_list_t *mods) { - size_t len = tll_length(*mods); /* ‘+’ , and NULL terminator */ + size_t len = tll_length(*mods); /* '+' , and NULL terminator */ tll_foreach(*mods, it) len += strlen(it->item); @@ -3537,7 +3537,7 @@ config_font_parse(const char *pattern, struct config_font *font) /* * First look for user specified {pixel}size option - * e.g. “font-name:size=12” + * e.g. "font-name:size=12" */ double pt_size = -1.0; @@ -3548,9 +3548,9 @@ config_font_parse(const char *pattern, struct config_font *font) if (have_pt_size != FcResultMatch && have_px_size != FcResultMatch) { /* - * Apply fontconfig config. Can’t do that until we’ve first + * Apply fontconfig config. Can't do that until we've first * checked for a user provided size, since we may end up with - * both “size” and “pixelsize” being set, and we don’t know + * both "size" and "pixelsize" being set, and we don't know * which one takes priority. */ FcPattern *pat_copy = FcPatternDuplicate(pat); diff --git a/config.h b/config.h index 39f169f9..30219ff0 100644 --- a/config.h +++ b/config.h @@ -311,7 +311,7 @@ struct config { uint32_t buttons; uint32_t minimize; uint32_t maximize; - uint32_t quit; /* ‘close’ collides with #define in epoll-shim */ + uint32_t quit; /* 'close' collides with #define in epoll-shim */ uint32_t border; } color; diff --git a/csi.c b/csi.c index 04f03b05..fe783b13 100644 --- a/csi.c +++ b/csi.c @@ -1536,8 +1536,8 @@ csi_dispatch(struct terminal *term, uint8_t final) break; case 4: /* modifyOtherKeys */ - /* We don’t support fully disabling modifyOtherKeys, - * but simply revert back to mode ‘1’ */ + /* We don't support fully disabling modifyOtherKeys, + * but simply revert back to mode '1' */ term->modify_other_keys_2 = false; LOG_DBG("modifyOtherKeys=1"); break; @@ -1615,7 +1615,7 @@ csi_dispatch(struct terminal *term, uint8_t final) break; } } - break; /* private[0] == ‘<’ */ + break; /* private[0] == '<' */ } case ' ': { @@ -1762,7 +1762,7 @@ csi_dispatch(struct terminal *term, uint8_t final) break; } - break; /* private[0] == ‘?’ && private[1] == ‘$’ */ + break; /* private[0] == '?' && private[1] == '$' */ default: UNHANDLED(); diff --git a/dcs.c b/dcs.c index 601f1172..c4309459 100644 --- a/dcs.c +++ b/dcs.c @@ -138,12 +138,12 @@ xtgettcap_reply(struct terminal *term, const char *hex_cap_name, size_t len) /* * Reply format: * \EP 1 + r cap=value \E\\ - * Where ‘cap’ and ‘value are hex encoded ascii strings + * Where 'cap' and 'value are hex encoded ascii strings */ char *reply = xmalloc( 5 + /* DCS 1 + r (\EP1+r) */ len + /* capability name, hex encoded */ - 1 + /* ‘=’ */ + 1 + /* '=' */ strlen(value) * 2 + /* capability value, hex encoded */ 2 + /* ST (\E\\) */ 1); @@ -253,8 +253,8 @@ decrqss_unhook(struct terminal *term) /* * A note on the Ps parameter in the reply: many DEC manual * instances (e.g. https://vt100.net/docs/vt510-rm/DECRPSS) claim - * that 0 means “request is valid”, and 1 means “request is - * invalid”. + * that 0 means "request is valid", and 1 means "request is + * invalid". * * However, this appears to be a typo; actual hardware inverts the * response (as does XTerm and mlterm): diff --git a/doc/foot.1.scd b/doc/foot.1.scd index 8e2fb313..73c0c2b1 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -313,10 +313,10 @@ Foot supports URL detection. But, unlike many other terminal emulators, where URLs are highlighted when they are hovered and opened by clicking on them, foot uses a keyboard driven approach. -Pressing *ctrl*+*shift*+*o* enters _“Open URL mode”_, where all currently +Pressing *ctrl*+*shift*+*o* enters _"Open URL mode"_, where all currently visible URLs are underlined, and is associated with a -_“jump-label”_. The jump-label indicates the _key sequence_ -(e.g. *”AF”*) to use to activate the URL. +_"jump-label"_. The jump-label indicates the _key sequence_ +(e.g. *"AF"*) to use to activate the URL. The key binding can, of course, be customized, like all other key bindings in foot. See *show-urls-launch* and *show-urls-copy* in @@ -398,7 +398,7 @@ For more information, see *foot.ini*(5). New foot terminal instances (bound to *ctrl*+*shift*+*n* by default) will open in the current working directory, if the shell in the -“parent” terminal reports directory changes. +"parent" terminal reports directory changes. This is done with the OSC-7 escape sequence. Most shells can be scripted to do this, if they do not support it natively. See the wiki @@ -424,16 +424,16 @@ See the wiki (https://codeberg.org/dnkl/foot/wiki#user-content-jumping-between-prompts) for details, and examples for other shells. -## Piping last command’s output +## Piping last command's output -The key binding *pipe-command-output* can pipe the last command’s +The key binding *pipe-command-output* can pipe the last command's output to an application of your choice (similar to the other *pipe-\** key bindings): *\[key-bindings\]++ pipe-command-output=[sh -c "f=$(mktemp); cat - > $f; footclient emacsclient -nw $f; rm $f"] Control+Shift+g* -When pressing *ctrl*+*shift*+*g*, the last command’s output is written +When pressing *ctrl*+*shift*+*g*, the last command's output is written to a temporary file, then an emacsclient is started in a new footclient instance. The temporary file is removed after the footclient instance has closed. @@ -496,10 +496,10 @@ also implemented (and extended, to some degree) by Kitty. It allows querying the terminal for terminfo classic, file-based, terminfo definition. For example, if all applications used this -feature, you would no longer have to install foot’s terminfo on remote +feature, you would no longer have to install foot's terminfo on remote hosts you SSH into. -XTerm’s implementation (as of XTerm-370) only supports querying key +XTerm's implementation (as of XTerm-370) only supports querying key (as in keyboard keys) capabilities, and three custom capabilities: - TN - terminal name @@ -511,7 +511,7 @@ Kitty has extended this, and also supports querying all integer and string capabilities. Foot supports this, and extends it even further, to also include -boolean capabilities. This means foot’s entire terminfo can be queried +boolean capabilities. This means foot's entire terminfo can be queried via *XTGETTCAP*. Note that both Kitty and foot handles responses to multi-capability @@ -522,7 +522,7 @@ capability/value pairs. There are a couple of issues with this: - The success/fail flag in the beginning of the response is always 1 (success), unless the very first queried capability is invalid. -- XTerm will not respond at all to an invalid capability, unless it’s +- XTerm will not respond at all to an invalid capability, unless it's the first one in the XTGETTCAP query. - XTerm will end the response at the first invalid capability. diff --git a/grid.c b/grid.c index e7cdedc5..03ceb0ec 100644 --- a/grid.c +++ b/grid.c @@ -17,7 +17,7 @@ #define TIME_REFLOW 0 /* - * “sb” (scrollback relative) coordinates + * "sb" (scrollback relative) coordinates * * The scrollback relative row number 0 is the *first*, and *oldest* * row in the scrollback history (and thus the *first* row to be @@ -606,7 +606,7 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row, /* * TODO: detect if the reused row is covered by the * selection. Of so, cancel the selection. The problem: we - * don’t know if we’ve translated the selection coordinates + * don't know if we've translated the selection coordinates * yet. */ } @@ -616,7 +616,7 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row, return new_row; /* - * URI ranges are per row. Thus, we need to ‘close’ the still-open + * URI ranges are per row. Thus, we need to 'close' the still-open * ranges on the previous row, and re-open them on the * next/current row. */ @@ -796,7 +796,7 @@ grid_resize_and_reflow( } if (!old_row->linebreak && col_count > 0) { - /* Don’t truncate logical lines */ + /* Don't truncate logical lines */ col_count = old_cols; } @@ -885,8 +885,8 @@ grid_resize_and_reflow( xassert(amount > 0); /* - * If we’re going to reach the end of the new row, we - * need to make sure we don’t end in the middle of a + * If we're going to reach the end of the new row, we + * need to make sure we don't end in the middle of a * multi-column character. */ int spacers = 0; @@ -895,7 +895,7 @@ grid_resize_and_reflow( * While the cell *after* the last cell is a CELL_SPACER * * This means we have a multi-column character - * that doesn’t fit on the current row. We need to + * that doesn't fit on the current row. We need to * push it to the next row, and insert CELL_SPACER * cells as padding. */ @@ -1004,9 +1004,9 @@ grid_resize_and_reflow( { /* * line_wrap() "closes" still-open URIs. Since this is - * the *last* row, and since we’re line-breaking due + * the *last* row, and since we're line-breaking due * to a hard line-break (rather than running out of - * cells in the "new_row"), there shouldn’t be an open + * cells in the "new_row"), there shouldn't be an open * URI (it would have been closed when we reached the * end of the URI while reflowing the last "old" * row). @@ -1033,7 +1033,7 @@ grid_resize_and_reflow( xassert(old_rows == 0 || *next_tp == &terminator); #if defined(_DEBUG) - /* Verify all URI ranges have been “closed” */ + /* Verify all URI ranges have been "closed" */ for (int r = 0; r < new_rows; r++) { const struct row *row = new_grid[r]; @@ -1077,7 +1077,7 @@ grid_resize_and_reflow( grid->num_cols = new_cols; /* - * Set new viewport, making sure it’s not too far down. + * Set new viewport, making sure it's not too far down. * * This is done by using scrollback-start relative cooardinates, * and bounding the new viewport to (grid_rows - screen_rows). @@ -1143,7 +1143,7 @@ grid_row_uri_range_put(struct row *row, int col, const char *uri, uint64_t id) const bool matching_id = r->id == id; if (matching_id && r->end + 1 == col) { - /* Extend existing URI’s tail */ + /* Extend existing URI's tail */ r->end++; goto out; } @@ -1182,7 +1182,7 @@ grid_row_uri_range_put(struct row *row, int col, const char *uri, uint64_t id) uri_range_insert(extra, i + 1, col + 1, r->end, r->id, r->uri); /* The insertion may xrealloc() the vector, making our - * ‘old’ pointer invalid */ + * 'old' pointer invalid */ r = &extra->uri_ranges.v[i]; r->end = col - 1; xassert(r->start <= r->end); @@ -1319,7 +1319,7 @@ grid_row_uri_range_erase(struct row *row, int start, int end) extra, i + 1, end + 1, old->end, old->id, old->uri); /* The insertion may xrealloc() the vector, making our - * ‘old’ pointer invalid */ + * 'old' pointer invalid */ old = &extra->uri_ranges.v[i]; old->end = start - 1; return; /* There can be no more URIs affected by the erase range */ @@ -1402,11 +1402,11 @@ UNITTEST * The insertion logic typically triggers an xrealloc(), which, in * some cases, *moves* the entire URI vector to a new base * address. grid_row_uri_range_erase() did not account for this, - * and tried to update the ‘end’ member in the URI range we just + * and tried to update the 'end' member in the URI range we just * split. This causes foot to crash when the xrealloc() has moved * the URI range vector. * - * (note: we’re only verifying we don’t crash here, hence the lack + * (note: we're only verifying we don't crash here, hence the lack * of assertions). */ free(row_data.uri_ranges.v); diff --git a/input.c b/input.c index 166ad70b..cfbd63b3 100644 --- a/input.c +++ b/input.c @@ -416,7 +416,7 @@ execute_binding(struct seat *seat, struct terminal *term, if (!row->shell_integration.prompt_marker) { if (r_abs == grid->offset + term->rows - 1) { - /* We’ve reached the bottom of the scrollback */ + /* We've reached the bottom of the scrollback */ break; } continue; @@ -979,19 +979,19 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, if (term->modify_other_keys_2) { /* - * Try to mimic XTerm’s behavior, when holding shift: + * Try to mimic XTerm's behavior, when holding shift: * * - if other modifiers are pressed (e.g. Alt), emit a CSI escape * - upper-case symbols A-Z are encoded as an CSI escape - * - other upper-case symbols (e.g ‘Ö’) or emitted as is + * - other upper-case symbols (e.g 'Ö') or emitted as is * - non-upper cased symbols are _mostly_ emitted as is (foot * always emits as is) * * Examples (assuming Swedish layout): - * - Shift-a (‘A’) emits a CSI - * - Shift-, (‘;’) emits ‘;’ + * - Shift-a ('A') emits a CSI + * - Shift-, (';') emits ';' * - Shift-Alt-, (Alt-;) emits a CSI - * - Shift-ö (‘Ö’) emits ‘Ö’ + * - Shift-ö ('Ö') emits 'Ö' */ /* Any modifiers, besides shift active? */ @@ -1004,9 +1004,9 @@ legacy_kbd_protocol(struct seat *seat, struct terminal *term, seat->kbd.xkb_state, ctx->key); /* - * Get pressed key’s base symbol. - * - for ‘A’ (shift-a), that’s ‘a’ - * - for ‘;’ (shift-,), that’s ‘,’ + * Get pressed key's base symbol. + * - for 'A' (shift-a), that's 'a' + * - for ';' (shift-,), that's ',' */ const xkb_keysym_t *base_syms = NULL; size_t base_count = xkb_keymap_key_get_syms_by_level( @@ -1142,7 +1142,7 @@ kitty_kbd_protocol(struct seat *seat, struct terminal *term, if (composed && released) return false; - /* TODO: should we even bother with this, or just say it’s not supported? */ + /* TODO: should we even bother with this, or just say it's not supported? */ if (!disambiguate && !report_all_as_escapes && pressed) return legacy_kbd_protocol(seat, term, ctx); @@ -1287,32 +1287,32 @@ emit_escapes: * * If the keysym is shifted, use its unshifted codepoint * instead. In other words, ctrl+a and ctrl+shift+a should - * both use the same value for ‘key’ (97 - i.a. ‘a’). + * both use the same value for 'key' (97 - i.a. 'a'). * - * However, don’t do this if a non-significant modifier was + * However, don't do this if a non-significant modifier was * used to generate the symbol. This is needed since we cannot - * encode non-significant modifiers, and thus the “extra” + * encode non-significant modifiers, and thus the "extra" * modifier(s) would get lost. * * Example: * - * the Swedish layout has ‘2’, QUOTATION MARK (“double - * quote”), ‘@’, and ‘²’ on the same key. ‘2’ is the base + * the Swedish layout has '2', QUOTATION MARK ("double + * quote"), '@', and '²' on the same key. '2' is the base * symbol. * * Shift+2 results in QUOTATION MARK - * AltGr+2 results in ‘@’ - * AltGr+Shift+2 results in ‘²’ + * AltGr+2 results in '@' + * AltGr+Shift+2 results in '²' * - * The kitty kbd protocol can’t encode AltGr. So, if we - * always used the base symbol (‘2’), Alt+Shift+2 would + * The kitty kbd protocol can't encode AltGr. So, if we + * always used the base symbol ('2'), Alt+Shift+2 would * result in the same escape sequence as * AltGr+Alt+Shift+2. * * (yes, this matches what kitty does, as of 0.23.1) */ - /* Get the key’s shift level */ + /* Get the key's shift level */ xkb_level_index_t lvl = xkb_state_key_get_level( seat->kbd.xkb_state, ctx->key, ctx->layout); @@ -1324,7 +1324,7 @@ emit_escapes: masks, ALEN(masks)); /* Check modifier combinations - if a combination has - * modifiers not in our set of ‘significant’ modifiers, + * modifiers not in our set of 'significant' modifiers, * use key sym as-is */ bool use_level0_sym = true; for (size_t i = 0; i < mask_count; i++) { @@ -1371,7 +1371,7 @@ emit_escapes: char event[4]; if (report_events /*&& !pressed*/) { /* Note: this deviates slightly from Kitty, which omits the - * “:1” subparameter for key press events */ + * ":1" subparameter for key press events */ event[0] = ':'; event[1] = '0' + (pressed ? 1 : repeating ? 2 : 3); event[2] = '\0'; @@ -2032,7 +2032,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, * event with a NULL surface - see wl_pointer_enter(). * * In this case, we never set seat->mouse_focus (since we - * can’t map the enter event to a specific window). */ + * can't map the enter event to a specific window). */ return; } @@ -2141,7 +2141,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, if (cursor_is_on_new_cell) { /* Prevent multiple/different mouse bindings from - * triggering if the mouse has moved “too much” (to + * triggering if the mouse has moved "too much" (to * another cell) */ seat->mouse.count = 0; } @@ -2161,14 +2161,14 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, if (!term->is_searching) { if (auto_scroll_direction != SELECTION_SCROLL_NOT) { /* - * Start ‘selection auto-scrolling’ + * Start 'selection auto-scrolling' * * The speed of the scrolling is proportional to the * distance between the mouse and the grid; the * further away the mouse is, the faster we scroll. * - * Note that the speed is measured in ‘intervals (in - * ns) between each timed scroll of a single line’. + * Note that the speed is measured in 'intervals (in + * ns) between each timed scroll of a single line'. * * Thus, the further away the mouse is, the smaller * interval value we use. @@ -2375,7 +2375,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, * clicking twice, waiting for the CSD timer, and finally * clicking once more, results in the following sequence * (keyboard and other irrelevant events filtered out, unless - * they’re needed to prove a point): + * they're needed to prove a point): * * dbg: input.c:1551: cancelling drag timer, moving window * dbg: input.c:759: keyboard_leave: keyboard=0x607000003580, serial=873, surface=0x6070000036d0 @@ -2407,12 +2407,12 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, * - GNOME does *not* send a pointer *enter* event after the drag * has stopped * - The second drag does *not* generate a pointer *leave* event - * - The missing leave event means we’re still tracking LMB as + * - The missing leave event means we're still tracking LMB as * being held down in our seat struct. * - This leads to an assert (debug builds) when LMB is clicked - * again (seat’s button list already contains LMB). + * again (seat's button list already contains LMB). * - * Note: I’ve also observed variants of the above + * Note: I've also observed variants of the above */ tll_foreach(seat->mouse.buttons, it) { if (it->item.button == button) { diff --git a/input.h b/input.h index 001d116f..2ea1c6a9 100644 --- a/input.h +++ b/input.h @@ -11,12 +11,12 @@ * Custom defines for mouse wheel left/right buttons. * * Libinput does not define these. On Wayland, all scroll events (both - * vertical and horizontal) are reported not as buttons, as ‘axis’ + * vertical and horizontal) are reported not as buttons, as 'axis' * events. * * Libinput _does_ define BTN_BACK and BTN_FORWARD, which is * what we use for vertical scroll events. But for horizontal scroll - * events, there aren’t any pre-defined mouse buttons. + * events, there aren't any pre-defined mouse buttons. * * Mouse buttons are in the range 0x110 - 0x11f, with joystick defines * starting at 0x120. diff --git a/key-binding.c b/key-binding.c index a7738da8..1c131e72 100644 --- a/key-binding.c +++ b/key-binding.c @@ -243,27 +243,27 @@ maybe_repair_key_combo(const struct seat *seat, * modifier, and replace the shifted symbol with its unshifted * variant. * - * For example, the combo is “Control+Shift+U”. In this case, - * Shift is the modifier used to “shift” ‘u’ to ‘U’, after which - * ‘Shift’ will have been “consumed”. Since we filter out consumed + * For example, the combo is "Control+Shift+U". In this case, + * Shift is the modifier used to "shift" 'u' to 'U', after which + * 'Shift' will have been "consumed". Since we filter out consumed * modifiers when matching key combos, this key combo will never - * trigger (we will never be able to match the ‘Shift’ modifier). + * trigger (we will never be able to match the 'Shift' modifier). * * There are two correct variants of the above key combo: - * - “Control+U” (upper case ‘U’) - * - “Control+Shift+u” (lower case ‘u’) + * - "Control+U" (upper case 'U') + * - "Control+Shift+u" (lower case 'u') * * What we do here is, for each key *code*, check if there are any - * (shifted) levels where it produces ‘sym’. If there are, check + * (shifted) levels where it produces 'sym'. If there are, check * *which* sets of modifiers are needed to produce it, and compare - * with ‘mods’. + * with 'mods'. * - * If there is at least one common modifier, it means ‘sym’ is a - * “shifted” symbol, with the corresponding shifting modifier + * If there is at least one common modifier, it means 'sym' is a + * "shifted" symbol, with the corresponding shifting modifier * explicitly included in the key combo. I.e. the key combo will * never trigger. * - * We then proceed and “repair” the key combo by replacing ‘sym’ + * We then proceed and "repair" the key combo by replacing 'sym' * with the corresponding unshifted symbol. * * To reduce the noise, we ignore all key codes where the shifted @@ -283,7 +283,7 @@ maybe_repair_key_combo(const struct seat *seat, seat->kbd.xkb_keymap, code, layout_idx, 0, &base_syms); if (base_count == 0 || sym == base_syms[0]) { - /* No unshifted symbols, or unshifted symbol is same as ‘sym’ */ + /* No unshifted symbols, or unshifted symbol is same as 'sym' */ continue; } @@ -313,7 +313,7 @@ maybe_repair_key_combo(const struct seat *seat, seat->kbd.xkb_keymap, code, layout_idx, level_idx, mod_masks, ALEN(mod_masks)); - /* Check if key combo’s modifier set intersects */ + /* Check if key combo's modifier set intersects */ for (size_t j = 0; j < mod_mask_count; j++) { if ((mod_masks[j] & mods) != mod_masks[j]) continue; @@ -359,19 +359,19 @@ key_cmp(struct key_binding a, struct key_binding b) * Sort bindings such that bindings with the same symbol are * sorted with the binding having the most modifiers comes first. * - * This fixes an issue where the “wrong” key binding are triggered - * when used with “consumed” modifiers. + * This fixes an issue where the "wrong" key binding are triggered + * when used with "consumed" modifiers. * * For example: if Control+BackSpace is bound before * Control+Shift+BackSpace, then the latter binding is never * triggered. * * Why? Because Shift is a consumed modifier. This means - * Control+BackSpace is “the same” as Control+Shift+BackSpace. + * Control+BackSpace is "the same" as Control+Shift+BackSpace. * * By sorting bindings with more modifiers first, we work around - * the problem. But note that it is *just* a workaround, and I’m - * not confident there aren’t cases where it doesn’t work. + * the problem. But note that it is *just* a workaround, and I'm + * not confident there aren't cases where it doesn't work. * * See https://codeberg.org/dnkl/foot/issues/1280 */ diff --git a/kitty-keymap.h b/kitty-keymap.h index ae911c4f..3420d01f 100644 --- a/kitty-keymap.h +++ b/kitty-keymap.h @@ -13,7 +13,7 @@ struct kitty_key_data { _Static_assert(sizeof(struct kitty_key_data) == 7, "bad size"); -/* Note! *Must* Be kept sorted (on ‘sym’) */ +/* Note! *Must* Be kept sorted (on 'sym') */ static const struct kitty_key_data kitty_keymap[] = { {XKB_KEY_ISO_Level3_Shift, 57453, 'u', true}, {XKB_KEY_ISO_Level5_Shift, 57454, 'u', true}, diff --git a/main.c b/main.c index 98db9c38..8b4d2715 100644 --- a/main.c +++ b/main.c @@ -427,7 +427,7 @@ main(int argc, char *const *argv) /* * Try to force an UTF-8 locale. If we succeed, launch the - * user’s shell as usual, but add a user-notification saying + * user's shell as usual, but add a user-notification saying * the locale has been changed. */ for (size_t i = 0; i < ALEN(fallback_locales); i++) { diff --git a/notify.c b/notify.c index 8180477d..04427477 100644 --- a/notify.c +++ b/notify.c @@ -20,7 +20,7 @@ notify_notify(const struct terminal *term, const char *title, const char *body) LOG_DBG("notify: title=\"%s\", msg=\"%s\"", title, body); if (term->conf->notify_focus_inhibit && term->kbd_focus) { - /* No notifications while we’re focused */ + /* No notifications while we're focused */ return; } diff --git a/osc.c b/osc.c index 5da8666f..1ea61a3e 100644 --- a/osc.c +++ b/osc.c @@ -353,7 +353,7 @@ parse_rgb(const char *string, uint32_t *color, bool *_have_alpha, return false; } - /* Verify prefix is “rgb:” or “rgba:” */ + /* Verify prefix is "rgb:" or "rgba:" */ if (have_alpha) { if (strncmp(string, "rgba:", 5) != 0) return false; @@ -443,9 +443,9 @@ osc_uri(struct terminal *term, char *string) /* * \E]8;;URI\e\\ * - * Params are key=value pairs, separated by ‘:’. + * Params are key=value pairs, separated by ':'. * - * The only defined key (as of 2020-05-31) is ‘id’, which is used + * The only defined key (as of 2020-05-31) is 'id', which is used * to group split-up URIs: * * ╔═ file1 ════╗ diff --git a/pgo/full-headless-cage.sh b/pgo/full-headless-cage.sh index eacb0c33..50fc7509 100755 --- a/pgo/full-headless-cage.sh +++ b/pgo/full-headless-cage.sh @@ -10,5 +10,5 @@ trap "rm -rf '${runtime_dir}'" EXIT INT HUP TERM XDG_RUNTIME_DIR="${runtime_dir}" WLR_RENDERER=pixman WLR_BACKENDS=headless cage "${srcdir}"/pgo/full-inner.sh "${srcdir}" "${blddir}" -# Cage’s exit code doesn’t reflect our script’s exit code +# Cage's exit code doesn't reflect our script's exit code [ -f "${blddir}"/pgo-ok ] || exit 1 diff --git a/pgo/full-headless-sway.sh b/pgo/full-headless-sway.sh index 48dbcb94..524bf42b 100755 --- a/pgo/full-headless-sway.sh +++ b/pgo/full-headless-sway.sh @@ -17,8 +17,8 @@ trap cleanup EXIT INT HUP TERM # Generate a custom config that executes our generate-pgo-data script > "${sway_conf}" echo "exec '${srcdir}'/pgo/full-headless-sway-inner.sh '${srcdir}' '${blddir}'" -# Run Sway. full-headless-sway-inner.sh ends with a ‘swaymsg exit’ +# Run Sway. full-headless-sway-inner.sh ends with a 'swaymsg exit' XDG_RUNTIME_DIR="${runtime_dir}" WLR_RENDERER=pixman WLR_BACKENDS=headless sway -c "${sway_conf}" -# Sway’s exit code doesn’t reflect our script’s exit code +# Sway's exit code doesn't reflect our script's exit code [ -f "${blddir}"/pgo-ok ] || exit 1 diff --git a/pgo/pgo.sh b/pgo/pgo.sh index f782a9f8..b59f5c21 100755 --- a/pgo/pgo.sh +++ b/pgo/pgo.sh @@ -98,8 +98,8 @@ if [ ${do_pgo} = yes ]; then ninja -C "${blddir}" # If fcft/tllist are subprojects, we need to ensure their tests - # have been executed, or we’ll get “profile count data file not - # found” errors. + # have been executed, or we'll get "profile count data file not + # found" errors. ninja -C "${blddir}" test # Run mode-dependent script to generate profiling data diff --git a/render.c b/render.c index 5d2ec6bc..2bfe36e8 100644 --- a/render.c +++ b/render.c @@ -269,12 +269,12 @@ color_dim(const struct terminal *term, uint32_t color) continue; if (term->colors.table[0 + i] == color) { - /* “Regular” color, return the corresponding “dim” */ + /* "Regular" color, return the corresponding "dim" */ return conf->colors.dim[i]; } else if (term->colors.table[8 + i] == color) { - /* “Bright” color, return the corresponding “regular” */ + /* "Bright" color, return the corresponding "regular" */ return term->colors.table[i]; } } @@ -1073,7 +1073,7 @@ grid_render_scroll(struct terminal *term, struct buffer *buf, /* * TODO: remove this if re-enabling scroll damage when re-applying - * last frame’s damage (see reapply_old_damage() + * last frame's damage (see reapply_old_damage() */ pixman_region32_union_rect( &buf->dirty[0], &buf->dirty[0], 0, dst_y, buf->width, height); @@ -1150,7 +1150,7 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf, /* * TODO: remove this if re-enabling scroll damage when re-applying - * last frame’s damage (see reapply_old_damage() + * last frame's damage (see reapply_old_damage() */ pixman_region32_union_rect( &buf->dirty[0], &buf->dirty[0], 0, dst_y, buf->width, height); @@ -1288,7 +1288,7 @@ render_sixel(struct terminal *term, pixman_image_t *pix, * If the last sixel row only partially covers the cell row, * 'erase' the cell by rendering them. * - * In all cases, do *not* clear the ‘dirty’ bit on the row, to + * In all cases, do *not* clear the 'dirty' bit on the row, to * ensure the regular renderer includes them in the damage * rect. */ @@ -1403,8 +1403,8 @@ render_ime_preedit_for_seat(struct terminal *term, struct seat *seat, { /* Cursor will be drawn *after* the pre-edit string, i.e. in * the cell *after*. This means we need to copy, and dirty, - * one extra cell from the original grid, or we’ll leave - * trailing “cursors” after us if the user deletes text while + * one extra cell from the original grid, or we'll leave + * trailing "cursors" after us if the user deletes text while * pre-editing */ cells_needed++; } @@ -1613,23 +1613,23 @@ render_overlay(struct terminal *term) * When possible, we only update the areas that have *changed* * since the last frame. That means: * - * - clearing/erasing cells that are now selected, but weren’t + * - clearing/erasing cells that are now selected, but weren't * in the last frame - * - dimming cells that were selected, but aren’t anymore + * - dimming cells that were selected, but aren't anymore * - * To do this, we save the last frame’s selected cells as a + * To do this, we save the last frame's selected cells as a * pixman region. * * Then, we calculate the corresponding region for this - * frame’s selected cells. + * frame's selected cells. * - * Last frame’s region minus this frame’s region gives us the + * Last frame's region minus this frame's region gives us the * region that needs to be *dimmed* in this frame * - * This frame’s region minus last frame’s region gives us the + * This frame's region minus last frame's region gives us the * region that needs to be *cleared* in this frame. * - * Finally, the union of the two “diff” regions above, gives + * Finally, the union of the two "diff" regions above, gives * us the total region affected by a change, in either way. We * use this as the bounding box for the * wl_surface_damage_buffer() call. @@ -1642,12 +1642,12 @@ render_overlay(struct terminal *term) buf->age == 0; if (!buffer_reuse) { - /* Can’t reuse last frame’s damage - set to full window, + /* Can't reuse last frame's damage - set to full window, * to ensure *everything* is updated */ pixman_region32_init_rect( &old_see_through, 0, 0, buf->width, buf->height); } else { - /* Use last frame’s saved region */ + /* Use last frame's saved region */ pixman_region32_init(&old_see_through); pixman_region32_copy(&old_see_through, see_through); } @@ -2072,7 +2072,7 @@ render_csd_border(struct terminal *term, enum csd_surface surf_idx, } /* - * The “visible” border. + * The "visible" border. */ float scale = term->scale; @@ -2692,21 +2692,21 @@ reapply_old_damage(struct terminal *term, struct buffer *new, struct buffer *old pixman_region32_init(&dirty); /* - * Figure out current frame’s damage region + * Figure out current frame's damage region * - * If current frame doesn’t have any scroll damage, we can simply - * subtract this frame’s damage from the last frame’s damage. That - * way, we don’t have to copy areas from the old frame that’ll + * If current frame doesn't have any scroll damage, we can simply + * subtract this frame's damage from the last frame's damage. That + * way, we don't have to copy areas from the old frame that'll * just get overwritten by current frame. * - * Note that this is row based. A “half damaged” row is not + * Note that this is row based. A "half damaged" row is not * excluded. I.e. the entire row will be copied from the old frame * to the new, and then when actually rendering the new frame, the * updated cells will overwrite parts of the copied row. * - * Since we’re scanning the entire viewport anyway, we also track + * Since we're scanning the entire viewport anyway, we also track * whether *all* cells are to be updated. In this case, just force - * a full re-rendering, and don’t copy anything from the old + * a full re-rendering, and don't copy anything from the old * frame. */ bool full_repaint_needed = true; @@ -2739,28 +2739,28 @@ reapply_old_damage(struct terminal *term, struct buffer *new, struct buffer *old } /* - * TODO: re-apply last frame’s scroll damage + * TODO: re-apply last frame's scroll damage * * We used to do this, but it turned out to be buggy. If we decide - * to re-add it, this is where to do it. Note that we’d also have + * to re-add it, this is where to do it. Note that we'd also have * to remove the updates to buf->dirty from grid_render_scroll() * and grid_render_scroll_reverse(). */ if (tll_length(term->grid->scroll_damage) == 0) { /* - * We can only subtract current frame’s damage from the old - * frame’s if we don’t have any scroll damage. + * We can only subtract current frame's damage from the old + * frame's if we don't have any scroll damage. * * If we do have scroll damage, the damage region we * calculated above is not (yet) valid - we need to apply the - * current frame’s scroll damage *first*. This is done later, + * current frame's scroll damage *first*. This is done later, * when rendering the frame. */ pixman_region32_subtract(&dirty, &old->dirty[0], &dirty); pixman_image_set_clip_region32(new->pix[0], &dirty); } else { - /* Copy *all* of last frame’s damaged areas */ + /* Copy *all* of last frame's damaged areas */ pixman_image_set_clip_region32(new->pix[0], &old->dirty[0]); } @@ -2819,7 +2819,7 @@ grid_render(struct terminal *term) struct buffer_chain *chain = term->render.chains.grid; struct buffer *buf = shm_get_buffer(chain, term->width, term->height); - /* Dirty old and current cursor cell, to ensure they’re repainted */ + /* Dirty old and current cursor cell, to ensure they're repainted */ dirty_old_cursor(term); dirty_cursor(term); @@ -2938,11 +2938,11 @@ grid_render(struct terminal *term) * they are overflowing. * * As soon as we see a non-overflowing cell we can - * stop, since it isn’t affecting the string of + * stop, since it isn't affecting the string of * overflowing glyphs that follows it. * * As soon as we see a dirty cell, we can stop, since - * that means we’ve already handled it (remember the + * that means we've already handled it (remember the * outer loop goes from left to right). */ for (struct cell *c = cell - 1; c >= &row->cells[0]; c--) { @@ -2960,9 +2960,9 @@ grid_render(struct terminal *term) * Note that the first non-overflowing cell must be * re-rendered as well, but any cell *after* that is * unaffected by the string of overflowing glyphs - * we’re dealing with right now. + * we're dealing with right now. * - * For performance, this iterates the *outer* loop’s + * For performance, this iterates the *outer* loop's * cell pointer - no point in re-checking all these * glyphs again, in the outer loop. */ @@ -3137,9 +3137,9 @@ render_search_box(struct terminal *term) /* * We treat the search box pretty much like a row of cells. That - * is, a glyph is either 1 or 2 (or more) “cells” wide. + * is, a glyph is either 1 or 2 (or more) "cells" wide. * - * The search ‘length’, and ‘cursor’ (position) is in + * The search 'length', and 'cursor' (position) is in * *characters*, not cells. This means we need to translate from * character count to cell count when calculating the length of * the search box, where in the search string we should start @@ -3307,7 +3307,7 @@ render_search_box(struct terminal *term) } /* - * Render the search string, starting at ‘glyph_offset’. Note that + * Render the search string, starting at 'glyph_offset'. Note that * glyph_offset is in cells, not characters */ for (size_t i = 0, @@ -3580,7 +3580,7 @@ render_urls(struct terminal *term) int x = col * term->cell_width - 15 * term->cell_width / 10; int y = row * term->cell_height - 5 * term->cell_height / 10; - /* Don’t position it outside our window */ + /* Don't position it outside our window */ if (x < -term->margins.left) x = -term->margins.left; if (y < -term->margins.top) @@ -3621,12 +3621,12 @@ render_urls(struct terminal *term) label[i] = U' '; /* - * Don’t extend outside our window + * Don't extend outside our window * - * Truncate label so that it doesn’t extend outside our + * Truncate label so that it doesn't extend outside our * window. * - * Do it in a way such that we don’t cut the label in the + * Do it in a way such that we don't cut the label in the * middle of a double-width character. */ @@ -3805,7 +3805,7 @@ delayed_reflow_of_normal_grid(struct terminal *term) term->selection.coords.end.row >= 0 ? ALEN(tracking_points) : 0, tracking_points); - /* Replace the current, truncated, “normal” grid with the + /* Replace the current, truncated, "normal" grid with the * correctly reflowed one */ grid_free(&term->normal); term->normal = *term->interactive_resizing.grid; @@ -3868,7 +3868,7 @@ send_dimensions_to_client(struct terminal *term) win->resize_timeout_fd = -1; } } else { - /* Send new dimensions to client “in a while” */ + /* Send new dimensions to client "in a while" */ assert(win->is_resizing && term->conf->resize_delay_ms > 0); int fd = win->resize_timeout_fd; @@ -4083,8 +4083,8 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) /* - * Since text reflow is slow, don’t do it *while* resizing. Only - * do it when done, or after “pausing” the resize for sufficiently + * Since text reflow is slow, don't do it *while* resizing. Only + * do it when done, or after "pausing" the resize for sufficiently * long. We reuse the TIOCSWINSZ timer to handle this. See * send_dimensions_to_client() and fdm_tiocswinsz(). * @@ -4095,7 +4095,7 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) if (term->interactive_resizing.grid == NULL) { term_ptmx_pause(term); - /* Stash the current ‘normal’ grid, as-is, to be used when + /* Stash the current 'normal' grid, as-is, to be used when * doing the final reflow */ term->interactive_resizing.old_screen_rows = term->rows; term->interactive_resizing.old_cols = term->cols; @@ -4106,7 +4106,7 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) if (term->grid == &term->normal) term->interactive_resizing.selection_coords = term->selection.coords; } else { - /* We’ll replace the current temporary grid, with a new + /* We'll replace the current temporary grid, with a new * one (again based on the original grid) */ grid_free(&term->normal); } @@ -4116,12 +4116,12 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) /* * Copy the current viewport (of the original grid) to a new * grid that will be used during the resize. For now, throw - * away sixels and OSC-8 URLs. They’ll be "restored" when we + * away sixels and OSC-8 URLs. They'll be "restored" when we * do the final reflow. * * Note that OSC-8 URLs are perfectly ok to throw away; they * cannot be interacted with during the resize. And, even if - * url.osc8-underline=always, the “underline” attribute is + * url.osc8-underline=always, the "underline" attribute is * part of the cell, not the URI struct (and thus our faked * grid will still render OSC-8 links underlined). * @@ -4163,7 +4163,7 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) selection_cancel(term); else { /* - * Don’t cancel, but make sure there aren’t any ongoing + * Don't cancel, but make sure there aren't any ongoing * selections after the resize. */ tll_foreach(term->wl->seats, it) { @@ -4175,7 +4175,7 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) /* * TODO: if we remove the selection_finalize() call above (i.e. if * we start allowing selections to be ongoing across resizes), the - * selection’s pivot point coordinates *must* be added to the + * selection's pivot point coordinates *must* be added to the * tracking points list. */ /* Resize grids */ @@ -4195,7 +4195,7 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) int old_normal_rows = old_rows; if (term->interactive_resizing.grid != NULL) { - /* Throw away the current, truncated, “normal” grid, and + /* Throw away the current, truncated, "normal" grid, and * use the original grid instead (from before the resize * started) */ grid_free(&term->normal); diff --git a/selection.c b/selection.c index 9e9bbb10..7540283b 100644 --- a/selection.c +++ b/selection.c @@ -858,8 +858,8 @@ pixman_region_for_coords_block(const struct terminal *term, return region; } -/* Returns a pixman region representing the selection between ‘start’ - * and ‘end’ (given the current selection kind), in *scrollback +/* Returns a pixman region representing the selection between 'start' + * and 'end' (given the current selection kind), in *scrollback * relative coordinates* */ static pixman_region32_t pixman_region_for_coords(const struct terminal *term, @@ -921,17 +921,17 @@ mark_selected_region(struct terminal *term, pixman_box32_t *boxes, * followed by non-empty cell(s), since this * corresponds to what gets extracted when the * selection is copied (that is, empty cells - * “between” non-empty cells are converted to + * "between" non-empty cells are converted to * spaces). * * However, they way we handle selection updates - * (diffing the “old” selection area against the - * “new” one, using pixman regions), means we - * can’t correctly update the state of empty - * cells. The result is “random” empty cells being - * rendered as selected when they shouldn’t. + * (diffing the "old" selection area against the + * "new" one, using pixman regions), means we + * can't correctly update the state of empty + * cells. The result is "random" empty cells being + * rendered as selected when they shouldn't. * - * “Fix” by *never* highlighting selected empty + * "Fix" by *never* highlighting selected empty * cells (they still get converted to spaces when * copied, if followed by non-empty cells). */ @@ -944,8 +944,8 @@ mark_selected_region(struct terminal *term, pixman_box32_t *boxes, * * This is due to how the algorithm for updating * the selection works; it uses regions to - * calculate the difference between the “old” and - * the “new” selection. This makes it impossible + * calculate the difference between the "old" and + * the "new" selection. This makes it impossible * to tell if an empty cell is a *trailing* empty * cell (that should not be highlighted), or an * empty cells between non-empty cells (that @@ -957,7 +957,7 @@ mark_selected_region(struct terminal *term, pixman_box32_t *boxes, * empty cell is trailing or not. * * So, what we need to do is check if a - * ‘selected’, and empty cell has been marked as + * 'selected', and empty cell has been marked as * selected, temporarily unmark (forcing it dirty, * to ensure it gets re-rendered). If it is *not* * a trailing empty cell, it will get re-tagged as @@ -1042,7 +1042,7 @@ set_pivot_point_for_block_and_char_wise(struct terminal *term, *pivot_start = start; - /* First, make sure ‘start’ isn’t in the middle of a + /* First, make sure 'start' isn't in the middle of a * multi-column character */ while (true) { const struct row *row = term->grid->rows[pivot_start->row & (term->grid->num_rows - 1)]; @@ -1051,7 +1051,7 @@ set_pivot_point_for_block_and_char_wise(struct terminal *term, if (cell->wc < CELL_SPACER) break; - /* Multi-column chars don’t cross rows */ + /* Multi-column chars don't cross rows */ xassert(pivot_start->col > 0); if (pivot_start->col == 0) break; @@ -1876,7 +1876,7 @@ cancelled(void *data, struct wl_data_source *wl_data_source) clipboard->text = NULL; } -/* We don’t support dragging *from* */ +/* We don't support dragging *from* */ static void dnd_drop_performed(void *data, struct wl_data_source *wl_data_source) { @@ -2218,11 +2218,11 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data) /* * In addition to stripping non-formatting C0 controls, - * XTerm has an option, “disallowedPasteControls”, that + * XTerm has an option, "disallowedPasteControls", that * defines C0 controls that will be replaced with spaces * when pasted. * - * It’s default value is BS,DEL,ENQ,EOT,NUL + * It's default value is BS,DEL,ENQ,EOT,NUL * * Instead of replacing them with spaces, we allow them in * bracketed paste mode, and strip them completely in @@ -2716,7 +2716,7 @@ enter(void *data, struct wl_data_device *wl_data_device, uint32_t serial, reject_offer: /* Either terminal is already busy sending paste data, or mouse - * pointer isn’t over the grid */ + * pointer isn't over the grid */ seat->clipboard.window = NULL; wl_data_offer_accept(offer, serial, NULL); wl_data_offer_set_actions( @@ -2812,7 +2812,7 @@ drop(void *data, struct wl_data_device *wl_data_device) term, read_fd, clipboard->mime_type, &receive_dnd, &receive_dnd_done, ctx); - /* data offer is now “owned” by the receive context */ + /* data offer is now "owned" by the receive context */ clipboard->data_offer = NULL; clipboard->mime_type = DATA_OFFER_MIME_UNSET; } diff --git a/shm.c b/shm.c index 87bd33a7..7959a84b 100644 --- a/shm.c +++ b/shm.c @@ -511,7 +511,7 @@ get_new_buffers(struct buffer_chain *chain, size_t count, #endif if (!(bufs[0] && shm_can_scroll(bufs[0]))) { - /* We only need to keep the pool FD open if we’re going to SHM + /* We only need to keep the pool FD open if we're going to SHM * scroll it */ close(pool_fd); pool->fd = -1; @@ -579,7 +579,7 @@ shm_get_buffer(struct buffer_chain *chain, int width, int height) cached = buf; else { /* We have multiple buffers eligible for - * reuse. Pick the “youngest” one, and mark the + * reuse. Pick the "youngest" one, and mark the * other one for purging */ if (buf->public.age < cached->public.age) { shm_unref(&cached->public); @@ -589,8 +589,8 @@ shm_get_buffer(struct buffer_chain *chain, int width, int height) * TODO: I think we _can_ use shm_unref() * here... * - * shm_unref() may remove ‘it’, but that - * should be safe; “our” tll_foreach() already + * shm_unref() may remove 'it', but that + * should be safe; "our" tll_foreach() already * holds the next pointer. */ if (buffer_unref_no_remove_from_chain(buf)) diff --git a/shm.h b/shm.h index f9e90a23..7d1796bf 100644 --- a/shm.h +++ b/shm.h @@ -49,7 +49,7 @@ void shm_chain_free(struct buffer_chain *chain); /* * Returns a single buffer. * - * May returned a cached buffer. If so, the buffer’s age indicates how + * May returned a cached buffer. If so, the buffer's age indicates how * many shm_get_buffer() calls have been made for the same * width/height while the buffer was still busy. * @@ -57,7 +57,7 @@ void shm_chain_free(struct buffer_chain *chain); */ struct buffer *shm_get_buffer(struct buffer_chain *chain, int width, int height); /* - * Returns many buffers, described by ‘info’, all sharing the same SHM + * Returns many buffers, described by 'info', all sharing the same SHM * buffer pool. * * Never returns cached buffers. However, the newly created buffers diff --git a/sixel.c b/sixel.c index 8a0b130f..c046145f 100644 --- a/sixel.c +++ b/sixel.c @@ -979,7 +979,7 @@ sixel_reflow_grid(struct terminal *term, struct grid *grid) struct grid *active_grid = term->grid; term->grid = grid; - /* Need the “real” list to be empty from the beginning */ + /* Need the "real" list to be empty from the beginning */ tll(struct sixel) copy = tll_init(); tll_foreach(grid->sixel_images, it) tll_push_back(copy, it->item); @@ -1028,7 +1028,7 @@ sixel_reflow_grid(struct terminal *term, struct grid *grid) continue; } - /* Sixels that didn’t overlap may now do so, which isn’t + /* Sixels that didn't overlap may now do so, which isn't * allowed of course */ _sixel_overwrite_by_rectangle( term, six->pos.row, six->pos.col, six->rows, six->cols, @@ -1200,8 +1200,8 @@ sixel_unhook(struct terminal *term) * Position the text cursor based on the **upper** * pixel, of the last sixel. * - * In most cases, that’ll end up being the very last - * row of the sixel (which we’re already at, thanks to + * In most cases, that'll end up being the very last + * row of the sixel (which we're already at, thanks to * the linefeeds). But for some combinations of font * and image sizes, the final cursor position is * higher up. @@ -1580,8 +1580,8 @@ decsixel_generic(struct terminal *term, uint8_t c) case '$': if (likely(term->sixel.pos.col <= term->sixel.max_width)) { /* - * We set, and keep, ‘col’ outside the image boundary when - * we’ve reached the maximum image height, to avoid also + * We set, and keep, 'col' outside the image boundary when + * we've reached the maximum image height, to avoid also * having to check the row vs image height in the common * path in sixel_add(). */ @@ -1775,12 +1775,12 @@ decgci(struct terminal *term, uint8_t c) int sat = min(c3, 100); /* - * Sixel’s HLS use the following primary color hues: + * Sixel's HLS use the following primary color hues: * blue: 0° * red: 120° * green: 240° * - * While “standard” HSL uses: + * While "standard" HSL uses: * red: 0° * green: 120° * blue: 240° diff --git a/terminal.c b/terminal.c index 5d6c956d..ed13073e 100644 --- a/terminal.c +++ b/terminal.c @@ -260,8 +260,8 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) if (unlikely(term->interactive_resizing.grid != NULL)) { /* - * Don’t consume PTMX while we’re doing an interactive resize, - * since the ‘normal’ grid we’re currently using is a + * Don't consume PTMX while we're doing an interactive resize, + * since the 'normal' grid we're currently using is a * temporary one - all changes done to it will be lost when * the interactive resize ends. */ @@ -817,7 +817,7 @@ get_font_dpi(const struct terminal *term) * downscaled by the compositor. * * With the newer fractional-scale-v1 protocol, we use the - * monitor’s real DPI, since we scale everything to the correct + * monitor's real DPI, since we scale everything to the correct * scaling factor (no downscaling done by the compositor). */ @@ -1092,8 +1092,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, goto close_fds; } - /* Need to register *very* early (before the first “goto err”), to - * ensure term_destroy() doesn’t unref a key-binding we haven’t + /* Need to register *very* early (before the first "goto err"), to + * ensure term_destroy() doesn't unref a key-binding we haven't * yet ref:d */ key_binding_new_for_conf(wayl->key_binding_manager, wayl, conf); @@ -1340,11 +1340,11 @@ term_window_configured(struct terminal *term) * * A foot instance can be terminated in two ways: * - * - the client application terminates (user types ‘exit’, or pressed C-d in the + * - the client application terminates (user types 'exit', or pressed C-d in the * shell, etc) * - the foot window is closed * - * Both variants need to trigger to “other” action. I.e. if the client + * Both variants need to trigger to "other" action. I.e. if the client * application is terminated, then we need to close the window. If the window is * closed, we need to terminate the client application. * @@ -1361,7 +1361,7 @@ term_window_configured(struct terminal *term) * - fdm_client_terminated(): reaper callback, called when the client * application has terminated. * - * + Kills the “terminate” timeout timer + * + Kills the "terminate" timeout timer * + Calls shutdown_maybe_done() if the shutdown procedure has already * started (i.e. the window being closed initiated the shutdown) * -OR- @@ -1369,18 +1369,18 @@ term_window_configured(struct terminal *term) * application termination initiated the shutdown). * * - term_shutdown(): unregisters all FDM callbacks, sends SIGTERM to the client - * application and installs a “terminate” timeout timer (if it hasn’t already + * application and installs a "terminate" timeout timer (if it hasn't already * terminated). Finally registers an event FD with the FDM, which is * immediately triggered. This is done to ensure any pending FDM events are * handled before shutting down. * * - fdm_shutdown(): FDM callback, triggered by the event FD in * term_shutdown(). Unmaps and destroys the window resources, and ensures the - * seats’ focused pointers don’t reference us. Finally calls + * seats' focused pointers don't reference us. Finally calls * shutdown_maybe_done(). * - * - fdm_terminate_timeout(): FDM callback for the “terminate” timeout - * timer. This function is called when the client application hasn’t + * - fdm_terminate_timeout(): FDM callback for the "terminate" timeout + * timer. This function is called when the client application hasn't * terminated after 60 seconds (after the SIGTERM). Sends SIGKILL to the * client application. * @@ -1391,7 +1391,7 @@ term_window_configured(struct terminal *term) * It may however also be called without term_shutdown() having been called * (typically in error code paths - for example, when the Wayland connection * is closed by the compositor). In this case, the client application is - * typically still running, and we can’t assume the FDM is running. To handle + * typically still running, and we can't assume the FDM is running. To handle * this, we install configure a 60 second SIGALRM, send SIGTERM to the client * application, and then enter a blocking waitpid(). * @@ -1715,7 +1715,7 @@ term_destroy(struct terminal *term) int ret = EXIT_SUCCESS; if (term->slave > 0) { - /* We’ll deal with this explicitly */ + /* We'll deal with this explicitly */ reaper_del(term->reaper, term->slave); int exit_status; @@ -1729,7 +1729,7 @@ term_destroy(struct terminal *term) kill(-term->slave, SIGTERM); /* - * we’ve closed the ptxm, and sent SIGTERM to the client + * we've closed the ptxm, and sent SIGTERM to the client * application. It *should* exit... * * But, since it is possible to write clients that ignore @@ -2086,10 +2086,10 @@ term_update_scale(struct terminal *term) const struct wl_window *win = term->window; /* - * We have a number of “sources” we can use as scale. We choose + * We have a number of "sources" we can use as scale. We choose * the scale in the following order: * - * - “preferred” scale, from the fractional-scale-v1 protocol + * - "preferred" scale, from the fractional-scale-v1 protocol * - "preferred" scale, from wl_compositor version 6. NOTE: if the compositor advertises version 6 we must use 1.0 until wl_surface.preferred_buffer_scale is sent @@ -2098,7 +2098,7 @@ term_update_scale(struct terminal *term) * - if we're not mapped, and we don't have a last known scaling * factor, use the scaling factor from the first available * output. - * - if there aren’t any outputs available, use 1.0 + * - if there aren't any outputs available, use 1.0 */ const float new_scale = (term_fractional_scaling(term) ? win->scale @@ -2260,7 +2260,7 @@ term_damage_scroll(struct terminal *term, enum damage_type damage_type, dmg->region.start == region.start && dmg->region.end == region.end)) { - /* Make sure we don’t overflow... */ + /* Make sure we don't overflow... */ int new_line_count = (int)dmg->lines + lines; if (likely(new_line_count <= UINT16_MAX)) { dmg->lines = new_line_count; @@ -2324,14 +2324,14 @@ term_erase_scrollback(struct terminal *term) if (sel_end >= 0) { /* * Cancel selection if it touches any of the rows in the - * scrollback, since we can’t have the selection reference + * scrollback, since we can't have the selection reference * soon-to-be deleted rows. * * This is done by range checking the selection range against * the scrollback range. * * To make this comparison simpler, the start/end absolute row - * numbers are “rebased” against the scrollback start, where + * numbers are "rebased" against the scrollback start, where * row 0 is the *first* row in the scrollback. A high number * thus means the row is further *down* in the scrollback, * closer to the screen bottom. @@ -3282,7 +3282,7 @@ term_bell(struct terminal *term) if (!wayl_win_set_urgent(term->window)) { /* * Urgency (xdg-activation) is relatively new in - * Wayland. Fallback to our old, “faked”, urgency - + * Wayland. Fallback to our old, "faked", urgency - * rendering our window margins in red */ term->render.urgency = true; @@ -3728,20 +3728,20 @@ term_command_output_to_text(const struct terminal *term, char **text, size_t *le * column, then the *entire* previous line is part of the command * output. *Including* the newline, if any. * - * Since rows_to_text() doesn’t extract the column + * Since rows_to_text() doesn't extract the column * FTCS_COMMAND_FINISHED was emitted at (that would be wrong - * FTCS_COMMAND_FINISHED is emitted *after* the command output, * not at its last character), the extraction logic will not see * the last newline (this is true for all non-line-wise selection * types), and the extracted text will *not* end with a newline. * - * Here we try to compensate for that. Note that if ‘end_col’ is + * Here we try to compensate for that. Note that if 'end_col' is * not 0, then the command output only covers a partial row, and * thus we do *not* want to append a newline. */ if (end_col > 0) { - /* Command output covers partial row - don’t append newline */ + /* Command output covers partial row - don't append newline */ return true; } diff --git a/terminal.h b/terminal.h index 35127e3c..9e003502 100644 --- a/terminal.h +++ b/terminal.h @@ -152,8 +152,8 @@ struct sixel { * We store the cell dimensions of the time the sixel was emitted. * * If the font size is changed, we rescale the image accordingly, - * to ensure it stays within its cell boundaries. ‘scaled’ is a - * cached, rescaled version of ‘data’ + ‘pix’. + * to ensure it stays within its cell boundaries. 'scaled' is a + * cached, rescaled version of 'data' + 'pix'. */ int cell_width; int cell_height; @@ -346,7 +346,7 @@ struct url { char32_t *key; struct range range; enum url_action action; - bool url_mode_dont_change_url_attr; /* Entering/exiting URL mode doesn’t touch the cells’ attr.url */ + bool url_mode_dont_change_url_attr; /* Entering/exiting URL mode doesn't touch the cells' attr.url */ bool osc8; bool duplicate; }; @@ -382,7 +382,7 @@ struct terminal { bool bracketed_paste; bool focus_events; bool alt_scrolling; - bool modify_other_keys_2; /* True when modifyOtherKeys=2 (i.e. “CSI >4;2m”) */ + bool modify_other_keys_2; /* True when modifyOtherKeys=2 (i.e. "CSI >4;2m") */ enum cursor_origin origin; enum cursor_keys cursor_keys_mode; enum keypad_keys keypad_keys_mode; @@ -644,7 +644,7 @@ struct terminal { } render; struct { - struct grid *grid; /* Original ‘normal’ grid, before resize started */ + struct grid *grid; /* Original 'normal' grid, before resize started */ int old_screen_rows; /* term->rows before resize started */ int old_cols; /* term->cols before resize started */ int old_hide_cursor; /* term->hide_cursor before resize started */ @@ -678,7 +678,7 @@ struct terminal { * Pan is the vertical shape of a pixel * Pad is the horizontal shape of a pixel * - * pan/pad is the sixel’s aspect ratio + * pan/pad is the sixel's aspect ratio */ int pan; int pad; diff --git a/url-mode.c b/url-mode.c index 07499794..0dc594f5 100644 --- a/url-mode.c +++ b/url-mode.c @@ -196,7 +196,7 @@ urls_input(struct seat *seat, struct terminal *term, char32_t wc = xkb_state_key_get_utf32(seat->kbd.xkb_state, key); /* - * Determine if this is a “valid” key. I.e. if there is a URL + * Determine if this is a "valid" key. I.e. if there is a URL * label with a key combo where this key is the next in * sequence. */ @@ -358,7 +358,7 @@ auto_detected(const struct terminal *term, enum url_action action, if (match == NULL) { /* * Character is not a valid URI character. Emit - * the URL we’ve collected so far, *without* + * the URL we've collected so far, *without* * including _this_ character. */ emit_url = true; @@ -410,7 +410,7 @@ auto_detected(const struct terminal *term, enum url_action action, if (c >= term->cols - 1 && row->linebreak) { /* - * Endpoint is inclusive, and we’ll be subtracting + * Endpoint is inclusive, and we'll be subtracting * 1 from the column when emitting the URL. */ c++; @@ -557,7 +557,7 @@ remove_overlapping(url_list_t *urls, int cols) (in_start >= out_start && in_end <= out_end)) { /* - * OSC-8 URLs can’t overlap with each + * OSC-8 URLs can't overlap with each * other. * * Similarly, auto-detected URLs cannot overlap with @@ -633,7 +633,7 @@ generate_key_combos(const struct config *conf, xassert(hints_count - offset >= count); - /* Copy slice of ‘hints’ array to the caller provided array */ + /* Copy slice of 'hints' array to the caller provided array */ for (size_t i = 0; i < hints_count; i++) { if (i >= offset && i < offset + count) combos[i - offset] = hints[i]; @@ -642,7 +642,7 @@ generate_key_combos(const struct config *conf, } free(hints); - /* Sorting is a kind of shuffle, since we’re sorting on the + /* Sorting is a kind of shuffle, since we're sorting on the * *reversed* strings */ qsort(combos, count, sizeof(char32_t *), &c32cmp_qsort_wrapper); @@ -709,7 +709,7 @@ urls_assign_key_combos(const struct config *conf, url_list_t *urls) it->item.key = combos[combo_idx++]; } - /* Free combos we didn’t use up */ + /* Free combos we didn't use up */ for (size_t i = combo_idx; i < count; i++) free(combos[i]); @@ -789,7 +789,7 @@ urls_render(struct terminal *term) } term->render.last_cursor.row = NULL; - /* Clear scroll damage, to ensure we don’t apply it twice (once on + /* Clear scroll damage, to ensure we don't apply it twice (once on * the snapshot:ed grid, and then later again on the real grid) */ tll_free(term->grid->scroll_damage); @@ -833,10 +833,10 @@ urls_reset(struct terminal *term) term->url_grid_snapshot = NULL; /* - * Make sure “last cursor” doesn’t point to a row in the just + * Make sure "last cursor" doesn't point to a row in the just * free:d snapshot grid. * - * Note that it will still be erased properly (if hasn’t already), + * Note that it will still be erased properly (if hasn't already), * since we marked the cell as dirty *before* taking the grid * snapshot. */ diff --git a/vt.c b/vt.c index 0f7bfe63..7529f302 100644 --- a/vt.c +++ b/vt.c @@ -137,12 +137,12 @@ action_execute(struct terminal *term, uint8_t c) /* backspace */ #if 0 /* - * This is the “correct” BS behavior. However, it doesn’t play + * This is the "correct" BS behavior. However, it doesn't play * nicely with bw/auto_left_margin, hence the alternative * implementation below. * - * Note that it breaks vttest “1. Test of cursor movements -> - * Test of autowrap” + * Note that it breaks vttest "1. Test of cursor movements -> + * Test of autowrap" */ term_cursor_left(term, 1); #else @@ -154,7 +154,7 @@ action_execute(struct terminal *term, uint8_t c) likely(term->reverse_wrap && term->auto_margin)) { if (term->grid->cursor.point.row <= term->scroll_region.start) { - /* Don’t wrap past, or inside, the scrolling region(?) */ + /* Don't wrap past, or inside, the scrolling region(?) */ } else term_cursor_to( term, @@ -398,7 +398,7 @@ action_collect(struct terminal *term, uint8_t c) * more. * * As such, we optimize *reading* the private(s), and *resetting* - * them (in action_clear()). Writing is ok if it’s a bit slow. + * them (in action_clear()). Writing is ok if it's a bit slow. */ if ((term->vt.private & 0xff) == 0) @@ -783,7 +783,7 @@ action_utf8_print(struct terminal *term, char32_t wc) /* * We may have a key collisison, so need to check that - * it’s a true match. If not, bump the key and try + * it's a true match. If not, bump the key and try * again. */ @@ -920,8 +920,8 @@ action_utf8_33(struct terminal *term, uint8_t c) return; } - /* Note: the E0 range contains overlong encodings. We don’t try to - detect, as they’ll still decode to valid UTF-32. */ + /* Note: the E0 range contains overlong encodings. We don't try to + detect, as they'll still decode to valid UTF-32. */ action_utf8_print(term, term->vt.utf8); } @@ -960,8 +960,8 @@ action_utf8_44(struct terminal *term, uint8_t c) return; } - /* Note: the F0 range contains overlong encodings. We don’t try to - detect, as they’ll still decode to valid UTF-32. */ + /* Note: the F0 range contains overlong encodings. We don't try to + detect, as they'll still decode to valid UTF-32. */ action_utf8_print(term, term->vt.utf8); } diff --git a/wayland.c b/wayland.c index 271f950e..d3d892df 100644 --- a/wayland.c +++ b/wayland.c @@ -405,7 +405,7 @@ update_term_for_output_change(struct terminal *term) if (fonts_updated) { /* * If the fonts have been updated, the cell dimensions have - * changed. This requires a “forced” resize, since the surface + * changed. This requires a "forced" resize, since the surface * buffer dimensions may not have been updated (in which case * render_resize() normally shortcuts and returns early). */ @@ -921,7 +921,7 @@ xdg_toplevel_wm_capabilities(void *data, static const struct xdg_toplevel_listener xdg_toplevel_listener = { .configure = &xdg_toplevel_configure, - /*.close = */&xdg_toplevel_close, /* epoll-shim defines a macro ‘close’... */ + /*.close = */&xdg_toplevel_close, /* epoll-shim defines a macro 'close'... */ #if defined(XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION) .configure_bounds = &xdg_toplevel_configure_bounds, #endif @@ -991,7 +991,7 @@ xdg_surface_configure(void *data, struct xdg_surface *xdg_surface, #if 1 /* - * TODO: decide if we should do the last “forced” call when ending + * TODO: decide if we should do the last "forced" call when ending * an interactive resize. * * Without it, the last TIOCSWINSZ sent to the client will be a @@ -2152,7 +2152,7 @@ bool wayl_win_set_urgent(struct wl_window *win) { if (win->urgency_token_is_pending) { - /* We already have a pending token. Don’t request another one, + /* We already have a pending token. Don't request another one, * to avoid flooding the Wayland socket */ return true; } From 9f4eb13e9e202a6df61f40bd28f9d86f17d2ab2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 5 Feb 2024 12:01:40 +0100 Subject: [PATCH 37/50] terminfo: smm: enable 8-bit Meta mode To enable 8-bit meta mode, we need to: * disable "send ESC when meta modifies a key" (private mode 1036) * enable "8-bit meta mode" (private mode 1034) rmm reverses the above. Closes #1584 --- foot.info | 2 ++ 1 file changed, 2 insertions(+) diff --git a/foot.info b/foot.info index 89601996..3bab3266 100644 --- a/foot.info +++ b/foot.info @@ -241,6 +241,7 @@ rmcup=\E[?1049l\E[23;0;0t, rmir=\E[4l, rmkx=\E[?1l\E>, + rmm=\E[?1036h\E[?1034l, rmso=\E[27m, rmul=\E[24m, rmxx=\E[29m, @@ -258,6 +259,7 @@ smcup=\E[?1049h\E[22;0;0t, smir=\E[4h, smkx=\E[?1h\E=, + smm=\E[?1036l\E[?1034h, smso=\E[7m, smul=\E[4m, smxx=\E[9m, From 756da873465e188f7b5b3ac1a29c9651d0bf9128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 5 Feb 2024 12:07:47 +0100 Subject: [PATCH 38/50] changelog: smm+rmm --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 096d43a3..48cea306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,11 +77,15 @@ in kitty >= 0.32.0 ([#1561][1561]). * When changing font sizes or display scales in floating windows, the window will be resized as needed to preserve the same grid size. +* `smm` now disables private mode 1036 (_"send ESC when Meta modifies + a key"_), and enables private mode 1034 (_"8-bit Meta mode"_). `rmm` + does the opposite ([#1584][1584]). [1526]: https://codeberg.org/dnkl/foot/issues/1526 [1528]: https://codeberg.org/dnkl/foot/issues/1528 [1561]: https://codeberg.org/dnkl/foot/issues/1561 [kitty-6913]: https://github.com/kovidgoyal/kitty/issues/6913 +[1584]: https://codeberg.org/dnkl/foot/issues/1584 ### Deprecated From 316136f428603481b78d8f6ca747c666e63fd210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 13:08:43 +0100 Subject: [PATCH 39/50] term: ignore attempts to set a title that contains an invalid UTF-8 sequence Setting the title ultimately leads to a call to xdg_toplevel::set_title(). It is a protocol violation to try to set a title that contains an invalid UTF-8 sequence: The string must be encoded in UTF-8. Closes #1552 --- CHANGELOG.md | 3 +++ terminal.c | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48cea306..b3255565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,10 +102,13 @@ set in `[environment]`. * Environment variables normally set by foot lost with `footclient -E,--client-environment` ([#1568][1568]). +* XDG toplevel protocol violation, by trying to set a title that + contains an invalid UTF-8 sequence ([#1552][1552]). [1531]: https://codeberg.org/dnkl/foot/issues/1531 [1573]: https://codeberg.org/dnkl/foot/issues/1573 [1568]: https://codeberg.org/dnkl/foot/issues/1568 +[1552]: https://codeberg.org/dnkl/foot/issues/1552 ### Security diff --git a/terminal.c b/terminal.c index ed13073e..f93e7abc 100644 --- a/terminal.c +++ b/terminal.c @@ -3249,6 +3249,13 @@ term_set_window_title(struct terminal *term, const char *title) if (term->window_title != NULL && streq(term->window_title, title)) return; + if (mbsntoc32(NULL, title, strlen(title), 0) == (char32_t)-1) { + /* It's an xdg_toplevel::set_title() protocol violation to set + a title with an invalid UTF-8 sequence */ + LOG_WARN("%s: title is not valid UTF-8, ignoring", title); + return; + } + free(term->window_title); term->window_title = xstrdup(title); render_refresh_title(term); From 41dc259744675e93239295286795ca4e8191f2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 13:38:08 +0100 Subject: [PATCH 40/50] doc: foot-ctlseq: add OSC 133 C/D (command output start/end) --- doc/foot-ctlseqs.7.scd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/foot-ctlseqs.7.scd b/doc/foot-ctlseqs.7.scd index d26bb39d..68a54beb 100644 --- a/doc/foot-ctlseqs.7.scd +++ b/doc/foot-ctlseqs.7.scd @@ -687,6 +687,12 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_. | \\E] 133 ; A \\E\\ : FinalTerm : Mark start of shell prompt +| \\E] 133 ; C \\E\\ +: FinalTerm +: Mark start of command output +| \\E] 133 ; D \\E\\ +: FinalTerm +: Mark end of command output | \\E] 555 \\E\\ : foot : Flash the entire terminal (foot extension) From 4801d3a305e80b449f041d469432780d7b0cc179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 13:41:09 +0100 Subject: [PATCH 41/50] term: drop term->render.title.is_armed This boolean isn't needed. The idea was probably to not re-program the timer unnecessarily, or even to prevent it from being moved forward in time indefinitely. However, the logic has (probably) gone through some changes, that now makes it irrelevant. The timer isn't moved forward indefinitely; it is always set to 8ms from the last title update. The closer we get to that point in time, the smaller the timeout we set. Now, is_armed _did_ prevent the timer from being re-programmed. But that tiny performance tweak isn't really necessary, as the title should, in normal cases, not be set that often anyway. --- render.c | 3 --- terminal.c | 2 -- terminal.h | 1 - 3 files changed, 6 deletions(-) diff --git a/render.c b/render.c index 2bfe36e8..13d348f3 100644 --- a/render.c +++ b/render.c @@ -4508,9 +4508,6 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data) void render_refresh_title(struct terminal *term) { - if (term->render.title.is_armed) - return; - struct timespec now; if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) return; diff --git a/terminal.c b/terminal.c index f93e7abc..7ace10ef 100644 --- a/terminal.c +++ b/terminal.c @@ -622,7 +622,6 @@ fdm_title_update_timeout(struct fdm *fdm, int fd, int events, void *data) struct itimerspec reset = {{0}}; timerfd_settime(term->render.title.timer_fd, 0, &reset, NULL); - term->render.title.is_armed = false; render_refresh_title(term); return true; @@ -1209,7 +1208,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .scrollback_lines = conf->scrollback.lines, .app_sync_updates.timer_fd = app_sync_updates_fd, .title = { - .is_armed = false, .timer_fd = title_update_fd, }, .workers = { diff --git a/terminal.h b/terminal.h index 9e003502..7b743c09 100644 --- a/terminal.h +++ b/terminal.h @@ -603,7 +603,6 @@ struct terminal { struct { struct timespec last_update; - bool is_armed; int timer_fd; } title; From 6c56b04b3f312be8dcee307e29515f3c83b3ae87 Mon Sep 17 00:00:00 2001 From: delthas Date: Mon, 4 Sep 2023 14:02:05 +0200 Subject: [PATCH 42/50] osc: add support for osc 176 (app ID) This adds support for a new OSC escape sequence: OSC 176, that lets terminal programs tell the terminal the name of the app that is running. foot then sets the app ID of the toplevel to that ID, which lets the compositor know which app is running, and typically sets the appropriate icon, window grouping, ... See: https://gist.github.com/delthas/d451e2cc1573bb2364839849c7117239 --- README.md | 1 + doc/foot-ctlseqs.7.scd | 5 ++++ notify.c | 2 +- osc.c | 4 +++ render.c | 22 +++++++++++++++ render.h | 1 + terminal.c | 61 +++++++++++++++++++++++++++++++++++++++++- terminal.h | 7 +++++ 8 files changed, 101 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c8d3878..75e10889 100644 --- a/README.md +++ b/README.md @@ -536,6 +536,7 @@ with the terminal emulator itself. Foot implements the following OSCs: * `OSC 117` - reset highlight background color * `OSC 119` - reset highlight foreground color * `OSC 133` - [shell integration](#shell-integration) +* `OSC 176` - set app ID * `OSC 555` - flash screen (**foot specific**) * `OSC 777` - desktop notification (only the `;notify` sub-command of OSC 777 is supported.) diff --git a/doc/foot-ctlseqs.7.scd b/doc/foot-ctlseqs.7.scd index 68a54beb..64c56d5d 100644 --- a/doc/foot-ctlseqs.7.scd +++ b/doc/foot-ctlseqs.7.scd @@ -693,6 +693,11 @@ All _OSC_ sequences begin with *\\E]*, sometimes abbreviated _OSC_. | \\E] 133 ; D \\E\\ : FinalTerm : Mark end of command output +| \\E] 176 ; _app-id_ \\E\\ +: foot +: Set app ID. _app-id_ is optional; if assigned, + the terminal window App ID will be set to the value. + An empty App ID resets the value to the default. | \\E] 555 \\E\\ : foot : Flash the entire terminal (foot extension) diff --git a/notify.c b/notify.c index 04427477..7a208479 100644 --- a/notify.c +++ b/notify.c @@ -36,7 +36,7 @@ notify_notify(const struct terminal *term, const char *title, const char *body) if (!spawn_expand_template( &term->conf->notify, 4, (const char *[]){"app-id", "window-title", "title", "body"}, - (const char *[]){term->conf->app_id, term->window_title, title, body}, + (const char *[]){term->app_id ? term->app_id : term->conf->app_id, term->window_title, title, body}, &argc, &argv)) { return; diff --git a/osc.c b/osc.c index 1ea61a3e..28e93e51 100644 --- a/osc.c +++ b/osc.c @@ -916,6 +916,10 @@ osc_dispatch(struct terminal *term) } break; + case 176: + term_set_app_id(term, string); + break; + case 555: osc_flash(term); break; diff --git a/render.c b/render.c index 13d348f3..f82e54f0 100644 --- a/render.c +++ b/render.c @@ -4529,6 +4529,28 @@ render_refresh_title(struct terminal *term) render_refresh_csd(term); } +void +render_refresh_app_id(struct terminal *term) +{ + struct timespec now; + if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) + return; + + struct timespec diff; + timespec_sub(&now, &term->render.app_id.last_update, &diff); + + if (diff.tv_sec == 0 && diff.tv_nsec < 8333 * 1000) { + const struct itimerspec timeout = { + .it_value = {.tv_nsec = 8333 * 1000 - diff.tv_nsec}, + }; + + timerfd_settime(term->render.app_id.timer_fd, 0, &timeout, NULL); + } else { + term->render.app_id.last_update = now; + xdg_toplevel_set_app_id(term->window->xdg_toplevel, term->app_id ? term->app_id : term->conf->app_id); + } +} + void render_refresh(struct terminal *term) { diff --git a/render.h b/render.h index 78ebae40..cfedf311 100644 --- a/render.h +++ b/render.h @@ -21,6 +21,7 @@ bool render_resize( struct terminal *term, int width, int height, uint8_t resize_options); void render_refresh(struct terminal *term); +void render_refresh_app_id(struct terminal *term); void render_refresh_csd(struct terminal *term); void render_refresh_search(struct terminal *term); void render_refresh_title(struct terminal *term); diff --git a/terminal.c b/terminal.c index 7ace10ef..bc7dc428 100644 --- a/terminal.c +++ b/terminal.c @@ -627,6 +627,30 @@ fdm_title_update_timeout(struct fdm *fdm, int fd, int events, void *data) return true; } +static bool +fdm_app_id_update_timeout(struct fdm *fdm, int fd, int events, void *data) +{ + if (events & EPOLLHUP) + return false; + + struct terminal *term = data; + uint64_t unused; + ssize_t ret = read(term->render.app_id.timer_fd, &unused, sizeof(unused)); + + if (ret < 0) { + if (errno == EAGAIN) + return true; + LOG_ERRNO("failed to read app ID update throttle timer"); + return false; + } + + struct itimerspec reset = {{0}}; + timerfd_settime(term->render.app_id.timer_fd, 0, &reset, NULL); + + render_refresh_app_id(term); + return true; +} + static bool initialize_render_workers(struct terminal *term) { @@ -1050,6 +1074,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, int delay_upper_fd = -1; int app_sync_updates_fd = -1; int title_update_fd = -1; + int app_id_update_fd = -1; struct terminal *term = malloc(sizeof(*term)); if (unlikely(term == NULL)) { @@ -1084,6 +1109,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, goto close_fds; } + if ((app_id_update_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK)) < 0) + { + LOG_ERRNO("failed to create app ID update throttle timer FD"); + goto close_fds; + } + if (ioctl(ptmx, (unsigned int)TIOCSWINSZ, &(struct winsize){.ws_row = 24, .ws_col = 80}) < 0) { @@ -1114,7 +1145,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, !fdm_add(fdm, delay_lower_fd, EPOLLIN, &fdm_delayed_render, term) || !fdm_add(fdm, delay_upper_fd, EPOLLIN, &fdm_delayed_render, term) || !fdm_add(fdm, app_sync_updates_fd, EPOLLIN, &fdm_app_sync_updates_timeout, term) || - !fdm_add(fdm, title_update_fd, EPOLLIN, &fdm_title_update_timeout, term)) + !fdm_add(fdm, title_update_fd, EPOLLIN, &fdm_title_update_timeout, term) || + !fdm_add(fdm, app_id_update_fd, EPOLLIN, &fdm_app_id_update_timeout, term)) { goto err; } @@ -1210,6 +1242,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .title = { .timer_fd = title_update_fd, }, + .app_id = { + .timer_fd = app_id_update_fd, + }, .workers = { .count = conf->render_worker_count, .queue = tll_init(), @@ -1318,6 +1353,7 @@ close_fds: fdm_del(fdm, delay_upper_fd); fdm_del(fdm, app_sync_updates_fd); fdm_del(fdm, title_update_fd); + fdm_del(fdm, app_id_update_fd); free(term); return NULL; @@ -1510,6 +1546,7 @@ term_shutdown(struct terminal *term) fdm_del(term->fdm, term->selection.auto_scroll.fd); fdm_del(term->fdm, term->render.app_sync_updates.timer_fd); + fdm_del(term->fdm, term->render.app_id.timer_fd); fdm_del(term->fdm, term->render.title.timer_fd); fdm_del(term->fdm, term->delayed_render_timer.lower_fd); fdm_del(term->fdm, term->delayed_render_timer.upper_fd); @@ -1548,6 +1585,7 @@ term_shutdown(struct terminal *term) term->selection.auto_scroll.fd = -1; term->render.app_sync_updates.timer_fd = -1; + term->render.app_id.timer_fd = -1; term->render.title.timer_fd = -1; term->delayed_render_timer.lower_fd = -1; term->delayed_render_timer.upper_fd = -1; @@ -1601,6 +1639,7 @@ term_destroy(struct terminal *term) fdm_del(term->fdm, term->selection.auto_scroll.fd); fdm_del(term->fdm, term->render.app_sync_updates.timer_fd); + fdm_del(term->fdm, term->render.app_id.timer_fd); fdm_del(term->fdm, term->render.title.timer_fd); fdm_del(term->fdm, term->delayed_render_timer.lower_fd); fdm_del(term->fdm, term->delayed_render_timer.upper_fd); @@ -1644,6 +1683,7 @@ term_destroy(struct terminal *term) composed_free(term->composed); + free(term->app_id); free(term->window_title); tll_free_and_free(term->window_title_stack, free); @@ -3260,6 +3300,25 @@ term_set_window_title(struct terminal *term, const char *title) term->window_title_has_been_set = true; } +void +term_set_app_id(struct terminal *term, const char *app_id) +{ + if (app_id != NULL && *app_id == '\0') + app_id = NULL; + if (term->app_id == NULL && app_id == NULL) + return; + if (term->app_id != NULL && app_id != NULL && strcmp(term->app_id, app_id) == 0) + return; + + free(term->app_id); + if (app_id != NULL) { + term->app_id = xstrdup(app_id); + } else { + term->app_id = NULL; + } + render_refresh_app_id(term); +} + void term_flash(struct terminal *term, unsigned duration_ms) { diff --git a/terminal.h b/terminal.h index 7b743c09..49c88926 100644 --- a/terminal.h +++ b/terminal.h @@ -483,6 +483,7 @@ struct terminal { bool window_title_has_been_set; char *window_title; tll(char *) window_title_stack; + char *app_id; struct { bool active; @@ -606,6 +607,11 @@ struct terminal { int timer_fd; } title; + struct { + struct timespec last_update; + int timer_fd; + } app_id; + uint32_t scrollback_lines; /* Number of scrollback lines, from conf (TODO: move out from render struct?) */ struct { @@ -832,6 +838,7 @@ void term_xcursor_update_for_seat(struct terminal *term, struct seat *seat); void term_set_user_mouse_cursor(struct terminal *term, const char *cursor); void term_set_window_title(struct terminal *term, const char *title); +void term_set_app_id(struct terminal *term, const char *app_id); void term_flash(struct terminal *term, unsigned duration_ms); void term_bell(struct terminal *term); bool term_spawn_new(const struct terminal *term); From 22f04f6a84b69937a4b8516f5b45404c4565953d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 13:49:46 +0100 Subject: [PATCH 43/50] changelog: OSC-176 - set app-id --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3255565..b2e4a62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,8 @@ * Support for custom (i.e. other than ctrl/shift/alt/super) modifiers in key bindings ([#1348][1348]). * `pipe-command-output` key binding. +* Support for OSC-176, _"Set App-ID"_ + (https://gist.github.com/delthas/d451e2cc1573bb2364839849c7117239). [1348]: https://codeberg.org/dnkl/foot/issues/1348 From 4b075bb0750754f219704b99486605ee81634c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 6 Feb 2024 13:55:30 +0100 Subject: [PATCH 44/50] osc: 176 (app-id): implement query+reply Applications can now query for the current app-id with: \E] 176 ; ? \E\\ The reply is \E] 176 ; \E\\ --- osc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osc.c b/osc.c index 28e93e51..06cc7db6 100644 --- a/osc.c +++ b/osc.c @@ -917,6 +917,18 @@ osc_dispatch(struct terminal *term) break; case 176: + if (string[0] == '?' && string[1] == '\0') { + const char *terminator = term->vt.osc.bel ? "\a" : "\033\\"; + char *reply = xasprintf( + "\033]176;%s%s", + term->app_id != NULL ? term->app_id : term->conf->app_id, + terminator); + + term_to_slave(term, reply, strlen(reply)); + free(reply); + break; + } + term_set_app_id(term, string); break; From af114f81a0cef1d789c354c4d05140400210b136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= <daniel@ekloef.se> Date: Tue, 6 Feb 2024 14:03:07 +0100 Subject: [PATCH 45/50] pgo: fix function prototype for stub function get_current_modifiers() --- pgo/pgo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pgo/pgo.c b/pgo/pgo.c index 54618204..6d4dab17 100644 --- a/pgo/pgo.c +++ b/pgo/pgo.c @@ -173,7 +173,8 @@ void search_selection_cancelled(struct terminal *term) {} void get_current_modifiers(const struct seat *seat, xkb_mod_mask_t *effective, - xkb_mod_mask_t *consumed, uint32_t key) {} + xkb_mod_mask_t *consumed, uint32_t key, + bool filter_locked) {} static struct key_binding_set kbd; static bool kbd_initialized = false; From 3b5d83a3ec0b0bba3a8e56d97aaa6d14c46417f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= <daniel@ekloef.se> Date: Tue, 6 Feb 2024 14:04:22 +0100 Subject: [PATCH 46/50] pgo: add missing stub for render_refresh_app_id() --- pgo/pgo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pgo/pgo.c b/pgo/pgo.c index 6d4dab17..2fd4e837 100644 --- a/pgo/pgo.c +++ b/pgo/pgo.c @@ -68,6 +68,7 @@ render_resize_force(struct terminal *term, int width, int height) void render_refresh(struct terminal *term) {} void render_refresh_csd(struct terminal *term) {} void render_refresh_title(struct terminal *term) {} +void render_refresh_app_id(struct terminal *term) {} bool render_xcursor_is_valid(const struct seat *seat, const char *cursor) From ebbee61f144e5f3f662d8b2421ab7429145a6637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= <daniel@ekloef.se> Date: Tue, 6 Feb 2024 14:04:59 +0100 Subject: [PATCH 47/50] input: remove debug logging --- input.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/input.c b/input.c index cfbd63b3..2dd1d9e4 100644 --- a/input.c +++ b/input.c @@ -1562,7 +1562,6 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, bind->mods == (mods & ~consumed) && execute_binding(seat, term, bind, serial, 1)) { - LOG_WARN("matched translated symbol"); goto maybe_repeat; } @@ -1574,7 +1573,6 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (bind->k.sym == raw_syms[i] && execute_binding(seat, term, bind, serial, 1)) { - LOG_WARN("matched untranslated symbol"); goto maybe_repeat; } } @@ -1584,7 +1582,6 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, if (code->item == key && execute_binding(seat, term, bind, serial, 1)) { - LOG_WARN("matched raw key code"); goto maybe_repeat; } } From bc8c2e01124eea4911df9750583bac11160d4d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= <daniel@ekloef.se> Date: Wed, 7 Feb 2024 16:22:33 +0100 Subject: [PATCH 48/50] wayland: regression: use correct scaling factor when calling render_resize() When an output property (such as scaling factor) has changed, we need to call render_resize() to ensure the window surface is correct (for example, we may have to change its scale). The width/height parameters are in *logical* pixels (i.e. already scaled). For render_resize() to work correctly when the scale is being changed, it needs to be called with *current* logical size. This means we need to scale our current width/height using the *old* scaling factor. --- wayland.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wayland.c b/wayland.c index d3d892df..c5feb6a1 100644 --- a/wayland.c +++ b/wayland.c @@ -392,6 +392,8 @@ static void update_term_for_output_change(struct terminal *term) { const float old_scale = term->scale; + const float logical_width = term->width / old_scale; + const float logical_height = term->height / old_scale; /* Note: order matters! term_update_scale() must come first */ bool scale_updated = term_update_scale(term); @@ -400,7 +402,7 @@ update_term_for_output_change(struct terminal *term) csd_reload_font(term->window, old_scale); - uint8_t resize_opts = RESIZE_KEEP_GRID; + enum resize_options resize_opts = RESIZE_KEEP_GRID; if (fonts_updated) { /* @@ -428,8 +430,8 @@ update_term_for_output_change(struct terminal *term) render_resize( term, - (int)roundf(term->width / term->scale), - (int)roundf(term->height / term->scale), + (int)roundf(logical_width), + (int)roundf(logical_height), resize_opts); } From 69df42c51bfed4ac25130751a578d6d5487c908a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= <daniel@ekloef.se> Date: Wed, 7 Feb 2024 17:09:01 +0100 Subject: [PATCH 49/50] doc: better examples for pipe-* commands --- doc/foot.ini.5.scd | 10 ++++------ foot.ini | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 14999a8b..f184eb9a 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -858,16 +858,14 @@ e.g. *search-start=none*. use *sh -c "command line"* if you need that. Example #1: - # Extract currently visible URLs, let user choose one (via fuzzel), then launch firefox with the selected URL++ -*pipe-visible=[sh -c "xurls | uniq | tac | fuzzel | xargs -r - firefox"] Control+Print* +*pipe-visible=[sh -c "xurls | uniq | tac | fuzzel | xargs -r firefox"] Control+Print* Example #2: - # Write scrollback content to /tmp/foot-scrollback.txt++ -*pipe-scrollback=[sh -c "cat - > /tmp/foot-scrollback.txt"] - Control+Shift+Print* + # Open scrollback contents in Emacs running in a new foot instance++ +*pipe-scrollback=[sh -c "f=$(mktemp) && cat - > $f && foot emacsclient -t $f; rm $f"] Control+Shift+Print* + Default: _none_ *show-urls-launch* diff --git a/foot.ini b/foot.ini index 42a71e58..9fd6c9db 100644 --- a/foot.ini +++ b/foot.ini @@ -158,7 +158,7 @@ # pipe-visible=[sh -c "xurls | fuzzel | xargs -r firefox"] none # pipe-scrollback=[sh -c "xurls | fuzzel | xargs -r firefox"] none # pipe-selected=[xargs -r firefox] none -# pipe-command-output=[sh -c "cat - > /tmp/foot-cmd-out.txt"] none # Write output of last command to /tmp/foot-cmd-out.txt (requires shell integration) +# pipe-command-output=[wl-copy] none # Copy last command's output to the clipboard # show-urls-launch=Control+Shift+o # show-urls-copy=none # show-urls-persistent=none From 9d9690410a72e03511bcc19e6f4a848d450fd0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= <daniel@ekloef.se> Date: Thu, 8 Feb 2024 16:44:55 +0100 Subject: [PATCH 50/50] pgo: render_resize_force() has been removed, adjust stub accordingly Closes #1601 --- pgo/pgo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pgo/pgo.c b/pgo/pgo.c index 2fd4e837..204c024d 100644 --- a/pgo/pgo.c +++ b/pgo/pgo.c @@ -60,7 +60,8 @@ fdm_event_del(struct fdm *fdm, int fd, int events) } bool -render_resize_force(struct terminal *term, int width, int height) +render_resize( + struct terminal *term, int width, int height, uint8_t resize_options) { return true; }