示例#1
0
def set_primary_monitor(monitor):
    """Set *monitor* to be the primary monitor.

    :param int monitor: Must be between 0 and the number of configured
     monitors.
    :raises: **ValueError** if an invalid monitor is specified.
    :raises: **BlacklistedDriverError** if your video driver does not
     support this.

    """
    try:
        glxinfo_out = subprocess.check_output("glxinfo")
    except OSError as e:
        raise OSError("Failed to run glxinfo: %s. (do you have mesa-utils installed?)" % e)

    for dri in _blacklisted_drivers:
        if dri in glxinfo_out:
            raise Display.BlacklistedDriverError('Impossible change the primary monitor for the given driver')

    num_monitors = Display.create().get_num_screens()
    if monitor < 0 or monitor >= num_monitors:
        raise ValueError('Monitor %d is not in valid range of 0 <= monitor < %d.' % (num_monitors))

    default_screen = Gdk.Screen.get_default()
    monitor_name = default_screen.get_monitor_plug_name(monitor)

    if not monitor_name:
        raise ValueError('Could not get monitor name from monitor number %d.' % (monitor))

    ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name, "--primary")

    if ret != 0:
        raise RuntimeError('Xrandr can\'t set the primary monitor. error code: %d' % (ret))
示例#2
0
     monitors.
    :raises: **ValueError** if an invalid monitor is specified.
    :raises: **BlacklistedDriverError** if your video driver does not
     support this.

    """
    try:
        glxinfo_out = subprocess.check_output("glxinfo")
    except OSError, e:
        raise OSError(
            "Failed to run glxinfo: %s. (do you have mesa-utils installed?)" %
            e)

    for dri in _blacklisted_drivers:
        if dri in glxinfo_out:
            raise Display.BlacklistedDriverError(
                'Impossible change the primary monitor for the given driver')

    num_monitors = Display.create().get_num_screens()
    if monitor < 0 or monitor >= num_monitors:
        raise ValueError(
            'Monitor %d is not in valid range of 0 <= monitor < %d.' %
            (num_monitors))

    default_screen = Gdk.Screen.get_default()
    monitor_name = default_screen.get_monitor_plug_name(monitor)

    if not monitor_name:
        raise ValueError('Could not get monitor name from monitor number %d.' %
                         (monitor))

    ret = os.spawnlp(os.P_WAIT, "xrandr", "xrandr", "--output", monitor_name,