CINXE.COM

Attic/GnomeArt/Tutorials/GtkThemes – GNOME Wiki Archive

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head><base href="/"> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Attic/GnomeArt/Tutorials/GtkThemes – GNOME Wiki Archive</title> <link rel="stylesheet" type="text/css" media="all" charset="utf-8" href="gnome/css/common.css"> <link rel="stylesheet" type="text/css" media="screen" charset="utf-8" href="gnome/css/screen.css"> <link rel="stylesheet" type="text/css" media="print" charset="utf-8" href="gnome/css/print.css"> <style type="text/css"> ul.pagetitle{ display: inline; margin: 0; padding: 0; font-size: 1.5em; } li.pagetitle{ display: inline; margin: 0; } td.noborder { border: 0; } </style> </head> <body><div class="retirement_banner">This site has been retired. For up to date information, see <a href="https://handbook.gnome.org/">handbook.gnome.org</a> or <a href="https://gitlab.gnome.org/">gitlab.gnome.org</a>.</div> <table> <tr> <td class="noborder"> <img src="logo.png"> </td> <td class="noborder"> <ul class="pagetitle"> <li class="pagetitle"><a class="backlink">Attic/GnomeArt/Tutorials/GtkThemes</a> </ul> <br><br> [<a href="Home.html">Home</a>]&nbsp;[<a href="TitleIndex.html">TitleIndex</a>]&nbsp;[<a href="WordIndex.html">WordIndex</a>]&nbsp; </td> </tr> </table> <hr> <div id="page"> <div dir="ltr" id="content" lang="en"><span class="anchor" id="top"></span> <span class="anchor" id="line-1"></span><span class="anchor" id="line-2"></span><p class="line867"><img alt="{i}" height="16" src="/gnome/gnome-responsive/img/icon-info.png" title="{i}" width="16" /> Please feel free to add documentation or correct things. If you have any comments, please write me an e-mail (<a class="mailto" href="mailto:benjamin@sipsolutions.net">benjamin@sipsolutions.net</a>), or come to #gnome-art on irc.gnome.org. A list of widgets: <span class="anchor" id="line-3"></span><span class="anchor" id="line-4"></span><p class="line867"><table class="navigation"><tr><td><a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GnomePanel.html">/GnomePanel</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkButton.html">/GtkButton</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkCheckButton.html">/GtkCheckButton</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkColorButton.html">/GtkColorButton</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkCombo.html">/GtkCombo</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkComboBox.html">/GtkComboBox</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkComboBoxEntry.html">/GtkComboBoxEntry</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkEntry.html">/GtkEntry</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkFrame.html">/GtkFrame</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkList.html">/GtkList</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkMenu.html">/GtkMenu</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkMenuBar.html">/GtkMenuBar</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkMenuItem.html">/GtkMenuItem</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkNotebook.html">/GtkNotebook</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkProgressBar.html">/GtkProgressBar</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkRadioButton.html">/GtkRadioButton</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkScale.html">/GtkScale</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkScrollbar.html">/GtkScrollbar</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkScrolledWindow.html">/GtkScrolledWindow</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkSpinButton.html">/GtkSpinButton</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkStatusbar.html">/GtkStatusbar</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkTreeView.html">/GtkTreeView</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)Pidgin.html">/Pidgin</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)StyleProperties.html">/StyleProperties</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)SymbolicColors.html">/SymbolicColors</a> &nbsp; <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)Workarounds.html">/Workarounds</a> &nbsp; </td></tr></table> <span class="anchor" id="line-5"></span><span class="anchor" id="line-6"></span><p class="line874">Things missing: <span class="anchor" id="line-7"></span><ul><li><p class="line862">Inheritance, i.e., <tt class="backtick">style&nbsp;"button"&nbsp;=&nbsp;"default"</tt>, but this is usually not necessary because of merging, and needs a warning, as it doesn't work correctly for engine options as far as is known. <span class="anchor" id="line-8"></span></li><li><p class="line862">The <a class="nonexistent" href="./GtkSettings.html">GtkSettings</a> properties are not mentioned here. See <a class="http" href="http://library.gnome.org/devel/gtk/stable/GtkSettings.html#id3227906">http://library.gnome.org/devel/gtk/stable/GtkSettings.html#id3227906</a> for a list of properties that can be set (not all of them make sense from the gtkrc). <span class="anchor" id="line-9"></span></li><li>Need information about icon size handling and a list of icon sizes in GNOME (see also Redmond gtkrc that sets numerous icon sizes) <span class="anchor" id="line-10"></span></li><li>How theme engines are used; see comment in the section. <span class="anchor" id="line-11"></span></li><li><p class="line862">Locale-specific <tt class="backtick">gtkrcs</tt> (<tt class="backtick">gtkrc.de</tt> will, for example, be parsed in German locales). This will only be useful in very rare cases (maybe for keybinding stuff, which is not the topic of this page). <span class="anchor" id="line-12"></span></li></ul><p class="line867"><hr /><p class="line874"> <span class="anchor" id="line-13"></span><span class="anchor" id="line-14"></span><p class="line867"> <h1 id="GTK_Theming_Tutorial">1. GTK Theming Tutorial</h1> <span class="anchor" id="line-15"></span><p class="line867"><div class="table-of-contents"><p class="table-of-contents-heading">Contents<ol><li> <a href="#GTK_Theming_Tutorial">GTK Theming Tutorial</a><ol><li> <a href="#Introduction">Introduction</a></li><li> <a href="#Architecture">Architecture</a><ol><li> <a href="#Widgets">Widgets</a></li><li> <a href="#Styles">Styles</a></li><li> <a href="#Engines">Engines</a></li></ol></li><li> <a href="#The_gtkrc_File">The gtkrc File</a><ol><li> <a href="#The_Style">The Style</a><ol><li> <a href="#x.2Fythickness">x/ythickness</a></li><li> <a href="#Style_Properties">Style Properties</a></li><li> <a href="#Colors">Colors</a></li></ol></li><li> <a href="#Applying_the_Style">Applying the Style</a><ol><li> <a href="#The_different_matching_lines">The different matching lines</a><ol><li> <a href="#class">class</a></li><li> <a href="#widget_class_matches">widget_class matches</a></li><li> <a href="#widget_matches">widget matches</a></li></ol></li><li> <a href="#Order_of_the_Merge">Order of the Merge</a></li><li> <a href="#Priority">Priority</a></li></ol></li><li> <a href="#Engines-1">Engines</a></li></ol></li><li> <a href="#Tips">Tips</a></li><li> <a href="#Check_List">Check List</a><ol><li> <a href="#Engine">Engine</a></li><li> <a href="#Theme">Theme</a></li></ol></li></ol></li></ol></div> <span class="anchor" id="line-16"></span> <h2 id="Introduction">1.1. Introduction</h2> <span class="anchor" id="line-17"></span><p class="line862">This tutorial will explain the basics of creating a GTK+2 theme for use with GNOME 2.2 and above. Some knowledge of the GTK+2 API can be helpful with more complicated themes; documentation can be found at <a class="http" href="http://developer.gnome.org/doc/API/2.0/gtk/index.html">http://developer.gnome.org/doc/API/2.0/gtk/index.html</a>. Other people's themes can be very helpful. You can find more GTK themes in the resources linked from <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)UsefulLinks.html">../UsefulLinks</a>. <span class="anchor" id="line-18"></span><span class="anchor" id="line-19"></span><p class="line874">Themes generally live in either a public directory (available to all users, typically in /usr/share/themes/) or in ~/.themes/ (just for you). A convenient place to put the themes you create are in ~/.themes/YOUR_THEME_NAME/gtk-2.0/. Within this gtk-2.0 directory you will place all files that go with your theme. Note that if themes of the same name are installed in both the public and the ~/.themes directories that GNOME will use the one in ~/.themes. <span class="anchor" id="line-20"></span><span class="anchor" id="line-21"></span><p class="line874">A good way to learn theming is to examine other people's themes. Your GNOME installation undoubtedly came with quite a few themes. More can be found at: <span class="anchor" id="line-22"></span><span class="anchor" id="line-23"></span><ul><li><p class="line891"><a class="http" href="http://art.gnome.org/">http://art.gnome.org/</a> <span class="anchor" id="line-24"></span></li><li><p class="line891"><a class="http" href="http://gnome-look.org/">http://gnome-look.org/</a> <span class="anchor" id="line-25"></span></li><li><p class="line891"><a class="http" href="http://themes.freshmeat.net/">http://themes.freshmeat.net/</a> <span class="anchor" id="line-26"></span><span class="anchor" id="line-27"></span><span class="anchor" id="line-28"></span></li></ul><p class="line867"> <h2 id="Architecture">1.2. Architecture</h2> <span class="anchor" id="line-29"></span><span class="anchor" id="line-30"></span><p class="line867"> <h3 id="Widgets">1.2.1. Widgets</h3> <span class="anchor" id="line-31"></span><span class="anchor" id="line-32"></span><p class="line874">GTK has a large set of widgets like buttons, scroll bars and edit boxes. Each of these widgets can be themed separately. <span class="anchor" id="line-33"></span><span class="anchor" id="line-34"></span><p class="line862">Every widget is derived from <tt class="backtick">GtkWidget</tt>. This means, changes to the properties of <tt class="backtick">GtkWidget</tt> will effect all widgets. Furthermore many other widgets have "parent widgets". For example, properties of <tt class="backtick">GtkButton</tt> will also be applied to <tt class="backtick">GtkCheckButton</tt> unless it is explicitly stated otherwise. <span class="anchor" id="line-35"></span><span class="anchor" id="line-36"></span><p class="line862">Hence this hierarchy — found at <a class="https" href="https://developer.gnome.org/gtk-tutorial/2.90/x477.html">https://developer.gnome.org/gtk-tutorial/2.90/x477.html</a> — is important when applying styles and we will come back to it later on. <span class="anchor" id="line-37"></span><span class="anchor" id="line-38"></span><p class="line867"> <h3 id="Styles">1.2.2. Styles</h3> <span class="anchor" id="line-39"></span><span class="anchor" id="line-40"></span><p class="line862">Everything you want to change is being changed in so called "styles". Within these styles you have two kinds of properties. On the one hand there is a limited set of predefined style-properties of the GTK+ theming system, which define things like the width of the scrollbar. On the other hand, there are the theming possibilities the <tt class="backtick">engines</tt> define. These engine styles are, where most of the theming options are possible. <span class="anchor" id="line-41"></span><span class="anchor" id="line-42"></span><p class="line874">The interesting part about the GTK theming system is that different styles are merged to create the final one. So, you will usually define a base style with all common options in it, and then change colors for a specific widget. <span class="anchor" id="line-43"></span><span class="anchor" id="line-44"></span><p class="line867"> <h3 id="Engines">1.2.3. Engines</h3> <span class="anchor" id="line-45"></span><span class="anchor" id="line-46"></span><p class="line862">As said above engines provide you with many interesting styling options. These options however are engine specific, and if you learned them for one Engine, you will still have to learn the options, other engines provide. Without any engine, GTK uses a <em>very</em> basic theme, that offers only a very boring look (the Raleigh theme does not use an engine). <span class="anchor" id="line-47"></span><span class="anchor" id="line-48"></span><p class="line874">There are many different engines out there, some providing a lot of possibilities, some a very fixed look. An important part of theming GTK+ is to find one or multiple engines on which to base the theme. <span class="anchor" id="line-49"></span><span class="anchor" id="line-50"></span><p class="line867"> <h2 id="The_gtkrc_File">1.3. The gtkrc File</h2> <span class="anchor" id="line-51"></span><span class="anchor" id="line-52"></span><p class="line862">The GTK theme lives inside the gtkrc file. The file format is case- sensitive; comments are marked with a <tt class="backtick">#</tt> (hash). Multiline comments are also possible with the C like <tt class="backtick">/*&nbsp;*/</tt>. <span class="anchor" id="line-53"></span><span class="anchor" id="line-54"></span><p class="line874">A small example follows, that shows how to create very a basic theme. <span class="anchor" id="line-55"></span><span class="anchor" id="line-56"></span><p class="line867"><span class="anchor" id="line-57"></span><span class="anchor" id="line-58"></span><span class="anchor" id="line-59"></span><span class="anchor" id="line-60"></span><span class="anchor" id="line-61"></span><span class="anchor" id="line-62"></span><span class="anchor" id="line-63"></span><span class="anchor" id="line-64"></span><span class="anchor" id="line-65"></span><span class="anchor" id="line-66"></span><span class="anchor" id="line-67"></span><span class="anchor" id="line-68"></span><span class="anchor" id="line-69"></span><span class="anchor" id="line-70"></span><span class="anchor" id="line-71"></span><span class="anchor" id="line-72"></span><span class="anchor" id="line-73"></span><pre><span class="anchor" id="line-1"></span>style "default-style" <span class="anchor" id="line-2"></span>{ <span class="anchor" id="line-3"></span> # modify the x/ythickness, used for spacing all over the place <span class="anchor" id="line-4"></span> xthickness = 3 <span class="anchor" id="line-5"></span> ythickness = 3 <span class="anchor" id="line-6"></span> <span class="anchor" id="line-7"></span> # one can set so called "style properties" <span class="anchor" id="line-8"></span> GtkRange::slider-width = 15 <span class="anchor" id="line-9"></span> <span class="anchor" id="line-10"></span> # set the background to a light grey <span class="anchor" id="line-11"></span> bg[NORMAL] = "#f6f6f6" <span class="anchor" id="line-12"></span> # and the forground to black <span class="anchor" id="line-13"></span> fg[NORMAL] = "#000000" <span class="anchor" id="line-14"></span>} <span class="anchor" id="line-15"></span> <span class="anchor" id="line-16"></span>class "GtkWidget" style "default-style"</pre><span class="anchor" id="line-74"></span><span class="anchor" id="line-75"></span><p class="line874">All, this snippet does, is create a style called "default-style", which then gets applied to all widgets. <span class="anchor" id="line-76"></span><span class="anchor" id="line-77"></span><p class="line874">Lets take a closer look at the different options inside the style. <span class="anchor" id="line-78"></span><span class="anchor" id="line-79"></span><p class="line867"> <h3 id="The_Style">1.3.1. The Style</h3> <span class="anchor" id="line-80"></span><span class="anchor" id="line-81"></span><p class="line874">While the above example style is very small, it gives you an idea of everything that is possible with plain GTK+. <span class="anchor" id="line-82"></span><span class="anchor" id="line-83"></span><p class="line867"> <h4 id="x.2Fythickness">1.3.1.1. x/ythickness</h4> <span class="anchor" id="line-84"></span><span class="anchor" id="line-85"></span><p class="line867"><span class="anchor" id="line-86"></span><span class="anchor" id="line-87"></span><span class="anchor" id="line-88"></span><pre><span class="anchor" id="line-1-1"></span> xthickness = 3 <span class="anchor" id="line-2-1"></span> ythickness = 3</pre><span class="anchor" id="line-89"></span><span class="anchor" id="line-90"></span><p class="line874">This option is used in many places to determine padding between text and border of widgets. For details see the geometry documentation of the specific widgets. <span class="anchor" id="line-91"></span><span class="anchor" id="line-92"></span><p class="line867"> <h4 id="Style_Properties">1.3.1.2. Style Properties</h4> <span class="anchor" id="line-93"></span><span class="anchor" id="line-94"></span><p class="line867"><span class="anchor" id="line-95"></span><span class="anchor" id="line-96"></span><pre><span class="anchor" id="line-1-2"></span> GtkRange::slider-width = 15</pre><span class="anchor" id="line-97"></span><p class="line862">This example sets the "slider-width" style property of <a class="nonexistent" href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkRange.html">/GtkRange</a> to 15 pixel. <span class="anchor" id="line-98"></span><span class="anchor" id="line-99"></span><p class="line862">There are a lot of style properties like this one available within GTK and also some specific to an appalication. They make it possible for you to change the basic behavior of widgets. Please refer to the widget documentation and the autogenerated list of style properties available at <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)StyleProperties.html">/StyleProperties</a>. <span class="anchor" id="line-100"></span><span class="anchor" id="line-101"></span><p class="line874">Style properties are always of the form <span class="anchor" id="line-102"></span><span class="anchor" id="line-103"></span><span class="anchor" id="line-104"></span><pre><span class="anchor" id="line-1-3"></span> WidgetName::style-property-name = VALUE</pre><span class="anchor" id="line-105"></span><p class="line862">The format of the value depends on the type of the style properties. Usually possible values are enumerations from GTK+ like <tt class="backtick">GTK_SHADOW_IN</tt>, integers and color values (same format as below). Note that <tt class="backtick">TRUE</tt> and <tt class="backtick">FALSE</tt> cannot be used in the theme, you can use 1 and 0 instead. (XXX is this OK?) <span class="anchor" id="line-106"></span><span class="anchor" id="line-107"></span><p class="line874">Some examples of style properties: <span class="anchor" id="line-108"></span><div><table><tbody><tr> <td><p class="line862"> <strong>Property</strong> </td> <td><p class="line862"> <strong>Description</strong> </td> <td><p class="line862"> <strong>Example</strong> </td> </tr> <tr> <td><span class="anchor" id="line-109"></span><p class="line862"> <tt class="backtick">GtkWidget::focus-line-width</tt> </td> <td><p class="line862"> Width of the focus line </td> <td><p class="line862"> <tt class="backtick">GtkWidget::focus-line-width&nbsp;=&nbsp;2</tt> </td> </tr> <tr> <td><span class="anchor" id="line-110"></span><p class="line862"> <tt class="backtick">GtkWidget::link-color</tt> </td> <td><p class="line862"> Color of unvisited links, that is supposed to be used by applications </td> <td><p class="line862"> <tt class="backtick">GtkWidget::link-color&nbsp;=&nbsp;"#0000ff"</tt> </td> </tr> <tr> <td><span class="anchor" id="line-111"></span><p class="line862"> ... </td> <td><p class="line862"> </td> <td><p class="line862"> </td> </tr> </tbody></table></div><span class="anchor" id="line-112"></span><span class="anchor" id="line-113"></span><p class="line862">An interesting feature is that you can easily set style properties on subclasses only. So instead of setting <tt class="backtick">GtkRange::trough-side-details</tt> on a style only applied to <tt class="backtick">GtkScale</tt>, you can just set it only on the scale. <span class="anchor" id="line-114"></span><span class="anchor" id="line-115"></span><p class="line867"><span class="anchor" id="line-116"></span><span class="anchor" id="line-117"></span><span class="anchor" id="line-118"></span><span class="anchor" id="line-119"></span><span class="anchor" id="line-120"></span><span class="anchor" id="line-121"></span><pre><span class="anchor" id="line-1-4"></span>style "default" { <span class="anchor" id="line-2-2"></span> GtkScale::trough-side-details = 1 <span class="anchor" id="line-3-1"></span>} <span class="anchor" id="line-4-1"></span> <span class="anchor" id="line-5-1"></span>class "GtkWidget" style "default"</pre><span class="anchor" id="line-122"></span><span class="anchor" id="line-123"></span><p class="line862">This will only affect <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkScale.html">/GtkScale</a>, and not scrollbars. <span class="anchor" id="line-124"></span><span class="anchor" id="line-125"></span><p class="line867"> <h4 id="Colors">1.3.1.3. Colors</h4> <span class="anchor" id="line-126"></span><span class="anchor" id="line-127"></span><p class="line867"><span class="anchor" id="line-128"></span><span class="anchor" id="line-129"></span><pre><span class="anchor" id="line-1-5"></span>bg[NORMAL] = "#f6f6f6"</pre><span class="anchor" id="line-130"></span><span class="anchor" id="line-131"></span><p class="line867"><tt class="backtick">bg</tt> stands for background. There are four valid categories: <span class="anchor" id="line-132"></span><span class="anchor" id="line-133"></span><div><table><tbody><tr> <td><p class="line862"> <strong>Category</strong> </td> <td><p class="line862"> <strong>Usage</strong> </td> </tr> <tr> <td><span class="anchor" id="line-134"></span><p class="line862"> <tt class="backtick">fg</tt> </td> <td><p class="line862"> Foreground color. Used for text on buttons. Also used for the button borders in some engines. </td> </tr> <tr> <td><span class="anchor" id="line-135"></span><p class="line862"> <tt class="backtick">bg</tt> </td> <td><p class="line862"> Background color. This is the background color of windows and buttons. </td> </tr> <tr> <td><span class="anchor" id="line-136"></span><p class="line862"> <tt class="backtick">text</tt> </td> <td><p class="line862"> Text color for text input widgets and lists (<a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)GtkTreeView.html">/GtkTreeView</a>). </td> </tr> <tr> <td><span class="anchor" id="line-137"></span><p class="line862"> <tt class="backtick">base</tt> </td> <td><p class="line862"> Background color of text widgets and lists. </td> </tr> </tbody></table></div><span class="anchor" id="line-138"></span><span class="anchor" id="line-139"></span><p class="line867"><tt class="backtick">NORMAL</tt> is the state the color should be used for. There are five states inside GTK. <span class="anchor" id="line-140"></span><span class="anchor" id="line-141"></span><div><table><tbody><tr> <td><p class="line862"> <strong>State</strong> </td> <td><p class="line862"> <strong>Usage</strong> </td> </tr> <tr> <td><span class="anchor" id="line-142"></span><p class="line862"> <tt class="backtick">NORMAL</tt> </td> <td><p class="line862"> The normal color, nothing special happening. </td> </tr> <tr> <td><span class="anchor" id="line-143"></span><p class="line862"> <tt class="backtick">PRELIGHT</tt> </td> <td><p class="line862"> Prelight means mouse over effects. Usually the background will be slightly lighter. </td> </tr> <tr> <td><span class="anchor" id="line-144"></span><p class="line862"> <tt class="backtick">ACTIVE</tt> </td> <td><p class="line862"> This state is used for buttons while the mouse is pressed. </td> </tr> <tr> <td><span class="anchor" id="line-145"></span><p class="line862"> <tt class="backtick">INSENSITIVE</tt> </td> <td><p class="line862"> Used for widgets that are insensitive and cannot be used at that point. </td> </tr> <tr> <td><span class="anchor" id="line-146"></span><p class="line862"> <tt class="backtick">SELECTED</tt> </td> <td><p class="line862"> This state is used for example for selected text. </td> </tr> </tbody></table></div><span class="anchor" id="line-147"></span><span class="anchor" id="line-148"></span><p class="line874">There are five different ways to describe colors, the most popular is probably the hexadecimal notation used in the example above. The possibilities are <span class="anchor" id="line-149"></span><span class="anchor" id="line-150"></span><div><table><tbody><tr> <td><p class="line862"> hexadecimal </td> <td><p class="line862"> "#RGB", "#RRGGBB", "#RRRGGGBBB" and "#RRRRGGGGBBBB" </td> </tr> <tr> <td><span class="anchor" id="line-151"></span><p class="line862"> floating point </td> <td><p class="line862"> {R, B, G} where R, B and G are floating point numbers between and including 0.0 and 1.0 (That is 1.0 not simply 1 as that will be interpreted as an integer) </td> </tr> <tr> <td><span class="anchor" id="line-152"></span><p class="line862"> integer values </td> <td><p class="line862"> {R, B, G} where R, B and G are values between and including 0 and 65535 </td> </tr> <tr> <td><span class="anchor" id="line-153"></span><p class="line862"> color strings from X </td> <td><p class="line862"> eg. "Red", "Magenta", etc. These are shipped with the X server, and can often be found in /etc/X11/rgb.txt </td> </tr> <tr> <td><span class="anchor" id="line-154"></span><p class="line862"> Symbolic colors and color expressions </td> <td><p class="line862"> For example <tt class="backtick">lighter(@color_name)</tt>. Please see <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkThemes(2f)SymbolicColors.html">/SymbolicColors</a> for details.</td> </tr> </tbody></table></div><span class="anchor" id="line-155"></span><span class="anchor" id="line-156"></span><p class="line867"> <h3 id="Applying_the_Style">1.3.2. Applying the Style</h3> <span class="anchor" id="line-157"></span><span class="anchor" id="line-158"></span><p class="line874">At the top of the snippet we defined a style with some colors. Still GTK needs to know where this style should be used. This is done with the line <span class="anchor" id="line-159"></span><span class="anchor" id="line-160"></span><p class="line867"><span class="anchor" id="line-161"></span><span class="anchor" id="line-162"></span><pre><span class="anchor" id="line-1-6"></span>class "GtkWidget" style "default-style"</pre><span class="anchor" id="line-163"></span><p class="line862">This line applies the style "default-style" to every widget that is based on <tt class="backtick">GtkWidget</tt>. As every widget is based on <tt class="backtick">GtkWidget</tt>, it will be used everywhere. <span class="anchor" id="line-164"></span><span class="anchor" id="line-165"></span><p class="line862">In GTK there are three ways to apply styles. These are the <tt class="backtick">class</tt>, <tt class="backtick">widget_class</tt> and <tt class="backtick">widget</tt> statements. Understanding how styles are applied is a key to understanding the whole of the GTK theming system. A very detailed explanation follows. <span class="anchor" id="line-166"></span><span class="anchor" id="line-167"></span><span class="anchor" id="line-168"></span><p class="line867"> <h4 id="The_different_matching_lines">1.3.2.1. The different matching lines</h4> <span class="anchor" id="line-169"></span><span class="anchor" id="line-170"></span><p class="line867"> <h5 id="class">1.3.2.1.1. class</h5> <span class="anchor" id="line-171"></span><span class="anchor" id="line-172"></span><p class="line862">The <tt class="backtick">class</tt> matches based on the widget class hierarchy (again see <a class="http" href="http://developer.gnome.org/doc/API/2.0/gtk/ch01.html">http://developer.gnome.org/doc/API/2.0/gtk/ch01.html</a>). <span class="anchor" id="line-173"></span><span class="anchor" id="line-174"></span><p class="line862">When finding styles relevant to the current widget, it walks down the widget hierarchy, trying if the widgets class name matches the one in the statement. Lets use the example from above, together with a <tt class="backtick">GtkToggleButton</tt>. <span class="anchor" id="line-175"></span><span class="anchor" id="line-176"></span><p class="line874">It will test the following class names (in this order of importance): <span class="anchor" id="line-177"></span><ul><li><p class="line891"><tt class="backtick">GtkWidget</tt> &lt;- match found here <span class="anchor" id="line-178"></span></li><li><p class="line891"><tt class="backtick">GtkContainer</tt>, no match <span class="anchor" id="line-179"></span></li><li><p class="line891"><tt class="backtick">GtkBin</tt>, no match <span class="anchor" id="line-180"></span></li><li><p class="line891"><tt class="backtick">GtkButton</tt>, no match <span class="anchor" id="line-181"></span></li><li><p class="line891"><tt class="backtick">GtkToggleButton</tt>, no match <span class="anchor" id="line-182"></span><span class="anchor" id="line-183"></span></li></ul><p class="line862">Note that you can not only use class names like <tt class="backtick">GtkWidget</tt> but also expressions like "Gt?T*". A '*' stands for arbitary number of characters and a '?' for exactly one. Both of these will also match the dots in the path. <span class="anchor" id="line-184"></span><span class="anchor" id="line-185"></span><p class="line867"> <h5 id="widget_class_matches">1.3.2.1.2. widget_class matches</h5> <span class="anchor" id="line-186"></span><span class="anchor" id="line-187"></span><p class="line862">Here the nesting of widgets comes into play. Lets assume a simple "Hello World!" application. In this application you have a <tt class="backtick">GtkWindow</tt> that contains a <tt class="backtick">GtkButton</tt> which contains a <tt class="backtick">GtkLabel</tt> with the text "Hello World". <span class="anchor" id="line-188"></span><span class="anchor" id="line-189"></span><p class="line874">Lets look at the following example: <span class="anchor" id="line-190"></span><span class="anchor" id="line-191"></span><p class="line867"><span class="anchor" id="line-192"></span><span class="anchor" id="line-193"></span><pre><span class="anchor" id="line-1-7"></span>widget_class "*.GtkButton.*" style "button-content"</pre><span class="anchor" id="line-194"></span><span class="anchor" id="line-195"></span><div><table><tbody><tr> <td><p class="line862"> </td> <td><p class="line862"> <strong>Classpath</strong> </td> </tr> <tr> <td><span class="anchor" id="line-196"></span><p class="line862"> the window </td> <td><p class="line862"> <tt class="backtick">GtkWindow</tt> </td> </tr> <tr> <td><span class="anchor" id="line-197"></span><p class="line862"> the button inside the window </td> <td><p class="line862"> <tt class="backtick">GtkWidget.GtkButton</tt> </td> </tr> <tr> <td><span class="anchor" id="line-198"></span><p class="line862"> the label inside the button </td> <td><p class="line862"> <tt class="backtick">GtkWidget.GtkButton.GtkLabel</tt> </td> </tr> </tbody></table></div><span class="anchor" id="line-199"></span><span class="anchor" id="line-200"></span><p class="line867"><tt class="backtick">"*.GtkButton.*"</tt> only matches to <tt class="backtick">"GtkWidget.GtkButton.GtkLabel"</tt>, so only the label uses the "button-content" style. But there is a catch, <span class="anchor" id="line-201"></span>if we want "button-content" to also be used for toggle buttons. They usually have look the same way as ordinary buttons. Historically one <span class="anchor" id="line-202"></span>usually would do things like <span class="anchor" id="line-203"></span><span class="anchor" id="line-204"></span><span class="anchor" id="line-205"></span><pre><span class="anchor" id="line-1-8"></span>widget_class "*.*Button.*" style "button-content"</pre><span class="anchor" id="line-206"></span><p class="line862">which will also work for <tt class="backtick">GtkToggleButton</tt>. Since GTK+ 2.10 however there is another way. <span class="anchor" id="line-207"></span><span class="anchor" id="line-208"></span><span class="anchor" id="line-209"></span><pre><span class="anchor" id="line-1-9"></span>widget_class "*.&lt;GtkButton&gt;.*" style "button-content"</pre><span class="anchor" id="line-210"></span><p class="line862">The angle brackets work similar to the class match we had earlier (however without pattern matching). So if there is a <tt class="backtick">GtkToggleButton</tt> GTK will <span class="anchor" id="line-211"></span>notice that it is based on <tt class="backtick">GtkButton</tt> and also apply the style to the label. <span class="anchor" id="line-212"></span><span class="anchor" id="line-213"></span><span class="anchor" id="line-214"></span><p class="line862">If you want to theme specific widgets in applications it can be harder to figure out the different paths. One possible way to do this is to use the eXperience engine and setting <tt class="backtick">EXPERIENCE_PRINT_WIDGET_PATH=TRUE</tt> in the command line. (XXX) <span class="anchor" id="line-215"></span><span class="anchor" id="line-216"></span><span class="anchor" id="line-217"></span><p class="line867"> <h5 id="widget_matches">1.3.2.1.3. widget matches</h5> <span class="anchor" id="line-218"></span><span class="anchor" id="line-219"></span><p class="line867"><tt class="backtick">widget</tt> matches work on the names of the widgets. This is very useful if there is a specific widget in an application that needs to be modified. <span class="anchor" id="line-220"></span>Similar to the <tt class="backtick">widget_class</tt> match, the matching is done against a string of names separated with dots. If one of the widget does not have a name <span class="anchor" id="line-221"></span>the class name will be used instead. <span class="anchor" id="line-222"></span><span class="anchor" id="line-223"></span><p class="line874">So, lets consider the above example. The button is named "my-button" and the window is named "my-app". The label does not have any name set. <span class="anchor" id="line-224"></span><span class="anchor" id="line-225"></span><div><table><tbody><tr> <td><p class="line862"> </td> <td><p class="line862"> <strong>widget path</strong> </td> </tr> <tr> <td><span class="anchor" id="line-226"></span><p class="line862"> the window </td> <td><p class="line862"> <tt class="backtick">my-app</tt> </td> </tr> <tr> <td><span class="anchor" id="line-227"></span><p class="line862"> the button </td> <td><p class="line862"> <tt class="backtick">my-app.my-button</tt> </td> </tr> <tr> <td><span class="anchor" id="line-228"></span><p class="line862"> the label </td> <td><p class="line862"> <tt class="backtick">my-app.my-button.GtkLabel</tt> </td> </tr> </tbody></table></div><span class="anchor" id="line-229"></span><span class="anchor" id="line-230"></span><p class="line874">So if you want to the just the button, you can do something like: <span class="anchor" id="line-231"></span><span class="anchor" id="line-232"></span><span class="anchor" id="line-233"></span><pre><span class="anchor" id="line-1-10"></span>widget "my-app.my-button" style "my-app button fix"</pre><span class="anchor" id="line-234"></span><span class="anchor" id="line-235"></span><span class="anchor" id="line-236"></span><p class="line867"> <h4 id="Order_of_the_Merge">1.3.2.2. Order of the Merge</h4> <span class="anchor" id="line-237"></span><span class="anchor" id="line-238"></span><p class="line862">GTK merges the different "matches" in the order we covered them above. Styles merged in later on override the settings of the earlier ones. This makes sense, as the <tt class="backtick">class</tt> matches are very broad while the <tt class="backtick">widget</tt> match is very specific and often picks out single widgets. The order for <tt class="backtick">widget_class</tt> and <tt class="backtick">widget</tt> matches is simply whatever order is in the file, later ones overriding the previous. <span class="anchor" id="line-239"></span><span class="anchor" id="line-240"></span><p class="line862">For <tt class="backtick">class</tt> matches this is different. GTK gives a higher priority if the matched class is higher up in the hierarchy. Lets take this broken example: <span class="anchor" id="line-241"></span><span class="anchor" id="line-242"></span><p class="line867"><span class="anchor" id="line-243"></span><span class="anchor" id="line-244"></span><span class="anchor" id="line-245"></span><pre><span class="anchor" id="line-1-11"></span>class "*" style "default" <span class="anchor" id="line-2-3"></span>class "GtkButton" style "button"</pre><span class="anchor" id="line-246"></span><span class="anchor" id="line-247"></span><p class="line862">This will work great for normal buttons, but it does not work for toggle buttons. This is because <tt class="backtick">GtkToggleButton</tt> matches against the <tt class="backtick">"*"</tt> with a higher priority than it does against the <tt class="backtick">"GtkButton"</tt> match. The styles are merged as following: <span class="anchor" id="line-248"></span><span class="anchor" id="line-249"></span><div><table><tbody><tr> <td><p class="line862"> <strong>Test against</strong> </td> <td><p class="line862"> <strong>styles merged in</strong> </td> </tr> <tr> <td><span class="anchor" id="line-250"></span><p class="line862"> <tt class="backtick">GtkWidget</tt> </td> <td><p class="line862"> "default" </td> </tr> <tr> <td><span class="anchor" id="line-251"></span><p class="line862"> <tt class="backtick">GtkContainer</tt> </td> <td><p class="line862"> "default" </td> </tr> <tr> <td><span class="anchor" id="line-252"></span><p class="line862"> <tt class="backtick">GtkBin</tt> </td> <td><p class="line862"> "default" </td> </tr> <tr> <td><span class="anchor" id="line-253"></span><p class="line862"> <tt class="backtick">GtkButton</tt> </td> <td><p class="line862"> first "default", then "button" (order in the gtkrc) </td> </tr> <tr> <td><span class="anchor" id="line-254"></span><p class="line862"> <tt class="backtick">GtkToggleButton</tt> </td> <td><p class="line862"> "default" again, which overrides the settings from "button" </td> </tr> </tbody></table></div><span class="anchor" id="line-255"></span><span class="anchor" id="line-256"></span><p class="line862">As you can see the <tt class="backtick">"default"</tt> style is merged in a lot of times. <span class="anchor" id="line-257"></span>So using <tt class="backtick">"*"</tt> to assign a default to every widget is not a good idea as GTK+ will be doing excessive work and you may not get the wanted results. <span class="anchor" id="line-258"></span><span class="anchor" id="line-259"></span><p class="line867"><img alt="{i}" height="16" src="/gnome/gnome-responsive/img/icon-info.png" title="{i}" width="16" /> In reality gtk will also match <tt class="backtick">class</tt> up to <tt class="backtick">GObject</tt>, but this does not make any difference in practice. <span class="anchor" id="line-260"></span><span class="anchor" id="line-261"></span><p class="line867"> <h4 id="Priority">1.3.2.3. Priority</h4> <span class="anchor" id="line-262"></span><span class="anchor" id="line-263"></span><p class="line867"><img alt="/!\" height="16" src="/gnome/gnome-responsive/img/dialog-warning-symbolic.png" title="/!\" width="16" /> The following is here for completeness sake. It is only needed in very seldom cases to override applications settings. Examples for this are the nautilus "more" widget (ie. the thing at the top that is shown in the trash and when burning CDs/DVDs) or to override GIMP settings. <span class="anchor" id="line-264"></span><span class="anchor" id="line-265"></span><p class="line874">It is possible to add a priority to any of the above "matches". <span class="anchor" id="line-266"></span><span class="anchor" id="line-267"></span><span class="anchor" id="line-268"></span><pre><span class="anchor" id="line-1-12"></span>class "SomeWidget" style : PRIORITY "some-style"</pre><span class="anchor" id="line-269"></span><span class="anchor" id="line-270"></span><p class="line874">Where PRIORITY is one of the following, sorted by increasing priority: <span class="anchor" id="line-271"></span><div><table><tbody><tr> <td><p class="line862"> <strong>Priority</strong> </td> <td><p class="line862"> </td> </tr> <tr> <td><span class="anchor" id="line-272"></span><p class="line862"> <tt class="backtick">lowest</tt> </td> <td><p class="line862"> </td> </tr> <tr> <td><span class="anchor" id="line-273"></span><p class="line862"> <tt class="backtick">gtk</tt> </td> <td><p class="line862"> Priority of the built-in theme </td> </tr> <tr> <td><span class="anchor" id="line-274"></span><p class="line862"> <tt class="backtick">application</tt> </td> <td><p class="line862"> dunno what this is for, if application use this they will be overridden by the theme. </td> </tr> <tr> <td><span class="anchor" id="line-275"></span><p class="line862"> <tt class="backtick">theme</tt> </td> <td><p class="line862"> Default priority of themes </td> </tr> <tr> <td><span class="anchor" id="line-276"></span><p class="line862"> <tt class="backtick">rc</tt> </td> <td><p class="line862"> gtkrc files set in the GTK2_RC_FILES environment variable and the standard files <tt class="backtick">~/.gtkrc-2.0</tt> and <tt class="backtick">/etc/gtk-2.0/gtkrc</tt> </td> </tr> <tr> <td><span class="anchor" id="line-277"></span><p class="line862"> <tt class="backtick">highest</tt> </td> <td><p class="line862"> </td> </tr> </tbody></table></div><span class="anchor" id="line-278"></span><span class="anchor" id="line-279"></span><span class="anchor" id="line-280"></span><p class="line867"> <h3 id="Engines-1">1.3.3. Engines</h3> <span class="anchor" id="line-281"></span><span class="anchor" id="line-282"></span><p class="line867"><img alt="/!\" height="16" src="/gnome/gnome-responsive/img/dialog-warning-symbolic.png" title="/!\" width="16" /> Hmm, I am not entirely happy with this section. While I think that there is not much it should cover, this feels like it is too little. <span class="anchor" id="line-283"></span><span class="anchor" id="line-284"></span><p class="line874">As said earlier, engines are used to define the look and extend the styles. For example to use the Clearlooks engine, you can just do the following. <span class="anchor" id="line-285"></span><span class="anchor" id="line-286"></span><span class="anchor" id="line-287"></span><span class="anchor" id="line-288"></span><span class="anchor" id="line-289"></span><span class="anchor" id="line-290"></span><span class="anchor" id="line-291"></span><pre><span class="anchor" id="line-1-13"></span>style "some-style" { <span class="anchor" id="line-2-4"></span> engine "clearlooks" { <span class="anchor" id="line-3-2"></span> # engine specific settings go here <span class="anchor" id="line-4-2"></span> } <span class="anchor" id="line-5-2"></span>}</pre><span class="anchor" id="line-292"></span><p class="line862">This means the Clearlooks engine will be used with its default settings. You can modify engine settings in the block. For a description of the possible options for different engines please refere to their documentation at <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)GtkEngines.html">../GtkEngines</a>. <span class="anchor" id="line-293"></span><span class="anchor" id="line-294"></span><span class="anchor" id="line-295"></span><p class="line867"> <h2 id="Tips">1.4. Tips</h2> <span class="anchor" id="line-296"></span><span class="anchor" id="line-297"></span><p class="line862">There are some preview applications like "The Widget Factory" available. Have a look at <a href="./Attic(2f)GnomeArt(2f)Tutorials(2f)UsefulLinks.html">../UsefulLinks</a>. <span class="anchor" id="line-298"></span><span class="anchor" id="line-299"></span><p class="line862">You can split the <tt class="backtick">gtkrc</tt> file into multiple files by using the <tt class="backtick">include</tt> option. So you could do an extra file just for button styles called <tt class="backtick">button-styles</tt> and simply include that. <span class="anchor" id="line-300"></span><span class="anchor" id="line-301"></span><span class="anchor" id="line-302"></span><span class="anchor" id="line-303"></span><pre><span class="anchor" id="line-1-14"></span># include the button-styles file <span class="anchor" id="line-2-5"></span>include "button-styles"</pre><span class="anchor" id="line-304"></span><span class="anchor" id="line-305"></span><div><table><tbody><tr> <td style="width: 30%; text-align: center; background-color: #eaeaea"><p class="line862"> <strong><a class="nonexistent" href="./GnomeArt(2f)Tutorials(2f)IconThemes.html">Previous chapter: Icon Themes</a></strong> </td> <td style="width: 40%; text-align: center; background-color: #eaeaea"><p class="line862"> <strong><a class="nonexistent" href="./GnomeArt(3a2f)InterWiki.html">Back to Tutorial start page</a></strong> </td> <td style="width: 30%; text-align: center; background-color: #eaeaea"><p class="line862"> <strong><a class="nonexistent" href="./GnomeArt(2f)Tutorials(2f)GdmThemes.html">Next chapter: GDM Themes</a></strong> </td> </tr> </tbody></table></div><span class="anchor" id="line-306"></span><span class="anchor" id="line-307"></span><span class="anchor" id="line-308"></span><p class="line867"> <h2 id="Check_List">1.5. Check List</h2> <span class="anchor" id="line-309"></span><span class="anchor" id="line-310"></span><p class="line867"> <h3 id="Engine">1.5.1. Engine</h3> <span class="anchor" id="line-311"></span><span class="anchor" id="line-312"></span><ul><li>Have a good GTK+ hacker give a once-over look at the theme engine's code. Is it sane? Does it do anything obviously stupid? Does it leak cairo contexts, GCs, pixmaps, regions, etc.? <span class="anchor" id="line-313"></span><span class="anchor" id="line-314"></span></li><li class="gap"><p class="line862">Check the implementation of the <a class="nonexistent" href="./GtkStyleClass.html">GtkStyleClass</a> virtual methods. Do they handle the "detail" argument correctly (null detail, unexpected string in detail)? Do they handle the "widget" argument correctly (may be null as well)? What happens if you draw very small elements (2x2 pixel boxes, 0x0 pixel boxes, etc.)? <span class="anchor" id="line-315"></span><span class="anchor" id="line-316"></span><ul><li>gtk-engines has a "torture test" application. This program basically brute forces almost all code paths in an engine. <span class="anchor" id="line-317"></span><span class="anchor" id="line-318"></span></li></ul></li></ul><p class="line867"> <h3 id="Theme">1.5.2. Theme</h3> <span class="anchor" id="line-319"></span><span class="anchor" id="line-320"></span><ul><li><p class="line862">Check that all the core desktop applications look correct with the theme. "Look correct" means, for example, that there are no sharp/ugly transitions in gradient backgrounds; this may be a bug in the app's widget structure. At least checking for this will help in finding bugs <em>somewhere</em>. <span class="anchor" id="line-321"></span><span class="anchor" id="line-322"></span></li><li class="gap">Check applications that do funny stuff with widgets. Check the tool bars in Evolution and its message composer; those go through libbonoboui, not GTK+, and this has been known to cause problems with gradient-y themes. <span class="anchor" id="line-323"></span><span class="anchor" id="line-324"></span></li><li class="gap">Check that flipped widgets in RTL locales are correctly drawn. <span class="anchor" id="line-325"></span><span class="anchor" id="line-326"></span></li><li class="gap"><p class="line862">Check that foreign tool kits using gtk engines for rendering work with your engine. The big applications to try this are <a class="nonexistent" href="./OpenOffice.html">OpenOffice</a> and Firefox. <span class="anchor" id="line-327"></span><span class="anchor" id="line-328"></span></li><li class="gap">Does the theme have enough contrast on low grade laptop displays? Industrial has problems with this, for example. <span class="anchor" id="line-329"></span><span class="anchor" id="line-330"></span></li><li class="gap"><p class="line862">Does the theme look correct if one increases and decreases the font size? (In addition to text readability, take note of Menu and <a class="nonexistent" href="./SpinButton.html">SpinButton</a> arrows, which change according to font size.) <span class="anchor" id="line-331"></span><span class="anchor" id="line-332"></span></li><li class="gap">Does the theme have acceptable performance on low-end machines? This is difficult to test, but have someone try it on a low-memory machine equipped with an Intel Pentium II processor. <span class="anchor" id="line-333"></span></li></ul><span class="anchor" id="bottom"></span></div> </div> <hr> 2024-10-23 10:58 </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10