diff options
| author | 135e2 <135e2@135e2.tk> | 2022-03-24 13:20:32 +0800 | 
|---|---|---|
| committer | 135e2 <135e2@135e2.tk> | 2022-03-24 13:27:16 +0800 | 
| commit | 8ff8768dfdede0e6d05fb39bcffeb20933fcc911 (patch) | |
| tree | c4e8df58aa27640e79b6019632b07e7de462eb32 | |
| parent | 676d0507dca35367b7a2a320ec3194a3baa8830f (diff) | |
| download | dotfiles-8ff8768dfdede0e6d05fb39bcffeb20933fcc911.tar.gz dotfiles-8ff8768dfdede0e6d05fb39bcffeb20933fcc911.tar.bz2 dotfiles-8ff8768dfdede0e6d05fb39bcffeb20933fcc911.zip  | |
scripts/tablet_mode: update to v1.1
Changelog:
- Adapt to latest python
  In python3.8, we won't be allowed to change keys in the same dict easily, so let's just create another one.
  Ref: https://bugs.python.org/issue36452
- Disable xfce-specific settings.
  Heyyyyyyy! We use i3 as the daily window manager, so the xfce4-panel settings would be commented out.
- Correct accelerometers dir location.
  This should be chromebook-specific, so you need to change it yourself.
| -rw-r--r-- | scripts/tablet_mode | 34 | 
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/tablet_mode b/scripts/tablet_mode index e159697..51f0cf2 100644 --- a/scripts/tablet_mode +++ b/scripts/tablet_mode @@ -1,7 +1,13 @@  #!/usr/bin/env python3  # -*- indent-tabs-mode: nil; tab-width: 4 -*- -"""Enable/disable tablet mode in a Crouton chroot based on lid angle.""" +""" +Enable/disable tablet mode in a Crouton chroot based on lid angle. + +Slightly modified from https://gist.github.com/ninlith/d0b56676c09b9d3142266c20c833d3da +Author: ninlith & 135e2 +Version: v1.1 +"""  import argparse  import logging @@ -65,21 +71,26 @@ class ConvertibleChromebook(object):          self.screen_orientation = "normal"      def read_accelerometers(self): -        """Get data from accelerometers.""" +        """ +        Get data from accelerometers. + +        Edit the path below for your chromebook. +        """          command = ( -            "grep --null '' /sys/class/chromeos/cros_ec/device" -            "/cros-ec-accel.*/iio\:device*/* 2>/dev/null" +            "grep --null '' /sys/class/chromeos/cros_ec/device/cros-ec-sensorhub.2.auto" +            "/cros-ec-accel.*/iio:device*/* 2>/dev/null"              )          ret = os.popen(command).readlines()          paths_to_values = dict(line.rstrip().split('\0', 1) for line in ret)          tree = lambda: defaultdict(tree) -        data = tree() +        orig_data = tree() +        data = {}   # Create a new data dict instead.          for path in paths_to_values:              dirname, filename = path.rsplit('/', 1) -            data[dirname][filename] = paths_to_values[path] -        for dirname in data: -            location = data[dirname]['location'] -            data[location] = data.pop(dirname)  # Rename. +            orig_data[dirname][filename] = paths_to_values[path] +        for dirname in orig_data: +            location = orig_data[dirname]['location'] +            data[location] = orig_data[dirname]  # Move data to the new dict.          self.lid_accel = [x*float(data['lid']['scale']) for x in [              float(data['lid']['in_accel_x_raw']), @@ -234,7 +245,8 @@ def main():              if tablet_mode_enabled is not True:                  tablet_mode_init()                  tablet_mode_enabled = True -            cc.orientate_screen(callback=switch_xfce_panel_mode) +            # Comment it out since we don't use xfce panel on i3. +            # cc.orientate_screen(callback=switch_xfce_panel_mode)          elif abs(cc.lid_accel[0]) > 9.5:              # Lid angle calculation is unreliable when hinge aligns with              # gravity. @@ -248,4 +260,4 @@ def main():  if __name__ == "__main__": -    main()
\ No newline at end of file +    main()  | 
