Subject: bug#75930: 30.0.92; Setting default frame background color messes up mouse pointer

From: [email-masked]
Date: Thu, 30 Jan 2025 22:04:31 +0100

Po Lu <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>> The thing is, I cannot find where this setting of the border happens
>> in our code.  It seems to be the consequence of setting the frame's
>> background mode, which happens when you set the background color, but
>> that's where the track went cold for me, probably because I don't know
>> enough about the X11 graphics.  I hope someone else will be able to
>> point out where we cause that border to appear, and then a solution
>> might be found.
>>
>> Po Lu, any suggestions or ideas?
>
> Set a breakpoint on x_set_mouse_color, perhaps?

I don't think a breakpoint will be necessary, I just popped in and had a
look at x_set_mouse_color, and it shows quite clearly that it does
explicitly do what I experience.

First it sets mask_color to the frame background near the start of the
function:

  unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
  unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);

Then a bit further down it does this:

    XColor colors[2]; /* 0=foreground, 1=background */

    colors[0].pixel = x->mouse_pixel;
    colors[1].pixel = mask_color;
    x_query_colors (f, colors, 2);

    for (i = 0; i < mouse_cursor_max; i++)
      XRecolorCursor (dpy, cursor_data.cursor[i], &colors[0], &colors[1]);

So it seems that x_set_mouse_color always sets the mouse pointer border
color to the frame background. However, the foreground color defaults to
BLACK_PIX_DEFAULT.

This makes reproducing the bug even simpler, as it can now be done
multiple times from within Emacs without having to restart and passing
arguments to it.

This sequence of commands will do the same thing as the reproduction
steps I gave in the first message:

  (set-background-color "#ff0000")
  (set-mouse-color "#000000")
  (set-background-color "#000000")

Technically, the only line needed is the set-mouse-color one, but
changing the background before and after makes it easier to see.

A slightly different question is of course why it even calls
x_set_mouse_color on startup in the first place, when there is no custom
mouse color configured anywhere. The default behaviour should surely be
to not explicitly set the mouse color unless a color has been specified.