From d46be0bc0b5cf3020b97ffa3dcaa7d2367c76a24 Mon Sep 17 00:00:00 2001 From: Richard Neumann Date: Tue, 28 Apr 2020 21:54:11 +0200 Subject: [PATCH] Fixed mode notification and refactored mode toggle. --- tabletmode/cli.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tabletmode/cli.py b/tabletmode/cli.py index b4645ba..cb36a44 100644 --- a/tabletmode/cli.py +++ b/tabletmode/cli.py @@ -67,23 +67,6 @@ def notify_tablet_mode(): return notify_send('Tablet mode.', 'The system is now in tablet mode.') -def toggle_mode(notify=False): - """Toggles between laptop and tablet mode.""" - - if systemctl('status', TABLET_MODE_SERVICE): - systemctl('stop', TABLET_MODE_SERVICE, root=True) - systemctl('start', LAPTOP_MODE_SERVICE, root=True) - - if notify: - notify_tablet_mode() - else: - systemctl('stop', LAPTOP_MODE_SERVICE, root=True) - systemctl('start', TABLET_MODE_SERVICE, root=True) - - if notify: - notify_laptop_mode() - - def default_mode(notify=False): """Restores all blocked input devices.""" @@ -114,6 +97,15 @@ def tablet_mode(notify=False): notify_tablet_mode() +def toggle_mode(notify=False): + """Toggles between laptop and tablet mode.""" + + if systemctl('status', TABLET_MODE_SERVICE): + laptop_mode(notify=notify) + else: + tablet_mode(notify=notify) + + def main(): """Runs the main program."""