Commit graph

770 commits

Author SHA1 Message Date
Daniel Eklöf
fba9bb6853
render: fix hollow cursor style for "extra" cursors
When the cursor is "block style", i.e. either when the window is
focused and the cursor is block, or when unfocused and we're supposed
to draw a hollow cursor, then we need to draw it *before* compositing
the glyph.

In all other cases (i.e. beam and underline cursors), it should be
rendered after the glyph.

With the addition of "extra" cursors, the logic for determining which
type it is has become much more complex, and the single if-statement
we had was wrong (it didn't handle "extra" cursors correctly).

Fix by splitting up all the checks into multiple if-statements.
2025-08-29 12:48:37 +02:00
Daniel Eklöf
6319ed8b29
render: multi-cursor: wip: colors 2025-08-28 12:18:00 +02:00
Daniel Eklöf
dcabe14392
render: multi-cell: decrement 'extra-cursor' pointer instead of indexing 2025-08-28 07:34:21 +02:00
Daniel Eklöf
64f52190ed
multi-cursor: render: wip
Shapes and most color options implemented
2025-08-28 07:30:37 +02:00
Daniel Eklöf
44bc720755
multi-cursor: render: wip 2025-08-27 17:08:39 +02:00
Daniel Eklöf
d5e99862af
multi-cursor: wip: render extra cursors
Currently ignores custom shapes and colors (i.e. all extra cursors are
rendered exactly as the primary cursor).
2025-08-27 15:00:27 +02:00
Daniel Eklöf
beb4556dc0
multi-cursor: wip: track cursor shapes and colors
And erase all extra cursors on reset, resize and clear
screen/scrollback (ED 2/3).
2025-08-27 13:43:45 +02:00
Daniel Eklöf
7347f4beb1
quirks: remove subsurface unmap quirk for Sway
Sway used to have an issue where unmapping a subsurface did not damage
the surface below (https://github.com/swaywm/sway/issues/6960).

This has been fixed for quite some time now, so let's remove the
quirk.
2025-06-09 07:08:24 +02:00
Daniel Eklöf
5a84f8d841
conf: pad: add center-when-fullscreen and center-when-maximized-and-fullscreen
Before this patch, the grid content was *always* centered when the
window was maximized or fullscreened, regardless of how the user had
configured padding.

Now, the behavior is controlled by the 'pad' option. Before this
patch, the syntax was

    pad MxN [center]

Now it is

    pad MxN [center|center-when-fullscreen|center-when-maximized-and-fullscreen]

The default is "pad 0x0 center-when-maximized-and-fullscreen", to
match current behavior.

Closes #2111
2025-05-24 09:56:16 +02:00
Daniel Eklöf
664cdcc65c
cursor-shape: add 'dnd-ask' and 'all-resize'
These (non-css) cursor shapes were added to the cursor-shape-v1
protocol in wayland-protocols 1.42.

We don't need (or use them at all) internally, but add them to the
list we use to translate from shape names to shape enums. This allows
users to set a custom shape (via OSC-22), while still using server
side cursors (i.e. no need to fallback to client-side cursors).

If we try to set a shape not implemented by the server, we get a
protocol error and foot exits. This is bad.

So, make sure we don't do that:

1. First, we need to explicitly bind v2 if implemented by the server
2. Track the bound version number in the wayland struct
3. When matching shape enum, skip shapes not supported in the
   currently bound version of the cursor-shape protocol
2025-05-22 06:59:33 +02:00
Kirill Primak
456ac5d79f
render: improve CSD button positioning
This commit fixes titlebar button positioning when maximization isn't
available but minimization is.
2025-05-21 07:39:35 +02:00
Daniel Eklöf
073b637d45
render: refactor to allow setting only selection bg or fg
Before this, we only applied custom selection colors, if *both* the
selection bg and fg had been set.

Since the options are already split up into two separate options, and
since it makes sense to at least be able to keep the foreground colors
unchanged (i.e. only setting the selection background), let's allow
only having one of the selection colors set.

Closes #1846
2025-05-05 13:02:32 +02:00
Daniel Eklöf
e5a0755451
config: tweak.surface-bit-depth now defaults to 'auto'
When set to 'auto', use 10-bit surfaces if gamma-correct blending is
enabled, and 8-bit surfaces otherwise.

Note that we may still fallback to 8-bit surfaces (without disabling
gamma-correct blending) if the compositor does not support 10-bit
surfaces.

Closes #2082
2025-05-01 08:54:30 +02:00
Daniel Eklöf
b07ce56321
config: gamma-correct-blending: disable by default 2025-05-01 08:09:08 +02:00
Daniel Eklöf
cb1b7ba0c5
render: regression: alpha applied to inversed text/selections
Introduced by 5f83278afd

Closes #2073
2025-04-25 19:20:36 +02:00
Daniel Eklöf
1a2e5f4932
render: fix colors.alpha-mode=matching
Before this patch, it only matched RGB color sources. It did not match
the default bg color, or indexed colors. That is, e.g. CSI 43m didn't
apply alpha, even if the color3 matched the default background color.
2025-04-19 13:33:23 +02:00
Daniel Eklöf
d2d4f53861
config+render: move alpha-mode to colors.alpha-mode, fix cursor handling
Move main.alpha-mode to colors.alpha-mode.

Fix (inverted) cursor handling, by always using the bg color without
alpha.

Do a minor optimization, where we don't even lock at colors.alpha-mode
if there's no transparency configured.
2025-04-14 16:58:23 +02:00
Fazzi
5f83278afd
config: add alpha_mode option 2025-04-14 16:47:45 +02:00
Sam McCall
663c9082db
render: dim and brighten using linear rgb interpolation
Adds setting tweak.dim-amount, similar to bold-text-in-bright-amount.

Closes #2006
2025-03-23 15:24:23 +01:00
Daniel Eklöf
d48a1c53f5
meson: require wayland-protocols >= 1.41 2025-03-13 13:28:34 +01:00
Daniel Eklöf
ccf625b991
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-03-05 18:45:01 +01:00
Daniel Eklöf
c41008da31
config+render: allow cursor.style=hollow
Closes #1965
2025-02-19 11:50:25 +01:00
Daniel Eklöf
8b63869f57
render: minimum window size: 2 cols -> 1 col 2025-02-10 13:19:57 +01:00
Daniel Eklöf
3d66db63cc
grid: refactor reflow
We've been trying to performance optimize reflow by "chunking" cells;
try to gather as many as possible, and memcpy a chunk at once.

The problem is that a) this quickly becomes very complex, and b) is
very hard to get right for multi-column characters, especially when we
need to truncate long ones due to the window being too small.

