Last active
December 25, 2023 06:31
-
-
Save Zren/6b9a0cea7b19ab42f239b379bea5e2b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dbus | |
from enum import Enum | |
import argparse | |
parser = argparse.ArgumentParser(description='Process some integers.') | |
parser.add_argument('temp', | |
type=int, | |
help='NightTemperature (eg: 4200)', | |
) | |
parser.add_argument('-d', '--delta', | |
help='Increment by temp instead.', | |
action='store_true', | |
default=False, | |
) | |
args = parser.parse_args() | |
# https://github.com/KDE/kwin/blob/master/colorcorrection/manager.h#L49 | |
class NightColorMode(Enum): | |
Automatic = 0 | |
Location = 1 | |
Timings = 2 | |
Constant = 3 | |
bus = dbus.SessionBus() | |
obj = bus.get_object('org.kde.KWin', '/ColorCorrect') | |
iface = dbus.Interface(obj, dbus_interface='org.kde.kwin.ColorCorrect') | |
oldProps = iface.nightColorInfo() | |
if args.delta: | |
nextTemp = oldProps['NightTemperature'] + args.temp | |
else: | |
nextTemp = args.temp | |
iface.setNightColorConfig({ | |
'Mode': NightColorMode.Constant.value, | |
'NightTemperature': nextTemp, | |
}) | |
newProps = iface.nightColorInfo() | |
def printPropDiff(key): | |
print("{}: {} => {}".format(key, oldProps[key], newProps[key])) | |
print("{}: {} => {}".format('Mode', NightColorMode(oldProps['Mode']), NightColorMode(newProps['Mode']))) | |
printPropDiff('NightTemperature') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment