How do I set background to specific GtkCombo and its children?

What is the best way to set background to a specific Combo and all its children, without affecting other Combos?

I’m working on a cross-platform window library called SWT. In it, there’s an API to set back/fore colors to various widgets.

We have a problem with composite widgets, such as Combo, because it has many parts: menu, drop button, cell, entry, etc.

The intuitive way to set background would be to

  1. Compose CSS like * {background: #414141}
  2. Allocate CSS provider with gtk_css_provider_new()
  3. Apply it to widget with gtk_style_context_add_provider()

However, this doesn’t work with Combo: it only sets background to the Combo itself.

The current workaround is to find all internal widgets and apply changes to them as well.
This has multiple problems:

  1. The code is hackish and reaches into non-public parts of GTK
  2. As a result, we sometimes need to adjust the searching magic
  3. The code has to detect changes in internal widgets, such as when ‘appears-as-list’ style causes Combo to create a different set of internal widgets.

The other potential solutions I investigated:

  1. gtk_style_context_add_provider_for_screen() - supposedly this can be used with IDs to only affect specific widgets. However, this doesn’t sound like a good approach for a window library. In a typical case, there are numerous widgets and everything gets styled (imagine app-driven “dark theme”). We will therefore need to compile massive CSS, which is going to be a performance issue in my understanding. Also, managing this massive CSS is going to be another problem.
  2. !important keyword like in web-based CSS - I understand that GTK does not support that.
  3. gtk_style_context_set_parent() - I understand that in Combo, every internal widget already refers to parent style context. Just it still doesn’t help. Not sure why, I expect something along the lines of specificity of default CSS rules overriding our CSS.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.