foot/quirks.c

95 lines
1.9 KiB
C
Raw Normal View History

#include "quirks.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#define LOG_MODULE "quirks"
#define LOG_ENABLE_DBG 0
#include "log.h"
#include "util.h"
static bool
is_weston(void)
{
static bool is_weston = false;
static bool initialized = false;
if (!initialized) {
initialized = true;
is_weston = getenv("WESTON_CONFIG_FILE") != NULL;
if (is_weston)
LOG_WARN("applying wl_subsurface_set_desync() workaround for weston");
}
return is_weston;
}
void
quirk_weston_subsurface_desync_on(struct wl_subsurface *sub)
{
if (!is_weston())
return;
wl_subsurface_set_desync(sub);
}
void
quirk_weston_subsurface_desync_off(struct wl_subsurface *sub)
{
if (!is_weston())
return;
wl_subsurface_set_sync(sub);
}
void
quirk_weston_csd_on(struct terminal *term)
{
if (term->window->csd_mode != CSD_YES)
return;
if (term->window->is_fullscreen)
return;
for (int i = 0; i < ALEN(term->window->csd.surface); i++)
quirk_weston_subsurface_desync_on(term->window->csd.surface[i].sub);
}
void
quirk_weston_csd_off(struct terminal *term)
{
if (term->window->csd_mode != CSD_YES)
return;
if (term->window->is_fullscreen)
return;
for (int i = 0; i < ALEN(term->window->csd.surface); i++)
quirk_weston_subsurface_desync_off(term->window->csd.surface[i].sub);
}
static bool
is_sway(void)
{
static bool is_sway = false;
static bool initialized = false;
if (!initialized) {
initialized = true;
is_sway = getenv("SWAYSOCK") != NULL;
if (is_sway)
LOG_WARN("applying wl_surface_damage_buffer() workaround for Sway");
}
return is_sway;
}
void
quirk_sway_subsurface_unmap(struct terminal *term)
{
render: gamma-correct blending This implements gamma-correct blending, which mainly affects font rendering. The implementation requires compile-time availability of the new color-management protocol (available in wayland-protocols >= 1.41), and run-time support for the same in the compositor (specifically, the EXT_LINEAR TF function and sRGB primaries). How it works: all colors are decoded from sRGB to linear (using a lookup table, generated in the exact same way pixman generates it's internal conversion tables) before being used by pixman. The resulting image buffer is thus in decoded/linear format. We use the color-management protocol to inform the compositor of this, by tagging the wayland surfaces with the 'ext_linear' image attribute. Sixes: all colors are sRGB internally, and decoded to linear before being used in any sixels. Thus, the image buffers will contain linear colors. This is important, since otherwise there would be a decode/encode penalty every time a sixel is blended to the grid. Emojis: we require fcft >= 3.2, which adds support for sRGB decoding color glyphs. Meaning, the emoji pixman surfaces can be blended directly to the grid, just like sixels. Gamma-correct blending is enabled by default *when the compositor supports it*. There's a new option to explicitly enable/disable it: gamma-correct-blending=no|yes. If set to 'yes', and the compositor does not implement the required color-management features, warning logs are emitted. There's a loss of precision when storing linear pixels in 8-bit channels. For this reason, this patch also adds supports for 10-bit surfaces. For now, this is disabled by default since such surfaces only have 2 bits for alpha. It can be enabled with tweak.surface-bit-depth=10-bit. Perhaps, in the future, we can enable it by default if: * gamma-correct blending is enabled * the user has not enabled a transparent background
2025-02-21 11:01:29 +01:00
return;
if (!is_sway())
return;
wl_surface_damage_buffer(term->window->surface.surf, 0, 0, INT32_MAX, INT32_MAX);
}