From a99e38764b2dbbe5fe3838bd77ec4403e2df55c3 Mon Sep 17 00:00:00 2001 From: Maciej Kisielewski Date: Thu, 6 Jun 2019 10:45:59 +0200 Subject: rotation_test: use xrandr bin to rotate the screen Signed-off-by: Maciej Kisielewski --- bin/rotation_test | 59 ++++++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) (limited to 'bin') diff --git a/bin/rotation_test b/bin/rotation_test index 258a881..6bf90fd 100755 --- a/bin/rotation_test +++ b/bin/rotation_test @@ -5,14 +5,14 @@ # # This file is part of Checkbox. # -# Copyright 2012 Canonical Ltd. +# Copyright 2012-2019 Canonical Ltd. # # Authors: Alberto Milone +# Maciej Kisielewski # # Checkbox is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, # as published by the Free Software Foundation. - # # Checkbox is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,53 +22,24 @@ # You should have received a copy of the GNU General Public License # along with Checkbox. If not, see . +import gi import time -import sys - -from checkbox_support.contrib import xrandr - +import subprocess -def rotate_screen(rotation): - # Refresh the screen. Required by NVIDIA - screen = xrandr.get_current_screen() - screen.set_rotation(rotation) - return screen.apply_config() +gi.require_version('Gdk', '3.0') +from gi.repository import Gdk def main(): - screen = xrandr.get_current_screen() - rotations = {'normal': xrandr.RR_ROTATE_0, - 'right': xrandr.RR_ROTATE_90, - 'inverted': xrandr.RR_ROTATE_180, - 'left': xrandr.RR_ROTATE_270} - rots_statuses = {} - - for rot in rotations: - try: - status = rotate_screen(rotations[rot]) - except (xrandr.RRError, xrandr.UnsupportedRRError) as exc: - status = 1 - error = exc - else: - error = 'N/A' - # Collect the status and the error message - rots_statuses[rot] = (status, error) + """Run rotation cycling by running xrandr command.""" + screen = Gdk.Screen.get_default() + output = screen.get_monitor_plug_name(screen.get_primary_monitor()) + print("Using output: {}".format(output)) + + for rotation in ['right', 'inverted', 'left', 'normal']: + print("Changing rotation to: {}".format(rotation)) + subprocess.check_call( + ['xrandr', '--output', output, '--rotation', rotation]) time.sleep(4) - # Try to set the screen back to normal - try: - rotate_screen(xrandr.RR_ROTATE_0) - except(xrandr.RRError, xrandr.UnsupportedRRError) as error: - print(error) - - result = 0 - for elem in rots_statuses: - status = rots_statuses.get(elem)[0] - error = rots_statuses.get(elem)[1] - if status != 0: - print('Error: rotation "%s" failed with status %d: %s.' % - (elem, status, error), file=sys.stderr) - result = 1 - return result - if __name__ == '__main__': exit(main()) -- cgit v1.2.3