gnome-tweak-tool: Add patches to work nicely on NixOS

- Search for themes and icon in system data dirs
- Don't show multiple entries for a single theme
- Create config dir if it doesn't exist
This commit is contained in:
Jascha Geerds 2015-08-02 12:19:06 +02:00
parent 5210b4c7a8
commit c6f5bb5785
4 changed files with 262 additions and 2 deletions

View File

@ -0,0 +1,123 @@
From 175218579aa2b4f4974ff1cf4fd1ac93082a4714 Mon Sep 17 00:00:00 2001
From: Jascha Geerds <jg@ekby.de>
Date: Sat, 1 Aug 2015 21:01:11 +0200
Subject: [PATCH 1/1] Search for themes and icons in system data dirs
---
gtweak/tweaks/tweak_group_interface.py | 17 ++++-------------
gtweak/tweaks/tweak_group_keymouse.py | 7 ++-----
gtweak/utils.py | 17 +++++++++++++++++
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/gtweak/tweaks/tweak_group_interface.py b/gtweak/tweaks/tweak_group_interface.py
index ed2ad5f..a319907 100644
--- a/gtweak/tweaks/tweak_group_interface.py
+++ b/gtweak/tweaks/tweak_group_interface.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, TWEAK_GROUP_APPEARANCE
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.gsettings import GSettingsSetting
@@ -46,10 +46,7 @@ class GtkThemeSwitcher(GSettingsComboTweak):
def _get_valid_themes(self):
""" Only shows themes that have variations for gtk+-3 and gtk+-2 """
- 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")))
return valid
@@ -64,10 +61,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
@@ -82,10 +76,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/tweaks/tweak_group_keymouse.py b/gtweak/tweaks/tweak_group_keymouse.py
index b56a4f4..3486098 100644
--- a/gtweak/tweaks/tweak_group_keymouse.py
+++ b/gtweak/tweaks/tweak_group_keymouse.py
@@ -20,7 +20,7 @@ import os.path
from gi.repository import GLib
import gtweak
-from gtweak.utils import XSettingsOverrides, walk_directories, make_combo_list_with_default
+from gtweak.utils import XSettingsOverrides, walk_directories, make_combo_list_with_default, get_resource_dirs
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboTweak, GSettingsSwitchTweak, GetterSetterSwitchTweak, Title
class PrimaryPasteTweak(GetterSetterSwitchTweak):
@@ -47,10 +47,7 @@ class KeyThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_key_themes(self):
- 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.isfile(os.path.join(d, "gtk-3.0", "gtk-keys.css")) and \
os.path.isfile(os.path.join(d, "gtk-2.0-key", "gtkrc")))
return valid
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 3d20425..0fcb51d 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
@@ -114,6 +115,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.4.5

View File

