Skip to content

Instantly share code, notes, and snippets.

@tjgordon
Created June 15, 2017 18:01
Show Gist options
  • Save tjgordon/d9ad7cff684f4dabd7b10595bb6f6544 to your computer and use it in GitHub Desktop.
Save tjgordon/d9ad7cff684f4dabd7b10595bb6f6544 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# From https://github.com/nitg16/tapioca, for debugging purposes
import evdev
import subprocess
from decimal import Decimal
import time
import os
import ConfigParser
from collections import OrderedDict
from threading import Timer, Thread
from pymouse import PyMouse
import argparse
import sys
# todo
# long press should not work on two finger long press
# implement three finger tap
# implement swipes
mouse = PyMouse()
app_name = "tapioca"
config_folder = os.path.join(os.path.expanduser("~"), '.config', app_name)
config_file = app_name + ".conf"
full_config_file_path = os.path.join(config_folder, config_file)
Config = ConfigParser.ConfigParser(allow_no_value=True)
parser = argparse.ArgumentParser(
description=app_name + " enables right click on linux touchscreen devices.")
parser.add_argument(
"--device", help="Specify name of your touch panel make" \
" (can be found out by running xinput command).")
args = parser.parse_args()
# print(args.device)
# do not edit these settings, all settings should be changed in .conf file
# in user section
default_section = "Default Settings"
user_section = "User Settings"
default_settings = OrderedDict([
('; Touch panel make (run xinput command in terminal)', None),
('touch_panel', ""),
('; Minimum long press time in seconds, e.g - 0.5, 1.2', None),
('minimum_long_press_time', 1.5),
('; Right click methods, possible values - xdotool, pymouse', None),
('right_click_method', 'xdotool'),
('; Long press behavior, possible values - pc (menu appears after finger lift),' \
' smartphone (no finger lift required, menu flickers once)', None),
('long_press_behavior', 'pc'),
('; Long press, possible values - 1 (True), 0 (False)', None),
('enable_long_press', 1),
('; Two finger tap, possible values - 1 (True), 0 (False)', None),
('enable_two_finger_tap', 1)
])
def setconfig():
try:
if os.stat(full_config_file_path).st_size > 0:
file_empty = False
else:
file_empty = True
except OSError:
pass
if not os.path.exists(config_folder):
os.makedirs(config_folder)
if not os.path.exists(full_config_file_path) or file_empty == True:
with open(full_config_file_path, "w+") as f:
Config.add_section(default_section)
Config.set(
default_section, '; !!!! do not edit, change settings in user section !!!!')
for k, v in default_settings.items():
if v == None:
Config.set(default_section, k)
else:
Config.set(default_section, k, v)
Config.add_section(user_section)
Config.set(user_section, '; change settings below')
for k, v in default_settings.items():
if v == None:
Config.set(user_section, k)
else:
Config.set(user_section, k, v)
Config.write(f)
if args.device != None:
with open(full_config_file_path, "w") as b:
Config.set(user_section, "touch_panel", args.device)
Config.write(b)
try:
setconfig()
except KeyboardInterrupt:
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment