1#!/usr/bin/env python3

2# -*- coding: utf-8 -*-

3#

4# rotation_test

5#

6# This file is part of Checkbox.

7#

8# Copyright 2012-2019 Canonical Ltd.

9#

10# Authors: Alberto Milone <alberto.milone@canonical.com>

11# Maciej Kisielewski <maciej.kisielewski@canonical.com>

12#

13# Checkbox is free software: you can redistribute it and/or modify

14# it under the terms of the GNU General Public License version 3,

15# as published by the Free Software Foundation.

16#

17# Checkbox is distributed in the hope that it will be useful,

18# but WITHOUT ANY WARRANTY; without even the implied warranty of

19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

20# GNU General Public License for more details.

21#

22# You should have received a copy of the GNU General Public License

23# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

24

25 import gi

26 import os

27 import time

28 import subprocess

29 import warnings

30

31 warnings.filterwarnings("ignore", category=DeprecationWarning)

32

33 gi.require_version("Gdk", "3.0")

34 from gi.repository import Gdk # noqa: E402

35

36

37 def main():

38 """Run rotation cycling by running xrandr command."""

39 screen = Gdk.Screen.get_default()

40 output = screen.get_monitor_plug_name(screen.get_primary_monitor())

41 print("Using output: {}".format(output))

42 for rotation in ["right", "inverted", "left", "normal"]:

43 if os.getenv("XDG_SESSION_TYPE") == "wayland":

44 subprocess.check_call(

45 ["gnome-randr", "modify", output, "--rotate", rotation]

46 )

47 else:

48 print("setting rotation to {}".format(rotation))

49 subprocess.check_call(

50 ["xrandr", "--output", output, "--rotation", rotation]

51 )

52 time.sleep(8)

53

54

55 if __name__ == "__main__":

56 exit(main())