Skip to content

Commit

Permalink
Support GNOME and Cinnamon
Browse files Browse the repository at this point in the history
  • Loading branch information
ALEX11BR committed Oct 5, 2021
1 parent 19184d3 commit 00e7622
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It also lets the user install icon and widget theme archives.
- Set the cursor theme, and tweak the cursor's size
- Set all these themes with a special searchable selector with previews for GTK3, icon and cursor themes
- Set various options like whether buttons have images or not
- Instantaneously apply your setting changes to the running applications using [xsettingsd](https://github.com/derat/xsettingsd) (you must download xsettingsd and run it in the background)
- Instantaneously apply your setting changes to the running applications in GNOME, Cinnamon, or using [xsettingsd](https://github.com/derat/xsettingsd) (you must download xsettingsd and run it in the background) for those that don't use GTK desktop environments
- Edit GTK CSS with instantaneous feedback of the changes made
- Install new widget or icon themes from archives available e.g. at https://gnome-look.org

Expand All @@ -32,7 +32,7 @@ In the folder with the source (obtainable e.g. by running `git clone https://git

# TODOs
- Add more advanced Kvantum support (e.g. handling of the Kvantum theme names, which oftentimes don't match the GTK theme names, or syncing some options)
- Implement live reloading for other XSETTINGS-compatible daemons.
- Implement live reloading for other desktop environments / XSETTINGS-compatible daemons.
- Add more options to set (see [further reference](https://developer.gnome.org/gtk3/stable/GtkSettings.html))
- Add theme remover
- Add a client for OCS-compatible websites like gnome-look.org, tailored for downloading (and automatically installing) themes (see [API reference]() and [a reference project](https://www.opencode.net/dfn2/pling-store-development))
Expand Down
60 changes: 57 additions & 3 deletions src/applythemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
import subprocess

from gi.repository import GLib
from gi.repository import GLib, Gio

class BaseApplyThemes:
def applyThemes(self, props, gtk2Theme, gtk4Theme, kvantumTheme, cssText):
Expand Down Expand Up @@ -79,7 +79,53 @@ def applyThemes(self, props, gtk2Theme, gtk4Theme, kvantumTheme, cssText):
with open(os.path.join(GLib.get_user_config_dir(), "gtk-4.0", "gtk.css"), "w") as cssFile:
cssFile.write(cssText)

class GSettingsApplyThemes(BaseApplyThemes):
def applyThemes(self, props, **kwargs):
super().applyThemes(props, **kwargs)

self.settings.set_string("gtk-theme", props.gtk_theme_name)
self.settings.set_string("icon-theme", props.gtk_icon_theme_name)
self.settings.set_string("cursor-theme", props.gtk_cursor_theme_name or "")
self.settings.set_int("cursor-size", props.gtk_cursor_theme_size)
self.settings.set_string("gtk-key-theme", props.gtk_key_theme_name or "")
self.settings.set_string("font-name", props.gtk_font_name)
self.settings.set_double("text-scaling-factor", props.gtk_xft_dpi/(96*1024))

class GnomeApplyThemes(GSettingsApplyThemes):
def __init__(self):
self.settings = Gio.Settings.new("org.gnome.desktop.interface")

def applyThemes(self, props, **kwargs):
super().applyThemes(props, **kwargs)

if props.gtk_xft_rgba != "none":
self.settings.set_string("font-rgba-order", props.gtk_xft_rgba or "rgb")
self.settings.set_string("font-antialiasing", "rgba" if props.gtk_xft_antialias else "none")
else:
self.settings.set_string("font-antialiasing", "grayscale" if props.gtk_xft_antialias else "none")
self.settings.set_string("font-hinting", props.gtk_xft_hintstyle[4:]) # drop the first 4 letters ('hint' in all cases)

self.settings.set_boolean("overlay-scrolling", props.gtk_overlay_scrolling)

class CinnamonApplyThemes(GSettingsApplyThemes):
def __init__(self):
self.settings = Gio.Settings.new("org.cinnamon.desktop.interface")
self.settingsFont = Gio.Settings.new("org.cinnamon.settings-daemon.plugins.xsettings")

def applyThemes(self, props, **kwargs):
super().applyThemes(props, **kwargs)

if props.gtk_xft_rgba != "none":
self.settingsFont.set_string("rgba-order", props.gtk_xft_rgba)
self.settingsFont.set_string("antialiasing", "rgba" if props.gtk_xft_antialias else "none")
else:
self.settingsFont.set_string("antialiasing", "grayscale" if props.gtk_xft_antialias else "none")
self.settingsFont.set_string("hinting", props.gtk_xft_hintstyle[4:]) # drop the first 4 letters ('hint' in all cases)

self.settings.set_boolean("gtk-overlay-scrollbars", props.gtk_overlay_scrolling)
self.settings.set_boolean("buttons-have-icons", props.gtk_button_images)
self.settings.set_boolean("menus-have-icons", props.gtk_menu_images)

class XsettingsdApplyThemes(BaseApplyThemes):
def __init__(self):
self.confFolder = os.path.join(GLib.get_user_config_dir(), "xsettingsd")
Expand All @@ -100,9 +146,10 @@ def applyThemes(self, props, **kwargs):
"Xft/HintStyle": f'"{props.gtk_xft_hintstyle or "hintnone"}"',
"Xft/RGBA": f'"{props.gtk_xft_rgba or "none"}"',
"Xft/DPI": props.gtk_xft_dpi,
"Gtk/CursorThemeName": f'"{props.gtk_cursor_theme_name or "default"}"',
"Gtk/CursorThemeName": f'"{props.gtk_cursor_theme_name or ""}"',
"Gtk/FontName": f'"{props.gtk_font_name}"',
"Gtk/KeyThemeName": f'"{props.gtk_key_theme_name or ""}"',
"Gtk/OverlayScrolling": int(props.gtk_overlay_scrolling),
"Gtk/MenuImages": int(props.gtk_menu_images),
"Gtk/ButtonImages": int(props.gtk_button_images),
}
Expand All @@ -113,8 +160,15 @@ def applyThemes(self, props, **kwargs):

subprocess.run(["pkill", "-HUP", "^xsettingsd$"])

def isRunning(app):
return subprocess.call(["pidof", app], stdout=subprocess.DEVNULL) == 0

def getThemeApplier():
if subprocess.call(["pidof", "xsettingsd"], stdout=subprocess.DEVNULL) == 0:
if isRunning("gsd-xsettings"):
return GnomeApplyThemes()
elif isRunning("csd-xsettings"):
return CinnamonApplyThemes()
elif isRunning("xsettingsd"):
return XsettingsdApplyThemes()
else:
return BaseApplyThemes()
2 changes: 1 addition & 1 deletion src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Live theme reloading detected. Setting another theme for GTK2 or GTK4 won't have any effect.</property>
<property name="label" translatable="yes">Instantaneous theme changing is supported. This means that setting another theme for GTK2 or GTK4 won't have any effect.</property>
<property name="wrap">True</property>
</object>
<packing>
Expand Down

0 comments on commit 00e7622

Please sign in to comment.