Skip to content

Commit

Permalink
Respect $GTK2_RC_FILES when writing themes
Browse files Browse the repository at this point in the history
`GTK2_RC_FILES` is an environment variable containing a colon seperated
list of RC files that are used to theme GTK2 applications. This patch
will write GTK2 theming to the first file in this list, if present,
rather than ~/.gtkrc-2.0.
  • Loading branch information
RossBrunton committed Sep 26, 2024
1 parent a312d61 commit fb2cd90
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ def on_overlay_scrollbars_changed(self, settings, key, data=None):

class Gtk2ScrollbarSizeEditor:
def __init__(self, ui_scale):
self._path = os.path.join(GLib.get_home_dir(), ".gtkrc-2.0")
rcpath = GLib.getenv("GTK2_RC_FILES")
if rcpath is None or rcpath == "":
self._path = os.path.join(GLib.get_home_dir(), ".gtkrc-2.0")
else:
self._path = rcpath.split(":")[0]
self._file = Gio.File.new_for_path(self._path)
self._settings = Gio.Settings(schema_id="org.cinnamon.theme")
self.ui_scale = ui_scale
Expand All @@ -425,7 +429,7 @@ def __init__(self, ui_scale):
if e.code == Gio.IOErrorEnum.NOT_FOUND:
pass
else:
print("Could not load ~/.gtkrc-2.0 file: %s" % e.message)
print("Could not load .gtkrc-2.0 file: %s" % e.message)

self.parse_contents()

Expand All @@ -450,6 +454,9 @@ def on_set_size_timeout(self, size):
# print("saving changed: ", final_contents)

try:
# If a path is specified through GTK2_RC_FILES, ensure it exists
if not self._file.get_parent().query_exists():
self._file.get_parent().make_directory_with_parents()
self._file.replace_contents(final_contents.encode("utf-8"),
None,
False,
Expand Down

0 comments on commit fb2cd90

Please sign in to comment.