toplevel-icon: implement OSC-1, CSI 20/21/22/23 t

* The toplevel icon is now set to the app-id, unless "overridden" by
  OSC-1 or OSC-0.
* Implemented OSC-1
* OSC-0 extended to also set the icon
* Implemented CSI 20 t - report window icon
* Implemented CSI 21 t - report window title
* Implemented CSI 22 ; 1 t - push window icon
* Implemented CS 23 ; 1 t - pop window icon
* Extended CSI 22/23 ; 0 t to also push/pop the icon
* Verify app-id set by OSC-176 is valid UTF-8
* Verify icon set by OSC-0/1 is valid UTF-8
This commit is contained in:
Daniel Eklöf 2024-09-10 18:53:38 +02:00
parent 3f8a1fc85b
commit 97ec375c67
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
10 changed files with 220 additions and 32 deletions

View file

@ -12,15 +12,19 @@
#include "macros.h"
#if HAS_INCLUDE(<pthread_np.h>)
#include <pthread_np.h>
#define pthread_setname_np(thread, name) (pthread_set_name_np(thread, name), 0)
#include <pthread_np.h>
#define pthread_setname_np(thread, name) (pthread_set_name_np(thread, name), 0)
#elif defined(__NetBSD__)
#define pthread_setname_np(thread, name) pthread_setname_np(thread, "%s", (void *)name)
#define pthread_setname_np(thread, name) pthread_setname_np(thread, "%s", (void *)name)
#endif
#include <presentation-time.h>
#include <wayland-cursor.h>
#include <xdg-shell.h>
#include <presentation-time.h>
#if defined(HAVE_XDG_TOPLEVEL_ICON)
#include <xdg-toplevel-icon-v1.h>
#endif
#include <fcft/fcft.h>
@ -4951,26 +4955,49 @@ render_refresh_app_id(struct terminal *term)
term->app_id != NULL ? term->app_id : term->conf->app_id;
xdg_toplevel_set_app_id(term->window->xdg_toplevel, app_id);
#if defined(HAVE_XDG_TOPLEVEL_ICON)
if (term->wl->toplevel_icon_manager != NULL) {
struct xdg_toplevel_icon_v1 *icon =
xdg_toplevel_icon_manager_v1_create_icon(
term->wl->toplevel_icon_manager);
xdg_toplevel_icon_v1_set_name(
icon, streq(app_id, "footclient") ? "foot" : app_id);
xdg_toplevel_icon_manager_v1_set_icon(
term->wl->toplevel_icon_manager, term->window->xdg_toplevel, icon);
xdg_toplevel_icon_v1_destroy(icon);
}
#endif
term->render.app_id.last_update = now;
}
void
render_refresh_icon(struct terminal *term)
{
#if defined(HAVE_XDG_TOPLEVEL_ICON)
if (term->wl->toplevel_icon_manager == NULL) {
LOG_DBG("compositor does not implement xdg-toplevel-icon: "
"ignoring request to refresh window icon");
return;
}
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now) < 0)
return;
struct timespec diff;
timespec_sub(&now, &term->render.icon.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.icon.timer_fd, 0, &timeout, NULL);
return;
}
const char *icon_name = term_icon(term);
LOG_DBG("setting toplevel icon: %s", icon_name);
struct xdg_toplevel_icon_v1 *icon =
xdg_toplevel_icon_manager_v1_create_icon(term->wl->toplevel_icon_manager);
xdg_toplevel_icon_v1_set_name(icon, icon_name);
xdg_toplevel_icon_manager_v1_set_icon(
term->wl->toplevel_icon_manager, term->window->xdg_toplevel, icon);
xdg_toplevel_icon_v1_destroy(icon);
term->render.icon.last_update = now;
#endif
}
void
render_refresh(struct terminal *term)
{