Writing Patterns
Patterns are the core of Gtheme’s theming system. This guide walks you through creating a pattern from an existing configuration file.
Step by step
Let’s say you want to theme your kitty terminal. Here’s how to turn a static config into a Gtheme pattern.
-
Start with the original config
Take the color-related section of your config file. For kitty, that might be:
foreground #f8f8f2background #1e1f28color0 #000000color1 #ff5555 -
Replace hardcoded colors with placeholders
Swap each hex value with the corresponding Gtheme variable:
foreground #<[foreground]>background #<[background]>color0 #<[black]>color1 #<[red]> -
Add the output-file directive
Add a line at the very top specifying where the filled file should be written:
<[output-file]>=~/.config/kitty/colors.conf -
Add user settings with fallbacks (optional)
For values that vary per user (like fonts), use user settings with a fallback:
font_family <[default-font|JetBrains Mono]>font_size <[default-font-size|12]> -
Save the pattern
Save the file as
kitty.patternin your desktop’sgtheme/patterns/directory. -
Enable it
Add
"kitty": trueto theactivedsection ofdesktop_config.json, or run:Terminal window gtheme pattern enable kitty -
Test it
Terminal window gtheme theme apply DraculaCheck that
~/.config/kitty/colors.confwas generated with the Dracula colors.
Real-world examples
CSS colors (Waybar)
For CSS-based configs, you might generate CSS custom properties:
<[output-file]>=~/.config/waybar/colors/colors.css@define-color background #<[background]>;@define-color on_background #<[foreground]>;@define-color primary #<[blue]>;@define-color secondary #<[cyan]>;@define-color error #<[red]>;Hyprland variables
For Hyprland, colors use the rgba() format:
<[output-file]>=~/.config/hypr/colors/colors.conf$primary = rgba(<[blue]>ff)$on_primary = rgba(<[background]>ff)$surface = rgba(<[background]>ff)$on_surface = rgba(<[foreground]>ff)Rasi format (Rofi)
<[output-file]>=~/.config/rofi/colors.rasi* { primary: #<[blue]>; surface: #<[background]>; on-surface: #<[foreground]>;}Adding a post-script
If the application doesn’t auto-reload when its config changes, create a post-script with the same name. For kitty:
#!/bin/bashpkill -USR1 kittyexit 0Make it executable:
chmod +x gtheme/post-scripts/kitty.shPattern modules
For applications with multiple config files (like Spotify with Spicetify), create a directory:
patterns/└── spotify/ ├── spotify-colors.pattern └── spotify-theme.patternThe module name is spotify. Enabling/disabling it affects both sub-patterns.
Tips
- Check existing patterns — browse the gtheme-desktops repository for real examples.
- Only template what changes — don’t put your entire config in a pattern. Only include the color-related portions. Use
@import,source, orincludedirectives in the main config to pull in the generated color file. - Use comments — add
<[theme-name]>in a comment at the top so you can tell which theme generated the file. - Test with contrasting themes — try a light theme (like
One-Light) and a dark theme (likeDracula) to make sure your pattern works well with both.