@ -0,0 +1,103 @@
From edd3203c7b7d5ba596df9f148c443cdfc8a58d88 Mon Sep 17 00:00:00 2001
From: Jascha Geerds <jg@ekby.de>
Date: Sat, 1 Aug 2015 21:26:57 +0200
Subject: [PATCH 1/1] Don't show multiple entries for a single theme
---
gtweak/tweaks/tweak_group_interface.py | 8 ++++----
gtweak/tweaks/tweak_group_keymouse.py | 4 ++--
gtweak/utils.py | 16 ++++++++++++++++
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/gtweak/tweaks/tweak_group_interface.py b/gtweak/tweaks/tweak_group_interface.py
index a319907..82c0286 100644
--- a/gtweak/tweaks/tweak_group_interface.py
+++ b/gtweak/tweaks/tweak_group_interface.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, get_resource_dirs
+from gtweak.utils import walk_directories, make_combo_list_with_default, extract_zip_file, get_resource_dirs, get_unique_resources
from gtweak.tweakmodel import Tweak, TWEAK_GROUP_APPEARANCE
from gtweak.gshellwrapper import GnomeShellFactory
from gtweak.gsettings import GSettingsSetting
@@ -49,7 +49,7 @@ class GtkThemeSwitcher(GSettingsComboTweak):
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")))
- return valid
+ return get_unique_resources(valid)
class IconThemeSwitcher(GSettingsComboTweak):
def __init__(self, **options):
@@ -64,7 +64,7 @@ class IconThemeSwitcher(GSettingsComboTweak):
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
+ return get_unique_resources(valid)
class CursorThemeSwitcher(GSettingsComboTweak):
def __init__(self, **options):
@@ -79,7 +79,7 @@ class CursorThemeSwitcher(GSettingsComboTweak):
valid = walk_directories(get_resource_dirs("icons"), lambda d:
os.path.isdir(d) and \
os.path.exists(os.path.join(d, "cursors")))
- return valid
+ return get_unique_resources(valid)
class ShellThemeTweak(Gtk.Box, Tweak):
diff --git a/gtweak/tweaks/tweak_group_keymouse.py b/gtweak/tweaks/tweak_group_keymouse.py
index 3486098..9f53425 100644
--- a/gtweak/tweaks/tweak_group_keymouse.py
+++ b/gtweak/tweaks/tweak_group_keymouse.py
@@ -20,7 +20,7 @@ import os.path
from gi.repository import GLib
import gtweak
-from gtweak.utils import XSettingsOverrides, walk_directories, make_combo_list_with_default, get_resource_dirs
+from gtweak.utils import XSettingsOverrides, walk_directories, make_combo_list_with_default, get_resource_dirs, get_unique_resources
from gtweak.widgets import ListBoxTweakGroup, GSettingsComboTweak, GSettingsSwitchTweak, GetterSetterSwitchTweak, Title
class PrimaryPasteTweak(GetterSetterSwitchTweak):
@@ -50,7 +50,7 @@ class KeyThemeSwitcher(GSettingsComboTweak):
valid = walk_directories(get_resource_dirs("themes"), lambda d:
os.path.isfile(os.path.join(d, "gtk-3.0", "gtk-keys.css")) and \
os.path.isfile(os.path.join(d, "gtk-2.0-key", "gtkrc")))
- return valid
+ return get_unique_resources(valid)
TWEAK_GROUPS = [
ListBoxTweakGroup(_("Keyboard and Mouse"),
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 0fcb51d..ce8e12e 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -131,6 +131,22 @@ def get_resource_dirs(resource):
return [dir for dir in dirs if os.path.isdir(dir)]
+def get_unique_resources(dirs):
+ """Filter out duplicated resources.
+
+ :param list dirs:
+ List of resource dirs (e.g. /usr/share/themes/Adwaita)
+ :return:
+ List of dirs without duplicated resources
+ """
+ unique_dirs = {}
+ for dir in dirs:
+ basename = os.path.basename(dir)
+ if basename not in unique_dirs:
+ unique_dirs[basename] = dir
+
+ return unique_dirs
+
@singleton
class AutostartManager:
--
2.4.5

View File

@ -0,0 +1,29 @@
From dea8fc3c37c43f4fbbcc658ee995a95b93452b3c Mon Sep 17 00:00:00 2001
From: Jascha Geerds <jg@ekby.de>
Date: Sun, 2 Aug 2015 12:01:20 +0200
Subject: [PATCH 1/1] Create config dir if it doesn't exist
Otherwise gnome-tweak-tool can't enable the dark theme and fails
without a clear error message.
---
gtweak/gtksettings.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gtweak/gtksettings.py b/gtweak/gtksettings.py
index bcec9f1..f39991b 100644
--- a/gtweak/gtksettings.py
+++ b/gtweak/gtksettings.py
@@ -35,6 +35,10 @@ class GtkSettingsManager:
def _get_keyfile(self):
keyfile = None
try:
+ config_dir = os.path.dirname(self._path)
+ if not os.path.isdir(config_dir):
+ os.makedirs(config_dir)
+
keyfile = GLib.KeyFile()
keyfile.load_from_file(self._path, 0)
except MemoryError:
--
2.4.5

View File

@ -28,12 +28,17 @@ stdenv.mkDerivation rec {
preFixup = ''
wrapProgram "$out/bin/gnome-tweak-tool" \
--set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE" \
--prefix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
--suffix XDG_DATA_DIRS : "${gtk3}/share:${gnome3.gnome_themes_standard}/share:$out/share:$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH" \
--prefix GI_TYPELIB_PATH : "$GI_TYPELIB_PATH" \
--prefix PYTHONPATH : "$PYTHONPATH:$(toPythonPath $out)"
'';
patches = [ ./find_gsettings.patch ];
patches = [
./find_gsettings.patch
./0001-Search-for-themes-and-icons-in-system-data-dirs.patch
./0002-Don-t-show-multiple-entries-for-a-single-theme.patch
./0003-Create-config-dir-if-it-doesn-t-exist.patch
];
meta = with stdenv.lib; {
homepage = https://wiki.gnome.org/action/show/Apps/GnomeTweakTool;