From 62b0b65d4712abd9ecd21ec2fe684c87a868bcc1 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 2 Aug 2024 14:33:26 +0200 Subject: changelog: add new 'unreleased' section --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1549a5d..ef655a22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +* [Unreleased](#unreleased) * [1.18.0](#1-18-0) * [1.17.2](#1-17-2) * [1.17.1](#1-17-1) @@ -52,6 +53,16 @@ * [1.2.0](#1-2-0) +## Unreleased +### Added +### Changed +### Deprecated +### Removed +### Fixed +### Security +### Contributors + + ## 1.18.0 ### Added -- cgit v1.3 From f87c9bb9f70f1a6c8c7081c762c15ba7eaaf971e Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 3 Aug 2024 08:12:13 +0100 Subject: xmalloc: remove delim param from xstrjoin() and add separate xstrjoin3() This avoids the need for an unused third argument for most xstrjoin() calls and replaces the cases where it's needed with a more flexible function. Code generation is the same in both cases, when there are 2 string params and a compile-time known delimiter. This commit also converts 4 uses of xasprintf() to use xstrjoin*(). See also: https://godbolt.org/z/xsjrhv9b6 --- config.c | 10 +++++----- main.c | 18 +++++++++++------- notify.c | 2 +- osc.c | 8 ++++---- slave.c | 4 ++-- terminal.c | 8 ++++---- xmalloc.h | 21 +++++++++++++++------ 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/config.c b/config.c index 46b3d2d2..bf3c4175 100644 --- a/config.c +++ b/config.c @@ -356,9 +356,9 @@ open_config(void) /* First, check XDG_CONFIG_HOME (or .config, if unset) */ if (xdg_config_home != NULL && xdg_config_home[0] != '\0') - path = xstrjoin(xdg_config_home, "/foot/foot.ini", 0); + path = xstrjoin(xdg_config_home, "/foot/foot.ini"); else if (home_dir != NULL) - path = xstrjoin(home_dir, "/.config/foot/foot.ini", 0); + path = xstrjoin(home_dir, "/.config/foot/foot.ini"); if (path != NULL) { LOG_DBG("checking for %s", path); @@ -383,7 +383,7 @@ open_config(void) conf_dir = strtok(NULL, ":")) { free(path); - path = xstrjoin(conf_dir, "/foot/foot.ini", 0); + path = xstrjoin(conf_dir, "/foot/foot.ini"); LOG_DBG("checking for %s", path); int fd = open(path, O_RDONLY | O_CLOEXEC); @@ -843,7 +843,7 @@ parse_section_main(struct context *ctx) return false; } - _include_path = xasprintf("%s/%s", home_dir, value + 2); + _include_path = xstrjoin3(home_dir, "/", value + 2); include_path = _include_path; } else include_path = value; @@ -2931,7 +2931,7 @@ get_server_socket_path(void) const char *wayland_display = getenv("WAYLAND_DISPLAY"); if (wayland_display == NULL) { - return xstrjoin(xdg_runtime, "/foot.sock", 0); + return xstrjoin(xdg_runtime, "/foot.sock"); } return xasprintf("%s/foot-%s.sock", xdg_runtime, wayland_display); diff --git a/main.c b/main.c index a6ec1cb7..f46d712e 100644 --- a/main.c +++ b/main.c @@ -258,7 +258,7 @@ main(int argc, char *const *argv) break; case 't': - tll_push_back(overrides, xstrjoin("term=", optarg, 0)); + tll_push_back(overrides, xstrjoin("term=", optarg)); break; case 'L': @@ -266,11 +266,11 @@ main(int argc, char *const *argv) break; case 'T': - tll_push_back(overrides, xstrjoin("title=", optarg, 0)); + tll_push_back(overrides, xstrjoin("title=", optarg)); break; case 'a': - tll_push_back(overrides, xstrjoin("app-id=", optarg, 0)); + tll_push_back(overrides, xstrjoin("app-id=", optarg)); break; case 'D': { @@ -284,7 +284,7 @@ main(int argc, char *const *argv) } case 'f': { - char *font_override = xstrjoin("font=", optarg, 0); + char *font_override = xstrjoin("font=", optarg); tll_push_back(overrides, font_override); break; } @@ -658,15 +658,19 @@ out: UNITTEST { - char *s = xstrjoin("foo", "bar", 0); + char *s = xstrjoin("foo", "bar"); xassert(streq(s, "foobar")); free(s); - s = xstrjoin("foo", "bar", ' '); + s = xstrjoin3("foo", " ", "bar"); xassert(streq(s, "foo bar")); free(s); - s = xstrjoin("foo", "bar", ','); + s = xstrjoin3("foo", ",", "bar"); xassert(streq(s, "foo,bar")); free(s); + + s = xstrjoin3("foo", "bar", "baz"); + xassert(streq(s, "foobarbaz")); + free(s); } diff --git a/notify.c b/notify.c index 9d2d3c71..15139c40 100644 --- a/notify.c +++ b/notify.c @@ -77,7 +77,7 @@ write_icon_file(const void *data, size_t data_sz, int *fd, char **filename, LOG_DBG("wrote icon data to %s", name); *filename = xstrdup(name); - *symbolic_name = xasprintf("file://%s", *filename); + *symbolic_name = xstrjoin("file://", *filename); return true; } diff --git a/osc.c b/osc.c index eb5e9718..92e3cad6 100644 --- a/osc.c +++ b/osc.c @@ -767,7 +767,7 @@ kitty_notification(struct terminal *term, char *string) else { /* Append, comma separated */ char *old_category = category; - category = xstrjoin(old_category, decoded, ','); + category = xstrjoin3(old_category, ",", decoded); free(decoded); free(old_category); } @@ -910,7 +910,7 @@ kitty_notification(struct terminal *term, char *string) category = NULL; /* Prevent double free */ } else { /* Append, comma separated */ - char *new_category = xstrjoin(notif->category, category, ','); + char *new_category = xstrjoin3(notif->category, ",", category); free(notif->category); notif->category = new_category; } @@ -929,7 +929,7 @@ kitty_notification(struct terminal *term, char *string) payload = NULL; } else { char *old = *ptr; - *ptr = xstrjoin(old, payload, 0); + *ptr = xstrjoin(old, payload); free(old); } break; @@ -1002,7 +1002,7 @@ kitty_notification(struct terminal *term, char *string) alive_ids = xstrdup(item_id); else { char *old_alive_ids = alive_ids; - alive_ids = xstrjoin(old_alive_ids, item_id, ','); + alive_ids = xstrjoin3(old_alive_ids, ",", item_id); free(old_alive_ids); } } diff --git a/slave.c b/slave.c index 00105adb..bf1ca8e0 100644 --- a/slave.c +++ b/slave.c @@ -55,7 +55,7 @@ find_file_in_path(const char *file) path != NULL; path = strtok(NULL, ":")) { - char *full = xasprintf("%s/%s", path, file); + char *full = xstrjoin3(path, "/", file); if (access(full, F_OK) == 0) { free(path_list); return full; @@ -329,7 +329,7 @@ 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); + char *e = xstrjoin3(name, "=", value); /* Search for existing variable. If found, replace it with the new value */ diff --git a/terminal.c b/terminal.c index 16de2d65..5699e6b5 100644 --- a/terminal.c +++ b/terminal.c @@ -994,7 +994,7 @@ reload_fonts(struct terminal *term, bool resize_grid) snprintf(size, sizeof(size), ":size=%.2f", term->font_sizes[i][j].pt_size * scale); - names[i][j] = xstrjoin(font->pattern, size, 0); + names[i][j] = xstrjoin(font->pattern, size); } } @@ -1021,9 +1021,9 @@ reload_fonts(struct terminal *term, bool resize_grid) char *attrs[4] = { [0] = dpi, /* Takes ownership */ - [1] = xstrjoin(dpi, !custom_bold ? ":weight=bold" : "", 0), - [2] = xstrjoin(dpi, !custom_italic ? ":slant=italic" : "", 0), - [3] = xstrjoin(dpi, !custom_bold_italic ? ":weight=bold:slant=italic" : "", 0), + [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]; diff --git a/xmalloc.h b/xmalloc.h index 76db7e1b..8a2c208f 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -25,16 +25,25 @@ xmemdup(const void *ptr, size_t size) } static inline char * -xstrjoin(const char *s1, const char *s2, char delim) +xstrjoin(const char *s1, const char *s2) { size_t n1 = strlen(s1); - size_t n2 = delim > 0 ? 1 : 0; - size_t n3 = strlen(s2); + size_t n2 = strlen(s2); + char *joined = xmalloc(n1 + n2 + 1); + memcpy(joined, s1, n1); + memcpy(joined + n1, s2, n2 + 1); + return joined; +} +static inline char * +xstrjoin3(const char *s1, const char *s2, const char *s3) +{ + size_t n1 = strlen(s1); + size_t n2 = strlen(s2); + size_t n3 = strlen(s3); char *joined = xmalloc(n1 + n2 + n3 + 1); memcpy(joined, s1, n1); - if (delim > 0) - joined[n1] = delim; - memcpy(joined + n1 + n2, s2, n3 + 1); + memcpy(joined + n1, s2, n2); + memcpy(joined + n1 + n2, s3, n3 + 1); return joined; } -- cgit v1.3 From 6b72108ee220dd64a3ff5a43a6c84d99078da62e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 3 Aug 2024 11:05:58 +0200 Subject: osc: kitty notifications: ignore invalid IDs Notification IDs must only use characters from [a-zA-Z0-9_-+.] Terminals **must** sanitize ids received from client programs before sending them back in responses, to mitigate input injection based attacks. That is, they must either reject ids containing characters not from the above set, or remove bad characters when reading ids sent to them. Foot implements the first: reject IDs containing characters not from the above set. --- osc.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/osc.c b/osc.c index eb5e9718..3ae8a051 100644 --- a/osc.c +++ b/osc.c @@ -564,6 +564,33 @@ osc_notify(struct terminal *term, char *string) }); } +IGNORE_WARNING("-Wpedantic") +static bool +verify_kitty_id_is_valid(const char *id) +{ + const size_t len = strlen(id); + + for (size_t i = 0; i < len; i++) { + switch (id[i]) { + case 'a' ... 'z': + case 'A' ... 'Z': + case '0' ... '9': + case '_': + case '-': + case '+': + case '.': + break; + + default: + return false; + } + } + + return true; +} +UNIGNORE_WARNINGS + + static void kitty_notification(struct terminal *term, char *string) { @@ -672,8 +699,11 @@ kitty_notification(struct terminal *term, char *string) case 'i': /* id */ - free(id); - id = xstrdup(value); + if (verify_kitty_id_is_valid(value)) { + free(id); + id = xstrdup(value); + } else + LOG_WARN("OSC-99: ignoring invalid 'i' identifier"); break; case 'p': @@ -963,7 +993,7 @@ kitty_notification(struct terminal *term, char *string) tll_push_back(notif->actions, xstrdup(button)); } } - + break; } } -- cgit v1.3 From a3a35f2c8c6ce3b35ec22627cb3097f621c46373 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 3 Aug 2024 09:04:24 +0200 Subject: term: reload_fonts(): don't ignore return value of thrd_join() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should fix the ‘ret’ may be used uninitialized warning Closes #1789 --- terminal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/terminal.c b/terminal.c index 5699e6b5..fe97e958 100644 --- a/terminal.c +++ b/terminal.c @@ -1048,8 +1048,10 @@ reload_fonts(struct terminal *term, bool resize_grid) for (size_t i = 0; i < 4; i++) { if (tids[i] != 0) { int ret; - thrd_join(tids[i], &ret); - success = success && ret; + if (thrd_join(tids[i], &ret) != 0) + success = false; + else + success = success && ret; } else success = false; } -- cgit v1.3 From 63492624918cd23a5efdd9b8a8b4f057da66d961 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 4 Aug 2024 14:16:56 +0200 Subject: osc: kitty notifications: implement s=silent This implements part of the new 's' (sound) parameter; the 'silent' value. When s=silent, we set the ${muted} template argument to "true". It is intended to set the 'suppress-sound' hint: notify-send --hint BOOLEAN:suppress-sound:${muted} --- config.c | 2 +- doc/foot.ini.5.scd | 6 ++++++ foot.ini | 2 +- notify.c | 13 ++++++++----- notify.h | 2 ++ osc.c | 29 +++++++++++++++++++++++++---- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index bf3c4175..5dbbacb7 100644 --- a/config.c +++ b/config.c @@ -3242,7 +3242,7 @@ config_load(struct config *conf, const char *conf_path, parse_modifiers(XKB_MOD_NAME_SHIFT, 5, &conf->mouse.selection_override_modifiers); tokenize_cmdline( - "notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body}", + "notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --hint BOOLEAN:suppress-sound:${muted} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body}", &conf->desktop_notifications.command.argv.args); tokenize_cmdline("--action ${action-name}=${action-label}", &conf->desktop_notifications.command_action_arg.argv.args); tokenize_cmdline("xdg-open ${url}", &conf->url.launch.argv.args); diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 8f9ffe57..6db7ffae 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -459,6 +459,11 @@ Note: do not set *TERM* here; use the *term* option in the main below. Can be used together with e.g. notify-send's *--replace-id* option. + _${muted}_ is replaced by either *true* or *false*, depending + on whether the notification has requested all notification + sounds be muted. It is intended to set the *suppress-sound* + hint (with e.g. notify-send's *--hint* option). + _${action-argument}_ will be expanded to the *command-action-argument* option, for each notification action. There will always be at least one action, the @@ -568,6 +573,7 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 --urgency ${urgency}++ --expire-time ${expire-time}++ --hint STRING:image-path:${icon}++ + --hint BOOLEAN:suppress-sound:${muted}++ --replace-id ${replace-id}++ ${action-argument}++ --print-id++ diff --git a/foot.ini b/foot.ini index 029daa9b..fba9305e 100644 --- a/foot.ini +++ b/foot.ini @@ -47,7 +47,7 @@ # command-focused=no [desktop-notifications] -# command=notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body} +# command=notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --hint BOOLEAN:suppress-sound:${muted} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body} # command-action-argument=--action ${action-name}=${action-label} # close="" # inhibit-when-focused=yes diff --git a/notify.c b/notify.c index 15139c40..0b37f40a 100644 --- a/notify.c +++ b/notify.c @@ -421,9 +421,12 @@ notify_notify(struct terminal *term, struct notification *notif) ? "normal" : "critical"; LOG_DBG("notify: title=\"%s\", body=\"%s\", app-id=\"%s\", category=\"%s\", " - "urgency=\"%s\", icon=\"%s\", expires=%d, replaces=%u (tracking: %s)", + "urgency=\"%s\", icon=\"%s\", expires=%d, replaces=%u, muted=%s " + "(tracking: %s)", title, body, app_id, notif->category, urgency_str, icon_name_or_path, - notif->expire_time, replaces_id, track_notification ? "yes" : "no"); + notif->expire_time, replaces_id, + notif->muted ? "yes" : "no", + track_notification ? "yes" : "no"); xassert(title != NULL); if (title == NULL) @@ -463,14 +466,14 @@ notify_notify(struct terminal *term, struct notification *notif) } if (!spawn_expand_template( - &term->conf->desktop_notifications.command, 10, + &term->conf->desktop_notifications.command, 11, (const char *[]){ "app-id", "window-title", "icon", "title", "body", "category", - "urgency", "expire-time", "replace-id", "action-argument"}, + "urgency", "muted", "expire-time", "replace-id", "action-argument"}, (const char *[]){ app_id, term->window_title, icon_name_or_path, title, body, notif->category != NULL ? notif->category : "", urgency_str, - expire_time, replaces_id_str, + notif->muted ? "true" : "false", expire_time, replaces_id_str, /* Custom expansion below, since we need to expand to multiple arguments */ "${action-argument}"}, diff --git a/notify.h b/notify.h index 592d2c84..ccdfdea8 100644 --- a/notify.h +++ b/notify.h @@ -52,6 +52,8 @@ struct notification { bool report_activated; /* OSC-99: report notification activation to client */ bool report_closed; /* OSC-99: report notification closed to client */ + bool muted; /* Explicitly mute the notification */ + /* * Used internally by notify */ diff --git a/osc.c b/osc.c index 28d8b7b8..50415570 100644 --- a/osc.c +++ b/osc.c @@ -609,6 +609,7 @@ kitty_notification(struct terminal *term, char *string) char *icon_cache_id = NULL; /* The 'g' parameter */ char *symbolic_icon = NULL; /* The 'n' parameter */ char *category = NULL; /* The 't' parameter */ + char *sound_name = NULL; /* The 's' parameter */ char *payload = NULL; bool focus = true; /* The 'a' parameter */ @@ -739,7 +740,7 @@ kitty_notification(struct terminal *term, char *string) char reply[128]; int n = xsnprintf( reply, sizeof(reply), - "\033]99;i=%s:p=?;p=%s:a=%s:o=%s:u=%s:c=1:w=1%s", + "\033]99;i=%s:p=?;p=%s:a=%s:o=%s:u=%s:c=1:w=1:s=silent%s", reply_id, p_caps, a_caps, when_caps, u_caps, terminator); xassert(n < sizeof(reply)); @@ -783,10 +784,15 @@ kitty_notification(struct terminal *term, char *string) break; } - case 'f': - free(app_id); - app_id = base64_decode(value, NULL); + case 'f': { + /* App-name */ + char *decoded = base64_decode(value, NULL); + if (decoded != NULL) { + free(app_id); + app_id = decoded; + } break; + } case 't': { /* Type (category) */ @@ -805,6 +811,16 @@ kitty_notification(struct terminal *term, char *string) break; } + case 's': { + /* Sound */ + char *decoded = base64_decode(value, NULL); + if (decoded != NULL) { + free(sound_name); + sound_name = decoded; + } + break; + } + case 'g': /* graphical ID (see 'n' and 'p=icon') */ free(icon_cache_id); @@ -946,6 +962,10 @@ kitty_notification(struct terminal *term, char *string) } } + if (sound_name != NULL) { + notif->muted = streq(sound_name, "silent"); + } + /* Handled chunked payload - append to existing metadata */ switch (payload_type) { case PAYLOAD_TITLE: @@ -1067,6 +1087,7 @@ out: free(symbolic_icon); free(payload); free(category); + free(sound_name); } void -- cgit v1.3 From 84d36606cbd3e35aae6a68e69101b22da60dbe99 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 4 Aug 2024 15:21:06 +0200 Subject: osc: kitty notifications: add support for XDG sound names --- config.c | 2 +- doc/foot.ini.5.scd | 7 +++++++ foot.ini | 2 +- notify.c | 17 +++++++++++------ notify.h | 1 + osc.c | 11 ++++++++++- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index 5dbbacb7..1ec73da0 100644 --- a/config.c +++ b/config.c @@ -3242,7 +3242,7 @@ config_load(struct config *conf, const char *conf_path, parse_modifiers(XKB_MOD_NAME_SHIFT, 5, &conf->mouse.selection_override_modifiers); tokenize_cmdline( - "notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --hint BOOLEAN:suppress-sound:${muted} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body}", + "notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --hint BOOLEAN:suppress-sound:${muted} --hint STRING:sound-name:${sound-name} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body}", &conf->desktop_notifications.command.argv.args); tokenize_cmdline("--action ${action-name}=${action-label}", &conf->desktop_notifications.command_action_arg.argv.args); tokenize_cmdline("xdg-open ${url}", &conf->url.launch.argv.args); diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 6db7ffae..71992c8f 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -464,6 +464,12 @@ Note: do not set *TERM* here; use the *term* option in the main sounds be muted. It is intended to set the *suppress-sound* hint (with e.g. notify-send's *--hint* option). + _${sound-name}_ is replaced by sound-name requested by the + notification. This should be a name from the freedesktop sound + naming specification, but this is not something that foot + enforces. It is intended to set the *sound-name* hint (with + e.g. notify-send's *--hint* option). + _${action-argument}_ will be expanded to the *command-action-argument* option, for each notification action. There will always be at least one action, the @@ -574,6 +580,7 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 --expire-time ${expire-time}++ --hint STRING:image-path:${icon}++ --hint BOOLEAN:suppress-sound:${muted}++ + --hint STRING:sound-name:${sound-name}++ --replace-id ${replace-id}++ ${action-argument}++ --print-id++ diff --git a/foot.ini b/foot.ini index fba9305e..9e2f5f29 100644 --- a/foot.ini +++ b/foot.ini @@ -47,7 +47,7 @@ # command-focused=no [desktop-notifications] -# command=notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --hint BOOLEAN:suppress-sound:${muted} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body} +# command=notify-send --wait --app-name ${app-id} --icon ${app-id} --category ${category} --urgency ${urgency} --expire-time ${expire-time} --hint STRING:image-path:${icon} --hint BOOLEAN:suppress-sound:${muted} --hint STRING:sound-name:${sound-name} --replace-id ${replace-id} ${action-argument} --print-id -- ${title} ${body} # command-action-argument=--action ${action-name}=${action-label} # close="" # inhibit-when-focused=yes diff --git a/notify.c b/notify.c index 0b37f40a..d1c06fb1 100644 --- a/notify.c +++ b/notify.c @@ -34,6 +34,7 @@ notify_free(struct terminal *term, struct notification *notif) free(notif->icon_cache_id); free(notif->icon_symbolic_name); free(notif->icon_data); + free(notif->sound_name); free(notif->xdg_token); free(notif->stdout_data); @@ -421,11 +422,11 @@ notify_notify(struct terminal *term, struct notification *notif) ? "normal" : "critical"; LOG_DBG("notify: title=\"%s\", body=\"%s\", app-id=\"%s\", category=\"%s\", " - "urgency=\"%s\", icon=\"%s\", expires=%d, replaces=%u, muted=%s " - "(tracking: %s)", + "urgency=\"%s\", icon=\"%s\", expires=%d, replaces=%u, muted=%s, " + "sound-name=%s (tracking: %s)", title, body, app_id, notif->category, urgency_str, icon_name_or_path, notif->expire_time, replaces_id, - notif->muted ? "yes" : "no", + notif->muted ? "yes" : "no", notif->sound_name, track_notification ? "yes" : "no"); xassert(title != NULL); @@ -466,14 +467,17 @@ notify_notify(struct terminal *term, struct notification *notif) } if (!spawn_expand_template( - &term->conf->desktop_notifications.command, 11, + &term->conf->desktop_notifications.command, 12, (const char *[]){ "app-id", "window-title", "icon", "title", "body", "category", - "urgency", "muted", "expire-time", "replace-id", "action-argument"}, + "urgency", "muted", "sound-name", "expire-time", "replace-id", + "action-argument"}, (const char *[]){ app_id, term->window_title, icon_name_or_path, title, body, notif->category != NULL ? notif->category : "", urgency_str, - notif->muted ? "true" : "false", expire_time, replaces_id_str, + notif->muted ? "true" : "false", + notif->sound_name != NULL ? notif->sound_name : "", + expire_time, replaces_id_str, /* Custom expansion below, since we need to expand to multiple arguments */ "${action-argument}"}, @@ -545,6 +549,7 @@ notify_notify(struct terminal *term, struct notification *notif) notif->icon_data = NULL; notif->icon_data_sz = 0; notif->icon_path = NULL; + notif->sound_name = NULL; notif->icon_fd = -1; notif->stdout_fd = -1; struct notification *new_notif = &tll_back(term->active_notifications); diff --git a/notify.h b/notify.h index ccdfdea8..89b51238 100644 --- a/notify.h +++ b/notify.h @@ -53,6 +53,7 @@ struct notification { bool report_closed; /* OSC-99: report notification closed to client */ bool muted; /* Explicitly mute the notification */ + char *sound_name; /* Should be set to NULL if muted == true */ /* * Used internally by notify diff --git a/osc.c b/osc.c index 50415570..eba1850f 100644 --- a/osc.c +++ b/osc.c @@ -740,7 +740,7 @@ kitty_notification(struct terminal *term, char *string) char reply[128]; int n = xsnprintf( reply, sizeof(reply), - "\033]99;i=%s:p=?;p=%s:a=%s:o=%s:u=%s:c=1:w=1:s=silent%s", + "\033]99;i=%s:p=?;p=%s:a=%s:o=%s:u=%s:c=1:w=1:s=silent,xdg-names%s", reply_id, p_caps, a_caps, when_caps, u_caps, terminator); xassert(n < sizeof(reply)); @@ -964,6 +964,15 @@ kitty_notification(struct terminal *term, char *string) if (sound_name != NULL) { notif->muted = streq(sound_name, "silent"); + + if (notif->muted || streq(sound_name, "system")) { + free(notif->sound_name); + notif->sound_name = NULL; + } else { + free(notif->sound_name); + notif->sound_name = sound_name; + sound_name = NULL; /* Prevent double free */ + } } /* Handled chunked payload - append to existing metadata */ -- cgit v1.3 From fb74a2df2766f9f43f6ed6b5020aab25925c671b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 4 Aug 2024 15:23:33 +0200 Subject: changelog: osc-99: sound support --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef655a22..258940d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,14 @@ ## Unreleased ### Added + +* OSC-99: support for the `s` parameter. Supported keywords are + `silent`, `system` and names from the freedesktop sound naming + specification. +* `${muted}` and `${sound-name}` added to the + `desktop-notifications.command` template. + + ### Changed ### Deprecated ### Removed -- cgit v1.3 From a0b5f79f3297b4774723e63e954aaf859d0058d0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 7 Aug 2024 17:13:38 +0200 Subject: readme: repology: use three columns instead of one --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c3fbd1b..32dfe11f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The fast, lightweight and minimalistic Wayland terminal emulator. [![Pipeline status](https://gitlab.com/dnkl/foot/badges/master/pipeline.svg)](https://gitlab.com/dnkl/foot/commits/master) [![builds.sr.ht status](https://builds.sr.ht/~dnkl/foot.svg)](https://builds.sr.ht/~dnkl/foot?) -[![Packaging status](https://repology.org/badge/vertical-allrepos/foot.svg)](https://repology.org/project/foot/versions) +[![Packaging status](https://repology.org/badge/vertical-allrepos/foot.svg?columns=3)](https://repology.org/project/foot/versions) ## Index -- cgit v1.3 From 8607fb6312f1e201b57518da8b67ca99f414f27b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 7 Aug 2024 17:14:26 +0200 Subject: readme: repology: use four columns instead of three --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32dfe11f..57e401a2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The fast, lightweight and minimalistic Wayland terminal emulator. [![Pipeline status](https://gitlab.com/dnkl/foot/badges/master/pipeline.svg)](https://gitlab.com/dnkl/foot/commits/master) [![builds.sr.ht status](https://builds.sr.ht/~dnkl/foot.svg)](https://builds.sr.ht/~dnkl/foot?) -[![Packaging status](https://repology.org/badge/vertical-allrepos/foot.svg?columns=3)](https://repology.org/project/foot/versions) +[![Packaging status](https://repology.org/badge/vertical-allrepos/foot.svg?columns=4)](https://repology.org/project/foot/versions) ## Index -- cgit v1.3 From 01eca82d33b47dffd46ae5a4a2f5085a374636e0 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 7 Aug 2024 17:15:00 +0200 Subject: readme: remove CI badges for gitlab and sr.ht --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 57e401a2..dc5421cc 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ The fast, lightweight and minimalistic Wayland terminal emulator. [![CI status](https://ci.codeberg.org/api/badges/dnkl/foot/status.svg)](https://ci.codeberg.org/dnkl/foot) -[![Pipeline status](https://gitlab.com/dnkl/foot/badges/master/pipeline.svg)](https://gitlab.com/dnkl/foot/commits/master) -[![builds.sr.ht status](https://builds.sr.ht/~dnkl/foot.svg)](https://builds.sr.ht/~dnkl/foot?) [![Packaging status](https://repology.org/badge/vertical-allrepos/foot.svg?columns=4)](https://repology.org/project/foot/versions) -- cgit v1.3 From 9d5d84a8350ec73f432d0522c274764ee37a9a50 Mon Sep 17 00:00:00 2001 From: Shogo Yamazaki Date: Wed, 7 Aug 2024 14:12:13 +0900 Subject: meson: fix false positive detection of `memfd_create` Add the arguments to `has_function` to properly detect availability of the function on SDK environments. --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index a99d1a48..7ce9d901 100644 --- a/meson.build +++ b/meson.build @@ -12,7 +12,8 @@ is_debug_build = get_option('buildtype').startswith('debug') cc = meson.get_compiler('c') -if cc.has_function('memfd_create') +if cc.has_function('memfd_create', + args: ['-D_GNU_SOURCE'], prefix: '#include ') add_project_arguments('-DMEMFD_CREATE', language: 'c') endif -- cgit v1.3 From 803f712332e7bcafbb3b41b69ed5787b6b032bbf Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 9 Aug 2024 08:15:13 +0200 Subject: meson: add "prefix: '#include " to cc.has_function() When checking for execvpe, include --- meson.build | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 7ce9d901..2bec645e 100644 --- a/meson.build +++ b/meson.build @@ -13,12 +13,15 @@ is_debug_build = get_option('buildtype').startswith('debug') cc = meson.get_compiler('c') if cc.has_function('memfd_create', - args: ['-D_GNU_SOURCE'], prefix: '#include ') + args: ['-D_GNU_SOURCE'], + prefix: '#include ') add_project_arguments('-DMEMFD_CREATE', language: 'c') endif # Missing on DragonFly, FreeBSD < 14.1 -if cc.has_function('execvpe') +if cc.has_function('execvpe', + args: ['-D_GNU_SOURCE'], + prefix: '#include ') add_project_arguments('-DEXECVPE', language: 'c') endif -- cgit v1.3 From 7ec9ca2b9528126bf11dda37cfea9687b6bc66a3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 2 Aug 2024 17:12:12 +0200 Subject: input: CSD buttons are now triggered when releasing the mouse button This is how most UIs work. Note that we (at least on River) don't get any surface enter/leave events while a button is held. This means we can't detect if the user pressed the mouse button while on a CSD button, but then moves the mouse outside. Releasing the mouse button will still activate the CSD button. Closes #1787 --- CHANGELOG.md | 5 +++++ input.c | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 258940d4..6d7d6614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,11 @@ ### Changed + +* CSD buttons now activate on mouse button **release**, rather than + press ([#1787][1787]). + + ### Deprecated ### Removed ### Fixed diff --git a/input.c b/input.c index 98f5c89c..4aa410c4 100644 --- a/input.c +++ b/input.c @@ -2577,12 +2577,19 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } case TERM_SURF_BUTTON_MINIMIZE: - if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + if (button == BTN_LEFT && + term->active_surface == TERM_SURF_BUTTON_MINIMIZE && + state == WL_POINTER_BUTTON_STATE_RELEASED) + { xdg_toplevel_set_minimized(term->window->xdg_toplevel); + } break; case TERM_SURF_BUTTON_MAXIMIZE: - if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) { + if (button == BTN_LEFT && + term->active_surface == TERM_SURF_BUTTON_MAXIMIZE && + state == WL_POINTER_BUTTON_STATE_RELEASED) + { if (term->window->is_maximized) xdg_toplevel_unset_maximized(term->window->xdg_toplevel); else @@ -2591,8 +2598,12 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, break; case TERM_SURF_BUTTON_CLOSE: - if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) + if (button == BTN_LEFT && + term->active_surface == TERM_SURF_BUTTON_CLOSE && + state == WL_POINTER_BUTTON_STATE_RELEASED) + { term_shutdown(term); + } break; case TERM_SURF_GRID: { -- cgit v1.3 From bef613e656a36400577cde295b09267c80f3adce Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 9 Aug 2024 08:20:59 +0200 Subject: csd: track pointer when rendering and handling CSD button clicks * Render button as highlighted only when pointer is above them * Releasing the mouse button while *not* on the button does *not* activate the button When pressing, and holding, a mouse button, the compositor keeps sending motion events for the surface where the button was pressed, even if the mouse has moved outside it. We also don't get any surface leave/enter events. This meant that the button was rendered as highlighted, and a click registered, if the user pressed the mouse button while on the button, and then moved the cursor away from the button before releasing the button. This patch fixes it, by checking if the current cursor coordinates fall within the button surface. --- input.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- render.c | 35 +++++++++++++++++++++++++++--- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/input.c b/input.c index 4aa410c4..201f5c69 100644 --- a/input.c +++ b/input.c @@ -2053,6 +2053,25 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, } } +static bool +pointer_is_on_button(const struct terminal *term, const struct seat *seat, + enum csd_surface csd_surface) +{ + if (seat->mouse.x < 0) + return false; + if (seat->mouse.y < 0) + return false; + + struct csd_data info = get_csd_data(term, csd_surface); + if (seat->mouse.x > info.width) + return false; + + if (seat->mouse.y > info.height) + return false; + + return true; +} + static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) @@ -2085,16 +2104,42 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, int x = wl_fixed_to_int(surface_x) * term->scale; int y = wl_fixed_to_int(surface_y) * term->scale; + enum term_surface surf_kind = term->active_surface; + int button = 0; + bool send_to_client = false; + bool is_on_button = false; + + /* If current surface is a button, check if pointer was on it + *before* the motion event */ + switch (surf_kind) { + case TERM_SURF_BUTTON_MINIMIZE: + is_on_button = pointer_is_on_button(term, seat, CSD_SURF_MINIMIZE); + break; + + case TERM_SURF_BUTTON_MAXIMIZE: + is_on_button = pointer_is_on_button(term, seat, CSD_SURF_MAXIMIZE); + break; + + case TERM_SURF_BUTTON_CLOSE: + is_on_button = pointer_is_on_button(term, seat, CSD_SURF_CLOSE); + break; + + case TERM_SURF_NONE: + case TERM_SURF_GRID: + case TERM_SURF_TITLE: + case TERM_SURF_BORDER_LEFT: + case TERM_SURF_BORDER_RIGHT: + case TERM_SURF_BORDER_TOP: + case TERM_SURF_BORDER_BOTTOM: + break; + } + seat->pointer.hidden = false; seat->mouse.x = x; seat->mouse.y = y; term_xcursor_update_for_seat(term, seat); - enum term_surface surf_kind = term->active_surface; - int button = 0; - bool send_to_client = false; - if (tll_length(seat->mouse.buttons) > 0) { const struct button_tracker *tracker = &tll_front(seat->mouse.buttons); surf_kind = tracker->surf_kind; @@ -2104,9 +2149,21 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, switch (surf_kind) { case TERM_SURF_NONE: + break; + case TERM_SURF_BUTTON_MINIMIZE: + if (pointer_is_on_button(term, seat, CSD_SURF_MINIMIZE) != is_on_button) + render_refresh_csd(term); + break; + case TERM_SURF_BUTTON_MAXIMIZE: + if (pointer_is_on_button(term, seat, CSD_SURF_MAXIMIZE) != is_on_button) + render_refresh_csd(term); + break; + case TERM_SURF_BUTTON_CLOSE: + if (pointer_is_on_button(term, seat, CSD_SURF_CLOSE) != is_on_button) + render_refresh_csd(term); break; case TERM_SURF_TITLE: @@ -2246,8 +2303,8 @@ fdm_csd_move(struct fdm *fdm, int fd, int events, void *data) } static const struct key_binding * - match_mouse_binding(const struct seat *seat, const struct terminal *term, - int button) +match_mouse_binding(const struct seat *seat, const struct terminal *term, + int button) { if (seat->wl_keyboard != NULL && seat->kbd.xkb_state != NULL) { /* Seat has keyboard - use mouse bindings *with* modifiers */ @@ -2578,7 +2635,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BUTTON_MINIMIZE: if (button == BTN_LEFT && - term->active_surface == TERM_SURF_BUTTON_MINIMIZE && + pointer_is_on_button(term, seat, CSD_SURF_MINIMIZE) && state == WL_POINTER_BUTTON_STATE_RELEASED) { xdg_toplevel_set_minimized(term->window->xdg_toplevel); @@ -2587,7 +2644,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BUTTON_MAXIMIZE: if (button == BTN_LEFT && - term->active_surface == TERM_SURF_BUTTON_MAXIMIZE && + pointer_is_on_button(term, seat, CSD_SURF_MAXIMIZE) && state == WL_POINTER_BUTTON_STATE_RELEASED) { if (term->window->is_maximized) @@ -2599,7 +2656,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case TERM_SURF_BUTTON_CLOSE: if (button == BTN_LEFT && - term->active_surface == TERM_SURF_BUTTON_CLOSE && + pointer_is_on_button(term, seat, CSD_SURF_CLOSE) && state == WL_POINTER_BUTTON_STATE_RELEASED) { term_shutdown(term); diff --git a/render.c b/render.c index 279e51bf..d9630983 100644 --- a/render.c +++ b/render.c @@ -2627,6 +2627,32 @@ render_csd_button_close(struct terminal *term, struct buffer *buf) pixman_image_unref(src); } +static bool +any_pointer_is_on_button(const struct terminal *term, enum csd_surface csd_surface) +{ + if (unlikely(tll_length(term->wl->seats) == 0)) + return false; + + tll_foreach(term->wl->seats, it) { + const struct seat *seat = &it->item; + + if (seat->mouse.x < 0) + continue; + if (seat->mouse.y < 0) + continue; + + struct csd_data info = get_csd_data(term, csd_surface); + if (seat->mouse.x > info.width) + continue; + + if (seat->mouse.y > info.height) + continue; + return true; + } + + return false; +} + static void render_csd_button(struct terminal *term, enum csd_surface surf_idx, const struct csd_data *info, struct buffer *buf) @@ -2650,21 +2676,24 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx, _color = term->conf->colors.table[4]; /* blue */ is_set = term->conf->csd.color.minimize_set; conf_color = &term->conf->csd.color.minimize; - is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE; + is_active = term->active_surface == TERM_SURF_BUTTON_MINIMIZE && + any_pointer_is_on_button(term, CSD_SURF_MINIMIZE); break; case CSD_SURF_MAXIMIZE: _color = term->conf->colors.table[2]; /* green */ is_set = term->conf->csd.color.maximize_set; conf_color = &term->conf->csd.color.maximize; - is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE; + is_active = term->active_surface == TERM_SURF_BUTTON_MAXIMIZE && + any_pointer_is_on_button(term, CSD_SURF_MAXIMIZE); break; case CSD_SURF_CLOSE: _color = term->conf->colors.table[1]; /* red */ is_set = term->conf->csd.color.close_set; conf_color = &term->conf->csd.color.quit; - is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE; + is_active = term->active_surface == TERM_SURF_BUTTON_CLOSE && + any_pointer_is_on_button(term, CSD_SURF_CLOSE); break; default: -- cgit v1.3 From 481ce82d661e1f3f4a05813bb209f2184b1f61c9 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 9 Aug 2024 08:24:53 +0200 Subject: doc: foot.ini: document the Unicode ranges covered by the builtin glyphs --- doc/foot.ini.5.scd | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 71992c8f..da887aee 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -179,9 +179,10 @@ empty string to be set, but it must be quoted: *KEY=""*) Default: _unset_ -*box-drawings-uses-font-glyphs* Boolean. When disabled, foot generates - box/line drawing characters itself. The are several advantages to - doing this instead of using font glyphs: +*box-drawings-uses-font-glyphs* + Boolean. When disabled, foot generates box/line drawing characters + itself. The are several advantages to doing this instead of using + font glyphs: - No antialiasing effects where e.g. line endpoints appear dimmed down, or blurred. @@ -195,6 +196,13 @@ empty string to be set, but it must be quoted: *KEY=""*) When enabled, box/line drawing characters are rendered using font glyphs. This may result in a more uniform look, in some use cases. + When disabled, foot will render the following Unicode codepoints + by itself: + + - U+02500 - U+0259F + - U+02800 - U+028FF + - U+1Fb00 - U+1FB9B + Default: _no_. *dpi-aware* -- cgit v1.3 From ee9c76ded00de9beac698d2bd4771e8c1d966c6a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 9 Aug 2024 08:25:36 +0200 Subject: osc: kitty: update 's' to the latest spec * The spec now defines a couple of "standard" names. Translate these to the freedesktop compliant names. * The query response no longer contains 'xdg-names', but instead list the supported standard names. --- osc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/osc.c b/osc.c index eba1850f..53597d0f 100644 --- a/osc.c +++ b/osc.c @@ -740,7 +740,7 @@ kitty_notification(struct terminal *term, char *string) char reply[128]; int n = xsnprintf( reply, sizeof(reply), - "\033]99;i=%s:p=?;p=%s:a=%s:o=%s:u=%s:c=1:w=1:s=silent,xdg-names%s", + "\033]99;i=%s:p=?;p=%s:a=%s:o=%s:u=%s:c=1:w=1:s=system,silent,error,warn,warning,info,question%s", reply_id, p_caps, a_caps, when_caps, u_caps, terminator); xassert(n < sizeof(reply)); @@ -817,6 +817,22 @@ kitty_notification(struct terminal *term, char *string) if (decoded != NULL) { free(sound_name); sound_name = decoded; + + const char *translated_name = NULL; + + if (streq(decoded, "error")) + translated_name = "dialog-error"; + else if (streq(decoded, "warn") || streq(decoded, "warning")) + translated_name = "dialog-warning"; + else if (streq(decoded, "info")) + translated_name = "dialog-information"; + else if (streq(decoded, "question")) + translated_name = "dialog-question"; + + if (translated_name != NULL) { + free(sound_name); + sound_name = xstrdup(translated_name); + } } break; } -- cgit v1.3 From 7e1894978fda263f823abbb1e66ea251e96bfd83 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 9 Aug 2024 13:55:21 +0200 Subject: slave: prefix user notifications with 'foot' To make it clearer _who_ is emitting the warning/errors --- slave.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slave.c b/slave.c index bf1ca8e0..47e59e87 100644 --- a/slave.c +++ b/slave.c @@ -158,6 +158,7 @@ emit_one_notification(int fd, const struct user_notification *notif) xassert(prefix != NULL); if (write(fd, prefix, strlen(prefix)) < 0 || + write(fd, "foot: ", 6) < 0 || write(fd, notif->text, strlen(notif->text)) < 0 || write(fd, postfix, strlen(postfix)) < 0) { @@ -180,7 +181,8 @@ emit_one_notification(int fd, const struct user_notification *notif) } static bool -emit_notifications_of_kind(int fd, const user_notifications_t *notifications, +emit_notifications_of_kind(int fd, + const user_notifications_t *notifications, enum user_notification_kind kind) { tll_foreach(*notifications, it) { -- cgit v1.3 From 6d351ffc43175b59359258eca83e652d76cfc426 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 10 Aug 2024 16:38:35 +0200 Subject: main: invalid locale != non-UTF-8 locale When doing locale fallback, and printing user notifications and log warnings, better separate the case "locale is invalid" from "locale is valid but not UTF-8". Closes #1798 --- main.c | 57 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index f46d712e..b2266d88 100644 --- a/main.c +++ b/main.c @@ -425,19 +425,18 @@ main(int argc, char *const *argv) * that does not exist on this system, then the above call may return * NULL. We should just continue with the fallback method below. */ - LOG_WARN("setlocale() failed"); - locale = "C"; + LOG_ERR("setlocale() failed"); } - LOG_INFO("locale: %s", locale); + LOG_INFO("locale: %s", locale != NULL ? locale : ""); - bool bad_locale = !locale_is_utf8(); + bool bad_locale = locale == NULL || !locale_is_utf8(); if (bad_locale) { static const char fallback_locales[][12] = { "C.UTF-8", "en_US.UTF-8", }; - char *saved_locale = xstrdup(locale); + char *saved_locale = locale != NULL ? xstrdup(locale) : NULL; /* * Try to force an UTF-8 locale. If we succeed, launch the @@ -448,13 +447,23 @@ main(int argc, char *const *argv) const char *const fallback_locale = fallback_locales[i]; if (setlocale(LC_CTYPE, fallback_locale) != NULL) { - LOG_WARN("'%s' is not a UTF-8 locale, using '%s' instead", - saved_locale, fallback_locale); - - user_notification_add_fmt( - &user_notifications, USER_NOTIFICATION_WARNING, - "'%s' is not a UTF-8 locale, using '%s' instead", - saved_locale, fallback_locale); + if (saved_locale != NULL) { + LOG_WARN( + "'%s' is not a UTF-8 locale, falling back to '%s'", + saved_locale, fallback_locale); + + user_notification_add_fmt( + &user_notifications, USER_NOTIFICATION_WARNING, + "'%s' is not a UTF-8 locale, falling back to '%s'", + saved_locale, fallback_locale); + + } else { + LOG_WARN( + "invalid locale, falling back to '%s'", fallback_locale); + user_notification_add_fmt( + &user_notifications, USER_NOTIFICATION_WARNING, + "invalid locale, falling back to '%s'", fallback_locale); + } bad_locale = false; break; @@ -462,14 +471,22 @@ main(int argc, char *const *argv) } if (bad_locale) { - LOG_ERR( - "'%s' is not a UTF-8 locale, and failed to find a fallback", - saved_locale); - - user_notification_add_fmt( - &user_notifications, USER_NOTIFICATION_ERROR, - "'%s' is not a UTF-8 locale, and failed to find a fallback", - saved_locale); + if (saved_locale != NULL) { + LOG_ERR( + "'%s' is not a UTF-8 locale, and failed to find a fallback", + saved_locale); + + user_notification_add_fmt( + &user_notifications, USER_NOTIFICATION_ERROR, + "'%s' is not a UTF-8 locale, and failed to find a fallback", + saved_locale); + } else { + LOG_ERR("invalid locale, and failed to find a fallback"); + + user_notification_add_fmt( + &user_notifications, USER_NOTIFICATION_ERROR, + "invalid locale, and failed to find a fallback"); + } } free(saved_locale); } -- cgit v1.3 From cee0c5423ae1b306fc85960058adfd9574e4c91b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 11 Aug 2024 11:11:38 +0200 Subject: main: spell out the most common reason for setlocale() to fail --- main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index b2266d88..15741012 100644 --- a/main.c +++ b/main.c @@ -425,7 +425,8 @@ main(int argc, char *const *argv) * that does not exist on this system, then the above call may return * NULL. We should just continue with the fallback method below. */ - LOG_ERR("setlocale() failed"); + LOG_ERR("setlocale() failed. The most common cause is that the " + "configured locale is not available, or has been misspelled"); } LOG_INFO("locale: %s", locale != NULL ? locale : ""); -- cgit v1.3 From eb185bfa47bad124149d8f921825231141d10b20 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 14 Aug 2024 08:53:21 +0200 Subject: utils/xtgettcap: fix possible NULL deref, found by -fanalyzer --- utils/xtgettcap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/xtgettcap.c b/utils/xtgettcap.c index 069a9ecb..82ee0085 100644 --- a/utils/xtgettcap.c +++ b/utils/xtgettcap.c @@ -141,6 +141,9 @@ main(int argc, const char *const *argv) const char *key = strtok(key_value, "="); const char *value = strtok(NULL, "="); + if (key == NULL) + continue; + #if 0 assert((success && value != NULL) || (!success && value == NULL)); -- cgit v1.3 From 2896c1898127256193d49c80a56ba7188fad0e33 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 14 Aug 2024 08:50:44 +0200 Subject: osc: regression: fix OSC-111 handling of alpha changes When the background alpha changes from fully opaque, to transparent, or vice versa, we need to do more than just repaint the affected cells. For example, we need to create new surfaces with the correct pixel format. OSC-11 (set background color) already does this, but the same alpha checking logic was missing in OSC-111 (reset background color). Fixes #1801 --- CHANGELOG.md | 7 +++++++ osc.c | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d7d6614..fe82d2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,13 @@ ### Deprecated ### Removed ### Fixed + +* Regression: OSC-111 not handling alpha changes correctly, causing + visual glitches ([#1801][1801]). + +[1801]: https://codeberg.org/dnkl/foot/issues/1801 + + ### Security ### Contributors diff --git a/osc.c b/osc.c index 53597d0f..3c5f7616 100644 --- a/osc.c +++ b/osc.c @@ -1381,13 +1381,22 @@ osc_dispatch(struct terminal *term) term_damage_color(term, COLOR_DEFAULT, 0); break; - case 111: /* Reset default text background color */ + case 111: { /* Reset default text background color */ LOG_DBG("resetting background color"); + bool alpha_changed = term->colors.alpha != term->conf->colors.alpha; + term->colors.bg = term->conf->colors.bg; term->colors.alpha = term->conf->colors.alpha; + + if (alpha_changed) { + wayl_win_alpha_changed(term->window); + term_font_subpixel_changed(term); + } + term_damage_color(term, COLOR_DEFAULT, 0); term_damage_margins(term); break; + } case 112: LOG_DBG("resetting cursor color"); -- cgit v1.3