Skip to content

Instantly share code, notes, and snippets.

@jpsutton
Created November 3, 2024 21:37
Show Gist options
  • Save jpsutton/1e6e57ebc81ef7d37b5e3afe98f4f64c to your computer and use it in GitHub Desktop.
Save jpsutton/1e6e57ebc81ef7d37b5e3afe98f4f64c to your computer and use it in GitHub Desktop.
KDE+Linux: Set all displays to max brightness when resuming from sleep
#!/usr/bin/env python
import dbus
import dbus.mainloop.glib
import gi
from gi.repository import GLib
# Initialize the D-Bus main loop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# Connect to the session bus
bus = dbus.SessionBus()
def on_sleep_wakeup(*args):
# Interface to the ScreenBrightness service
screen_brightness_service = "org.kde.ScreenBrightness"
try:
for i in range(0,10):
display_iface = dbus.Interface(bus.get_object(screen_brightness_service, f"/org/kde/ScreenBrightness/display{i}"), f'{screen_brightness_service}.Display')
# Set the brightness to the maximum value
display_iface.SetBrightness(10000, 0)
except:
pass
def main():
# Listen for the sleep/wake signal from the 'org.freedesktop.login1' service
bus.add_signal_receiver(on_sleep_wakeup,
dbus_interface='org.kde.Solid.PowerManagement.Actions.SuspendSession',
signal_name='resumingFromSuspend',
path='/org/kde/Solid/PowerManagement/Actions/SuspendSession')
# Start the GLib main loop
loop = GLib.MainLoop()
print("Waiting for the sleep/wake signal...")
loop.run()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment