AutoDarkMode / Windows-Auto-Night-Mode

Automatically switches between the dark and light theme of Windows 10 and Windows 11
GNU General Public License v3.0
7.62k stars 267 forks source link

Dynamic Lighting Support #893

Open N8endo opened 2 days ago

N8endo commented 2 days ago

Windows Personalization settings includes Dynamic Lighting, which controls your computer's RGB lights. Unfortunately, it doesn't link these settings to Themes, so theme switching can't change Dynamic Lighting settings.

I was wondering if Windows-Auto-Night-Mode could change Dynamic Lighting settings. For my use case, I just want the setting disabled during the day and enabled at night. Could that be added to your app?

Thanks!

ThioJoe commented 2 days ago

You can do it manually with scripts and powershell in the mean time, I have one like this for example below. The registry location for the devices is in HKEY_CURRENT_USER\Software\Microsoft\Lighting\Devices\ .

The names of the devices aren't listed anywhere in the entries, and it seems that device entries stick around even if they're not active or they change or something, so you'll need to do some trial and error to figure out which is which. You can just do that by setting some specific brightness per device in the Dynamic Lighting menu and see which registry entry updates to that 'Brightness' property value. My script just purely changes the brightness but you could also have other commands that change color and stuff.

Also since the YAML apparently can't have variables the best I could do to make it easier to edit the script was powershell variables, but that requires setting the variables twice, in both ArgsLight and ArgsDark, but it's just an extra copy paste.

Maybe the devs could add support for creating custom variables in the yaml itself that get expanded before the commands are run, so they could be set in one place.

Enabled: true
Component:
  Scripts:
  - Name: Set Theme
    Command: powershell
    ArgsLight: 
      - -Command
      - |
        # Device-specific registry paths
        $MouseDevicePath = 'HID#HID_DEVICE_SYSTEM_VHF#7&ee39c11&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 
        $PadDevicePath = 'HID#HID_DEVICE_SYSTEM_VHF#7&98cac03&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 
        $KeyboardDevicePath = 'HID#HID_DEVICE_SYSTEM_VHF#7&bc3184a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 
        $MotherboardDevicePath = 'HID#VID_0B05&PID_19AF&MI_03#7&24fc6c75&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 

        # ------------------------------------------------------------------------------------------------------------
        $BasePath = 'HKCU:\Software\Microsoft\Lighting\Devices\'; 
        Set-ItemProperty -Path ($BasePath + $MouseDevicePath) -Name 'Brightness' -Value 100; 
        Set-ItemProperty -Path ($BasePath + $PadDevicePath) -Name 'Brightness' -Value 100; 
        Set-ItemProperty -Path ($BasePath + $KeyboardDevicePath) -Name 'Brightness' -Value 100; 
        Set-ItemProperty -Path ($BasePath + $MotherboardDevicePath) -Name 'Brightness' -Value 100
    ArgsDark: 
      - -Command
      - |
        # Device-specific registry paths
        $MouseDevicePath = 'HID#HID_DEVICE_SYSTEM_VHF#7&ee39c11&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 
        $PadDevicePath = 'HID#HID_DEVICE_SYSTEM_VHF#7&98cac03&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 
        $KeyboardDevicePath = 'HID#HID_DEVICE_SYSTEM_VHF#7&bc3184a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 
        $MotherboardDevicePath = 'HID#VID_0B05&PID_19AF&MI_03#7&24fc6c75&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'; 

        # ------------------------------------------------------------------------------------------------------------
        $BasePath = 'HKCU:\Software\Microsoft\Lighting\Devices\'; 
        Set-ItemProperty -Path ($BasePath + $MouseDevicePath) -Name 'Brightness' -Value 30; 
        Set-ItemProperty -Path ($BasePath + $PadDevicePath) -Name 'Brightness' -Value 30; 
        Set-ItemProperty -Path ($BasePath + $KeyboardDevicePath) -Name 'Brightness' -Value 50; 
        Set-ItemProperty -Path ($BasePath + $MotherboardDevicePath) -Name 'Brightness' -Value 5
    AllowedSources: [Any]

Edit: Optimized the script

N8endo commented 1 day ago

@ThioJoe Thank you! That was very helpful! I edited the script to this: `Enabled: true Component: Scripts:

That worked perfectly. Can I also add another script to open OpenRGB (it's an app that control's my GPU's RGB) at night and close OpenRGB in the day? I'm a noob when it comes to scripting.

N8endo commented 1 day ago

Actually, I'm looking more at how OpenRGB works and I don't think just opening it and closing it will work for what I want. RGB is too complicated.

N8endo commented 1 day ago

@ThioJoe Ok. I figured it out. I've got OpenRGB opening at login and loading the rainbow profile for my GPU. WindowsAutoDarkMode can can close OpenRGB at sunset, then it will switch to my orange profile. Could you show me how to add that to my script? Just close the app OpenRGB at sunset. I'd really appreciate it!

ThioJoe commented 1 day ago

I think you could probably just add a line to the ArgsDark section using this:

Stop-Process -Name "OpenRGB"

So you could put it above the line that sets the registry value so those few lines now look like:

$BasePath = 'HKCU:\Software\Microsoft\Lighting\Devices'; 
Stop-Process -Name "OpenRGB"; 
Set-ItemProperty -Path ($BasePath + $CaseDevicePath) -Name 'AmbientLightingEnabled' -Value 1; 

Basically the way I have the script is each line effectively chains together multiple powershell commands into one. The semicolon and space ; at the end of the lines basically tells it to separate it from the next. So to add any additional powershell command just add a new line and make sure the previous one ended with a semicolon and space (I've found that the space is important). So all the lines beneath ArgsLight and ArgsDark is really just part of one big command (or rather each one is a single command).

All that being said, I would try experimenting with whether you can get everything working purely with dynamic lighting instead of having to use OpenRGB at all.