Subject: bug#16992: feature request: background images

From: Cecilio Pardo <[email-masked]>
Date: Fri, 8 Nov 2024 17:42:48 +0100

On 08/11/2024 16:46, Eli Zaretskii wrote:

> So showing a vertical line for the fill-column indication would need
> to define a background image for a frame?  How do we control the
> horizontal coordinate where the line is drawn?

No, the background image (if present) is drawn first, then 'dynamic' 
things like the indicator are drawn over, with the corresponding drawing 
api. We are doing both things. In the patch, the fill-column indicator 
line is drawn by looking directly at the value of fill_column. But I 
think it would be better to allow lisp to define multiple vertical 
lines, with the desired position.

>> The image can be placed in the center, or on sides or corners with 'n,
>> 's, 'se, 'sw, etc. The background can be filled be repeating the image
>> passing t as the last parameter of frame-set-background-image.
> 
> Why not let Lisp specify explicit coordinates for the image?

Yes, I will add x/y offsets, to put it anywhere.

>> Apart from the obvious overhead of drawing the image pixels,
>> unfortunately the frame contents can't be scrolled to reuse text pixels
>> (dispnew.c:scrolling_window). I don't think this can't be fixed without
>> big changes.
> 
> Hmm.. scroll_run_hook is also called from two redisplay optimizations
> in xdisp.c, so those will need to be disabled as well.  Too bad.
> 
> But maybe we can make them work if we consider the background image to
> be scrolled together with the text? "all we need" is to insert a slice
> of the same image from below or from above, depending on the scrolling
> direction.

We can add scrolling images, sure. I think we should do both types then.

> Btw, what happens when text is scrolled horizontally?

Nothing special. Besides redrawing everything.

> Is this only going to work with fixed images?  Then I guess features
> like showing vertical lines as indentation indicators, like those
> here:
> 
>    https://techpress.net/how-to-show-hide-indent-dots-in-vscode/
> 
> will not be possible?

Yes. Those are not part of the image. We use the same mechanism to draw 
on the background, but they are independent. We can use them without 
background images at all.

Some of these things are easy to do, like the fill indicator, which 
doesn't depend on the contents of the buffer. Indentation lines are much 
more complex.

If you find the mechanism to draw on the background acceptable, I can 
work on a first version of that.

>> +get_all_live_windows (struct window *w, struct window **dest)
>> +{
>> +  if (WINDOW_LEAF_P (w))
>> +    {
> 
> You could perhaps extend window_loop to do whatever the callers of
> this function do

Ok, thanks.