Enable dynamic colors for UI and firefox

This commit is contained in:
Jakob Lechner 2023-11-22 14:50:11 +00:00
parent 0f2e97a3fc
commit 668c83dfc0
No known key found for this signature in database
GPG key ID: 996082EFB5906C10
4 changed files with 70 additions and 18 deletions

View file

@ -33,6 +33,13 @@ let
target = "theme.css";
exec = [ "${pkgs.systemd}/bin/systemctl" "--user" "restart" "waybar.service" ];
}
{
exec = (
if nixosConfig.jalr.gui.enable
then [ "/usr/bin/env" "gsettings" "set" "org.gnome.desktop.interface" "color-scheme" "prefer-%scheme%" ]
else null
);
}
];
dynamic-colors = pkgs.writers.writePython3Bin "dynamic-colors" { } ''
import json
@ -43,34 +50,62 @@ let
def main():
DEFAULT_SCHEME = 'light'
CONFIG_FILE = "~/.config/dynamic-colors/config.json"
with open(pathlib.Path(CONFIG_FILE).expanduser(), "r") as fh:
config = json.load(fh)
command, = sys.argv[1:]
scheme = None
if command in ('light', 'dark'):
scheme = command
elif command == 'install':
pass
else:
raise NotImplementedError
for entry in config:
directory = pathlib.Path(entry['dir']).expanduser()
target = directory.joinpath(entry['target'])
directory = (
pathlib.Path(entry['dir']).expanduser() if 'dir' in entry else None
)
if all(key in entry for key in (
'target',
'light',
'dark'
)):
target = directory.joinpath(entry['target'])
if command in ('light', 'dark'):
if target.exists() and target.is_symlink:
os.remove(target)
if scheme is None:
if target.exists():
continue
scheme = entry[DEFAULT_SCHEME]
else:
if target.exists() and target.is_symlink:
os.remove(target)
src = {
'light': entry['light'],
'dark': entry['dark'],
}[command]
src = {
'light': entry['light'],
'dark': entry['dark'],
}[scheme]
os.symlink(src, target)
else:
if target.exists():
continue
os.symlink(entry['light'], target)
if 'exec' in entry:
subprocess.run(entry['exec'], cwd=directory)
if entry.get('exec') is not None:
command, *args = entry["exec"]
args = [
arg.replace(
'%scheme%', scheme
if scheme is not None
else DEFAULT_SCHEME
)
for arg in args
]
print(command, *args)
subprocess.run(
(command, *args),
cwd=directory
)
if __name__ == '__main__':
@ -82,6 +117,7 @@ in
text = lib.generators.toJSON { } applicationConfig;
onChange = "${dynamic-colors}/bin/dynamic-colors install";
};
home.packages = [
dynamic-colors
];

View file

@ -6,6 +6,7 @@
profiles = {
default = {
extensions = with pkgs.nur.repos.rycee.firefox-addons; [
darkreader
tree-style-tab
ublock-origin
umatrix

View file

@ -27,6 +27,17 @@ let
meta.license = lib.licenses.cc0;
};
move-to-output = pkgs.callPackage ./move-to-output { };
gsettings =
let
schema = pkgs.gsettings-desktop-schemas;
datadir = "${schema}/share/gsettings-schemas/${schema.name}";
in
pkgs.writeShellScriptBin "gsettings" ''
export XDG_DATA_DIRS=${datadir}:$XDG_DATA_DIRS
gnome_schema=org.gnome.desktop.interface
#gsettings set $gnome_schema gtk-theme 'Dracula'
${pkgs.glib}/bin/gsettings "$@"
'';
in
{
imports = lib.optionals nixosConfig.jalr.gui.enable [
@ -40,6 +51,7 @@ in
home.packages = with pkgs; [
sway-contrib.grimshot # screenshots
wdisplays # graphical output manager
gsettings
];
home.sessionVariables = {

View file

@ -26,7 +26,10 @@ lib.mkIf config.jalr.gui.enable {
xdg = {
portal = {
enable = true;
extraPortals = [ pkgs.xdg-desktop-portal-wlr ];
extraPortals = with pkgs; [
xdg-desktop-portal-wlr
xdg-desktop-portal-gtk
];
};
icons.enable = true;
};