nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.71k stars 1.76k forks source link

Feature idea: Xcursor theme and size #200

Closed league closed 6 years ago

league commented 6 years ago

Oh man, it took me way too long to figure out how to configure the X cursor when using NixOS and Xmonad. (I assume this is easier with Gnome/KDE). But it's life-changing to have properly magnified cursors on my HighDPI display. No more squinting and thrashing the mouse to find that invisible 1-pixel i-beam!

So I thought home-manager might be the place to capture this hard-won knowledge. Since it touches a few different modules here, I'd like advice on how to approach it. Here's the sketch:

I set these using let at the top of my home.nix:

  xcursorTheme = "Vanilla-DMZ";
  xcursorPackage = pkgs.vanilla-dmz;
  xcursorSize = 64;

and then plug them in like this:

  xresources.properties = {
    "Xcursor.theme" = xcursorTheme;
    "Xcursor.size"  = xcursorSize;
  };
  gtk.gtk2.extraConfig = ''
    gtk-cursor-theme-name="${xcursorTheme}"
    gtk-cursor-theme-size=${toString xcursorSize}
  '';
  gtk.gtk3.extraConfig = {
    "gtk-cursor-theme-name" = xcursorTheme;
    "gtk-cursor-theme-size" = xcursorSize;
  };
  xsession.initExtra = ''
    # ...other stuff...
    xsetroot -xcf ${xcursorPackage}/share/icons/${xcursorTheme}/cursors/X_cursor ${toString xcursorSize}
  '';

The xsetroot controls how the pointer appears when it's just on the root window, or hovering on taffybar.

I assume my let-bound settings could be a cursor-theme module that insinuates itself into all of the above. The cursor themes that I know about within nixpkgs are:

Thanks.

rycee commented 6 years ago

This is super nice! Thanks for investigating :-)

Maybe a way forward would be to add an option xsession.cursor having the type nullOr cursorType where cursorType is similar to the fontType and themeType type in the gtk module. Something like

  cursorType = types.submodule {
    options = {
      package = mkOption {
        type = types.package;
        example = literalExample "pkgs.vanilla-dmz";
        description = "Package providing the cursor.";
      };

      name = mkOption {
        type = types.str;
        example = "Vanilla-DMZ";
        description = "The cursor name within the package.";
      };

      size = mkOption {
        type = types.int;
        example = 64;
        description = "The cursor size.";
      };
    };
  };

So you're example configuration would be

  xsession.cursor = {
    name = "Vanilla-DMZ";
    package = pkgs.vanilla-dmz;
    size = 64;
  };

Now, I guess the tricky part is whether the code setting the xresources, gtk2, gtk3, etc. options should be placed in the different modules or gathered together in a new xcursor.nix module. I'm kind of inclined to having it all gathered together. Any preference?

But then maybe the font and icon theme configurations should be gathered in an xfont.nix and xicons.nix module as well? But let's worry about that in the future.

league commented 6 years ago

Thanks, that sounds about right. Could be gathered together, as long as merging settings across multiple places works. (Should be okay for records like in xresources and gtk3, not certain about gtk2 because it's a string.)

Anyway I'm entering the part of my week where there's no room to fiddle with such things. But I'll give it a shot after a few days.

rycee commented 6 years ago

The gtk2 textual config should merge without any issues. The resulting order is a bit unspecified but I think it shouldn't matter in this case.

rycee commented 6 years ago

In master now 👍