diff --git a/README.md b/README.md index db11fd8..4f7d1dc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,21 @@ -# Chuwi Minibook tablet mode switch +# tablet-mode -Allow users to toggle a Chuwi Minibook laptop between laptop and tablet mode. -This is based on https://github.com/conqp/tablet-mode. +Allow users to toggle a convertible laptop between laptop and tablet mode. -## Installation +## Configuration -Just run `install.sh` on your Debian system and enter the name of you local user account. -Reboot after successful installation. +The devices to be deactivated in either *tablet* or *laptop* mode must be specified in `/etc/tablet-mode.json`. +Optionally you can specify whether desktop notifications shall be send when changing the mode using the *notify* flag. + + { + "tablet": [ + "/dev/input/by-path/platform-i8042-serio-0-event-kbd", + "/dev/input/by-path/platform-i8042-serio-1-event-mouse" + ], + "notify": false + } ## Usage +You must be a member of the group `tablet` to toggle between tablet and laptop mode. You can toggle between tablet and laptop mode by running `setsysmode toggle` or use the desktop icon provided with this package. diff --git a/install.sh b/install.sh deleted file mode 100755 index 990b345..0000000 --- a/install.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -GROUP=tablet - -if ! [ $(getent group "$GROUP") ]; then - echo "Add tablet group..." - /usr/sbin/groupadd tablet -fi - -read -p "Enter your local username: " user - -if ! [ $(groupmems -g "$GROUP" -l | grep "$user" ) ]; then - echo "Add user to group..." - usermod -a -G tablet "$user" -fi - -echo "Copy files..." -cp -r tabletmode/ /usr/local/lib/python3.11/dist-packages -cp tablet-mode.service /etc/systemd/system -cp laptop-mode.service /etc/systemd/system -cp tablet-mode.json /etc/ -cp tablet-mode.desktop /home/"$user"/.local/applications -cp tablet-mode.sudoers /etc/sudoers.d/tablet-mode -cp setsysmode /usr/local/bin -chmod +x /usr/local/bin/setsysmode -cp sysmoded /usr/local/bin -chmod +x /usr/local/bin/sysmoded - -echo "Reload systemd..." -systemctl daemon-reload - -echo "Install packages..." -apt install evtest -y diff --git a/laptop-mode.service b/laptop-mode.service index 93e4f27..7f9bd26 100644 --- a/laptop-mode.service +++ b/laptop-mode.service @@ -3,7 +3,7 @@ Description=Configure system for laptop mode Conflicts=tablet-mode.service [Service] -ExecStart=/usr/local/bin/sysmoded laptop +ExecStart=/usr/bin/sysmoded laptop StandardOutput=null [Install] diff --git a/setsysmode b/setsysmode deleted file mode 100644 index fb31d1f..0000000 --- a/setsysmode +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env python3 -"""Sets the system mode.""" - -from tabletmode.cli import main - - -if __name__ == '__main__': - main() diff --git a/sysmoded b/sysmoded deleted file mode 100644 index 347aca9..0000000 --- a/sysmoded +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env python3 -"""System mode daemon.""" - -from tabletmode.daemon import main - - -if __name__ == '__main__': - main() diff --git a/tablet-mode.desktop b/tablet-mode.desktop index 2c3a375..b077626 100644 --- a/tablet-mode.desktop +++ b/tablet-mode.desktop @@ -2,6 +2,6 @@ Comment=Toggle tablet mode Terminal=false Name=Tablet Mode -Exec=/usr/local/bin/setsysmode toggle +Exec=/usr/bin/setsysmode toggle Type=Application Icon=pda-symbolic diff --git a/tablet-mode.json b/tablet-mode.json deleted file mode 100644 index 14f657e..0000000 --- a/tablet-mode.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "tablet": [ - "/dev/input/by-path/platform-i8042-serio-0-event-kbd", - "/dev/input/by-path/pci-0000:00:14.0-usb-0:9:1.0-event-mouse" - ], - "notify": false -} diff --git a/tablet-mode.service b/tablet-mode.service index fc893e7..5ca2d1d 100644 --- a/tablet-mode.service +++ b/tablet-mode.service @@ -3,7 +3,7 @@ Description=Configure system for tablet mode Conflicts=laptop-mode.service [Service] -ExecStart=/usr/local/bin/sysmoded tablet +ExecStart=/usr/bin/sysmoded tablet StandardOutput=null [Install] diff --git a/tabletmode/cli.py b/tabletmode/cli.py index c20e898..82eed77 100644 --- a/tabletmode/cli.py +++ b/tabletmode/cli.py @@ -15,7 +15,6 @@ from tabletmode.config import load_config DESCRIPTION = 'Sets or toggles the system mode.' LAPTOP_MODE_SERVICE = 'laptop-mode.service' TABLET_MODE_SERVICE = 'tablet-mode.service' -SUDO = '/usr/bin/sudo' def get_args() -> Namespace: @@ -33,11 +32,10 @@ def get_args() -> Namespace: return parser.parse_args() -def systemctl(action: str, unit: str, *, root: bool = False, - sudo: str = SUDO) -> bool: +def systemctl(action: str, unit: str, *, root: bool = False) -> bool: """Runs systemctl.""" - command = [sudo] if root else [] + command = ['/usr/bin/sudo'] if root else [] command += ['systemctl', action, unit] try: @@ -71,43 +69,43 @@ def notify_tablet_mode() -> CompletedProcess: return notify_send('Tablet mode.', 'The system is now in tablet mode.') -def default_mode(notify: bool = False, *, sudo: str = SUDO) -> None: +def default_mode(notify: bool = False) -> None: """Restores all blocked input devices.""" - systemctl('stop', LAPTOP_MODE_SERVICE, root=True, sudo=sudo) - systemctl('stop', TABLET_MODE_SERVICE, root=True, sudo=sudo) + systemctl('stop', LAPTOP_MODE_SERVICE, root=True) + systemctl('stop', TABLET_MODE_SERVICE, root=True) if notify: notify_send('Default mode.', 'The system is now in default mode.') -def laptop_mode(notify: bool = False, *, sudo: str = SUDO) -> None: +def laptop_mode(notify: bool = False) -> None: """Starts the laptop mode.""" - systemctl('stop', TABLET_MODE_SERVICE, root=True, sudo=sudo) - systemctl('start', LAPTOP_MODE_SERVICE, root=True, sudo=sudo) + systemctl('stop', TABLET_MODE_SERVICE, root=True) + systemctl('start', LAPTOP_MODE_SERVICE, root=True) if notify: notify_laptop_mode() -def tablet_mode(notify: bool = False, *, sudo: str = SUDO) -> None: +def tablet_mode(notify: bool = False) -> None: """Starts the tablet mode.""" - systemctl('stop', LAPTOP_MODE_SERVICE, root=True, sudo=sudo) - systemctl('start', TABLET_MODE_SERVICE, root=True, sudo=sudo) + systemctl('stop', LAPTOP_MODE_SERVICE, root=True) + systemctl('start', TABLET_MODE_SERVICE, root=True) if notify: notify_tablet_mode() -def toggle_mode(notify: bool = False, *, sudo: str = SUDO) -> None: +def toggle_mode(notify: bool = False) -> None: """Toggles between laptop and tablet mode.""" if systemctl('status', TABLET_MODE_SERVICE): - laptop_mode(notify=notify, sudo=sudo) + laptop_mode(notify=notify) else: - tablet_mode(notify=notify, sudo=sudo) + tablet_mode(notify=notify) def main() -> None: @@ -116,15 +114,14 @@ def main() -> None: args = get_args() config = load_config() notify = config.get('notify', False) or args.notify - sudo = config.get('sudo', SUDO) if args.mode == 'toggle': - toggle_mode(notify=notify, sudo=sudo) + toggle_mode(notify=notify) elif args.mode == 'default': - default_mode(notify=notify, sudo=sudo) + default_mode(notify=notify) elif args.mode == 'laptop': - laptop_mode(notify=notify, sudo=sudo) + laptop_mode(notify=notify) elif args.mode == 'tablet': - tablet_mode(notify=notify, sudo=sudo) + tablet_mode(notify=notify) else: print('Must specify a mode.', file=stderr, flush=True)