title: Customizing GtkTextTag appearance thru GTK3 CSS stylesheets?
body: <p>I have some <code>GtkTextTable*mom_tagtable;</code> which is the tag table of a <code>GtkTextBuffer *mom_obtextbuf;</code> (which is shown in two text views <code>GtkWidget *mom_tview1;</code> &amp; <code>GtkWidget*mom_tview2;</code>). I'm using GTK3.21 on Linux/Debian/Sid and it is for the same (free software, GPLv3) application than in <a href="https://stackoverflow.com/q/39366248/841108">this other</a> question: the <a href="https://github.com/bstarynk/melt-monitor-2015/tree/expjs" rel="nofollow noreferrer">expjs branch</a> (on <code>github</code>) of the MELT monitor. BTW all the GTK code is in one C99 file <a href="https://github.com/bstarynk/melt-monitor-2015/blob/expjs/gui.c" rel="nofollow noreferrer">gui.c</a>. I have a few dozen of text tags:</p>
  
  <pre><code>static GtkTextTag *mom_tag_toptitle;    // tag for top text
  static GtkTextTag *mom_tag_objtitle;    // tag for object title line
  static GtkTextTag *mom_tag_objsubtitle; // tag for object subtitle line
  static GtkTextTag *mom_tag_idstart;     // tag for first characters of objids
  /* etc .... */
  </code></pre>
  
  <p>I don't want to build my GUI using <code>GtkBuilder</code> (I prefer coding manually, because most of the code could be later generated by my application). I would like to customize the appearance of the tags and of all my app in the same textual file. It seems that <a href="https://developer.gnome.org/gtk3/stable/chap-css-overview.html" rel="nofollow noreferrer">GTK CSS stylesheets</a> could be useful.</p>
  
  <p>Actually, it looks that GTK3 has or had several ways to describe the look&amp;feel and theme of an application in textual files (<a href="https://developer.gnome.org/gtk3/stable/GtkBuilder.html" rel="nofollow noreferrer">GtkBuilder</a> which also defines the GUI and I don't want to have that, <a href="https://developer.gnome.org/gtk3/stable/chap-css-overview.html" rel="nofollow noreferrer">GTK-CSS stylesheets</a>, obsolete Gtk <a href="https://developer.gnome.org/gtk3/stable/gtk3-Resource-Files.html" rel="nofollow noreferrer">resource</a> files, obsolete <a href="https://developer.gnome.org/gtk3/stable/GtkUIManager.html" rel="nofollow noreferrer">GtkUIManager</a>, etc...) and that it is transitioning to the GTK CSS framework but the transition did not complete in GTK3.20.</p>
  
  <p>I'm currently initializing these tags using hard-coded look &amp; feel:</p>
  
  <pre><code>    mom_tag_toptitle =
        gtk_text_buffer_create_tag (mom_obtextbuf,
                                    "toptitle",
                                    "justification", GTK_JUSTIFY_CENTER,
                                    "pixels-above-lines", 2,
                                    "pixels-below-lines", 4,
                                    "foreground", "navy",
                                    "paragraph-background", "lightyellow",
                                    "font", "Helvetica Bold", "scale", 1.5, NULL);
      mom_tag_objtitle =
        gtk_text_buffer_create_tag (mom_obtextbuf,
                                    "objtitle",
                                    "justification", GTK_JUSTIFY_CENTER,
                                    "pixels-above-lines", 4,
                                    "pixels-below-lines", 2,
                                    "foreground", "brown",
                                    "font", "Sans Bold",
                                    "paragraph-background", "lightcyan",
                                    "scale", 1.3, NULL);
      mom_tag_objsubtitle =
        gtk_text_buffer_create_tag (mom_obtextbuf,
                                    "objsubtitle",
                                    "justification", GTK_JUSTIFY_CENTER,
                                    "pixels-above-lines", 1,
                                    "pixels-below-lines", 1,
                                    "foreground", "chocolate4",
                                    "font", "Sans Bold",
                                    "paragraph-background", "lightgoldenrod",
                                    "scale", 1.15, NULL);
      mom_tag_idstart =
        gtk_text_buffer_create_tag (mom_obtextbuf,
                                    "idstart",
                                    "font", "Courier Bold",
                                    "foreground", "darkgreen", NULL);
  </code></pre>
  
  <p>I am not happy with that approach, and I would like these tags to have an appearance (font, size, colors) described in some external textual file (and likewise for the widgets around the textviews).</p>
  
  <p>So my question is:</p>
  
  <p><strong>How to customize <code>GtkTextTag</code>-s thru GTK CSS stylesheets?</strong></p>
  
  <p>I was thinking of creating some "fake" <a href="https://developer.gnome.org/gtk3/stable/gtk3-GtkWidgetPath.html" rel="nofollow noreferrer">GtkWidgetPath</a> (should I create one such path per gtk text tag) and using it to retrieve the style information in the GTK CSS but I am not sure at all it is the right approach.</p>
  
  <p>I also don't understand exactly how two different text views showing the <em>same</em> text buffers can have different styles for the same text (I hope it is not possible, but I am not sure why).</p>
  
  <p><a href="https://stackoverflow.com/q/8946016/841108">This</a> might be a related question, but it looks quite different to mine.</p>
  
  <p>PS. I am not specifically focused on GTK3 CSS, but I do want to have if possible one single text file describing the appearance of my entire GTK3 application.</p>