mirror of
https://github.com/zoriya/flake.git
synced 2026-05-25 15:59:46 +00:00
Use darkman for automatic darkmode switching
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
import Gio from "gi://Gio";
|
||||
import GLib from "gi://GLib?version=2.0";
|
||||
|
||||
import { SimpleToggleButton } from "../misc/menu.js";
|
||||
|
||||
const interfaceXml = `
|
||||
<node name="/nl/whynothugo/darkman">
|
||||
<interface name="nl.whynothugo.darkman">
|
||||
<signal name="ModeChanged">
|
||||
<arg name="NewMode" type="s" />
|
||||
</signal>
|
||||
<property name="Mode" type="s" access="readwrite">
|
||||
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true" />
|
||||
</property>
|
||||
</interface>
|
||||
</node>
|
||||
`;
|
||||
const Darkman = Gio.DBusProxy.makeProxyWrapper(interfaceXml);
|
||||
|
||||
const theme = Variable(/** @type {"light" | "dark"} */ ("light"));
|
||||
|
||||
/** @param {Partial<import("../misc/menu.js").SimpleToggleButtonProps>} props */
|
||||
@@ -28,24 +40,18 @@ export const Toggle = ({ ...props } = {}) =>
|
||||
});
|
||||
|
||||
function init() {
|
||||
const settings = new Gio.Settings({
|
||||
schema: "org.gnome.desktop.interface",
|
||||
});
|
||||
const initial = /** @type {"prefer-light" | "prefer-dark"}} */ (
|
||||
settings.get_value("color-scheme").get_string()[0]
|
||||
const darkman = Darkman(
|
||||
Gio.DBus.session,
|
||||
"nl.whynothugo.darkman",
|
||||
"/nl/whynothugo/darkman",
|
||||
);
|
||||
theme.setValue(/** @type {any}} */ (initial.substring("prefer-".length)));
|
||||
theme.connect("changed", () => {
|
||||
settings.set_string("color-scheme", `prefer-${theme.value}`);
|
||||
settings.set_string(
|
||||
"gtk-theme",
|
||||
`adw-gtk3${theme.value === "dark" ? "-dark" : ""}`,
|
||||
);
|
||||
|
||||
const conf = GLib.get_user_config_dir();
|
||||
Utils.execAsync(
|
||||
`/bin/sh -c 'ln -sf ${conf}/kitty/${theme.value}.conf ${conf}/kitty/theme.conf && pkill -USR1 kitty'`,
|
||||
).catch(print);
|
||||
theme.value = darkman.Mode;
|
||||
theme.connect("changed", () => {
|
||||
darkman.Mode = theme.value;
|
||||
});
|
||||
darkman.connectSignal("ModeChanged", (_proxy, _senderName, nTheme) => {
|
||||
theme.value = nTheme[0];
|
||||
});
|
||||
}
|
||||
init();
|
||||
|
||||
@@ -1 +1 @@
|
||||
/nix/store/0wizyq5vnr0l5nyrvjnya732hxnk2cvw-ags-1.8.2/share/com.github.Aylur.ags/types
|
||||
/nix/store/bvbfvg7s1n35wv0afs7krkvppj6dx538-ags-1.8.2/share/com.github.Aylur.ags/types
|
||||
@@ -17,6 +17,29 @@ in {
|
||||
wallpaper
|
||||
];
|
||||
|
||||
services.darkman = {
|
||||
enable = true;
|
||||
settings = {
|
||||
usegeoclue = true;
|
||||
};
|
||||
lightModeScripts = {
|
||||
color-scheme = "${pkgs.glib}/bin/gsettings set org.gnome.desktop.interface color-scheme prefer-light";
|
||||
gtk3 = "${pkgs.glib}/bin/gsettings set org.gnome.desktop.interface gtk-theme adw-gtk3";
|
||||
kittycs = ''
|
||||
${pkgs.coreutils}/bin/ln -sf $XDG_CONFIG_HOME/kitty/light.conf $XDG_CONFIG_HOME/kitty/theme.conf
|
||||
${pkgs.procps}/bin/pkill -USR1 kitty
|
||||
'';
|
||||
};
|
||||
darkModeScripts = {
|
||||
color-scheme = "${pkgs.glib}/bin/gsettings set org.gnome.desktop.interface color-scheme prefer-dark";
|
||||
gtk3 = "${pkgs.glib}/bin/gsettings set org.gnome.desktop.interface gtk-theme adw-gtk3-dark";
|
||||
kittycs = ''
|
||||
${pkgs.coreutils}/bin/ln -sf $XDG_CONFIG_HOME/kitty/dark.conf $XDG_CONFIG_HOME/kitty/theme.conf
|
||||
${pkgs.procps}/bin/pkill -USR1 kitty
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
programs.hyprlock = {
|
||||
enable = true;
|
||||
settings = {
|
||||
|
||||
Reference in New Issue
Block a user