nixpkgs/pkgs/desktops/gnome-3/misc/gnome-tweak-tool/0001-Search-for-themes-and-icons-in-system-data-dirs.patch
2017-11-26 03:10:49 +01:00

98 lines
3.9 KiB
Diff

From f7f7fe6bf36ca08c66192077bf964036eb02ffb5 Mon Sep 17 00:00:00 2001
From: Jascha Geerds <jascha@jgeerds.name>
Date: Tue, 19 Sep 2017 03:08:07 +0200
Subject: [PATCH 1/3] Search for themes and icons in system data dirs
---
gtweak/tweaks/tweak_group_appearance.py | 17 ++++-------------
gtweak/utils.py | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/gtweak/tweaks/tweak_group_appearance.py b/gtweak/tweaks/tweak_group_appearance.py
index ccadefc..0d12194 100644
--- a/gtweak/tweaks/tweak_group_appearance.py
+++ b/gtweak/tweaks/tweak_group_appearance.py
@@ -26,7 +26,7 @@ from gi.repository import Gtk
from gi.repository import GLib
import gtweak
-from gtweak.utils import walk_directories, make_combo_list_with_default, extract_zip_file
+from gtweak.utils import walk_directories, make_combo_list_with_default, extract_zip_file, get_resource_dirs
from gtweak.tweakmodel import Tweak
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.gsettings import GSettingsSetting
@@ -50,10 +50,7 @@ class GtkThemeSwitcher(GSettingsComboTweak):
if gtk_ver % 2: # Want even number
gtk_ver += 1
- dirs = ( os.path.join(gtweak.DATA_DIR, "themes"),
- os.path.join(GLib.get_user_data_dir(), "themes"),
- os.path.join(os.path.expanduser("~"), ".themes"))
- valid = walk_directories(dirs, lambda d:
+ valid = walk_directories(get_resource_dirs("themes"), lambda d:
os.path.exists(os.path.join(d, "gtk-2.0")) and \
(os.path.exists(os.path.join(d, "gtk-3.0")) or \
os.path.exists(os.path.join(d, "gtk-3.{}".format(gtk_ver)))))
@@ -69,10 +66,7 @@ class IconThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_icon_themes(self):
- dirs = ( os.path.join(gtweak.DATA_DIR, "icons"),
- os.path.join(GLib.get_user_data_dir(), "icons"),
- os.path.join(os.path.expanduser("~"), ".icons"))
- valid = walk_directories(dirs, lambda d:
+ valid = walk_directories(get_resource_dirs("icons"), lambda d:
os.path.isdir(d) and \
os.path.exists(os.path.join(d, "index.theme")))
return valid
@@ -87,10 +81,7 @@ class CursorThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_cursor_themes(self):
- dirs = ( os.path.join(gtweak.DATA_DIR, "icons"),
- os.path.join(GLib.get_user_data_dir(), "icons"),
- os.path.join(os.path.expanduser("~"), ".icons"))
- valid = walk_directories(dirs, lambda d:
+ valid = walk_directories(get_resource_dirs("icons"), lambda d:
os.path.isdir(d) and \
os.path.exists(os.path.join(d, "cursors")))
return valid
diff --git a/gtweak/utils.py b/gtweak/utils.py
index de6c345..6c60b88 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -21,6 +21,7 @@ import tempfile
import shutil
import subprocess
import glob
+import itertools
import gtweak
from gtweak.gsettings import GSettingsSetting
@@ -117,6 +118,22 @@ def execute_subprocess(cmd_then_args, block=True):
stdout, stderr = p.communicate()
return stdout, stderr, p.returncode
+def get_resource_dirs(resource):
+ """Returns a list of all known resource dirs for a given resource.
+
+ :param str resource:
+ Name of the resource (e.g. "themes")
+ :return:
+ A list of resource dirs
+ """
+ dirs = [os.path.join(dir, resource)
+ for dir in itertools.chain(GLib.get_system_data_dirs(),
+ (gtweak.DATA_DIR,
+ GLib.get_user_data_dir()))]
+ dirs += [os.path.join(os.path.expanduser("~"), ".{}".format(resource))]
+
+ return [dir for dir in dirs if os.path.isdir(dir)]
+
@singleton
class AutostartManager:
--
2.14.1