Refactor, and once again walk and copy all cells one by one. This is
slower, but at least it's correct.
2025-02-10 13:19:50 +01:00
Daniel Eklöf
a3a404a257
render: resize: note why min_cols=7 2025-02-06 14:02:38 +01:00
Daniel Eklöf
7a8d2b5e01
osc: wip: kitty text size protocol
This brings initial support for the new kitty text-sizing
protocol. Note hat only the width-parameter ('w') is supported. That
is, no font scaling, and no multi-line cells.

For now, only explicit widths are supported. That is, w=0 does not yet
work.

There are a couple of changes to the renderer, to handle e.g.

    OSC 66 ; w=6 ; foobar ST

There are two ways this can get rendered, depending on whether
grapheme shaping has been enabled. We either shape it, and get an
array of glyphs back that we render. Or, we rasterize each codepoint
ourselves, and render each resulting glyph.

The two cases ends up in two different renderer loops, that worked
somewhat different. In particular, the first case has probably never
been tested/used at all...

With this patch, both are changed, and now uses some heuristic to
differentiate between multi-cell text strings (like in the example
above), or single-cell combining characters. The difference is mainly
in which offset to use for the secondary glyphs.

In a multi-cell string, each glyph is mapped to its own cell, while in
the combining case, we try to map all glyphs to the same cell.
2025-02-06 07:42:38 +01:00
Daniel Eklöf
846271e8d3
render: resize: configure with only one dimension being zero
The protocol states:

    If the width or height arguments are zero, it means the client
    should decide its own window dimension. This may happen when the
    compositor needs to configure the state of the surface but doesn't
    have any information about any previous or expected dimension.

The wording is a bit ambiguous; does it mean we should set *both*
width and height to values we choose, even if only one dimension is
zero in the configure event? Or does it mean that we should choose the
value for the dimension that is zero in the configure event?

Regardless, it's pretty clear that it does *not* mean we should *only*
choose width and height if *both* dimensions are zero in the configure
event. This is foot's behavior before this patch, meaning if only one
of them is zero, foot assumed the compositor wanted us to set the
width (or height) to zero...

Change this, so that we now choose value for the "missing" dimension,
but do use the compositor provided value for the other dimension.

Closes #1925

Relevant issues:

* https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/155
* https://github.com/YaLTeR/niri/issues/1050
2025-01-26 09:28:54 +01:00
Alexander Orzechowski
301101e7d9
Revert "config: don't allow colors.flash-alpha to be 1.0"
This reverts commit 56d2c3e990.
2025-01-09 07:53:50 +01:00
Alexander Orzechowski
f0253633d3
render: Expose render_overlay
This function updates the overlay that foot uses. It will be used to
update the overlay when the flash effect ends.
2025-01-09 07:53:50 +01:00
Daniel Eklöf
f5c10a2452
render: fix order we're checking custom codepoints
Fixes a crash when trying to print a "Legacy Computing"
symbol (U+1FB00-U+1FB9B).

Closes #1901
2025-01-03 07:33:14 +01:00
Daniel Eklöf
56d2c3e990
config: don't allow colors.flash-alpha to be 1.0
A compositor will not send a frame callback for our main window if it
is fully occluded (for example, by a fully opaque overlay...). This
causes the overlay to stuck.

For regular buffers, it _should_ be enough to *not* hint the
compositor it's opaque. But at least some compositor special cases
single-pixel buffers, and actually look at their pixel value.

Thus, we have two options: implement frame callback handling for the
overlay sub-surface, or ensure we don't use a fully opaque
surface. Since no overlays are fully opaque by default, and the flash
surface is the only one that can be configured to be
opaque (colors.flash-alpha), and since adding frame callback handling
adds a lot of boilerplate code... let's go with the simpler solution
of
2025-01-02 09:10:51 +01:00
Daniel Eklöf
9a1b59adae
box-drawings: implement octants 2024-12-08 12:55:57 +01:00
Daniel Eklöf
e891abdd6a
render: remove unnecessary call to wl_surface_damage_buffer()
The damage region(s) are translated to wl_surface_damage_buffer()
calls after the entire frame has been rendered.
2024-10-06 11:26:35 +02:00
Daniel Eklöf
ce38f5b413
render: sixels: update damage region when rendering sixels
This fixes flickering when foot is forced to double-buffer (e.g when
running under KDE, or smithay based compositors).

Since the damage region isn't updated, the sixel images aren't
included in the memcpy that is done to transfer the last frame's
updated regions to the next frame.

As a result, every other frame will have the sixels, while the others
don't.

