Skip to content

Commit

Permalink
Merge branch 'release/4.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-ueding committed Oct 15, 2015
2 parents 247d601 + 47434ce commit f455757
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
Changelog
#########

v4.6.0
Released: 2015-10-15 20:30:31 +0200

- Add a ``--force-direction`` command line option for ``thinkpad-rotate``
such that this can be used in a script. When starting up the computer an
autostart entry like ::

thinkpad-rotate --force-direction normal

could be very handy to normalize the setup.

v4.5.0
Released: 2015-10-15 16:50:57 +0200

Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

# General information about the project.
project = 'thinkpad-scripts'
copyright = '2012-2014, Martin Ueding and Jim Turner'
copyright = '2012-2015, Martin Ueding and Jim Turner'

try:
sys.path.append('..')
Expand Down
23 changes: 22 additions & 1 deletion doc/man/thinkpad-rotate.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ screen.
Options
=======

direction
``direction``
The direction can be any of:

- ccw
Expand All @@ -59,6 +59,19 @@ direction
accepts all of them, so that you do not have to learn yet another set of
directions.

``-v``
Enable verbose output. Can be supplied multiple times for even more
verbosity.

``--via-hook``
Let the program know that it was called using the hook. This will then
enable some workarounds. You do not need to care about this.

``--force-direction``
Do not try to be smart. Actually rotate in the direction given even it
already is the case.


Exit Status
===========

Expand Down Expand Up @@ -97,6 +110,14 @@ the ``thinkpad-scripts-config-migrate`` script that was introduced in version
You can set the following option:

``hooks.postrotate``
Executable file to run after rotation.
*Default: ~/.config/thinkpad-scripts/hooks/postrotate*

``hooks.prerotate``
Executable file to run before rotation.
*Default: ~/.config/thinkpad-scripts/hooks/prerotate*

``rotate.default_rotation``
Default rotation if device is in normal rotation and no arguments are
given. *Default: right*
Expand Down
15 changes: 11 additions & 4 deletions tps/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main():
'''
options = _parse_args()


config = tps.config.get_config()

if options.via_hook:
Expand All @@ -33,7 +34,7 @@ def main():
try:
new_direction = new_rotation(
tps.screen.get_rotation(config['screen']['internal']),
options.direction, config)
options.direction, config, options.force_direction)
except tps.UnknownDirectionException:
logger.error('Direction cannot be understood.')
sys.exit(1)
Expand Down Expand Up @@ -92,9 +93,13 @@ def rotate_to(direction, config):
tps.hooks.postrotate(direction, config)


def new_rotation(current, desired_str, config):
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:
Expand All @@ -105,13 +110,14 @@ def new_rotation(current, desired_str, config):
logger.info('Using default, setting to {}'.format(new))
else:
desired = tps.translate_direction(desired_str)
if desired == current:
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


Expand Down Expand Up @@ -210,7 +216,8 @@ def _parse_args():
parser.add_argument("-v", dest='verbose', action="count",
help='Enable verbose output. Can be supplied multiple '
'times for even more verbosity.')
parser.add_argument('--via-hook', action='store_true')
parser.add_argument('--via-hook', action='store_true', help='Let the program know that it was called using the hook. This will then enable some workarounds. You do not need to care about this.')
parser.add_argument('--force-direction', action='store_true', help='Do not try to be smart. Actually rotate in the direction given even it already is the case.')

options = parser.parse_args()

Expand Down

0 comments on commit f455757

Please sign in to comment.