Re: [Nix-dev] Easier GTK theming

2017-04-23 Thread Jookia
On Sun, Apr 23, 2017 at 07:09:43AM -0700, William Casarin wrote:
> ...
> 
> Thoughts? Has there been progress down these lines before?

Well I got a patch in to GTK3 to read themes from XDG_DATA_PATH (or something
like that) so installed themes should just work. GTK2 has a patch, but it's not
upstream. Here it is:
commit 0df8a7c7ba26f368f01ada4233dedc4193cdbebf
Author: Jookia <166...@gmail.com>
Date:   Sat Apr 8 20:16:54 2017 +1000

gtk2: Patch theme paths

diff --git a/pkgs/development/libraries/gtk+/2.x.nix 
b/pkgs/development/libraries/gtk+/2.x.nix
index 306e2db..f6e718d 100644
--- a/pkgs/development/libraries/gtk+/2.x.nix
+++ b/pkgs/development/libraries/gtk+/2.x.nix
@@ -30,7 +30,7 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ setupHook perl pkgconfig gettext ];
 
-  patches = [ ./2.0-immodules.cache.patch ];
+  patches = [ ./2.0-immodules.cache.patch ./gtk2-theme-paths.patch ];
 
   propagatedBuildInputs = with xorg;
 [ glib cairo pango gdk_pixbuf atk ]
diff --git a/pkgs/development/libraries/gtk+/gtk2-theme-paths.patch 
b/pkgs/development/libraries/gtk+/gtk2-theme-paths.patch
new file mode 100644
index 000..397cc97
--- /dev/null
+++ b/pkgs/development/libraries/gtk+/gtk2-theme-paths.patch
@@ -0,0 +1,35 @@
+diff -Naur gtk+-2.24.28.new/gtk/gtkrc.c gtk+-2.24.28/gtk/gtkrc.c
+--- gtk+-2.24.28.new/gtk/gtkrc.c   2016-03-13 10:31:14.413644362 +1100
 gtk+-2.24.28/gtk/gtkrc.c   2016-03-13 12:51:34.723398423 +1100
+@@ -808,6 +808,8 @@
+   gchar *path = NULL;
+   const gchar *home_dir;
+   gchar *subpath;
++  const gchar * const *xdg_data_dirs;
++  gint i;
+ 
+   if (type)
+ subpath = g_strconcat ("gtk-2.0-", type,
+@@ -830,6 +832,22 @@
+ }
+ 
+   if (!path)
++{
++  xdg_data_dirs = g_get_system_data_dirs ();
++  for (i = 0; xdg_data_dirs[i]; i++)
++{
++  path = g_build_filename (xdg_data_dirs[i], "themes", name, subpath, 
NULL);
++  if (g_file_test (path, G_FILE_TEST_EXISTS))
++break;
++  else
++{
++  g_free (path);
++  path = NULL;
++}
++}
++}
++
++  if (!path)
+ {
+   gchar *theme_dir = gtk_rc_get_theme_dir ();
+   path = g_build_filename (theme_dir, name, subpath, NULL);
___
nix-dev mailing list
nix-dev@lists.science.uu.nl
https://mailman.science.uu.nl/mailman/listinfo/nix-dev


[Nix-dev] Easier GTK theming

2017-04-23 Thread William Casarin

I've been talking to NixOS newcomers and a simple pain point that they
are running into is with GTK themes. This makes sense as I have run into
the same pain points:

To get GTK themes working, I have something like this in my
nixos-config:

  { config, lib, pkgs, ... }:
  let gtk2rc = pkgs.writeText "gtk2rc" ''
gtk-icon-theme-name = "${icon-theme.name}"
gtk-theme-name = "${theme.name}"
  '';
  theme = {
package = pkgs.theme-vertex;
name = "Vertex-Dark";
  };
  icon-theme = {
package = pkgs.numix-icon-theme;
name = "Numix";
  };
  in {

# I have no idea what is actually needed here, this was just me trying
# a bunch of different things
environment.variables = {
  GDK_PIXBUF_MODULE_FILE = 
"${pkgs.librsvg.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache";
  GTK2_RC_FILES = 
"${gtk2rc}:${theme.package}/share/themes/${theme.name}/gtk-2.0/gtkrc:$GTK2_RC_FILES";
  GTK_DATA_PREFIX = "${theme.package}";
  GTK_EXEC_PREFIX = "${theme.package}";
  GTK_IM_MODULE = "xim";
  GTK_PATH = "${theme.package}:${pkgs.gtk3.out}";
  GTK_THEME = "${theme.name}";
  LC_TIME="en_DK.UTF-8";
  QT_STYLE_OVERRIDE = "GTK+";
};

environment.systemPackages = with pkgs; [
  gtk-engine-murrine
  theme.package
  icon-theme.package
];
  }

I feel like a lot of this could be automated. Perhaps something like:

  environment.gtk.theme = {
package = pkgs.theme-vertex;
name = "Vertex-Dark;
  }

  environment.gtk.iconTheme = {
package = pkgs.numix-icon-theme;
name = "Numix";
  }

A thing to keep in mind is that some themes require additional packages
or libraries, for example, for numix I have to add:

  GDK_PIXBUF_MODULE_FILE = 
"${pkgs.librsvg.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache";

to get svg icon rendering to work, and for some themes I need to add
gtk-engine-murrine to my system packages.

Perhaps there could be some way for themes to represent these
requirements? I'm no NixOS infrastructure expert so I'm not sure what
would be the best way to go about this.

Some pseudo-code:

  theme-vertex = mkGtkTheme {
# ... package stuff ...

# better way to do this ?
pixbufModules = [ 
"${pkgs.librsvg.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" ];
requiredModules = [ gtk-engine-murrine ];
  }

and then environment machinery could set up all the required environment
variables from this.

Thoughts? Has there been progress down these lines before?

Cheers,

-- 
https://jb55.com
___
nix-dev mailing list
nix-dev@lists.science.uu.nl
https://mailman.science.uu.nl/mailman/listinfo/nix-dev