mike-fabian / ibus-typing-booster

ibus-typing-booster is a completion input method for faster typing
https://mike-fabian.github.io/ibus-typing-booster/
Other
228 stars 16 forks source link

Should not the background color of inline completions be transparent? #241

Open psads-git opened 3 years ago

psads-git commented 3 years ago

Hi, Mike,

I have recently changed the theme of my Thunderbird to Dark. The ibus-typing-booster inline completion background color does not match the dark one of the compose window -- it is white. Surprisingly, it works fine with the Gedit dark mode -- the background color of inline completions matches the Gedit background color.

My suspicion is that ibus-typing-booster is using white as background color for inline suggestions and not a transparent background color!

Thanks!

mike-fabian commented 3 years ago

Can you please make a screen shot or video?

psads-git commented 3 years ago

Thanks and welcome back, Mike. The requested screen-shot is attached.

Screenshot_2021-09-12_14-43-15

mike-fabian commented 3 years ago

My suspicion is that ibus-typing-booster is using white as background color for inline suggestions and not a transparent background color!

It doesn't set any background colour at all:

https://github.com/mike-fabian/ibus-typing-booster/blob/main/engine/hunspell_table.py#L2239

            if self._color_inline_completion:
                attrs.append(IBus.attr_foreground_new(
                    self._color_inline_completion_argb,
                    len(typed_string), len(typed_string + completion)))
psads-git commented 3 years ago

Thanks, Mike. Would it be worthy to have the possibility of the user being able to select the background color?

mike-fabian commented 3 years ago

Thanks, Mike. Would it be worthy to have the possibility of the user being able to select the background color?

I'm not sure. Maybe it would be nicer to find out where this background colour comes from and how to avoid it. I can reproduce this in firefox with the “Dark mode” addon.

Of course I could add an option to set the background. But if one sets it to black, it would look good on the dark theme in firefox but would look bad in other places. For the foreground of the inline completion, it is possible to select some colour like a medium gray which looks fine both on white and black backgrounds. I use some sort of orange which also looks fine both on white and black backgrounds. But if one sets the background of the preedit to black, it will only look good on a black background and look terrible everywhere else.

I would prefer to leave the background alone. And it looks like I am not setting it at all, so where does this come from 🤔 ?

mike-fabian commented 3 years ago

And, as you noticed, this doesn't happen in dark themes in gedit.

What is different in dark themes in firefox and thunderbird?

psads-git commented 3 years ago

What I mean is to have the user to select the background color from a pallet of colors, Mike!

mike-fabian commented 3 years ago

What I mean is to have the user to select the background color from a pallet of colors, Mike!

Yes, of course, just like you currently choose the foreground colour for the inline completion.

But I don't think is possible to choose any colour for the background which looks good on all kinds of themes.

For the dark mode in firefox and thunderbird, choosing some very dark gray or black might look OK. But that would look terrible in a light theme.

mike-fabian commented 3 years ago

Writing github comments in firefox with a dark theme (The entry where I actually write is not dark!):

Screenshot

mike-fabian commented 3 years ago

Writing into Duolingo using a dark theme in firefox:

Screenshot

mike-fabian commented 3 years ago

So if I would choose a background colour which looks good in Duolingo, it would look bad when writing the github comments.

I think what we actually want is to leave the background as it is.

psads-git commented 3 years ago

Maybe, Mike, if we do not explicitly select a transparent background, Thunderbird and Firefox dark theme will choose the background color that is selected by default.

mike-fabian commented 3 years ago

Maybe, Mike, if we do not explicitly select a transparent background, Thunderbird and Firefox dark theme will choose the background color that is selected by default.

I immediately tried to explicitely set a transparent background yesterday, but it didn’t help.

mike-fabian commented 3 years ago

Here is why it didn’t help when I tried this yesterday:

in _ibus_context_update_preedit_text_cb () in ibus there is:

https://github.com/ibus/ibus/blob/master/client/gtk2/ibusimcontext.c#L2037

            case IBUS_ATTR_TYPE_FOREGROUND:
                pango_attr = pango_attr_foreground_new (
                                        ((attr->value & 0xff0000) >> 8) | 0xff,
                                        ((attr->value & 0x00ff00)) | 0xff,
                                        ((attr->value & 0x0000ff) << 8) | 0xff);
                break;
            case IBUS_ATTR_TYPE_BACKGROUND:
                pango_attr = pango_attr_background_new (
                                        ((attr->value & 0xff0000) >> 8) | 0xff,
                                        ((attr->value & 0x00ff00)) | 0xff,
                                        ((attr->value & 0x0000ff) << 8) | 0xff);

This seems to handle only red, green, and blue, apparently it ignores the alpha channel for transparency.

mike-fabian commented 3 years ago

https://docs.gtk.org/Pango/func.attr_foreground_new.html https://docs.gtk.org/Pango/func.attr_foreground_alpha_new.html

mike-fabian commented 3 years ago

So at the moment I cannot set the alpha value (i.e. the transparency) from ibus-typing-booster, it is ignored in ibus. To make transparency possible, the code in _ibus_context_update_preedit_text_cb ()

https://github.com/ibus/ibus/blob/master/client/gtk2/ibusimcontext.c#L2037

would need to be extended to use also pango_attr_foreground_alpha_new()

mike-fabian commented 3 years ago

Testing that the transparency is ignored:

From the command line, one can set a foreground colour for the inline completion with transparency like this:

$ dconf write /org/freedesktop/ibus/engine/typing-booster/colorinlinecompletionstring '"rgba(2
55,163,72, 0.3)"'

where 0.3 is the transparency value.

After doing that one can see in the setup tool that a transparent colour is set:

Screenshot

But when testing this by using inline completion with ibus-typing-booster, one finds that there is not transparency, it is 100% opaque.

mike-fabian commented 3 years ago

In color_string_to_argb(color_string: str) -> int

https://github.com/mike-fabian/ibus-typing-booster/blob/main/engine/itb_util.py#L2525

ibus-typing-booster converts the value rgba(255,163,72, 0.3) set above using dconf on the command line to a 32 bit integer.

For example:

    >>> print('%x' %color_string_to_argb('rgba(0xff, 0x10, 0x25, 0.5)'))
    7fff1025

I.e. it puts the transparency, 0.5 in this example into the first 8 bit of the 32 bit integer, the 0.5 becomes 7f here. The following 24 bits are 8 bits each for red, green, and blue. This 32 bit value is passed to ibus.

But then the code in

https://github.com/ibus/ibus/blob/master/client/gtk2/ibusimcontext.c#L2037

Uses only the lower 24 bits and not the high 8 bits for the transparency.

mike-fabian commented 3 years ago

It might be interesting to enhance ibus to allow to use transparency in the colours. Might be a useful improvement.

But I am not sure whether this would fix the problem seen in the dark theme of firefox/thunderbird.

It might fix it, but it is also possible that it would not fix it.

Maybe there is a way to fix this in the dark theme?

mike-fabian commented 3 years ago

To me it also looks like a bug in the dark theme that it uses white as a background colour even though no background colour was set by pango.

psads-git commented 3 years ago

There this option in dark them, Mike, which seems to be set as never by default:

Override the colors specified...

Maybe if one sets always, it will work.

mike-fabian commented 3 years ago

I don't see such an option in the extensions I tried. I tried:

psads-git commented 3 years ago

Sorry, Mike: I mistook Thunderbird settings with Dark Theme ones!

Screenshot_2021-09-13_17-53-47

mike-fabian commented 3 years ago

Does playing with that option help?

psads-git commented 3 years ago

No, Mike.

psads-git commented 3 years ago

Maybe we should leave this problem as it is, as there is nothing more we can do, Mike.

mike-fabian commented 3 years ago

By the way, in thunderbird, when using a dark theme, the inline completion looks better if colour is switched off in the setup tool of ibus-typing-booster:

Screenshot

But of course with this setting it looks less good in cases where the problem with the white background does not occur.

mike-fabian commented 3 years ago

Maybe we should leave this problem as it is, as there is nothing more we can do, Mike.

Yes, I think I can do nothing in ibus-typing-booster at the moment.

If I can convince the ibus-developer to support setting transparency, then I could try to use that, maybe it helps. But it is hard to say. And maybe transparency for the ibus colour settings is usually not important. Using it to try to override the wrong white background seems more like a workaround than a necessary feature.

psads-git commented 3 years ago

Thanks, Mike. Indeed, with no color set for inline completion, it looks better in Thunderbird Dark theme.

Hoping that, in the future, the ibus-developer will add transparency!

mike-fabian commented 3 years ago

I found other stuff which looks pretty bad in the dark theme in thunderbird. When I try to discard a mail I get this dialog:

Screenshot

The text on the buttons is not really readable in the dark theme.

Looks like the dark theme has some bugs, especially because the dark themes in gedit work well with typing-booster, I suspect there is something wrong with the dark themes in thunderbird and firefox. Maybe one could try to make a bug report against these themes.

mike-fabian commented 3 years ago

Do you think you can open an issue against the dark thunderbird theme?

mike-fabian commented 3 years ago

Fujiwara San, the ibus developer, thinks there is no reason to have transparency in the preedit colors. I cannot see a reason either, except to workaround such bugs as in the dark themes for thunderbird and firefox. And then it is probably better to try to fix these bugs in the themes.

mike-fabian commented 3 years ago

I reported this bug against the dark theme in thunderbird:

https://bugzilla.mozilla.org/show_bug.cgi?id=1730678

I am not sure whether this is related to the white background we see in the ibus preedit, but it could be. And definitely looks like a bug to me.

psads-git commented 3 years ago

Thanks, Mike! This afternoon, I was going to report the bug against the dark theme in thunderbird, since I was the whole morning in meetings.