Ejemplo n.º 1
0
def new_rotation(current, desired_str, config, force=False):
    '''
    Determines the new rotation based on desired and current one.

    :param bool force: If set the function does not try to be too clever but
    just uses the rotation given. If no rotation is given in ``desired_str``,
    it still uses the default from the configuration.
    '''
    if desired_str is None:
        if not current.physically_closed:
            new = tps.translate_direction(config['rotate']['default_rotation'])
            logger.info('Using default, setting to {}'.format(new))
        else:
            new = tps.NORMAL
            logger.info('Using default, setting to {}'.format(new))
    else:
        desired = tps.translate_direction(desired_str)
        if desired == current and not force:
            new = tps.NORMAL
            logger.info('You try to rotate into the direction it is, '
                        'reverting to normal.')
        else:
            new = desired
            logger.info('User chose to set to {}'.format(new))

    return new
Ejemplo n.º 2
0
def new_rotation(current, desired_str, config, force=False):
    """
    Determines the new rotation based on desired and current one.

    :param bool force: If set the function does not try to be too clever but
    just uses the rotation given. If no rotation is given in ``desired_str``,
    it still uses the default from the configuration.
    """
    if desired_str is None:
        if not current.physically_closed:
            new = tps.translate_direction(config["rotate"]["default_rotation"])
            logger.info("Using default, setting to {}".format(new))
        else:
            new = tps.NORMAL
            logger.info("Using default, setting to {}".format(new))
    else:
        desired = tps.translate_direction(desired_str)
        if desired == current and not force:
            new = tps.NORMAL
            logger.info("You try to rotate into the direction it is, " "reverting to normal.")
        else:
            new = desired
            logger.info("User chose to set to {}".format(new))

    return new
Ejemplo n.º 3
0
def new_rotation(current, desired_str, config):
    '''
    Determines the new rotation based on desired and current one.
    '''
    if desired_str is None:
        if not current.physically_closed:
            new = tps.translate_direction(config['rotate']['default_rotation'])
            logger.info('Using default, setting to {}'.format(new))
        else:
            new = tps.NORMAL
            logger.info('Using default, setting to {}'.format(new))
    else:
        desired = tps.translate_direction(desired_str)
        if desired == current:
            new = tps.NORMAL
            logger.info('You try to rotate into the direction it is, '
                        'reverting to normal.')
        else:
            new = desired
            logger.info('User chose to set to {}'.format(new))
    return new
Ejemplo n.º 4
0
def get_rotation(screen):
    '''
    Gets the current rotation of the given screen.

    :param str screen: Find rotation of given output
    :returns: Current direction
    :rtype: tps.Direction
    '''
    output = tps.check_output(['xrandr', '-q', '--verbose'], logger).decode()
    lines = output.split('\n')
    for line in lines:
        if screen in line:
            matcher = re.search(r'\) (normal|left|inverted|right) \(', line)
            if matcher:
                rotation = tps.translate_direction(matcher.group(1))
                logger.info('Current rotation is “{}”.'.format(rotation))
                return rotation
    else:
        raise ScreenNotFoundException(
            'Screen "{}" is not enabled. Do you have a screen like that in '
            'the output of "xrandr", and is it enabled? Maybe you have to '
            'adjust the option of screen.internal in the '
            'configuration.'.format(screen))
Ejemplo n.º 5
0
def get_rotation(screen):
    '''
    Gets the current rotation of the given screen.

    :param str screen: Find rotation of given output
    :returns: Current direction
    :rtype: tps.Direction
    '''
    output = tps.check_output(['xrandr', '-q', '--verbose'], logger).decode()
    lines = output.split('\n')
    for line in lines:
        if screen in line:
            matcher = re.search(r'\) (normal|left|inverted|right) \(', line)
            if matcher:
                rotation = tps.translate_direction(matcher.group(1))
                logger.info('Current rotation is “{}”.'.format(rotation))
                return rotation
    else:
        raise ScreenNotFoundException(
            'Screen "{}" is not enabled. Do you have a screen like that in '
            'the output of "xrandr", and is it enabled? Maybe you have to '
            'adjust the option of screen.internal in the '
            'configuration.'.format(screen))