App-provided styling defaults get overridden by less-specific theme rules

MATE’s file manager Caja has custom CSS for rendering the desktop items. This works, but it currently uses the APPLICATION priority for its CSS because of the issue I’ll be describing. The problem it causes is that, obviously, a theme cannot alter it. AFAICT it’s meant to be overridable, but is not because of a failure to implement it otherwise.

The thing is that apparently one cannot override a treeview foreground color (in Adwaita, other themes my prevent overriding other aspects) from a provider with priority THEME, even when selecting with a highly specific rule (which includes hierarchy, specific classes, etc.). This effectively prevents Caja from providing defaults that the theme could override, because not only a theme not providing specifics won’t style the desktop separately, but more importantly if Caja’s defaults contain any element not set by the theme they will end up with inconsistent visual (like black drop-shadow for black text or any fancy like that).

So, how can an application provide a default styling for some custom elements that is used unless the theme provides effectively styling for those (and not just some random generic catchalls)?

Here is an example program showing the issue, where you can see the CSS is not take into account despite the presence of a custom class:

Test program

#!/usr/bin/env python3
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gio, Gtk, Gdk

class AppWindow(Gtk.ApplicationWindow):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)


        self.provider = Gtk.CssProvider()

        Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default(),

        builder = Gtk.Builder()

        self.view = builder.get_object('treeview1')


class Application(Gtk.Application):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, application_id="org.example.themetest",
        self.window = None

    def do_activate(self):
        if not self.window:
            self.window = AppWindow(application=self, title="Main Window")


if __name__ == "__main__":
    app = Application()


.test-widget:backdrop {
  color: green;
  text-shadow: 1px 1px alpha(red, 0.8);
/* if the above didn't work, I would expect this to do, given how precise it is * /
* scrolledwindow treeview.view.test-widget:dir(ltr),
* scrolledwindow treeview.view.test-widget:dir(ltr):focus,
* scrolledwindow treeview.view.test-widget:dir(ltr):backdrop {
  color: red;
  text-shadow: 1px 1px alpha (#000000, 0.8);
/ **/


<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkListStore" id="liststore1">
      <!-- column-name gchararray1 -->
      <column type="gchararray"/>
        <col id="0" translatable="yes">First test line</col>
        <col id="0" translatable="yes">Second test line</col>
  <object class="GtkScrolledWindow" id="root">
    <property name="visible">True</property>
    <property name="can_focus">True</property>
    <property name="shadow_type">in</property>
      <object class="GtkTreeView" id="treeview1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="model">liststore1</property>
        <child internal-child="selection">
          <object class="GtkTreeSelection"/>
          <object class="GtkTreeViewColumn">
            <property name="title" translatable="yes">column</property>
              <object class="GtkCellRendererText"/>
                <attribute name="text">0</attribute>

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