Closes #1851
2024-10-05 08:55:48 +02:00
Daniel Eklöf
6ad84dab2d
render: do dirty/clean consistency check before rendering sixels
Since the sixels may render some of the cells, we want the check to
happen before the sixels.
2024-09-21 09:11:28 +02:00
Daniel Eklöf
798b44934f
render: double-buffer: optimization: skip clean rows
When scanning the grid for all-dirty rows (that we can remove from the
damage region we're about to memcpy from the old frame), check the
row->dirty bit, and skip scanning the cells of that row altogether.

We're only looking for rows where all cells are dirty - those rows can
be removed from the region we copy from the old frame, since the
entire row will be re-rendered anyway.

If a row is clean, it *must* be copied from the old frame.
2024-09-21 09:11:07 +02:00
Daniel Eklöf
a9fefcf58b
render: (debug): assert row->dirty vs. cell->attrs.clean consistency 2024-09-21 09:11:07 +02:00
Daniel Eklöf
e2aeb7f336
render: xcursor_is_valid(): don't crash when there's no theme loaded
When trying to set a custom cursor shape, we first validate it. This
is done by checking against known server-side names, and then trying
to load the cursor from the client side cursor theme.

But, if we're using server side names, there is no theme loaded, and
foot crashed.

Fix by checking if we have a theme loaded, and if not, fail the cursor
shape name validation.
2024-09-21 09:10:48 +02:00
Daniel Eklöf
297cb370aa
render: add missing include, limits.h 2024-09-15 09:56:41 +02:00
Daniel Eklöf
97ec375c67
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
2024-09-13 09:04:17 +02:00
Daniel Eklöf
b34137dde3
toplevel-icon: set to app-id, instead of hardcoding to "foot"
And, special case "footclient", and map it to "foot".
2024-09-13 09:04:17 +02:00
Daniel Eklöf
1925593a37
render: resize(): don't overflow the number of scrollback lines
The config system allows setting the scrollback lines to
2**32-1.

However, the total number of grid lines is the scrollback lines plus
the window size, and then rounded *up* to the nearest power of two.

Furthermore, the number of rows is represented with a plain 'int'
throughout the code base.

The largest positive integer that fits in an int is 2**31-1. That
however, is not a power of two.

The largest positive integer, that also is a power of two, that fits
in an int is 2**30, or 1073741824.

Ideally, we'd just cast the line count to a 64-bit integer, and call
__builtin_clzl{,l}() on it, and then take the smallest value of that,
or 2**30. But, for some reason, __builtin_clzl(), and
__builtin_clzll() appears to ignore bits above 32, despite they being
typed to long and long long. Bug?

Instead, ensure we never call __builtin_clz() on anything larger than
2**30.

Closes #1828
2024-09-09 06:58:52 +02:00
Oleh Hushchenkov
b47a4dd255
add setting for strikeout thickness 2024-08-26 19:34:47 +02:00
tokyo4j
a2fc2a986e
render: follow cursor.unfocused-style regardless of cursor.style
Before this commit, cursor.unfocused-style was effective only with
cursor.style=block
2024-08-20 06:59:33 +02:00
Daniel Eklöf
bef613e656
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.
2024-08-09 08:20:59 +02:00
Daniel Eklöf
a9e462d952
Remove a number of unused includes 2024-08-02 08:28:13 +02:00
Daniel Eklöf
38461eef6f
csi: in-band window resize notifications, private mode 2048
This implements
https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83,
in-band window resize notifications.

When user enables private mode 2048 (in-band resize
notifications), *always* send current size, even if the mode is
already active.

This ensures applications can rely on getting a reply from the
terminal.
2024-07-19 06:54:32 +02:00
Daniel Eklöf
56556e5f23
render: hollow-cursor: use correct cursor color 2024-07-13 10:37:21 +02:00
Daniel Eklöf
c46c124363
render: cursor: use default fg/bg if cell fg/bg are the same
When deciding which colors to use for the cursor, and the cursor text
and background colors are the same, use the default fg/bg instead.

Closes #1761
2024-07-13 10:30:23 +02:00
Daniel Eklöf
5d4a002413
osc: merge OSC 10/11/12/17/19 handling
10/11/17/19 were already merged, so this patch just stops special
casing 12 (cursor color).

In preparation for XTPUSHCOLORS/XTPOPCOLORS, the cursor colors are
moved from their own struct, into the 'colors' struct.

Also fix a bug where OSC 17/19 queries returned OSC-11 data.
2024-07-03 09:47:30 +02:00