Last active
August 18, 2021 17:23
-
-
Save michaelgruenewald/adcc50d4e44bb0565fb01caac6936912 to your computer and use it in GitHub Desktop.
Script to switch GNOME to 'the other' monitor (if you have two connected and only one enabled)
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
#!/usr/bin/python3 | |
# This tool switches GNOME from one active monitor to the other connected | |
# monitor. | |
import dbus | |
bus = dbus.SessionBus() | |
display_config = dbus.Interface( | |
bus.get_object("org.gnome.Mutter.DisplayConfig", "/org/gnome/Mutter/DisplayConfig"), | |
"org.gnome.Mutter.DisplayConfig", | |
) | |
serial, crtcs, outputs, modes = display_config.GetCurrentState() | |
outputs = [] | |
for crtc_id, crtc_modes, _ in crtcs: | |
outputs.extend( | |
(crtc_id[0], crtc_mode[0], crtc_mode[-1].get("is-current")) | |
for crtc_mode in crtc_modes | |
if crtc_mode[-1].get("is-preferred") | |
) | |
(connector_id, mode_id), = ( | |
(connector_id, mode_id) for connector_id, mode_id, current in outputs if not current | |
) | |
display_config.ApplyMonitorsConfig( | |
serial, 1, [(0, 0, 1.0, 0, True, [(connector_id, mode_id, [])])], [] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment